From: halcanary Date: Wed, 28 Jan 2015 19:45:58 +0000 (-0800) Subject: DM::PDFSink::draw excercises multi-page pdf X-Git-Tag: submit/tizen/20180928.044319~3852 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd4a993f8b162f6ca541514234a81759b67dc64d;p=platform%2Fupstream%2FlibSkiaSharp.git DM::PDFSink::draw excercises multi-page pdf BUG=skia:3365 Review URL: https://codereview.chromium.org/881343002 --- diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 7979dff9bd..3fd1a4d25d 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -180,18 +180,37 @@ 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 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(), + 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)); + canvas->clipRect(letter); + canvas->translate(-letter.width() * x, -letter.height() * y); + Error err = src.draw(canvas); + if (!err.isEmpty()) { + return err; + } + doc->endPage(); + } } - canvas->flush(); - doc->endPage(); doc->close(); + dst->flush(); return ""; }