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

Side by Side Diff: src/doc/SkDocument_PDF.cpp

Issue 32233003: Add DPI stettings to SkDocument::CreatePDF(). Tests will be added in a future cl, once DPI will be … (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add comments Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkDocument.h" 8 #include "SkDocument.h"
9 #include "SkPDFDocument.h" 9 #include "SkPDFDocument.h"
10 #include "SkPDFDeviceFlattener.h" 10 #include "SkPDFDeviceFlattener.h"
11 11
12 class SkDocument_PDF : public SkDocument { 12 class SkDocument_PDF : public SkDocument {
13 public: 13 public:
14 SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*), 14 SkDocument_PDF(SkWStream* stream, void (*doneProc)(SkWStream*),
15 SkPicture::EncodeBitmap encoder) 15 SkPicture::EncodeBitmap encoder,
16 SkScalar rasterDpi)
16 : SkDocument(stream, doneProc) 17 : SkDocument(stream, doneProc)
17 , fEncoder(encoder) { 18 , fEncoder(encoder)
19 , fRasterDpi(rasterDpi) {
18 fDoc = SkNEW(SkPDFDocument); 20 fDoc = SkNEW(SkPDFDocument);
19 fCanvas = NULL; 21 fCanvas = NULL;
20 fDevice = NULL; 22 fDevice = NULL;
21 } 23 }
22 24
23 virtual ~SkDocument_PDF() { 25 virtual ~SkDocument_PDF() {
24 // subclasses must call close() in their destructors 26 // subclasses must call close() in their destructors
25 this->close(); 27 this->close();
26 } 28 }
27 29
28 protected: 30 protected:
29 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, 31 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
30 const SkRect& trimBox) SK_OVERRIDE { 32 const SkRect& trimBox) SK_OVERRIDE {
31 SkASSERT(NULL == fCanvas); 33 SkASSERT(NULL == fCanvas);
32 SkASSERT(NULL == fDevice); 34 SkASSERT(NULL == fDevice);
33 35
34 SkSize mediaBoxSize; 36 SkSize mediaBoxSize;
35 mediaBoxSize.set(width, height); 37 mediaBoxSize.set(width, height);
36 38
37 fDevice = SkNEW_ARGS(SkPDFDeviceFlattener, (mediaBoxSize, &trimBox)); 39 fDevice = SkNEW_ARGS(SkPDFDeviceFlattener, (mediaBoxSize, &trimBox));
38 if (fEncoder) { 40 if (fEncoder) {
39 fDevice->setDCTEncoder(fEncoder); 41 fDevice->setDCTEncoder(fEncoder);
40 } 42 }
43 if (fRasterDpi != 0) {
44 fDevice->setRasterDpi(fRasterDpi);
45 }
41 fCanvas = SkNEW_ARGS(SkCanvas, (fDevice)); 46 fCanvas = SkNEW_ARGS(SkCanvas, (fDevice));
42 return fCanvas; 47 return fCanvas;
43 } 48 }
44 49
45 virtual void onEndPage() SK_OVERRIDE { 50 virtual void onEndPage() SK_OVERRIDE {
46 SkASSERT(fCanvas); 51 SkASSERT(fCanvas);
47 SkASSERT(fDevice); 52 SkASSERT(fDevice);
48 53
49 fCanvas->flush(); 54 fCanvas->flush();
50 fDoc->appendPage(fDevice); 55 fDoc->appendPage(fDevice);
(...skipping 18 matching lines...) Expand all
69 virtual void onAbort() SK_OVERRIDE { 74 virtual void onAbort() SK_OVERRIDE {
70 SkDELETE(fDoc); 75 SkDELETE(fDoc);
71 fDoc = NULL; 76 fDoc = NULL;
72 } 77 }
73 78
74 private: 79 private:
75 SkPDFDocument* fDoc; 80 SkPDFDocument* fDoc;
76 SkPDFDeviceFlattener* fDevice; 81 SkPDFDeviceFlattener* fDevice;
77 SkCanvas* fCanvas; 82 SkCanvas* fCanvas;
78 SkPicture::EncodeBitmap fEncoder; 83 SkPicture::EncodeBitmap fEncoder;
84 SkScalar fRasterDpi;
79 }; 85 };
80 86
81 /////////////////////////////////////////////////////////////////////////////// 87 ///////////////////////////////////////////////////////////////////////////////
82 88
83 SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*), 89 SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*),
84 SkPicture::EncodeBitmap enc) { 90 SkPicture::EncodeBitmap enc,
85 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc)) : NULL; 91 SkScalar dpi) {
92 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc, dpi)) : NULL;
86 } 93 }
87 94
88 static void delete_wstream(SkWStream* stream) { 95 static void delete_wstream(SkWStream* stream) {
89 SkDELETE(stream); 96 SkDELETE(stream);
90 } 97 }
91 98
92 SkDocument* SkDocument::CreatePDF(const char path[], SkPicture::EncodeBitmap enc ) { 99 SkDocument* SkDocument::CreatePDF(const char path[],
100 SkPicture::EncodeBitmap enc,
101 SkScalar dpi) {
93 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); 102 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path));
94 if (!stream->isValid()) { 103 if (!stream->isValid()) {
95 SkDELETE(stream); 104 SkDELETE(stream);
96 return NULL; 105 return NULL;
97 } 106 }
98 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc)); 107 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi));
99 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698