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

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: formatting,consts 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 "SkPictureData.h" 7 #include "SkPictureData.h"
8 #include "SkPictureRecorder.h" 8 #include "SkPictureRecorder.h"
9 #include "SkRandom.h" 9 #include "SkRandom.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 factory.abandonContexts(); 173 factory.abandonContexts();
174 } 174 }
175 return ""; 175 return "";
176 } 176 }
177 177
178 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 178 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
179 179
180 PDFSink::PDFSink() {} 180 PDFSink::PDFSink() {}
181 181
182 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst) const { 182 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst) const {
183 SkSize size; 183 // Print the given DM:Src to a PDF, breaking on 8.5x11 pages.
184 size = src.size();
185 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst)); 184 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
186 SkCanvas* canvas = doc->beginPage(size.width(), size.height());
187 185
188 Error err = src.draw(canvas); 186 int width = src.size().width(),
189 if (!err.isEmpty()) { 187 height = src.size().height();
190 return err; 188
189 const int kLetterWidth = 612, // 8.5 * 72
190 kLetterHeight = 792; // 11 * 72
191 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
192 SkIntToScalar(kLetterHeight));
193
194 int xPages = ((width - 1) / kLetterWidth) + 1;
195 int yPages = ((height - 1) / kLetterHeight) + 1;
196
197 for (int y = 0; y < yPages; ++y) {
198 for (int x = 0; x < xPages; ++x) {
199 int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
200 int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
201 SkCanvas* canvas =
202 doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
203 canvas->clipRect(letter);
204 canvas->translate(-letter.width() * x, -letter.height() * y);
205 Error err = src.draw(canvas);
206 if (!err.isEmpty()) {
207 return err;
208 }
209 doc->endPage();
210 }
191 } 211 }
192 canvas->flush();
193 doc->endPage();
194 doc->close(); 212 doc->close();
213 dst->flush();
195 return ""; 214 return "";
196 } 215 }
197 216
198 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 217 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
199 218
200 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {} 219 RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {}
201 220
202 Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const { 221 Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*) const {
203 const SkISize size = limit_raster_dimensions(src.size()); 222 const SkISize size = limit_raster_dimensions(src.size());
204 // If there's an appropriate alpha type for this color type, use it, otherwi se use premul. 223 // 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
352 surfaces.unrefAll(); 371 surfaces.unrefAll();
353 return ""; 372 return "";
354 } 373 }
355 SkISize size() const SK_OVERRIDE { return fSize; } 374 SkISize size() const SK_OVERRIDE { return fSize; }
356 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 375 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
357 } proxy(fW, fH, pic, src.size()); 376 } proxy(fW, fH, pic, src.size());
358 return fSink->draw(proxy, bitmap, stream); 377 return fSink->draw(proxy, bitmap, stream);
359 } 378 }
360 379
361 } // namespace DM 380 } // 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