epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 10 | #ifndef SkPDFDevice_DEFINED |
| 11 | #define SkPDFDevice_DEFINED |
| 12 | |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 13 | #include "SkDevice.h" |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 14 | #include "SkBitmap.h" |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 15 | #include "SkCanvas.h" |
vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 16 | #include "SkPaint.h" |
| 17 | #include "SkPath.h" |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 18 | #include "SkPicture.h" |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 19 | #include "SkRect.h" |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 20 | #include "SkRefCnt.h" |
| 21 | #include "SkStream.h" |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 22 | #include "SkTDArray.h" |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 23 | #include "SkTemplates.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 24 | |
| 25 | class SkPDFArray; |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 26 | class SkPDFCanon; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 27 | class SkPDFDevice; |
| 28 | class SkPDFDict; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 29 | class SkPDFFont; |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 30 | class SkPDFFormXObject; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 31 | class SkPDFGlyphSetMap; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 32 | class SkPDFGraphicState; |
| 33 | class SkPDFObject; |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 34 | class SkPDFResourceDict; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 35 | class SkPDFShader; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 36 | class SkPDFStream; |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 37 | class SkRRect; |
edisonn@google.com | a20e42c | 2013-05-31 18:04:20 +0000 | [diff] [blame] | 38 | template <typename T> class SkTSet; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 39 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 40 | // Private classes. |
| 41 | struct ContentEntry; |
| 42 | struct GraphicStateEntry; |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 43 | struct NamedDestination; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 44 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 45 | /** \class SkPDFDevice |
| 46 | |
| 47 | The drawing context for the PDF backend. |
| 48 | */ |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 49 | class SkPDFDevice : public SkBaseDevice { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 50 | public: |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 51 | /** Create a PDF drawing context. SkPDFDevice applies a |
| 52 | * scale-and-translate transform to move the origin from the |
| 53 | * bottom left (PDF default) to the top left (Skia default). |
| 54 | * @param pageSize Page size in point units. |
| 55 | * 1 point == 127/360 mm == 1/72 inch |
| 56 | * @param rasterDpi the DPI at which features without native PDF |
| 57 | * support will be rasterized (e.g. draw image with |
| 58 | * perspective, draw text with perspective, ...). A |
| 59 | * larger DPI would create a PDF that reflects the |
| 60 | * original intent with better fidelity, but it can make |
| 61 | * for larger PDF files too, which would use more memory |
| 62 | * while rendering, and it would be slower to be processed |
| 63 | * or sent online or to printer. A good choice is |
| 64 | * SK_ScalarDefaultRasterDPI(72.0f). |
| 65 | * @param SkPDFCanon. Should be non-null, and shared by all |
| 66 | * devices in a document. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 67 | */ |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 68 | static SkPDFDevice* Create(SkISize pageSize, |
| 69 | SkScalar rasterDpi, |
| 70 | SkPDFCanon* canon) { |
| 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(); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 82 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 83 | /** These are called inside the per-device-layer loop for each draw call. |
| 84 | When these are called, we have already applied any saveLayer operations, |
| 85 | and are handling any looping from the paint, and any effects from the |
| 86 | DrawFilter. |
| 87 | */ |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 88 | void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; |
| 89 | void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
| 90 | size_t count, const SkPoint[], |
| 91 | const SkPaint& paint) SK_OVERRIDE; |
| 92 | void drawRect(const SkDraw&, const SkRect& r, const SkPaint& paint) SK_OVERRIDE; |
| 93 | void drawOval(const SkDraw&, const SkRect& oval, const SkPaint& paint) SK_OVERRIDE; |
| 94 | void drawRRect(const SkDraw&, const SkRRect& rr, const SkPaint& paint) SK_OVERRIDE; |
| 95 | void drawPath(const SkDraw&, const SkPath& origpath, |
| 96 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 97 | bool pathIsMutable) SK_OVERRIDE; |
| 98 | void drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
| 99 | const SkRect* src, const SkRect& dst, |
| 100 | const SkPaint& paint, |
| 101 | SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE; |
| 102 | void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
| 103 | const SkMatrix& matrix, const SkPaint&) SK_OVERRIDE; |
| 104 | void drawSprite(const SkDraw&, const SkBitmap& bitmap, int x, int y, |
| 105 | const SkPaint& paint) SK_OVERRIDE; |
| 106 | void drawText(const SkDraw&, const void* text, size_t len, |
| 107 | SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE; |
| 108 | void drawPosText(const SkDraw&, const void* text, size_t len, |
| 109 | const SkScalar pos[], int scalarsPerPos, |
| 110 | const SkPoint& offset, const SkPaint&) SK_OVERRIDE; |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 111 | void drawVertices(const SkDraw&, SkCanvas::VertexMode, |
| 112 | int vertexCount, const SkPoint verts[], |
| 113 | const SkPoint texs[], const SkColor colors[], |
| 114 | SkXfermode* xmode, const uint16_t indices[], |
| 115 | int indexCount, const SkPaint& paint) SK_OVERRIDE; |
| 116 | void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
| 117 | const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 118 | |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 119 | void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE; |
| 120 | void onDetachFromCanvas() SK_OVERRIDE; |
| 121 | SkImageInfo imageInfo() const SK_OVERRIDE; |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 122 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 123 | enum DrawingArea { |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 124 | kContent_DrawingArea, // Drawing area for the page content. |
| 125 | kMargin_DrawingArea, // Drawing area for the margin content. |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | /** Sets the drawing area for the device. Subsequent draw calls are directed |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 129 | * to the specific drawing area (margin or content). The default drawing |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 130 | * area is the content drawing area. |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 131 | * |
| 132 | * Currently if margin content is drawn and then a complex (for PDF) xfer |
| 133 | * mode is used, like SrcIn, Clear, etc, the margin content will get |
| 134 | * clipped. A simple way to avoid the bug is to always draw the margin |
| 135 | * content last. |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 136 | */ |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 137 | void setDrawingArea(DrawingArea drawingArea); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 138 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 139 | // PDF specific methods. |
| 140 | |
reed@google.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 141 | /** Returns the resource dictionary for this device. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 142 | */ |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 143 | SkPDFResourceDict* getResourceDict(); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 144 | |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 145 | /** Get the fonts used on this device. |
| 146 | */ |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 147 | const SkTDArray<SkPDFFont*>& getFontResources() const; |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 148 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 149 | /** Add our named destinations to the supplied dictionary. |
| 150 | * @param dict Dictionary to add destinations to. |
| 151 | * @param page The PDF object representing the page for this device. |
| 152 | */ |
| 153 | void appendDestinations(SkPDFDict* dict, SkPDFObject* page); |
| 154 | |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 155 | /** Returns a copy of the media box for this device. The caller is required |
| 156 | * to unref() this when it is finished. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 157 | */ |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 158 | SkPDFArray* copyMediaBox() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 159 | |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 160 | /** Get the annotations from this page, or NULL if there are none. |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 161 | */ |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 162 | SkPDFArray* getAnnotations() const { return fAnnotations; } |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 163 | |
vandebo@chromium.org | c2a9b7f | 2011-02-24 23:22:30 +0000 | [diff] [blame] | 164 | /** Returns a SkStream with the page contents. The caller is responsible |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 165 | * for a deleting the returned value. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 166 | */ |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 167 | SkStreamAsset* content() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 168 | |
halcanary | 334fcbc | 2015-02-24 12:56:16 -0800 | [diff] [blame] | 169 | /** Writes the page contents to the stream. */ |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 170 | void writeContent(SkWStream*) const; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 171 | |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 172 | const SkMatrix& initialTransform() const { |
vandebo@chromium.org | 3509f05 | 2011-05-30 20:52:33 +0000 | [diff] [blame] | 173 | return fInitialTransform; |
| 174 | } |
vandebo@chromium.org | 61d2678 | 2011-05-24 23:02:07 +0000 | [diff] [blame] | 175 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 176 | /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font |
| 177 | * that shows on this device. |
| 178 | */ |
| 179 | const SkPDFGlyphSetMap& getFontGlyphUsage() const { |
| 180 | return *(fFontGlyphUsage.get()); |
| 181 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 182 | |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 183 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 184 | const SkBitmap& onAccessBitmap() SK_OVERRIDE { |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 185 | return fLegacyBitmap; |
| 186 | } |
| 187 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 188 | SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE; |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 189 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 190 | private: |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 191 | // TODO(vandebo): push most of SkPDFDevice's state into a core object in |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 192 | // order to get the right access levels without using friend. |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 193 | friend class ScopedContentEntry; |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 194 | |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 195 | SkISize fPageSize; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 196 | SkISize fContentSize; |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 197 | SkMatrix fInitialTransform; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 198 | SkClipStack fExistingClipStack; |
| 199 | SkRegion fExistingClipRegion; |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 200 | SkPDFArray* fAnnotations; |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 201 | SkPDFResourceDict* fResourceDict; |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 202 | SkTDArray<NamedDestination*> fNamedDestinations; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 203 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 204 | SkTDArray<SkPDFGraphicState*> fGraphicStateResources; |
| 205 | SkTDArray<SkPDFObject*> fXObjectResources; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 206 | SkTDArray<SkPDFFont*> fFontResources; |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 207 | SkTDArray<SkPDFObject*> fShaderResources; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 208 | |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 209 | SkAutoTDelete<ContentEntry> fContentEntries; |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 210 | ContentEntry* fLastContentEntry; |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 211 | SkAutoTDelete<ContentEntry> fMarginContentEntries; |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 212 | ContentEntry* fLastMarginContentEntry; |
| 213 | DrawingArea fDrawingArea; |
| 214 | |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 215 | const SkClipStack* fClipStack; |
| 216 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 217 | // Accessor and setter functions based on the current DrawingArea. |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 218 | SkAutoTDelete<ContentEntry>* getContentEntries(); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 219 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 220 | // Glyph ids used for each font on this device. |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 221 | SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 222 | |
commit-bot@chromium.org | 8c29490 | 2013-10-21 17:14:37 +0000 | [diff] [blame] | 223 | SkScalar fRasterDpi; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 224 | |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 225 | SkBitmap fLegacyBitmap; |
| 226 | |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 227 | SkPDFCanon* fCanon; // Owned by SkDocument_PDF |
| 228 | //////////////////////////////////////////////////////////////////////////// |
| 229 | |
| 230 | SkPDFDevice(SkISize pageSize, |
| 231 | SkScalar rasterDpi, |
| 232 | SkPDFCanon* canon, |
| 233 | bool flip); |
| 234 | |
| 235 | ContentEntry* getLastContentEntry(); |
| 236 | void setLastContentEntry(ContentEntry* contentEntry); |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 237 | |
reed | 0e040f7 | 2015-03-13 07:28:28 -0700 | [diff] [blame^] | 238 | // override from SkBaseDevice |
| 239 | SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) SK_OVERRIDE; |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 240 | |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 241 | void init(); |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 242 | void cleanUp(bool clearFontUsage); |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 243 | SkPDFFormXObject* createFormXObjectFromDevice(); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 244 | |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 245 | void drawFormXObjectWithMask(int xObjectIndex, |
| 246 | SkPDFFormXObject* mask, |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 247 | const SkClipStack* clipStack, |
| 248 | const SkRegion& clipRegion, |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 249 | SkXfermode::Mode mode, |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 250 | bool invertClip); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 251 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 252 | // If the paint or clip is such that we shouldn't draw anything, this |
| 253 | // returns NULL and does not create a content entry. |
| 254 | // setUpContentEntry and finishContentEntry can be used directly, but |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 255 | // the preferred method is to use the ScopedContentEntry helper class. |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 256 | ContentEntry* setUpContentEntry(const SkClipStack* clipStack, |
| 257 | const SkRegion& clipRegion, |
| 258 | const SkMatrix& matrix, |
| 259 | const SkPaint& paint, |
| 260 | bool hasText, |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 261 | SkPDFFormXObject** dst); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 262 | void finishContentEntry(SkXfermode::Mode xfermode, |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 263 | SkPDFFormXObject* dst, |
| 264 | SkPath* shape); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 265 | bool isContentEmpty(); |
| 266 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 267 | void populateGraphicStateEntryFromPaint(const SkMatrix& matrix, |
| 268 | const SkClipStack& clipStack, |
| 269 | const SkRegion& clipRegion, |
| 270 | const SkPaint& paint, |
| 271 | bool hasText, |
| 272 | GraphicStateEntry* entry); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 273 | int addGraphicStateResource(SkPDFGraphicState* gs); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 274 | int addXObjectResource(SkPDFObject* xObject); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 275 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 276 | void updateFont(const SkPaint& paint, uint16_t glyphID, |
| 277 | ContentEntry* contentEntry); |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 278 | int getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 279 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 280 | void internalDrawPaint(const SkPaint& paint, ContentEntry* contentEntry); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 281 | void internalDrawBitmap(const SkMatrix& matrix, |
vandebo@chromium.org | 78dad54 | 2011-05-11 18:46:03 +0000 | [diff] [blame] | 282 | const SkClipStack* clipStack, |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 283 | const SkRegion& clipRegion, |
| 284 | const SkBitmap& bitmap, |
| 285 | const SkIRect* srcRect, |
| 286 | const SkPaint& paint); |
| 287 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 288 | /** Helper method for copyContentToData. It is responsible for copying the |
| 289 | * list of content entries |entry| to |data|. |
| 290 | */ |
| 291 | void copyContentEntriesToData(ContentEntry* entry, SkWStream* data) const; |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 292 | |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 293 | #ifdef SK_PDF_USE_PATHOPS |
commit-bot@chromium.org | 92ffe7d | 2013-07-31 22:54:31 +0000 | [diff] [blame] | 294 | bool handleInversePath(const SkDraw& d, const SkPath& origPath, |
edisonn@google.com | a9ebd16 | 2013-10-07 13:22:21 +0000 | [diff] [blame] | 295 | const SkPaint& paint, bool pathIsMutable, |
| 296 | const SkMatrix* prePathMatrix = NULL); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 297 | #endif |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 298 | bool handleRectAnnotation(const SkRect& r, const SkMatrix& matrix, |
| 299 | const SkPaint& paint); |
| 300 | bool handlePointAnnotation(const SkPoint* points, size_t count, |
| 301 | const SkMatrix& matrix, const SkPaint& paint); |
| 302 | SkPDFDict* createLinkAnnotation(const SkRect& r, const SkMatrix& matrix); |
| 303 | void handleLinkToURL(SkData* urlData, const SkRect& r, |
| 304 | const SkMatrix& matrix); |
| 305 | void handleLinkToNamedDest(SkData* nameData, const SkRect& r, |
| 306 | const SkMatrix& matrix); |
| 307 | void defineNamedDestination(SkData* nameData, const SkPoint& point, |
| 308 | const SkMatrix& matrix); |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 309 | |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 310 | typedef SkBaseDevice INHERITED; |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 311 | |
| 312 | // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to create |
| 313 | // an SkPDFDevice |
| 314 | //friend class SkDocument_PDF; |
| 315 | //friend class SkPDFImageShader; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | #endif |