OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | 8 |
10 #ifndef SkPDFTypes_DEFINED | 9 #ifndef SkPDFTypes_DEFINED |
11 #define SkPDFTypes_DEFINED | 10 #define SkPDFTypes_DEFINED |
12 | 11 |
13 #include "SkPDFTypes.h" | |
14 #include "SkRefCnt.h" | 12 #include "SkRefCnt.h" |
15 #include "SkScalar.h" | 13 #include "SkScalar.h" |
16 #include "SkString.h" | 14 #include "SkString.h" |
17 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
18 #include "SkTHash.h" | 16 #include "SkTHash.h" |
19 #include "SkTypes.h" | 17 #include "SkTypes.h" |
20 | 18 |
21 class SkPDFObjNumMap; | 19 class SkPDFObjNumMap; |
22 class SkPDFObject; | 20 class SkPDFObject; |
23 class SkPDFSubstituteMap; | 21 class SkPDFSubstituteMap; |
24 class SkWStream; | 22 class SkWStream; |
25 | 23 |
26 /** \class SkPDFObject | 24 /** \class SkPDFObject |
27 | 25 |
28 A PDF Object is the base class for primitive elements in a PDF file. A | 26 A PDF Object is the base class for primitive elements in a PDF file. A |
29 common subtype is used to ease the use of indirect object references, | 27 common subtype is used to ease the use of indirect object references, |
30 which are common in the PDF format. | 28 which are common in the PDF format. |
| 29 |
31 */ | 30 */ |
32 class SkPDFObject : public SkRefCnt { | 31 class SkPDFObject : public SkRefCnt { |
33 public: | 32 public: |
34 SK_DECLARE_INST_COUNT(SkPDFObject) | 33 SK_DECLARE_INST_COUNT(SkPDFObject); |
35 | 34 |
36 /** Subclasses must implement this method to print the object to the | 35 /** Subclasses must implement this method to print the object to the |
37 * PDF file. | 36 * PDF file. |
38 * @param catalog The object catalog to use. | 37 * @param catalog The object catalog to use. |
39 * @param stream The writable output stream to send the output to. | 38 * @param stream The writable output stream to send the output to. |
40 */ | 39 */ |
41 // TODO(halcanary): make this method const | 40 // TODO(halcanary): make this method const |
42 virtual void emitObject(SkWStream* stream, | 41 virtual void emitObject(SkWStream* stream, |
43 const SkPDFObjNumMap& objNumMap, | 42 const SkPDFObjNumMap& objNumMap, |
44 const SkPDFSubstituteMap& substitutes) = 0; | 43 const SkPDFSubstituteMap& substitutes) = 0; |
45 | 44 |
46 /** | 45 /** |
47 * Adds all transitive dependencies of this object to the | 46 * Adds all transitive dependencies of this object to the |
48 * catalog. Implementations should respect the catalog's object | 47 * catalog. Implementations should respect the catalog's object |
49 * substitution map. | 48 * substitution map. |
50 */ | 49 */ |
51 virtual void addResources(SkPDFObjNumMap* catalog, | 50 virtual void addResources(SkPDFObjNumMap* catalog, |
52 const SkPDFSubstituteMap& substitutes) const {} | 51 const SkPDFSubstituteMap& substitutes) const {} |
53 | 52 |
54 private: | 53 private: |
55 typedef SkRefCnt INHERITED; | 54 typedef SkRefCnt INHERITED; |
56 }; | 55 }; |
57 | 56 |
58 /** \class SkPDFObjRef | 57 //////////////////////////////////////////////////////////////////////////////// |
59 | 58 |
60 An indirect reference to a PDF object. | 59 /** |
61 */ | 60 A SkPDFUnion is a non-virtualized implementation of the |
62 class SkPDFObjRef : public SkPDFObject { | 61 non-compound, non-specialized PDF Object types: Name, String, |
| 62 Number, Boolean. |
| 63 */ |
| 64 class SkPDFUnion { |
63 public: | 65 public: |
64 SK_DECLARE_INST_COUNT(SkPDFObjRef) | 66 // u.move() is analogous to std::move(u). It returns an rvalue. |
| 67 SkPDFUnion move() { return static_cast<SkPDFUnion&&>(*this); } |
| 68 // Move contstructor and assignemnt operator destroy the argument |
| 69 // and steal their references (if needed). |
| 70 SkPDFUnion(SkPDFUnion&& other); |
| 71 SkPDFUnion& operator=(SkPDFUnion&& other); |
65 | 72 |
66 /** Create a reference to an existing SkPDFObject. | 73 ~SkPDFUnion(); |
67 * @param obj The object to reference. | |
68 */ | |
69 explicit SkPDFObjRef(SkPDFObject* obj); | |
70 virtual ~SkPDFObjRef(); | |
71 | 74 |
72 // The SkPDFObject interface. | 75 /** The following nine functions are the standard way of creating |
73 virtual void emitObject(SkWStream* stream, | 76 SkPDFUnion objects. */ |
74 const SkPDFObjNumMap& objNumMap, | 77 |
75 const SkPDFSubstituteMap& substitutes) override; | 78 static SkPDFUnion Int(int32_t); |
76 virtual void addResources(SkPDFObjNumMap*, | 79 |
77 const SkPDFSubstituteMap&) const override; | 80 static SkPDFUnion Bool(bool); |
| 81 |
| 82 static SkPDFUnion Scalar(SkScalar); |
| 83 |
| 84 /** These two functions do NOT take ownership of ptr, and do NOT |
| 85 copy the string. Suitable for passing in static const |
| 86 strings. For example: |
| 87 SkPDFUnion n = SkPDFUnion::Name("Length"); |
| 88 SkPDFUnion u = SkPDFUnion::String("Identity"); */ |
| 89 |
| 90 /** SkPDFUnion::Name(const char*) assumes that the passed string |
| 91 is already a valid name (that is: it has no control or |
| 92 whitespace characters). This will not copy the name. */ |
| 93 static SkPDFUnion Name(const char*); |
| 94 |
| 95 /** SkPDFUnion::String will encode the passed string. This will |
| 96 not copy the name. */ |
| 97 static SkPDFUnion String(const char*); |
| 98 |
| 99 /** SkPDFUnion::Name(const SkString&) does not assume that the |
| 100 passed string is already a valid name and it will escape the |
| 101 string. */ |
| 102 static SkPDFUnion Name(const SkString&); |
| 103 |
| 104 /** SkPDFUnion::String will encode the passed string. */ |
| 105 static SkPDFUnion String(const SkString&); |
| 106 |
| 107 /** This function DOES take ownership of the object. E.g. |
| 108 SkAutoTUnref<SkPDFDict> dict(new SkPDFDict); |
| 109 dict->insert(.....); |
| 110 SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */ |
| 111 static SkPDFUnion Object(SkPDFObject*); |
| 112 |
| 113 /** This function DOES take ownership of the object. E.g. |
| 114 SkAutoTUnref<SkPDFBitmap> image( |
| 115 SkPDFBitmap::Create(fCanon, bitmap)); |
| 116 SkPDFUnion u = SkPDFUnion::ObjRef(image.detach()) */ |
| 117 static SkPDFUnion ObjRef(SkPDFObject*); |
| 118 |
| 119 /** These two non-virtual methods mirror SkPDFObject's |
| 120 corresponding virtuals. */ |
| 121 void emitObject(SkWStream*, |
| 122 const SkPDFObjNumMap&, |
| 123 const SkPDFSubstituteMap&) const; |
| 124 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const; |
| 125 |
| 126 bool isName() const; |
78 | 127 |
79 private: | 128 private: |
80 SkAutoTUnref<SkPDFObject> fObj; | 129 union { |
| 130 int32_t fIntValue; |
| 131 bool fBoolValue; |
| 132 SkScalar fScalarValue; |
| 133 const char* fStaticString; |
| 134 char fSkString[sizeof(SkString)]; |
| 135 SkPDFObject* fObject; |
| 136 }; |
| 137 enum class Type : char { |
| 138 /** It is an error to call emitObject() or addResources() on an |
| 139 kDestroyed object. */ |
| 140 kDestroyed = 0, |
| 141 kInt, |
| 142 kBool, |
| 143 kScalar, |
| 144 kName, |
| 145 kString, |
| 146 kNameSkS, |
| 147 kStringSkS, |
| 148 kObjRef, |
| 149 kObject, |
| 150 }; |
| 151 Type fType; |
81 | 152 |
| 153 SkPDFUnion(Type); |
| 154 // We do not now need copy constructor and copy assignment, so we |
| 155 // will disable this functionality. |
| 156 SkPDFUnion& operator=(const SkPDFUnion&) = delete; |
| 157 SkPDFUnion(const SkPDFUnion&) = delete; |
| 158 }; |
| 159 SK_COMPILE_ASSERT(sizeof(SkString) == sizeof(void*), SkString_size); |
| 160 |
| 161 //////////////////////////////////////////////////////////////////////////////// |
| 162 |
| 163 /** This class is a SkPDFUnion with SkPDFObject virtuals attached. */ |
| 164 // TODO(halcanary): 99% of the uses of this class should be |
| 165 // transitioned to using a bare SkPDFUnion inside an array or dict. |
| 166 class SkPDFAtom : public SkPDFObject { |
| 167 public: |
| 168 void emitObject(SkWStream* stream, |
| 169 const SkPDFObjNumMap& objNumMap, |
| 170 const SkPDFSubstituteMap& substitutes) final; |
| 171 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; |
| 172 |
| 173 protected: |
| 174 SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {} |
| 175 |
| 176 private: |
| 177 const SkPDFUnion fValue; |
82 typedef SkPDFObject INHERITED; | 178 typedef SkPDFObject INHERITED; |
83 }; | 179 }; |
84 | 180 |
85 /** \class SkPDFInt | 181 /** The following six classes exist only to ease transition to SkPDFUnion. */ |
| 182 class SkPDFObjRef : public SkPDFAtom { |
| 183 public: |
| 184 SK_DECLARE_INST_COUNT(SkPDFObjRef); |
| 185 explicit SkPDFObjRef(SkPDFObject* obj) |
| 186 : INHERITED(SkPDFUnion::ObjRef(SkRef(obj))) {} |
| 187 typedef SkPDFAtom INHERITED; |
| 188 }; |
86 | 189 |
87 An integer object in a PDF. | 190 class SkPDFInt : public SkPDFAtom { |
88 */ | |
89 class SkPDFInt : public SkPDFObject { | |
90 public: | 191 public: |
91 SK_DECLARE_INST_COUNT(SkPDFInt) | 192 SK_DECLARE_INST_COUNT(SkPDFInt); |
| 193 explicit SkPDFInt(int32_t value) : INHERITED(SkPDFUnion::Int(value)) {} |
| 194 typedef SkPDFAtom INHERITED; |
| 195 }; |
92 | 196 |
93 /** Create a PDF integer (usually for indirect reference purposes). | 197 class SkPDFBool : public SkPDFAtom { |
94 * @param value An integer value between 2^31 - 1 and -2^31. | 198 public: |
95 */ | 199 SK_DECLARE_INST_COUNT(SkPDFBool); |
96 explicit SkPDFInt(int32_t value); | 200 explicit SkPDFBool(bool value) : INHERITED(SkPDFUnion::Bool(value)) {} |
97 virtual ~SkPDFInt(); | 201 typedef SkPDFAtom INHERITED; |
| 202 }; |
98 | 203 |
99 // The SkPDFObject interface. | 204 class SkPDFScalar : public SkPDFAtom { |
100 virtual void emitObject(SkWStream* stream, | 205 public: |
101 const SkPDFObjNumMap& objNumMap, | 206 SK_DECLARE_INST_COUNT(SkPDFScalar); |
102 const SkPDFSubstituteMap& substitutes) override; | 207 explicit SkPDFScalar(SkScalar value) |
| 208 : INHERITED(SkPDFUnion::Scalar(value)) {} |
| 209 static void Append(SkScalar value, SkWStream* stream); |
| 210 typedef SkPDFAtom INHERITED; |
| 211 }; |
| 212 |
| 213 class SkPDFString : public SkPDFAtom { |
| 214 public: |
| 215 SK_DECLARE_INST_COUNT(SkPDFString); |
| 216 explicit SkPDFString(const char value[]) |
| 217 : INHERITED(SkPDFUnion::String(value)) {} |
| 218 explicit SkPDFString(const SkString& value) |
| 219 : INHERITED(SkPDFUnion::String(value)) {} |
| 220 |
| 221 static SkString FormatString(const char* input, size_t len); |
| 222 |
| 223 static const size_t kMaxLen = 65535; |
103 | 224 |
104 private: | 225 private: |
105 int32_t fValue; | 226 typedef SkPDFAtom INHERITED; |
106 | |
107 typedef SkPDFObject INHERITED; | |
108 }; | 227 }; |
109 | 228 |
110 /** \class SkPDFBool | 229 class SkPDFName : public SkPDFAtom { |
| 230 public: |
| 231 SK_DECLARE_INST_COUNT(SkPDFName); |
| 232 /** Create a PDF name object. Maximum length is 127 bytes. */ |
| 233 explicit SkPDFName(const char name[]) |
| 234 : INHERITED(SkPDFUnion::Name(SkString(name))) {} |
| 235 explicit SkPDFName(const SkString& name) |
| 236 : INHERITED(SkPDFUnion::Name(name)) {} |
111 | 237 |
112 An boolean value in a PDF. | 238 static const size_t kMaxLen = 127; |
113 */ | |
114 class SkPDFBool : public SkPDFObject { | |
115 public: | |
116 SK_DECLARE_INST_COUNT(SkPDFBool) | |
117 | |
118 /** Create a PDF boolean. | |
119 * @param value true or false. | |
120 */ | |
121 explicit SkPDFBool(bool value); | |
122 virtual ~SkPDFBool(); | |
123 | |
124 // The SkPDFObject interface. | |
125 virtual void emitObject(SkWStream* stream, | |
126 const SkPDFObjNumMap& objNumMap, | |
127 const SkPDFSubstituteMap& substitutes) override; | |
128 | 239 |
129 private: | 240 private: |
130 bool fValue; | 241 typedef SkPDFAtom INHERITED; |
131 | |
132 typedef SkPDFObject INHERITED; | |
133 }; | |
134 | |
135 /** \class SkPDFScalar | |
136 | |
137 A real number object in a PDF. | |
138 */ | |
139 class SkPDFScalar : public SkPDFObject { | |
140 public: | |
141 SK_DECLARE_INST_COUNT(SkPDFScalar) | |
142 | |
143 /** Create a PDF real number. | |
144 * @param value A real value. | |
145 */ | |
146 explicit SkPDFScalar(SkScalar value); | |
147 virtual ~SkPDFScalar(); | |
148 | |
149 static void Append(SkScalar value, SkWStream* stream); | |
150 | |
151 // The SkPDFObject interface. | |
152 virtual void emitObject(SkWStream* stream, | |
153 const SkPDFObjNumMap& objNumMap, | |
154 const SkPDFSubstituteMap& substitutes) override; | |
155 | |
156 private: | |
157 SkScalar fValue; | |
158 | |
159 typedef SkPDFObject INHERITED; | |
160 }; | |
161 | |
162 /** \class SkPDFString | |
163 | |
164 A string object in a PDF. | |
165 */ | |
166 class SkPDFString : public SkPDFObject { | |
167 public: | |
168 SK_DECLARE_INST_COUNT(SkPDFString) | |
169 | |
170 /** Create a PDF string. Maximum length (in bytes) is 65,535. | |
171 * @param value A string value. | |
172 */ | |
173 explicit SkPDFString(const char value[]); | |
174 explicit SkPDFString(const SkString& value); | |
175 | |
176 virtual ~SkPDFString(); | |
177 | |
178 // The SkPDFObject interface. | |
179 virtual void emitObject(SkWStream* stream, | |
180 const SkPDFObjNumMap& objNumMap, | |
181 const SkPDFSubstituteMap& substitutes) override; | |
182 | |
183 static SkString FormatString(const char* input, size_t len); | |
184 private: | |
185 static const size_t kMaxLen = 65535; | |
186 | |
187 const SkString fValue; | |
188 | |
189 typedef SkPDFObject INHERITED; | |
190 }; | |
191 | |
192 /** \class SkPDFName | |
193 | |
194 A name object in a PDF. | |
195 */ | |
196 class SkPDFName : public SkPDFObject { | |
197 public: | |
198 SK_DECLARE_INST_COUNT(SkPDFName) | |
199 | |
200 /** Create a PDF name object. Maximum length is 127 bytes. | |
201 * @param value The name. | |
202 */ | |
203 explicit SkPDFName(const char name[]); | |
204 explicit SkPDFName(const SkString& name); | |
205 virtual ~SkPDFName(); | |
206 | |
207 bool operator==(const SkPDFName& b) const; | |
208 | |
209 // The SkPDFObject interface. | |
210 virtual void emitObject(SkWStream* stream, | |
211 const SkPDFObjNumMap& objNumMap, | |
212 const SkPDFSubstituteMap& substitutes) override; | |
213 | |
214 private: | |
215 static const size_t kMaxLen = 127; | |
216 | |
217 const SkString fValue; | |
218 | |
219 static SkString FormatName(const SkString& input); | |
220 | |
221 typedef SkPDFObject INHERITED; | |
222 }; | 242 }; |
223 | 243 |
224 /** \class SkPDFArray | 244 /** \class SkPDFArray |
225 | 245 |
226 An array object in a PDF. | 246 An array object in a PDF. |
227 */ | 247 */ |
228 class SkPDFArray : public SkPDFObject { | 248 class SkPDFArray : public SkPDFObject { |
229 public: | 249 public: |
230 SK_DECLARE_INST_COUNT(SkPDFArray) | 250 SK_DECLARE_INST_COUNT(SkPDFArray) |
231 | 251 |
| 252 static const int kMaxLen = 8191; |
| 253 |
232 /** Create a PDF array. Maximum length is 8191. | 254 /** Create a PDF array. Maximum length is 8191. |
233 */ | 255 */ |
234 SkPDFArray(); | 256 SkPDFArray(); |
235 virtual ~SkPDFArray(); | 257 virtual ~SkPDFArray(); |
236 | 258 |
237 // The SkPDFObject interface. | 259 // The SkPDFObject interface. |
238 virtual void emitObject(SkWStream* stream, | 260 virtual void emitObject(SkWStream* stream, |
239 const SkPDFObjNumMap& objNumMap, | 261 const SkPDFObjNumMap& objNumMap, |
240 const SkPDFSubstituteMap& substitutes) override; | 262 const SkPDFSubstituteMap& substitutes) override; |
241 virtual void addResources(SkPDFObjNumMap*, | 263 virtual void addResources(SkPDFObjNumMap*, |
242 const SkPDFSubstituteMap&) const override; | 264 const SkPDFSubstituteMap&) const override; |
243 | 265 |
244 /** The size of the array. | 266 /** The size of the array. |
245 */ | 267 */ |
246 int size() { return fValue.count(); } | 268 int size() const; |
247 | 269 |
248 /** Preallocate space for the given number of entries. | 270 /** Preallocate space for the given number of entries. |
249 * @param length The number of array slots to preallocate. | 271 * @param length The number of array slots to preallocate. |
250 */ | 272 */ |
251 void reserve(int length); | 273 void reserve(int length); |
252 | 274 |
253 /** Append the object to the end of the array and increments its ref count. | 275 /** Append the object to the end of the array and increments its ref count. |
254 * @param value The value to add to the array. | 276 * @param value The value to add to the array. |
255 * @return The value argument is returned. | 277 * @return The value argument is returned. |
256 */ | 278 */ |
| 279 // DEPRECATED |
257 SkPDFObject* append(SkPDFObject* value); | 280 SkPDFObject* append(SkPDFObject* value); |
258 | 281 |
259 /** Creates a SkPDFInt object and appends it to the array. | 282 /** Appends a value to the end of the array. |
260 * @param value The value to add to the array. | 283 * @param value The value to add to the array. |
261 */ | 284 */ |
262 void appendInt(int32_t value); | 285 void appendInt(int32_t); |
263 | 286 void appendBool(bool); |
264 /** Creates a SkPDFScalar object and appends it to the array. | 287 void appendScalar(SkScalar); |
265 * @param value The value to add to the array. | 288 void appendName(const char[]); |
266 */ | 289 void appendName(const SkString&); |
267 void appendScalar(SkScalar value); | 290 void appendString(const char[]); |
268 | 291 void appendString(const SkString&); |
269 /** Creates a SkPDFName object and appends it to the array. | 292 /** appendObject and appendObjRef take ownership of the passed object */ |
270 * @param value The value to add to the array. | 293 void appendObject(SkPDFObject*); |
271 */ | 294 void appendObjRef(SkPDFObject*); |
272 void appendName(const char name[]); | |
273 | 295 |
274 private: | 296 private: |
275 static const int kMaxLen = 8191; | 297 SkTDArray<SkPDFUnion> fValues; |
276 SkTDArray<SkPDFObject*> fValue; | 298 void append(SkPDFUnion&& value); |
277 | |
278 typedef SkPDFObject INHERITED; | 299 typedef SkPDFObject INHERITED; |
279 }; | 300 }; |
280 | 301 |
281 /** \class SkPDFDict | 302 /** \class SkPDFDict |
282 | 303 |
283 A dictionary object in a PDF. | 304 A dictionary object in a PDF. |
284 */ | 305 */ |
285 class SkPDFDict : public SkPDFObject { | 306 class SkPDFDict : public SkPDFObject { |
286 public: | 307 public: |
287 SK_DECLARE_INST_COUNT(SkPDFDict) | 308 SK_DECLARE_INST_COUNT(SkPDFDict) |
(...skipping 18 matching lines...) Expand all Loading... |
306 | 327 |
307 /** The size of the dictionary. | 328 /** The size of the dictionary. |
308 */ | 329 */ |
309 int size() const; | 330 int size() const; |
310 | 331 |
311 /** Add the value to the dictionary with the given key. Refs value. | 332 /** Add the value to the dictionary with the given key. Refs value. |
312 * @param key The key for this dictionary entry. | 333 * @param key The key for this dictionary entry. |
313 * @param value The value for this dictionary entry. | 334 * @param value The value for this dictionary entry. |
314 * @return The value argument is returned. | 335 * @return The value argument is returned. |
315 */ | 336 */ |
| 337 // DEPRECATED |
316 SkPDFObject* insert(SkPDFName* key, SkPDFObject* value); | 338 SkPDFObject* insert(SkPDFName* key, SkPDFObject* value); |
| 339 // DEPRECATED |
| 340 SkPDFObject* insert(const char key[], SkPDFObject* value); |
317 | 341 |
318 /** Add the value to the dictionary with the given key. Refs value. The | 342 /** Add the value to the dictionary with the given key. Takes |
319 * method will create the SkPDFName object. | 343 * ownership of the object. |
320 * @param key The text of the key for this dictionary entry. | 344 * @param key The text of the key for this dictionary entry. |
321 * @param value The value for this dictionary entry. | 345 * @param value The value for this dictionary entry. |
322 * @return The value argument is returned. | |
323 */ | 346 */ |
324 SkPDFObject* insert(const char key[], SkPDFObject* value); | 347 void insertObject(const char key[], SkPDFObject* value); |
| 348 void insertObject(const SkString& key, SkPDFObject* value); |
| 349 void insertObjRef(const char key[], SkPDFObject* value); |
| 350 void insertObjRef(const SkString& key, SkPDFObject* value); |
325 | 351 |
326 /** Add the int to the dictionary with the given key. | 352 /** Add the value to the dictionary with the given key. |
327 * @param key The text of the key for this dictionary entry. | 353 * @param key The text of the key for this dictionary entry. |
328 * @param value The int value for this dictionary entry. | 354 * @param value The value for this dictionary entry. |
329 */ | 355 */ |
330 void insertInt(const char key[], int32_t value); | 356 void insertInt(const char key[], int32_t value); |
331 | 357 void insertInt(const char key[], size_t value); |
332 /** | |
333 * Calls insertInt() but asserts in debug builds that the value can be repr
esented | |
334 * by an int32_t. | |
335 */ | |
336 void insertInt(const char key[], size_t value) { | |
337 this->insertInt(key, SkToS32(value)); | |
338 } | |
339 | |
340 /** Add the scalar to the dictionary with the given key. | |
341 * @param key The text of the key for this dictionary entry. | |
342 * @param value The scalar value for this dictionary entry. | |
343 */ | |
344 void insertScalar(const char key[], SkScalar value); | 358 void insertScalar(const char key[], SkScalar value); |
345 | 359 void insertName(const char key[], const char nameValue[]); |
346 /** Add the name to the dictionary with the given key. | 360 void insertName(const char key[], const SkString& nameValue); |
347 * @param key The text of the key for this dictionary entry. | 361 void insertString(const char key[], const char value[]); |
348 * @param name The name for this dictionary entry. | 362 void insertString(const char key[], const SkString& value); |
349 */ | |
350 void insertName(const char key[], const char name[]); | |
351 | |
352 /** Add the name to the dictionary with the given key. | |
353 * @param key The text of the key for this dictionary entry. | |
354 * @param name The name for this dictionary entry. | |
355 */ | |
356 void insertName(const char key[], const SkString& name) { | |
357 this->insertName(key, name.c_str()); | |
358 } | |
359 | 363 |
360 /** Remove all entries from the dictionary. | 364 /** Remove all entries from the dictionary. |
361 */ | 365 */ |
362 void clear(); | 366 void clear(); |
363 | 367 |
364 protected: | |
365 /** Use to remove a single key from the dictionary. | |
366 */ | |
367 void remove(const char key[]); | |
368 | |
369 /** Insert references to all of the key-value pairs from the other | |
370 * dictionary into this one. | |
371 */ | |
372 void mergeFrom(const SkPDFDict& other); | |
373 | |
374 private: | 368 private: |
375 struct Rec { | 369 struct Record { |
376 SkPDFName* key; | 370 SkPDFUnion fKey; |
377 SkPDFObject* value; | 371 SkPDFUnion fValue; |
378 Rec(SkPDFName* k, SkPDFObject* v) : key(k), value(v) {} | |
379 }; | 372 }; |
380 | 373 SkTDArray<Record> fRecords; |
381 static const int kMaxLen = 4095; | 374 static const int kMaxLen = 4095; |
382 | 375 |
383 SkTDArray<struct Rec> fValue; | 376 void set(const SkPDFUnion& name, const SkPDFUnion& value); |
384 | 377 void set(SkPDFUnion&& name, SkPDFUnion&& value); |
385 SkPDFObject* append(SkPDFName* key, SkPDFObject* value); | |
386 | 378 |
387 typedef SkPDFObject INHERITED; | 379 typedef SkPDFObject INHERITED; |
388 }; | 380 }; |
389 | 381 |
390 //////////////////////////////////////////////////////////////////////////////// | 382 //////////////////////////////////////////////////////////////////////////////// |
391 | 383 |
392 /** \class SkPDFSubstituteMap | |
393 | |
394 The PDF Substitute Map manages substitute objects and owns the | |
395 substitutes. | |
396 */ | |
397 class SkPDFSubstituteMap : SkNoncopyable { | |
398 public: | |
399 ~SkPDFSubstituteMap(); | |
400 /** Set substitute object for the passed object. | |
401 Refs substitute. | |
402 */ | |
403 void setSubstitute(SkPDFObject* original, SkPDFObject* substitute); | |
404 | |
405 /** Find and return any substitute object set for the passed object. If | |
406 * there is none, return the passed object. | |
407 */ | |
408 SkPDFObject* getSubstitute(SkPDFObject* object) const; | |
409 | |
410 private: | |
411 SkTHashMap<SkPDFObject*, SkPDFObject*> fSubstituteMap; | |
412 }; | |
413 | |
414 /** \class SkPDFObjNumMap | 384 /** \class SkPDFObjNumMap |
415 | 385 |
416 The PDF Object Number Map manages object numbers. It is used to | 386 The PDF Object Number Map manages object numbers. It is used to |
417 create the PDF cross reference table. | 387 create the PDF cross reference table. |
418 */ | 388 */ |
419 class SkPDFObjNumMap : SkNoncopyable { | 389 class SkPDFObjNumMap : SkNoncopyable { |
420 public: | 390 public: |
421 /** Add the passed object to the catalog. | 391 /** Add the passed object to the catalog. |
422 * @param obj The object to add. | 392 * @param obj The object to add. |
423 * @return True iff the object was not already added to the catalog. | 393 * @return True iff the object was not already added to the catalog. |
424 */ | 394 */ |
425 bool addObject(SkPDFObject* obj); | 395 bool addObject(SkPDFObject* obj); |
426 | 396 |
427 /** Get the object number for the passed object. | 397 /** Get the object number for the passed object. |
428 * @param obj The object of interest. | 398 * @param obj The object of interest. |
429 */ | 399 */ |
430 int32_t getObjectNumber(SkPDFObject* obj) const; | 400 int32_t getObjectNumber(SkPDFObject* obj) const; |
431 | 401 |
432 const SkTDArray<SkPDFObject*>& objects() const { return fObjects; } | 402 const SkTDArray<SkPDFObject*>& objects() const { return fObjects; } |
433 | 403 |
434 private: | 404 private: |
435 SkTDArray<SkPDFObject*> fObjects; | 405 SkTDArray<SkPDFObject*> fObjects; |
436 SkTHashMap<SkPDFObject*, int32_t> fObjectNumbers; | 406 SkTHashMap<SkPDFObject*, int32_t> fObjectNumbers; |
437 }; | 407 }; |
438 | 408 |
| 409 //////////////////////////////////////////////////////////////////////////////// |
| 410 |
| 411 /** \class SkPDFSubstituteMap |
| 412 |
| 413 The PDF Substitute Map manages substitute objects and owns the |
| 414 substitutes. |
| 415 */ |
| 416 class SkPDFSubstituteMap : SkNoncopyable { |
| 417 public: |
| 418 ~SkPDFSubstituteMap(); |
| 419 /** Set substitute object for the passed object. |
| 420 Refs substitute. |
| 421 */ |
| 422 void setSubstitute(SkPDFObject* original, SkPDFObject* substitute); |
| 423 |
| 424 /** Find and return any substitute object set for the passed object. If |
| 425 * there is none, return the passed object. |
| 426 */ |
| 427 SkPDFObject* getSubstitute(SkPDFObject* object) const; |
| 428 |
| 429 SkPDFObject* operator()(SkPDFObject* o) const { |
| 430 return this->getSubstitute(o); |
| 431 } |
| 432 |
| 433 private: |
| 434 SkTHashMap<SkPDFObject*, SkPDFObject*> fSubstituteMap; |
| 435 }; |
| 436 |
439 #endif | 437 #endif |
OLD | NEW |