SkPDFDevice.h revision ef6c50a80f77e6da84e198a34755dd42b1b0cf1e
19b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc.
39b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
69b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org */
79b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
89b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org#ifndef SkPDFDevice_DEFINED
99b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org#define SkPDFDevice_DEFINED
109b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
115e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.org#include "SkBitmap.h"
12b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org#include "SkCanvas.h"
13d3ebb48320cf1b7e969974673e4bd7743816985ebungeman#include "SkClipStack.h"
14d3ebb48320cf1b7e969974673e4bd7743816985ebungeman#include "SkDevice.h"
15a518086928494319b8968abc09808eff492c194fvandebo@chromium.org#include "SkPaint.h"
16a518086928494319b8968abc09808eff492c194fvandebo@chromium.org#include "SkPath.h"
17608ea6508ae2e9ea05ea863ba50fc27d44d2eae9commit-bot@chromium.org#include "SkPicture.h"
18238be8c7e5de5a83517440a3db7f7965b47fb010vandebo@chromium.org#include "SkRect.h"
199fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org#include "SkRefCnt.h"
209fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org#include "SkStream.h"
21b58772f86659cfe0e8d9247fcee878dddd8fdad9epoger@google.com#include "SkTDArray.h"
22e02944075840d672bd1797f3d945ff82d302282fcommit-bot@chromium.org#include "SkTemplates.h"
239b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
249b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.orgclass SkPDFArray;
25a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanaryclass SkPDFCanon;
269b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.orgclass SkPDFDevice;
279b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.orgclass SkPDFDict;
2828be72b63e457c680c192a34fb9f58e1c693363fvandebo@chromium.orgclass SkPDFFont;
296112c215fbdd53388e64ece36e6c7bba0fe3a451vandebo@chromium.orgclass SkPDFFormXObject;
309859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.orgclass SkPDFGlyphSetMap;
319b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.orgclass SkPDFGraphicState;
329b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.orgclass SkPDFObject;
33da912d61ede86dd3dfa8f645c6f3977f2183812bvandebo@chromium.orgclass SkPDFShader;
349b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.orgclass SkPDFStream;
35a8e33a92e27ca1523601226cad83c79a7e00c93bscroggo@google.comclass SkRRect;
369b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
379fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org// Private classes.
389fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.orgstruct ContentEntry;
399fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.orgstruct GraphicStateEntry;
40b58772f86659cfe0e8d9247fcee878dddd8fdad9epoger@google.comstruct NamedDestination;
41ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhustruct RectWithData;
429fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org
439b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org/** \class SkPDFDevice
449b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
459b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org    The drawing context for the PDF backend.
469b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org*/
4789443aba5bfa2b040dc9fd24938b7d0b3decd737reedclass SkPDFDevice : public SkBaseDevice {
489b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.orgpublic:
49a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    /** Create a PDF drawing context.  SkPDFDevice applies a
50a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *  scale-and-translate transform to move the origin from the
51a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *  bottom left (PDF default) to the top left (Skia default).
52a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *  @param pageSize Page size in point units.
53a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         1 point == 127/360 mm == 1/72 inch
54a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *  @param rasterDpi the DPI at which features without native PDF
55a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         support will be rasterized (e.g. draw image with
56a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         perspective, draw text with perspective, ...).  A
57a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         larger DPI would create a PDF that reflects the
58a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         original intent with better fidelity, but it can make
59a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         for larger PDF files too, which would use more memory
60a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         while rendering, and it would be slower to be processed
61a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         or sent online or to printer.  A good choice is
62a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         SK_ScalarDefaultRasterDPI(72.0f).
63a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *  @param SkPDFCanon.  Should be non-null, and shared by all
64a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary     *         devices in a document.
659b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org     */
66a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    static SkPDFDevice* Create(SkISize pageSize,
67a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary                               SkScalar rasterDpi,
68a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary                               SkPDFCanon* canon) {
69385fe4d4b62d7d1dd76116dd570df3290a2f487bhalcanary        return new SkPDFDevice(pageSize, rasterDpi, canon, true);
70a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    }
71a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary
72a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    /** Create a PDF drawing context without fipping the y-axis. */
73a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    static SkPDFDevice* CreateUnflipped(SkISize pageSize,
74a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary                                        SkScalar rasterDpi,
75a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary                                        SkPDFCanon* canon) {
76385fe4d4b62d7d1dd76116dd570df3290a2f487bhalcanary        return new SkPDFDevice(pageSize, rasterDpi, canon, false);
77a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    }
78a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary
79a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    virtual ~SkPDFDevice();
809b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
819b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org    /** These are called inside the per-device-layer loop for each draw call.
829b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org     When these are called, we have already applied any saveLayer operations,
839b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org     and are handling any looping from the paint, and any effects from the
849b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org     DrawFilter.
859b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org     */
8636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void drawPaint(const SkDraw&, const SkPaint& paint) override;
87fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina    void drawPoints(const SkDraw&, SkCanvas::PointMode mode,
88fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina                    size_t count, const SkPoint[],
8936352bf5e38f45a70ee4f4fc132a38048d38206dmtklein                    const SkPaint& paint) override;
9036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void drawRect(const SkDraw&, const SkRect& r, const SkPaint& paint) override;
9136352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void drawOval(const SkDraw&, const SkRect& oval, const SkPaint& paint) override;
9236352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void drawRRect(const SkDraw&, const SkRRect& rr, const SkPaint& paint) override;
93fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina    void drawPath(const SkDraw&, const SkPath& origpath,
94fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina                  const SkPaint& paint, const SkMatrix* prePathMatrix,
9536352bf5e38f45a70ee4f4fc132a38048d38206dmtklein                  bool pathIsMutable) override;
96562fe4767cc73e08a4e039362bc0336aea66ecfbreed    void drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, const SkRect* src,
97562fe4767cc73e08a4e039362bc0336aea66ecfbreed                        const SkRect& dst, const SkPaint&, SkCanvas::SrcRectConstraint) override;
98fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina    void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
9936352bf5e38f45a70ee4f4fc132a38048d38206dmtklein                    const SkMatrix& matrix, const SkPaint&) override;
100fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina    void drawSprite(const SkDraw&, const SkBitmap& bitmap, int x, int y,
10136352bf5e38f45a70ee4f4fc132a38048d38206dmtklein                    const SkPaint& paint) override;
102fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina    void drawText(const SkDraw&, const void* text, size_t len,
10336352bf5e38f45a70ee4f4fc132a38048d38206dmtklein                  SkScalar x, SkScalar y, const SkPaint&) override;
104fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina    void drawPosText(const SkDraw&, const void* text, size_t len,
105fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina                     const SkScalar pos[], int scalarsPerPos,
10636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein                     const SkPoint& offset, const SkPaint&) override;
107fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina    void drawVertices(const SkDraw&, SkCanvas::VertexMode,
108fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina                      int vertexCount, const SkPoint verts[],
109fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina                      const SkPoint texs[], const SkColor colors[],
110fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina                      SkXfermode* xmode, const uint16_t indices[],
11136352bf5e38f45a70ee4f4fc132a38048d38206dmtklein                      int indexCount, const SkPaint& paint) override;
112fa4f6cba2f9260cec345ec51fb3687c20c50fa61tfarina    void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
11336352bf5e38f45a70ee4f4fc132a38048d38206dmtklein                    const SkPaint&) override;
1149b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
11536352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onAttachToCanvas(SkCanvas* canvas) override;
11636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onDetachFromCanvas() override;
11736352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkImageInfo imageInfo() const override;
11840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com
1198dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org    enum DrawingArea {
1209510ccc06bbfa5e888f66578042674be98d8ac60ctguil@chromium.org        kContent_DrawingArea,  // Drawing area for the page content.
1219510ccc06bbfa5e888f66578042674be98d8ac60ctguil@chromium.org        kMargin_DrawingArea,   // Drawing area for the margin content.
1228dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org    };
1238dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org
1248dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org    /** Sets the drawing area for the device. Subsequent draw calls are directed
125769fa6a013baca6d7404e2bf096a34a7e3635fa5ctguil@chromium.org     *  to the specific drawing area (margin or content). The default drawing
1268dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org     *  area is the content drawing area.
1279510ccc06bbfa5e888f66578042674be98d8ac60ctguil@chromium.org     *
1289510ccc06bbfa5e888f66578042674be98d8ac60ctguil@chromium.org     *  Currently if margin content is drawn and then a complex (for PDF) xfer
1299510ccc06bbfa5e888f66578042674be98d8ac60ctguil@chromium.org     *  mode is used, like SrcIn, Clear, etc, the margin content will get
1309510ccc06bbfa5e888f66578042674be98d8ac60ctguil@chromium.org     *  clipped. A simple way to avoid the bug is to always draw the margin
1319510ccc06bbfa5e888f66578042674be98d8ac60ctguil@chromium.org     *  content last.
1328dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org     */
1334e4e8160459f68c1795f2297bcec6f7866e01fa8halcanary    void setDrawingArea(DrawingArea drawingArea);
1348dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org
1359b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org    // PDF specific methods.
1369b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
1376d622703e578eddc64ab4e3340d0ab0033268799halcanary    /** Create the resource dictionary for this device.
1389b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org     */
1392b86155b42c2493ff0c558ce105a464769962274halcanary    SkPDFDict* createResourceDict() const;
1409b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
141f0ec2666d9a3f0f1662f0d63b5147628c49648aavandebo@chromium.org    /** Get the fonts used on this device.
142f0ec2666d9a3f0f1662f0d63b5147628c49648aavandebo@chromium.org     */
1434e4e8160459f68c1795f2297bcec6f7866e01fa8halcanary    const SkTDArray<SkPDFFont*>& getFontResources() const;
144f0ec2666d9a3f0f1662f0d63b5147628c49648aavandebo@chromium.org
145ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu    /** Add our annotations (link to urls and destinations) to the supplied
146ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu     *  array.
147ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu     *  @param array Array to add annotations to.
148ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu     */
149ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu    void appendAnnotations(SkPDFArray* array) const;
150ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu
151b58772f86659cfe0e8d9247fcee878dddd8fdad9epoger@google.com    /** Add our named destinations to the supplied dictionary.
152b58772f86659cfe0e8d9247fcee878dddd8fdad9epoger@google.com     *  @param dict  Dictionary to add destinations to.
153b58772f86659cfe0e8d9247fcee878dddd8fdad9epoger@google.com     *  @param page  The PDF object representing the page for this device.
154b58772f86659cfe0e8d9247fcee878dddd8fdad9epoger@google.com     */
1556d622703e578eddc64ab4e3340d0ab0033268799halcanary    void appendDestinations(SkPDFDict* dict, SkPDFObject* page) const;
156b58772f86659cfe0e8d9247fcee878dddd8fdad9epoger@google.com
1572a006c112743e07ce258ca223631fc19233f5ddcreed@google.com    /** Returns a copy of the media box for this device. The caller is required
1582a006c112743e07ce258ca223631fc19233f5ddcreed@google.com     *  to unref() this when it is finished.
1599b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org     */
1604e4e8160459f68c1795f2297bcec6f7866e01fa8halcanary    SkPDFArray* copyMediaBox() const;
1619b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
162c2a9b7fe5640af8f0c371561f1ac71b045d6d8ecvandebo@chromium.org    /** Returns a SkStream with the page contents.  The caller is responsible
1634e4e8160459f68c1795f2297bcec6f7866e01fa8halcanary     *  for a deleting the returned value.
1649b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org     */
1654e4e8160459f68c1795f2297bcec6f7866e01fa8halcanary    SkStreamAsset* content() const;
1669b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
167334fcbc167237f02058cb508cb5f51b718141461halcanary    /** Writes the page contents to the stream. */
1684e4e8160459f68c1795f2297bcec6f7866e01fa8halcanary    void writeContent(SkWStream*) const;
1699859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org
1704e4e8160459f68c1795f2297bcec6f7866e01fa8halcanary    const SkMatrix& initialTransform() const {
1713509f050810ab95cc36265f3b486b9569799041dvandebo@chromium.org        return fInitialTransform;
1723509f050810ab95cc36265f3b486b9569799041dvandebo@chromium.org    }
17361d267879bdf85c84b05f0519eb53b9322abbf0evandebo@chromium.org
1749859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org    /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font
1759859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org     *  that shows on this device.
1769859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org     */
1779859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org    const SkPDFGlyphSetMap& getFontGlyphUsage() const {
1789859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org        return *(fFontGlyphUsage.get());
1799859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org    }
18074b461961607fa57a150a9282c410ef0cab38764vandebo@chromium.org
18126b5d15dab81883fac05a2d3685ca6e3a3459678halcanary#ifdef SK_DEBUG
18226b5d15dab81883fac05a2d3685ca6e3a3459678halcanary    SkPDFCanon* getCanon() const { return fCanon; }
18326b5d15dab81883fac05a2d3685ca6e3a3459678halcanary#endif  // SK_DEBUG
18426b5d15dab81883fac05a2d3685ca6e3a3459678halcanary
18573a7ea3ae0d37ee28f90d6b38c49fda052638253edisonn@google.comprotected:
18636352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    const SkBitmap& onAccessBitmap() override {
18789443aba5bfa2b040dc9fd24938b7d0b3decd737reed        return fLegacyBitmap;
18889443aba5bfa2b040dc9fd24938b7d0b3decd737reed    }
18989443aba5bfa2b040dc9fd24938b7d0b3decd737reed
19036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override;
19173a7ea3ae0d37ee28f90d6b38c49fda052638253edisonn@google.com
1929b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.orgprivate:
193769fa6a013baca6d7404e2bf096a34a7e3635fa5ctguil@chromium.org    // TODO(vandebo): push most of SkPDFDevice's state into a core object in
194b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org    // order to get the right access levels without using friend.
19513d14a9dbd2cf0a9654045cc967e92626690631avandebo@chromium.org    friend class ScopedContentEntry;
196a0c7edbb0804144ab320951db5c741eea247fc0fvandebo@chromium.org
197152612938020fa46999f33668027d5bc0f7afd18ctguil@chromium.org    SkISize fPageSize;
1989fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org    SkISize fContentSize;
19975f97e452e8f2ee55cd2b283df7d7734f48bc2bfvandebo@chromium.org    SkMatrix fInitialTransform;
2009fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org    SkClipStack fExistingClipStack;
2019fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org    SkRegion fExistingClipRegion;
202ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu
203ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu    SkTDArray<RectWithData*> fLinkToURLs;
204ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu    SkTDArray<RectWithData*> fLinkToDestinations;
205b58772f86659cfe0e8d9247fcee878dddd8fdad9epoger@google.com    SkTDArray<NamedDestination*> fNamedDestinations;
2069b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
207be27a118c277af23377d38e9b3bfd3fcc276114fhalcanary    SkTDArray<SkPDFObject*> fGraphicStateResources;
2089b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org    SkTDArray<SkPDFObject*> fXObjectResources;
20928be72b63e457c680c192a34fb9f58e1c693363fvandebo@chromium.org    SkTDArray<SkPDFFont*> fFontResources;
210421d6443fbd3a913dfa32b6492c4a2969bc6314bvandebo@chromium.org    SkTDArray<SkPDFObject*> fShaderResources;
2119b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
212e02944075840d672bd1797f3d945ff82d302282fcommit-bot@chromium.org    SkAutoTDelete<ContentEntry> fContentEntries;
213b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org    ContentEntry* fLastContentEntry;
214e02944075840d672bd1797f3d945ff82d302282fcommit-bot@chromium.org    SkAutoTDelete<ContentEntry> fMarginContentEntries;
2158dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org    ContentEntry* fLastMarginContentEntry;
2168dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org    DrawingArea fDrawingArea;
2178dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org
21840a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com    const SkClipStack* fClipStack;
21940a1ae4df28810aa5aa5cf2627d8387b2dfb867arobertphillips@google.com
2208dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org    // Accessor and setter functions based on the current DrawingArea.
221e02944075840d672bd1797f3d945ff82d302282fcommit-bot@chromium.org    SkAutoTDelete<ContentEntry>* getContentEntries();
2229b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
2239859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org    // Glyph ids used for each font on this device.
224e02944075840d672bd1797f3d945ff82d302282fcommit-bot@chromium.org    SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage;
2259859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org
2268c294900f31d8d032b62182f011019276d27d5d0commit-bot@chromium.org    SkScalar fRasterDpi;
227d9dfa18372119c8e1318125d2075fa80e0819094edisonn@google.com
22889443aba5bfa2b040dc9fd24938b7d0b3decd737reed    SkBitmap fLegacyBitmap;
22989443aba5bfa2b040dc9fd24938b7d0b3decd737reed
230a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    SkPDFCanon* fCanon;  // Owned by SkDocument_PDF
231a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    ////////////////////////////////////////////////////////////////////////////
232a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary
233a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    SkPDFDevice(SkISize pageSize,
234a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary                SkScalar rasterDpi,
235a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary                SkPDFCanon* canon,
236a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary                bool flip);
237a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary
238a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    ContentEntry* getLastContentEntry();
239a1f1ee98a1f6d0770f6243270ca2f0e6c92efabahalcanary    void setLastContentEntry(ContentEntry* contentEntry);
240a0c7edbb0804144ab320951db5c741eea247fc0fvandebo@chromium.org
24136352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
242e97f0856a8044866b12527819d14cdfbcdfd96f2bsalomon@google.com
24377bcaa324a574584331322d98768582d9232f7fcvandebo@chromium.org    void init();
2449859428e71c6041928e6dd741ae3284017e78e81vandebo@chromium.org    void cleanUp(bool clearFontUsage);
245fc641d09e5a1a9f7fae369ae06a8b96089faf57breed@google.com    SkPDFFormXObject* createFormXObjectFromDevice();
2469fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org
2473b416216d1e90cb8b1bba41bb95806fe2d40da88vandebo@chromium.org    void drawFormXObjectWithMask(int xObjectIndex,
2483b416216d1e90cb8b1bba41bb95806fe2d40da88vandebo@chromium.org                                 SkPDFFormXObject* mask,
249481aef68333e01c19badda456d8e60bd1f1bee2avandebo@chromium.org                                 const SkClipStack* clipStack,
250481aef68333e01c19badda456d8e60bd1f1bee2avandebo@chromium.org                                 const SkRegion& clipRegion,
2513b416216d1e90cb8b1bba41bb95806fe2d40da88vandebo@chromium.org                                 SkXfermode::Mode mode,
252481aef68333e01c19badda456d8e60bd1f1bee2avandebo@chromium.org                                 bool invertClip);
253466f3d66f09285d2d988315bacde573a5359ce54vandebo@chromium.org
254b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org    // If the paint or clip is such that we shouldn't draw anything, this
25596fcdcc219d2a0d3579719b84b28bede76efba64halcanary    // returns nullptr and does not create a content entry.
256b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org    // setUpContentEntry and finishContentEntry can be used directly, but
25713d14a9dbd2cf0a9654045cc967e92626690631avandebo@chromium.org    // the preferred method is to use the ScopedContentEntry helper class.
258b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org    ContentEntry* setUpContentEntry(const SkClipStack* clipStack,
259b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org                                    const SkRegion& clipRegion,
260b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org                                    const SkMatrix& matrix,
261b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org                                    const SkPaint& paint,
262b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org                                    bool hasText,
263fc641d09e5a1a9f7fae369ae06a8b96089faf57breed@google.com                                    SkPDFFormXObject** dst);
264b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org    void finishContentEntry(SkXfermode::Mode xfermode,
2653b416216d1e90cb8b1bba41bb95806fe2d40da88vandebo@chromium.org                            SkPDFFormXObject* dst,
2663b416216d1e90cb8b1bba41bb95806fe2d40da88vandebo@chromium.org                            SkPath* shape);
267481aef68333e01c19badda456d8e60bd1f1bee2avandebo@chromium.org    bool isContentEmpty();
268481aef68333e01c19badda456d8e60bd1f1bee2avandebo@chromium.org
2699fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org    void populateGraphicStateEntryFromPaint(const SkMatrix& matrix,
2709fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org                                            const SkClipStack& clipStack,
2719fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org                                            const SkRegion& clipRegion,
2729fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org                                            const SkPaint& paint,
2739fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org                                            bool hasText,
2749fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org                                            GraphicStateEntry* entry);
275be27a118c277af23377d38e9b3bfd3fcc276114fhalcanary    int addGraphicStateResource(SkPDFObject* gs);
2763b416216d1e90cb8b1bba41bb95806fe2d40da88vandebo@chromium.org    int addXObjectResource(SkPDFObject* xObject);
2779fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org
2788e0c1500a78f450115ce1a8de438d66e2e892cdcrobertphillips    void updateFont(const SkPaint& paint, uint16_t glyphID, ContentEntry* contentEntry);
2799db86bb9cd1b77be0afc504ccc07026e4282d7e7ctguil@chromium.org    int getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID);
2809fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org
281b069c8cfcd5df285193eb334b3bc33438782e8davandebo@chromium.org    void internalDrawPaint(const SkPaint& paint, ContentEntry* contentEntry);
2829fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org    void internalDrawBitmap(const SkMatrix& matrix,
28378dad54080ad806be89adb5cc0e3c530b031cdafvandebo@chromium.org                            const SkClipStack* clipStack,
2849fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org                            const SkRegion& clipRegion,
2859fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org                            const SkBitmap& bitmap,
2869fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org                            const SkIRect* srcRect,
2879fbdf875183f5142b8e0ba46ab430cc46ad701bfvandebo@chromium.org                            const SkPaint& paint);
2889b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
2898dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org    /** Helper method for copyContentToData. It is responsible for copying the
2908dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org     *  list of content entries |entry| to |data|.
2918dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org     */
2928dcf74f27690476193f5d4ca34fba2e87ca7c98dctguil@chromium.org    void copyContentEntriesToData(ContentEntry* entry, SkWStream* data) const;
2939510ccc06bbfa5e888f66578042674be98d8ac60ctguil@chromium.org
29492ffe7d10ef5db05f1f4ffef0cfe898169ba13bfcommit-bot@chromium.org    bool handleInversePath(const SkDraw& d, const SkPath& origPath,
295a9ebd161a7c08515f0c4bd885e61c4b52688ececedisonn@google.com                           const SkPaint& paint, bool pathIsMutable,
29696fcdcc219d2a0d3579719b84b28bede76efba64halcanary                           const SkMatrix* prePathMatrix = nullptr);
297b58772f86659cfe0e8d9247fcee878dddd8fdad9epoger@google.com    bool handlePointAnnotation(const SkPoint* points, size_t count,
298d76665da1c93372720506ce7763cc810223ee9eewangxianzhu                               const SkMatrix& matrix, SkAnnotation* annot);
299ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu    bool handlePathAnnotation(const SkPath& path, const SkDraw& d,
300ef6c50a80f77e6da84e198a34755dd42b1b0cf1ewangxianzhu                              SkAnnotation* annot);
301238be8c7e5de5a83517440a3db7f7965b47fb010vandebo@chromium.org
30289443aba5bfa2b040dc9fd24938b7d0b3decd737reed    typedef SkBaseDevice INHERITED;
3035e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.org
3045e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.org    // TODO(edisonn): Only SkDocument_PDF and SkPDFImageShader should be able to create
3055e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.org    // an SkPDFDevice
3065e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.org    //friend class SkDocument_PDF;
3075e00989a283111cef05bed8102e45c16651e43e4commit-bot@chromium.org    //friend class SkPDFImageShader;
3089b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org};
3099b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org
3109b49dc0db8254e3dcdc2de4a1e0add4f8a7ac5a8vandebo@chromium.org#endif
311