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

Side by Side 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, 10 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 #include "DMSrcSink.h" 1 #include "DMSrcSink.h"
2 #include "SamplePipeControllers.h" 2 #include "SamplePipeControllers.h"
3 #include "SkCommonFlags.h" 3 #include "SkCommonFlags.h"
4 #include "SkDocument.h" 4 #include "SkDocument.h"
5 #include "SkMultiPictureDraw.h" 5 #include "SkMultiPictureDraw.h"
6 #include "SkOSFile.h" 6 #include "SkOSFile.h"
7 #include "SkPictureRecorder.h" 7 #include "SkPictureRecorder.h"
8 #include "SkRandom.h" 8 #include "SkRandom.h"
9 #include "SkStream.h" 9 #include "SkStream.h"
10 10
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 Name ImageSrc::name() const { 94 Name ImageSrc::name() const {
95 Name name = SkOSPath::Basename(fPath.c_str()); 95 Name name = SkOSPath::Basename(fPath.c_str());
96 if (fSubsets > 0) { 96 if (fSubsets > 0) {
97 name.appendf("-%d-subsets", fSubsets); 97 name.appendf("-%d-subsets", fSubsets);
98 } 98 }
99 return name; 99 return name;
100 } 100 }
101 101
102 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 102 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
103 103
104 static const SkRect kSKPViewport = {0,0, 1000,1000}; 104 static const SkRect kSKPViewport = {0,0, 1000,1000};
mtklein 2015/01/28 16:08:30 I suspect a change like this will require us to re
105 105
106 SKPSrc::SKPSrc(SkString path) : fPath(path) {} 106 SKPSrc::SKPSrc(SkString path) : fPath(path) {}
107 107
108 Error SKPSrc::draw(SkCanvas* canvas) const { 108 Error SKPSrc::draw(SkCanvas* canvas) const {
109 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); 109 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
110 if (!stream) { 110 if (!stream) {
111 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 111 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
112 } 112 }
113 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); 113 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream));
114 if (!pic) { 114 if (!pic) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 factory.abandonContexts(); 166 factory.abandonContexts();
167 } 167 }
168 return ""; 168 return "";
169 } 169 }
170 170
171 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 171 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
172 172
173 PDFSink::PDFSink() {} 173 PDFSink::PDFSink() {}
174 174
175 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst) const { 175 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst) const {
176 SkSize size; 176 // Print the given DM:Src to a PDF, breaking on 8.5x11 pages.
177 size = src.size();
178 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst)); 177 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
179 SkCanvas* canvas = doc->beginPage(size.width(), size.height());
180 178
181 Error err = src.draw(canvas); 179 int width = src.size().width();
182 if (!err.isEmpty()) { 180 int height = src.size().height();
183 return err; 181
182 const int kLetterWidth = 612; // 8.5 * 72
183 const int kLetterHeight = 792; // 11 * 72
184 const SkScalar kLetterWidthScalar = SkIntToScalar(kLetterWidth);
mtklein 2015/01/28 16:28:26 I think this would be more readable with fewer con
185 const SkScalar kLetterHeightScalar = SkIntToScalar(kLetterHeight);
186 SkRect letterRect = SkRect::MakeWH(kLetterWidthScalar, kLetterHeightScalar);
187
188 int xPages = ((width - 1) / kLetterWidth) + 1;
189 int yPages = ((height - 1) / kLetterHeight) + 1;
190
191 for (int y = 0; y < yPages; ++y) {
192 for (int x = 0; x < xPages; ++x) {
193 int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
194 int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
195 SkCanvas* canvas = doc->beginPage(w, h);
196 canvas->clipRect(letterRect);
197 canvas->translate(-kLetterWidthScalar * x,
198 -kLetterHeightScalar * y);
199 Error err = src.draw(canvas);
200 if (!err.isEmpty()) {
201 return err;
202 }
203 doc->endPage();
204 }
184 } 205 }
185 canvas->flush();
186 doc->endPage();
187 doc->close(); 206 doc->close();
207 dst->flush();
188 return ""; 208 return "";
189 } 209 }
190 210
191 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 211 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
192 212
193 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {} 213 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {}
194 214
195 Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { 215 Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const {
196 const SkISize size = src.size(); 216 const SkISize size = src.size();
197 // If there's an appropriate alpha type for this color type, use it, otherwi se use premul. 217 // If there's an appropriate alpha type for this color type, use it, otherwi se use premul.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 surfaces.unrefAll(); 365 surfaces.unrefAll();
346 return ""; 366 return "";
347 } 367 }
348 SkISize size() const SK_OVERRIDE { return fSize; } 368 SkISize size() const SK_OVERRIDE { return fSize; }
349 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 369 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
350 } proxy(fW, fH, pic, src.size()); 370 } proxy(fW, fH, pic, src.size());
351 return fSink->draw(proxy, bitmap, stream); 371 return fSink->draw(proxy, bitmap, stream);
352 } 372 }
353 373
354 } // namespace DM 374 } // 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