Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/pdf/SkPDFTypes.h

Issue 1069103003: SkPDF: Refactor SkPDFObject heiararchy. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-04-23 (Thursday) 17:02:33 EDT Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // move
tomhudson 2015/04/24 21:32:29 This comment tells me nothing. Please improve. (Ge
hal.canary 2015/04/25 13:41:02 Done. Please let me know if you need more informa
67 SkPDFUnion move() { return static_cast<SkPDFUnion&&>(*this); }
68 SkPDFUnion(SkPDFUnion&& other);
69 SkPDFUnion& operator=(SkPDFUnion&& other);
65 70
66 /** Create a reference to an existing SkPDFObject. 71 ~SkPDFUnion();
67 * @param obj The object to reference.
68 */
69 explicit SkPDFObjRef(SkPDFObject* obj);
70 virtual ~SkPDFObjRef();
71 72
72 // The SkPDFObject interface. 73 /** The following nine functions are the standard way of creating
73 virtual void emitObject(SkWStream* stream, 74 SkPDFUnion objects. */
74 const SkPDFObjNumMap& objNumMap, 75
75 const SkPDFSubstituteMap& substitutes) override; 76 static SkPDFUnion Int(int32_t);
76 virtual void addResources(SkPDFObjNumMap*, 77
77 const SkPDFSubstituteMap&) const override; 78 static SkPDFUnion Bool(bool);
79
80 static SkPDFUnion Scalar(SkScalar);
81
82 /** These two functions do NOT take ownership of ptr, and do NOT
83 copy the string. Suitable for passing in static const
84 strings. For example:
85 SkPDFUnion n = SkPDFUnion::Name("Length");
86 SkPDFUnion u = SkPDFUnion::String("Identity"); */
87
88 /** SkPDFUnion::Name(const char*) assumes that the passed string
89 is already a valid name (that is: it has no control or
90 whitespace characters). This will not copy the name. */
91 static SkPDFUnion Name(const char*);
92
93 /** SkPDFUnion::String will encode the passed string. This will
94 not copy the name. */
95 static SkPDFUnion String(const char*);
96
97 /** SkPDFUnion::Name(const SkString&) does not assume that the
98 passed string is already a valid name and it will escape the
99 string. */
100 static SkPDFUnion Name(const SkString&);
101
102 /** SkPDFUnion::String will encode the passed string. */
103 static SkPDFUnion String(const SkString&);
104
105 /** This function DOES take ownership of the object. E.g.
106 SkAutoTUnref<SkPDFDict> dict(new SkPDFDict);
107 dict->insert(.....);
108 SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */
109 static SkPDFUnion Object(SkPDFObject*);
110
111 /** This function DOES take ownership of the object. E.g.
112 SkAutoTUnref<SkPDFBitmap> image(
113 SkPDFBitmap::Create(fCanon, bitmap));
114 SkPDFUnion u = SkPDFUnion::ObjRef(image.detach()) */
115 static SkPDFUnion ObjRef(SkPDFObject*);
116
117 /** These two non-virtual methods mirror SkPDFObject's
118 corresponding virtuals. */
119 void emitObject(SkWStream*,
120 const SkPDFObjNumMap&,
121 const SkPDFSubstituteMap&) const;
122 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const;
123
124 /** Given an arbitrary string, convert it to a valid name. */
125 static SkString EscapeName(const char*, size_t len);
126 /** Most names need no escaping */
127 static bool IsValidName(const char*);
tomhudson 2015/04/24 21:32:30 Musing for future consideration: do we ever use th
hal.canary 2015/04/25 13:41:02 Actually, in every case we create a Name object, w
128
129 bool isName() const;
78 130
79 private: 131 private:
80 SkAutoTUnref<SkPDFObject> fObj; 132 union {
133 int32_t fIntValue;
134 bool fBoolValue;
135 SkScalar fScalarValue;
136 const char* fStaticString;
137 char fSkString[sizeof(SkString)];
138 SkPDFObject* fObject;
139 };
140 enum class Type : char {
141 /** It is an error to call emitObject() or addResources() on an
142 kDestroyed object. */
143 kDestroyed = 0,
144 kInt,
145 kBool,
146 kScalar,
147 kName,
148 kString,
149 kNameSkS,
150 kStringSkS,
151 kObjRef,
152 kObject,
153 };
154 Type fType;
81 155
156 SkPDFUnion(Type);
157 SkPDFUnion& operator=(const SkPDFUnion&) = delete;
158 SkPDFUnion(const SkPDFUnion&) = delete;
159 };
160 SK_COMPILE_ASSERT(sizeof(SkString) == sizeof(void*), SkString_size);
161
162 ////////////////////////////////////////////////////////////////////////////////
163
164 /** This class is a SkPDFUnion with SkPDFObject virtuals attached. */
165 // TODO(halcanary): 99% of the uses of this class should be
166 // transitioned to using a bare SkPDFUnion inside an array or dict.
167 class SkPDFAtom : public SkPDFObject {
168 public:
169 void emitObject(SkWStream* stream,
170 const SkPDFObjNumMap& objNumMap,
171 const SkPDFSubstituteMap& substitutes) final;
172 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final;
173
174 protected:
175 SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {}
176
177 private:
178 const SkPDFUnion fValue;
82 typedef SkPDFObject INHERITED; 179 typedef SkPDFObject INHERITED;
83 }; 180 };
84 181
85 /** \class SkPDFInt 182 /** The following six classes exist only to ease transition to SkPDFUnion. */
183 class SkPDFObjRef : public SkPDFAtom {
184 public:
185 SK_DECLARE_INST_COUNT(SkPDFObjRef);
186 explicit SkPDFObjRef(SkPDFObject* obj)
187 : INHERITED(SkPDFUnion::ObjRef(SkRef(obj))) {}
188 typedef SkPDFAtom INHERITED;
189 };
86 190
87 An integer object in a PDF. 191 class SkPDFInt : public SkPDFAtom {
88 */
89 class SkPDFInt : public SkPDFObject {
90 public: 192 public:
91 SK_DECLARE_INST_COUNT(SkPDFInt) 193 SK_DECLARE_INST_COUNT(SkPDFInt);
194 explicit SkPDFInt(int32_t value) : INHERITED(SkPDFUnion::Int(value)) {}
195 typedef SkPDFAtom INHERITED;
196 };
92 197
93 /** Create a PDF integer (usually for indirect reference purposes). 198 class SkPDFBool : public SkPDFAtom {
94 * @param value An integer value between 2^31 - 1 and -2^31. 199 public:
95 */ 200 SK_DECLARE_INST_COUNT(SkPDFBool);
96 explicit SkPDFInt(int32_t value); 201 explicit SkPDFBool(bool value) : INHERITED(SkPDFUnion::Bool(value)) {}
97 virtual ~SkPDFInt(); 202 typedef SkPDFAtom INHERITED;
203 };
98 204
99 // The SkPDFObject interface. 205 class SkPDFScalar : public SkPDFAtom {
100 virtual void emitObject(SkWStream* stream, 206 public:
101 const SkPDFObjNumMap& objNumMap, 207 SK_DECLARE_INST_COUNT(SkPDFScalar);
102 const SkPDFSubstituteMap& substitutes) override; 208 explicit SkPDFScalar(SkScalar value)
209 : INHERITED(SkPDFUnion::Scalar(value)) {}
210 static void Append(SkScalar value, SkWStream* stream);
211 typedef SkPDFAtom INHERITED;
212 };
213
214 class SkPDFString : public SkPDFAtom {
215 public:
216 SK_DECLARE_INST_COUNT(SkPDFString);
217 explicit SkPDFString(const char value[])
218 : INHERITED(SkPDFUnion::String(value)) {}
219 explicit SkPDFString(const SkString& value)
220 : INHERITED(SkPDFUnion::String(value)) {}
221
222 static SkString FormatString(const char* input, size_t len);
223
224 static const size_t kMaxLen = 65535;
103 225
104 private: 226 private:
105 int32_t fValue; 227 typedef SkPDFAtom INHERITED;
106
107 typedef SkPDFObject INHERITED;
108 }; 228 };
109 229
110 /** \class SkPDFBool 230 class SkPDFName : public SkPDFAtom {
231 public:
232 SK_DECLARE_INST_COUNT(SkPDFName);
233 /** Create a PDF name object. Maximum length is 127 bytes. */
234 explicit SkPDFName(const char name[])
235 : INHERITED(SkPDFUnion::Name(SkString(name))) {}
236 explicit SkPDFName(const SkString& name)
237 : INHERITED(SkPDFUnion::Name(name)) {}
111 238
112 An boolean value in a PDF. 239 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 240
129 private: 241 private:
130 bool fValue; 242 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 }; 243 };
223 244
224 /** \class SkPDFArray 245 /** \class SkPDFArray
225 246
226 An array object in a PDF. 247 An array object in a PDF.
227 */ 248 */
228 class SkPDFArray : public SkPDFObject { 249 class SkPDFArray : public SkPDFObject {
229 public: 250 public:
230 SK_DECLARE_INST_COUNT(SkPDFArray) 251 SK_DECLARE_INST_COUNT(SkPDFArray)
231 252
253 static const int kMaxLen = 8191;
254
232 /** Create a PDF array. Maximum length is 8191. 255 /** Create a PDF array. Maximum length is 8191.
233 */ 256 */
234 SkPDFArray(); 257 SkPDFArray();
235 virtual ~SkPDFArray(); 258 virtual ~SkPDFArray();
236 259
237 // The SkPDFObject interface. 260 // The SkPDFObject interface.
238 virtual void emitObject(SkWStream* stream, 261 virtual void emitObject(SkWStream* stream,
239 const SkPDFObjNumMap& objNumMap, 262 const SkPDFObjNumMap& objNumMap,
240 const SkPDFSubstituteMap& substitutes) override; 263 const SkPDFSubstituteMap& substitutes) override;
241 virtual void addResources(SkPDFObjNumMap*, 264 virtual void addResources(SkPDFObjNumMap*,
242 const SkPDFSubstituteMap&) const override; 265 const SkPDFSubstituteMap&) const override;
243 266
244 /** The size of the array. 267 /** The size of the array.
245 */ 268 */
246 int size() { return fValue.count(); } 269 int size() const;
247 270
248 /** Preallocate space for the given number of entries. 271 /** Preallocate space for the given number of entries.
249 * @param length The number of array slots to preallocate. 272 * @param length The number of array slots to preallocate.
250 */ 273 */
251 void reserve(int length); 274 void reserve(int length);
252 275
253 /** Append the object to the end of the array and increments its ref count. 276 /** Append the object to the end of the array and increments its ref count.
254 * @param value The value to add to the array. 277 * @param value The value to add to the array.
255 * @return The value argument is returned. 278 * @return The value argument is returned.
256 */ 279 */
280 // DEPRECATED
257 SkPDFObject* append(SkPDFObject* value); 281 SkPDFObject* append(SkPDFObject* value);
258 282
259 /** Creates a SkPDFInt object and appends it to the array. 283 /** Appends a value to the end of the array.
260 * @param value The value to add to the array. 284 * @param value The value to add to the array.
261 */ 285 */
262 void appendInt(int32_t value); 286 void appendInt(int32_t);
263 287 void appendBool(bool);
264 /** Creates a SkPDFScalar object and appends it to the array. 288 void appendScalar(SkScalar);
265 * @param value The value to add to the array. 289 void appendName(const char[]);
266 */ 290 void appendName(const SkString&);
267 void appendScalar(SkScalar value); 291 void appendString(const char[]);
268 292 void appendString(const SkString&);
269 /** Creates a SkPDFName object and appends it to the array. 293 /** appendObject and appendObjRef take ownership of the passed object */
270 * @param value The value to add to the array. 294 void appendObject(SkPDFObject*);
271 */ 295 void appendObjRef(SkPDFObject*);
272 void appendName(const char name[]);
273 296
274 private: 297 private:
275 static const int kMaxLen = 8191; 298 SkTDArray<SkPDFUnion> fValues;
276 SkTDArray<SkPDFObject*> fValue; 299 void append(SkPDFUnion&& value);
277
278 typedef SkPDFObject INHERITED; 300 typedef SkPDFObject INHERITED;
279 }; 301 };
280 302
281 /** \class SkPDFDict 303 /** \class SkPDFDict
282 304
283 A dictionary object in a PDF. 305 A dictionary object in a PDF.
284 */ 306 */
285 class SkPDFDict : public SkPDFObject { 307 class SkPDFDict : public SkPDFObject {
286 public: 308 public:
287 SK_DECLARE_INST_COUNT(SkPDFDict) 309 SK_DECLARE_INST_COUNT(SkPDFDict)
(...skipping 18 matching lines...) Expand all
306 328
307 /** The size of the dictionary. 329 /** The size of the dictionary.
308 */ 330 */
309 int size() const; 331 int size() const;
310 332
311 /** Add the value to the dictionary with the given key. Refs value. 333 /** Add the value to the dictionary with the given key. Refs value.
312 * @param key The key for this dictionary entry. 334 * @param key The key for this dictionary entry.
313 * @param value The value for this dictionary entry. 335 * @param value The value for this dictionary entry.
314 * @return The value argument is returned. 336 * @return The value argument is returned.
315 */ 337 */
338 // DEPRECATED
316 SkPDFObject* insert(SkPDFName* key, SkPDFObject* value); 339 SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
340 // DEPRECATED
341 SkPDFObject* insert(const char key[], SkPDFObject* value);
317 342
318 /** Add the value to the dictionary with the given key. Refs value. The 343 /** Add the value to the dictionary with the given key. Takes
319 * method will create the SkPDFName object. 344 * ownership of the object;
tomhudson 2015/04/24 21:32:30 Nit: interrupted comment edit?
hal.canary 2015/04/25 13:41:02 Thinking in C. ';' ends a statement.
320 * @param key The text of the key for this dictionary entry. 345 * @param key The text of the key for this dictionary entry.
321 * @param value The value for this dictionary entry. 346 * @param value The value for this dictionary entry.
322 * @return The value argument is returned.
323 */ 347 */
324 SkPDFObject* insert(const char key[], SkPDFObject* value); 348 void insertObject(const char key[], SkPDFObject* value);
349 void insertObject(const SkString& key, SkPDFObject* value);
350 void insertObjRef(const char key[], SkPDFObject* value);
351 void insertObjRef(const SkString& key, SkPDFObject* value);
325 352
326 /** Add the int to the dictionary with the given key. 353 /** Add the value to the dictionary with the given key.
327 * @param key The text of the key for this dictionary entry. 354 * @param key The text of the key for this dictionary entry.
328 * @param value The int value for this dictionary entry. 355 * @param value The value for this dictionary entry.
329 */ 356 */
330 void insertInt(const char key[], int32_t value); 357 void insertInt(const char key[], int32_t value);
331 358 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); 359 void insertScalar(const char key[], SkScalar value);
345 360 void insertName(const char key[], const char nameValue[]);
346 /** Add the name to the dictionary with the given key. 361 void insertName(const char key[], const SkString& nameValue);
347 * @param key The text of the key for this dictionary entry. 362 void insertString(const char key[], const char value[]);
348 * @param name The name for this dictionary entry. 363 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 364
360 /** Remove all entries from the dictionary. 365 /** Remove all entries from the dictionary.
361 */ 366 */
362 void clear(); 367 void clear();
363 368
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: 369 private:
375 struct Rec { 370 struct Record {
376 SkPDFName* key; 371 SkPDFUnion fKey;
377 SkPDFObject* value; 372 SkPDFUnion fValue;
378 Rec(SkPDFName* k, SkPDFObject* v) : key(k), value(v) {}
379 }; 373 };
380 374 SkTDArray<Record> fRecords;
381 static const int kMaxLen = 4095; 375 static const int kMaxLen = 4095;
382 376
383 SkTDArray<struct Rec> fValue; 377 void set(const SkPDFUnion& name, const SkPDFUnion& value);
384 378 void set(SkPDFUnion&& name, SkPDFUnion&& value);
385 SkPDFObject* append(SkPDFName* key, SkPDFObject* value);
386 379
387 typedef SkPDFObject INHERITED; 380 typedef SkPDFObject INHERITED;
388 }; 381 };
389 382
390 //////////////////////////////////////////////////////////////////////////////// 383 ////////////////////////////////////////////////////////////////////////////////
391 384
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 385 /** \class SkPDFObjNumMap
415 386
416 The PDF Object Number Map manages object numbers. It is used to 387 The PDF Object Number Map manages object numbers. It is used to
417 create the PDF cross reference table. 388 create the PDF cross reference table.
418 */ 389 */
419 class SkPDFObjNumMap : SkNoncopyable { 390 class SkPDFObjNumMap : SkNoncopyable {
420 public: 391 public:
421 /** Add the passed object to the catalog. 392 /** Add the passed object to the catalog.
422 * @param obj The object to add. 393 * @param obj The object to add.
423 * @return True iff the object was not already added to the catalog. 394 * @return True iff the object was not already added to the catalog.
424 */ 395 */
425 bool addObject(SkPDFObject* obj); 396 bool addObject(SkPDFObject* obj);
426 397
427 /** Get the object number for the passed object. 398 /** Get the object number for the passed object.
428 * @param obj The object of interest. 399 * @param obj The object of interest.
429 */ 400 */
430 int32_t getObjectNumber(SkPDFObject* obj) const; 401 int32_t getObjectNumber(SkPDFObject* obj) const;
431 402
432 const SkTDArray<SkPDFObject*>& objects() const { return fObjects; } 403 const SkTDArray<SkPDFObject*>& objects() const { return fObjects; }
433 404
434 private: 405 private:
435 SkTDArray<SkPDFObject*> fObjects; 406 SkTDArray<SkPDFObject*> fObjects;
436 SkTHashMap<SkPDFObject*, int32_t> fObjectNumbers; 407 SkTHashMap<SkPDFObject*, int32_t> fObjectNumbers;
437 }; 408 };
438 409
410 ////////////////////////////////////////////////////////////////////////////////
411
412 /** \class SkPDFSubstituteMap
413
414 The PDF Substitute Map manages substitute objects and owns the
415 substitutes.
416 */
417 class SkPDFSubstituteMap : SkNoncopyable {
418 public:
419 ~SkPDFSubstituteMap();
420 /** Set substitute object for the passed object.
421 Refs substitute.
422 */
423 void setSubstitute(SkPDFObject* original, SkPDFObject* substitute);
424
425 /** Find and return any substitute object set for the passed object. If
426 * there is none, return the passed object.
427 */
428 SkPDFObject* getSubstitute(SkPDFObject* object) const;
429
430 SkPDFObject* operator()(SkPDFObject* o) const {
431 return this->getSubstitute(o);
432 }
433
434 private:
435 SkTHashMap<SkPDFObject*, SkPDFObject*> fSubstituteMap;
436 };
437
439 #endif 438 #endif
OLDNEW
« no previous file with comments | « src/pdf/SkPDFResourceDict.cpp ('k') | src/pdf/SkPDFTypes.cpp » ('j') | src/pdf/SkPDFTypes.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698