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" |
Mike Reed | f0fb929 | 2017-02-21 13:15:07 -0500 | [diff] [blame] | 14 | #include "SkClipStackDevice.h" |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 15 | #include "SkData.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" |
halcanary | 4ed2f01 | 2016-08-15 18:40:07 -0700 | [diff] [blame] | 19 | #include "SkSinglyLinkedList.h" |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 20 | #include "SkStream.h" |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 21 | #include "SkTDArray.h" |
halcanary | 4ed2f01 | 2016-08-15 18:40:07 -0700 | [diff] [blame] | 22 | #include "SkTextBlob.h" |
halcanary | 2be7e01 | 2016-03-28 11:58:08 -0700 | [diff] [blame] | 23 | |
Hal Canary | f50ff39 | 2016-09-30 10:25:39 -0400 | [diff] [blame] | 24 | class SkImageSubset; |
martina.kollarova | b8d6af1 | 2016-06-29 05:12:31 -0700 | [diff] [blame] | 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 | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 32 | class SkPDFObject; |
halcanary | 4b1e17e | 2016-07-27 14:49:46 -0700 | [diff] [blame] | 33 | class SkPDFStream; |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 34 | class SkRRect; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 35 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 36 | /** \class SkPDFDevice |
| 37 | |
| 38 | The drawing context for the PDF backend. |
| 39 | */ |
Mike Reed | f0fb929 | 2017-02-21 13:15:07 -0500 | [diff] [blame] | 40 | class SkPDFDevice final : public SkClipStackDevice { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 41 | public: |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 42 | /** Create a PDF drawing context. SkPDFDevice applies a |
| 43 | * scale-and-translate transform to move the origin from the |
| 44 | * bottom left (PDF default) to the top left (Skia default). |
| 45 | * @param pageSize Page size in point units. |
| 46 | * 1 point == 127/360 mm == 1/72 inch |
| 47 | * @param rasterDpi the DPI at which features without native PDF |
| 48 | * support will be rasterized (e.g. draw image with |
| 49 | * perspective, draw text with perspective, ...). A |
| 50 | * larger DPI would create a PDF that reflects the |
| 51 | * original intent with better fidelity, but it can make |
| 52 | * for larger PDF files too, which would use more memory |
| 53 | * while rendering, and it would be slower to be processed |
| 54 | * or sent online or to printer. A good choice is |
| 55 | * SK_ScalarDefaultRasterDPI(72.0f). |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 56 | * @param SkPDFDocument. A non-null pointer back to the |
| 57 | * document. The document is repsonsible for |
| 58 | * de-duplicating across pages (via the SkPDFCanon) and |
| 59 | * for early serializing of large immutable objects, such |
| 60 | * as images (via SkPDFDocument::serialize()). |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 61 | */ |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 62 | static SkPDFDevice* Create(SkISize pageSize, |
| 63 | SkScalar rasterDpi, |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 64 | SkPDFDocument* doc) { |
| 65 | return new SkPDFDevice(pageSize, rasterDpi, doc, true); |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** Create a PDF drawing context without fipping the y-axis. */ |
| 69 | static SkPDFDevice* CreateUnflipped(SkISize pageSize, |
| 70 | SkScalar rasterDpi, |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 71 | SkPDFDocument* doc) { |
| 72 | return new SkPDFDevice(pageSize, rasterDpi, doc, false); |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 75 | ~SkPDFDevice() override; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 76 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 77 | /** These are called inside the per-device-layer loop for each draw call. |
| 78 | When these are called, we have already applied any saveLayer operations, |
| 79 | and are handling any looping from the paint, and any effects from the |
| 80 | DrawFilter. |
| 81 | */ |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 82 | void drawPaint(const SkPaint& paint) override; |
| 83 | void drawPoints(SkCanvas::PointMode mode, |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 84 | size_t count, const SkPoint[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 85 | const SkPaint& paint) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 86 | void drawRect(const SkRect& r, const SkPaint& paint) override; |
| 87 | void drawOval(const SkRect& oval, const SkPaint& paint) override; |
| 88 | void drawRRect(const SkRRect& rr, const SkPaint& paint) override; |
| 89 | void drawPath(const SkPath& origpath, |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 90 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 91 | bool pathIsMutable) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 92 | void drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 93 | const SkRect& dst, const SkPaint&, SkCanvas::SrcRectConstraint) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 94 | void drawBitmap(const SkBitmap& bitmap, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 95 | const SkMatrix& matrix, const SkPaint&) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 96 | void drawSprite(const SkBitmap& bitmap, int x, int y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 97 | const SkPaint& paint) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 98 | void drawImage(const SkImage*, |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 99 | SkScalar x, |
| 100 | SkScalar y, |
| 101 | const SkPaint&) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 102 | void drawImageRect(const SkImage*, |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 103 | const SkRect* src, |
| 104 | const SkRect& dst, |
| 105 | const SkPaint&, |
| 106 | SkCanvas::SrcRectConstraint) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 107 | void drawText(const void* text, size_t len, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 108 | SkScalar x, SkScalar y, const SkPaint&) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 109 | void drawPosText(const void* text, size_t len, |
tfarina | fa4f6cb | 2014-12-21 10:27:07 -0800 | [diff] [blame] | 110 | const SkScalar pos[], int scalarsPerPos, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 111 | const SkPoint& offset, const SkPaint&) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 112 | void drawTextBlob(const SkTextBlob*, SkScalar x, SkScalar y, |
halcanary | e06ca96 | 2016-09-09 05:34:55 -0700 | [diff] [blame] | 113 | const SkPaint &, SkDrawFilter*) override; |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 114 | void drawVertices(const SkVertices*, SkBlendMode, const SkPaint&) override; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 115 | void drawDevice(SkBaseDevice*, int x, int y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 116 | const SkPaint&) override; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 117 | |
| 118 | // PDF specific methods. |
| 119 | |
halcanary | 8103a34 | 2016-03-08 15:10:16 -0800 | [diff] [blame] | 120 | /** Create the resource dictionary for this device. */ |
| 121 | sk_sp<SkPDFDict> makeResourceDict() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 122 | |
wangxianzhu | ef6c50a | 2015-09-17 20:38:02 -0700 | [diff] [blame] | 123 | /** Add our annotations (link to urls and destinations) to the supplied |
| 124 | * array. |
| 125 | * @param array Array to add annotations to. |
| 126 | */ |
| 127 | void appendAnnotations(SkPDFArray* array) const; |
| 128 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 129 | /** Add our named destinations to the supplied dictionary. |
| 130 | * @param dict Dictionary to add destinations to. |
| 131 | * @param page The PDF object representing the page for this device. |
| 132 | */ |
halcanary | 6d62270 | 2015-03-25 08:45:42 -0700 | [diff] [blame] | 133 | void appendDestinations(SkPDFDict* dict, SkPDFObject* page) const; |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 134 | |
halcanary | 8103a34 | 2016-03-08 15:10:16 -0800 | [diff] [blame] | 135 | /** Returns a copy of the media box for this device. */ |
| 136 | sk_sp<SkPDFArray> copyMediaBox() const; |
halcanary | 51d04d3 | 2016-03-08 13:03:55 -0800 | [diff] [blame] | 137 | |
halcanary | 8103a34 | 2016-03-08 15:10:16 -0800 | [diff] [blame] | 138 | /** Returns a SkStream with the page contents. |
halcanary | 51d04d3 | 2016-03-08 13:03:55 -0800 | [diff] [blame] | 139 | */ |
mtklein | 5f939ab | 2016-03-16 10:28:35 -0700 | [diff] [blame] | 140 | std::unique_ptr<SkStreamAsset> content() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 141 | |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 142 | SkPDFCanon* getCanon() const; |
halcanary | 26b5d15 | 2015-03-25 08:38:03 -0700 | [diff] [blame] | 143 | |
halcanary | 2be7e01 | 2016-03-28 11:58:08 -0700 | [diff] [blame] | 144 | // It is important to not confuse GraphicStateEntry with SkPDFGraphicState, the |
| 145 | // later being our representation of an object in the PDF file. |
| 146 | struct GraphicStateEntry { |
| 147 | GraphicStateEntry(); |
| 148 | |
| 149 | // Compare the fields we care about when setting up a new content entry. |
| 150 | bool compareInitialState(const GraphicStateEntry& b); |
| 151 | |
| 152 | SkMatrix fMatrix; |
| 153 | // We can't do set operations on Paths, though PDF natively supports |
| 154 | // intersect. If the clip stack does anything other than intersect, |
| 155 | // we have to fall back to the region. Treat fClipStack as authoritative. |
| 156 | // See https://bugs.skia.org/221 |
| 157 | SkClipStack fClipStack; |
halcanary | 2be7e01 | 2016-03-28 11:58:08 -0700 | [diff] [blame] | 158 | |
| 159 | // When emitting the content entry, we will ensure the graphic state |
| 160 | // is set to these values first. |
| 161 | SkColor fColor; |
| 162 | SkScalar fTextScaleX; // Zero means we don't care what the value is. |
| 163 | SkPaint::Style fTextFill; // Only if TextScaleX is non-zero. |
| 164 | int fShaderIndex; |
| 165 | int fGraphicStateIndex; |
halcanary | 2be7e01 | 2016-03-28 11:58:08 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 168 | protected: |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 169 | sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
edisonn@google.com | 73a7ea3 | 2013-11-11 20:55:15 +0000 | [diff] [blame] | 170 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 171 | void drawAnnotation(const SkRect&, const char key[], SkData* value) override; |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 172 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 173 | void drawSpecial(SkSpecialImage*, int x, int y, const SkPaint&) override; |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 174 | sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&) override; |
| 175 | sk_sp<SkSpecialImage> makeSpecial(const SkImage*) override; |
| 176 | sk_sp<SkSpecialImage> snapSpecial() override; |
brianosman | 04a44d0 | 2016-09-21 09:46:57 -0700 | [diff] [blame] | 177 | SkImageFilterCache* getImageFilterCache() override; |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 178 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 179 | private: |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 180 | struct RectWithData { |
| 181 | SkRect rect; |
halcanary | d7b2885 | 2016-03-07 12:39:14 -0800 | [diff] [blame] | 182 | sk_sp<SkData> data; |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 183 | RectWithData(const SkRect& rect, SkData* data) |
| 184 | : rect(rect), data(SkRef(data)) {} |
halcanary | 9be3720 | 2016-08-08 07:21:42 -0700 | [diff] [blame] | 185 | RectWithData(RectWithData&&) = default; |
| 186 | RectWithData& operator=(RectWithData&& other) = default; |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | struct NamedDestination { |
halcanary | d7b2885 | 2016-03-07 12:39:14 -0800 | [diff] [blame] | 190 | sk_sp<SkData> nameData; |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 191 | SkPoint point; |
| 192 | NamedDestination(SkData* nameData, const SkPoint& point) |
| 193 | : nameData(SkRef(nameData)), point(point) {} |
halcanary | 9be3720 | 2016-08-08 07:21:42 -0700 | [diff] [blame] | 194 | NamedDestination(NamedDestination&&) = default; |
| 195 | NamedDestination& operator=(NamedDestination&&) = default; |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 196 | }; |
| 197 | |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 198 | // 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] | 199 | // order to get the right access levels without using friend. |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 200 | friend class ScopedContentEntry; |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 201 | |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 202 | SkISize fPageSize; |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 203 | SkMatrix fInitialTransform; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 204 | SkClipStack fExistingClipStack; |
wangxianzhu | ef6c50a | 2015-09-17 20:38:02 -0700 | [diff] [blame] | 205 | |
halcanary | 91fcb3e | 2016-03-04 13:53:22 -0800 | [diff] [blame] | 206 | SkTArray<RectWithData> fLinkToURLs; |
| 207 | SkTArray<RectWithData> fLinkToDestinations; |
| 208 | SkTArray<NamedDestination> fNamedDestinations; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 209 | |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 210 | SkTDArray<SkPDFObject*> fGraphicStateResources; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 211 | SkTDArray<SkPDFObject*> fXObjectResources; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 212 | SkTDArray<SkPDFFont*> fFontResources; |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 213 | SkTDArray<SkPDFObject*> fShaderResources; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 214 | |
halcanary | 2be7e01 | 2016-03-28 11:58:08 -0700 | [diff] [blame] | 215 | struct ContentEntry { |
| 216 | GraphicStateEntry fState; |
| 217 | SkDynamicMemoryWStream fContent; |
| 218 | }; |
| 219 | SkSinglyLinkedList<ContentEntry> fContentEntries; |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 220 | |
commit-bot@chromium.org | 8c29490 | 2013-10-21 17:14:37 +0000 | [diff] [blame] | 221 | SkScalar fRasterDpi; |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 222 | |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 223 | SkPDFDocument* fDocument; |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 224 | //////////////////////////////////////////////////////////////////////////// |
| 225 | |
| 226 | SkPDFDevice(SkISize pageSize, |
| 227 | SkScalar rasterDpi, |
halcanary | 989da4a | 2016-03-21 14:33:17 -0700 | [diff] [blame] | 228 | SkPDFDocument* doc, |
halcanary | a1f1ee9 | 2015-02-20 06:17:26 -0800 | [diff] [blame] | 229 | bool flip); |
| 230 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 231 | SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 232 | |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 233 | void init(); |
halcanary | 3c35fb3 | 2016-06-30 11:55:07 -0700 | [diff] [blame] | 234 | void cleanUp(); |
halcanary | 4b1e17e | 2016-07-27 14:49:46 -0700 | [diff] [blame] | 235 | sk_sp<SkPDFObject> makeFormXObjectFromDevice(); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 236 | |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 237 | void drawFormXObjectWithMask(int xObjectIndex, |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 238 | sk_sp<SkPDFObject> mask, |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 239 | const SkClipStack& clipStack, |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 240 | SkBlendMode, |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 241 | bool invertClip); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 242 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 243 | // 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] | 244 | // returns nullptr and does not create a content entry. |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 245 | // setUpContentEntry and finishContentEntry can be used directly, but |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 246 | // the preferred method is to use the ScopedContentEntry helper class. |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 247 | ContentEntry* setUpContentEntry(const SkClipStack& clipStack, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 248 | const SkMatrix& matrix, |
| 249 | const SkPaint& paint, |
| 250 | bool hasText, |
halcanary | dabd4f0 | 2016-08-03 11:16:56 -0700 | [diff] [blame] | 251 | sk_sp<SkPDFObject>* dst); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 252 | void finishContentEntry(SkBlendMode, sk_sp<SkPDFObject> dst, SkPath* shape); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 253 | bool isContentEmpty(); |
| 254 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 255 | void populateGraphicStateEntryFromPaint(const SkMatrix& matrix, |
| 256 | const SkClipStack& clipStack, |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 257 | const SkPaint& paint, |
| 258 | bool hasText, |
| 259 | GraphicStateEntry* entry); |
halcanary | be27a11 | 2015-04-01 13:31:19 -0700 | [diff] [blame] | 260 | int addGraphicStateResource(SkPDFObject* gs); |
vandebo@chromium.org | 3b41621 | 2013-10-30 20:48:05 +0000 | [diff] [blame] | 261 | int addXObjectResource(SkPDFObject* xObject); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 262 | |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 263 | int getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 264 | |
halcanary | 4ed2f01 | 2016-08-15 18:40:07 -0700 | [diff] [blame] | 265 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 266 | void internalDrawText( const void*, size_t, const SkScalar pos[], |
halcanary | e06ca96 | 2016-09-09 05:34:55 -0700 | [diff] [blame] | 267 | SkTextBlob::GlyphPositioning, SkPoint, const SkPaint&, |
| 268 | const uint32_t*, uint32_t, const char*); |
halcanary | 4ed2f01 | 2016-08-15 18:40:07 -0700 | [diff] [blame] | 269 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 270 | void internalDrawPaint(const SkPaint& paint, ContentEntry* contentEntry); |
halcanary | a50151d | 2016-03-25 11:57:49 -0700 | [diff] [blame] | 271 | |
| 272 | void internalDrawImage(const SkMatrix& origMatrix, |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 273 | const SkClipStack& clipStack, |
Hal Canary | f50ff39 | 2016-09-30 10:25:39 -0400 | [diff] [blame] | 274 | SkImageSubset imageSubset, |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 275 | const SkPaint& paint); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 276 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 277 | void internalDrawPath(const SkClipStack&, |
| 278 | const SkMatrix&, |
| 279 | const SkPath&, |
| 280 | const SkPaint&, |
| 281 | const SkMatrix* prePathMatrix, |
| 282 | bool pathIsMutable); |
| 283 | |
| 284 | bool handleInversePath(const SkPath& origPath, |
edisonn@google.com | a9ebd16 | 2013-10-07 13:22:21 +0000 | [diff] [blame] | 285 | const SkPaint& paint, bool pathIsMutable, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 286 | const SkMatrix* prePathMatrix = nullptr); |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 287 | |
Mike Reed | f0fb929 | 2017-02-21 13:15:07 -0500 | [diff] [blame] | 288 | typedef SkClipStackDevice INHERITED; |
commit-bot@chromium.org | 5e00989 | 2013-10-14 13:42:12 +0000 | [diff] [blame] | 289 | |
| 290 | // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to create |
| 291 | // an SkPDFDevice |
| 292 | //friend class SkDocument_PDF; |
| 293 | //friend class SkPDFImageShader; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 294 | }; |
| 295 | |
| 296 | #endif |