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

Unified Diff: dm/DMSrcSink.cpp

Issue 2023593002: SkMultiPictureDocument & SkMultiPictureDocumentReader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-06-02 (Thursday) 09:23:50 EDT Created 4 years, 7 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 | « dm/DMSrcSink.h ('k') | gyp/dm.gypi » ('j') | 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 356416035baaa809609d77c02b31c677b64e0989..a1be0979fda883fe7b382ab0cfc19673f081a363 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1007,6 +1007,41 @@ Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+MSKPSrc::MSKPSrc(Path path) : fPath(path) {
+ std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str()));
+ (void)fReader.init(stream.get());
+}
+
+int MSKPSrc::pageCount() const { return fReader.pageCount(); }
+
+SkISize MSKPSrc::size() const { return this->size(0); }
+SkISize MSKPSrc::size(int i) const { return fReader.pageSize(i).toCeil(); }
+
+Error MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); }
+Error MSKPSrc::draw(int i, SkCanvas* canvas) const {
+ std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str()));
+ if (!stream) {
+ return SkStringPrintf("Unable to open file: %s", fPath.c_str());
+ }
+ if (fReader.pageCount() == 0) {
+ return SkStringPrintf("Unable to parse MultiPictureDocument file: %s", fPath.c_str());
+ }
+ if (i >= fReader.pageCount()) {
+ return SkStringPrintf("MultiPictureDocument page number out of range: %d", i);
+ }
+ sk_sp<SkPicture> page = fReader.readPage(stream.get(), i);
+ if (!page) {
+ return SkStringPrintf("SkMultiPictureDocumentReader failed on page %d: %s",
+ i, fPath.c_str());
+ }
+ canvas->drawPicture(page);
+ return "";
+}
+
+Name MSKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
+
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const {
SkAutoTDelete<SkCanvas> canvas(SkCreateNullCanvas());
return src.draw(canvas);
@@ -1099,44 +1134,15 @@ static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
return "Source has empty dimensions";
}
SkASSERT(doc);
- int width = src.size().width(),
- height = src.size().height();
-
- if (FLAGS_multiPage) {
- // Print the given DM:Src to a document, breaking on 8.5x11 pages.
- 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 nullptr";
- }
- canvas->clipRect(letter);
- canvas->translate(-letter.width() * x, -letter.height() * y);
- Error err = src.draw(canvas);
- if (!err.isEmpty()) {
- return err;
- }
- doc->endPage();
- }
- }
- } else {
+ int pageCount = src.pageCount();
+ for (int i = 0; i < pageCount; ++i) {
+ int width = src.size(i).width(), height = src.size(i).height();
SkCanvas* canvas =
doc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
if (!canvas) {
return "SkDocument::beginPage(w,h) returned nullptr";
}
- Error err = src.draw(canvas);
+ Error err = src.draw(i, canvas);
if (!err.isEmpty()) {
return err;
}
« no previous file with comments | « dm/DMSrcSink.h ('k') | gyp/dm.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698