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 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 13 | #include "SkCanvas.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 14 | #include "SkDevice.h" |
vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 15 | #include "SkPaint.h" |
| 16 | #include "SkPath.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" |
| 20 | #include "SkTScopedPtr.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 21 | |
| 22 | class SkPDFArray; |
| 23 | class SkPDFDevice; |
| 24 | class SkPDFDict; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 25 | class SkPDFFont; |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 26 | class SkPDFFormXObject; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 27 | class SkPDFGlyphSetMap; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 28 | class SkPDFGraphicState; |
| 29 | class SkPDFObject; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 30 | class SkPDFShader; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 31 | class SkPDFStream; |
| 32 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 33 | // Private classes. |
| 34 | struct ContentEntry; |
| 35 | struct GraphicStateEntry; |
| 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 | */ |
| 41 | class SkPDFDevice : public SkDevice { |
| 42 | public: |
| 43 | /** Create a PDF drawing context with the given width and height. |
| 44 | * 72 points/in means letter paper is 612x792. |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 45 | * @param pageSize Page size in points. |
| 46 | * @param contentSize The content size of the page in points. This will be |
| 47 | * combined with the initial transform to determine the drawing area |
| 48 | * (as reported by the width and height methods). Anything outside |
| 49 | * of the drawing area will be clipped. |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 50 | * @param initialTransform The initial transform to apply to the page. |
| 51 | * This may be useful to, for example, move the origin in and |
| 52 | * over a bit to account for a margin, scale the canvas, |
| 53 | * or apply a rotation. Note1: the SkPDFDevice also applies |
| 54 | * a scale+translate transform to move the origin from the |
| 55 | * bottom left (PDF default) to the top left. Note2: drawDevice |
| 56 | * (used by layer restore) draws the device after this initial |
reed@google.com | cde9211 | 2011-07-06 20:00:52 +0000 | [diff] [blame] | 57 | * transform is applied, so the PDF device does an |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 58 | * inverse scale+translate to accommodate the one that SkPDFDevice |
| 59 | * always does. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 60 | */ |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 61 | // TODO(vandebo): The sizes should be SkSize and not SkISize. |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 62 | SK_API SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, |
| 63 | const SkMatrix& initialTransform); |
| 64 | SK_API virtual ~SkPDFDevice(); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 65 | |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 66 | virtual uint32_t getDeviceCapabilities() SK_OVERRIDE; |
vandebo@chromium.org | 35fc62b | 2010-10-26 19:47:30 +0000 | [diff] [blame] | 67 | |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 68 | virtual void clear(SkColor color) SK_OVERRIDE; |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 69 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 70 | /** These are called inside the per-device-layer loop for each draw call. |
| 71 | When these are called, we have already applied any saveLayer operations, |
| 72 | and are handling any looping from the paint, and any effects from the |
| 73 | DrawFilter. |
| 74 | */ |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 75 | virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 76 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, |
| 77 | size_t count, const SkPoint[], |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 78 | const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 79 | virtual void drawRect(const SkDraw&, const SkRect& r, const SkPaint& paint); |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 80 | virtual void drawPath(const SkDraw&, const SkPath& origpath, |
vandebo@chromium.org | 02cc5aa | 2011-01-25 22:06:29 +0000 | [diff] [blame] | 81 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 82 | bool pathIsMutable) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 83 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 84 | const SkIRect* srcRectOrNull, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 85 | const SkMatrix& matrix, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 86 | 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] | 87 | const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 88 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 89 | SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 90 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
| 91 | const SkScalar pos[], SkScalar constY, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 92 | int scalarsPerPos, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 93 | virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
| 94 | const SkPath& path, const SkMatrix* matrix, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 95 | const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 96 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, |
| 97 | int vertexCount, const SkPoint verts[], |
| 98 | const SkPoint texs[], const SkColor colors[], |
| 99 | SkXfermode* xmode, const uint16_t indices[], |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 100 | int indexCount, const SkPaint& paint) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 101 | virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 102 | const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 103 | |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 104 | virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE; |
| 105 | virtual void onDetachFromCanvas() SK_OVERRIDE; |
| 106 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 107 | enum DrawingArea { |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 108 | kContent_DrawingArea, // Drawing area for the page content. |
| 109 | kMargin_DrawingArea, // Drawing area for the margin content. |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | /** 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] | 113 | * to the specific drawing area (margin or content). The default drawing |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 114 | * area is the content drawing area. |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 115 | * |
| 116 | * Currently if margin content is drawn and then a complex (for PDF) xfer |
| 117 | * mode is used, like SrcIn, Clear, etc, the margin content will get |
| 118 | * clipped. A simple way to avoid the bug is to always draw the margin |
| 119 | * content last. |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 120 | */ |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 121 | SK_API void setDrawingArea(DrawingArea drawingArea); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 122 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 123 | // PDF specific methods. |
| 124 | |
reed@google.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 125 | /** Returns the resource dictionary for this device. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 126 | */ |
reed@google.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 127 | SK_API SkPDFDict* getResourceDict(); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 128 | |
vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 129 | /** Get the list of resources (PDF objects) used on this page. |
| 130 | * @param resourceList A list to append the resources to. |
vandebo@chromium.org | 188838c | 2012-03-09 22:16:58 +0000 | [diff] [blame] | 131 | * @param recursive If recursive is true, get the resources of the |
| 132 | * device's resources recursively. (Useful for adding |
| 133 | * objects to the catalog.) |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 134 | */ |
vandebo@chromium.org | 188838c | 2012-03-09 22:16:58 +0000 | [diff] [blame] | 135 | SK_API void getResources(SkTDArray<SkPDFObject*>* resourceList, |
| 136 | bool recursive) const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 137 | |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 138 | /** Get the fonts used on this device. |
| 139 | */ |
vandebo@chromium.org | 3509f05 | 2011-05-30 20:52:33 +0000 | [diff] [blame] | 140 | SK_API const SkTDArray<SkPDFFont*>& getFontResources() const; |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 141 | |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 142 | /** Returns a copy of the media box for this device. The caller is required |
| 143 | * to unref() this when it is finished. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 144 | */ |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 145 | SK_API SkPDFArray* copyMediaBox() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 146 | |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 147 | /** 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] | 148 | */ |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 149 | SK_API SkPDFArray* getAnnotations() const { return fAnnotations; } |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 150 | |
vandebo@chromium.org | c2a9b7f | 2011-02-24 23:22:30 +0000 | [diff] [blame] | 151 | /** Returns a SkStream with the page contents. The caller is responsible |
| 152 | for a reference to the returned value. |
reed@google.com | 5667afc | 2011-06-27 14:42:15 +0000 | [diff] [blame] | 153 | DEPRECATED: use copyContentToData() |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 154 | */ |
vandebo@chromium.org | 3509f05 | 2011-05-30 20:52:33 +0000 | [diff] [blame] | 155 | SK_API SkStream* content() const; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 156 | |
reed@google.com | 5667afc | 2011-06-27 14:42:15 +0000 | [diff] [blame] | 157 | /** Returns a SkStream with the page contents. The caller is responsible |
| 158 | * for calling data->unref() when it is finished. |
| 159 | */ |
| 160 | SK_API SkData* copyContentToData() const; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 161 | |
vandebo@chromium.org | 3509f05 | 2011-05-30 20:52:33 +0000 | [diff] [blame] | 162 | SK_API const SkMatrix& initialTransform() const { |
| 163 | return fInitialTransform; |
| 164 | } |
vandebo@chromium.org | 61d2678 | 2011-05-24 23:02:07 +0000 | [diff] [blame] | 165 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 166 | /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font |
| 167 | * that shows on this device. |
| 168 | */ |
| 169 | const SkPDFGlyphSetMap& getFontGlyphUsage() const { |
| 170 | return *(fFontGlyphUsage.get()); |
| 171 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 172 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 173 | protected: |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 174 | virtual bool onReadPixels(const SkBitmap& bitmap, int x, int y, |
| 175 | SkCanvas::Config8888) SK_OVERRIDE; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 176 | |
reed@google.com | b55deeb | 2012-01-06 14:43:09 +0000 | [diff] [blame] | 177 | virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE; |
| 178 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 179 | private: |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 180 | // 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] | 181 | // order to get the right access levels without using friend. |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 182 | friend class ScopedContentEntry; |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 183 | |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 184 | SkISize fPageSize; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 185 | SkISize fContentSize; |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 186 | SkMatrix fInitialTransform; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 187 | SkClipStack fExistingClipStack; |
| 188 | SkRegion fExistingClipRegion; |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 189 | SkPDFArray* fAnnotations; |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame^] | 190 | SkPDFDict* fResourceDict; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 191 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 192 | SkTDArray<SkPDFGraphicState*> fGraphicStateResources; |
| 193 | SkTDArray<SkPDFObject*> fXObjectResources; |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 194 | SkTDArray<SkPDFFont*> fFontResources; |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 195 | SkTDArray<SkPDFObject*> fShaderResources; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 196 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 197 | SkTScopedPtr<ContentEntry> fContentEntries; |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 198 | ContentEntry* fLastContentEntry; |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 199 | SkTScopedPtr<ContentEntry> fMarginContentEntries; |
| 200 | ContentEntry* fLastMarginContentEntry; |
| 201 | DrawingArea fDrawingArea; |
| 202 | |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 203 | const SkClipStack* fClipStack; |
| 204 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 205 | // Accessor and setter functions based on the current DrawingArea. |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 206 | SkTScopedPtr<ContentEntry>* getContentEntries(); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 207 | ContentEntry* getLastContentEntry(); |
| 208 | void setLastContentEntry(ContentEntry* contentEntry); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 209 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 210 | // Glyph ids used for each font on this device. |
| 211 | SkTScopedPtr<SkPDFGlyphSetMap> fFontGlyphUsage; |
| 212 | |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 213 | SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, |
| 214 | const SkRegion& existingClipRegion); |
| 215 | |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 216 | // override from SkDevice |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 217 | virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, |
| 218 | int width, int height, |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 219 | bool isOpaque, |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 220 | Usage usage) SK_OVERRIDE; |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 221 | |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 222 | void init(); |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 223 | void cleanUp(bool clearFontUsage); |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame^] | 224 | SkPDFFormXObject* createFormXObjectFromDevice(); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 225 | |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 226 | // Clear the passed clip from all existing content entries. |
| 227 | void clearClipFromContent(const SkClipStack* clipStack, |
| 228 | const SkRegion& clipRegion); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 229 | void drawFormXObjectWithClip(SkPDFFormXObject* form, |
| 230 | const SkClipStack* clipStack, |
| 231 | const SkRegion& clipRegion, |
| 232 | bool invertClip); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 233 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 234 | // If the paint or clip is such that we shouldn't draw anything, this |
| 235 | // returns NULL and does not create a content entry. |
| 236 | // setUpContentEntry and finishContentEntry can be used directly, but |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 237 | // the preferred method is to use the ScopedContentEntry helper class. |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 238 | ContentEntry* setUpContentEntry(const SkClipStack* clipStack, |
| 239 | const SkRegion& clipRegion, |
| 240 | const SkMatrix& matrix, |
| 241 | const SkPaint& paint, |
| 242 | bool hasText, |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame^] | 243 | SkPDFFormXObject** dst); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 244 | void finishContentEntry(SkXfermode::Mode xfermode, |
| 245 | SkPDFFormXObject* dst); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 246 | bool isContentEmpty(); |
| 247 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 248 | void populateGraphicStateEntryFromPaint(const SkMatrix& matrix, |
| 249 | const SkClipStack& clipStack, |
| 250 | const SkRegion& clipRegion, |
| 251 | const SkPaint& paint, |
| 252 | bool hasText, |
| 253 | GraphicStateEntry* entry); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 254 | int addGraphicStateResource(SkPDFGraphicState* gs); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 255 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 256 | void updateFont(const SkPaint& paint, uint16_t glyphID, |
| 257 | ContentEntry* contentEntry); |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 258 | int getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 259 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 260 | void internalDrawPaint(const SkPaint& paint, ContentEntry* contentEntry); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 261 | void internalDrawBitmap(const SkMatrix& matrix, |
vandebo@chromium.org | 78dad54 | 2011-05-11 18:46:03 +0000 | [diff] [blame] | 262 | const SkClipStack* clipStack, |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 263 | const SkRegion& clipRegion, |
| 264 | const SkBitmap& bitmap, |
| 265 | const SkIRect* srcRect, |
| 266 | const SkPaint& paint); |
| 267 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 268 | /** Helper method for copyContentToData. It is responsible for copying the |
| 269 | * list of content entries |entry| to |data|. |
| 270 | */ |
| 271 | void copyContentEntriesToData(ContentEntry* entry, SkWStream* data) const; |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 272 | |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 273 | bool handleAnnotations(const SkRect& r, const SkMatrix& matrix, |
| 274 | const SkPaint& paint); |
| 275 | |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 276 | typedef SkDevice INHERITED; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | #endif |