Skia
2D Graphics Library
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 
10 #include "include/core/SkColor.h"
12 #include "include/core/SkScalar.h"
13 #include "include/core/SkString.h"
14 #include "include/private/base/SkNoncopyable.h"
15 #include "src/base/SkTime.h"
16 
17 #define SKPDF_STRING(X) SKPDF_STRING_IMPL(X)
18 #define SKPDF_STRING_IMPL(X) #X
19 
20 class SkExecutor;
21 class SkPDFArray;
22 class SkPDFTagTree;
23 
24 namespace SkPDF {
25 
27 class SK_API AttributeList : SkNoncopyable {
28 public:
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 
45 private:
46  friend class ::SkPDFTagTree;
47 
48  std::unique_ptr<SkPDFArray> fAttrs;
49 };
50 
58  std::vector<std::unique_ptr<StructureElementNode>> fChildVector;
59  int fNodeId = 0;
60  std::vector<int> fAdditionalNodeIds;
64 };
65 
66 struct DateTime {
67  int16_t fTimeZoneMinutes; // The number of minutes that this
68  // is ahead of or behind UTC.
69  uint16_t fYear;
70  uint8_t fMonth;
71  uint8_t fDayOfWeek;
72  uint8_t fDay;
73  uint8_t fHour;
74  uint8_t fMinute;
75  uint8_t fSecond;
76 
77  void toISO8601(SkString* dst) const;
78 };
79 
82 struct Metadata {
86 
90 
94 
99 
105 
109 
113  DateTime fCreation = {0, 0, 0, 0, 0, 0, 0, 0};
114 
118  DateTime fModified = {0, 0, 0, 0, 0, 0, 0, 0};
119 
128 
133  bool fPDFA = false;
134 
140  int fEncodingQuality = 101;
141 
147 
148  enum class Outline : int {
149  None = 0,
152 
163  SkExecutor* fExecutor = nullptr;
164 
168  enum class CompressionLevel : int {
169  Default = -1,
170  None = 0,
171  LowButFast = 1,
172  Average = 6,
173  HighButSlow = 9,
175 
182  enum Subsetter {
186 };
187 
198 SK_API void SetNodeId(SkCanvas* dst, int nodeID);
199 
211 SK_API sk_sp<SkDocument> MakeDocument(SkWStream* stream, const Metadata& metadata);
212 
213 static inline sk_sp<SkDocument> MakeDocument(SkWStream* stream) {
214  return MakeDocument(stream, Metadata());
215 }
216 
217 } // namespace SkPDF
218 
219 #undef SKPDF_STRING
220 #undef SKPDF_STRING_IMPL
221 #endif // SkPDFDocument_DEFINED
Types, consts, functions, and macros for colors.
static constexpr SkScalar SK_ScalarDefaultRasterDPI
SK_ScalarDefaultDPI is 72 dots per inch.
Definition: SkDocument.h:20
#define SK_MILESTONE
Definition: SkMilestone.h:8
#define SKPDF_STRING(X)
Definition: SkPDFDocument.h:17
float SkScalar
Definition: SkScalar.h:14
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
Definition: SkExecutor.h:15
Attributes for nodes in the PDF tree.
Definition: SkPDFDocument.h:27
void appendNodeIdArray(const char *owner, const char *attrName, const std::vector< int > &nodeIds)
void appendFloatArray(const char *owner, const char *name, const std::vector< float > &value)
void appendName(const char *owner, const char *attrName, const char *value)
void appendInt(const char *owner, const char *name, int value)
void appendFloat(const char *owner, const char *name, float value)
Light weight class for managing strings.
Definition: SkString.h:118
Definition: SkStream.h:218
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Definition: SkPDFDocument.h:24
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
Create a PDF-backed document, writing the results into a SkWStream.
SK_API void SetNodeId(SkCanvas *dst, int nodeID)
Associate a node ID with subsequent drawing commands in an SkCanvas.
Definition: SkPDFDocument.h:66
uint8_t fMinute
0..59
Definition: SkPDFDocument.h:74
uint8_t fMonth
1..12
Definition: SkPDFDocument.h:70
uint8_t fDay
1..31
Definition: SkPDFDocument.h:72
uint16_t fYear
e.g. 2005
Definition: SkPDFDocument.h:69
void toISO8601(SkString *dst) const
uint8_t fSecond
0..59
Definition: SkPDFDocument.h:75
int16_t fTimeZoneMinutes
Definition: SkPDFDocument.h:67
uint8_t fHour
0..23
Definition: SkPDFDocument.h:73
uint8_t fDayOfWeek
0..6, 0==Sunday
Definition: SkPDFDocument.h:71
Optional metadata to be passed into the PDF factory function.
Definition: SkPDFDocument.h:82
SkString fCreator
If the document was converted to PDF from another format, the name of the conforming product that cre...
Definition: SkPDFDocument.h:104
int fEncodingQuality
Encoding quality controls the trade-off between size and quality.
Definition: SkPDFDocument.h:140
SkExecutor * fExecutor
Executor to handle threaded work within PDF Backend.
Definition: SkPDFDocument.h:163
enum SkPDF::Metadata::Outline fOutline
SkString fTitle
The document's title.
Definition: SkPDFDocument.h:85
SkString fSubject
The subject of the document.
Definition: SkPDFDocument.h:93
SkString fAuthor
The name of the person who created the document.
Definition: SkPDFDocument.h:89
enum SkPDF::Metadata::Subsetter fSubsetter
SkScalar fRasterDPI
The DPI (pixels-per-inch) at which features without native PDF support will be rasterized (e....
Definition: SkPDFDocument.h:127
SkString fProducer
The product that is converting this document to PDF.
Definition: SkPDFDocument.h:108
Subsetter
Preferred Subsetter.
Definition: SkPDFDocument.h:182
@ kSfntly_Subsetter
Definition: SkPDFDocument.h:184
@ kHarfbuzz_Subsetter
Definition: SkPDFDocument.h:183
bool fPDFA
If true, include XMP metadata, a document UUID, and sRGB output intent information.
Definition: SkPDFDocument.h:133
SkString fKeywords
Keywords associated with the document.
Definition: SkPDFDocument.h:98
StructureElementNode * fStructureElementTreeRoot
An optional tree of structured document tags that provide a semantic representation of the content.
Definition: SkPDFDocument.h:146
Outline
Definition: SkPDFDocument.h:148
DateTime fCreation
The date and time the document was created.
Definition: SkPDFDocument.h:113
enum SkPDF::Metadata::CompressionLevel fCompressionLevel
DateTime fModified
The date and time the document was most recently modified.
Definition: SkPDFDocument.h:118
CompressionLevel
PDF streams may be compressed to save space.
Definition: SkPDFDocument.h:168
A node in a PDF structure tree, giving a semantic representation of the content.
Definition: SkPDFDocument.h:56
SkString fTypeString
Definition: SkPDFDocument.h:57
std::vector< std::unique_ptr< StructureElementNode > > fChildVector
Definition: SkPDFDocument.h:58
SkString fAlt
Definition: SkPDFDocument.h:62
int fNodeId
Definition: SkPDFDocument.h:59
std::vector< int > fAdditionalNodeIds
Definition: SkPDFDocument.h:60
AttributeList fAttributes
Definition: SkPDFDocument.h:61
SkString fLang
Definition: SkPDFDocument.h:63