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

Unified Diff: dm/DMSrcSink.cpp

Issue 881343002: DM::PDFSink::draw excercises multi-page pdf (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: . Created 5 years, 11 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 affb844bc6aa39f76d5c2b5150f6c8954ea5fe94..dd4878257d722cb8cdb23e5909a799f94e13444a 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -173,18 +173,38 @@ Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const {
PDFSink::PDFSink() {}
Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst) const {
- SkSize size;
- size = src.size();
+ // Print the given DM:Src to a PDF, breaking on 8.5x11 pages.
SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
- SkCanvas* canvas = doc->beginPage(size.width(), size.height());
- Error err = src.draw(canvas);
- if (!err.isEmpty()) {
- return err;
+ int width = src.size().width();
+ int height = src.size().height();
+
+ const int kLetterWidth = 612; // 8.5 * 72
+ const int kLetterHeight = 792; // 11 * 72
+ const SkScalar kLetterWidthScalar = SkIntToScalar(kLetterWidth);
mtklein 2015/01/28 16:28:26 I think this would be more readable with fewer con
+ const SkScalar kLetterHeightScalar = SkIntToScalar(kLetterHeight);
+ SkRect letterRect = SkRect::MakeWH(kLetterWidthScalar, kLetterHeightScalar);
+
+ 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(w, h);
+ canvas->clipRect(letterRect);
+ canvas->translate(-kLetterWidthScalar * x,
+ -kLetterHeightScalar * y);
+ Error err = src.draw(canvas);
+ if (!err.isEmpty()) {
+ return err;
+ }
+ doc->endPage();
+ }
}
- canvas->flush();
- doc->endPage();
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