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

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

Issue 1049753002: SkPDF: Factor SkPDFCatalog into SkPDFObjNumMap and SkPDFSubstituteMap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: full 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 1
2 /* 2 /*
3 * Copyright 2010 The Android Open Source Project 3 * Copyright 2010 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkPDFTypes_DEFINED 10 #ifndef SkPDFTypes_DEFINED
11 #define SkPDFTypes_DEFINED 11 #define SkPDFTypes_DEFINED
12 12
13 #include "SkPDFTypes.h"
13 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
14 #include "SkScalar.h" 15 #include "SkScalar.h"
15 #include "SkString.h" 16 #include "SkString.h"
16 #include "SkTDArray.h" 17 #include "SkTDArray.h"
18 #include "SkTHash.h"
17 #include "SkTypes.h" 19 #include "SkTypes.h"
18 20
19 class SkPDFCatalog; 21 class SkPDFObjNumMap;
22 class SkPDFObject;
23 class SkPDFSubstituteMap;
20 class SkWStream; 24 class SkWStream;
21 25
22 class SkPDFObject;
23
24 /** \class SkPDFObject 26 /** \class SkPDFObject
25 27
26 A PDF Object is the base class for primitive elements in a PDF file. A 28 A PDF Object is the base class for primitive elements in a PDF file. A
27 common subtype is used to ease the use of indirect object references, 29 common subtype is used to ease the use of indirect object references,
28 which are common in the PDF format. 30 which are common in the PDF format.
29 */ 31 */
30 class SkPDFObject : public SkRefCnt { 32 class SkPDFObject : public SkRefCnt {
31 public: 33 public:
32 SK_DECLARE_INST_COUNT(SkPDFObject) 34 SK_DECLARE_INST_COUNT(SkPDFObject)
33 35
34 /** Subclasses must implement this method to print the object to the 36 /** Subclasses must implement this method to print the object to the
35 * PDF file. 37 * PDF file.
36 * @param catalog The object catalog to use. 38 * @param catalog The object catalog to use.
37 * @param stream The writable output stream to send the output to. 39 * @param stream The writable output stream to send the output to.
38 */ 40 */
39 // TODO(halcanary): make this method const 41 // TODO(halcanary): make this method const
40 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) = 0; 42 virtual void emitObject(SkWStream* stream,
43 const SkPDFObjNumMap& objNumMap,
44 const SkPDFSubstituteMap& substitutes) = 0;
41 45
42 /** 46 /**
43 * Adds all transitive dependencies of this object to the 47 * Adds all transitive dependencies of this object to the
44 * catalog. Implementations should respect the catalog's object 48 * catalog. Implementations should respect the catalog's object
45 * substitution map. 49 * substitution map.
46 */ 50 */
47 virtual void addResources(SkPDFCatalog* catalog) const {} 51 virtual void addResources(SkPDFObjNumMap* catalog,
52 const SkPDFSubstituteMap& substitutes) const {}
48 53
49 private: 54 private:
50 typedef SkRefCnt INHERITED; 55 typedef SkRefCnt INHERITED;
51 }; 56 };
52 57
53 /** \class SkPDFObjRef 58 /** \class SkPDFObjRef
54 59
55 An indirect reference to a PDF object. 60 An indirect reference to a PDF object.
56 */ 61 */
57 class SkPDFObjRef : public SkPDFObject { 62 class SkPDFObjRef : public SkPDFObject {
58 public: 63 public:
59 SK_DECLARE_INST_COUNT(SkPDFObjRef) 64 SK_DECLARE_INST_COUNT(SkPDFObjRef)
60 65
61 /** Create a reference to an existing SkPDFObject. 66 /** Create a reference to an existing SkPDFObject.
62 * @param obj The object to reference. 67 * @param obj The object to reference.
63 */ 68 */
64 explicit SkPDFObjRef(SkPDFObject* obj); 69 explicit SkPDFObjRef(SkPDFObject* obj);
65 virtual ~SkPDFObjRef(); 70 virtual ~SkPDFObjRef();
66 71
67 // The SkPDFObject interface. 72 // The SkPDFObject interface.
68 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) override; 73 virtual void emitObject(SkWStream* stream,
69 virtual void addResources(SkPDFCatalog*) const override; 74 const SkPDFObjNumMap& objNumMap,
75 const SkPDFSubstituteMap& substitutes) override;
76 virtual void addResources(SkPDFObjNumMap*,
77 const SkPDFSubstituteMap&) const override;
70 78
71 private: 79 private:
72 SkAutoTUnref<SkPDFObject> fObj; 80 SkAutoTUnref<SkPDFObject> fObj;
73 81
74 typedef SkPDFObject INHERITED; 82 typedef SkPDFObject INHERITED;
75 }; 83 };
76 84
77 /** \class SkPDFInt 85 /** \class SkPDFInt
78 86
79 An integer object in a PDF. 87 An integer object in a PDF.
80 */ 88 */
81 class SkPDFInt : public SkPDFObject { 89 class SkPDFInt : public SkPDFObject {
82 public: 90 public:
83 SK_DECLARE_INST_COUNT(SkPDFInt) 91 SK_DECLARE_INST_COUNT(SkPDFInt)
84 92
85 /** Create a PDF integer (usually for indirect reference purposes). 93 /** Create a PDF integer (usually for indirect reference purposes).
86 * @param value An integer value between 2^31 - 1 and -2^31. 94 * @param value An integer value between 2^31 - 1 and -2^31.
87 */ 95 */
88 explicit SkPDFInt(int32_t value); 96 explicit SkPDFInt(int32_t value);
89 virtual ~SkPDFInt(); 97 virtual ~SkPDFInt();
90 98
91 // The SkPDFObject interface. 99 // The SkPDFObject interface.
92 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) override; 100 virtual void emitObject(SkWStream* stream,
101 const SkPDFObjNumMap& objNumMap,
102 const SkPDFSubstituteMap& substitutes) override;
93 103
94 private: 104 private:
95 int32_t fValue; 105 int32_t fValue;
96 106
97 typedef SkPDFObject INHERITED; 107 typedef SkPDFObject INHERITED;
98 }; 108 };
99 109
100 /** \class SkPDFBool 110 /** \class SkPDFBool
101 111
102 An boolean value in a PDF. 112 An boolean value in a PDF.
103 */ 113 */
104 class SkPDFBool : public SkPDFObject { 114 class SkPDFBool : public SkPDFObject {
105 public: 115 public:
106 SK_DECLARE_INST_COUNT(SkPDFBool) 116 SK_DECLARE_INST_COUNT(SkPDFBool)
107 117
108 /** Create a PDF boolean. 118 /** Create a PDF boolean.
109 * @param value true or false. 119 * @param value true or false.
110 */ 120 */
111 explicit SkPDFBool(bool value); 121 explicit SkPDFBool(bool value);
112 virtual ~SkPDFBool(); 122 virtual ~SkPDFBool();
113 123
114 // The SkPDFObject interface. 124 // The SkPDFObject interface.
115 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) override; 125 virtual void emitObject(SkWStream* stream,
126 const SkPDFObjNumMap& objNumMap,
127 const SkPDFSubstituteMap& substitutes) override;
116 128
117 private: 129 private:
118 bool fValue; 130 bool fValue;
119 131
120 typedef SkPDFObject INHERITED; 132 typedef SkPDFObject INHERITED;
121 }; 133 };
122 134
123 /** \class SkPDFScalar 135 /** \class SkPDFScalar
124 136
125 A real number object in a PDF. 137 A real number object in a PDF.
126 */ 138 */
127 class SkPDFScalar : public SkPDFObject { 139 class SkPDFScalar : public SkPDFObject {
128 public: 140 public:
129 SK_DECLARE_INST_COUNT(SkPDFScalar) 141 SK_DECLARE_INST_COUNT(SkPDFScalar)
130 142
131 /** Create a PDF real number. 143 /** Create a PDF real number.
132 * @param value A real value. 144 * @param value A real value.
133 */ 145 */
134 explicit SkPDFScalar(SkScalar value); 146 explicit SkPDFScalar(SkScalar value);
135 virtual ~SkPDFScalar(); 147 virtual ~SkPDFScalar();
136 148
137 static void Append(SkScalar value, SkWStream* stream); 149 static void Append(SkScalar value, SkWStream* stream);
138 150
139 // The SkPDFObject interface. 151 // The SkPDFObject interface.
140 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) override; 152 virtual void emitObject(SkWStream* stream,
153 const SkPDFObjNumMap& objNumMap,
154 const SkPDFSubstituteMap& substitutes) override;
141 155
142 private: 156 private:
143 SkScalar fValue; 157 SkScalar fValue;
144 158
145 typedef SkPDFObject INHERITED; 159 typedef SkPDFObject INHERITED;
146 }; 160 };
147 161
148 /** \class SkPDFString 162 /** \class SkPDFString
149 163
150 A string object in a PDF. 164 A string object in a PDF.
(...skipping 11 matching lines...) Expand all
162 /** Create a PDF string. Maximum length (in bytes) is 65,535. 176 /** Create a PDF string. Maximum length (in bytes) is 65,535.
163 * @param value A string value. 177 * @param value A string value.
164 * @param len The length of value. 178 * @param len The length of value.
165 * @param wideChars Indicates if the top byte in value is significant and 179 * @param wideChars Indicates if the top byte in value is significant and
166 * should be encoded (true) or not (false). 180 * should be encoded (true) or not (false).
167 */ 181 */
168 SkPDFString(const uint16_t* value, size_t len, bool wideChars); 182 SkPDFString(const uint16_t* value, size_t len, bool wideChars);
169 virtual ~SkPDFString(); 183 virtual ~SkPDFString();
170 184
171 // The SkPDFObject interface. 185 // The SkPDFObject interface.
172 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) override; 186 virtual void emitObject(SkWStream* stream,
187 const SkPDFObjNumMap& objNumMap,
188 const SkPDFSubstituteMap& substitutes) override;
173 189
174 static SkString FormatString(const char* input, size_t len); 190 static SkString FormatString(const char* input, size_t len);
175 static SkString FormatString(const uint16_t* input, size_t len, 191 static SkString FormatString(const uint16_t* input, size_t len,
176 bool wideChars); 192 bool wideChars);
177 private: 193 private:
178 static const size_t kMaxLen = 65535; 194 static const size_t kMaxLen = 65535;
179 195
180 const SkString fValue; 196 const SkString fValue;
181 197
182 static SkString DoFormatString(const void* input, size_t len, 198 static SkString DoFormatString(const void* input, size_t len,
(...skipping 13 matching lines...) Expand all
196 /** Create a PDF name object. Maximum length is 127 bytes. 212 /** Create a PDF name object. Maximum length is 127 bytes.
197 * @param value The name. 213 * @param value The name.
198 */ 214 */
199 explicit SkPDFName(const char name[]); 215 explicit SkPDFName(const char name[]);
200 explicit SkPDFName(const SkString& name); 216 explicit SkPDFName(const SkString& name);
201 virtual ~SkPDFName(); 217 virtual ~SkPDFName();
202 218
203 bool operator==(const SkPDFName& b) const; 219 bool operator==(const SkPDFName& b) const;
204 220
205 // The SkPDFObject interface. 221 // The SkPDFObject interface.
206 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) override; 222 virtual void emitObject(SkWStream* stream,
223 const SkPDFObjNumMap& objNumMap,
224 const SkPDFSubstituteMap& substitutes) override;
207 225
208 private: 226 private:
209 static const size_t kMaxLen = 127; 227 static const size_t kMaxLen = 127;
210 228
211 const SkString fValue; 229 const SkString fValue;
212 230
213 static SkString FormatName(const SkString& input); 231 static SkString FormatName(const SkString& input);
214 232
215 typedef SkPDFObject INHERITED; 233 typedef SkPDFObject INHERITED;
216 }; 234 };
217 235
218 /** \class SkPDFArray 236 /** \class SkPDFArray
219 237
220 An array object in a PDF. 238 An array object in a PDF.
221 */ 239 */
222 class SkPDFArray : public SkPDFObject { 240 class SkPDFArray : public SkPDFObject {
223 public: 241 public:
224 SK_DECLARE_INST_COUNT(SkPDFArray) 242 SK_DECLARE_INST_COUNT(SkPDFArray)
225 243
226 /** Create a PDF array. Maximum length is 8191. 244 /** Create a PDF array. Maximum length is 8191.
227 */ 245 */
228 SkPDFArray(); 246 SkPDFArray();
229 virtual ~SkPDFArray(); 247 virtual ~SkPDFArray();
230 248
231 // The SkPDFObject interface. 249 // The SkPDFObject interface.
232 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) override; 250 virtual void emitObject(SkWStream* stream,
233 virtual void addResources(SkPDFCatalog*) const override; 251 const SkPDFObjNumMap& objNumMap,
252 const SkPDFSubstituteMap& substitutes) override;
253 virtual void addResources(SkPDFObjNumMap*,
254 const SkPDFSubstituteMap&) const override;
234 255
235 /** The size of the array. 256 /** The size of the array.
236 */ 257 */
237 int size() { return fValue.count(); } 258 int size() { return fValue.count(); }
238 259
239 /** Preallocate space for the given number of entries. 260 /** Preallocate space for the given number of entries.
240 * @param length The number of array slots to preallocate. 261 * @param length The number of array slots to preallocate.
241 */ 262 */
242 void reserve(int length); 263 void reserve(int length);
243 264
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 SkPDFDict(); 315 SkPDFDict();
295 316
296 /** Create a PDF dictionary with a Type entry. 317 /** Create a PDF dictionary with a Type entry.
297 * @param type The value of the Type entry. 318 * @param type The value of the Type entry.
298 */ 319 */
299 explicit SkPDFDict(const char type[]); 320 explicit SkPDFDict(const char type[]);
300 321
301 virtual ~SkPDFDict(); 322 virtual ~SkPDFDict();
302 323
303 // The SkPDFObject interface. 324 // The SkPDFObject interface.
304 virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog) override; 325 virtual void emitObject(SkWStream* stream,
305 virtual void addResources(SkPDFCatalog*) const override; 326 const SkPDFObjNumMap& objNumMap,
327 const SkPDFSubstituteMap& substitutes) override;
328 virtual void addResources(SkPDFObjNumMap*,
329 const SkPDFSubstituteMap&) const override;
306 330
307 /** The size of the dictionary. 331 /** The size of the dictionary.
308 */ 332 */
309 int size() const; 333 int size() const;
310 334
311 /** Add the value to the dictionary with the given key. Refs value. 335 /** Add the value to the dictionary with the given key. Refs value.
312 * @param key The key for this dictionary entry. 336 * @param key The key for this dictionary entry.
313 * @param value The value for this dictionary entry. 337 * @param value The value for this dictionary entry.
314 * @return The value argument is returned. 338 * @return The value argument is returned.
315 */ 339 */
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 404
381 static const int kMaxLen = 4095; 405 static const int kMaxLen = 4095;
382 406
383 SkTDArray<struct Rec> fValue; 407 SkTDArray<struct Rec> fValue;
384 408
385 SkPDFObject* append(SkPDFName* key, SkPDFObject* value); 409 SkPDFObject* append(SkPDFName* key, SkPDFObject* value);
386 410
387 typedef SkPDFObject INHERITED; 411 typedef SkPDFObject INHERITED;
388 }; 412 };
389 413
414 ////////////////////////////////////////////////////////////////////////////////
415
416 /** \class SkPDFSubstituteMap
417
418 The PDF Substitute Map manages substitute objects and owns the
419 substitutes.
420 */
421 class SkPDFSubstituteMap : SkNoncopyable {
422 public:
423 ~SkPDFSubstituteMap();
424 /** Set substitute object for the passed object.
425 Refs substitute.
426 */
427 void setSubstitute(SkPDFObject* original, SkPDFObject* substitute);
428
429 /** Find and return any substitute object set for the passed object. If
430 * there is none, return the passed object.
431 */
432 SkPDFObject* getSubstitute(SkPDFObject* object) const;
433
434 private:
435 SkTHashMap<SkPDFObject*, SkPDFObject*> fSubstituteMap;
436 };
437
438 /** \class SkPDFObjNumMap
439
440 The PDF Object Number Map manages object numbers. It is used to
441 create the PDF cross reference table.
442 */
443 class SkPDFObjNumMap : SkNoncopyable {
444 public:
445 /** Add the passed object to the catalog.
446 * @param obj The object to add.
447 * @return True iff the object was not already added to the catalog.
448 */
449 bool addObject(SkPDFObject* obj);
450
451 /** Get the object number for the passed object.
452 * @param obj The object of interest.
453 */
454 int32_t getObjectNumber(SkPDFObject* obj) const;
455
456 const SkTDArray<SkPDFObject*>& objects() const { return fObjects; }
457
458 private:
459 SkTDArray<SkPDFObject*> fObjects;
460 SkTHashMap<SkPDFObject*, int32_t> fObjectNumbers;
461 };
462
390 #endif 463 #endif
OLDNEW
« src/pdf/SkPDFStream.cpp ('K') | « src/pdf/SkPDFStream.cpp ('k') | src/pdf/SkPDFTypes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698