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; |
| 26 | class SkPDFDevice; |
| 27 | class SkPDFDict; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 28 | class SkPDFFont; |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 29 | class SkPDFFormXObject; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 30 | class SkPDFGlyphSetMap; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 31 | class SkPDFGraphicState; |
| 32 | class SkPDFObject; |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 33 | class SkPDFResourceDict; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 34 | class SkPDFShader; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 35 | class SkPDFStream; |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 36 | class SkRRect; |
edisonn@google.com | a20e42c | 2013-05-31 18:04:20 +0000 | [diff] [blame] | 37 | template <typename T> class SkTSet; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 38 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 39 | // Private classes. |
| 40 | struct ContentEntry; |
| 41 | struct GraphicStateEntry; |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 42 | struct NamedDestination; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 43 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 44 | /** \class SkPDFDevice |
| 45 | |
| 46 | The drawing context for the PDF backend. |
| 47 | */ |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 48 | class SkPDFDevice : public SkBaseDevice { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 49 | public: |
| 50 | /** Create a PDF drawing context with the given width and height. |
| 51 | * 72 points/in means letter paper is 612x792. |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 52 | * @param pageSize Page size in points. |
| 53 | * @param contentSize The content size of the page in points. This will be |
| 54 | * combined with the initial transform to determine the drawing area |
| 55 | * (as reported by the width and height methods). Anything outside |
| 56 | * of the drawing area will be clipped. |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 57 | * @param initialTransform The initial transform to apply to the page. |
| 58 | * This may be useful to, for example, move the origin in and |
| 59 | * over a bit to account for a margin, scale the canvas, |
| 60 | * or apply a rotation. Note1: the SkPDFDevice also applies |
| 61 | * a scale+translate transform to move the origin from the |
| 62 | * bottom left (PDF default) to the top left. Note2: drawDevice |
| 63 | * (used by layer restore) draws the device after this initial |
reed@google.com | cde9211 | 2011-07-06 20:00:52 +0000 | [diff] [blame] | 64 | * transform is applied, so the PDF device does an |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 65 | * inverse scale+translate to accommodate the one that SkPDFDevice |
| 66 | * always does. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 67 | */ |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 68 | // Deprecated, please use SkDocument::CreatePdf() instead. |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 69 | SK_API SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, |
| 70 | const SkMatrix& initialTransform); |
| 71 | SK_API virtual ~SkPDFDevice(); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 72 | |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 73 | virtual void clear(SkColor color) SK_OVERRIDE; |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 74 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 75 | /** These are called inside the per-device-layer loop for each draw call. |
| 76 | When these are called, we have already applied any saveLayer operations, |
| 77 | and are handling any looping from the paint, and any effects from the |
| 78 | DrawFilter. |
| 79 | */ |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 80 | virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 81 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
| 82 | size_t count, const SkPoint[], |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 83 | const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 84 | virtual void drawRect(const SkDraw&, const SkRect& r, const SkPaint& paint); |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 85 | virtual void drawOval(const SkDraw&, const SkRect& oval, const SkPaint& paint) SK_OVERRIDE; |
| 86 | virtual void drawRRect(const SkDraw&, const SkRRect& rr, const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 87 | virtual void drawPath(const SkDraw&, const SkPath& origpath, |
vandebo@chromium.org | 02cc5aa | 2011-01-25 22:06:29 +0000 | [diff] [blame] | 88 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 89 | bool pathIsMutable) SK_OVERRIDE; |
edisonn@google.com | 2ae67e7 | 2013-02-12 01:06:38 +0000 | [diff] [blame] | 90 | virtual void drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
| 91 | const SkRect* src, const SkRect& dst, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 92 | const SkPaint& paint, |
| 93 | SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 94 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 95 | const SkMatrix& matrix, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 96 | virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, int x, int y, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 97 | const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 98 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 99 | SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 100 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
| 101 | const SkScalar pos[], SkScalar constY, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 102 | int scalarsPerPos, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 103 | virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
| 104 | const SkPath& path, const SkMatrix* matrix, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 105 | const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 106 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, |
| 107 | int vertexCount, const SkPoint verts[], |
| 108 | const SkPoint texs[], const SkColor colors[], |
| 109 | SkXfermode* xmode, const uint16_t indices[], |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 110 | int indexCount, const SkPaint& paint) SK_OVERRIDE; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 111 | virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 112 | const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 113 | |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 114 | virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE; |
| 115 | virtual void onDetachFromCanvas() SK_OVERRIDE; |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 116 | virtual SkImageInfo imageInfo() const SK_OVERRIDE; |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 117 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 118 | enum DrawingArea { |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 119 | kContent_DrawingArea, // Drawing area for the page content. |
| 120 | kMargin_DrawingArea, // Drawing area for the margin content. |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /** 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] | 124 | * to the specific drawing area (margin or content). The default drawing |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 125 | * area is the content drawing area. |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 126 | * |
| 127 | * Currently if margin content is drawn and then a complex (for PDF) xfer |
| 128 | * mode is used, like SrcIn, Clear, etc, the margin content will get |
| 129 | * clipped. A simple way to avoid the bug is to always draw the margin |
| 130 | * content last. |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 131 | */ |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 132 | SK_API void setDrawingArea(DrawingArea drawingArea); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 133 | |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 134 | /** Sets the DCTEncoder for images. |
| 135 | * @param encoder The encoder to encode a bitmap as JPEG (DCT). |
| 136 | * Result of encodings are cached, if the encoder changes the |
| 137 | * behaivor dynamically and an image is added to a second catalog, |
| 138 | * we will likely use the result of the first encoding call. |
| 139 | * By returning false from the encoder function, the encoder result |
| 140 | * is not used. |
| 141 | * Callers might not want to encode small images, as the time spent |
| 142 | * encoding and decoding might not be worth the space savings, |
| 143 | * if any at all. |
| 144 | */ |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 145 | void setDCTEncoder(SkPicture::EncodeBitmap encoder) { |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 146 | fEncoder = encoder; |
| 147 | } |
| 148 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 149 | // PDF specific methods. |
| 150 | |
reed@google.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 151 | /** Returns the resource dictionary for this device. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 152 | */ |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 153 | SK_API SkPDFResourceDict* getResourceDict(); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 154 | |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 155 | /** Get the fonts used on this device. |
| 156 | */ |
vandebo@chromium.org | 3509f05 | 2011-05-30 20:52:33 +0000 | [diff] [blame] | 157 | SK_API const SkTDArray<SkPDFFont*>& getFontResources() const; |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 158 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 159 | /** Add our named destinations to the supplied dictionary. |
| 160 | * @param dict Dictionary to add destinations to. |
| 161 | * @param page The PDF object representing the page for this device. |
| 162 | */ |
| 163 | void appendDestinations(SkPDFDict* dict, SkPDFObject* page); |
| 164 | |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 165 | /** Returns a copy of the media box for this device. The caller is required |
| 166 | * to unref() this when it is finished. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 167 | */ |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 168 | SK_API SkPDFArray* copyMediaBox() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 169 | |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 170 | /** 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] | 171 | */ |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 172 | SK_API SkPDFArray* getAnnotations() const { return fAnnotations; } |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 173 | |
vandebo@chromium.org | c2a9b7f | 2011-02-24 23:22:30 +0000 | [diff] [blame] | 174 | /** Returns a SkStream with the page contents. The caller is responsible |
| 175 | for a reference to the returned value. |
reed@google.com | 5667afc | 2011-06-27 14:42:15 +0000 | [diff] [blame] | 176 | DEPRECATED: use copyContentToData() |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 177 | */ |
vandebo@chromium.org | 3509f05 | 2011-05-30 20:52:33 +0000 | [diff] [blame] | 178 | SK_API SkStream* content() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 179 | |
reed@google.com | 5667afc | 2011-06-27 14:42:15 +0000 | [diff] [blame] | 180 | /** Returns a SkStream with the page contents. The caller is responsible |
| 181 | * for calling data->unref() when it is finished. |
| 182 | */ |
| 183 | SK_API SkData* copyContentToData() const; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 184 | |
vandebo@chromium.org | 3509f05 | 2011-05-30 20:52:33 +0000 | [diff] [blame] | 185 | SK_API const SkMatrix& initialTransform() const { |
| 186 | return fInitialTransform; |
| 187 | } |
vandebo@chromium.org | 61d2678 | 2011-05-24 23:02:07 +0000 | [diff] [blame] | 188 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 189 | /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font |
| 190 | * that shows on this device. |
| 191 | */ |
| 192 | const SkPDFGlyphSetMap& getFontGlyphUsage() const { |
| 193 | return *(fFontGlyphUsage.get()); |
| 194 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 195 | |
reed@google.com | b55deeb | 2012-01-06 14:43:09 +0000 | [diff] [blame] | 196 | |
commit-bot@chromium.org | 8c29490 | 2013-10-21 17:14:37 +0000 | [diff] [blame] | 197 | /** |
| 198 | * rasterDpi - the DPI at which features without native PDF support |
| 199 | * will be rasterized (e.g. draw image with perspective, |
| 200 | * draw text with perspective, ...) |
| 201 | * A larger DPI would create a PDF that reflects the original |
| 202 | * intent with better fidelity, but it can make for larger |
| 203 | * PDF files too, which would use more memory while rendering, |
| 204 | * and it would be slower to be processed or sent online or |
| 205 | * to printer. |
| 206 | */ |
| 207 | void setRasterDpi(SkScalar rasterDpi) { |
| 208 | fRasterDpi = rasterDpi; |
| 209 | } |
| 210 | |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 211 | protected: |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 212 | virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE { |
| 213 | return fLegacyBitmap; |
| 214 | } |
| 215 | |
| 216 | virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE { |
| 217 | return false; |
| 218 | } |
| 219 | |
reed | 3716fd0 | 2014-09-21 09:39:55 -0700 | [diff] [blame^] | 220 | virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE; |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 221 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 222 | private: |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 223 | // 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] | 224 | // order to get the right access levels without using friend. |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 225 | friend class ScopedContentEntry; |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 226 | |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 227 | SkISize fPageSize; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 228 | SkISize fContentSize; |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 229 | SkMatrix fInitialTransform; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 230 | SkClipStack fExistingClipStack; |
| 231 | SkRegion fExistingClipRegion; |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 232 | SkPDFArray* fAnnotations; |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 233 | SkPDFResourceDict* fResourceDict; |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 234 | SkTDArray<NamedDestination*> fNamedDestinations; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 235 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 236 | SkTDArray<SkPDFGraphicState*> fGraphicStateResources; |
| 237 | SkTDArray<SkPDFObject*> fXObjectResources; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 238 | SkTDArray<SkPDFFont*> fFontResources; |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 239 | SkTDArray<SkPDFObject*> fShaderResources; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 240 | |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 241 | SkAutoTDelete<ContentEntry> fContentEntries; |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 242 | ContentEntry* fLastContentEntry; |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 243 | SkAutoTDelete<ContentEntry> fMarginContentEntries; |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 244 | ContentEntry* fLastMarginContentEntry; |
| 245 | DrawingArea fDrawingArea; |
| 246 | |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 247 | const SkClipStack* fClipStack; |
| 248 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 249 | // Accessor and setter functions based on the current DrawingArea. |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 250 | SkAutoTDelete<ContentEntry>* getContentEntries(); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 251 | ContentEntry* getLastContentEntry(); |
| 252 | void setLastContentEntry(ContentEntry* contentEntry); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 253 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 254 | // Glyph ids used for each font on this device. |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 255 | SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 256 | |
commit-bot@chromium.org | 608ea65 | 2013-10-03 19:29:21 +0000 | [diff] [blame] | 257 | SkPicture::EncodeBitmap fEncoder; |
commit-bot@chromium.org | 8c29490 | 2013-10-21 17:14:37 +0000 | [diff] [blame] | 258 | SkScalar fRasterDpi; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 259 | |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 260 | SkBitmap fLegacyBitmap; |
| 261 | |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 262 | SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, |
| 263 | const SkRegion& existingClipRegion); |
| 264 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 265 | // override from SkBaseDevice |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 266 | virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 267 | |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 268 | void init(); |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 269 | void cleanUp(bool clearFontUsage); |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 270 | SkPDFFormXObject* createFormXObjectFromDevice(); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 271 | |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 272 | void drawFormXObjectWithMask(int xObjectIndex, |
| 273 | SkPDFFormXObject* mask, |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 274 | const SkClipStack* clipStack, |
| 275 | const SkRegion& clipRegion, |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 276 | SkXfermode::Mode mode, |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 277 | bool invertClip); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 278 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 279 | // If the paint or clip is such that we shouldn't draw anything, this |
| 280 | // returns NULL and does not create a content entry. |
| 281 | // setUpContentEntry and finishContentEntry can be used directly, but |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 282 | // the preferred method is to use the ScopedContentEntry helper class. |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 283 | ContentEntry* setUpContentEntry(const SkClipStack* clipStack, |
| 284 | const SkRegion& clipRegion, |
| 285 | const SkMatrix& matrix, |
| 286 | const SkPaint& paint, |
| 287 | bool hasText, |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 288 | SkPDFFormXObject** dst); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 289 | void finishContentEntry(SkXfermode::Mode xfermode, |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 290 | SkPDFFormXObject* dst, |
| 291 | SkPath* shape); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 292 | bool isContentEmpty(); |
| 293 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 294 | void populateGraphicStateEntryFromPaint(const SkMatrix& matrix, |
| 295 | const SkClipStack& clipStack, |
| 296 | const SkRegion& clipRegion, |
| 297 | const SkPaint& paint, |
| 298 | bool hasText, |
| 299 | GraphicStateEntry* entry); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 300 | int addGraphicStateResource(SkPDFGraphicState* gs); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 301 | int addXObjectResource(SkPDFObject* xObject); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 302 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 303 | void updateFont(const SkPaint& paint, uint16_t glyphID, |
| 304 | ContentEntry* contentEntry); |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 305 | int getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 306 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 307 | void internalDrawPaint(const SkPaint& paint, ContentEntry* contentEntry); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 308 | void internalDrawBitmap(const SkMatrix& matrix, |
vandebo@chromium.org | 78dad54 | 2011-05-11 18:46:03 +0000 | [diff] [blame] | 309 | const SkClipStack* clipStack, |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 310 | const SkRegion& clipRegion, |
| 311 | const SkBitmap& bitmap, |
| 312 | const SkIRect* srcRect, |
| 313 | const SkPaint& paint); |
| 314 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 315 | /** Helper method for copyContentToData. It is responsible for copying the |
| 316 | * list of content entries |entry| to |data|. |
| 317 | */ |
| 318 | void copyContentEntriesToData(ContentEntry* entry, SkWStream* data) const; |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 319 | |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 320 | #ifdef SK_PDF_USE_PATHOPS |
commit-bot@chromium.org | 92ffe7d | 2013-07-31 22:54:31 +0000 | [diff] [blame] | 321 | bool handleInversePath(const SkDraw& d, const SkPath& origPath, |
edisonn@google.com | a9ebd16 | 2013-10-07 13:22:21 +0000 | [diff] [blame] | 322 | const SkPaint& paint, bool pathIsMutable, |
| 323 | const SkMatrix* prePathMatrix = NULL); |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 324 | #endif |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 325 | bool handleRectAnnotation(const SkRect& r, const SkMatrix& matrix, |
| 326 | const SkPaint& paint); |
| 327 | bool handlePointAnnotation(const SkPoint* points, size_t count, |
| 328 | const SkMatrix& matrix, const SkPaint& paint); |
| 329 | SkPDFDict* createLinkAnnotation(const SkRect& r, const SkMatrix& matrix); |
| 330 | void handleLinkToURL(SkData* urlData, const SkRect& r, |
| 331 | const SkMatrix& matrix); |
| 332 | void handleLinkToNamedDest(SkData* nameData, const SkRect& r, |
| 333 | const SkMatrix& matrix); |
| 334 | void defineNamedDestination(SkData* nameData, const SkPoint& point, |
| 335 | const SkMatrix& matrix); |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 336 | |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 337 | typedef SkBaseDevice INHERITED; |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 338 | |
| 339 | // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to create |
| 340 | // an SkPDFDevice |
| 341 | //friend class SkDocument_PDF; |
| 342 | //friend class SkPDFImageShader; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | #endif |