OLD | NEW |
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 "SkPDFDevice.h" | 10 #include "SkPDFDevice.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*,bool), | 14 SkDocument_PDF(SkWStream* stream, |
15 SkPicture::EncodeBitmap encoder, | 15 void (*doneProc)(SkWStream*,bool), |
16 SkScalar rasterDpi) | 16 SkScalar rasterDpi) |
17 : SkDocument(stream, doneProc) | 17 : SkDocument(stream, doneProc) |
18 , fEncoder(encoder) | 18 , fDoc(SkNEW(SkPDFDocument)) |
19 , fRasterDpi(rasterDpi) { | 19 , fDevice(NULL) |
20 fDoc = SkNEW(SkPDFDocument); | 20 , fCanvas(NULL) |
21 fCanvas = NULL; | 21 , fRasterDpi(rasterDpi) {} |
22 fDevice = NULL; | |
23 } | |
24 | 22 |
25 virtual ~SkDocument_PDF() { | 23 virtual ~SkDocument_PDF() { |
26 // subclasses must call close() in their destructors | 24 // subclasses must call close() in their destructors |
27 this->close(); | 25 this->close(); |
28 } | 26 } |
29 | 27 |
30 protected: | 28 protected: |
31 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, | 29 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, |
32 const SkRect& trimBox) SK_OVERRIDE { | 30 const SkRect& trimBox) SK_OVERRIDE { |
33 SkASSERT(NULL == fCanvas); | 31 SkASSERT(NULL == fCanvas); |
34 SkASSERT(NULL == fDevice); | 32 SkASSERT(NULL == fDevice); |
35 | 33 |
36 SkISize mediaBoxSize; | 34 SkISize mediaBoxSize; |
37 mediaBoxSize.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height)); | 35 mediaBoxSize.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height)); |
38 | 36 |
39 fDevice = SkNEW_ARGS(SkPDFDevice, (mediaBoxSize, mediaBoxSize, SkMatrix:
:I())); | 37 fDevice = SkNEW_ARGS(SkPDFDevice, (mediaBoxSize, mediaBoxSize, SkMatrix:
:I())); |
40 if (fEncoder) { | |
41 fDevice->setDCTEncoder(fEncoder); | |
42 } | |
43 if (fRasterDpi != 0) { | 38 if (fRasterDpi != 0) { |
44 fDevice->setRasterDpi(fRasterDpi); | 39 fDevice->setRasterDpi(fRasterDpi); |
45 } | 40 } |
46 fCanvas = SkNEW_ARGS(SkCanvas, (fDevice)); | 41 fCanvas = SkNEW_ARGS(SkCanvas, (fDevice)); |
47 fCanvas->clipRect(trimBox); | 42 fCanvas->clipRect(trimBox); |
48 fCanvas->translate(trimBox.x(), trimBox.y()); | 43 fCanvas->translate(trimBox.x(), trimBox.y()); |
49 return fCanvas; | 44 return fCanvas; |
50 } | 45 } |
51 | 46 |
52 void onEndPage() SK_OVERRIDE { | 47 void onEndPage() SK_OVERRIDE { |
(...skipping 22 matching lines...) Expand all Loading... |
75 | 70 |
76 void onAbort() SK_OVERRIDE { | 71 void onAbort() SK_OVERRIDE { |
77 SkDELETE(fDoc); | 72 SkDELETE(fDoc); |
78 fDoc = NULL; | 73 fDoc = NULL; |
79 } | 74 } |
80 | 75 |
81 private: | 76 private: |
82 SkPDFDocument* fDoc; | 77 SkPDFDocument* fDoc; |
83 SkPDFDevice* fDevice; | 78 SkPDFDevice* fDevice; |
84 SkCanvas* fCanvas; | 79 SkCanvas* fCanvas; |
85 SkPicture::EncodeBitmap fEncoder; | |
86 SkScalar fRasterDpi; | 80 SkScalar fRasterDpi; |
87 }; | 81 }; |
88 | 82 |
89 /////////////////////////////////////////////////////////////////////////////// | 83 /////////////////////////////////////////////////////////////////////////////// |
90 | 84 |
91 SkDocument* SkDocument::CreatePDF(SkWStream* stream, void (*done)(SkWStream*,boo
l), | 85 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { |
92 SkPicture::EncodeBitmap enc, | 86 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, NULL, dpi)) : NULL; |
93 SkScalar dpi) { | |
94 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, done, enc, dpi)) : NULL; | |
95 } | 87 } |
96 | 88 |
97 static void delete_wstream(SkWStream* stream, bool aborted) { | 89 static void delete_wstream(SkWStream* stream, bool aborted) { |
98 SkDELETE(stream); | 90 SkDELETE(stream); |
99 } | 91 } |
100 | 92 |
101 SkDocument* SkDocument::CreatePDF(const char path[], | 93 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
102 SkPicture::EncodeBitmap enc, | |
103 SkScalar dpi) { | |
104 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); | 94 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
105 if (!stream->isValid()) { | 95 if (!stream->isValid()) { |
106 SkDELETE(stream); | 96 SkDELETE(stream); |
107 return NULL; | 97 return NULL; |
108 } | 98 } |
109 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, enc, dpi)); | 99 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); |
110 } | 100 } |
OLD | NEW |