Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPDFTypes.h
Go to the documentation of this file.
1/*
2 * Copyright 2010 The Android Open Source Project
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 SkPDFTypes_DEFINED
9#define SkPDFTypes_DEFINED
10
15#include "src/core/SkTHash.h"
16
17#include <memory>
18#include <new>
19#include <type_traits>
20#include <utility>
21#include <vector>
22#include <memory>
23
24class SkData;
25class SkPDFArray;
26
27class SkPDFDict;
28class SkPDFDocument;
29class SkPDFObject;
30class SkPDFUnion;
31class SkStreamAsset;
32class SkString;
33class SkWStream;
34struct SkPDFObjectSerializer;
35
37 int fValue = -1;
38 explicit operator bool() const { return fValue != -1; }
39
41 return fValue == v.fValue;
42 }
43
45 return fValue != v.fValue;
46 }
47};
48
49/** \class SkPDFObject
50
51 A PDF Object is the base class for primitive elements in a PDF file. A
52 common subtype is used to ease the use of indirect object references,
53 which are common in the PDF format.
54
55*/
57public:
58 SkPDFObject() = default;
59
60 /** Subclasses must implement this method to print the object to the
61 * PDF file.
62 * @param catalog The object catalog to use.
63 * @param stream The writable output stream to send the output to.
64 */
65 virtual void emitObject(SkWStream* stream) const = 0;
66
67 virtual ~SkPDFObject() = default;
68
69private:
70 SkPDFObject(SkPDFObject&&) = delete;
71 SkPDFObject(const SkPDFObject&) = delete;
72 SkPDFObject& operator=(SkPDFObject&&) = delete;
73 SkPDFObject& operator=(const SkPDFObject&) = delete;
74};
75
76////////////////////////////////////////////////////////////////////////////////
77
78/** \class SkPDFArray
79
80 An array object in a PDF.
81*/
82class SkPDFArray final : public SkPDFObject {
83public:
84 /** Create a PDF array. Maximum length is 8191.
85 */
86 SkPDFArray();
87 ~SkPDFArray() override;
88
89 // The SkPDFObject interface.
90 void emitObject(SkWStream* stream) const override;
91
92 /** The size of the array.
93 */
94 size_t size() const;
95
96 /** Preallocate space for the given number of entries.
97 * @param length The number of array slots to preallocate.
98 */
99 void reserve(int length);
100
101 /** Appends a value to the end of the array.
102 * @param value The value to add to the array.
103 */
104 void appendInt(int32_t);
105 void appendColorComponent(uint8_t);
106 void appendBool(bool);
108 void appendName(const char[]);
109 void appendName(SkString);
110 void appendByteString(const char[]);
111 void appendTextString(const char[]);
114 void appendObject(std::unique_ptr<SkPDFObject>&&);
116
117private:
118 std::vector<SkPDFUnion> fValues;
119 void append(SkPDFUnion&& value);
120};
121
122static inline void SkPDFArray_Append(SkPDFArray* a, int v) { a->appendInt(v); }
123
124static inline void SkPDFArray_Append(SkPDFArray* a, SkScalar v) { a->appendScalar(v); }
125
126template <typename T, typename... Args>
127static inline void SkPDFArray_Append(SkPDFArray* a, T v, Args... args) {
130}
131
132static inline void SkPDFArray_Append(SkPDFArray* a) {}
133
134template <typename... Args>
135static inline std::unique_ptr<SkPDFArray> SkPDFMakeArray(Args... args) {
136 std::unique_ptr<SkPDFArray> ret(new SkPDFArray());
137 ret->reserve(sizeof...(Args));
138 SkPDFArray_Append(ret.get(), args...);
139 return ret;
140}
141
142/** \class SkPDFDict
143
144 A dictionary object in a PDF.
145*/
146class SkPDFDict final : public SkPDFObject {
147public:
148 /** Create a PDF dictionary.
149 * @param type The value of the Type entry, nullptr for no type.
150 */
151 explicit SkPDFDict(const char type[] = nullptr);
152
153 ~SkPDFDict() override;
154
155 // The SkPDFObject interface.
156 void emitObject(SkWStream* stream) const override;
157
158 /** The size of the dictionary.
159 */
160 size_t size() const;
161
162 /** Preallocate space for n key-value pairs */
163 void reserve(int n);
164
165 /** Add the value to the dictionary with the given key.
166 * @param key The text of the key for this dictionary entry.
167 * @param value The value for this dictionary entry.
168 */
169 void insertObject(const char key[], std::unique_ptr<SkPDFObject>&&);
170 void insertObject(SkString, std::unique_ptr<SkPDFObject>&&);
171 void insertRef(const char key[], SkPDFIndirectReference);
173
174 /** Add the value to the dictionary with the given key.
175 * @param key The text of the key for this dictionary entry.
176 * @param value The value for this dictionary entry.
177 */
178 void insertBool(const char key[], bool value);
179 void insertInt(const char key[], int32_t value);
180 void insertInt(const char key[], size_t value);
181 void insertScalar(const char key[], SkScalar value);
182 void insertColorComponentF(const char key[], SkScalar value);
183 void insertName(const char key[], const char nameValue[]);
184 void insertName(const char key[], SkString nameValue);
185 void insertByteString(const char key[], const char value[]);
186 void insertTextString(const char key[], const char value[]);
187 void insertByteString(const char key[], SkString value);
188 void insertTextString(const char key[], SkString value);
189 void insertUnion(const char key[], SkPDFUnion&&);
190
191private:
192 std::vector<std::pair<SkPDFUnion, SkPDFUnion>> fRecords;
193};
194
195static inline std::unique_ptr<SkPDFDict> SkPDFMakeDict(const char* type = nullptr) {
196 return std::make_unique<SkPDFDict>(type);
197}
198
200 No = false,
201 Yes = true,
202 Default =
203#ifdef SK_PDF_LESS_COMPRESSION
204 No,
205#else
206 Yes,
207#endif
208};
209
210// Exposed for unit testing.
211void SkPDFWriteTextString(SkWStream* wStream, const char* cin, size_t len);
212void SkPDFWriteByteString(SkWStream* wStream, const char* cin, size_t len);
213
215 std::unique_ptr<SkPDFDict> dict,
216 std::unique_ptr<SkStreamAsset> stream,
217 SkPDFDocument* doc,
219#endif
#define nameValue(fill)
SkPDFIndirectReference SkPDFStreamOut(std::unique_ptr< SkPDFDict > dict, std::unique_ptr< SkStreamAsset > stream, SkPDFDocument *doc, SkPDFSteamCompressionEnabled compress=SkPDFSteamCompressionEnabled::Default)
static std::unique_ptr< SkPDFDict > SkPDFMakeDict(const char *type=nullptr)
Definition SkPDFTypes.h:195
static void SkPDFArray_Append(SkPDFArray *a, int v)
Definition SkPDFTypes.h:122
void SkPDFWriteByteString(SkWStream *wStream, const char *cin, size_t len)
static std::unique_ptr< SkPDFArray > SkPDFMakeArray(Args... args)
Definition SkPDFTypes.h:135
SkPDFSteamCompressionEnabled
Definition SkPDFTypes.h:199
void SkPDFWriteTextString(SkWStream *wStream, const char *cin, size_t len)
size_t size() const
void appendRef(SkPDFIndirectReference)
void reserve(int length)
void appendTextString(const char[])
~SkPDFArray() override
void appendInt(int32_t)
void appendByteString(const char[])
void appendObject(std::unique_ptr< SkPDFObject > &&)
void appendBool(bool)
void appendColorComponent(uint8_t)
void appendName(const char[])
void appendScalar(SkScalar)
void emitObject(SkWStream *stream) const override
void reserve(int n)
void insertName(const char key[], const char nameValue[])
void insertObject(const char key[], std::unique_ptr< SkPDFObject > &&)
~SkPDFDict() override
void insertColorComponentF(const char key[], SkScalar value)
void insertUnion(const char key[], SkPDFUnion &&)
void insertInt(const char key[], int32_t value)
void insertTextString(const char key[], const char value[])
void insertRef(const char key[], SkPDFIndirectReference)
void insertScalar(const char key[], SkScalar value)
void insertByteString(const char key[], const char value[])
size_t size() const
void emitObject(SkWStream *stream) const override
void insertBool(const char key[], bool value)
virtual ~SkPDFObject()=default
SkPDFObject()=default
virtual void emitObject(SkWStream *stream) const =0
float SkScalar
Definition extension.cpp:12
struct MyStruct a[10]
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint8_t value
size_t length
#define T
bool operator!=(SkPDFIndirectReference v) const
Definition SkPDFTypes.h:44
bool operator==(SkPDFIndirectReference v) const
Definition SkPDFTypes.h:40