Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPDFDocument.h
Go to the documentation of this file.
1// Copyright 2018 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3#ifndef SkPDFDocument_DEFINED
4#define SkPDFDocument_DEFINED
5
7
8#include <vector>
9
15#include "src/base/SkTime.h"
16
17#define SKPDF_STRING(X) SKPDF_STRING_IMPL(X)
18#define SKPDF_STRING_IMPL(X) #X
19
20class SkExecutor;
21class SkPDFArray;
22class SkPDFTagTree;
23
24namespace SkPDF {
25
26/** Attributes for nodes in the PDF tree. */
28public:
31
32 // Each attribute must have an owner (e.g. "Layout", "List", "Table", etc)
33 // and an attribute name (e.g. "BBox", "RowSpan", etc.) from PDF32000_2008 14.8.5,
34 // and then a value of the proper type according to the spec.
35 void appendInt(const char* owner, const char* name, int value);
36 void appendFloat(const char* owner, const char* name, float value);
37 void appendName(const char* owner, const char* attrName, const char* value);
38 void appendFloatArray(const char* owner,
39 const char* name,
40 const std::vector<float>& value);
41 void appendNodeIdArray(const char* owner,
42 const char* attrName,
43 const std::vector<int>& nodeIds);
44
45private:
46 friend class ::SkPDFTagTree;
47
48 std::unique_ptr<SkPDFArray> fAttrs;
49};
50
51/** A node in a PDF structure tree, giving a semantic representation
52 of the content. Each node ID is associated with content
53 by passing the SkCanvas and node ID to SkPDF::SetNodeId() when drawing.
54 NodeIDs should be unique within each tree.
55*/
58 std::vector<std::unique_ptr<StructureElementNode>> fChildVector;
59 int fNodeId = 0;
60 std::vector<int> fAdditionalNodeIds;
64};
65
66struct DateTime {
67 int16_t fTimeZoneMinutes; // The number of minutes that this
68 // is ahead of or behind UTC.
69 uint16_t fYear; //!< e.g. 2005
70 uint8_t fMonth; //!< 1..12
71 uint8_t fDayOfWeek; //!< 0..6, 0==Sunday
72 uint8_t fDay; //!< 1..31
73 uint8_t fHour; //!< 0..23
74 uint8_t fMinute; //!< 0..59
75 uint8_t fSecond; //!< 0..59
76
77 void toISO8601(SkString* dst) const;
78};
79
80/** Optional metadata to be passed into the PDF factory function.
81*/
82struct Metadata {
83 /** The document's title.
84 */
86
87 /** The name of the person who created the document.
88 */
90
91 /** The subject of the document.
92 */
94
95 /** Keywords associated with the document. Commas may be used to delineate
96 keywords within the string.
97 */
99
100 /** If the document was converted to PDF from another format,
101 the name of the conforming product that created the
102 original document from which it was converted.
103 */
105
106 /** The product that is converting this document to PDF.
107 */
109
110 /** The date and time the document was created.
111 The zero default value represents an unknown/unset time.
112 */
113 DateTime fCreation = {0, 0, 0, 0, 0, 0, 0, 0};
114
115 /** The date and time the document was most recently modified.
116 The zero default value represents an unknown/unset time.
117 */
118 DateTime fModified = {0, 0, 0, 0, 0, 0, 0, 0};
119
120 /** The natural language of the text in the PDF. If fLang is empty, the root
121 StructureElementNode::fLang will be used (if not empty). Text not in
122 this language should be marked with StructureElementNode::fLang.
123 */
125
126 /** The DPI (pixels-per-inch) at which features without native PDF support
127 will be rasterized (e.g. draw image with perspective, draw text with
128 perspective, ...) A larger DPI would create a PDF that reflects the
129 original intent with better fidelity, but it can make for larger PDF
130 files too, which would use more memory while rendering, and it would be
131 slower to be processed or sent online or to printer.
132 */
134
135 /** If true, include XMP metadata, a document UUID, and sRGB output intent
136 information. This adds length to the document and makes it
137 non-reproducable, but are necessary features for PDF/A-2b conformance
138 */
139 bool fPDFA = false;
140
141 /** Encoding quality controls the trade-off between size and quality. By
142 default this is set to 101 percent, which corresponds to lossless
143 encoding. If this value is set to a value <= 100, and the image is
144 opaque, it will be encoded (using JPEG) with that quality setting.
145 */
147
148 /** An optional tree of structured document tags that provide
149 a semantic representation of the content. The caller
150 should retain ownership.
151 */
153
154 enum class Outline : int {
155 None = 0,
158
159 /** Executor to handle threaded work within PDF Backend. If this is nullptr,
160 then all work will be done serially on the main thread. To have worker
161 threads assist with various tasks, set this to a valid SkExecutor
162 instance. Currently used for executing Deflate algorithm in parallel.
163
164 If set, the PDF output will be non-reproducible in the order and
165 internal numbering of objects, but should render the same.
166
167 Experimental.
168 */
170
171 /** PDF streams may be compressed to save space.
172 Use this to specify the desired compression vs time tradeoff.
173 */
174 enum class CompressionLevel : int {
175 Default = -1,
176 None = 0,
177 LowButFast = 1,
178 Average = 6,
179 HighButSlow = 9,
181
182 /** Preferred Subsetter. */
186};
187
188/** Associate a node ID with subsequent drawing commands in an
189 SkCanvas. The same node ID can appear in a StructureElementNode
190 in order to associate a document's structure element tree with
191 its content.
192
193 A node ID of zero indicates no node ID.
194
195 @param canvas The canvas used to draw to the PDF.
196 @param nodeId The node ID for subsequent drawing commands.
197*/
198SK_API void SetNodeId(SkCanvas* dst, int nodeID);
199
200/** Create a PDF-backed document, writing the results into a SkWStream.
201
202 PDF pages are sized in point units. 1 pt == 1/72 inch == 127/360 mm.
203
204 @param stream A PDF document will be written to this stream. The document may write
205 to the stream at anytime during its lifetime, until either close() is
206 called or the document is deleted.
207 @param metadata a PDFmetadata object. Any fields may be left empty.
208
209 @returns NULL if there is an error, otherwise a newly created PDF-backed SkDocument.
210*/
211SK_API sk_sp<SkDocument> MakeDocument(SkWStream* stream, const Metadata& metadata);
212
214 return MakeDocument(stream, Metadata());
215}
216
217} // namespace SkPDF
218
219#undef SKPDF_STRING
220#undef SKPDF_STRING_IMPL
221#endif // SkPDFDocument_DEFINED
#define SK_API
Definition SkAPI.h:35
static constexpr SkScalar SK_ScalarDefaultRasterDPI
Definition SkDocument.h:20
#define SK_MILESTONE
Definition SkMilestone.h:8
#define SKPDF_STRING(X)
float SkScalar
Definition extension.cpp:12
const char * name
Definition fuchsia.cc:50
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
SK_API void SetNodeId(SkCanvas *dst, int nodeID)
uint8_t fMinute
0..59
uint8_t fMonth
1..12
uint8_t fDay
1..31
uint16_t fYear
e.g. 2005
void toISO8601(SkString *dst) const
uint8_t fSecond
0..59
int16_t fTimeZoneMinutes
uint8_t fHour
0..23
uint8_t fDayOfWeek
0..6, 0==Sunday
SkExecutor * fExecutor
enum SkPDF::Metadata::Outline fOutline
enum SkPDF::Metadata::Subsetter fSubsetter
StructureElementNode * fStructureElementTreeRoot
enum SkPDF::Metadata::CompressionLevel fCompressionLevel
std::vector< std::unique_ptr< StructureElementNode > > fChildVector
std::vector< int > fAdditionalNodeIds