OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkPdfNativeObject_DEFINED | 8 #ifndef SkPdfNativeObject_DEFINED |
9 #define SkPdfNativeObject_DEFINED | 9 #define SkPdfNativeObject_DEFINED |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 class SkPdfDictionary; | 24 class SkPdfDictionary; |
25 class SkPdfStream; | 25 class SkPdfStream; |
26 class SkPdfAllocator; | 26 class SkPdfAllocator; |
27 | 27 |
28 // TODO(edisonn): remove these constants and clean up the code. | 28 // TODO(edisonn): remove these constants and clean up the code. |
29 #define kFilteredStreamBit 0 | 29 #define kFilteredStreamBit 0 |
30 #define kUnfilteredStreamBit 1 | 30 #define kUnfilteredStreamBit 1 |
31 #define kOwnedStreamBit 2 | 31 #define kOwnedStreamBit 2 |
32 | 32 |
| 33 /** \class SkPdfNativeObject |
| 34 * |
| 35 * The SkPdfNativeObject class is used to store a pdf object. Classes that inhe
rit it are not |
| 36 * allowed to add fields. |
| 37 * |
| 38 * SkPdfAllocator will allocate them in chunks and will free them in destructor
. |
| 39 * |
| 40 * You can allocate one on the stack, as long as you call reset() at the end, a
nd any objects it |
| 41 * points to in an allocator. But if your object is a simple one, like number,
then |
| 42 * putting it on stack will be just fine. |
| 43 * |
| 44 */ |
33 class SkPdfNativeObject { | 45 class SkPdfNativeObject { |
34 public: | 46 public: |
35 enum ObjectType { | 47 enum ObjectType { |
36 // The type will have only one of these values, but for error reporting
, we make it an enum | 48 // The type will have only one of these values, but for error reporting
, we make it an enum |
37 // so it can easily report that something was expected to be one of a f
ew types | 49 // so it can easily report that something was expected to be one of a f
ew types |
38 kInvalid_PdfObjectType = 1 << 1, | 50 kInvalid_PdfObjectType = 1 << 1, |
39 | 51 |
40 kBoolean_PdfObjectType = 1 << 2, | 52 kBoolean_PdfObjectType = 1 << 2, |
41 kInteger_PdfObjectType = 1 << 3, | 53 kInteger_PdfObjectType = 1 << 3, |
42 kReal_PdfObjectType = 1 << 4, | 54 kReal_PdfObjectType = 1 << 4, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 99 |
88 SkTDArray<SkPdfNativeObject*>* fArray; | 100 SkTDArray<SkPdfNativeObject*>* fArray; |
89 Reference fRef; | 101 Reference fRef; |
90 }; | 102 }; |
91 SkTDict<SkPdfNativeObject*>* fMap; | 103 SkTDict<SkPdfNativeObject*>* fMap; |
92 | 104 |
93 // TODO(edisonn): rename data with cache | 105 // TODO(edisonn): rename data with cache |
94 void* fData; | 106 void* fData; |
95 DataType fDataType; | 107 DataType fDataType; |
96 | 108 |
97 // Keep this the last entries | |
98 #ifdef PDF_TRACK_OBJECT_USAGE | 109 #ifdef PDF_TRACK_OBJECT_USAGE |
| 110 // Records if the object was used during rendering/proccessing. It can be us
ed to track |
| 111 // what features are only partially implemented, by looking at what objects
have not been |
| 112 // accessed. |
99 mutable bool fUsed; | 113 mutable bool fUsed; |
100 #endif // PDF_TRACK_OBJECT_USAGE | 114 #endif // PDF_TRACK_OBJECT_USAGE |
101 | 115 |
102 #ifdef PDF_TRACK_STREAM_OFFSETS | 116 #ifdef PDF_TRACK_STREAM_OFFSETS |
103 public: | 117 public: |
| 118 // TODO(edisonn): replace them with char* start, end - and a mechanism to re
gister streams. |
104 int fStreamId; | 119 int fStreamId; |
105 int fOffsetStart; | 120 int fOffsetStart; |
106 int fOffsetEnd; | 121 int fOffsetEnd; |
107 #endif // PDF_TRACK_STREAM_OFFSETS | 122 #endif // PDF_TRACK_STREAM_OFFSETS |
108 | 123 |
109 public: | 124 public: |
110 | 125 |
111 #ifdef PDF_TRACK_STREAM_OFFSETS | 126 #ifdef PDF_TRACK_STREAM_OFFSETS |
| 127 // TODO(edisonn): remove these ones. |
112 int streamId() const { return fStreamId; } | 128 int streamId() const { return fStreamId; } |
113 int offsetStart() const { return fOffsetStart; } | 129 int offsetStart() const { return fOffsetStart; } |
114 int offsetEnd() const { return fOffsetEnd; } | 130 int offsetEnd() const { return fOffsetEnd; } |
115 #endif // PDF_TRACK_STREAM_OFFSETS | 131 #endif // PDF_TRACK_STREAM_OFFSETS |
116 | 132 |
117 | |
118 SkPdfNativeObject() : fInRendering(0) | 133 SkPdfNativeObject() : fInRendering(0) |
119 , fObjectType(kInvalid_PdfObjectType) | 134 , fObjectType(kInvalid_PdfObjectType) |
120 , fMap(NULL) | 135 , fMap(NULL) |
121 , fData(NULL) | 136 , fData(NULL) |
122 , fDataType(kEmpty_Data) | 137 , fDataType(kEmpty_Data) |
123 #ifdef PDF_TRACK_OBJECT_USAGE | 138 #ifdef PDF_TRACK_OBJECT_USAGE |
124 , fUsed(false) | 139 , fUsed(false) |
125 #endif // PDF_TRACK_OBJECT_USAGE | 140 #endif // PDF_TRACK_OBJECT_USAGE |
126 | 141 |
127 #ifdef PDF_TRACK_STREAM_OFFSETS | 142 #ifdef PDF_TRACK_STREAM_OFFSETS |
128 , fStreamId(-1) | 143 , fStreamId(-1) |
129 , fOffsetStart(-1) | 144 , fOffsetStart(-1) |
130 , fOffsetEnd(-1) | 145 , fOffsetEnd(-1) |
131 #endif // PDF_TRACK_STREAM_OFFSETS | 146 #endif // PDF_TRACK_STREAM_OFFSETS |
132 {} | 147 {} |
133 | 148 |
| 149 // Used to verify if a form is used in rendering, to check for infinite loop
s. |
134 bool inRendering() const { return fInRendering != 0; } | 150 bool inRendering() const { return fInRendering != 0; } |
135 void startRendering() {fInRendering = 1;} | 151 void startRendering() {fInRendering = 1;} |
136 void doneRendering() {fInRendering = 0;} | 152 void doneRendering() {fInRendering = 0;} |
137 | 153 |
| 154 // Each object can cache one entry associated with it. |
| 155 // for example a SkPdfImage could cache an SkBitmap, of a SkPdfFont, could c
ache a SkTypeface. |
138 inline bool hasData(DataType type) { | 156 inline bool hasData(DataType type) { |
139 return type == fDataType; | 157 return type == fDataType; |
140 } | 158 } |
141 | 159 |
| 160 // returns the cached value |
142 inline void* data(DataType type) { | 161 inline void* data(DataType type) { |
143 return type == fDataType ? fData : NULL; | 162 return type == fDataType ? fData : NULL; |
144 } | 163 } |
145 | 164 |
| 165 // Stores something in the cache |
146 inline void setData(void* data, DataType type) { | 166 inline void setData(void* data, DataType type) { |
147 releaseData(); | 167 releaseData(); |
148 fDataType = type; | 168 fDataType = type; |
149 fData = data; | 169 fData = data; |
150 } | 170 } |
151 | 171 |
| 172 // destroys the cache |
152 void releaseData(); | 173 void releaseData(); |
153 | 174 |
| 175 // TODO(edisonn): add an assert that reset was called |
154 // ~SkPdfNativeObject() { | 176 // ~SkPdfNativeObject() { |
155 // //reset(); must be called manually! Normally, will be called by alloc
ator destructor. | 177 // //reset(); must be called manually! Normally, will be called by alloc
ator destructor. |
156 // } | 178 // } |
157 | 179 |
| 180 // Resets a pdf object, deleting all resources directly referenced. |
| 181 // It will not reset/delete indirect resources. |
| 182 // (e.g. it deletes only the array holding pointers to objects, but does not
del the objects) |
158 void reset() { | 183 void reset() { |
159 SkPdfMarkObjectUnused(); | 184 SkPdfMarkObjectUnused(); |
160 | 185 |
161 switch (fObjectType) { | 186 switch (fObjectType) { |
162 case kArray_PdfObjectType: | 187 case kArray_PdfObjectType: |
163 delete fArray; | 188 delete fArray; |
164 break; | 189 break; |
165 | 190 |
166 case kDictionary_PdfObjectType: | 191 case kDictionary_PdfObjectType: |
167 delete fMap; | 192 delete fMap; |
168 if (isStreamOwned()) { | 193 if (isStreamOwned()) { |
169 delete[] fStr.fBuffer; | 194 delete[] fStr.fBuffer; |
170 fStr.fBuffer = NULL; | 195 fStr.fBuffer = NULL; |
171 fStr.fBytes = 0; | 196 fStr.fBytes = 0; |
172 } | 197 } |
173 break; | 198 break; |
174 | 199 |
175 default: | 200 default: |
176 break; | 201 break; |
177 } | 202 } |
178 fObjectType = kInvalid_PdfObjectType; | 203 fObjectType = kInvalid_PdfObjectType; |
179 releaseData(); | 204 releaseData(); |
180 } | 205 } |
181 | 206 |
| 207 // returns the object type (Null, Integer, String, Dictionary, ... ) |
| 208 // It does not specify what type of dictionary we have. |
182 ObjectType type() { | 209 ObjectType type() { |
183 SkPdfMarkObjectUsed(); | 210 SkPdfMarkObjectUsed(); |
184 | 211 |
185 return fObjectType; | 212 return fObjectType; |
186 } | 213 } |
187 | 214 |
| 215 // Gives quick access to the buffer's address of a string/keyword/name |
188 const char* c_str() const { | 216 const char* c_str() const { |
189 SkPdfMarkObjectUsed(); | 217 SkPdfMarkObjectUsed(); |
190 | 218 |
191 switch (fObjectType) { | 219 switch (fObjectType) { |
192 case kString_PdfObjectType: | 220 case kString_PdfObjectType: |
193 case kHexString_PdfObjectType: | 221 case kHexString_PdfObjectType: |
194 case kKeyword_PdfObjectType: | 222 case kKeyword_PdfObjectType: |
195 case kName_PdfObjectType: | 223 case kName_PdfObjectType: |
196 return (const char*)fStr.fBuffer; | 224 return (const char*)fStr.fBuffer; |
197 | 225 |
198 default: | 226 default: |
199 // TODO(edisonn): report/warning/assert? | 227 // TODO(edisonn): report/warning/assert? |
200 return NULL; | 228 return NULL; |
201 } | 229 } |
202 } | 230 } |
203 | 231 |
| 232 // Gives quick access to the length of a string/keyword/name |
204 size_t lenstr() const { | 233 size_t lenstr() const { |
205 SkPdfMarkObjectUsed(); | 234 SkPdfMarkObjectUsed(); |
206 | 235 |
207 switch (fObjectType) { | 236 switch (fObjectType) { |
208 case kString_PdfObjectType: | 237 case kString_PdfObjectType: |
209 case kHexString_PdfObjectType: | 238 case kHexString_PdfObjectType: |
210 case kKeyword_PdfObjectType: | 239 case kKeyword_PdfObjectType: |
211 case kName_PdfObjectType: | 240 case kName_PdfObjectType: |
212 return fStr.fBytes; | 241 return fStr.fBytes; |
213 | 242 |
(...skipping 21 matching lines...) Expand all Loading... |
235 static SkPdfFileSpec nyi; | 264 static SkPdfFileSpec nyi; |
236 return nyi; | 265 return nyi; |
237 } | 266 } |
238 | 267 |
239 // TODO(edisonn): NYI | 268 // TODO(edisonn): NYI |
240 SkPdfTree& treeValue() const { | 269 SkPdfTree& treeValue() const { |
241 static SkPdfTree nyi; | 270 static SkPdfTree nyi; |
242 return nyi; | 271 return nyi; |
243 } | 272 } |
244 | 273 |
| 274 // Creates a Boolean object. Assumes and asserts that it was never initializ
ed. |
245 static void makeBoolean(bool value, SkPdfNativeObject* obj) { | 275 static void makeBoolean(bool value, SkPdfNativeObject* obj) { |
246 | |
247 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 276 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
248 | 277 |
249 obj->fObjectType = kBoolean_PdfObjectType; | 278 obj->fObjectType = kBoolean_PdfObjectType; |
250 obj->fBooleanValue = value; | 279 obj->fBooleanValue = value; |
251 } | 280 } |
252 | 281 |
253 static SkPdfNativeObject makeBoolean(bool value) { | 282 static SkPdfNativeObject makeBoolean(bool value) { |
254 SkPdfNativeObject obj; | 283 SkPdfNativeObject obj; |
255 | 284 |
256 obj.fObjectType = kBoolean_PdfObjectType; | 285 obj.fObjectType = kBoolean_PdfObjectType; |
257 obj.fBooleanValue = value; | 286 obj.fBooleanValue = value; |
258 return obj; | 287 return obj; |
259 } | 288 } |
260 | 289 |
| 290 // Creates an Integer object. Assumes and asserts that it was never initiali
zed. |
261 static void makeInteger(int64_t value, SkPdfNativeObject* obj) { | 291 static void makeInteger(int64_t value, SkPdfNativeObject* obj) { |
262 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 292 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
263 | 293 |
264 obj->fObjectType = kInteger_PdfObjectType; | 294 obj->fObjectType = kInteger_PdfObjectType; |
265 obj->fIntegerValue = value; | 295 obj->fIntegerValue = value; |
266 } | 296 } |
267 | 297 |
| 298 // Creates a Real object. Assumes and asserts that it was never initialized. |
268 static void makeReal(double value, SkPdfNativeObject* obj) { | 299 static void makeReal(double value, SkPdfNativeObject* obj) { |
269 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 300 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
270 | 301 |
271 obj->fObjectType = kReal_PdfObjectType; | 302 obj->fObjectType = kReal_PdfObjectType; |
272 obj->fRealValue = value; | 303 obj->fRealValue = value; |
273 } | 304 } |
274 | 305 |
| 306 // Creates a Null object. Assumes and asserts that it was never initialized. |
275 static void makeNull(SkPdfNativeObject* obj) { | 307 static void makeNull(SkPdfNativeObject* obj) { |
276 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 308 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
277 | 309 |
278 obj->fObjectType = kNull_PdfObjectType; | 310 obj->fObjectType = kNull_PdfObjectType; |
279 } | 311 } |
280 | 312 |
281 static SkPdfNativeObject makeNull() { | 313 static SkPdfNativeObject makeNull() { |
282 SkPdfNativeObject obj; | 314 SkPdfNativeObject obj; |
283 | 315 |
284 obj.fObjectType = kNull_PdfObjectType; | 316 obj.fObjectType = kNull_PdfObjectType; |
285 return obj; | 317 return obj; |
286 } | 318 } |
287 | 319 |
| 320 // TODO(edisonn): this might not woirk well in Chrome |
288 static SkPdfNativeObject kNull; | 321 static SkPdfNativeObject kNull; |
289 | 322 |
| 323 // Creates a Numeric object from a string. Assumes and asserts that it was n
ever initialized. |
290 static void makeNumeric(const unsigned char* start, const unsigned char* end
, | 324 static void makeNumeric(const unsigned char* start, const unsigned char* end
, |
291 SkPdfNativeObject* obj) { | 325 SkPdfNativeObject* obj) { |
292 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 326 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
293 | 327 |
294 // TODO(edisonn): NYI properly | 328 // TODO(edisonn): NYI properly |
295 // if has dot (impl), or exceeds max int, is real, otherwise is int | 329 // if has dot (impl), or exceeds max int, is real, otherwise is int |
296 bool isInt = true; | 330 bool isInt = true; |
297 for (const unsigned char* current = start; current < end; current++) { | 331 for (const unsigned char* current = start; current < end; current++) { |
298 if (*current == '.') { | 332 if (*current == '.') { |
299 isInt = false; | 333 isInt = false; |
300 break; | 334 break; |
301 } | 335 } |
302 // TODO(edisonn): report parse issue with numbers like "24asdasd123" | 336 // TODO(edisonn): report parse issue with numbers like "24asdasd123" |
303 } | 337 } |
304 if (isInt) { | 338 if (isInt) { |
305 makeInteger(atol((const char*)start), obj); | 339 makeInteger(atol((const char*)start), obj); |
306 } else { | 340 } else { |
307 makeReal(atof((const char*)start), obj); | 341 makeReal(atof((const char*)start), obj); |
308 } | 342 } |
309 } | 343 } |
310 | 344 |
| 345 // Creates a Reference object. Assumes and asserts that it was never initial
ized. |
311 static void makeReference(unsigned int id, unsigned int gen, SkPdfNativeObje
ct* obj) { | 346 static void makeReference(unsigned int id, unsigned int gen, SkPdfNativeObje
ct* obj) { |
312 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 347 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
313 | 348 |
314 obj->fObjectType = kReference_PdfObjectType; | 349 obj->fObjectType = kReference_PdfObjectType; |
315 obj->fRef.fId = id; | 350 obj->fRef.fId = id; |
316 obj->fRef.fGen = gen; | 351 obj->fRef.fGen = gen; |
317 } | 352 } |
318 | 353 |
| 354 // Creates a Reference object. Resets the object before use. |
319 static void resetAndMakeReference(unsigned int id, unsigned int gen, SkPdfNa
tiveObject* obj) { | 355 static void resetAndMakeReference(unsigned int id, unsigned int gen, SkPdfNa
tiveObject* obj) { |
320 obj->reset(); | 356 obj->reset(); |
321 makeReference(id, gen, obj); | 357 makeReference(id, gen, obj); |
322 } | 358 } |
323 | 359 |
324 | 360 // Creates a String object. Assumes and asserts that it was never initialize
d. |
325 static void makeString(const unsigned char* start, SkPdfNativeObject* obj) { | 361 static void makeString(const unsigned char* start, SkPdfNativeObject* obj) { |
326 makeStringCore(start, strlen((const char*)start), obj, kString_PdfObject
Type); | 362 makeStringCore(start, strlen((const char*)start), obj, kString_PdfObject
Type); |
327 } | 363 } |
328 | 364 |
| 365 // Creates a String object. Assumes and asserts that it was never initialize
d. |
329 static void makeString(const unsigned char* start, const unsigned char* end, | 366 static void makeString(const unsigned char* start, const unsigned char* end, |
330 SkPdfNativeObject* obj) { | 367 SkPdfNativeObject* obj) { |
331 makeStringCore(start, end - start, obj, kString_PdfObjectType); | 368 makeStringCore(start, end - start, obj, kString_PdfObjectType); |
332 } | 369 } |
333 | 370 |
| 371 // Creates a String object. Assumes and asserts that it was never initialize
d. |
334 static void makeString(const unsigned char* start, size_t bytes, SkPdfNative
Object* obj) { | 372 static void makeString(const unsigned char* start, size_t bytes, SkPdfNative
Object* obj) { |
335 makeStringCore(start, bytes, obj, kString_PdfObjectType); | 373 makeStringCore(start, bytes, obj, kString_PdfObjectType); |
336 } | 374 } |
337 | 375 |
338 | 376 // Creates a HexString object. Assumes and asserts that it was never initial
ized. |
339 static void makeHexString(const unsigned char* start, SkPdfNativeObject* obj
) { | 377 static void makeHexString(const unsigned char* start, SkPdfNativeObject* obj
) { |
340 makeStringCore(start, strlen((const char*)start), obj, kHexString_PdfObj
ectType); | 378 makeStringCore(start, strlen((const char*)start), obj, kHexString_PdfObj
ectType); |
341 } | 379 } |
342 | 380 |
| 381 // Creates a HexString object. Assumes and asserts that it was never initial
ized. |
343 static void makeHexString(const unsigned char* start, const unsigned char* e
nd, | 382 static void makeHexString(const unsigned char* start, const unsigned char* e
nd, |
344 SkPdfNativeObject* obj) { | 383 SkPdfNativeObject* obj) { |
345 makeStringCore(start, end - start, obj, kHexString_PdfObjectType); | 384 makeStringCore(start, end - start, obj, kHexString_PdfObjectType); |
346 } | 385 } |
347 | 386 |
| 387 // Creates a HexString object. Assumes and asserts that it was never initial
ized. |
348 static void makeHexString(const unsigned char* start, size_t bytes, SkPdfNat
iveObject* obj) { | 388 static void makeHexString(const unsigned char* start, size_t bytes, SkPdfNat
iveObject* obj) { |
349 makeStringCore(start, bytes, obj, kHexString_PdfObjectType); | 389 makeStringCore(start, bytes, obj, kHexString_PdfObjectType); |
350 } | 390 } |
351 | 391 |
352 | 392 // Creates a Name object. Assumes and asserts that it was never initialized. |
353 static void makeName(const unsigned char* start, SkPdfNativeObject* obj) { | 393 static void makeName(const unsigned char* start, SkPdfNativeObject* obj) { |
354 makeStringCore(start, strlen((const char*)start), obj, kName_PdfObjectTy
pe); | 394 makeStringCore(start, strlen((const char*)start), obj, kName_PdfObjectTy
pe); |
355 } | 395 } |
356 | 396 |
| 397 // Creates a Name object. Assumes and asserts that it was never initialized. |
357 static void makeName(const unsigned char* start, const unsigned char* end, | 398 static void makeName(const unsigned char* start, const unsigned char* end, |
358 SkPdfNativeObject* obj) { | 399 SkPdfNativeObject* obj) { |
359 makeStringCore(start, end - start, obj, kName_PdfObjectType); | 400 makeStringCore(start, end - start, obj, kName_PdfObjectType); |
360 } | 401 } |
361 | 402 |
| 403 // Creates a Name object. Assumes and asserts that it was never initialized. |
362 static void makeName(const unsigned char* start, size_t bytes, SkPdfNativeOb
ject* obj) { | 404 static void makeName(const unsigned char* start, size_t bytes, SkPdfNativeOb
ject* obj) { |
363 makeStringCore(start, bytes, obj, kName_PdfObjectType); | 405 makeStringCore(start, bytes, obj, kName_PdfObjectType); |
364 } | 406 } |
365 | 407 |
366 | 408 // Creates a Keyword object. Assumes and asserts that it was never initializ
ed. |
367 static void makeKeyword(const unsigned char* start, SkPdfNativeObject* obj)
{ | 409 static void makeKeyword(const unsigned char* start, SkPdfNativeObject* obj)
{ |
368 makeStringCore(start, strlen((const char*)start), obj, kKeyword_PdfObjec
tType); | 410 makeStringCore(start, strlen((const char*)start), obj, kKeyword_PdfObjec
tType); |
369 } | 411 } |
370 | 412 |
| 413 // Creates a Keyword object. Assumes and asserts that it was never initializ
ed. |
371 static void makeKeyword(const unsigned char* start, const unsigned char* end
, | 414 static void makeKeyword(const unsigned char* start, const unsigned char* end
, |
372 SkPdfNativeObject* obj) { | 415 SkPdfNativeObject* obj) { |
373 makeStringCore(start, end - start, obj, kKeyword_PdfObjectType); | 416 makeStringCore(start, end - start, obj, kKeyword_PdfObjectType); |
374 } | 417 } |
375 | 418 |
| 419 // Creates a Keyword object. Assumes and asserts that it was never initializ
ed. |
376 static void makeKeyword(const unsigned char* start, size_t bytes, SkPdfNativ
eObject* obj) { | 420 static void makeKeyword(const unsigned char* start, size_t bytes, SkPdfNativ
eObject* obj) { |
377 makeStringCore(start, bytes, obj, kKeyword_PdfObjectType); | 421 makeStringCore(start, bytes, obj, kKeyword_PdfObjectType); |
378 } | 422 } |
379 | 423 |
| 424 // Creates an empty Array object. Assumes and asserts that it was never init
ialized. |
380 static void makeEmptyArray(SkPdfNativeObject* obj) { | 425 static void makeEmptyArray(SkPdfNativeObject* obj) { |
381 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 426 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
382 | 427 |
383 obj->fObjectType = kArray_PdfObjectType; | 428 obj->fObjectType = kArray_PdfObjectType; |
384 obj->fArray = new SkTDArray<SkPdfNativeObject*>(); | 429 obj->fArray = new SkTDArray<SkPdfNativeObject*>(); |
385 } | 430 } |
386 | 431 |
| 432 // Appends an object into the array. Assumes <this> is an array. |
387 bool appendInArray(SkPdfNativeObject* obj) { | 433 bool appendInArray(SkPdfNativeObject* obj) { |
388 SkASSERT(fObjectType == kArray_PdfObjectType); | 434 SkASSERT(fObjectType == kArray_PdfObjectType); |
389 if (fObjectType != kArray_PdfObjectType) { | 435 if (fObjectType != kArray_PdfObjectType) { |
390 // TODO(edisonn): report/warning/assert? | 436 // TODO(edisonn): report/warning/assert? |
391 return false; | 437 return false; |
392 } | 438 } |
393 | 439 |
394 fArray->push(obj); | 440 fArray->push(obj); |
395 return true; | 441 return true; |
396 } | 442 } |
397 | 443 |
| 444 // Returns the size of an array. |
398 size_t size() const { | 445 size_t size() const { |
399 SkPdfMarkObjectUsed(); | 446 SkPdfMarkObjectUsed(); |
400 | 447 |
401 SkASSERT(fObjectType == kArray_PdfObjectType); | 448 SkASSERT(fObjectType == kArray_PdfObjectType); |
402 | 449 |
403 return fArray->count(); | 450 return fArray->count(); |
404 } | 451 } |
405 | 452 |
| 453 // Returns one object of an array, by index. |
406 SkPdfNativeObject* objAtAIndex(int i) { | 454 SkPdfNativeObject* objAtAIndex(int i) { |
407 SkPdfMarkObjectUsed(); | 455 SkPdfMarkObjectUsed(); |
408 | 456 |
409 SkASSERT(fObjectType == kArray_PdfObjectType); | 457 SkASSERT(fObjectType == kArray_PdfObjectType); |
410 | 458 |
411 return (*fArray)[i]; | 459 return (*fArray)[i]; |
412 } | 460 } |
413 | 461 |
414 SkPdfNativeObject* removeLastInArray() { | 462 // Returns one object of an array, by index. |
| 463 const SkPdfNativeObject* objAtAIndex(int i) const { |
415 SkPdfMarkObjectUsed(); | 464 SkPdfMarkObjectUsed(); |
416 | 465 |
417 SkASSERT(fObjectType == kArray_PdfObjectType); | 466 SkASSERT(fObjectType == kArray_PdfObjectType); |
418 | 467 |
419 SkPdfNativeObject* ret = NULL; | 468 return (*fArray)[i]; |
420 fArray->pop(&ret); | |
421 | |
422 return ret; | |
423 } | 469 } |
424 | 470 |
425 const SkPdfNativeObject* objAtAIndex(int i) const { | 471 // Returns one object of an array, by index. |
| 472 SkPdfNativeObject* operator[](int i) { |
426 SkPdfMarkObjectUsed(); | 473 SkPdfMarkObjectUsed(); |
427 | 474 |
428 SkASSERT(fObjectType == kArray_PdfObjectType); | 475 SkASSERT(fObjectType == kArray_PdfObjectType); |
429 | 476 |
430 return (*fArray)[i]; | 477 return (*fArray)[i]; |
431 } | 478 } |
432 | 479 |
433 SkPdfNativeObject* operator[](int i) { | 480 const SkPdfNativeObject* operator[](int i) const { |
434 SkPdfMarkObjectUsed(); | 481 SkPdfMarkObjectUsed(); |
435 | 482 |
436 SkASSERT(fObjectType == kArray_PdfObjectType); | 483 SkASSERT(fObjectType == kArray_PdfObjectType); |
437 | 484 |
438 return (*fArray)[i]; | 485 return (*fArray)[i]; |
439 } | 486 } |
440 | 487 |
441 const SkPdfNativeObject* operator[](int i) const { | 488 // Removes the last object in the array. |
| 489 SkPdfNativeObject* removeLastInArray() { |
442 SkPdfMarkObjectUsed(); | 490 SkPdfMarkObjectUsed(); |
443 | 491 |
444 SkASSERT(fObjectType == kArray_PdfObjectType); | 492 SkASSERT(fObjectType == kArray_PdfObjectType); |
445 | 493 |
446 return (*fArray)[i]; | 494 SkPdfNativeObject* ret = NULL; |
| 495 fArray->pop(&ret); |
| 496 |
| 497 return ret; |
447 } | 498 } |
448 | 499 |
| 500 // Creates an empty Dictionary object. Assumes and asserts that it was never
initialized. |
449 static void makeEmptyDictionary(SkPdfNativeObject* obj) { | 501 static void makeEmptyDictionary(SkPdfNativeObject* obj) { |
450 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 502 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
451 | 503 |
452 obj->fObjectType = kDictionary_PdfObjectType; | 504 obj->fObjectType = kDictionary_PdfObjectType; |
453 obj->fMap = new SkTDict<SkPdfNativeObject*>(1); | 505 obj->fMap = new SkTDict<SkPdfNativeObject*>(1); |
454 obj->fStr.fBuffer = NULL; | 506 obj->fStr.fBuffer = NULL; |
455 obj->fStr.fBytes = 0; | 507 obj->fStr.fBytes = 0; |
456 } | 508 } |
457 | 509 |
458 // TODO(edisonn): perf: get all the possible names from spec, and compute a
hash function | 510 // TODO(edisonn): perf: get all the possible names from spec, and compute a
hash function |
459 // that would create no overlaps in the same dictionary | 511 // that would create no overlaps in the same dictionary |
460 // or build a tree of chars that when followed goes to a unique id/index/has
h | 512 // or build a tree of chars that when followed goes to a unique id/index/has
h |
461 // TODO(edisonn): generate constants like kDictFoo, kNameDict_name | 513 // TODO(edisonn): generate constants like kDictFoo, kNameDict_name |
462 // which will be used in code | 514 // which will be used in code |
463 // add function SkPdfFastNameKey key(const char* key); | 515 // add function SkPdfFastNameKey key(const char* key); |
464 // TODO(edisonn): setting the same key twice, will make the value undefined! | 516 // TODO(edisonn): setting the same key twice, will make the value undefined! |
| 517 |
| 518 // this[key] = value; |
465 bool set(const SkPdfNativeObject* key, SkPdfNativeObject* value) { | 519 bool set(const SkPdfNativeObject* key, SkPdfNativeObject* value) { |
466 SkPdfMarkObjectUsed(); | 520 SkPdfMarkObjectUsed(); |
467 | 521 |
468 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 522 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
469 SkASSERT(key->fObjectType == kName_PdfObjectType); | 523 SkASSERT(key->fObjectType == kName_PdfObjectType); |
470 | 524 |
471 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 525 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
472 // TODO(edisonn): report/warn/assert? | 526 // TODO(edisonn): report/warn/assert? |
473 return false; | 527 return false; |
474 } | 528 } |
475 | 529 |
476 return set(key->fStr.fBuffer, key->fStr.fBytes, value); | 530 return set(key->fStr.fBuffer, key->fStr.fBytes, value); |
477 } | 531 } |
478 | 532 |
| 533 // this[key] = value; |
479 bool set(const char* key, SkPdfNativeObject* value) { | 534 bool set(const char* key, SkPdfNativeObject* value) { |
480 SkPdfMarkObjectUsed(); | 535 SkPdfMarkObjectUsed(); |
481 | 536 |
482 return set((const unsigned char*)key, strlen(key), value); | 537 return set((const unsigned char*)key, strlen(key), value); |
483 } | 538 } |
484 | 539 |
| 540 // this[key] = value; |
485 bool set(const unsigned char* key, size_t len, SkPdfNativeObject* value) { | 541 bool set(const unsigned char* key, size_t len, SkPdfNativeObject* value) { |
486 SkPdfMarkObjectUsed(); | 542 SkPdfMarkObjectUsed(); |
487 | 543 |
488 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 544 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
489 | 545 |
490 if (fObjectType != kDictionary_PdfObjectType) { | 546 if (fObjectType != kDictionary_PdfObjectType) { |
491 // TODO(edisonn): report/warn/assert. | 547 // TODO(edisonn): report/warn/assert. |
492 return false; | 548 return false; |
493 } | 549 } |
494 | 550 |
495 return fMap->set((const char*)key, len, value); | 551 return fMap->set((const char*)key, len, value); |
496 } | 552 } |
497 | 553 |
| 554 // Returns an object from a Dictionary, identified by it's name. |
498 SkPdfNativeObject* get(const SkPdfNativeObject* key) { | 555 SkPdfNativeObject* get(const SkPdfNativeObject* key) { |
499 SkPdfMarkObjectUsed(); | 556 SkPdfMarkObjectUsed(); |
500 | 557 |
501 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 558 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
502 SkASSERT(key->fObjectType == kName_PdfObjectType); | 559 SkASSERT(key->fObjectType == kName_PdfObjectType); |
503 | 560 |
504 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 561 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
505 // TODO(edisonn): report/warn/assert. | 562 // TODO(edisonn): report/warn/assert. |
506 return NULL; | 563 return NULL; |
507 } | 564 } |
508 | 565 |
509 return get(key->fStr.fBuffer, key->fStr.fBytes); | 566 return get(key->fStr.fBuffer, key->fStr.fBytes); |
510 } | 567 } |
511 | 568 |
| 569 // Returns an object from a Dictionary, identified by it's name. |
512 SkPdfNativeObject* get(const char* key) { | 570 SkPdfNativeObject* get(const char* key) { |
513 SkPdfMarkObjectUsed(); | 571 SkPdfMarkObjectUsed(); |
514 | 572 |
515 return get((const unsigned char*)key, strlen(key)); | 573 return get((const unsigned char*)key, strlen(key)); |
516 } | 574 } |
517 | 575 |
| 576 // Returns an object from a Dictionary, identified by it's name. |
518 SkPdfNativeObject* get(const unsigned char* key, size_t len) { | 577 SkPdfNativeObject* get(const unsigned char* key, size_t len) { |
519 SkPdfMarkObjectUsed(); | 578 SkPdfMarkObjectUsed(); |
520 | 579 |
521 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 580 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
522 SkASSERT(key); | 581 SkASSERT(key); |
523 if (fObjectType != kDictionary_PdfObjectType) { | 582 if (fObjectType != kDictionary_PdfObjectType) { |
524 // TODO(edisonn): report/warn/assert. | 583 // TODO(edisonn): report/warn/assert. |
525 return NULL; | 584 return NULL; |
526 } | 585 } |
527 SkPdfNativeObject* ret = NULL; | 586 SkPdfNativeObject* ret = NULL; |
528 fMap->find((const char*)key, len, &ret); | 587 fMap->find((const char*)key, len, &ret); |
529 | 588 |
530 #ifdef PDF_TRACE | 589 #ifdef PDF_TRACE |
531 SkString _key; | 590 SkString _key; |
532 _key.append((const char*)key, len); | 591 _key.append((const char*)key, len); |
533 printf("\nget(/%s) = %s\n", _key.c_str(), | 592 printf("\nget(/%s) = %s\n", _key.c_str(), |
534 ret ? ret->toString(0, len + 9).c_str() : "_NOT_FOUND"); | 593 ret ? ret->toString(0, len + 9).c_str() : "_NOT_FOUND"); |
535 #endif | 594 #endif |
536 | 595 |
537 return ret; | 596 return ret; |
538 } | 597 } |
539 | 598 |
| 599 // Returns an object from a Dictionary, identified by it's name. |
540 const SkPdfNativeObject* get(const SkPdfNativeObject* key) const { | 600 const SkPdfNativeObject* get(const SkPdfNativeObject* key) const { |
541 SkPdfMarkObjectUsed(); | 601 SkPdfMarkObjectUsed(); |
542 | 602 |
543 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 603 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
544 SkASSERT(key->fObjectType == kName_PdfObjectType); | 604 SkASSERT(key->fObjectType == kName_PdfObjectType); |
545 | 605 |
546 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 606 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
547 // TODO(edisonn): report/warn/assert. | 607 // TODO(edisonn): report/warn/assert. |
548 return NULL; | 608 return NULL; |
549 } | 609 } |
550 | 610 |
551 return get(key->fStr.fBuffer, key->fStr.fBytes); | 611 return get(key->fStr.fBuffer, key->fStr.fBytes); |
552 } | 612 } |
553 | 613 |
| 614 // Returns an object from a Dictionary, identified by it's name. |
554 const SkPdfNativeObject* get(const char* key) const { | 615 const SkPdfNativeObject* get(const char* key) const { |
555 SkPdfMarkObjectUsed(); | 616 SkPdfMarkObjectUsed(); |
556 | 617 |
557 return get((const unsigned char*)key, strlen(key)); | 618 return get((const unsigned char*)key, strlen(key)); |
558 } | 619 } |
559 | 620 |
| 621 // Returns an object from a Dictionary, identified by it's name. |
560 const SkPdfNativeObject* get(const unsigned char* key, size_t len) const { | 622 const SkPdfNativeObject* get(const unsigned char* key, size_t len) const { |
561 SkPdfMarkObjectUsed(); | 623 SkPdfMarkObjectUsed(); |
562 | 624 |
563 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 625 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
564 SkASSERT(key); | 626 SkASSERT(key); |
565 if (fObjectType != kDictionary_PdfObjectType) { | 627 if (fObjectType != kDictionary_PdfObjectType) { |
566 // TODO(edisonn): report/warn/assert. | 628 // TODO(edisonn): report/warn/assert. |
567 return NULL; | 629 return NULL; |
568 } | 630 } |
569 SkPdfNativeObject* ret = NULL; | 631 SkPdfNativeObject* ret = NULL; |
570 fMap->find((const char*)key, len, &ret); | 632 fMap->find((const char*)key, len, &ret); |
571 | 633 |
572 #ifdef PDF_TRACE | 634 #ifdef PDF_TRACE |
573 SkString _key; | 635 SkString _key; |
574 _key.append((const char*)key, len); | 636 _key.append((const char*)key, len); |
575 printf("\nget(/%s) = %s\n", _key.c_str(), | 637 printf("\nget(/%s) = %s\n", _key.c_str(), |
576 ret ? ret->toString(0, len + 9).c_str() : "_NOT_FOUND"); | 638 ret ? ret->toString(0, len + 9).c_str() : "_NOT_FOUND"); |
577 #endif | 639 #endif |
578 | 640 |
579 return ret; | 641 return ret; |
580 } | 642 } |
581 | 643 |
| 644 // Returns an object from a Dictionary, identified by it's name. |
582 const SkPdfNativeObject* get(const char* key, const char* abr) const { | 645 const SkPdfNativeObject* get(const char* key, const char* abr) const { |
583 SkPdfMarkObjectUsed(); | 646 SkPdfMarkObjectUsed(); |
584 | 647 |
585 const SkPdfNativeObject* ret = get(key); | 648 const SkPdfNativeObject* ret = get(key); |
586 // TODO(edisonn): remove || *abr == '\0' and pass NULL in the _autogen
files instead. | 649 // TODO(edisonn): remove || *abr == '\0' and pass NULL in the _autogen
files instead. |
587 if (ret != NULL || abr == NULL || *abr == '\0') { | 650 if (ret != NULL || abr == NULL || *abr == '\0') { |
588 return ret; | 651 return ret; |
589 } | 652 } |
590 return get(abr); | 653 return get(abr); |
591 } | 654 } |
592 | 655 |
| 656 // Returns an object from a Dictionary, identified by it's name. |
593 SkPdfNativeObject* get(const char* key, const char* abr) { | 657 SkPdfNativeObject* get(const char* key, const char* abr) { |
594 SkPdfMarkObjectUsed(); | 658 SkPdfMarkObjectUsed(); |
595 | 659 |
596 SkPdfNativeObject* ret = get(key); | 660 SkPdfNativeObject* ret = get(key); |
597 // TODO(edisonn): remove || *abr == '\0' and pass NULL in the _autogen
files instead. | 661 // TODO(edisonn): remove || *abr == '\0' and pass NULL in the _autogen
files instead. |
598 if (ret != NULL || abr == NULL || *abr == '\0') { | 662 if (ret != NULL || abr == NULL || *abr == '\0') { |
599 return ret; | 663 return ret; |
600 } | 664 } |
601 return get(abr); | 665 return get(abr); |
602 } | 666 } |
603 | 667 |
| 668 // Casts the object to a Dictionary. Asserts if the object is not a Dictiona
ry. |
604 SkPdfDictionary* asDictionary() { | 669 SkPdfDictionary* asDictionary() { |
605 SkPdfMarkObjectUsed(); | 670 SkPdfMarkObjectUsed(); |
606 | 671 |
607 SkASSERT(isDictionary()); | 672 SkASSERT(isDictionary()); |
608 if (!isDictionary()) { | 673 if (!isDictionary()) { |
609 return NULL; | 674 return NULL; |
610 } | 675 } |
611 return (SkPdfDictionary*) this; | 676 return (SkPdfDictionary*) this; |
612 } | 677 } |
613 | 678 |
| 679 // Casts the object to a Dictionary. Asserts if the object is not a Dictiona
ry. |
614 const SkPdfDictionary* asDictionary() const { | 680 const SkPdfDictionary* asDictionary() const { |
615 SkPdfMarkObjectUsed(); | 681 SkPdfMarkObjectUsed(); |
616 | 682 |
617 SkASSERT(isDictionary()); | 683 SkASSERT(isDictionary()); |
618 if (!isDictionary()) { | 684 if (!isDictionary()) { |
619 return NULL; | 685 return NULL; |
620 } | 686 } |
621 return (SkPdfDictionary*) this; | 687 return (SkPdfDictionary*) this; |
622 } | 688 } |
623 | 689 |
624 | 690 |
| 691 // Returns true if the object is a Reference. |
625 bool isReference() const { | 692 bool isReference() const { |
626 SkPdfMarkObjectUsed(); | 693 SkPdfMarkObjectUsed(); |
627 | 694 |
628 return fObjectType == kReference_PdfObjectType; | 695 return fObjectType == kReference_PdfObjectType; |
629 } | 696 } |
630 | 697 |
| 698 // Returns true if the object is a Boolean. |
631 bool isBoolean() const { | 699 bool isBoolean() const { |
632 SkPdfMarkObjectUsed(); | 700 SkPdfMarkObjectUsed(); |
633 | 701 |
634 return fObjectType == kBoolean_PdfObjectType; | 702 return fObjectType == kBoolean_PdfObjectType; |
635 } | 703 } |
636 | 704 |
| 705 // Returns true if the object is an Integer. |
637 bool isInteger() const { | 706 bool isInteger() const { |
638 SkPdfMarkObjectUsed(); | 707 SkPdfMarkObjectUsed(); |
639 | 708 |
640 return fObjectType == kInteger_PdfObjectType; | 709 return fObjectType == kInteger_PdfObjectType; |
641 } | 710 } |
| 711 |
642 private: | 712 private: |
| 713 // Returns true if the object is a Real number. |
643 bool isReal() const { | 714 bool isReal() const { |
644 SkPdfMarkObjectUsed(); | 715 SkPdfMarkObjectUsed(); |
645 | 716 |
646 return fObjectType == kReal_PdfObjectType; | 717 return fObjectType == kReal_PdfObjectType; |
647 } | 718 } |
| 719 |
648 public: | 720 public: |
| 721 // Returns true if the object is a Number (either Integer or Real). |
649 bool isNumber() const { | 722 bool isNumber() const { |
650 SkPdfMarkObjectUsed(); | 723 SkPdfMarkObjectUsed(); |
651 | 724 |
652 return fObjectType == kInteger_PdfObjectType || fObjectType == kReal_Pdf
ObjectType; | 725 return fObjectType == kInteger_PdfObjectType || fObjectType == kReal_Pdf
ObjectType; |
653 } | 726 } |
654 | 727 |
| 728 // Returns true if the object is a R keyword (used to identify references, e
.g. "10 3 R". |
655 bool isKeywordReference() const { | 729 bool isKeywordReference() const { |
656 SkPdfMarkObjectUsed(); | 730 SkPdfMarkObjectUsed(); |
657 | 731 |
658 return fObjectType == kKeyword_PdfObjectType && fStr.fBytes == 1 && fStr
.fBuffer[0] == 'R'; | 732 return fObjectType == kKeyword_PdfObjectType && fStr.fBytes == 1 && fStr
.fBuffer[0] == 'R'; |
659 } | 733 } |
660 | 734 |
| 735 // Returns true if the object is a Keyword. |
661 bool isKeyword() const { | 736 bool isKeyword() const { |
662 SkPdfMarkObjectUsed(); | 737 SkPdfMarkObjectUsed(); |
663 | 738 |
664 return fObjectType == kKeyword_PdfObjectType; | 739 return fObjectType == kKeyword_PdfObjectType; |
665 } | 740 } |
666 | 741 |
| 742 // Returns true if the object is a given Keyword. |
667 bool isKeyword(const char* keyword) const { | 743 bool isKeyword(const char* keyword) const { |
668 SkPdfMarkObjectUsed(); | 744 SkPdfMarkObjectUsed(); |
669 | 745 |
670 if (!isKeyword()) { | 746 if (!isKeyword()) { |
671 return false; | 747 return false; |
672 } | 748 } |
673 | 749 |
674 if (strlen(keyword) != fStr.fBytes) { | 750 if (strlen(keyword) != fStr.fBytes) { |
675 return false; | 751 return false; |
676 } | 752 } |
677 | 753 |
678 if (strncmp(keyword, (const char*)fStr.fBuffer, fStr.fBytes) != 0) { | 754 if (strncmp(keyword, (const char*)fStr.fBuffer, fStr.fBytes) != 0) { |
679 return false; | 755 return false; |
680 } | 756 } |
681 | 757 |
682 return true; | 758 return true; |
683 } | 759 } |
684 | 760 |
| 761 // Returns true if the object is a Name. |
685 bool isName() const { | 762 bool isName() const { |
686 SkPdfMarkObjectUsed(); | 763 SkPdfMarkObjectUsed(); |
687 | 764 |
688 return fObjectType == kName_PdfObjectType; | 765 return fObjectType == kName_PdfObjectType; |
689 } | 766 } |
690 | 767 |
| 768 // Returns true if the object is a given Name. |
691 bool isName(const char* name) const { | 769 bool isName(const char* name) const { |
692 SkPdfMarkObjectUsed(); | 770 SkPdfMarkObjectUsed(); |
693 | 771 |
694 return fObjectType == kName_PdfObjectType && | 772 return fObjectType == kName_PdfObjectType && |
695 fStr.fBytes == strlen(name) && | 773 fStr.fBytes == strlen(name) && |
696 strncmp((const char*)fStr.fBuffer, name, fStr.fBytes) == 0; | 774 strncmp((const char*)fStr.fBuffer, name, fStr.fBytes) == 0; |
697 } | 775 } |
698 | 776 |
| 777 // Returns true if the object is an Array. |
699 bool isArray() const { | 778 bool isArray() const { |
700 SkPdfMarkObjectUsed(); | 779 SkPdfMarkObjectUsed(); |
701 | 780 |
702 return fObjectType == kArray_PdfObjectType; | 781 return fObjectType == kArray_PdfObjectType; |
703 } | 782 } |
704 | 783 |
| 784 // Returns true if the object is a Date. |
| 785 // TODO(edisonn): NYI |
705 bool isDate() const { | 786 bool isDate() const { |
706 SkPdfMarkObjectUsed(); | 787 SkPdfMarkObjectUsed(); |
707 | 788 |
708 return fObjectType == kString_PdfObjectType || fObjectType == kHexString
_PdfObjectType; | 789 return fObjectType == kString_PdfObjectType || fObjectType == kHexString
_PdfObjectType; |
709 } | 790 } |
710 | 791 |
| 792 // Returns true if the object is a Dictionary. |
711 bool isDictionary() const { | 793 bool isDictionary() const { |
712 SkPdfMarkObjectUsed(); | 794 SkPdfMarkObjectUsed(); |
713 | 795 |
714 return fObjectType == kDictionary_PdfObjectType; | 796 return fObjectType == kDictionary_PdfObjectType; |
715 } | 797 } |
716 | 798 |
| 799 // Returns true if the object is a Date. |
| 800 // TODO(edisonn): NYI |
717 bool isFunction() const { | 801 bool isFunction() const { |
718 SkPdfMarkObjectUsed(); | 802 SkPdfMarkObjectUsed(); |
719 | 803 |
720 return false; // NYI | 804 return false; // NYI |
721 } | 805 } |
722 | 806 |
| 807 // Returns true if the object is a Rectangle. |
723 bool isRectangle() const { | 808 bool isRectangle() const { |
724 SkPdfMarkObjectUsed(); | 809 SkPdfMarkObjectUsed(); |
725 | 810 |
726 // TODO(edisonn): add also that each of these 4 objects are numbers. | 811 // TODO(edisonn): add also that each of these 4 objects are numbers. |
727 return fObjectType == kArray_PdfObjectType && fArray->count() == 4; | 812 return fObjectType == kArray_PdfObjectType && fArray->count() == 4; |
728 } | 813 } |
729 | 814 |
730 // TODO(edisonn): has stream .. or is stream ... TBD | 815 // TODO(edisonn): Design: decide if we should use hasStream or isStream |
| 816 // Returns true if the object has a stream associated with it. |
731 bool hasStream() const { | 817 bool hasStream() const { |
732 SkPdfMarkObjectUsed(); | 818 SkPdfMarkObjectUsed(); |
733 | 819 |
734 return isDictionary() && fStr.fBuffer != NULL; | 820 return isDictionary() && fStr.fBuffer != NULL; |
735 } | 821 } |
736 | 822 |
737 // TODO(edisonn): has stream .. or is stream ... TBD | 823 // Returns the stream associated with the dictionary. As of now, it casts th
is to Stream. |
738 const SkPdfStream* getStream() const { | 824 const SkPdfStream* getStream() const { |
739 SkPdfMarkObjectUsed(); | 825 SkPdfMarkObjectUsed(); |
740 | 826 |
741 return hasStream() ? (const SkPdfStream*)this : NULL; | 827 return hasStream() ? (const SkPdfStream*)this : NULL; |
742 } | 828 } |
743 | 829 |
| 830 // Returns the stream associated with the dictionary. As of now, it casts th
is to Stream. |
744 SkPdfStream* getStream() { | 831 SkPdfStream* getStream() { |
745 SkPdfMarkObjectUsed(); | 832 SkPdfMarkObjectUsed(); |
746 | 833 |
747 return hasStream() ? (SkPdfStream*)this : NULL; | 834 return hasStream() ? (SkPdfStream*)this : NULL; |
748 } | 835 } |
749 | 836 |
| 837 // Returns true if the object is a String or HexString. |
750 bool isAnyString() const { | 838 bool isAnyString() const { |
751 SkPdfMarkObjectUsed(); | 839 SkPdfMarkObjectUsed(); |
752 | 840 |
753 return fObjectType == kString_PdfObjectType || fObjectType == kHexString
_PdfObjectType; | 841 return fObjectType == kString_PdfObjectType || fObjectType == kHexString
_PdfObjectType; |
754 } | 842 } |
755 | 843 |
| 844 // Returns true if the object is a HexString. |
756 bool isHexString() const { | 845 bool isHexString() const { |
757 SkPdfMarkObjectUsed(); | 846 SkPdfMarkObjectUsed(); |
758 | 847 |
759 return fObjectType == kHexString_PdfObjectType; | 848 return fObjectType == kHexString_PdfObjectType; |
760 } | 849 } |
761 | 850 |
| 851 // Returns true if the object is a Matrix. |
762 bool isMatrix() const { | 852 bool isMatrix() const { |
763 SkPdfMarkObjectUsed(); | 853 SkPdfMarkObjectUsed(); |
764 | 854 |
765 // TODO(edisonn): add also that each of these 6 objects are numbers. | 855 // TODO(edisonn): add also that each of these 6 objects are numbers. |
766 return fObjectType == kArray_PdfObjectType && fArray->count() == 6; | 856 return fObjectType == kArray_PdfObjectType && fArray->count() == 6; |
767 } | 857 } |
768 | 858 |
| 859 // Returns the int value stored in the object. Assert if the object is not a
n Integer. |
769 inline int64_t intValue() const { | 860 inline int64_t intValue() const { |
770 SkPdfMarkObjectUsed(); | 861 SkPdfMarkObjectUsed(); |
771 | 862 |
772 SkASSERT(fObjectType == kInteger_PdfObjectType); | 863 SkASSERT(fObjectType == kInteger_PdfObjectType); |
773 | 864 |
774 if (fObjectType != kInteger_PdfObjectType) { | 865 if (fObjectType != kInteger_PdfObjectType) { |
775 // TODO(edisonn): report/warn/assert. | 866 // TODO(edisonn): report/warn/assert. |
776 return 0; | 867 return 0; |
777 } | 868 } |
778 return fIntegerValue; | 869 return fIntegerValue; |
779 } | 870 } |
| 871 |
780 private: | 872 private: |
| 873 // Returns the real value stored in the object. Assert if the object is not
a Real. |
781 inline double realValue() const { | 874 inline double realValue() const { |
782 SkPdfMarkObjectUsed(); | 875 SkPdfMarkObjectUsed(); |
783 | 876 |
784 SkASSERT(fObjectType == kReal_PdfObjectType); | 877 SkASSERT(fObjectType == kReal_PdfObjectType); |
785 | 878 |
786 if (fObjectType != kReal_PdfObjectType) { | 879 if (fObjectType != kReal_PdfObjectType) { |
787 // TODO(edisonn): report/warn/assert. | 880 // TODO(edisonn): report/warn/assert. |
788 return 0; | 881 return 0; |
789 } | 882 } |
790 return fRealValue; | 883 return fRealValue; |
791 } | 884 } |
| 885 |
792 public: | 886 public: |
| 887 // Returns the numeric value stored in the object. Assert if the object is n
ot a Real |
| 888 // or an Integer. |
793 inline double numberValue() const { | 889 inline double numberValue() const { |
794 SkPdfMarkObjectUsed(); | 890 SkPdfMarkObjectUsed(); |
795 | 891 |
796 SkASSERT(isNumber()); | 892 SkASSERT(isNumber()); |
797 | 893 |
798 if (!isNumber()) { | 894 if (!isNumber()) { |
799 // TODO(edisonn): report/warn/assert. | 895 // TODO(edisonn): report/warn/assert. |
800 return 0; | 896 return 0; |
801 } | 897 } |
802 return fObjectType == kReal_PdfObjectType ? fRealValue : fIntegerValue; | 898 return fObjectType == kReal_PdfObjectType ? fRealValue : fIntegerValue; |
803 } | 899 } |
804 | 900 |
| 901 // Returns the numeric value stored in the object as a scalar. Assert if the
object is not |
| 902 // a Realor an Integer. |
805 inline SkScalar scalarValue() const { | 903 inline SkScalar scalarValue() const { |
806 SkPdfMarkObjectUsed(); | 904 SkPdfMarkObjectUsed(); |
807 | 905 |
808 SkASSERT(isNumber()); | 906 SkASSERT(isNumber()); |
809 | 907 |
810 if (!isNumber()) { | 908 if (!isNumber()) { |
811 // TODO(edisonn): report/warn/assert. | 909 // TODO(edisonn): report/warn/assert. |
812 return SkIntToScalar(0); | 910 return SkIntToScalar(0); |
813 } | 911 } |
814 return fObjectType == kReal_PdfObjectType ? SkDoubleToScalar(fRealValue)
: | 912 return fObjectType == kReal_PdfObjectType ? SkDoubleToScalar(fRealValue)
: |
815 SkIntToScalar(fIntegerValue)
; | 913 SkIntToScalar(fIntegerValue)
; |
816 } | 914 } |
817 | 915 |
| 916 // Returns the id of the referenced object. Assert if the object is not a Re
ference. |
818 int referenceId() const { | 917 int referenceId() const { |
819 SkPdfMarkObjectUsed(); | 918 SkPdfMarkObjectUsed(); |
820 | 919 |
821 SkASSERT(fObjectType == kReference_PdfObjectType); | 920 SkASSERT(fObjectType == kReference_PdfObjectType); |
822 return fRef.fId; | 921 return fRef.fId; |
823 } | 922 } |
824 | 923 |
| 924 // Returns the generation of the referenced object. Assert if the object is
not a Reference. |
825 int referenceGeneration() const { | 925 int referenceGeneration() const { |
826 SkPdfMarkObjectUsed(); | 926 SkPdfMarkObjectUsed(); |
827 | 927 |
828 SkASSERT(fObjectType == kReference_PdfObjectType); | 928 SkASSERT(fObjectType == kReference_PdfObjectType); |
829 return fRef.fGen; | 929 return fRef.fGen; |
830 } | 930 } |
831 | 931 |
| 932 // Returns the buffer of a Name object. Assert if the object is not a Name. |
832 inline const char* nameValue() const { | 933 inline const char* nameValue() const { |
833 SkPdfMarkObjectUsed(); | 934 SkPdfMarkObjectUsed(); |
834 | 935 |
835 SkASSERT(fObjectType == kName_PdfObjectType); | 936 SkASSERT(fObjectType == kName_PdfObjectType); |
836 | 937 |
837 if (fObjectType != kName_PdfObjectType) { | 938 if (fObjectType != kName_PdfObjectType) { |
838 // TODO(edisonn): report/warn/assert. | 939 // TODO(edisonn): report/warn/assert. |
839 return ""; | 940 return ""; |
840 } | 941 } |
841 return (const char*)fStr.fBuffer; | 942 return (const char*)fStr.fBuffer; |
842 } | 943 } |
843 | 944 |
| 945 // Returns the buffer of a (Hex)String object. Assert if the object is not a
(Hex)String. |
844 inline const char* stringValue() const { | 946 inline const char* stringValue() const { |
845 SkPdfMarkObjectUsed(); | 947 SkPdfMarkObjectUsed(); |
846 | 948 |
847 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); | 949 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); |
848 | 950 |
849 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { | 951 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { |
850 // TODO(edisonn): report/warn/assert. | 952 // TODO(edisonn): report/warn/assert. |
851 return ""; | 953 return ""; |
852 } | 954 } |
853 return (const char*)fStr.fBuffer; | 955 return (const char*)fStr.fBuffer; |
854 } | 956 } |
855 | 957 |
| 958 // Returns the storage of any type that can hold a form of string. |
856 inline NotOwnedString strRef() { | 959 inline NotOwnedString strRef() { |
857 SkPdfMarkObjectUsed(); | 960 SkPdfMarkObjectUsed(); |
858 | 961 |
859 switch (fObjectType) { | 962 switch (fObjectType) { |
860 case kString_PdfObjectType: | 963 case kString_PdfObjectType: |
861 case kHexString_PdfObjectType: | 964 case kHexString_PdfObjectType: |
862 case kKeyword_PdfObjectType: | 965 case kKeyword_PdfObjectType: |
863 case kName_PdfObjectType: | 966 case kName_PdfObjectType: |
864 return fStr; | 967 return fStr; |
865 | 968 |
(...skipping 11 matching lines...) Expand all Loading... |
877 | 980 |
878 SkASSERT(fObjectType == kName_PdfObjectType); | 981 SkASSERT(fObjectType == kName_PdfObjectType); |
879 | 982 |
880 if (fObjectType != kName_PdfObjectType) { | 983 if (fObjectType != kName_PdfObjectType) { |
881 // TODO(edisonn): log err | 984 // TODO(edisonn): log err |
882 return SkString(); | 985 return SkString(); |
883 } | 986 } |
884 return SkString((const char*)fStr.fBuffer, fStr.fBytes); | 987 return SkString((const char*)fStr.fBuffer, fStr.fBytes); |
885 } | 988 } |
886 | 989 |
| 990 // Returns an SkString with the value of the (Hex)String object. |
887 inline SkString stringValue2() const { | 991 inline SkString stringValue2() const { |
888 SkPdfMarkObjectUsed(); | 992 SkPdfMarkObjectUsed(); |
889 | 993 |
890 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); | 994 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); |
891 | 995 |
892 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { | 996 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { |
893 // TODO(edisonn): report/warn/assert. | 997 // TODO(edisonn): report/warn/assert. |
894 return SkString(); | 998 return SkString(); |
895 } | 999 } |
896 return SkString((const char*)fStr.fBuffer, fStr.fBytes); | 1000 return SkString((const char*)fStr.fBuffer, fStr.fBytes); |
897 } | 1001 } |
898 | 1002 |
| 1003 // Returns the boolean of the Bool object. Assert if the object is not a Boo
l. |
899 inline bool boolValue() const { | 1004 inline bool boolValue() const { |
900 SkPdfMarkObjectUsed(); | 1005 SkPdfMarkObjectUsed(); |
901 | 1006 |
902 SkASSERT(fObjectType == kBoolean_PdfObjectType); | 1007 SkASSERT(fObjectType == kBoolean_PdfObjectType); |
903 | 1008 |
904 if (fObjectType != kBoolean_PdfObjectType) { | 1009 if (fObjectType != kBoolean_PdfObjectType) { |
905 // TODO(edisonn): report/warn/assert. | 1010 // TODO(edisonn): report/warn/assert. |
906 return false; | 1011 return false; |
907 } | 1012 } |
908 return fBooleanValue; | 1013 return fBooleanValue; |
909 } | 1014 } |
910 | 1015 |
| 1016 // Returns the rectangle of the Rectangle object. Assert if the object is no
t a Rectangle. |
911 SkRect rectangleValue() const { | 1017 SkRect rectangleValue() const { |
912 SkPdfMarkObjectUsed(); | 1018 SkPdfMarkObjectUsed(); |
913 | 1019 |
914 SkASSERT(isRectangle()); | 1020 SkASSERT(isRectangle()); |
915 if (!isRectangle()) { | 1021 if (!isRectangle()) { |
916 return SkRect::MakeEmpty(); | 1022 return SkRect::MakeEmpty(); |
917 } | 1023 } |
918 | 1024 |
919 double array[4]; | 1025 double array[4]; |
920 for (int i = 0; i < 4; i++) { | 1026 for (int i = 0; i < 4; i++) { |
921 // TODO(edisonn): version where we could resolve references? | 1027 // TODO(edisonn): version where we could resolve references? |
922 const SkPdfNativeObject* elem = objAtAIndex(i); | 1028 const SkPdfNativeObject* elem = objAtAIndex(i); |
923 if (elem == NULL || !elem->isNumber()) { | 1029 if (elem == NULL || !elem->isNumber()) { |
924 // TODO(edisonn): report/warn/assert. | 1030 // TODO(edisonn): report/warn/assert. |
925 return SkRect::MakeEmpty(); | 1031 return SkRect::MakeEmpty(); |
926 } | 1032 } |
927 array[i] = elem->numberValue(); | 1033 array[i] = elem->numberValue(); |
928 } | 1034 } |
929 | 1035 |
930 return SkRect::MakeLTRB(SkDoubleToScalar(array[0]), | 1036 return SkRect::MakeLTRB(SkDoubleToScalar(array[0]), |
931 SkDoubleToScalar(array[1]), | 1037 SkDoubleToScalar(array[1]), |
932 SkDoubleToScalar(array[2]), | 1038 SkDoubleToScalar(array[2]), |
933 SkDoubleToScalar(array[3])); | 1039 SkDoubleToScalar(array[3])); |
934 } | 1040 } |
935 | 1041 |
| 1042 // Returns the matrix of the Matrix object. Assert if the object is not a Ma
trix. |
936 SkMatrix matrixValue() const { | 1043 SkMatrix matrixValue() const { |
937 SkPdfMarkObjectUsed(); | 1044 SkPdfMarkObjectUsed(); |
938 | 1045 |
939 SkASSERT(isMatrix()); | 1046 SkASSERT(isMatrix()); |
940 if (!isMatrix()) { | 1047 if (!isMatrix()) { |
941 return SkMatrix::I(); | 1048 return SkMatrix::I(); |
942 } | 1049 } |
943 | 1050 |
944 double array[6]; | 1051 double array[6]; |
945 for (int i = 0; i < 6; i++) { | 1052 for (int i = 0; i < 6; i++) { |
946 // TODO(edisonn): version where we could resolve references? | 1053 // TODO(edisonn): version where we could resolve references? |
947 const SkPdfNativeObject* elem = objAtAIndex(i); | 1054 const SkPdfNativeObject* elem = objAtAIndex(i); |
948 if (elem == NULL || !elem->isNumber()) { | 1055 if (elem == NULL || !elem->isNumber()) { |
949 // TODO(edisonn): report/warn/assert. | 1056 // TODO(edisonn): report/warn/assert. |
950 return SkMatrix::I(); | 1057 return SkMatrix::I(); |
951 } | 1058 } |
952 array[i] = elem->numberValue(); | 1059 array[i] = elem->numberValue(); |
953 } | 1060 } |
954 | 1061 |
955 return SkMatrixFromPdfMatrix(array); | 1062 return SkMatrixFromPdfMatrix(array); |
956 } | 1063 } |
957 | 1064 |
| 1065 // Runs all the filters of this stream, except the last one, if it is a DCT. |
| 1066 // Returns false on failure. |
958 bool filterStream(); | 1067 bool filterStream(); |
959 | 1068 |
960 | 1069 // Runs all the filters of this stream, except the last one, if it is a DCT,
a gives back |
| 1070 // the buffer and the length. The object continues to own the buffer. |
| 1071 // Returns false on failure. |
961 bool GetFilteredStreamRef(unsigned char const** buffer, size_t* len) { | 1072 bool GetFilteredStreamRef(unsigned char const** buffer, size_t* len) { |
962 SkPdfMarkObjectUsed(); | 1073 SkPdfMarkObjectUsed(); |
963 | 1074 |
964 // TODO(edisonn): add params that could let the last filter in place | 1075 // TODO(edisonn): add params that could let the last filter in place |
965 // if it is jpeg or png to fast load images. | 1076 // if it is jpeg or png to fast load images. |
966 if (!hasStream()) { | 1077 if (!hasStream()) { |
967 return false; | 1078 return false; |
968 } | 1079 } |
969 | 1080 |
970 filterStream(); | 1081 filterStream(); |
971 | 1082 |
972 if (buffer) { | 1083 if (buffer) { |
973 *buffer = fStr.fBuffer; | 1084 *buffer = fStr.fBuffer; |
974 } | 1085 } |
975 | 1086 |
976 if (len) { | 1087 if (len) { |
977 *len = fStr.fBytes >> 2; // last 2 bits - TODO(edisonn): clean up. | 1088 *len = fStr.fBytes >> 2; // last 2 bits - TODO(edisonn): clean up. |
978 } | 1089 } |
979 | 1090 |
980 return true; | 1091 return true; |
981 } | 1092 } |
982 | 1093 |
| 1094 // Returns true if the stream is already filtered. |
983 bool isStreamFiltered() const { | 1095 bool isStreamFiltered() const { |
984 SkPdfMarkObjectUsed(); | 1096 SkPdfMarkObjectUsed(); |
985 | 1097 |
986 return hasStream() && ((fStr.fBytes & 1) == kFilteredStreamBit); | 1098 return hasStream() && ((fStr.fBytes & 1) == kFilteredStreamBit); |
987 } | 1099 } |
988 | 1100 |
| 1101 // Returns true if this object own the buffer, or false if an Allocator own
it. |
989 bool isStreamOwned() const { | 1102 bool isStreamOwned() const { |
990 SkPdfMarkObjectUsed(); | 1103 SkPdfMarkObjectUsed(); |
991 | 1104 |
992 return hasStream() && ((fStr.fBytes & 2) == kOwnedStreamBit); | 1105 return hasStream() && ((fStr.fBytes & 2) == kOwnedStreamBit); |
993 } | 1106 } |
994 | 1107 |
| 1108 // Gives back the original buffer and the length. The object continues to ow
n the buffer. |
| 1109 // Returns false if the stream is already filtered. |
995 bool GetUnfilteredStreamRef(unsigned char const** buffer, size_t* len) const
{ | 1110 bool GetUnfilteredStreamRef(unsigned char const** buffer, size_t* len) const
{ |
996 SkPdfMarkObjectUsed(); | 1111 SkPdfMarkObjectUsed(); |
997 | 1112 |
998 if (isStreamFiltered()) { | 1113 if (isStreamFiltered()) { |
999 return false; | 1114 return false; |
1000 } | 1115 } |
1001 | 1116 |
1002 if (!hasStream()) { | 1117 if (!hasStream()) { |
1003 return false; | 1118 return false; |
1004 } | 1119 } |
1005 | 1120 |
1006 if (buffer) { | 1121 if (buffer) { |
1007 *buffer = fStr.fBuffer; | 1122 *buffer = fStr.fBuffer; |
1008 } | 1123 } |
1009 | 1124 |
1010 if (len) { | 1125 if (len) { |
1011 *len = fStr.fBytes >> 2; // remove last 2 bits - TODO(edisonn): cle
an up. | 1126 *len = fStr.fBytes >> 2; // remove last 2 bits - TODO(edisonn): cle
an up. |
1012 } | 1127 } |
1013 | 1128 |
1014 return true; | 1129 return true; |
1015 } | 1130 } |
1016 | 1131 |
| 1132 // Add a stream to this Dictionarry. Asserts we do not have yet a stream. |
1017 bool addStream(const unsigned char* buffer, size_t len) { | 1133 bool addStream(const unsigned char* buffer, size_t len) { |
1018 SkPdfMarkObjectUsed(); | 1134 SkPdfMarkObjectUsed(); |
1019 | 1135 |
1020 SkASSERT(!hasStream()); | 1136 SkASSERT(!hasStream()); |
1021 SkASSERT(isDictionary()); | 1137 SkASSERT(isDictionary()); |
1022 | 1138 |
1023 if (!isDictionary() || hasStream()) { | 1139 if (!isDictionary() || hasStream()) { |
1024 return false; | 1140 return false; |
1025 } | 1141 } |
1026 | 1142 |
(...skipping 25 matching lines...) Expand all Loading... |
1052 str->append("0C"); | 1168 str->append("0C"); |
1053 } else if (data[i] == kCR_PdfWhiteSpace) { | 1169 } else if (data[i] == kCR_PdfWhiteSpace) { |
1054 str->append(prefix); | 1170 str->append(prefix); |
1055 str->append("0D"); | 1171 str->append("0D"); |
1056 } else { | 1172 } else { |
1057 str->append(data + i, 1); | 1173 str->append(data + i, 1); |
1058 } | 1174 } |
1059 } | 1175 } |
1060 } | 1176 } |
1061 | 1177 |
| 1178 // Returns the string representation of the object value. |
1062 SkString toString(int firstRowLevel = 0, int level = 0) { | 1179 SkString toString(int firstRowLevel = 0, int level = 0) { |
1063 SkString str; | 1180 SkString str; |
1064 appendSpaces(&str, firstRowLevel); | 1181 appendSpaces(&str, firstRowLevel); |
1065 switch (fObjectType) { | 1182 switch (fObjectType) { |
1066 case kInvalid_PdfObjectType: | 1183 case kInvalid_PdfObjectType: |
1067 str.append("__Invalid"); | 1184 str.append("__Invalid"); |
1068 break; | 1185 break; |
1069 | 1186 |
1070 case kBoolean_PdfObjectType: | 1187 case kBoolean_PdfObjectType: |
1071 str.appendf("%s", fBooleanValue ? "true" : "false"); | 1188 str.appendf("%s", fBooleanValue ? "true" : "false"); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 obj->fObjectType = type; | 1296 obj->fObjectType = type; |
1180 obj->fStr.fBuffer = start; | 1297 obj->fStr.fBuffer = start; |
1181 obj->fStr.fBytes = bytes; | 1298 obj->fStr.fBytes = bytes; |
1182 } | 1299 } |
1183 | 1300 |
1184 bool applyFilter(const char* name); | 1301 bool applyFilter(const char* name); |
1185 bool applyFlateDecodeFilter(); | 1302 bool applyFlateDecodeFilter(); |
1186 bool applyDCTDecodeFilter(); | 1303 bool applyDCTDecodeFilter(); |
1187 }; | 1304 }; |
1188 | 1305 |
| 1306 // These classes are provided for convenience. You still have to make sure an Sk
PdfInteger |
| 1307 // is indeed an Integer. |
1189 class SkPdfStream : public SkPdfNativeObject {}; | 1308 class SkPdfStream : public SkPdfNativeObject {}; |
1190 class SkPdfArray : public SkPdfNativeObject {}; | 1309 class SkPdfArray : public SkPdfNativeObject {}; |
1191 class SkPdfString : public SkPdfNativeObject {}; | 1310 class SkPdfString : public SkPdfNativeObject {}; |
1192 class SkPdfHexString : public SkPdfNativeObject {}; | 1311 class SkPdfHexString : public SkPdfNativeObject {}; |
1193 class SkPdfInteger : public SkPdfNativeObject {}; | 1312 class SkPdfInteger : public SkPdfNativeObject {}; |
1194 class SkPdfReal : public SkPdfNativeObject {}; | 1313 class SkPdfReal : public SkPdfNativeObject {}; |
1195 class SkPdfNumber : public SkPdfNativeObject {}; | 1314 class SkPdfNumber : public SkPdfNativeObject {}; |
1196 | 1315 |
1197 class SkPdfName : public SkPdfNativeObject { | 1316 class SkPdfName : public SkPdfNativeObject { |
1198 SkPdfName() : SkPdfNativeObject() { | 1317 SkPdfName() : SkPdfNativeObject() { |
1199 SkPdfNativeObject::makeName((const unsigned char*)"", this); | 1318 SkPdfNativeObject::makeName((const unsigned char*)"", this); |
1200 } | 1319 } |
1201 public: | 1320 public: |
1202 SkPdfName(char* name) : SkPdfNativeObject() { | 1321 SkPdfName(char* name) : SkPdfNativeObject() { |
1203 this->makeName((const unsigned char*)name, this); | 1322 this->makeName((const unsigned char*)name, this); |
1204 } | 1323 } |
1205 }; | 1324 }; |
1206 | 1325 |
1207 #endif // SkPdfNativeObject | 1326 #endif // SkPdfNativeObject |
OLD | NEW |