Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Unified Diff: dm/DMSrcSink.cpp

Issue 1063873004: DM: add --multiPage option (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-04-14 (Tuesday) 16:49:26 EDT Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 9e9a77c27124e85350406c7e84ec3b2f8f5f0886..e70dd3e2b0def9a2825f01c10573b7eb98e773c3 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<SkData> 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 "";
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698