From 7e79818137f2173302d6476a6127525b11684ec2 Mon Sep 17 00:00:00 2001 From: halcanary Date: Tue, 14 Apr 2015 14:06:18 -0700 Subject: DM: add --multiPage option Motivation: I want to switch back to single-page output by default for direct comparison to raster backends in Gold. I can still test the multi-page option via a command-line switch. BUG=skia:3721 Review URL: https://codereview.chromium.org/1063873004 --- dm/DMSrcSink.cpp | 66 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'dm') diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 9e9a77c271..e70dd3e2b0 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -24,6 +24,9 @@ #include "SkStream.h" #include "SkXMLWriter.h" +DEFINE_bool(multiPage, false, "For document-type backends, render the source" + " into multiple pages"); + static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { SkAutoTUnref encoded(SkData::NewWithCopy(src, size)); return encoded && SkInstallDiscardablePixelRef(encoded, dst); @@ -377,33 +380,48 @@ static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) { int width = src.size().width(), height = src.size().height(); - const int kLetterWidth = 612, // 8.5 * 72 - kLetterHeight = 792; // 11 * 72 - const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), - SkIntToScalar(kLetterHeight)); - - int xPages = ((width - 1) / kLetterWidth) + 1; - int yPages = ((height - 1) / kLetterHeight) + 1; - - for (int y = 0; y < yPages; ++y) { - for (int x = 0; x < xPages; ++x) { - int w = SkTMin(kLetterWidth, width - (x * kLetterWidth)); - int h = SkTMin(kLetterHeight, height - (y * kLetterHeight)); - SkCanvas* canvas = - doc->beginPage(SkIntToScalar(w), SkIntToScalar(h)); - if (!canvas) { - return "SkDocument::beginPage(w,h) returned NULL"; - } - canvas->clipRect(letter); - canvas->translate(-letter.width() * x, -letter.height() * y); - Error err = src.draw(canvas); - if (!err.isEmpty()) { - return err; + if (FLAGS_multiPage) { + const int kLetterWidth = 612, // 8.5 * 72 + kLetterHeight = 792; // 11 * 72 + const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), + SkIntToScalar(kLetterHeight)); + + int xPages = ((width - 1) / kLetterWidth) + 1; + int yPages = ((height - 1) / kLetterHeight) + 1; + + for (int y = 0; y < yPages; ++y) { + for (int x = 0; x < xPages; ++x) { + int w = SkTMin(kLetterWidth, width - (x * kLetterWidth)); + int h = SkTMin(kLetterHeight, height - (y * kLetterHeight)); + SkCanvas* canvas = + doc->beginPage(SkIntToScalar(w), SkIntToScalar(h)); + if (!canvas) { + return "SkDocument::beginPage(w,h) returned NULL"; + } + canvas->clipRect(letter); + canvas->translate(-letter.width() * x, -letter.height() * y); + Error err = src.draw(canvas); + if (!err.isEmpty()) { + return err; + } + doc->endPage(); } - doc->endPage(); } + } else { + SkCanvas* canvas = + doc->beginPage(SkIntToScalar(width), SkIntToScalar(height)); + if (!canvas) { + return "SkDocument::beginPage(w,h) returned NULL"; + } + Error err = src.draw(canvas); + if (!err.isEmpty()) { + return err; + } + doc->endPage(); + } + if (!doc->close()) { + return "SkDocument::close() returned false"; } - doc->close(); dst->flush(); return ""; } -- cgit v1.2.3