| OLD | NEW | 
|---|
| 1 | 1 | 
| 2 /* | 2 /* | 
| 3  * Copyright 2011 Google Inc. | 3  * Copyright 2011 Google Inc. | 
| 4  * | 4  * | 
| 5  * Use of this source code is governed by a BSD-style license that can be | 5  * Use of this source code is governed by a BSD-style license that can be | 
| 6  * found in the LICENSE file. | 6  * found in the LICENSE file. | 
| 7  */ | 7  */ | 
| 8 | 8 | 
| 9 | 9 | 
| 10 #ifndef SkPDFDevice_DEFINED | 10 #ifndef SkPDFDevice_DEFINED | 
| 11 #define SkPDFDevice_DEFINED | 11 #define SkPDFDevice_DEFINED | 
| 12 | 12 | 
| 13 #include "SkBitmapDevice.h" | 13 #include "SkDevice.h" | 
| 14 #include "SkBitmap.h" | 14 #include "SkBitmap.h" | 
| 15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" | 
| 16 #include "SkPaint.h" | 16 #include "SkPaint.h" | 
| 17 #include "SkPath.h" | 17 #include "SkPath.h" | 
| 18 #include "SkPicture.h" | 18 #include "SkPicture.h" | 
| 19 #include "SkRect.h" | 19 #include "SkRect.h" | 
| 20 #include "SkRefCnt.h" | 20 #include "SkRefCnt.h" | 
| 21 #include "SkStream.h" | 21 #include "SkStream.h" | 
| 22 #include "SkTDArray.h" | 22 #include "SkTDArray.h" | 
| 23 #include "SkTemplates.h" | 23 #include "SkTemplates.h" | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 38 | 38 | 
| 39 // Private classes. | 39 // Private classes. | 
| 40 struct ContentEntry; | 40 struct ContentEntry; | 
| 41 struct GraphicStateEntry; | 41 struct GraphicStateEntry; | 
| 42 struct NamedDestination; | 42 struct NamedDestination; | 
| 43 | 43 | 
| 44 /** \class SkPDFDevice | 44 /** \class SkPDFDevice | 
| 45 | 45 | 
| 46     The drawing context for the PDF backend. | 46     The drawing context for the PDF backend. | 
| 47 */ | 47 */ | 
| 48 class SkPDFDevice : public SkBitmapDevice { | 48 class SkPDFDevice : public SkBaseDevice { | 
| 49 public: | 49 public: | 
| 50     /** Create a PDF drawing context with the given width and height. | 50     /** Create a PDF drawing context with the given width and height. | 
| 51      *  72 points/in means letter paper is 612x792. | 51      *  72 points/in means letter paper is 612x792. | 
| 52      *  @param pageSize Page size in points. | 52      *  @param pageSize Page size in points. | 
| 53      *  @param contentSize The content size of the page in points. This will be | 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 | 54      *         combined with the initial transform to determine the drawing area | 
| 55      *         (as reported by the width and height methods). Anything outside | 55      *         (as reported by the width and height methods). Anything outside | 
| 56      *         of the drawing area will be clipped. | 56      *         of the drawing area will be clipped. | 
| 57      *  @param initialTransform The initial transform to apply to the page. | 57      *  @param initialTransform The initial transform to apply to the page. | 
| 58      *         This may be useful to, for example, move the origin in and | 58      *         This may be useful to, for example, move the origin in and | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 75     /** These are called inside the per-device-layer loop for each draw call. | 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, | 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 | 77      and are handling any looping from the paint, and any effects from the | 
| 78      DrawFilter. | 78      DrawFilter. | 
| 79      */ | 79      */ | 
| 80     virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; | 80     virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; | 
| 81     virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, | 81     virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, | 
| 82                             size_t count, const SkPoint[], | 82                             size_t count, const SkPoint[], | 
| 83                             const SkPaint& paint) SK_OVERRIDE; | 83                             const SkPaint& paint) SK_OVERRIDE; | 
| 84     virtual void drawRect(const SkDraw&, const SkRect& r, const SkPaint& paint); | 84     virtual void drawRect(const SkDraw&, const SkRect& r, const SkPaint& paint); | 
| 85     virtual void drawRRect(const SkDraw&, const SkRRect& rr, | 85     virtual void drawOval(const SkDraw&, const SkRect& oval, const SkPaint& pain
     t) SK_OVERRIDE; | 
| 86                            const SkPaint& paint) SK_OVERRIDE; | 86     virtual void drawRRect(const SkDraw&, const SkRRect& rr, const SkPaint& pain
     t) SK_OVERRIDE; | 
| 87     virtual void drawPath(const SkDraw&, const SkPath& origpath, | 87     virtual void drawPath(const SkDraw&, const SkPath& origpath, | 
| 88                           const SkPaint& paint, const SkMatrix* prePathMatrix, | 88                           const SkPaint& paint, const SkMatrix* prePathMatrix, | 
| 89                           bool pathIsMutable) SK_OVERRIDE; | 89                           bool pathIsMutable) SK_OVERRIDE; | 
| 90     virtual void drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | 90     virtual void drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | 
| 91                                 const SkRect* src, const SkRect& dst, | 91                                 const SkRect* src, const SkRect& dst, | 
| 92                                 const SkPaint& paint, | 92                                 const SkPaint& paint, | 
| 93                                 SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE
     ; | 93                                 SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE
     ; | 
| 94     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, | 94     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, | 
| 95                             const SkMatrix& matrix, const SkPaint&) SK_OVERRIDE; | 95                             const SkMatrix& matrix, const SkPaint&) SK_OVERRIDE; | 
| 96     virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, int x, int y, | 96     virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, int x, int y, | 
| 97                             const SkPaint& paint) SK_OVERRIDE; | 97                             const SkPaint& paint) SK_OVERRIDE; | 
| 98     virtual void drawText(const SkDraw&, const void* text, size_t len, | 98     virtual void drawText(const SkDraw&, const void* text, size_t len, | 
| 99                           SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE; | 99                           SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE; | 
| 100     virtual void drawPosText(const SkDraw&, const void* text, size_t len, | 100     virtual void drawPosText(const SkDraw&, const void* text, size_t len, | 
| 101                              const SkScalar pos[], SkScalar constY, | 101                              const SkScalar pos[], SkScalar constY, | 
| 102                              int scalarsPerPos, const SkPaint&) SK_OVERRIDE; | 102                              int scalarsPerPos, const SkPaint&) SK_OVERRIDE; | 
| 103     virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, | 103     virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, | 
| 104                                 const SkPath& path, const SkMatrix* matrix, | 104                                 const SkPath& path, const SkMatrix* matrix, | 
| 105                                 const SkPaint& paint) SK_OVERRIDE; | 105                                 const SkPaint& paint) SK_OVERRIDE; | 
| 106     virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, | 106     virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, | 
| 107                               int vertexCount, const SkPoint verts[], | 107                               int vertexCount, const SkPoint verts[], | 
| 108                               const SkPoint texs[], const SkColor colors[], | 108                               const SkPoint texs[], const SkColor colors[], | 
| 109                               SkXfermode* xmode, const uint16_t indices[], | 109                               SkXfermode* xmode, const uint16_t indices[], | 
| 110                               int indexCount, const SkPaint& paint) SK_OVERRIDE; | 110                               int indexCount, const SkPaint& paint) SK_OVERRIDE; | 
| 111     virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, | 111     virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, | 
| 112                             const SkPaint&) SK_OVERRIDE; | 112                             const SkPaint&) SK_OVERRIDE; | 
| 113 | 113 | 
| 114     virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE; | 114     virtual void onAttachToCanvas(SkCanvas* canvas) SK_OVERRIDE; | 
| 115     virtual void onDetachFromCanvas() SK_OVERRIDE; | 115     virtual void onDetachFromCanvas() SK_OVERRIDE; | 
|  | 116     virtual SkImageInfo imageInfo() const SK_OVERRIDE; | 
| 116 | 117 | 
| 117     enum DrawingArea { | 118     enum DrawingArea { | 
| 118         kContent_DrawingArea,  // Drawing area for the page content. | 119         kContent_DrawingArea,  // Drawing area for the page content. | 
| 119         kMargin_DrawingArea,   // Drawing area for the margin content. | 120         kMargin_DrawingArea,   // Drawing area for the margin content. | 
| 120     }; | 121     }; | 
| 121 | 122 | 
| 122     /** Sets the drawing area for the device. Subsequent draw calls are directed | 123     /** Sets the drawing area for the device. Subsequent draw calls are directed | 
| 123      *  to the specific drawing area (margin or content). The default drawing | 124      *  to the specific drawing area (margin or content). The default drawing | 
| 124      *  area is the content drawing area. | 125      *  area is the content drawing area. | 
| 125      * | 126      * | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 201      *              intent with better fidelity, but it can make for larger | 202      *              intent with better fidelity, but it can make for larger | 
| 202      *              PDF files too, which would use more memory while rendering, | 203      *              PDF files too, which would use more memory while rendering, | 
| 203      *              and it would be slower to be processed or sent online or | 204      *              and it would be slower to be processed or sent online or | 
| 204      *              to printer. | 205      *              to printer. | 
| 205      */ | 206      */ | 
| 206     void setRasterDpi(SkScalar rasterDpi) { | 207     void setRasterDpi(SkScalar rasterDpi) { | 
| 207         fRasterDpi = rasterDpi; | 208         fRasterDpi = rasterDpi; | 
| 208     } | 209     } | 
| 209 | 210 | 
| 210 protected: | 211 protected: | 
| 211     virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE; | 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 | 
|  | 220     virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE; | 
| 212 | 221 | 
| 213 private: | 222 private: | 
| 214     // TODO(vandebo): push most of SkPDFDevice's state into a core object in | 223     // TODO(vandebo): push most of SkPDFDevice's state into a core object in | 
| 215     // order to get the right access levels without using friend. | 224     // order to get the right access levels without using friend. | 
| 216     friend class ScopedContentEntry; | 225     friend class ScopedContentEntry; | 
| 217 | 226 | 
| 218     SkISize fPageSize; | 227     SkISize fPageSize; | 
| 219     SkISize fContentSize; | 228     SkISize fContentSize; | 
| 220     SkMatrix fInitialTransform; | 229     SkMatrix fInitialTransform; | 
| 221     SkClipStack fExistingClipStack; | 230     SkClipStack fExistingClipStack; | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 241     SkAutoTDelete<ContentEntry>* getContentEntries(); | 250     SkAutoTDelete<ContentEntry>* getContentEntries(); | 
| 242     ContentEntry* getLastContentEntry(); | 251     ContentEntry* getLastContentEntry(); | 
| 243     void setLastContentEntry(ContentEntry* contentEntry); | 252     void setLastContentEntry(ContentEntry* contentEntry); | 
| 244 | 253 | 
| 245     // Glyph ids used for each font on this device. | 254     // Glyph ids used for each font on this device. | 
| 246     SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage; | 255     SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage; | 
| 247 | 256 | 
| 248     SkPicture::EncodeBitmap fEncoder; | 257     SkPicture::EncodeBitmap fEncoder; | 
| 249     SkScalar fRasterDpi; | 258     SkScalar fRasterDpi; | 
| 250 | 259 | 
|  | 260     SkBitmap fLegacyBitmap; | 
|  | 261 | 
| 251     SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, | 262     SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack, | 
| 252                 const SkRegion& existingClipRegion); | 263                 const SkRegion& existingClipRegion); | 
| 253 | 264 | 
| 254     // override from SkBaseDevice | 265     // override from SkBaseDevice | 
| 255     virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; | 266     virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; | 
| 256 | 267 | 
| 257     void init(); | 268     void init(); | 
| 258     void cleanUp(bool clearFontUsage); | 269     void cleanUp(bool clearFontUsage); | 
| 259     SkPDFFormXObject* createFormXObjectFromDevice(); | 270     SkPDFFormXObject* createFormXObjectFromDevice(); | 
| 260 | 271 | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 316     bool handlePointAnnotation(const SkPoint* points, size_t count, | 327     bool handlePointAnnotation(const SkPoint* points, size_t count, | 
| 317                                const SkMatrix& matrix, const SkPaint& paint); | 328                                const SkMatrix& matrix, const SkPaint& paint); | 
| 318     SkPDFDict* createLinkAnnotation(const SkRect& r, const SkMatrix& matrix); | 329     SkPDFDict* createLinkAnnotation(const SkRect& r, const SkMatrix& matrix); | 
| 319     void handleLinkToURL(SkData* urlData, const SkRect& r, | 330     void handleLinkToURL(SkData* urlData, const SkRect& r, | 
| 320                          const SkMatrix& matrix); | 331                          const SkMatrix& matrix); | 
| 321     void handleLinkToNamedDest(SkData* nameData, const SkRect& r, | 332     void handleLinkToNamedDest(SkData* nameData, const SkRect& r, | 
| 322                                const SkMatrix& matrix); | 333                                const SkMatrix& matrix); | 
| 323     void defineNamedDestination(SkData* nameData, const SkPoint& point, | 334     void defineNamedDestination(SkData* nameData, const SkPoint& point, | 
| 324                                 const SkMatrix& matrix); | 335                                 const SkMatrix& matrix); | 
| 325 | 336 | 
| 326     typedef SkBitmapDevice INHERITED; | 337     typedef SkBaseDevice INHERITED; | 
| 327 | 338 | 
| 328     // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to
      create | 339     // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to
      create | 
| 329     // an SkPDFDevice | 340     // an SkPDFDevice | 
| 330     //friend class SkDocument_PDF; | 341     //friend class SkDocument_PDF; | 
| 331     //friend class SkPDFImageShader; | 342     //friend class SkPDFImageShader; | 
| 332 }; | 343 }; | 
| 333 | 344 | 
| 334 #endif | 345 #endif | 
| OLD | NEW | 
|---|