vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkPDFDevice_DEFINED |
| 9 | #define SkPDFDevice_DEFINED |
| 10 | |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 11 | #include "SkBitmap.h" |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 12 | #include "SkCanvas.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 13 | #include "SkClipStack.h" |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 14 | #include "SkData.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 15 | #include "SkDevice.h" |
vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 16 | #include "SkPaint.h" |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 17 | #include "SkRect.h" |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 18 | #include "SkRefCnt.h" |
| 19 | #include "SkStream.h" |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 20 | #include "SkTDArray.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 21 | |
halcanary | 2be7e01 | 2016-03-28 11:58:08 -0700 | [diff] [blame] | 22 | #include "SkSinglyLinkedList.h" |
| 23 | |
martina.kollarova | b8d6af1 | 2016-06-29 05:12:31 -0700 | [diff] [blame^] | 24 | class SkImageBitmap; |
| 25 | class SkPath; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 26 | class SkPDFArray; |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 27 | class SkPDFCanon; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 28 | class SkPDFDevice; |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 29 | class SkPDFDocument; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 30 | class SkPDFDict; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 31 | class SkPDFFont; |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 32 | class SkPDFFormXObject; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 33 | class SkPDFGlyphSetMap; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 34 | class SkPDFObject; |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 35 | class SkRRect; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 36 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 37 | /** \class SkPDFDevice |
| 38 | |
| 39 | The drawing context for the PDF backend. |
| 40 | */ |
halcanary | 70d1554 | 2015-11-22 12:55:04 -0800 | [diff] [blame] | 41 | class SkPDFDevice final : public SkBaseDevice { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 42 | public: |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 43 | /** Create a PDF drawing context. SkPDFDevice applies a |
| 44 | * scale-and-translate transform to move the origin from the |
| 45 | * bottom left (PDF default) to the top left (Skia default). |
| 46 | * @param pageSize Page size in point units. |
| 47 | * 1 point == 127/360 mm == 1/72 inch |
| 48 | * @param rasterDpi the DPI at which features without native PDF |
| 49 | * support will be rasterized (e.g. draw image with |
| 50 | * perspective, draw text with perspective, ...). A |
| 51 | * larger DPI would create a PDF that reflects the |
| 52 | * original intent with better fidelity, but it can make |
| 53 | * for larger PDF files too, which would use more memory |
| 54 | * while rendering, and it would be slower to be processed |
| 55 | * or sent online or to printer. A good choice is |
| 56 | * SK_ScalarDefaultRasterDPI(72.0f). |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 57 | * @param SkPDFDocument. A non-null pointer back to the |
| 58 | * document. The document is repsonsible for |
| 59 | * de-duplicating across pages (via the SkPDFCanon) and |
| 60 | * for early serializing of large immutable objects, such |
| 61 | * as images (via SkPDFDocument::serialize()). |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 62 | */ |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 63 | static SkPDFDevice* Create(SkISize pageSize, |
| 64 | SkScalar rasterDpi, |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 65 | SkPDFDocument* doc) { |
| 66 | return new SkPDFDevice(pageSize, rasterDpi, doc, true); |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** Create a PDF drawing context without fipping the y-axis. */ |
| 70 | static SkPDFDevice* CreateUnflipped(SkISize pageSize, |
| 71 | SkScalar rasterDpi, |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 72 | SkPDFDocument* doc) { |
| 73 | return new SkPDFDevice(pageSize, rasterDpi, doc, false); |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | virtual ~SkPDFDevice(); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 77 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 78 | /** These are called inside the per-device-layer loop for each draw call. |
| 79 | When these are called, we have already applied any saveLayer operations, |
| 80 | and are handling any looping from the paint, and any effects from the |
| 81 | DrawFilter. |
| 82 | */ |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 83 | void drawPaint(const SkDraw&, const SkPaint& paint) override; |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 84 | void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
| 85 | size_t count, const SkPoint[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 86 | const SkPaint& paint) override; |
| 87 | void drawRect(const SkDraw&, const SkRect& r, const SkPaint& paint) override; |
| 88 | void drawOval(const SkDraw&, const SkRect& oval, const SkPaint& paint) override; |
| 89 | void drawRRect(const SkDraw&, const SkRRect& rr, const SkPaint& paint) override; |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 90 | void drawPath(const SkDraw&, const SkPath& origpath, |
| 91 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 92 | bool pathIsMutable) override; |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 93 | void drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, const SkRect* src, |
| 94 | const SkRect& dst, const SkPaint&, SkCanvas::SrcRectConstraint) override; |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 95 | void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 96 | const SkMatrix& matrix, const SkPaint&) override; |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 97 | void drawSprite(const SkDraw&, const SkBitmap& bitmap, int x, int y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 98 | const SkPaint& paint) override; |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 99 | void drawImage(const SkDraw&, |
| 100 | const SkImage*, |
| 101 | SkScalar x, |
| 102 | SkScalar y, |
| 103 | const SkPaint&) override; |
| 104 | void drawImageRect(const SkDraw&, |
| 105 | const SkImage*, |
| 106 | const SkRect* src, |
| 107 | const SkRect& dst, |
| 108 | const SkPaint&, |
| 109 | SkCanvas::SrcRectConstraint) override; |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 110 | void drawText(const SkDraw&, const void* text, size_t len, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 111 | SkScalar x, SkScalar y, const SkPaint&) override; |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 112 | void drawPosText(const SkDraw&, const void* text, size_t len, |
| 113 | const SkScalar pos[], int scalarsPerPos, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 114 | const SkPoint& offset, const SkPaint&) override; |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 115 | void drawVertices(const SkDraw&, SkCanvas::VertexMode, |
| 116 | int vertexCount, const SkPoint verts[], |
| 117 | const SkPoint texs[], const SkColor colors[], |
| 118 | SkXfermode* xmode, const uint16_t indices[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 119 | int indexCount, const SkPaint& paint) override; |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 120 | void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 121 | const SkPaint&) override; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 122 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 123 | void onAttachToCanvas(SkCanvas* canvas) override; |
| 124 | void onDetachFromCanvas() override; |
| 125 | SkImageInfo imageInfo() const override; |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 126 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 127 | // PDF specific methods. |
| 128 | |
halcanary | 8103a34 | 2016-03-08 15:10:16 -0800 | [diff] [blame] | 129 | /** Create the resource dictionary for this device. */ |
| 130 | sk_sp<SkPDFDict> makeResourceDict() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 131 | |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 132 | /** Get the fonts used on this device. |
| 133 | */ |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 134 | const SkTDArray<SkPDFFont*>& getFontResources() const; |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 135 | |
wangxianzhu | ef6c50a | 2015-09-17 20:38:02 -0700 | [diff] [blame] | 136 | /** Add our annotations (link to urls and destinations) to the supplied |
| 137 | * array. |
| 138 | * @param array Array to add annotations to. |
| 139 | */ |
| 140 | void appendAnnotations(SkPDFArray* array) const; |
| 141 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 142 | /** Add our named destinations to the supplied dictionary. |
| 143 | * @param dict Dictionary to add destinations to. |
| 144 | * @param page The PDF object representing the page for this device. |
| 145 | */ |
halcanary | 6d62270 | 2015-03-25 08:45:42 -0700 | [diff] [blame] | 146 | void appendDestinations(SkPDFDict* dict, SkPDFObject* page) const; |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 147 | |
halcanary | 8103a34 | 2016-03-08 15:10:16 -0800 | [diff] [blame] | 148 | /** Returns a copy of the media box for this device. */ |
| 149 | sk_sp<SkPDFArray> copyMediaBox() const; |
halcanary | 51d04d3 | 2016-03-08 13:03:55 -0800 | [diff] [blame] | 150 | |
halcanary | 8103a34 | 2016-03-08 15:10:16 -0800 | [diff] [blame] | 151 | /** Returns a SkStream with the page contents. |
halcanary | 51d04d3 | 2016-03-08 13:03:55 -0800 | [diff] [blame] | 152 | */ |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 153 | std::unique_ptr<SkStreamAsset> content() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 154 | |
halcanary | 334fcbc | 2015-02-24 12:56:16 -0800 | [diff] [blame] | 155 | /** Writes the page contents to the stream. */ |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 156 | void writeContent(SkWStream*) const; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 157 | |
halcanary | 4e4e816 | 2015-02-25 08:59:48 -0800 | [diff] [blame] | 158 | const SkMatrix& initialTransform() const { |
vandebo@chromium.org | 3509f05 | 2011-05-30 20:52:33 +0000 | [diff] [blame] | 159 | return fInitialTransform; |
| 160 | } |
vandebo@chromium.org | 61d2678 | 2011-05-24 23:02:07 +0000 | [diff] [blame] | 161 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 162 | /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font |
| 163 | * that shows on this device. |
| 164 | */ |
| 165 | const SkPDFGlyphSetMap& getFontGlyphUsage() const { |
| 166 | return *(fFontGlyphUsage.get()); |
| 167 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 168 | |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 169 | SkPDFCanon* getCanon() const; |
halcanary | 26b5d15 | 2015-03-25 08:38:03 -0700 | [diff] [blame] | 170 | |
halcanary | 2be7e01 | 2016-03-28 11:58:08 -0700 | [diff] [blame] | 171 | // It is important to not confuse GraphicStateEntry with SkPDFGraphicState, the |
| 172 | // later being our representation of an object in the PDF file. |
| 173 | struct GraphicStateEntry { |
| 174 | GraphicStateEntry(); |
| 175 | |
| 176 | // Compare the fields we care about when setting up a new content entry. |
| 177 | bool compareInitialState(const GraphicStateEntry& b); |
| 178 | |
| 179 | SkMatrix fMatrix; |
| 180 | // We can't do set operations on Paths, though PDF natively supports |
| 181 | // intersect. If the clip stack does anything other than intersect, |
| 182 | // we have to fall back to the region. Treat fClipStack as authoritative. |
| 183 | // See https://bugs.skia.org/221 |
| 184 | SkClipStack fClipStack; |
| 185 | SkRegion fClipRegion; |
| 186 | |
| 187 | // When emitting the content entry, we will ensure the graphic state |
| 188 | // is set to these values first. |
| 189 | SkColor fColor; |
| 190 | SkScalar fTextScaleX; // Zero means we don't care what the value is. |
| 191 | SkPaint::Style fTextFill; // Only if TextScaleX is non-zero. |
| 192 | int fShaderIndex; |
| 193 | int fGraphicStateIndex; |
| 194 | |
| 195 | // We may change the font (i.e. for Type1 support) within a |
| 196 | // ContentEntry. This is the one currently in effect, or nullptr if none. |
| 197 | SkPDFFont* fFont; |
| 198 | // In PDF, text size has no default value. It is only valid if fFont is |
| 199 | // not nullptr. |
| 200 | SkScalar fTextSize; |
| 201 | }; |
| 202 | |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 203 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 204 | const SkBitmap& onAccessBitmap() override { |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 205 | return fLegacyBitmap; |
| 206 | } |
| 207 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 208 | sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 209 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 210 | void drawAnnotation(const SkDraw&, const SkRect&, const char key[], SkData* value) override; |
| 211 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 212 | private: |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 213 | struct RectWithData { |
| 214 | SkRect rect; |
halcanary | d7b2885 | 2016-03-07 12:39:14 -0800 | [diff] [blame] | 215 | sk_sp<SkData> data; |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 216 | RectWithData(const SkRect& rect, SkData* data) |
| 217 | : rect(rect), data(SkRef(data)) {} |
halcanary | d7b2885 | 2016-03-07 12:39:14 -0800 | [diff] [blame] | 218 | RectWithData(RectWithData&& other) |
| 219 | : rect(other.rect), data(std::move(other.data)) {} |
| 220 | RectWithData& operator=(RectWithData&& other) { |
| 221 | rect = other.rect; |
| 222 | data = std::move(other.data); |
| 223 | return *this; |
| 224 | } |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | struct NamedDestination { |
halcanary | d7b2885 | 2016-03-07 12:39:14 -0800 | [diff] [blame] | 228 | sk_sp<SkData> nameData; |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 229 | SkPoint point; |
| 230 | NamedDestination(SkData* nameData, const SkPoint& point) |
| 231 | : nameData(SkRef(nameData)), point(point) {} |
halcanary | d7b2885 | 2016-03-07 12:39:14 -0800 | [diff] [blame] | 232 | NamedDestination(NamedDestination&& other) |
| 233 | : nameData(std::move(other.nameData)), point(other.point) {} |
| 234 | NamedDestination& operator=(NamedDestination&& other) { |
| 235 | nameData = std::move(other.nameData); |
| 236 | point = other.point; |
| 237 | return *this; |
| 238 | } |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 239 | }; |
| 240 | |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 241 | // 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] | 242 | // order to get the right access levels without using friend. |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 243 | friend class ScopedContentEntry; |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 244 | |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 245 | SkISize fPageSize; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 246 | SkISize fContentSize; |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 247 | SkMatrix fInitialTransform; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 248 | SkClipStack fExistingClipStack; |
| 249 | SkRegion fExistingClipRegion; |
wangxianzhu | ef6c50a | 2015-09-17 20:38:02 -0700 | [diff] [blame] | 250 | |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 251 | SkTArray<RectWithData> fLinkToURLs; |
| 252 | SkTArray<RectWithData> fLinkToDestinations; |
| 253 | SkTArray<NamedDestination> fNamedDestinations; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 254 | |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 255 | SkTDArray<SkPDFObject*> fGraphicStateResources; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 256 | SkTDArray<SkPDFObject*> fXObjectResources; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 257 | SkTDArray<SkPDFFont*> fFontResources; |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 258 | SkTDArray<SkPDFObject*> fShaderResources; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 259 | |
halcanary | 2be7e01 | 2016-03-28 11:58:08 -0700 | [diff] [blame] | 260 | struct ContentEntry { |
| 261 | GraphicStateEntry fState; |
| 262 | SkDynamicMemoryWStream fContent; |
| 263 | }; |
| 264 | SkSinglyLinkedList<ContentEntry> fContentEntries; |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 265 | |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 266 | const SkClipStack* fClipStack; |
| 267 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 268 | // Glyph ids used for each font on this device. |
halcanary | b8fb993 | 2016-03-28 07:58:30 -0700 | [diff] [blame] | 269 | std::unique_ptr<SkPDFGlyphSetMap> fFontGlyphUsage; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 270 | |
commit-bot@chromium.org | 8c29490 | 2013-10-21 17:14:37 +0000 | [diff] [blame] | 271 | SkScalar fRasterDpi; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 272 | |
reed | 89443ab | 2014-06-27 11:34:19 -0700 | [diff] [blame] | 273 | SkBitmap fLegacyBitmap; |
| 274 | |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 275 | SkPDFDocument* fDocument; |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 276 | //////////////////////////////////////////////////////////////////////////// |
| 277 | |
| 278 | SkPDFDevice(SkISize pageSize, |
| 279 | SkScalar rasterDpi, |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 280 | SkPDFDocument* doc, |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 281 | bool flip); |
| 282 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 283 | SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 284 | |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 285 | void init(); |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 286 | void cleanUp(bool clearFontUsage); |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 287 | SkPDFFormXObject* createFormXObjectFromDevice(); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 288 | |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 289 | void drawFormXObjectWithMask(int xObjectIndex, |
| 290 | SkPDFFormXObject* mask, |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 291 | const SkClipStack* clipStack, |
| 292 | const SkRegion& clipRegion, |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 293 | SkXfermode::Mode mode, |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 294 | bool invertClip); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 295 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 296 | // If the paint or clip is such that we shouldn't draw anything, this |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 297 | // returns nullptr and does not create a content entry. |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 298 | // setUpContentEntry and finishContentEntry can be used directly, but |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 299 | // the preferred method is to use the ScopedContentEntry helper class. |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 300 | ContentEntry* setUpContentEntry(const SkClipStack* clipStack, |
| 301 | const SkRegion& clipRegion, |
| 302 | const SkMatrix& matrix, |
| 303 | const SkPaint& paint, |
| 304 | bool hasText, |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 305 | SkPDFFormXObject** dst); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 306 | void finishContentEntry(SkXfermode::Mode xfermode, |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 307 | SkPDFFormXObject* dst, |
| 308 | SkPath* shape); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 309 | bool isContentEmpty(); |
| 310 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 311 | void populateGraphicStateEntryFromPaint(const SkMatrix& matrix, |
| 312 | const SkClipStack& clipStack, |
| 313 | const SkRegion& clipRegion, |
| 314 | const SkPaint& paint, |
| 315 | bool hasText, |
| 316 | GraphicStateEntry* entry); |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 317 | int addGraphicStateResource(SkPDFObject* gs); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 318 | int addXObjectResource(SkPDFObject* xObject); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 319 | |
robertphillips | 8e0c150 | 2015-07-07 10:28:43 -0700 | [diff] [blame] | 320 | void updateFont(const SkPaint& paint, uint16_t glyphID, ContentEntry* contentEntry); |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 321 | int getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 322 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 323 | void internalDrawPaint(const SkPaint& paint, ContentEntry* contentEntry); |
halcanary | a50151d | 2016-03-25 11:57:49 -0700 | [diff] [blame] | 324 | |
| 325 | void internalDrawImage(const SkMatrix& origMatrix, |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 326 | const SkClipStack* clipStack, |
halcanary | a50151d | 2016-03-25 11:57:49 -0700 | [diff] [blame] | 327 | const SkRegion& origClipRegion, |
| 328 | SkImageBitmap imageBitmap, |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 329 | const SkPaint& paint); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 330 | |
commit-bot@chromium.org | 92ffe7d | 2013-07-31 22:54:31 +0000 | [diff] [blame] | 331 | bool handleInversePath(const SkDraw& d, const SkPath& origPath, |
edisonn@google.com | a9ebd16 | 2013-10-07 13:22:21 +0000 | [diff] [blame] | 332 | const SkPaint& paint, bool pathIsMutable, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 333 | const SkMatrix* prePathMatrix = nullptr); |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 334 | void handlePointAnnotation(const SkPoint&, const SkMatrix&, const char key[], SkData* value); |
| 335 | void handlePathAnnotation(const SkPath&, const SkDraw& d, const char key[], SkData* value); |
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 |