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 |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 #include <string.h> | 12 #include <string.h> |
| 13 |
| 14 #include "SkMatrix.h" |
| 15 #include "SkPdfConfig.h" |
| 16 #include "SkPdfNativeTokenizer.h" |
| 17 #include "SkPdfNYI.h" |
| 18 #include "SkPdfUtils.h" |
| 19 #include "SkRect.h" |
13 #include "SkString.h" | 20 #include "SkString.h" |
14 #include "SkTDArray.h" | 21 #include "SkTDArray.h" |
15 #include "SkTDict.h" | 22 #include "SkTDict.h" |
16 #include "SkRect.h" | |
17 #include "SkMatrix.h" | |
18 #include "SkString.h" | |
19 | |
20 #include "SkPdfNYI.h" | |
21 #include "SkPdfConfig.h" | |
22 #include "SkPdfUtils.h" | |
23 | |
24 #include "SkPdfNativeTokenizer.h" | |
25 | 23 |
26 class SkPdfDictionary; | 24 class SkPdfDictionary; |
27 class SkPdfStream; | 25 class SkPdfStream; |
28 class SkPdfAllocator; | 26 class SkPdfAllocator; |
29 | 27 |
30 // TODO(edisonn): macro it and move it to utils | 28 // TODO(edisonn): remove these constants and clean up the code. |
31 SkMatrix SkMatrixFromPdfMatrix(double array[6]); | |
32 | |
33 | |
34 #define kFilteredStreamBit 0 | 29 #define kFilteredStreamBit 0 |
35 #define kUnfilteredStreamBit 1 | 30 #define kUnfilteredStreamBit 1 |
36 #define kOwnedStreamBit 2 | 31 #define kOwnedStreamBit 2 |
37 | 32 |
38 class SkPdfNativeObject { | 33 class SkPdfNativeObject { |
39 public: | 34 public: |
40 enum ObjectType { | 35 enum ObjectType { |
41 // The type will have only one of these values, but for error reporting
, we make it an enum | 36 // The type will have only one of these values, but for error reporting
, we make it an enum |
42 // so it can easily report that something was expected to be one of a f
ew types | 37 // so it can easily report that something was expected to be one of a f
ew types |
43 kInvalid_PdfObjectType = 1 << 1, | 38 kInvalid_PdfObjectType = 1 << 1, |
44 | 39 |
45 kBoolean_PdfObjectType = 1 << 2, | 40 kBoolean_PdfObjectType = 1 << 2, |
46 kInteger_PdfObjectType = 1 << 3, | 41 kInteger_PdfObjectType = 1 << 3, |
47 kReal_PdfObjectType = 1 << 4, | 42 kReal_PdfObjectType = 1 << 4, |
48 _kNumber_PdfObjectType = kInteger_PdfObjectType | kReal_PdfObjectType, | 43 _kNumber_PdfObjectType = kInteger_PdfObjectType | kReal_PdfObjectType, |
49 kString_PdfObjectType = 1 << 5, | 44 kString_PdfObjectType = 1 << 5, |
50 kHexString_PdfObjectType = 1 << 6, | 45 kHexString_PdfObjectType = 1 << 6, |
51 _kAnyString_PdfObjectType = kString_PdfObjectType | kHexString_PdfObjec
tType, | 46 _kAnyString_PdfObjectType = kString_PdfObjectType | kHexString_PdfObjec
tType, |
52 kName_PdfObjectType = 1 << 7, | 47 kName_PdfObjectType = 1 << 7, |
53 kKeyword_PdfObjectType = 1 << 8, | 48 kKeyword_PdfObjectType = 1 << 8, |
54 _kStream_PdfObjectType = 1 << 9, // attached to a Dictionary, do not
use | 49 _kStream_PdfObjectType = 1 << 9, // attached to a Dictionary, do not
use |
55 kArray_PdfObjectType = 1 << 10, | 50 kArray_PdfObjectType = 1 << 10, |
56 kDictionary_PdfObjectType = 1 << 11, | 51 kDictionary_PdfObjectType = 1 << 11, |
57 kNull_PdfObjectType = 1 << 12, | 52 kNull_PdfObjectType = 1 << 12, |
58 | 53 |
59 // TODO(edisonn): after the pdf has been loaded completely, resolve all
references | |
60 // try the same thing with delayed loaded ... | |
61 kReference_PdfObjectType = 1 << 13, | 54 kReference_PdfObjectType = 1 << 13, |
62 | 55 |
63 kUndefined_PdfObjectType = 1 << 14, // per 1.4 spec, if the same key a
ppear twice in the dictionary, the value is undefined | 56 kUndefined_PdfObjectType = 1 << 14, // per 1.4 spec, if the same key a
ppear twice in the |
| 57 // dictionary, the value is undefi
ned. |
64 | 58 |
65 _kObject_PdfObjectType = -1, | 59 _kObject_PdfObjectType = -1, |
66 }; | 60 }; |
67 | 61 |
68 enum DataType { | 62 enum DataType { |
69 kEmpty_Data, | 63 kEmpty_Data, |
70 kFont_Data, | 64 kFont_Data, |
71 kBitmap_Data, | 65 kBitmap_Data, |
72 }; | 66 }; |
73 | 67 |
74 private: | 68 private: |
75 // TODO(edisonn): assert reset operations while in rendering! | 69 // TODO(edisonn): assert reset operations while in rendering! The objects sh
ould be reset |
| 70 // only when rendering is completed. |
76 uint32_t fInRendering : 1; | 71 uint32_t fInRendering : 1; |
77 uint32_t fUnused : 31; | 72 uint32_t fUnused : 31; |
78 | 73 |
79 | |
80 struct Reference { | 74 struct Reference { |
81 unsigned int fId; | 75 unsigned int fId; |
82 unsigned int fGen; | 76 unsigned int fGen; |
83 }; | 77 }; |
84 | 78 |
85 // TODO(edisonn): add stream start, stream end, where stream is weither the
file | |
86 // or decoded/filtered pdf stream | |
87 | |
88 // TODO(edisonn): add warning/report per object | |
89 // TODO(edisonn): add flag fUsed, to be used once the parsing is complete, | |
90 // so we could show what parts have been proccessed, ignored, or generated e
rrors | |
91 | |
92 ObjectType fObjectType; | 79 ObjectType fObjectType; |
93 | 80 |
94 union { | 81 union { |
95 bool fBooleanValue; | 82 bool fBooleanValue; |
96 int64_t fIntegerValue; | 83 int64_t fIntegerValue; |
97 // TODO(edisonn): double, float? typedefed | 84 // TODO(edisonn): double, float, SkScalar? |
98 double fRealValue; | 85 double fRealValue; |
99 NotOwnedString fStr; | 86 NotOwnedString fStr; |
100 | 87 |
101 // TODO(edisonn): make sure the foorprint of fArray and fMap is small, o
therwise, use pointers, or classes with up to 8 bytes in footprint | |
102 SkTDArray<SkPdfNativeObject*>* fArray; | 88 SkTDArray<SkPdfNativeObject*>* fArray; |
103 Reference fRef; | 89 Reference fRef; |
104 }; | 90 }; |
105 SkTDict<SkPdfNativeObject*>* fMap; | 91 SkTDict<SkPdfNativeObject*>* fMap; |
106 | 92 |
107 // TODO(edisonn): rename data with cache | 93 // TODO(edisonn): rename data with cache |
108 void* fData; | 94 void* fData; |
109 DataType fDataType; | 95 DataType fDataType; |
110 | 96 |
111 | |
112 // Keep this the last entries | 97 // Keep this the last entries |
113 #ifdef PDF_TRACK_OBJECT_USAGE | 98 #ifdef PDF_TRACK_OBJECT_USAGE |
114 mutable bool fUsed; | 99 mutable bool fUsed; |
115 #endif // PDF_TRACK_OBJECT_USAGE | 100 #endif // PDF_TRACK_OBJECT_USAGE |
116 | 101 |
117 #ifdef PDF_TRACK_STREAM_OFFSETS | 102 #ifdef PDF_TRACK_STREAM_OFFSETS |
118 public: | 103 public: |
119 int fStreamId; | 104 int fStreamId; |
120 int fOffsetStart; | 105 int fOffsetStart; |
121 int fOffsetEnd; | 106 int fOffsetEnd; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 145 |
161 inline void setData(void* data, DataType type) { | 146 inline void setData(void* data, DataType type) { |
162 releaseData(); | 147 releaseData(); |
163 fDataType = type; | 148 fDataType = type; |
164 fData = data; | 149 fData = data; |
165 } | 150 } |
166 | 151 |
167 void releaseData(); | 152 void releaseData(); |
168 | 153 |
169 // ~SkPdfNativeObject() { | 154 // ~SkPdfNativeObject() { |
170 // //reset(); must be called manually! | 155 // //reset(); must be called manually! Normally, will be called by alloc
ator destructor. |
171 // } | 156 // } |
172 | 157 |
173 void reset() { | 158 void reset() { |
174 SkPdfMarkObjectUnused(); | 159 SkPdfMarkObjectUnused(); |
175 | 160 |
176 switch (fObjectType) { | 161 switch (fObjectType) { |
177 case kArray_PdfObjectType: | 162 case kArray_PdfObjectType: |
178 delete fArray; | 163 delete fArray; |
179 break; | 164 break; |
180 | 165 |
(...skipping 23 matching lines...) Expand all Loading... |
204 SkPdfMarkObjectUsed(); | 189 SkPdfMarkObjectUsed(); |
205 | 190 |
206 switch (fObjectType) { | 191 switch (fObjectType) { |
207 case kString_PdfObjectType: | 192 case kString_PdfObjectType: |
208 case kHexString_PdfObjectType: | 193 case kHexString_PdfObjectType: |
209 case kKeyword_PdfObjectType: | 194 case kKeyword_PdfObjectType: |
210 case kName_PdfObjectType: | 195 case kName_PdfObjectType: |
211 return (const char*)fStr.fBuffer; | 196 return (const char*)fStr.fBuffer; |
212 | 197 |
213 default: | 198 default: |
214 // TODO(edisonn): report/warning | 199 // TODO(edisonn): report/warning/assert? |
215 return NULL; | 200 return NULL; |
216 } | 201 } |
217 } | 202 } |
218 | 203 |
219 size_t lenstr() const { | 204 size_t lenstr() const { |
220 SkPdfMarkObjectUsed(); | 205 SkPdfMarkObjectUsed(); |
221 | 206 |
222 switch (fObjectType) { | 207 switch (fObjectType) { |
223 case kString_PdfObjectType: | 208 case kString_PdfObjectType: |
224 case kHexString_PdfObjectType: | 209 case kHexString_PdfObjectType: |
225 case kKeyword_PdfObjectType: | 210 case kKeyword_PdfObjectType: |
226 case kName_PdfObjectType: | 211 case kName_PdfObjectType: |
227 return fStr.fBytes; | 212 return fStr.fBytes; |
228 | 213 |
229 default: | 214 default: |
230 // TODO(edisonn): report/warning | 215 // TODO(edisonn): report/warning/assert? |
231 return 0; | 216 return 0; |
232 } | 217 } |
233 } | 218 } |
234 | 219 |
235 | 220 |
236 // TODO(edisonn): NYI | 221 // TODO(edisonn): NYI |
237 SkPdfDate& dateValue() const { | 222 SkPdfDate& dateValue() const { |
238 static SkPdfDate nyi; | 223 static SkPdfDate nyi; |
239 return nyi; | 224 return nyi; |
240 } | 225 } |
241 | 226 |
242 // TODO(edisonn): NYI | 227 // TODO(edisonn): NYI |
243 SkPdfFunction& functionValue() const { | 228 SkPdfFunction& functionValue() const { |
244 static SkPdfFunction nyi; | 229 static SkPdfFunction nyi; |
245 return nyi; | 230 return nyi; |
246 } | 231 } |
247 | 232 |
248 // TODO(edisonn): NYI | 233 // TODO(edisonn): NYI |
249 SkPdfFileSpec& fileSpecValue() const { | 234 SkPdfFileSpec& fileSpecValue() const { |
250 static SkPdfFileSpec nyi; | 235 static SkPdfFileSpec nyi; |
251 return nyi; | 236 return nyi; |
252 } | 237 } |
253 | 238 |
254 // TODO(edisonn): NYI | 239 // TODO(edisonn): NYI |
255 SkPdfTree& treeValue() const { | 240 SkPdfTree& treeValue() const { |
256 static SkPdfTree nyi; | 241 static SkPdfTree nyi; |
257 return nyi; | 242 return nyi; |
258 } | 243 } |
259 | 244 |
260 // TODO(edisonn) impl store | |
261 //STORE_TRACK_PARAMETERS(obj); | |
262 | |
263 static void makeBoolean(bool value, SkPdfNativeObject* obj) { | 245 static void makeBoolean(bool value, SkPdfNativeObject* obj) { |
264 | 246 |
265 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 247 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
266 | 248 |
267 obj->fObjectType = kBoolean_PdfObjectType; | 249 obj->fObjectType = kBoolean_PdfObjectType; |
268 obj->fBooleanValue = value; | 250 obj->fBooleanValue = value; |
269 } | 251 } |
270 | 252 |
271 static SkPdfNativeObject makeBoolean(bool value) { | 253 static SkPdfNativeObject makeBoolean(bool value) { |
272 SkPdfNativeObject obj; | 254 SkPdfNativeObject obj; |
(...skipping 25 matching lines...) Expand all Loading... |
298 | 280 |
299 static SkPdfNativeObject makeNull() { | 281 static SkPdfNativeObject makeNull() { |
300 SkPdfNativeObject obj; | 282 SkPdfNativeObject obj; |
301 | 283 |
302 obj.fObjectType = kNull_PdfObjectType; | 284 obj.fObjectType = kNull_PdfObjectType; |
303 return obj; | 285 return obj; |
304 } | 286 } |
305 | 287 |
306 static SkPdfNativeObject kNull; | 288 static SkPdfNativeObject kNull; |
307 | 289 |
308 static void makeNumeric(const unsigned char* start, const unsigned char* end
, SkPdfNativeObject* obj) { | 290 static void makeNumeric(const unsigned char* start, const unsigned char* end
, |
| 291 SkPdfNativeObject* obj) { |
309 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 292 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
310 | 293 |
311 // TODO(edisonn): NYI properly | 294 // TODO(edisonn): NYI properly |
312 // if has dot (impl), or exceeds max int, is real, otherwise is int | 295 // if has dot (impl), or exceeds max int, is real, otherwise is int |
313 bool isInt = true; | 296 bool isInt = true; |
314 for (const unsigned char* current = start; current < end; current++) { | 297 for (const unsigned char* current = start; current < end; current++) { |
315 if (*current == '.') { | 298 if (*current == '.') { |
316 isInt = false; | 299 isInt = false; |
317 break; | 300 break; |
318 } | 301 } |
(...skipping 17 matching lines...) Expand all Loading... |
336 static void resetAndMakeReference(unsigned int id, unsigned int gen, SkPdfNa
tiveObject* obj) { | 319 static void resetAndMakeReference(unsigned int id, unsigned int gen, SkPdfNa
tiveObject* obj) { |
337 obj->reset(); | 320 obj->reset(); |
338 makeReference(id, gen, obj); | 321 makeReference(id, gen, obj); |
339 } | 322 } |
340 | 323 |
341 | 324 |
342 static void makeString(const unsigned char* start, SkPdfNativeObject* obj) { | 325 static void makeString(const unsigned char* start, SkPdfNativeObject* obj) { |
343 makeStringCore(start, strlen((const char*)start), obj, kString_PdfObject
Type); | 326 makeStringCore(start, strlen((const char*)start), obj, kString_PdfObject
Type); |
344 } | 327 } |
345 | 328 |
346 static void makeString(const unsigned char* start, const unsigned char* end,
SkPdfNativeObject* obj) { | 329 static void makeString(const unsigned char* start, const unsigned char* end, |
| 330 SkPdfNativeObject* obj) { |
347 makeStringCore(start, end - start, obj, kString_PdfObjectType); | 331 makeStringCore(start, end - start, obj, kString_PdfObjectType); |
348 } | 332 } |
349 | 333 |
350 static void makeString(const unsigned char* start, size_t bytes, SkPdfNative
Object* obj) { | 334 static void makeString(const unsigned char* start, size_t bytes, SkPdfNative
Object* obj) { |
351 makeStringCore(start, bytes, obj, kString_PdfObjectType); | 335 makeStringCore(start, bytes, obj, kString_PdfObjectType); |
352 } | 336 } |
353 | 337 |
354 | 338 |
355 static void makeHexString(const unsigned char* start, SkPdfNativeObject* obj
) { | 339 static void makeHexString(const unsigned char* start, SkPdfNativeObject* obj
) { |
356 makeStringCore(start, strlen((const char*)start), obj, kHexString_PdfObj
ectType); | 340 makeStringCore(start, strlen((const char*)start), obj, kHexString_PdfObj
ectType); |
357 } | 341 } |
358 | 342 |
359 static void makeHexString(const unsigned char* start, const unsigned char* e
nd, SkPdfNativeObject* obj) { | 343 static void makeHexString(const unsigned char* start, const unsigned char* e
nd, |
| 344 SkPdfNativeObject* obj) { |
360 makeStringCore(start, end - start, obj, kHexString_PdfObjectType); | 345 makeStringCore(start, end - start, obj, kHexString_PdfObjectType); |
361 } | 346 } |
362 | 347 |
363 static void makeHexString(const unsigned char* start, size_t bytes, SkPdfNat
iveObject* obj) { | 348 static void makeHexString(const unsigned char* start, size_t bytes, SkPdfNat
iveObject* obj) { |
364 makeStringCore(start, bytes, obj, kHexString_PdfObjectType); | 349 makeStringCore(start, bytes, obj, kHexString_PdfObjectType); |
365 } | 350 } |
366 | 351 |
367 | 352 |
368 static void makeName(const unsigned char* start, SkPdfNativeObject* obj) { | 353 static void makeName(const unsigned char* start, SkPdfNativeObject* obj) { |
369 makeStringCore(start, strlen((const char*)start), obj, kName_PdfObjectTy
pe); | 354 makeStringCore(start, strlen((const char*)start), obj, kName_PdfObjectTy
pe); |
370 } | 355 } |
371 | 356 |
372 static void makeName(const unsigned char* start, const unsigned char* end, S
kPdfNativeObject* obj) { | 357 static void makeName(const unsigned char* start, const unsigned char* end, |
| 358 SkPdfNativeObject* obj) { |
373 makeStringCore(start, end - start, obj, kName_PdfObjectType); | 359 makeStringCore(start, end - start, obj, kName_PdfObjectType); |
374 } | 360 } |
375 | 361 |
376 static void makeName(const unsigned char* start, size_t bytes, SkPdfNativeOb
ject* obj) { | 362 static void makeName(const unsigned char* start, size_t bytes, SkPdfNativeOb
ject* obj) { |
377 makeStringCore(start, bytes, obj, kName_PdfObjectType); | 363 makeStringCore(start, bytes, obj, kName_PdfObjectType); |
378 } | 364 } |
379 | 365 |
380 | 366 |
381 static void makeKeyword(const unsigned char* start, SkPdfNativeObject* obj)
{ | 367 static void makeKeyword(const unsigned char* start, SkPdfNativeObject* obj)
{ |
382 makeStringCore(start, strlen((const char*)start), obj, kKeyword_PdfObjec
tType); | 368 makeStringCore(start, strlen((const char*)start), obj, kKeyword_PdfObjec
tType); |
383 } | 369 } |
384 | 370 |
385 static void makeKeyword(const unsigned char* start, const unsigned char* end
, SkPdfNativeObject* obj) { | 371 static void makeKeyword(const unsigned char* start, const unsigned char* end
, |
| 372 SkPdfNativeObject* obj) { |
386 makeStringCore(start, end - start, obj, kKeyword_PdfObjectType); | 373 makeStringCore(start, end - start, obj, kKeyword_PdfObjectType); |
387 } | 374 } |
388 | 375 |
389 static void makeKeyword(const unsigned char* start, size_t bytes, SkPdfNativ
eObject* obj) { | 376 static void makeKeyword(const unsigned char* start, size_t bytes, SkPdfNativ
eObject* obj) { |
390 makeStringCore(start, bytes, obj, kKeyword_PdfObjectType); | 377 makeStringCore(start, bytes, obj, kKeyword_PdfObjectType); |
391 } | 378 } |
392 | 379 |
393 | |
394 | |
395 // TODO(edisonn): make the functions to return SkPdfArray, move these functi
ons in SkPdfArray | |
396 static void makeEmptyArray(SkPdfNativeObject* obj) { | 380 static void makeEmptyArray(SkPdfNativeObject* obj) { |
397 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 381 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
398 | 382 |
399 obj->fObjectType = kArray_PdfObjectType; | 383 obj->fObjectType = kArray_PdfObjectType; |
400 obj->fArray = new SkTDArray<SkPdfNativeObject*>(); | 384 obj->fArray = new SkTDArray<SkPdfNativeObject*>(); |
401 // return (SkPdfArray*)obj; | |
402 } | 385 } |
403 | 386 |
404 bool appendInArray(SkPdfNativeObject* obj) { | 387 bool appendInArray(SkPdfNativeObject* obj) { |
405 SkASSERT(fObjectType == kArray_PdfObjectType); | 388 SkASSERT(fObjectType == kArray_PdfObjectType); |
406 if (fObjectType != kArray_PdfObjectType) { | 389 if (fObjectType != kArray_PdfObjectType) { |
407 // TODO(edisonn): report err | 390 // TODO(edisonn): report/warning/assert? |
408 return false; | 391 return false; |
409 } | 392 } |
410 | 393 |
411 fArray->push(obj); | 394 fArray->push(obj); |
412 return true; | 395 return true; |
413 } | 396 } |
414 | 397 |
415 size_t size() const { | 398 size_t size() const { |
416 SkPdfMarkObjectUsed(); | 399 SkPdfMarkObjectUsed(); |
417 | 400 |
418 SkASSERT(fObjectType == kArray_PdfObjectType); | 401 SkASSERT(fObjectType == kArray_PdfObjectType); |
419 | 402 |
420 return fArray->count(); | 403 return fArray->count(); |
421 } | 404 } |
422 | 405 |
423 SkPdfNativeObject* objAtAIndex(int i) { | 406 SkPdfNativeObject* objAtAIndex(int i) { |
424 SkPdfMarkObjectUsed(); | 407 SkPdfMarkObjectUsed(); |
425 | 408 |
426 SkASSERT(fObjectType == kArray_PdfObjectType); | 409 SkASSERT(fObjectType == kArray_PdfObjectType); |
427 | 410 |
428 return (*fArray)[i]; | 411 return (*fArray)[i]; |
429 } | 412 } |
430 | 413 |
431 SkPdfNativeObject* removeLastInArray() { | 414 SkPdfNativeObject* removeLastInArray() { |
432 // SkPdfMarkObjectUsed(); | 415 SkPdfMarkObjectUsed(); |
433 | 416 |
434 SkASSERT(fObjectType == kArray_PdfObjectType); | 417 SkASSERT(fObjectType == kArray_PdfObjectType); |
435 | 418 |
436 SkPdfNativeObject* ret = NULL; | 419 SkPdfNativeObject* ret = NULL; |
437 fArray->pop(&ret); | 420 fArray->pop(&ret); |
438 | 421 |
439 return ret; | 422 return ret; |
440 } | 423 } |
441 | 424 |
442 | |
443 const SkPdfNativeObject* objAtAIndex(int i) const { | 425 const SkPdfNativeObject* objAtAIndex(int i) const { |
444 SkPdfMarkObjectUsed(); | 426 SkPdfMarkObjectUsed(); |
445 | 427 |
446 SkASSERT(fObjectType == kArray_PdfObjectType); | 428 SkASSERT(fObjectType == kArray_PdfObjectType); |
447 | 429 |
448 return (*fArray)[i]; | 430 return (*fArray)[i]; |
449 } | 431 } |
450 | 432 |
451 SkPdfNativeObject* operator[](int i) { | 433 SkPdfNativeObject* operator[](int i) { |
| 434 SkPdfMarkObjectUsed(); |
| 435 |
452 SkASSERT(fObjectType == kArray_PdfObjectType); | 436 SkASSERT(fObjectType == kArray_PdfObjectType); |
453 | 437 |
454 return (*fArray)[i]; | 438 return (*fArray)[i]; |
455 } | 439 } |
456 | 440 |
457 const SkPdfNativeObject* operator[](int i) const { | 441 const SkPdfNativeObject* operator[](int i) const { |
458 SkPdfMarkObjectUsed(); | 442 SkPdfMarkObjectUsed(); |
459 | 443 |
460 SkASSERT(fObjectType == kArray_PdfObjectType); | 444 SkASSERT(fObjectType == kArray_PdfObjectType); |
461 | 445 |
462 return (*fArray)[i]; | 446 return (*fArray)[i]; |
463 } | 447 } |
464 | 448 |
465 | |
466 // TODO(edisonn): make the functions to return SkPdfDictionary, move these f
unctions in SkPdfDictionary | |
467 static void makeEmptyDictionary(SkPdfNativeObject* obj) { | 449 static void makeEmptyDictionary(SkPdfNativeObject* obj) { |
468 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 450 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
469 | 451 |
470 obj->fObjectType = kDictionary_PdfObjectType; | 452 obj->fObjectType = kDictionary_PdfObjectType; |
471 obj->fMap = new SkTDict<SkPdfNativeObject*>(1); | 453 obj->fMap = new SkTDict<SkPdfNativeObject*>(1); |
472 obj->fStr.fBuffer = NULL; | 454 obj->fStr.fBuffer = NULL; |
473 obj->fStr.fBytes = 0; | 455 obj->fStr.fBytes = 0; |
474 } | 456 } |
475 | 457 |
476 // TODO(edisonn): get all the possible names from spec, and compute a hash f
unction | 458 // TODO(edisonn): perf: get all the possible names from spec, and compute a
hash function |
477 // that would create no overlaps in the same dictionary | 459 // that would create no overlaps in the same dictionary |
478 // or build a tree of chars that when followed goes to a unique id/index/has
h | 460 // or build a tree of chars that when followed goes to a unique id/index/has
h |
479 // TODO(edisonn): generate constants like kDictFoo, kNameDict_name | 461 // TODO(edisonn): generate constants like kDictFoo, kNameDict_name |
480 // which will be used in code | 462 // which will be used in code |
481 // add function SkPdfFastNameKey key(const char* key); | 463 // add function SkPdfFastNameKey key(const char* key); |
482 // TODO(edisonn): setting the same key twike, will make the value undefined! | 464 // TODO(edisonn): setting the same key twice, will make the value undefined! |
483 bool set(const SkPdfNativeObject* key, SkPdfNativeObject* value) { | 465 bool set(const SkPdfNativeObject* key, SkPdfNativeObject* value) { |
484 //SkPdfMarkObjectUsed(); | 466 SkPdfMarkObjectUsed(); |
485 | 467 |
486 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 468 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
487 SkASSERT(key->fObjectType == kName_PdfObjectType); | 469 SkASSERT(key->fObjectType == kName_PdfObjectType); |
488 | 470 |
489 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 471 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
490 // TODO(edisonn): report err | 472 // TODO(edisonn): report/warn/assert? |
491 return false; | 473 return false; |
492 } | 474 } |
493 | 475 |
494 //// we rewrite all delimiters and white spaces with '\0', so we expect
the end of name to be '\0' | |
495 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); | |
496 | |
497 return set(key->fStr.fBuffer, key->fStr.fBytes, value); | 476 return set(key->fStr.fBuffer, key->fStr.fBytes, value); |
498 } | 477 } |
499 | 478 |
500 bool set(const char* key, SkPdfNativeObject* value) { | 479 bool set(const char* key, SkPdfNativeObject* value) { |
501 //SkPdfMarkObjectUsed(); | 480 SkPdfMarkObjectUsed(); |
502 | 481 |
503 return set((const unsigned char*)key, strlen(key), value); | 482 return set((const unsigned char*)key, strlen(key), value); |
504 } | 483 } |
505 | 484 |
506 bool set(const unsigned char* key, size_t len, SkPdfNativeObject* value) { | 485 bool set(const unsigned char* key, size_t len, SkPdfNativeObject* value) { |
507 //SkPdfMarkObjectUsed(); | 486 SkPdfMarkObjectUsed(); |
508 | 487 |
509 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 488 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
510 | 489 |
511 if (fObjectType != kDictionary_PdfObjectType) { | 490 if (fObjectType != kDictionary_PdfObjectType) { |
512 // TODO(edisonn): report err | 491 // TODO(edisonn): report/warn/assert. |
513 return false; | 492 return false; |
514 } | 493 } |
515 | 494 |
516 return fMap->set((const char*)key, len, value); | 495 return fMap->set((const char*)key, len, value); |
517 } | 496 } |
518 | 497 |
519 SkPdfNativeObject* get(const SkPdfNativeObject* key) { | 498 SkPdfNativeObject* get(const SkPdfNativeObject* key) { |
520 SkPdfMarkObjectUsed(); | 499 SkPdfMarkObjectUsed(); |
521 | 500 |
522 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 501 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
523 SkASSERT(key->fObjectType == kName_PdfObjectType); | 502 SkASSERT(key->fObjectType == kName_PdfObjectType); |
524 | 503 |
525 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 504 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
526 // TODO(edisonn): report err | 505 // TODO(edisonn): report/warn/assert. |
527 return NULL; | 506 return NULL; |
528 } | 507 } |
529 | 508 |
530 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); | |
531 | |
532 return get(key->fStr.fBuffer, key->fStr.fBytes); | 509 return get(key->fStr.fBuffer, key->fStr.fBytes); |
533 } | 510 } |
534 | 511 |
535 SkPdfNativeObject* get(const char* key) { | 512 SkPdfNativeObject* get(const char* key) { |
536 SkPdfMarkObjectUsed(); | 513 SkPdfMarkObjectUsed(); |
537 | 514 |
538 return get((const unsigned char*)key, strlen(key)); | 515 return get((const unsigned char*)key, strlen(key)); |
539 } | 516 } |
540 | 517 |
541 SkPdfNativeObject* get(const unsigned char* key, size_t len) { | 518 SkPdfNativeObject* get(const unsigned char* key, size_t len) { |
542 SkPdfMarkObjectUsed(); | 519 SkPdfMarkObjectUsed(); |
543 | 520 |
544 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 521 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
545 SkASSERT(key); | 522 SkASSERT(key); |
546 if (fObjectType != kDictionary_PdfObjectType) { | 523 if (fObjectType != kDictionary_PdfObjectType) { |
547 // TODO(edisonn): report err | 524 // TODO(edisonn): report/warn/assert. |
548 return NULL; | 525 return NULL; |
549 } | 526 } |
550 SkPdfNativeObject* ret = NULL; | 527 SkPdfNativeObject* ret = NULL; |
551 fMap->find((const char*)key, len, &ret); | 528 fMap->find((const char*)key, len, &ret); |
552 | 529 |
553 #ifdef PDF_TRACE | 530 #ifdef PDF_TRACE |
554 SkString _key; | 531 SkString _key; |
555 _key.append((const char*)key, len); | 532 _key.append((const char*)key, len); |
556 printf("\nget(/%s) = %s\n", _key.c_str(), ret ? ret->toString(0, len + 9
).c_str() : "_NOT_FOUND"); | 533 printf("\nget(/%s) = %s\n", _key.c_str(), |
| 534 ret ? ret->toString(0, len + 9).c_str() : "_NOT_FOUND"); |
557 #endif | 535 #endif |
558 | 536 |
559 return ret; | 537 return ret; |
560 } | 538 } |
561 | 539 |
562 const SkPdfNativeObject* get(const SkPdfNativeObject* key) const { | 540 const SkPdfNativeObject* get(const SkPdfNativeObject* key) const { |
563 SkPdfMarkObjectUsed(); | 541 SkPdfMarkObjectUsed(); |
564 | 542 |
565 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 543 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
566 SkASSERT(key->fObjectType == kName_PdfObjectType); | 544 SkASSERT(key->fObjectType == kName_PdfObjectType); |
567 | 545 |
568 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 546 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
569 // TODO(edisonn): report err | 547 // TODO(edisonn): report/warn/assert. |
570 return NULL; | 548 return NULL; |
571 } | 549 } |
572 | 550 |
573 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); | |
574 | |
575 return get(key->fStr.fBuffer, key->fStr.fBytes); | 551 return get(key->fStr.fBuffer, key->fStr.fBytes); |
576 } | 552 } |
577 | 553 |
578 const SkPdfNativeObject* get(const char* key) const { | 554 const SkPdfNativeObject* get(const char* key) const { |
579 SkPdfMarkObjectUsed(); | 555 SkPdfMarkObjectUsed(); |
580 | 556 |
581 return get((const unsigned char*)key, strlen(key)); | 557 return get((const unsigned char*)key, strlen(key)); |
582 } | 558 } |
583 | 559 |
584 const SkPdfNativeObject* get(const unsigned char* key, size_t len) const { | 560 const SkPdfNativeObject* get(const unsigned char* key, size_t len) const { |
585 SkPdfMarkObjectUsed(); | 561 SkPdfMarkObjectUsed(); |
586 | 562 |
587 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 563 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
588 SkASSERT(key); | 564 SkASSERT(key); |
589 if (fObjectType != kDictionary_PdfObjectType) { | 565 if (fObjectType != kDictionary_PdfObjectType) { |
590 // TODO(edisonn): report err | 566 // TODO(edisonn): report/warn/assert. |
591 return NULL; | 567 return NULL; |
592 } | 568 } |
593 SkPdfNativeObject* ret = NULL; | 569 SkPdfNativeObject* ret = NULL; |
594 fMap->find((const char*)key, len, &ret); | 570 fMap->find((const char*)key, len, &ret); |
595 | 571 |
596 #ifdef PDF_TRACE | 572 #ifdef PDF_TRACE |
597 SkString _key; | 573 SkString _key; |
598 _key.append((const char*)key, len); | 574 _key.append((const char*)key, len); |
599 printf("\nget(/%s) = %s\n", _key.c_str(), ret ? ret->toString(0, len + 9
).c_str() : "_NOT_FOUND"); | 575 printf("\nget(/%s) = %s\n", _key.c_str(), |
| 576 ret ? ret->toString(0, len + 9).c_str() : "_NOT_FOUND"); |
600 #endif | 577 #endif |
601 | 578 |
602 return ret; | 579 return ret; |
603 } | 580 } |
604 | 581 |
605 const SkPdfNativeObject* get(const char* key, const char* abr) const { | 582 const SkPdfNativeObject* get(const char* key, const char* abr) const { |
606 SkPdfMarkObjectUsed(); | 583 SkPdfMarkObjectUsed(); |
607 | 584 |
608 const SkPdfNativeObject* ret = get(key); | 585 const SkPdfNativeObject* ret = get(key); |
609 // TODO(edisonn): / is a valid name, and it might be an abreviation, so
"" should not be like NULL | 586 // TODO(edisonn): remove || *abr == '\0' and pass NULL in the _autogen
files instead. |
610 // make this distiontion in generator, and remove "" from condition | |
611 if (ret != NULL || abr == NULL || *abr == '\0') { | 587 if (ret != NULL || abr == NULL || *abr == '\0') { |
612 return ret; | 588 return ret; |
613 } | 589 } |
614 return get(abr); | 590 return get(abr); |
615 } | 591 } |
616 | 592 |
617 SkPdfNativeObject* get(const char* key, const char* abr) { | 593 SkPdfNativeObject* get(const char* key, const char* abr) { |
618 SkPdfMarkObjectUsed(); | 594 SkPdfMarkObjectUsed(); |
619 | 595 |
620 SkPdfNativeObject* ret = get(key); | 596 SkPdfNativeObject* ret = get(key); |
621 // TODO(edisonn): / is a valid name, and it might be an abreviation, so
"" should not be like NULL | 597 // TODO(edisonn): remove || *abr == '\0' and pass NULL in the _autogen
files instead. |
622 // make this distiontion in generator, and remove "" from condition | |
623 if (ret != NULL || abr == NULL || *abr == '\0') { | 598 if (ret != NULL || abr == NULL || *abr == '\0') { |
624 return ret; | 599 return ret; |
625 } | 600 } |
626 return get(abr); | 601 return get(abr); |
627 } | 602 } |
628 | 603 |
629 SkPdfDictionary* asDictionary() { | 604 SkPdfDictionary* asDictionary() { |
630 SkPdfMarkObjectUsed(); | 605 SkPdfMarkObjectUsed(); |
631 | 606 |
632 SkASSERT(isDictionary()); | 607 SkASSERT(isDictionary()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 | 684 |
710 bool isName() const { | 685 bool isName() const { |
711 SkPdfMarkObjectUsed(); | 686 SkPdfMarkObjectUsed(); |
712 | 687 |
713 return fObjectType == kName_PdfObjectType; | 688 return fObjectType == kName_PdfObjectType; |
714 } | 689 } |
715 | 690 |
716 bool isName(const char* name) const { | 691 bool isName(const char* name) const { |
717 SkPdfMarkObjectUsed(); | 692 SkPdfMarkObjectUsed(); |
718 | 693 |
719 return fObjectType == kName_PdfObjectType && fStr.fBytes == strlen(name)
&& strncmp((const char*)fStr.fBuffer, name, fStr.fBytes) == 0; | 694 return fObjectType == kName_PdfObjectType && |
| 695 fStr.fBytes == strlen(name) && |
| 696 strncmp((const char*)fStr.fBuffer, name, fStr.fBytes) == 0; |
720 } | 697 } |
721 | 698 |
722 bool isArray() const { | 699 bool isArray() const { |
723 SkPdfMarkObjectUsed(); | 700 SkPdfMarkObjectUsed(); |
724 | 701 |
725 return fObjectType == kArray_PdfObjectType; | 702 return fObjectType == kArray_PdfObjectType; |
726 } | 703 } |
727 | 704 |
728 bool isDate() const { | 705 bool isDate() const { |
729 SkPdfMarkObjectUsed(); | 706 SkPdfMarkObjectUsed(); |
730 | 707 |
731 return fObjectType == kString_PdfObjectType || fObjectType == kHexString
_PdfObjectType; | 708 return fObjectType == kString_PdfObjectType || fObjectType == kHexString
_PdfObjectType; |
732 } | 709 } |
733 | 710 |
734 bool isDictionary() const { | 711 bool isDictionary() const { |
735 SkPdfMarkObjectUsed(); | 712 SkPdfMarkObjectUsed(); |
736 | 713 |
737 return fObjectType == kDictionary_PdfObjectType; | 714 return fObjectType == kDictionary_PdfObjectType; |
738 } | 715 } |
739 | 716 |
740 bool isFunction() const { | 717 bool isFunction() const { |
741 SkPdfMarkObjectUsed(); | 718 SkPdfMarkObjectUsed(); |
742 | 719 |
743 return false; // NYI | 720 return false; // NYI |
744 } | 721 } |
745 | 722 |
746 bool isRectangle() const { | 723 bool isRectangle() const { |
747 SkPdfMarkObjectUsed(); | 724 SkPdfMarkObjectUsed(); |
748 | 725 |
749 return fObjectType == kArray_PdfObjectType && fArray->count() == 4; // N
YI + and elems are numbers | 726 // TODO(edisonn): add also that each of these 4 objects are numbers. |
| 727 return fObjectType == kArray_PdfObjectType && fArray->count() == 4; |
750 } | 728 } |
751 | 729 |
752 // TODO(edisonn): has stream .. or is stream ... TBD | 730 // TODO(edisonn): has stream .. or is stream ... TBD |
753 bool hasStream() const { | 731 bool hasStream() const { |
754 SkPdfMarkObjectUsed(); | 732 SkPdfMarkObjectUsed(); |
755 | 733 |
756 return isDictionary() && fStr.fBuffer != NULL; | 734 return isDictionary() && fStr.fBuffer != NULL; |
757 } | 735 } |
758 | 736 |
759 // TODO(edisonn): has stream .. or is stream ... TBD | 737 // TODO(edisonn): has stream .. or is stream ... TBD |
(...skipping 17 matching lines...) Expand all Loading... |
777 | 755 |
778 bool isHexString() const { | 756 bool isHexString() const { |
779 SkPdfMarkObjectUsed(); | 757 SkPdfMarkObjectUsed(); |
780 | 758 |
781 return fObjectType == kHexString_PdfObjectType; | 759 return fObjectType == kHexString_PdfObjectType; |
782 } | 760 } |
783 | 761 |
784 bool isMatrix() const { | 762 bool isMatrix() const { |
785 SkPdfMarkObjectUsed(); | 763 SkPdfMarkObjectUsed(); |
786 | 764 |
787 return fObjectType == kArray_PdfObjectType && fArray->count() == 6; // N
YI + and elems are numbers | 765 // TODO(edisonn): add also that each of these 6 objects are numbers. |
| 766 return fObjectType == kArray_PdfObjectType && fArray->count() == 6; |
788 } | 767 } |
789 | 768 |
790 inline int64_t intValue() const { | 769 inline int64_t intValue() const { |
791 SkPdfMarkObjectUsed(); | 770 SkPdfMarkObjectUsed(); |
792 | 771 |
793 SkASSERT(fObjectType == kInteger_PdfObjectType); | 772 SkASSERT(fObjectType == kInteger_PdfObjectType); |
794 | 773 |
795 if (fObjectType != kInteger_PdfObjectType) { | 774 if (fObjectType != kInteger_PdfObjectType) { |
796 // TODO(edisonn): log err | 775 // TODO(edisonn): report/warn/assert. |
797 return 0; | 776 return 0; |
798 } | 777 } |
799 return fIntegerValue; | 778 return fIntegerValue; |
800 } | 779 } |
801 private: | 780 private: |
802 inline double realValue() const { | 781 inline double realValue() const { |
803 SkPdfMarkObjectUsed(); | 782 SkPdfMarkObjectUsed(); |
804 | 783 |
805 SkASSERT(fObjectType == kReal_PdfObjectType); | 784 SkASSERT(fObjectType == kReal_PdfObjectType); |
806 | 785 |
807 if (fObjectType != kReal_PdfObjectType) { | 786 if (fObjectType != kReal_PdfObjectType) { |
808 // TODO(edisonn): log err | 787 // TODO(edisonn): report/warn/assert. |
809 return 0; | 788 return 0; |
810 } | 789 } |
811 return fRealValue; | 790 return fRealValue; |
812 } | 791 } |
813 public: | 792 public: |
814 inline double numberValue() const { | 793 inline double numberValue() const { |
815 SkPdfMarkObjectUsed(); | 794 SkPdfMarkObjectUsed(); |
816 | 795 |
817 SkASSERT(isNumber()); | 796 SkASSERT(isNumber()); |
818 | 797 |
819 if (!isNumber()) { | 798 if (!isNumber()) { |
820 // TODO(edisonn): log err | 799 // TODO(edisonn): report/warn/assert. |
821 return 0; | 800 return 0; |
822 } | 801 } |
823 return fObjectType == kReal_PdfObjectType ? fRealValue : fIntegerValue; | 802 return fObjectType == kReal_PdfObjectType ? fRealValue : fIntegerValue; |
824 } | 803 } |
825 | 804 |
826 inline SkScalar scalarValue() const { | 805 inline SkScalar scalarValue() const { |
827 SkPdfMarkObjectUsed(); | 806 SkPdfMarkObjectUsed(); |
828 | 807 |
829 SkASSERT(isNumber()); | 808 SkASSERT(isNumber()); |
830 | 809 |
831 if (!isNumber()) { | 810 if (!isNumber()) { |
832 // TODO(edisonn): log err | 811 // TODO(edisonn): report/warn/assert. |
833 return SkIntToScalar(0); | 812 return SkIntToScalar(0); |
834 } | 813 } |
835 return fObjectType == kReal_PdfObjectType ? SkDoubleToScalar(fRealValue)
: | 814 return fObjectType == kReal_PdfObjectType ? SkDoubleToScalar(fRealValue)
: |
836 SkIntToScalar(fIntegerValue)
; | 815 SkIntToScalar(fIntegerValue)
; |
837 } | 816 } |
838 | 817 |
839 int referenceId() const { | 818 int referenceId() const { |
840 SkPdfMarkObjectUsed(); | 819 SkPdfMarkObjectUsed(); |
841 | 820 |
842 SkASSERT(fObjectType == kReference_PdfObjectType); | 821 SkASSERT(fObjectType == kReference_PdfObjectType); |
843 return fRef.fId; | 822 return fRef.fId; |
844 } | 823 } |
845 | 824 |
846 int referenceGeneration() const { | 825 int referenceGeneration() const { |
847 SkPdfMarkObjectUsed(); | 826 SkPdfMarkObjectUsed(); |
848 | 827 |
849 SkASSERT(fObjectType == kReference_PdfObjectType); | 828 SkASSERT(fObjectType == kReference_PdfObjectType); |
850 return fRef.fGen; | 829 return fRef.fGen; |
851 } | 830 } |
852 | 831 |
853 inline const char* nameValue() const { | 832 inline const char* nameValue() const { |
854 SkPdfMarkObjectUsed(); | 833 SkPdfMarkObjectUsed(); |
855 | 834 |
856 SkASSERT(fObjectType == kName_PdfObjectType); | 835 SkASSERT(fObjectType == kName_PdfObjectType); |
857 | 836 |
858 if (fObjectType != kName_PdfObjectType) { | 837 if (fObjectType != kName_PdfObjectType) { |
859 // TODO(edisonn): log err | 838 // TODO(edisonn): report/warn/assert. |
860 return ""; | 839 return ""; |
861 } | 840 } |
862 return (const char*)fStr.fBuffer; | 841 return (const char*)fStr.fBuffer; |
863 } | 842 } |
864 | 843 |
865 inline const char* stringValue() const { | 844 inline const char* stringValue() const { |
866 SkPdfMarkObjectUsed(); | 845 SkPdfMarkObjectUsed(); |
867 | 846 |
868 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); | 847 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); |
869 | 848 |
870 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { | 849 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { |
871 // TODO(edisonn): log err | 850 // TODO(edisonn): report/warn/assert. |
872 return ""; | 851 return ""; |
873 } | 852 } |
874 return (const char*)fStr.fBuffer; | 853 return (const char*)fStr.fBuffer; |
875 } | 854 } |
876 | 855 |
877 inline NotOwnedString strRef() { | 856 inline NotOwnedString strRef() { |
878 SkPdfMarkObjectUsed(); | 857 SkPdfMarkObjectUsed(); |
879 | 858 |
880 switch (fObjectType) { | 859 switch (fObjectType) { |
881 case kString_PdfObjectType: | 860 case kString_PdfObjectType: |
(...skipping 22 matching lines...) Expand all Loading... |
904 } | 883 } |
905 return SkString((const char*)fStr.fBuffer, fStr.fBytes); | 884 return SkString((const char*)fStr.fBuffer, fStr.fBytes); |
906 } | 885 } |
907 | 886 |
908 inline SkString stringValue2() const { | 887 inline SkString stringValue2() const { |
909 SkPdfMarkObjectUsed(); | 888 SkPdfMarkObjectUsed(); |
910 | 889 |
911 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); | 890 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); |
912 | 891 |
913 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { | 892 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { |
914 // TODO(edisonn): log err | 893 // TODO(edisonn): report/warn/assert. |
915 return SkString(); | 894 return SkString(); |
916 } | 895 } |
917 return SkString((const char*)fStr.fBuffer, fStr.fBytes); | 896 return SkString((const char*)fStr.fBuffer, fStr.fBytes); |
918 } | 897 } |
919 | 898 |
920 inline bool boolValue() const { | 899 inline bool boolValue() const { |
921 SkPdfMarkObjectUsed(); | 900 SkPdfMarkObjectUsed(); |
922 | 901 |
923 SkASSERT(fObjectType == kBoolean_PdfObjectType); | 902 SkASSERT(fObjectType == kBoolean_PdfObjectType); |
924 | 903 |
925 if (fObjectType != kBoolean_PdfObjectType) { | 904 if (fObjectType != kBoolean_PdfObjectType) { |
926 // TODO(edisonn): log err | 905 // TODO(edisonn): report/warn/assert. |
927 return false; | 906 return false; |
928 } | 907 } |
929 return fBooleanValue; | 908 return fBooleanValue; |
930 } | 909 } |
931 | 910 |
932 SkRect rectangleValue() const { | 911 SkRect rectangleValue() const { |
933 SkPdfMarkObjectUsed(); | 912 SkPdfMarkObjectUsed(); |
934 | 913 |
935 SkASSERT(isRectangle()); | 914 SkASSERT(isRectangle()); |
936 if (!isRectangle()) { | 915 if (!isRectangle()) { |
937 return SkRect::MakeEmpty(); | 916 return SkRect::MakeEmpty(); |
938 } | 917 } |
939 | 918 |
940 double array[4]; | 919 double array[4]; |
941 for (int i = 0; i < 4; i++) { | 920 for (int i = 0; i < 4; i++) { |
942 // TODO(edisonn): version where we could resolve references? | 921 // TODO(edisonn): version where we could resolve references? |
943 const SkPdfNativeObject* elem = objAtAIndex(i); | 922 const SkPdfNativeObject* elem = objAtAIndex(i); |
944 if (elem == NULL || !elem->isNumber()) { | 923 if (elem == NULL || !elem->isNumber()) { |
945 // TODO(edisonn): report error | 924 // TODO(edisonn): report/warn/assert. |
946 return SkRect::MakeEmpty(); | 925 return SkRect::MakeEmpty(); |
947 } | 926 } |
948 array[i] = elem->numberValue(); | 927 array[i] = elem->numberValue(); |
949 } | 928 } |
950 | 929 |
951 return SkRect::MakeLTRB(SkDoubleToScalar(array[0]), | 930 return SkRect::MakeLTRB(SkDoubleToScalar(array[0]), |
952 SkDoubleToScalar(array[1]), | 931 SkDoubleToScalar(array[1]), |
953 SkDoubleToScalar(array[2]), | 932 SkDoubleToScalar(array[2]), |
954 SkDoubleToScalar(array[3])); | 933 SkDoubleToScalar(array[3])); |
955 } | 934 } |
956 | 935 |
957 SkMatrix matrixValue() const { | 936 SkMatrix matrixValue() const { |
958 SkPdfMarkObjectUsed(); | 937 SkPdfMarkObjectUsed(); |
959 | 938 |
960 SkASSERT(isMatrix()); | 939 SkASSERT(isMatrix()); |
961 if (!isMatrix()) { | 940 if (!isMatrix()) { |
962 return SkMatrix::I(); | 941 return SkMatrix::I(); |
963 } | 942 } |
964 | 943 |
965 double array[6]; | 944 double array[6]; |
966 for (int i = 0; i < 6; i++) { | 945 for (int i = 0; i < 6; i++) { |
967 // TODO(edisonn): version where we could resolve references? | 946 // TODO(edisonn): version where we could resolve references? |
968 const SkPdfNativeObject* elem = objAtAIndex(i); | 947 const SkPdfNativeObject* elem = objAtAIndex(i); |
969 if (elem == NULL || !elem->isNumber()) { | 948 if (elem == NULL || !elem->isNumber()) { |
970 // TODO(edisonn): report error | 949 // TODO(edisonn): report/warn/assert. |
971 return SkMatrix::I(); | 950 return SkMatrix::I(); |
972 } | 951 } |
973 array[i] = elem->numberValue(); | 952 array[i] = elem->numberValue(); |
974 } | 953 } |
975 | 954 |
976 return SkMatrixFromPdfMatrix(array); | 955 return SkMatrixFromPdfMatrix(array); |
977 } | 956 } |
978 | 957 |
979 bool filterStream(); | 958 bool filterStream(); |
980 | 959 |
981 | 960 |
982 bool GetFilteredStreamRef(unsigned char const** buffer, size_t* len) { | 961 bool GetFilteredStreamRef(unsigned char const** buffer, size_t* len) { |
983 SkPdfMarkObjectUsed(); | 962 SkPdfMarkObjectUsed(); |
984 | 963 |
985 // TODO(edisonn): add params that couls let the last filter in place if
it is jpeg or png to fast load images | 964 // TODO(edisonn): add params that could let the last filter in place |
| 965 // if it is jpeg or png to fast load images. |
986 if (!hasStream()) { | 966 if (!hasStream()) { |
987 return false; | 967 return false; |
988 } | 968 } |
989 | 969 |
990 filterStream(); | 970 filterStream(); |
991 | 971 |
992 if (buffer) { | 972 if (buffer) { |
993 *buffer = fStr.fBuffer; | 973 *buffer = fStr.fBuffer; |
994 } | 974 } |
995 | 975 |
996 if (len) { | 976 if (len) { |
997 *len = fStr.fBytes >> 2; // last 2 bits | 977 *len = fStr.fBytes >> 2; // last 2 bits - TODO(edisonn): clean up. |
998 } | 978 } |
999 | 979 |
1000 return true; | 980 return true; |
1001 } | 981 } |
1002 | 982 |
1003 bool isStreamFiltered() const { | 983 bool isStreamFiltered() const { |
1004 SkPdfMarkObjectUsed(); | 984 SkPdfMarkObjectUsed(); |
1005 | 985 |
1006 return hasStream() && ((fStr.fBytes & 1) == kFilteredStreamBit); | 986 return hasStream() && ((fStr.fBytes & 1) == kFilteredStreamBit); |
1007 } | 987 } |
(...skipping 13 matching lines...) Expand all Loading... |
1021 | 1001 |
1022 if (!hasStream()) { | 1002 if (!hasStream()) { |
1023 return false; | 1003 return false; |
1024 } | 1004 } |
1025 | 1005 |
1026 if (buffer) { | 1006 if (buffer) { |
1027 *buffer = fStr.fBuffer; | 1007 *buffer = fStr.fBuffer; |
1028 } | 1008 } |
1029 | 1009 |
1030 if (len) { | 1010 if (len) { |
1031 *len = fStr.fBytes >> 2; // remove last 2 bits | 1011 *len = fStr.fBytes >> 2; // remove last 2 bits - TODO(edisonn): cle
an up. |
1032 } | 1012 } |
1033 | 1013 |
1034 return true; | 1014 return true; |
1035 } | 1015 } |
1036 | 1016 |
1037 bool addStream(const unsigned char* buffer, size_t len) { | 1017 bool addStream(const unsigned char* buffer, size_t len) { |
1038 //SkPdfMarkObjectUsed(); | 1018 SkPdfMarkObjectUsed(); |
1039 | 1019 |
1040 SkASSERT(!hasStream()); | 1020 SkASSERT(!hasStream()); |
1041 SkASSERT(isDictionary()); | 1021 SkASSERT(isDictionary()); |
1042 | 1022 |
1043 if (!isDictionary() || hasStream()) { | 1023 if (!isDictionary() || hasStream()) { |
1044 return false; | 1024 return false; |
1045 } | 1025 } |
1046 | 1026 |
1047 fStr.fBuffer = buffer; | 1027 fStr.fBuffer = buffer; |
1048 fStr.fBytes = (len << 2) + kUnfilteredStreamBit; | 1028 fStr.fBytes = (len << 2) + kUnfilteredStreamBit; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 str.append("]"); | 1115 str.append("]"); |
1136 break; | 1116 break; |
1137 | 1117 |
1138 case kDictionary_PdfObjectType: { | 1118 case kDictionary_PdfObjectType: { |
1139 SkTDict<SkPdfNativeObject*>::Iter iter(*fMap); | 1119 SkTDict<SkPdfNativeObject*>::Iter iter(*fMap); |
1140 SkPdfNativeObject* obj = NULL; | 1120 SkPdfNativeObject* obj = NULL; |
1141 const char* key = NULL; | 1121 const char* key = NULL; |
1142 str.append("<<\n"); | 1122 str.append("<<\n"); |
1143 while ((key = iter.next(&obj)) != NULL) { | 1123 while ((key = iter.next(&obj)) != NULL) { |
1144 appendSpaces(&str, level + 2); | 1124 appendSpaces(&str, level + 2); |
1145 str.appendf("/%s %s\n", key, obj->toString(0, level + st
rlen(key) + 4).c_str()); | 1125 str.appendf("/%s %s\n", key, |
| 1126 obj->toString(0, level + strlen(key) + 4).c_
str()); |
1146 } | 1127 } |
1147 appendSpaces(&str, level); | 1128 appendSpaces(&str, level); |
1148 str.append(">>"); | 1129 str.append(">>"); |
1149 if (hasStream()) { | 1130 if (hasStream()) { |
1150 const unsigned char* stream = NULL; | 1131 const unsigned char* stream = NULL; |
1151 size_t length = 0; | 1132 size_t length = 0; |
1152 if (GetFilteredStreamRef(&stream, &length)) { | 1133 if (GetFilteredStreamRef(&stream, &length)) { |
1153 str.append("stream\n"); | 1134 str.append("stream\n"); |
1154 append(&str, (const char*)stream, length > 256 ? 256
: length); | 1135 append(&str, (const char*)stream, length > 256 ? 256
: length); |
1155 str.append("\nendstream"); | 1136 str.append("\nendstream"); |
(...skipping 18 matching lines...) Expand all Loading... |
1174 | 1155 |
1175 default: | 1156 default: |
1176 str = "Error"; | 1157 str = "Error"; |
1177 break; | 1158 break; |
1178 } | 1159 } |
1179 | 1160 |
1180 return str; | 1161 return str; |
1181 } | 1162 } |
1182 | 1163 |
1183 private: | 1164 private: |
1184 static void makeStringCore(const unsigned char* start, SkPdfNativeObject* ob
j, ObjectType type) { | 1165 static void makeStringCore(const unsigned char* start, SkPdfNativeObject* ob
j, |
| 1166 ObjectType type) { |
1185 makeStringCore(start, strlen((const char*)start), obj, type); | 1167 makeStringCore(start, strlen((const char*)start), obj, type); |
1186 } | 1168 } |
1187 | 1169 |
1188 static void makeStringCore(const unsigned char* start, const unsigned char*
end, SkPdfNativeObject* obj, ObjectType type) { | 1170 static void makeStringCore(const unsigned char* start, const unsigned char*
end, |
| 1171 SkPdfNativeObject* obj, ObjectType type) { |
1189 makeStringCore(start, end - start, obj, type); | 1172 makeStringCore(start, end - start, obj, type); |
1190 } | 1173 } |
1191 | 1174 |
1192 static void makeStringCore(const unsigned char* start, size_t bytes, SkPdfNa
tiveObject* obj, ObjectType type) { | 1175 static void makeStringCore(const unsigned char* start, size_t bytes, SkPdfNa
tiveObject* obj, |
1193 | 1176 ObjectType type) { |
1194 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 1177 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
1195 | 1178 |
1196 obj->fObjectType = type; | 1179 obj->fObjectType = type; |
1197 obj->fStr.fBuffer = start; | 1180 obj->fStr.fBuffer = start; |
1198 obj->fStr.fBytes = bytes; | 1181 obj->fStr.fBytes = bytes; |
1199 } | 1182 } |
1200 | 1183 |
1201 bool applyFilter(const char* name); | 1184 bool applyFilter(const char* name); |
1202 bool applyFlateDecodeFilter(); | 1185 bool applyFlateDecodeFilter(); |
1203 bool applyDCTDecodeFilter(); | 1186 bool applyDCTDecodeFilter(); |
(...skipping 11 matching lines...) Expand all Loading... |
1215 SkPdfName() : SkPdfNativeObject() { | 1198 SkPdfName() : SkPdfNativeObject() { |
1216 SkPdfNativeObject::makeName((const unsigned char*)"", this); | 1199 SkPdfNativeObject::makeName((const unsigned char*)"", this); |
1217 } | 1200 } |
1218 public: | 1201 public: |
1219 SkPdfName(char* name) : SkPdfNativeObject() { | 1202 SkPdfName(char* name) : SkPdfNativeObject() { |
1220 this->makeName((const unsigned char*)name, this); | 1203 this->makeName((const unsigned char*)name, this); |
1221 } | 1204 } |
1222 }; | 1205 }; |
1223 | 1206 |
1224 #endif // SkPdfNativeObject | 1207 #endif // SkPdfNativeObject |
OLD | NEW |