Flutter Engine
The Flutter Engine
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
19#include "src/core/SkTHash.h"
22#include "src/pdf/SkPDFTypes.h"
23
24#include <cstddef>
25#include <memory>
26
27class SkBitmap;
28class SkBlender;
29class SkData;
30class SkDevice;
31class SkImage;
32class SkMesh;
33class SkPDFDocument;
34class SkPaint;
35class SkPath;
36class SkRRect;
37class SkSpecialImage;
38class SkSurface;
39class SkSurfaceProps;
40class SkVertices;
41enum class SkBlendMode;
42struct SkIRect;
43struct SkISize;
44struct SkImageInfo;
45struct SkPoint;
46struct SkRect;
47
48namespace sktext {
49class GlyphRun;
50class GlyphRunList;
51}
52
53/**
54 * \class SkPDFDevice
55 *
56 * An SkPDFDevice is the drawing context for a page or layer of PDF
57 * content.
58 */
59class SkPDFDevice final : public SkClipStackDevice {
60public:
61 /**
62 * @param pageSize Page size in point units.
63 * 1 point == 127/360 mm == 1/72 inch
64 * @param document A non-null pointer back to the
65 * PDFDocument object. The document is responsible for
66 * de-duplicating across pages (via the SkPDFDocument) and
67 * for early serializing of large immutable objects, such
68 * as images (via SkPDFDocument::serialize()).
69 * @param initialTransform Transform to be applied to the entire page.
70 */
71 SkPDFDevice(SkISize pageSize, SkPDFDocument* document,
73
75 return sk_make_sp<SkPDFDevice>(this->size(), fDocument);
76 }
77
78 ~SkPDFDevice() override;
79
80 /**
81 * These are called inside the per-device-layer loop for each draw call.
82 * When these are called, we have already applied any saveLayer
83 * operations, and are handling any looping from the paint.
84 */
85 void drawPaint(const SkPaint& paint) override;
87 size_t count, const SkPoint[],
88 const SkPaint& paint) override;
89 void drawRect(const SkRect& r, const SkPaint& paint) override;
90 void drawOval(const SkRect& oval, const SkPaint& paint) override;
91 void drawRRect(const SkRRect& rr, const SkPaint& paint) override;
92 void drawPath(const SkPath& origpath, const SkPaint& paint, bool pathIsMutable) override;
93
94 void drawImageRect(const SkImage*,
95 const SkRect* src,
96 const SkRect& dst,
97 const SkSamplingOptions&,
98 const SkPaint&,
100
101 void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override;
102 void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override;
103
104 void drawAnnotation(const SkRect&, const char key[], SkData* value) override;
105
106 void drawDevice(SkDevice*, const SkSamplingOptions&, const SkPaint&) override;
108 const SkPaint&, SkCanvas::SrcRectConstraint) override;
109
111 sk_sp<SkDevice> createDevice(const CreateInfo&, const SkPaint*) override;
112
113 // PDF specific methods.
114 void drawSprite(const SkBitmap& bitmap, int x, int y,
115 const SkPaint& paint);
116
117 /** Create the resource dictionary for this device. Destructive. */
118 std::unique_ptr<SkPDFDict> makeResourceDict();
119
120 /** Returns a SkStream with the page contents.
121 */
122 std::unique_ptr<SkStreamAsset> content();
123
124 const SkMatrix& initialTransform() const { return fInitialTransform; }
125
126protected:
129
130private:
131 // TODO(vandebo): push most of SkPDFDevice's state into a core object in
132 // order to get the right access levels without using friend.
133 friend class ScopedContentEntry;
134
135 SkMatrix fInitialTransform;
136
141 int fNodeId;
142
143 SkDynamicMemoryWStream fContent;
144 SkDynamicMemoryWStream fContentBuffer;
145 bool fNeedsExtraSave = false;
146 SkPDFGraphicStackState fActiveStackState;
147 SkPDFDocument* fDocument;
148
149 ////////////////////////////////////////////////////////////////////////////
150
151 void onDrawGlyphRunList(SkCanvas*, const sktext::GlyphRunList&, const SkPaint& paint) override;
152
153 // Set alpha to true if making a transparency group form x-objects.
154 SkPDFIndirectReference makeFormXObjectFromDevice(bool alpha = false);
155 SkPDFIndirectReference makeFormXObjectFromDevice(SkIRect bbox, bool alpha = false);
156
157 void drawFormXObjectWithMask(SkPDFIndirectReference xObject,
160 bool invertClip);
161
162 // If the paint or clip is such that we shouldn't draw anything, this
163 // returns nullptr and does not create a content entry.
164 // setUpContentEntry and finishContentEntry can be used directly, but
165 // the preferred method is to use the ScopedContentEntry helper class.
166 SkDynamicMemoryWStream* setUpContentEntry(const SkClipStack* clipStack,
167 const SkMatrix& matrix,
168 const SkPaint& paint,
169 SkScalar,
171 void finishContentEntry(const SkClipStack*, SkBlendMode, SkPDFIndirectReference, SkPath*);
172 bool isContentEmpty();
173
174 void internalDrawGlyphRun(
175 const sktext::GlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint);
176 void drawGlyphRunAsPath(
177 const sktext::GlyphRun& glyphRun, SkPoint offset, const SkPaint& runPaint);
178
179 void internalDrawImageRect(SkKeyedImage,
180 const SkRect* src,
181 const SkRect& dst,
182 const SkSamplingOptions&,
183 const SkPaint&,
184 const SkMatrix& canvasTransformationMatrix);
185
186 void internalDrawPath(const SkClipStack&,
187 const SkMatrix&,
188 const SkPath&,
189 const SkPaint&,
190 bool pathIsMutable);
191
192 void internalDrawPathWithFilter(const SkClipStack& clipStack,
193 const SkMatrix& ctm,
194 const SkPath& origPath,
195 const SkPaint& paint);
196
197 bool handleInversePath(const SkPath& origPath, const SkPaint& paint, bool pathIsMutable);
198
199 void clearMaskOnGraphicState(SkDynamicMemoryWStream*);
200 void setGraphicState(SkPDFIndirectReference gs, SkDynamicMemoryWStream*);
201 void drawFormXObject(SkPDFIndirectReference xObject, SkDynamicMemoryWStream*, SkPath* shape);
202
203 bool hasEmptyClip() const { return this->cs().isEmpty(this->bounds()); }
204
205 void reset();
206};
207
208#endif
m reset()
int count
Definition: FontMgrTest.cpp:50
SkBlendMode
Definition: SkBlendMode.h:38
SrcRectConstraint
Definition: SkCanvas.h:1541
SkClipStack & cs()
bool isEmpty(const SkIRect &deviceBounds) const
Definition: SkData.h:25
SkISize size() const
Definition: SkDevice.h:126
SkIRect bounds() const
Definition: SkDevice.h:125
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
Definition: SkMesh.h:263
SkPDFDevice(SkISize pageSize, SkPDFDocument *document, const SkMatrix &initialTransform=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 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
Definition: SkPDFDevice.h:124
sk_sp< SkPDFDevice > makeCongruentDevice()
Definition: SkPDFDevice.h:74
sk_sp< SkSpecialImage > makeSpecial(const SkBitmap &) override
Definition: SkPath.h:59
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
uint8_t value
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
SkRect oval
Definition: SkRecords.h:249
Definition: bitmap.py:1
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
dst
Definition: cp.py:12
SeparatedVector2 offset
Definition: SkRect.h:32
Definition: SkSize.h:16