aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-01-06 09:54:13 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-06 09:54:14 -0800
commitefdac514a9846e4ef32e1160fe7f2dae471cef39 (patch)
tree53ab81d241b34d49e0d617e6e0c19f17b4ed8c18 /gm
parent8b1f761365df6652ea9304b6572d2dd91917b9aa (diff)
Revert "Remove SkPDFDocument and SkPDFDevice from the public headers."
This reverts commit 8b1f761365df6652ea9304b6572d2dd91917b9aa. BUG=skia: TBR= NOTRY=True NOTREECHECKS=True Review URL: https://codereview.chromium.org/839603002
Diffstat (limited to 'gm')
-rw-r--r--gm/gmmain.cpp65
1 files changed, 51 insertions, 14 deletions
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index b8c8891471..ece8ff32d4 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -74,6 +74,13 @@ typedef int GrGLStandard;
#define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
+DECLARE_bool(useDocumentInsteadOfDevice);
+
+#ifdef SK_SUPPORT_PDF
+ #include "SkPDFDevice.h"
+ #include "SkPDFDocument.h"
+#endif
+
// Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
// stop writing out XPS-format image baselines in gm.
#undef SK_SUPPORT_XPS
@@ -668,24 +675,53 @@ public:
static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
#ifdef SK_SUPPORT_PDF
- SkAutoTUnref<SkDocument> pdfDoc(
- SkDocument::CreatePDF(&pdf, NULL, encode_to_dct_data,
- SkIntToScalar(FLAGS_pdfRasterDpi)));
- if (!pdfDoc) {
- return false;
- }
-
- SkCanvas* canvas = NULL;
- canvas = pdfDoc->beginPage(gm->width(), gm->height());
- canvas->concat(gm->getInitialTransform());
+ SkMatrix initialTransform = gm->getInitialTransform();
+ if (FLAGS_useDocumentInsteadOfDevice) {
+ SkISize pageISize = gm->getISize();
+ SkAutoTUnref<SkDocument> pdfDoc(
+ SkDocument::CreatePDF(&pdf, NULL,
+ encode_to_dct_data,
+ SkIntToScalar(FLAGS_pdfRasterDpi)));
+
+ if (!pdfDoc.get()) {
+ return false;
+ }
- invokeGM(gm, canvas, true, false);
+ SkCanvas* canvas = NULL;
+ canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()),
+ SkIntToScalar(pageISize.height()));
+ canvas->concat(initialTransform);
- return pdfDoc->close();
+ invokeGM(gm, canvas, true, false);
-#else // SK_SUPPORT_PDF
- return true; // Do not report failure if pdf is not supported.
+ return pdfDoc->close();
+ } else {
+ SkISize pageSize = gm->getISize();
+ SkPDFDevice* dev = NULL;
+ if (initialTransform.isIdentity()) {
+ dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
+ } else {
+ SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
+ SkIntToScalar(pageSize.height()));
+ initialTransform.mapRect(&content);
+ content.intersect(0, 0, SkIntToScalar(pageSize.width()),
+ SkIntToScalar(pageSize.height()));
+ SkISize contentSize =
+ SkISize::Make(SkScalarRoundToInt(content.width()),
+ SkScalarRoundToInt(content.height()));
+ dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
+ }
+ dev->setDCTEncoder(encode_to_dct_data);
+ dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi));
+ SkAutoUnref aur(dev);
+ SkCanvas c(dev);
+ invokeGM(gm, &c, true, false);
+ SkPDFDocument doc;
+ doc.appendPage(dev);
+ doc.emitPDF(&pdf);
+ }
#endif // SK_SUPPORT_PDF
+ return true; // Do not report failure if pdf is not supported.
}
static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
@@ -1542,6 +1578,7 @@ DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
// Probably define spacial names like centerx, centery, top, bottom, left, right
// then we can write something reabable like --rotate centerx centery 90
DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
+DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instead of SkFooDevice.");
DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported "
"features in PDF are rasterized. Must be be in range 0-10000. "
"Default is 72. N = 0 will disable rasterizing features like "