OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkPDFDevice_DEFINED | 10 #ifndef SkPDFDevice_DEFINED |
11 #define SkPDFDevice_DEFINED | 11 #define SkPDFDevice_DEFINED |
12 | 12 |
13 #include "SkDevice.h" | 13 #include "SkDevice.h" |
14 #include "SkBitmap.h" | 14 #include "SkBitmap.h" |
15 #include "SkCanvas.h" | 15 #include "SkCanvas.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 SkPDFDevice; | 27 class SkPDFDevice; |
27 class SkPDFDict; | 28 class SkPDFDict; |
28 class SkPDFFont; | 29 class SkPDFFont; |
29 class SkPDFFormXObject; | 30 class SkPDFFormXObject; |
30 class SkPDFGlyphSetMap; | 31 class SkPDFGlyphSetMap; |
31 class SkPDFGraphicState; | 32 class SkPDFGraphicState; |
32 class SkPDFObject; | 33 class SkPDFObject; |
33 class SkPDFResourceDict; | 34 class SkPDFResourceDict; |
34 class SkPDFShader; | 35 class SkPDFShader; |
35 class SkPDFStream; | 36 class SkPDFStream; |
36 class SkRRect; | 37 class SkRRect; |
37 template <typename T> class SkTSet; | 38 template <typename T> class SkTSet; |
38 | 39 |
39 // Private classes. | 40 // Private classes. |
40 struct ContentEntry; | 41 struct ContentEntry; |
41 struct GraphicStateEntry; | 42 struct GraphicStateEntry; |
42 struct NamedDestination; | 43 struct NamedDestination; |
43 | 44 |
44 /** \class SkPDFDevice | 45 /** \class SkPDFDevice |
45 | 46 |
46 The drawing context for the PDF backend. | 47 The drawing context for the PDF backend. |
47 */ | 48 */ |
48 class SkPDFDevice : public SkBaseDevice { | 49 class SkPDFDevice : public SkBaseDevice { |
49 public: | 50 public: |
50 /** Create a PDF drawing context with the given width and height. | 51 /** Create a PDF drawing context. SkPDFDevice applies a |
51 * 72 points/in means letter paper is 612x792. | 52 * scale-and-translate transform to move the origin from the |
52 * @param pageSize Page size in points. | 53 * bottom left (PDF default) to the top left (Skia default). |
53 * @param contentSize The content size of the page in points. This will be | 54 * @param pageSize Page size in point units. |
54 * combined with the initial transform to determine the drawing area | 55 * 1 point == 127/360 mm == 1/72 inch |
55 * (as reported by the width and height methods). Anything outside | 56 * @param rasterDpi the DPI at which features without native PDF |
56 * of the drawing area will be clipped. | 57 * support will be rasterized (e.g. draw image with |
57 * @param initialTransform The initial transform to apply to the page. | 58 * perspective, draw text with perspective, ...). A |
58 * This may be useful to, for example, move the origin in and | 59 * larger DPI would create a PDF that reflects the |
59 * over a bit to account for a margin, scale the canvas, | 60 * original intent with better fidelity, but it can make |
60 * or apply a rotation. Note1: the SkPDFDevice also applies | 61 * for larger PDF files too, which would use more memory |
61 * a scale+translate transform to move the origin from the | 62 * while rendering, and it would be slower to be processed |
62 * bottom left (PDF default) to the top left. Note2: drawDevice | 63 * or sent online or to printer. A good choice is |
63 * (used by layer restore) draws the device after this initial | 64 * SK_ScalarDefaultRasterDPI(72.0f). |
64 * transform is applied, so the PDF device does an | 65 * @param SkPDFCanon. Should be non-null, and shared by all |
65 * inverse scale+translate to accommodate the one that SkPDFDevice | 66 * devices in a document. |
66 * always does. | |
67 */ | 67 */ |
68 // Deprecated, please use SkDocument::CreatePdf() instead. | 68 static SkPDFDevice* Create(SkISize pageSize, |
69 SK_API SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, | 69 SkScalar rasterDpi, |
70 const SkMatrix& initialTransform); | 70 SkPDFCanon* canon) { |
71 SK_API virtual ~SkPDFDevice(); | 71 return SkNEW_ARGS(SkPDFDevice, (pageSize, rasterDpi, canon, true)); |
| 72 } |
| 73 |
| 74 /** Create a PDF drawing context without fipping the y-axis. */ |
| 75 static SkPDFDevice* CreateUnflipped(SkISize pageSize, |
| 76 SkScalar rasterDpi, |
| 77 SkPDFCanon* canon) { |
| 78 return SkNEW_ARGS(SkPDFDevice, (pageSize, rasterDpi, canon, false)); |
| 79 } |
| 80 |
| 81 virtual ~SkPDFDevice(); |
72 | 82 |
73 /** These are called inside the per-device-layer loop for each draw call. | 83 /** These are called inside the per-device-layer loop for each draw call. |
74 When these are called, we have already applied any saveLayer operations, | 84 When these are called, we have already applied any saveLayer operations, |
75 and are handling any looping from the paint, and any effects from the | 85 and are handling any looping from the paint, and any effects from the |
76 DrawFilter. | 86 DrawFilter. |
77 */ | 87 */ |
78 void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; | 88 void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; |
79 void drawPoints(const SkDraw&, SkCanvas::PointMode mode, | 89 void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
80 size_t count, const SkPoint[], | 90 size_t count, const SkPoint[], |
81 const SkPaint& paint) SK_OVERRIDE; | 91 const SkPaint& paint) SK_OVERRIDE; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return fInitialTransform; | 176 return fInitialTransform; |
167 } | 177 } |
168 | 178 |
169 /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font | 179 /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font |
170 * that shows on this device. | 180 * that shows on this device. |
171 */ | 181 */ |
172 const SkPDFGlyphSetMap& getFontGlyphUsage() const { | 182 const SkPDFGlyphSetMap& getFontGlyphUsage() const { |
173 return *(fFontGlyphUsage.get()); | 183 return *(fFontGlyphUsage.get()); |
174 } | 184 } |
175 | 185 |
176 | |
177 /** | |
178 * rasterDpi - the DPI at which features without native PDF support | |
179 * will be rasterized (e.g. draw image with perspective, | |
180 * draw text with perspective, ...) | |
181 * A larger DPI would create a PDF that reflects the original | |
182 * intent with better fidelity, but it can make for larger | |
183 * PDF files too, which would use more memory while rendering, | |
184 * and it would be slower to be processed or sent online or | |
185 * to printer. | |
186 */ | |
187 void setRasterDpi(SkScalar rasterDpi) { | |
188 fRasterDpi = rasterDpi; | |
189 } | |
190 | |
191 protected: | 186 protected: |
192 const SkBitmap& onAccessBitmap() SK_OVERRIDE { | 187 const SkBitmap& onAccessBitmap() SK_OVERRIDE { |
193 return fLegacyBitmap; | 188 return fLegacyBitmap; |
194 } | 189 } |
195 | 190 |
196 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE
; | 191 SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE
; |
197 | 192 |
198 private: | 193 private: |
199 // TODO(vandebo): push most of SkPDFDevice's state into a core object in | 194 // TODO(vandebo): push most of SkPDFDevice's state into a core object in |
200 // order to get the right access levels without using friend. | 195 // order to get the right access levels without using friend. |
(...skipping 16 matching lines...) Expand all Loading... |
217 SkAutoTDelete<ContentEntry> fContentEntries; | 212 SkAutoTDelete<ContentEntry> fContentEntries; |
218 ContentEntry* fLastContentEntry; | 213 ContentEntry* fLastContentEntry; |
219 SkAutoTDelete<ContentEntry> fMarginContentEntries; | 214 SkAutoTDelete<ContentEntry> fMarginContentEntries; |
220 ContentEntry* fLastMarginContentEntry; | 215 ContentEntry* fLastMarginContentEntry; |
221 DrawingArea fDrawingArea; | 216 DrawingArea fDrawingArea; |
222 | 217 |
223 const SkClipStack* fClipStack; | 218 const SkClipStack* fClipStack; |
224 | 219 |
225 // Accessor and setter functions based on the current DrawingArea. | 220 // Accessor and setter functions based on the current DrawingArea. |
226 SkAutoTDelete<ContentEntry>* getContentEntries(); | 221 SkAutoTDelete<ContentEntry>* getContentEntries(); |
227 ContentEntry* getLastContentEntry(); | |
228 void setLastContentEntry(ContentEntry* contentEntry); | |
229 | 222 |
230 // Glyph ids used for each font on this device. | 223 // Glyph ids used for each font on this device. |
231 SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage; | 224 SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage; |
232 | 225 |
233 SkScalar fRasterDpi; | 226 SkScalar fRasterDpi; |
234 | 227 |
235 SkBitmap fLegacyBitmap; | 228 SkBitmap fLegacyBitmap; |
236 | 229 |
237 SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, | 230 SkPDFCanon* fCanon; // Owned by SkDocument_PDF |
238 const SkRegion& existingClipRegion); | 231 //////////////////////////////////////////////////////////////////////////// |
| 232 |
| 233 SkPDFDevice(SkISize pageSize, |
| 234 SkScalar rasterDpi, |
| 235 SkPDFCanon* canon, |
| 236 bool flip); |
| 237 |
| 238 ContentEntry* getLastContentEntry(); |
| 239 void setLastContentEntry(ContentEntry* contentEntry); |
239 | 240 |
240 // override from SkBaseDevice | 241 // override from SkBaseDevice |
241 SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE; | 242 SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE; |
242 | 243 |
243 void init(); | 244 void init(); |
244 void cleanUp(bool clearFontUsage); | 245 void cleanUp(bool clearFontUsage); |
245 SkPDFFormXObject* createFormXObjectFromDevice(); | 246 SkPDFFormXObject* createFormXObjectFromDevice(); |
246 | 247 |
247 void drawFormXObjectWithMask(int xObjectIndex, | 248 void drawFormXObjectWithMask(int xObjectIndex, |
248 SkPDFFormXObject* mask, | 249 SkPDFFormXObject* mask, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 312 |
312 typedef SkBaseDevice INHERITED; | 313 typedef SkBaseDevice INHERITED; |
313 | 314 |
314 // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to
create | 315 // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to
create |
315 // an SkPDFDevice | 316 // an SkPDFDevice |
316 //friend class SkDocument_PDF; | 317 //friend class SkDocument_PDF; |
317 //friend class SkPDFImageShader; | 318 //friend class SkPDFImageShader; |
318 }; | 319 }; |
319 | 320 |
320 #endif | 321 #endif |
OLD | NEW |