Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPDFDevice.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkPDFDevice_DEFINED
9#define SkPDFDevice_DEFINED
10
13#include "include/core/SkData.h"
15#include "include/core/SkRect.h"
20#include "src/core/SkTHash.h"
24#include "src/pdf/SkPDFTypes.h"
25
26#include <vector>
27
28namespace sktext {
29class GlyphRun;
30class GlyphRunList;
31}
32
33class SkKeyedImage;
34class SkPDFArray;
35class SkPDFDevice;
36class SkPDFDict;
37class SkPDFDocument;
38class SkPDFFont;
39class SkPDFObject;
40class SkPath;
41class SkRRect;
43
44/**
45 * \class SkPDFDevice
46 *
47 * An SkPDFDevice is the drawing context for a page or layer of PDF
48 * content.
49 */
50class SkPDFDevice final : public SkClipStackDevice {
51public:
52 /**
53 * @param pageSize Page size in point units.
54 * 1 point == 127/360 mm == 1/72 inch
55 * @param document A non-null pointer back to the
56 * PDFDocument object. The document is responsible for
57 * de-duplicating across pages (via the SkPDFDocument) and
58 * for early serializing of large immutable objects, such
59 * as images (via SkPDFDocument::serialize()).
60 * @param initialTransform Transform to be applied to the entire page.
61 */
62 SkPDFDevice(SkISize pageSize, SkPDFDocument* document,
64
66 return sk_make_sp<SkPDFDevice>(this->size(), fDocument);
67 }
68
69 ~SkPDFDevice() override;
70
71 /**
72 * These are called inside the per-device-layer loop for each draw call.
73 * When these are called, we have already applied any saveLayer
74 * operations, and are handling any looping from the paint.
75 */
76 void drawPaint(const SkPaint& paint) override;
78 size_t count, const SkPoint[],
79 const SkPaint& paint) override;
80 void drawRect(const SkRect& r, const SkPaint& paint) override;
81 void drawOval(const SkRect& oval, const SkPaint& paint) override;
82 void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
83 void drawPath(const SkPath& origpath, const SkPaint& paint, bool pathIsMutable) override;
84
85 void drawImageRect(const SkImage*,
86 const SkRect* src,
87 const SkRect& dst,
88 const SkSamplingOptions&,
89 const SkPaint&,
91
92 void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override;
93 void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override;
94
95 void drawAnnotation(const SkRect&, const char key[], SkData* value) override;
96
97 void drawDevice(SkDevice*, const SkSamplingOptions&, const SkPaint&) override;
99 const SkPaint&, SkCanvas::SrcRectConstraint) override;
100
102 sk_sp<SkDevice> createDevice(const CreateInfo&, const SkPaint*) override;
103
104 // PDF specific methods.
105 void drawSprite(const SkBitmap& bitmap, int x, int y,
106 const SkPaint& paint);
107
108 /** Create the resource dictionary for this device. Destructive. */
109 std::unique_ptr<SkPDFDict> makeResourceDict();
110
111 /** Returns a SkStream with the page contents.
112 */
113 std::unique_ptr<SkStreamAsset> content();
114
115 const SkMatrix& initialTransform() const { return fInitialTransform; }
116
117protected:
120
121private:
122 // TODO(vandebo): push most of SkPDFDevice's state into a core object in
123 // order to get the right access levels without using friend.
124 friend class ScopedContentEntry;
125
126 SkMatrix fInitialTransform;
127
132 int fNodeId;
133
134 SkDynamicMemoryWStream fContent;
135 SkDynamicMemoryWStream fContentBuffer;
136 bool fNeedsExtraSave = false;
137 SkPDFGraphicStackState fActiveStackState;
138 SkPDFDocument* fDocument;
139
140 ////////////////////////////////////////////////////////////////////////////
141
142 void onDrawGlyphRunList(SkCanvas*, const sktext::GlyphRunList&, const SkPaint& paint) override;
143
144 // Set alpha to true if making a transparency group form x-objects.
145 SkPDFIndirectReference makeFormXObjectFromDevice(bool alpha = false);
146 SkPDFIndirectReference makeFormXObjectFromDevice(SkIRect bbox, bool alpha = false);
147
148 void drawFormXObjectWithMask(SkPDFIndirectReference xObject,
151 bool invertClip);
152
153 // If the paint or clip is such that we shouldn't draw anything, this
154 // returns nullptr and does not create a content entry.
155 // setUpContentEntry and finishContentEntry can be used directly, but
156 // the preferred method is to use the ScopedContentEntry helper class.
157 SkDynamicMemoryWStream* setUpContentEntry(const SkClipStack* clipStack,
158 const SkMatrix& matrix,
159 const SkPaint& paint,
160 SkScalar,
162 void finishContentEntry(const SkClipStack*, SkBlendMode, SkPDFIndirectReference, SkPath*);
163 bool isContentEmpty();
164
165 void internalDrawGlyphRun(
166 const sktext::GlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint);
167 void drawGlyphRunAsPath(
168 const sktext::GlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint);
169
170 void internalDrawImageRect(SkKeyedImage,
171 const SkRect* src,
172 const SkRect& dst,
173 const SkSamplingOptions&,
174 const SkPaint&,
175 const SkMatrix& canvasTransformationMatrix);
176
177 void internalDrawPath(const SkClipStack&,
178 const SkMatrix&,
179 const SkPath&,
180 const SkPaint&,
181 bool pathIsMutable);
182
183 void internalDrawPathWithFilter(const SkClipStack& clipStack,
184 const SkMatrix& ctm,
185 const SkPath& origPath,
186 const SkPaint& paint);
187
188 bool handleInversePath(const SkPath& origPath, const SkPaint& paint, bool pathIsMutable);
189
190 void clearMaskOnGraphicState(SkDynamicMemoryWStream*);
191 void setGraphicState(SkPDFIndirectReference gs, SkDynamicMemoryWStream*);
192 void drawFormXObject(SkPDFIndirectReference xObject, SkDynamicMemoryWStream*, SkPath* shape);
193
194 bool hasEmptyClip() const { return this->cs().isEmpty(this->bounds()); }
195
196 void reset();
197};
198
199#endif
m reset()
int count
SkBlendMode
Definition SkBlendMode.h:38
SrcRectConstraint
Definition SkCanvas.h:1541
SkClipStack & cs()
bool isEmpty(const SkIRect &deviceBounds) const
SkISize size() const
Definition SkDevice.h:126
SkIRect bounds() const
Definition SkDevice.h:125
static const SkMatrix & I()
std::unique_ptr< SkStreamAsset > content()
void drawRect(const SkRect &r, const SkPaint &paint) override
sk_sp< SkDevice > createDevice(const CreateInfo &, const SkPaint *) override
void drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint) override
~SkPDFDevice() override
void drawMesh(const SkMesh &, sk_sp< SkBlender >, const SkPaint &) override
void onDrawGlyphRunList(SkCanvas *, const sktext::GlyphRunList &, const SkPaint &paint) override
void drawVertices(const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool) override
void drawRRect(const SkRRect &rr, const SkPaint &paint) override
void drawPaint(const SkPaint &paint) override
sk_sp< SkSurface > makeSurface(const SkImageInfo &, const SkSurfaceProps &) override
void drawDevice(SkDevice *, const SkSamplingOptions &, const SkPaint &) override
void drawSpecial(SkSpecialImage *, const SkMatrix &, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
void drawSprite(const SkBitmap &bitmap, int x, int y, const SkPaint &paint)
void drawImageRect(const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
void drawOval(const SkRect &oval, const SkPaint &paint) override
void drawPath(const SkPath &origpath, const SkPaint &paint, bool pathIsMutable) override
std::unique_ptr< SkPDFDict > makeResourceDict()
void drawAnnotation(const SkRect &, const char key[], SkData *value) override
const SkMatrix & initialTransform() const
sk_sp< SkPDFDevice > makeCongruentDevice()
Definition SkPDFDevice.h:65
sk_sp< SkSpecialImage > makeSpecial(const SkBitmap &) override
const Paint & paint
float SkScalar
Definition extension.cpp:12
double y
double x
Point offset