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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "SamplePipeControllers.h" 9 #include "SamplePipeControllers.h"
10 #include "SkCommonFlags.h" 10 #include "SkCommonFlags.h"
11 #include "SkCodec.h" 11 #include "SkCodec.h"
12 #include "SkData.h" 12 #include "SkData.h"
13 #include "SkDocument.h" 13 #include "SkDocument.h"
14 #include "SkError.h" 14 #include "SkError.h"
15 #include "SkImageGenerator.h" 15 #include "SkImageGenerator.h"
16 #include "SkMultiPictureDraw.h" 16 #include "SkMultiPictureDraw.h"
17 #include "SkNullCanvas.h" 17 #include "SkNullCanvas.h"
18 #include "SkOSFile.h" 18 #include "SkOSFile.h"
19 #include "SkPictureData.h" 19 #include "SkPictureData.h"
20 #include "SkPictureRecorder.h" 20 #include "SkPictureRecorder.h"
21 #include "SkRandom.h" 21 #include "SkRandom.h"
22 #include "SkScanlineDecoder.h" 22 #include "SkScanlineDecoder.h"
23 #include "SkSVGCanvas.h" 23 #include "SkSVGCanvas.h"
24 #include "SkStream.h" 24 #include "SkStream.h"
25 #include "SkXMLWriter.h" 25 #include "SkXMLWriter.h"
26 26
27 DEFINE_bool(multiPage, false, "For document-type backends, render the source"
28 " into multiple pages");
29
27 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { 30 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
28 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); 31 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
29 return encoded && SkInstallDiscardablePixelRef(encoded, dst); 32 return encoded && SkInstallDiscardablePixelRef(encoded, dst);
30 } 33 }
31 34
32 namespace DM { 35 namespace DM {
33 36
34 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} 37 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
35 38
36 Error GMSrc::draw(SkCanvas* canvas) const { 39 Error GMSrc::draw(SkCanvas* canvas) const {
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 373 }
371 374
372 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 375 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
373 376
374 static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) { 377 static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
375 // Print the given DM:Src to a document, breaking on 8.5x11 pages. 378 // Print the given DM:Src to a document, breaking on 8.5x11 pages.
376 SkASSERT(doc); 379 SkASSERT(doc);
377 int width = src.size().width(), 380 int width = src.size().width(),
378 height = src.size().height(); 381 height = src.size().height();
379 382
380 const int kLetterWidth = 612, // 8.5 * 72 383 if (FLAGS_multiPage) {
381 kLetterHeight = 792; // 11 * 72 384 const int kLetterWidth = 612, // 8.5 * 72
382 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), 385 kLetterHeight = 792; // 11 * 72
383 SkIntToScalar(kLetterHeight)); 386 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
387 SkIntToScalar(kLetterHeight));
384 388
385 int xPages = ((width - 1) / kLetterWidth) + 1; 389 int xPages = ((width - 1) / kLetterWidth) + 1;
386 int yPages = ((height - 1) / kLetterHeight) + 1; 390 int yPages = ((height - 1) / kLetterHeight) + 1;
387 391
388 for (int y = 0; y < yPages; ++y) { 392 for (int y = 0; y < yPages; ++y) {
389 for (int x = 0; x < xPages; ++x) { 393 for (int x = 0; x < xPages; ++x) {
390 int w = SkTMin(kLetterWidth, width - (x * kLetterWidth)); 394 int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
391 int h = SkTMin(kLetterHeight, height - (y * kLetterHeight)); 395 int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
392 SkCanvas* canvas = 396 SkCanvas* canvas =
393 doc->beginPage(SkIntToScalar(w), SkIntToScalar(h)); 397 doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
394 if (!canvas) { 398 if (!canvas) {
395 return "SkDocument::beginPage(w,h) returned NULL"; 399 return "SkDocument::beginPage(w,h) returned NULL";
400 }
401 canvas->clipRect(letter);
402 canvas->translate(-letter.width() * x, -letter.height() * y);
403 Error err = src.draw(canvas);
404 if (!err.isEmpty()) {
405 return err;
406 }
407 doc->endPage();
396 } 408 }
397 canvas->clipRect(letter);
398 canvas->translate(-letter.width() * x, -letter.height() * y);
399 Error err = src.draw(canvas);
400 if (!err.isEmpty()) {
401 return err;
402 }
403 doc->endPage();
404 } 409 }
410 } else {
411 SkCanvas* canvas =
412 doc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
413 if (!canvas) {
414 return "SkDocument::beginPage(w,h) returned NULL";
415 }
416 Error err = src.draw(canvas);
417 if (!err.isEmpty()) {
418 return err;
419 }
420 doc->endPage();
405 } 421 }
406 doc->close(); 422 if (!doc->close()) {
423 return "SkDocument::close() returned false";
424 }
407 dst->flush(); 425 dst->flush();
408 return ""; 426 return "";
409 } 427 }
410 428
411 PDFSink::PDFSink() {} 429 PDFSink::PDFSink() {}
412 430
413 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { 431 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
414 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst)); 432 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
415 if (!doc) { 433 if (!doc) {
416 return "SkDocument::CreatePDF() returned NULL"; 434 return "SkDocument::CreatePDF() returned NULL";
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 canvas->drawPicture(pic); 713 canvas->drawPicture(pic);
696 return ""; 714 return "";
697 } 715 }
698 SkISize size() const override { return fSrc.size(); } 716 SkISize size() const override { return fSrc.size(); }
699 Name name() const override { sk_throw(); return ""; } // No one should be calling this. 717 Name name() const override { sk_throw(); return ""; } // No one should be calling this.
700 } proxy(src); 718 } proxy(src);
701 return fSink->draw(proxy, bitmap, stream, log); 719 return fSink->draw(proxy, bitmap, stream, log);
702 } 720 }
703 721
704 } // namespace DM 722 } // namespace DM
OLDNEW
« 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