OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #ifndef SkPDFDevice_DEFINED | 8 #ifndef SkPDFDevice_DEFINED |
9 #define SkPDFDevice_DEFINED | 9 #define SkPDFDevice_DEFINED |
10 | 10 |
11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkClipStack.h" | 13 #include "SkClipStack.h" |
14 #include "SkData.h" | 14 #include "SkData.h" |
15 #include "SkDevice.h" | 15 #include "SkDevice.h" |
16 #include "SkPaint.h" | 16 #include "SkPaint.h" |
17 #include "SkPath.h" | 17 #include "SkPath.h" |
18 #include "SkPicture.h" | 18 #include "SkPicture.h" |
19 #include "SkRect.h" | 19 #include "SkRect.h" |
20 #include "SkRefCnt.h" | 20 #include "SkRefCnt.h" |
21 #include "SkStream.h" | 21 #include "SkStream.h" |
22 #include "SkTDArray.h" | 22 #include "SkTDArray.h" |
23 #include "SkTemplates.h" | 23 #include "SkTemplates.h" |
24 | 24 |
25 class SkPDFArray; | 25 class SkPDFArray; |
26 class SkPDFCanon; | 26 class SkPDFCanon; |
27 class SkPDFDevice; | 27 class SkPDFDevice; |
| 28 class SkPDFDocument; |
28 class SkPDFDict; | 29 class SkPDFDict; |
29 class SkPDFFont; | 30 class SkPDFFont; |
30 class SkPDFFormXObject; | 31 class SkPDFFormXObject; |
31 class SkPDFGlyphSetMap; | 32 class SkPDFGlyphSetMap; |
32 class SkPDFGraphicState; | 33 class SkPDFGraphicState; |
33 class SkPDFObject; | 34 class SkPDFObject; |
34 class SkPDFShader; | 35 class SkPDFShader; |
35 class SkPDFStream; | 36 class SkPDFStream; |
36 class SkRRect; | 37 class SkRRect; |
37 | 38 |
(...skipping 14 matching lines...) Expand all Loading... |
52 * 1 point == 127/360 mm == 1/72 inch | 53 * 1 point == 127/360 mm == 1/72 inch |
53 * @param rasterDpi the DPI at which features without native PDF | 54 * @param rasterDpi the DPI at which features without native PDF |
54 * support will be rasterized (e.g. draw image with | 55 * support will be rasterized (e.g. draw image with |
55 * perspective, draw text with perspective, ...). A | 56 * perspective, draw text with perspective, ...). A |
56 * larger DPI would create a PDF that reflects the | 57 * larger DPI would create a PDF that reflects the |
57 * original intent with better fidelity, but it can make | 58 * original intent with better fidelity, but it can make |
58 * for larger PDF files too, which would use more memory | 59 * for larger PDF files too, which would use more memory |
59 * while rendering, and it would be slower to be processed | 60 * while rendering, and it would be slower to be processed |
60 * or sent online or to printer. A good choice is | 61 * or sent online or to printer. A good choice is |
61 * SK_ScalarDefaultRasterDPI(72.0f). | 62 * SK_ScalarDefaultRasterDPI(72.0f). |
62 * @param SkPDFCanon. Should be non-null, and shared by all | 63 * @param SkPDFDocument. A non-null pointer back to the |
63 * devices in a document. | 64 * document. The document is repsonsible for |
| 65 * de-duplicating across pages (via the SkPDFCanon) and |
| 66 * for early serializing of large immutable objects, such |
| 67 * as images (via SkPDFDocument::serialize()). |
64 */ | 68 */ |
65 static SkPDFDevice* Create(SkISize pageSize, | 69 static SkPDFDevice* Create(SkISize pageSize, |
66 SkScalar rasterDpi, | 70 SkScalar rasterDpi, |
67 SkPDFCanon* canon) { | 71 SkPDFDocument* doc) { |
68 return new SkPDFDevice(pageSize, rasterDpi, canon, true); | 72 return new SkPDFDevice(pageSize, rasterDpi, doc, true); |
69 } | 73 } |
70 | 74 |
71 /** Create a PDF drawing context without fipping the y-axis. */ | 75 /** Create a PDF drawing context without fipping the y-axis. */ |
72 static SkPDFDevice* CreateUnflipped(SkISize pageSize, | 76 static SkPDFDevice* CreateUnflipped(SkISize pageSize, |
73 SkScalar rasterDpi, | 77 SkScalar rasterDpi, |
74 SkPDFCanon* canon) { | 78 SkPDFDocument* doc) { |
75 return new SkPDFDevice(pageSize, rasterDpi, canon, false); | 79 return new SkPDFDevice(pageSize, rasterDpi, doc, false); |
76 } | 80 } |
77 | 81 |
78 virtual ~SkPDFDevice(); | 82 virtual ~SkPDFDevice(); |
79 | 83 |
80 /** These are called inside the per-device-layer loop for each draw call. | 84 /** These are called inside the per-device-layer loop for each draw call. |
81 When these are called, we have already applied any saveLayer operations, | 85 When these are called, we have already applied any saveLayer operations, |
82 and are handling any looping from the paint, and any effects from the | 86 and are handling any looping from the paint, and any effects from the |
83 DrawFilter. | 87 DrawFilter. |
84 */ | 88 */ |
85 void drawPaint(const SkDraw&, const SkPaint& paint) override; | 89 void drawPaint(const SkDraw&, const SkPaint& paint) override; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return fInitialTransform; | 181 return fInitialTransform; |
178 } | 182 } |
179 | 183 |
180 /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font | 184 /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font |
181 * that shows on this device. | 185 * that shows on this device. |
182 */ | 186 */ |
183 const SkPDFGlyphSetMap& getFontGlyphUsage() const { | 187 const SkPDFGlyphSetMap& getFontGlyphUsage() const { |
184 return *(fFontGlyphUsage.get()); | 188 return *(fFontGlyphUsage.get()); |
185 } | 189 } |
186 | 190 |
187 SkPDFCanon* getCanon() const { return fCanon; } | 191 SkPDFCanon* getCanon() const; |
188 | 192 |
189 protected: | 193 protected: |
190 const SkBitmap& onAccessBitmap() override { | 194 const SkBitmap& onAccessBitmap() override { |
191 return fLegacyBitmap; | 195 return fLegacyBitmap; |
192 } | 196 } |
193 | 197 |
194 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override; | 198 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
195 | 199 |
196 void drawAnnotation(const SkDraw&, const SkRect&, const char key[], SkData*
value) override; | 200 void drawAnnotation(const SkDraw&, const SkRect&, const char key[], SkData*
value) override; |
197 | 201 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // Accessor and setter functions based on the current DrawingArea. | 258 // Accessor and setter functions based on the current DrawingArea. |
255 SkAutoTDelete<ContentEntry>* getContentEntries(); | 259 SkAutoTDelete<ContentEntry>* getContentEntries(); |
256 | 260 |
257 // Glyph ids used for each font on this device. | 261 // Glyph ids used for each font on this device. |
258 SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage; | 262 SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage; |
259 | 263 |
260 SkScalar fRasterDpi; | 264 SkScalar fRasterDpi; |
261 | 265 |
262 SkBitmap fLegacyBitmap; | 266 SkBitmap fLegacyBitmap; |
263 | 267 |
264 SkPDFCanon* fCanon; // Owned by SkDocument_PDF | 268 SkPDFDocument* fDocument; |
265 //////////////////////////////////////////////////////////////////////////// | 269 //////////////////////////////////////////////////////////////////////////// |
266 | 270 |
267 SkPDFDevice(SkISize pageSize, | 271 SkPDFDevice(SkISize pageSize, |
268 SkScalar rasterDpi, | 272 SkScalar rasterDpi, |
269 SkPDFCanon* canon, | 273 SkPDFDocument* doc, |
270 bool flip); | 274 bool flip); |
271 | 275 |
272 ContentEntry* getLastContentEntry(); | 276 ContentEntry* getLastContentEntry(); |
273 void setLastContentEntry(ContentEntry* contentEntry); | 277 void setLastContentEntry(ContentEntry* contentEntry); |
274 | 278 |
275 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; | 279 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; |
276 | 280 |
277 void init(); | 281 void init(); |
278 void cleanUp(bool clearFontUsage); | 282 void cleanUp(bool clearFontUsage); |
279 SkPDFFormXObject* createFormXObjectFromDevice(); | 283 SkPDFFormXObject* createFormXObjectFromDevice(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 337 |
334 typedef SkBaseDevice INHERITED; | 338 typedef SkBaseDevice INHERITED; |
335 | 339 |
336 // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to
create | 340 // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to
create |
337 // an SkPDFDevice | 341 // an SkPDFDevice |
338 //friend class SkDocument_PDF; | 342 //friend class SkDocument_PDF; |
339 //friend class SkPDFImageShader; | 343 //friend class SkPDFImageShader; |
340 }; | 344 }; |
341 | 345 |
342 #endif | 346 #endif |
OLD | NEW |