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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 963953002: XPS, DM: add SkDocument::CreateXPS (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix conics Created 5 years, 9 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
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 "SkError.h" 5 #include "SkError.h"
6 #include "SkMultiPictureDraw.h" 6 #include "SkMultiPictureDraw.h"
7 #include "SkNullCanvas.h" 7 #include "SkNullCanvas.h"
8 #include "SkOSFile.h" 8 #include "SkOSFile.h"
9 #include "SkPictureRecorder.h" 9 #include "SkPictureRecorder.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 dst->allocPixels(info); 187 dst->allocPixels(info);
188 canvas->readPixels(dst, 0, 0); 188 canvas->readPixels(dst, 0, 0);
189 if (FLAGS_abandonGpuContext) { 189 if (FLAGS_abandonGpuContext) {
190 factory.abandonContexts(); 190 factory.abandonContexts();
191 } 191 }
192 return ""; 192 return "";
193 } 193 }
194 194
195 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 195 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
196 196
197 PDFSink::PDFSink() {} 197 static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
198 198 // Print the given DM:Src to a document, breaking on 8.5x11 pages.
199 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
200 // Print the given DM:Src to a PDF, breaking on 8.5x11 pages.
201 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
202
203 int width = src.size().width(), 199 int width = src.size().width(),
204 height = src.size().height(); 200 height = src.size().height();
205 201
206 const int kLetterWidth = 612, // 8.5 * 72 202 const int kLetterWidth = 612, // 8.5 * 72
207 kLetterHeight = 792; // 11 * 72 203 kLetterHeight = 792; // 11 * 72
208 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), 204 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
209 SkIntToScalar(kLetterHeight)); 205 SkIntToScalar(kLetterHeight));
210 206
211 int xPages = ((width - 1) / kLetterWidth) + 1; 207 int xPages = ((width - 1) / kLetterWidth) + 1;
212 int yPages = ((height - 1) / kLetterHeight) + 1; 208 int yPages = ((height - 1) / kLetterHeight) + 1;
(...skipping 11 matching lines...) Expand all
224 return err; 220 return err;
225 } 221 }
226 doc->endPage(); 222 doc->endPage();
227 } 223 }
228 } 224 }
229 doc->close(); 225 doc->close();
230 dst->flush(); 226 dst->flush();
231 return ""; 227 return "";
232 } 228 }
233 229
230 PDFSink::PDFSink() {}
231
232 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
233 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
234 return draw_skdocument(src, doc.get(), dst);
235 }
236
234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 237 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
235 238
239 #ifdef SK_SUPPORT_XPS
240 XPSSink::XPSSink() {}
241
242 Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
243 SkAutoTUnref<SkDocument> doc(SkDocument::CreateXPS(dst));
244 return draw_skdocument(src, doc.get(), dst);
245 }
246 #endif // SK_SUPPORT_XPS
247 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
248
236 SKPSink::SKPSink() {} 249 SKPSink::SKPSink() {}
237 250
238 Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { 251 Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
239 SkSize size; 252 SkSize size;
240 size = src.size(); 253 size = src.size();
241 SkPictureRecorder recorder; 254 SkPictureRecorder recorder;
242 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); 255 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
243 if (!err.isEmpty()) { 256 if (!err.isEmpty()) {
244 return err; 257 return err;
245 } 258 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 surfaces.unrefAll(); 477 surfaces.unrefAll();
465 return ""; 478 return "";
466 } 479 }
467 SkISize size() const SK_OVERRIDE { return fSize; } 480 SkISize size() const SK_OVERRIDE { return fSize; }
468 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 481 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
469 } proxy(fW, fH, pic, src.size()); 482 } proxy(fW, fH, pic, src.size());
470 return fSink->draw(proxy, bitmap, stream, log); 483 return fSink->draw(proxy, bitmap, stream, log);
471 } 484 }
472 485
473 } // namespace DM 486 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMSrcSink.h ('k') | gyp/dm.gyp » ('j') | include/core/SkDocument.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698