| OLD | NEW |
| 1 #ifndef EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ | 1 #ifndef EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ |
| 2 #define EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ | 2 #define EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ |
| 3 | 3 |
| 4 #include <stdint.h> | 4 #include <stdint.h> |
| 5 #include <string.h> | 5 #include <string.h> |
| 6 #include <string> | 6 #include <string> |
| 7 #include "SkTDArray.h" | 7 #include "SkTDArray.h" |
| 8 #include "SkTDict.h" | 8 #include "SkTDict.h" |
| 9 #include "SkRect.h" | 9 #include "SkRect.h" |
| 10 #include "SkMatrix.h" | 10 #include "SkMatrix.h" |
| 11 #include "SkString.h" | 11 #include "SkString.h" |
| 12 | 12 |
| 13 #include "SkPdfNYI.h" | 13 #include "SkPdfNYI.h" |
| 14 #include "SkPdfConfig.h" | 14 #include "SkPdfConfig.h" |
| 15 | 15 |
| 16 class SkPdfDictionary; | 16 class SkPdfDictionary; |
| 17 class SkPdfStream; | 17 class SkPdfStream; |
| 18 class SkPdfAllocator; | 18 class SkPdfAllocator; |
| 19 | 19 |
| 20 // TODO(edisonn): macro it and move it to utils | 20 // TODO(edisonn): macro it and move it to utils |
| 21 SkMatrix SkMatrixFromPdfMatrix(double array[6]); | 21 SkMatrix SkMatrixFromPdfMatrix(double array[6]); |
| 22 | 22 |
| 23 | 23 |
| 24 #define kFilteredStreamBit 0 | 24 #define kFilteredStreamBit 0 |
| 25 #define kUnfilteredStreamBit 1 | 25 #define kUnfilteredStreamBit 1 |
| 26 | 26 #define kOwnedStreamBit 2 |
| 27 | 27 |
| 28 class SkPdfObject { | 28 class SkPdfObject { |
| 29 public: | 29 public: |
| 30 enum ObjectType { | 30 enum ObjectType { |
| 31 kInvalid_PdfObjectType, | 31 kInvalid_PdfObjectType, |
| 32 | 32 |
| 33 kBoolean_PdfObjectType, | 33 kBoolean_PdfObjectType, |
| 34 kInteger_PdfObjectType, | 34 kInteger_PdfObjectType, |
| 35 kReal_PdfObjectType, | 35 kReal_PdfObjectType, |
| 36 kString_PdfObjectType, | 36 kString_PdfObjectType, |
| 37 kHexString_PdfObjectType, | 37 kHexString_PdfObjectType, |
| 38 kName_PdfObjectType, | 38 kName_PdfObjectType, |
| 39 kKeyword_PdfObjectType, | 39 kKeyword_PdfObjectType, |
| 40 //kStream_PdfObjectType, // attached to a Dictionary | 40 //kStream_PdfObjectType, // attached to a Dictionary |
| 41 kArray_PdfObjectType, | 41 kArray_PdfObjectType, |
| 42 kDictionary_PdfObjectType, | 42 kDictionary_PdfObjectType, |
| 43 kNull_PdfObjectType, | 43 kNull_PdfObjectType, |
| 44 | 44 |
| 45 // TODO(edisonn): after the pdf has been loaded completely, resolve all
references | 45 // TODO(edisonn): after the pdf has been loaded completely, resolve all
references |
| 46 // try the same thing with delayed loaded ... | 46 // try the same thing with delayed loaded ... |
| 47 kReference_PdfObjectType, | 47 kReference_PdfObjectType, |
| 48 | 48 |
| 49 kUndefined_PdfObjectType, // per 1.4 spec, if the same key appear twic
e in the dictionary, the value is undefined | 49 kUndefined_PdfObjectType, // per 1.4 spec, if the same key appear twic
e in the dictionary, the value is undefined |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 struct NotOwnedString { | |
| 54 unsigned char* fBuffer; | |
| 55 size_t fBytes; | |
| 56 }; | |
| 57 | |
| 58 struct Reference { | 53 struct Reference { |
| 59 unsigned int fId; | 54 unsigned int fId; |
| 60 unsigned int fGen; | 55 unsigned int fGen; |
| 61 }; | 56 }; |
| 62 | 57 |
| 63 // TODO(edisonn): add stream start, stream end, where stream is weither the
file | 58 // TODO(edisonn): add stream start, stream end, where stream is weither the
file |
| 64 // or decoded/filtered pdf stream | 59 // or decoded/filtered pdf stream |
| 65 | 60 |
| 66 // TODO(edisonn): add warning/report per object | 61 // TODO(edisonn): add warning/report per object |
| 67 // TODO(edisonn): add flag fUsed, to be used once the parsing is complete, | 62 // TODO(edisonn): add flag fUsed, to be used once the parsing is complete, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // } | 96 // } |
| 102 | 97 |
| 103 void reset() { | 98 void reset() { |
| 104 switch (fObjectType) { | 99 switch (fObjectType) { |
| 105 case kArray_PdfObjectType: | 100 case kArray_PdfObjectType: |
| 106 delete fArray; | 101 delete fArray; |
| 107 break; | 102 break; |
| 108 | 103 |
| 109 case kDictionary_PdfObjectType: | 104 case kDictionary_PdfObjectType: |
| 110 delete fMap; | 105 delete fMap; |
| 106 if (isStreamOwned()) { |
| 107 delete[] fStr.fBuffer; |
| 108 fStr.fBuffer = NULL; |
| 109 fStr.fBytes = 0; |
| 110 } |
| 111 break; | 111 break; |
| 112 | 112 |
| 113 default: | 113 default: |
| 114 break; | 114 break; |
| 115 } | 115 } |
| 116 fObjectType = kInvalid_PdfObjectType; | 116 fObjectType = kInvalid_PdfObjectType; |
| 117 } | 117 } |
| 118 | 118 |
| 119 ObjectType type() { return fObjectType; } | 119 ObjectType type() { return fObjectType; } |
| 120 | 120 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 205 } |
| 206 | 206 |
| 207 static SkPdfObject makeNull() { | 207 static SkPdfObject makeNull() { |
| 208 SkPdfObject obj; | 208 SkPdfObject obj; |
| 209 obj.fObjectType = kNull_PdfObjectType; | 209 obj.fObjectType = kNull_PdfObjectType; |
| 210 return obj; | 210 return obj; |
| 211 } | 211 } |
| 212 | 212 |
| 213 static SkPdfObject kNull; | 213 static SkPdfObject kNull; |
| 214 | 214 |
| 215 static void makeNumeric(unsigned char* start, unsigned char* end, SkPdfObjec
t* obj) { | 215 static void makeNumeric(const unsigned char* start, const unsigned char* end
, SkPdfObject* obj) { |
| 216 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 216 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
| 217 | 217 |
| 218 // TODO(edisonn): NYI properly | 218 // TODO(edisonn): NYI properly |
| 219 // if has dot (impl), or exceeds max int, is real, otherwise is int | 219 // if has dot (impl), or exceeds max int, is real, otherwise is int |
| 220 bool isInt = true; | 220 bool isInt = true; |
| 221 for (unsigned char* current = start; current < end; current++) { | 221 for (const unsigned char* current = start; current < end; current++) { |
| 222 if (*current == '.') { | 222 if (*current == '.') { |
| 223 isInt = false; | 223 isInt = false; |
| 224 break; | 224 break; |
| 225 } | 225 } |
| 226 // TODO(edisonn): report parse issue with numbers like "24asdasd123" | 226 // TODO(edisonn): report parse issue with numbers like "24asdasd123" |
| 227 } | 227 } |
| 228 if (isInt) { | 228 if (isInt) { |
| 229 makeInteger(atol((const char*)start), obj); | 229 makeInteger(atol((const char*)start), obj); |
| 230 } else { | 230 } else { |
| 231 makeReal(atof((const char*)start), obj); | 231 makeReal(atof((const char*)start), obj); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 static void makeReference(unsigned int id, unsigned int gen, SkPdfObject* ob
j) { | 235 static void makeReference(unsigned int id, unsigned int gen, SkPdfObject* ob
j) { |
| 236 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 236 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
| 237 | 237 |
| 238 obj->fObjectType = kReference_PdfObjectType; | 238 obj->fObjectType = kReference_PdfObjectType; |
| 239 obj->fRef.fId = id; | 239 obj->fRef.fId = id; |
| 240 obj->fRef.fGen = gen; | 240 obj->fRef.fGen = gen; |
| 241 } | 241 } |
| 242 | 242 |
| 243 | 243 |
| 244 static void makeString(unsigned char* start, SkPdfObject* obj) { | 244 static void makeString(const unsigned char* start, SkPdfObject* obj) { |
| 245 makeStringCore(start, strlen((const char*)start), obj, kString_PdfObject
Type); | 245 makeStringCore(start, strlen((const char*)start), obj, kString_PdfObject
Type); |
| 246 } | 246 } |
| 247 | 247 |
| 248 static void makeString(unsigned char* start, unsigned char* end, SkPdfObject
* obj) { | 248 static void makeString(const unsigned char* start, const unsigned char* end,
SkPdfObject* obj) { |
| 249 makeStringCore(start, end - start, obj, kString_PdfObjectType); | 249 makeStringCore(start, end - start, obj, kString_PdfObjectType); |
| 250 } | 250 } |
| 251 | 251 |
| 252 static void makeString(unsigned char* start, size_t bytes, SkPdfObject* obj)
{ | 252 static void makeString(const unsigned char* start, size_t bytes, SkPdfObject
* obj) { |
| 253 makeStringCore(start, bytes, obj, kString_PdfObjectType); | 253 makeStringCore(start, bytes, obj, kString_PdfObjectType); |
| 254 } | 254 } |
| 255 | 255 |
| 256 | 256 |
| 257 static void makeHexString(unsigned char* start, SkPdfObject* obj) { | 257 static void makeHexString(const unsigned char* start, SkPdfObject* obj) { |
| 258 makeStringCore(start, strlen((const char*)start), obj, kHexString_PdfObj
ectType); | 258 makeStringCore(start, strlen((const char*)start), obj, kHexString_PdfObj
ectType); |
| 259 } | 259 } |
| 260 | 260 |
| 261 static void makeHexString(unsigned char* start, unsigned char* end, SkPdfObj
ect* obj) { | 261 static void makeHexString(const unsigned char* start, const unsigned char* e
nd, SkPdfObject* obj) { |
| 262 makeStringCore(start, end - start, obj, kHexString_PdfObjectType); | 262 makeStringCore(start, end - start, obj, kHexString_PdfObjectType); |
| 263 } | 263 } |
| 264 | 264 |
| 265 static void makeHexString(unsigned char* start, size_t bytes, SkPdfObject* o
bj) { | 265 static void makeHexString(const unsigned char* start, size_t bytes, SkPdfObj
ect* obj) { |
| 266 makeStringCore(start, bytes, obj, kHexString_PdfObjectType); | 266 makeStringCore(start, bytes, obj, kHexString_PdfObjectType); |
| 267 } | 267 } |
| 268 | 268 |
| 269 | 269 |
| 270 static void makeName(unsigned char* start, SkPdfObject* obj) { | 270 static void makeName(const unsigned char* start, SkPdfObject* obj) { |
| 271 makeStringCore(start, strlen((const char*)start), obj, kName_PdfObjectTy
pe); | 271 makeStringCore(start, strlen((const char*)start), obj, kName_PdfObjectTy
pe); |
| 272 } | 272 } |
| 273 | 273 |
| 274 static void makeName(unsigned char* start, unsigned char* end, SkPdfObject*
obj) { | 274 static void makeName(const unsigned char* start, const unsigned char* end, S
kPdfObject* obj) { |
| 275 makeStringCore(start, end - start, obj, kName_PdfObjectType); | 275 makeStringCore(start, end - start, obj, kName_PdfObjectType); |
| 276 } | 276 } |
| 277 | 277 |
| 278 static void makeName(unsigned char* start, size_t bytes, SkPdfObject* obj) { | 278 static void makeName(const unsigned char* start, size_t bytes, SkPdfObject*
obj) { |
| 279 makeStringCore(start, bytes, obj, kName_PdfObjectType); | 279 makeStringCore(start, bytes, obj, kName_PdfObjectType); |
| 280 } | 280 } |
| 281 | 281 |
| 282 | 282 |
| 283 static void makeKeyword(unsigned char* start, SkPdfObject* obj) { | 283 static void makeKeyword(const unsigned char* start, SkPdfObject* obj) { |
| 284 makeStringCore(start, strlen((const char*)start), obj, kKeyword_PdfObjec
tType); | 284 makeStringCore(start, strlen((const char*)start), obj, kKeyword_PdfObjec
tType); |
| 285 } | 285 } |
| 286 | 286 |
| 287 static void makeKeyword(unsigned char* start, unsigned char* end, SkPdfObjec
t* obj) { | 287 static void makeKeyword(const unsigned char* start, const unsigned char* end
, SkPdfObject* obj) { |
| 288 makeStringCore(start, end - start, obj, kKeyword_PdfObjectType); | 288 makeStringCore(start, end - start, obj, kKeyword_PdfObjectType); |
| 289 } | 289 } |
| 290 | 290 |
| 291 static void makeKeyword(unsigned char* start, size_t bytes, SkPdfObject* obj
) { | 291 static void makeKeyword(const unsigned char* start, size_t bytes, SkPdfObjec
t* obj) { |
| 292 makeStringCore(start, bytes, obj, kKeyword_PdfObjectType); | 292 makeStringCore(start, bytes, obj, kKeyword_PdfObjectType); |
| 293 } | 293 } |
| 294 | 294 |
| 295 | 295 |
| 296 | 296 |
| 297 // TODO(edisonn): make the functions to return SkPdfArray, move these functi
ons in SkPdfArray | 297 // TODO(edisonn): make the functions to return SkPdfArray, move these functi
ons in SkPdfArray |
| 298 static void makeEmptyArray(SkPdfObject* obj) { | 298 static void makeEmptyArray(SkPdfObject* obj) { |
| 299 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 299 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
| 300 | 300 |
| 301 obj->fObjectType = kArray_PdfObjectType; | 301 obj->fObjectType = kArray_PdfObjectType; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 // TODO(edisonn): setting the same key twike, will make the value undefined! | 374 // TODO(edisonn): setting the same key twike, will make the value undefined! |
| 375 bool set(SkPdfObject* key, SkPdfObject* value) { | 375 bool set(SkPdfObject* key, SkPdfObject* value) { |
| 376 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 376 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
| 377 SkASSERT(key->fObjectType == kName_PdfObjectType); | 377 SkASSERT(key->fObjectType == kName_PdfObjectType); |
| 378 | 378 |
| 379 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 379 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
| 380 // TODO(edisonn): report err | 380 // TODO(edisonn): report err |
| 381 return false; | 381 return false; |
| 382 } | 382 } |
| 383 | 383 |
| 384 // we rewrite all delimiters and white spaces with '\0', so we expect th
e end of name to be '\0' | 384 //// we rewrite all delimiters and white spaces with '\0', so we expect
the end of name to be '\0' |
| 385 SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); | 385 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); |
| 386 | 386 |
| 387 return set(key->fStr.fBuffer, key->fStr.fBytes, value); | 387 return set(key->fStr.fBuffer, key->fStr.fBytes, value); |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool set(const char* key, SkPdfObject* value) { | 390 bool set(const char* key, SkPdfObject* value) { |
| 391 return set((const unsigned char*)key, strlen(key), value); | 391 return set((const unsigned char*)key, strlen(key), value); |
| 392 } | 392 } |
| 393 | 393 |
| 394 bool set(const unsigned char* key, size_t len, SkPdfObject* value) { | 394 bool set(const unsigned char* key, size_t len, SkPdfObject* value) { |
| 395 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 395 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
| 396 | 396 |
| 397 if (fObjectType != kDictionary_PdfObjectType) { | 397 if (fObjectType != kDictionary_PdfObjectType) { |
| 398 // TODO(edisonn): report err | 398 // TODO(edisonn): report err |
| 399 return false; | 399 return false; |
| 400 } | 400 } |
| 401 | 401 |
| 402 return fMap->set((const char*)key, len, value); | 402 return fMap->set((const char*)key, len, value); |
| 403 } | 403 } |
| 404 | 404 |
| 405 SkPdfObject* get(SkPdfObject* key) { | 405 SkPdfObject* get(SkPdfObject* key) { |
| 406 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 406 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
| 407 SkASSERT(key->fObjectType == kName_PdfObjectType); | 407 SkASSERT(key->fObjectType == kName_PdfObjectType); |
| 408 | 408 |
| 409 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 409 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
| 410 // TODO(edisonn): report err | 410 // TODO(edisonn): report err |
| 411 return NULL; | 411 return NULL; |
| 412 } | 412 } |
| 413 | 413 |
| 414 SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); | 414 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); |
| 415 | 415 |
| 416 return get(key->fStr.fBuffer, key->fStr.fBytes); | 416 return get(key->fStr.fBuffer, key->fStr.fBytes); |
| 417 } | 417 } |
| 418 | 418 |
| 419 SkPdfObject* get(const char* key) { | 419 SkPdfObject* get(const char* key) { |
| 420 return get((const unsigned char*)key, strlen(key)); | 420 return get((const unsigned char*)key, strlen(key)); |
| 421 } | 421 } |
| 422 | 422 |
| 423 SkPdfObject* get(const unsigned char* key, size_t len) { | 423 SkPdfObject* get(const unsigned char* key, size_t len) { |
| 424 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 424 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
| 425 SkASSERT(key); | 425 SkASSERT(key); |
| 426 if (fObjectType != kDictionary_PdfObjectType) { | 426 if (fObjectType != kDictionary_PdfObjectType) { |
| 427 // TODO(edisonn): report err | 427 // TODO(edisonn): report err |
| 428 return NULL; | 428 return NULL; |
| 429 } | 429 } |
| 430 SkPdfObject* ret = NULL; | 430 SkPdfObject* ret = NULL; |
| 431 fMap->find((const char*)key, len, &ret); | 431 fMap->find((const char*)key, len, &ret); |
| 432 return ret; | 432 return ret; |
| 433 } | 433 } |
| 434 | 434 |
| 435 const SkPdfObject* get(SkPdfObject* key) const { | 435 const SkPdfObject* get(SkPdfObject* key) const { |
| 436 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 436 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
| 437 SkASSERT(key->fObjectType == kName_PdfObjectType); | 437 SkASSERT(key->fObjectType == kName_PdfObjectType); |
| 438 | 438 |
| 439 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 439 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
| 440 // TODO(edisonn): report err | 440 // TODO(edisonn): report err |
| 441 return NULL; | 441 return NULL; |
| 442 } | 442 } |
| 443 | 443 |
| 444 SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); | 444 //SkASSERT(key->fStr.fBuffer[key->fStr.fBytes] == '\0'); |
| 445 | 445 |
| 446 return get(key->fStr.fBuffer, key->fStr.fBytes); | 446 return get(key->fStr.fBuffer, key->fStr.fBytes); |
| 447 } | 447 } |
| 448 | 448 |
| 449 const SkPdfObject* get(const char* key) const { | 449 const SkPdfObject* get(const char* key) const { |
| 450 return get((const unsigned char*)key, strlen(key)); | 450 return get((const unsigned char*)key, strlen(key)); |
| 451 } | 451 } |
| 452 | 452 |
| 453 const SkPdfObject* get(const unsigned char* key, size_t len) const { | 453 const SkPdfObject* get(const unsigned char* key, size_t len) const { |
| 454 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 454 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 inline const char* stringValue() const { | 630 inline const char* stringValue() const { |
| 631 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); | 631 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); |
| 632 | 632 |
| 633 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { | 633 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { |
| 634 // TODO(edisonn): log err | 634 // TODO(edisonn): log err |
| 635 return ""; | 635 return ""; |
| 636 } | 636 } |
| 637 return (const char*)fStr.fBuffer; | 637 return (const char*)fStr.fBuffer; |
| 638 } | 638 } |
| 639 | 639 |
| 640 inline NotOwnedString strRef() { |
| 641 switch (fObjectType) { |
| 642 case kString_PdfObjectType: |
| 643 case kHexString_PdfObjectType: |
| 644 case kKeyword_PdfObjectType: |
| 645 return fStr; |
| 646 |
| 647 default: |
| 648 // TODO(edisonn): report/warning |
| 649 return NotOwnedString(); |
| 650 } |
| 651 } |
| 652 |
| 640 // TODO(edisonn): nameValue2 and stringValue2 are used to make code generati
on easy, | 653 // TODO(edisonn): nameValue2 and stringValue2 are used to make code generati
on easy, |
| 641 // but it is not a performat way to do it, since it will create an extra cop
y | 654 // but it is not a performat way to do it, since it will create an extra cop
y |
| 642 // remove these functions and make code generated faster | 655 // remove these functions and make code generated faster |
| 643 inline std::string nameValue2() const { | 656 inline std::string nameValue2() const { |
| 644 SkASSERT(fObjectType == kName_PdfObjectType); | 657 SkASSERT(fObjectType == kName_PdfObjectType); |
| 645 | 658 |
| 646 if (fObjectType != kName_PdfObjectType) { | 659 if (fObjectType != kName_PdfObjectType) { |
| 647 // TODO(edisonn): log err | 660 // TODO(edisonn): log err |
| 648 return ""; | 661 return ""; |
| 649 } | 662 } |
| 650 return (const char*)fStr.fBuffer; | 663 return std::string((const char*)fStr.fBuffer, fStr.fBytes); |
| 651 } | 664 } |
| 652 | 665 |
| 653 inline std::string stringValue2() const { | 666 inline std::string stringValue2() const { |
| 654 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); | 667 SkASSERT(fObjectType == kString_PdfObjectType || fObjectType == kHexStri
ng_PdfObjectType); |
| 655 | 668 |
| 656 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { | 669 if (fObjectType != kString_PdfObjectType && fObjectType != kHexString_Pd
fObjectType) { |
| 657 // TODO(edisonn): log err | 670 // TODO(edisonn): log err |
| 658 return ""; | 671 return ""; |
| 659 } | 672 } |
| 660 return (const char*)fStr.fBuffer; | 673 return std::string((const char*)fStr.fBuffer, fStr.fBytes); |
| 661 } | 674 } |
| 662 | 675 |
| 663 inline bool boolValue() const { | 676 inline bool boolValue() const { |
| 664 SkASSERT(fObjectType == kBoolean_PdfObjectType); | 677 SkASSERT(fObjectType == kBoolean_PdfObjectType); |
| 665 | 678 |
| 666 if (fObjectType == kBoolean_PdfObjectType) { | 679 if (fObjectType == kBoolean_PdfObjectType) { |
| 667 // TODO(edisonn): log err | 680 // TODO(edisonn): log err |
| 668 return false; | 681 return false; |
| 669 } | 682 } |
| 670 return fBooleanValue; | 683 return fBooleanValue; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 if (elem == NULL || !elem->isNumber()) { | 719 if (elem == NULL || !elem->isNumber()) { |
| 707 // TODO(edisonn): report error | 720 // TODO(edisonn): report error |
| 708 return SkMatrix::I(); | 721 return SkMatrix::I(); |
| 709 } | 722 } |
| 710 array[i] = elem->numberValue(); | 723 array[i] = elem->numberValue(); |
| 711 } | 724 } |
| 712 | 725 |
| 713 return SkMatrixFromPdfMatrix(array); | 726 return SkMatrixFromPdfMatrix(array); |
| 714 } | 727 } |
| 715 | 728 |
| 716 bool filterStream(SkPdfAllocator* allocator); | 729 bool filterStream(); |
| 717 | 730 |
| 718 | 731 |
| 719 bool GetFilteredStreamRef(unsigned char** buffer, size_t* len, SkPdfAllocato
r* allocator) { | 732 bool GetFilteredStreamRef(unsigned char const** buffer, size_t* len) { |
| 720 // TODO(edisonn): add params that couls let the last filter in place if
it is jpeg or png to fast load images | 733 // TODO(edisonn): add params that couls let the last filter in place if
it is jpeg or png to fast load images |
| 721 if (!hasStream()) { | 734 if (!hasStream()) { |
| 722 return false; | 735 return false; |
| 723 } | 736 } |
| 724 | 737 |
| 725 filterStream(allocator); | 738 filterStream(); |
| 726 | 739 |
| 727 if (buffer) { | 740 if (buffer) { |
| 728 *buffer = fStr.fBuffer; | 741 *buffer = fStr.fBuffer; |
| 729 } | 742 } |
| 730 | 743 |
| 731 if (len) { | 744 if (len) { |
| 732 *len = fStr.fBytes >> 1; // last bit | 745 *len = fStr.fBytes >> 2; // last 2 bits |
| 733 } | 746 } |
| 734 | 747 |
| 735 return true; | 748 return true; |
| 736 } | 749 } |
| 737 | 750 |
| 738 bool isStreamFiltered() const { | 751 bool isStreamFiltered() const { |
| 739 return hasStream() && ((fStr.fBytes & 1) == kFilteredStreamBit); | 752 return hasStream() && ((fStr.fBytes & 1) == kFilteredStreamBit); |
| 740 } | 753 } |
| 741 | 754 |
| 742 bool GetUnfilteredStreamRef(unsigned char** buffer, size_t* len) const { | 755 bool isStreamOwned() const { |
| 756 return hasStream() && ((fStr.fBytes & 2) == kOwnedStreamBit); |
| 757 } |
| 758 |
| 759 bool GetUnfilteredStreamRef(unsigned char const** buffer, size_t* len) const
{ |
| 743 if (isStreamFiltered()) { | 760 if (isStreamFiltered()) { |
| 744 return false; | 761 return false; |
| 745 } | 762 } |
| 746 | 763 |
| 747 if (!hasStream()) { | 764 if (!hasStream()) { |
| 748 return false; | 765 return false; |
| 749 } | 766 } |
| 750 | 767 |
| 751 if (buffer) { | 768 if (buffer) { |
| 752 *buffer = fStr.fBuffer; | 769 *buffer = fStr.fBuffer; |
| 753 } | 770 } |
| 754 | 771 |
| 755 if (len) { | 772 if (len) { |
| 756 *len = fStr.fBytes >> 1; // remove slast bit | 773 *len = fStr.fBytes >> 2; // remove last 2 bits |
| 757 } | 774 } |
| 758 | 775 |
| 759 return true; | 776 return true; |
| 760 } | 777 } |
| 761 | 778 |
| 762 bool addStream(unsigned char* buffer, size_t len) { | 779 bool addStream(const unsigned char* buffer, size_t len) { |
| 763 SkASSERT(!hasStream()); | 780 SkASSERT(!hasStream()); |
| 764 SkASSERT(isDictionary()); | 781 SkASSERT(isDictionary()); |
| 765 | 782 |
| 766 if (!isDictionary() || hasStream()) { | 783 if (!isDictionary() || hasStream()) { |
| 767 return false; | 784 return false; |
| 768 } | 785 } |
| 769 | 786 |
| 770 fStr.fBuffer = buffer; | 787 fStr.fBuffer = buffer; |
| 771 fStr.fBytes = (len << 2) + kUnfilteredStreamBit; | 788 fStr.fBytes = (len << 2) + kUnfilteredStreamBit; |
| 772 | 789 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 | 859 |
| 843 default: | 860 default: |
| 844 str = "Internal Error Object Type"; | 861 str = "Internal Error Object Type"; |
| 845 break; | 862 break; |
| 846 } | 863 } |
| 847 | 864 |
| 848 return str; | 865 return str; |
| 849 } | 866 } |
| 850 | 867 |
| 851 private: | 868 private: |
| 852 static void makeStringCore(unsigned char* start, SkPdfObject* obj, ObjectTyp
e type) { | 869 static void makeStringCore(const unsigned char* start, SkPdfObject* obj, Obj
ectType type) { |
| 853 makeStringCore(start, strlen((const char*)start), obj, type); | 870 makeStringCore(start, strlen((const char*)start), obj, type); |
| 854 } | 871 } |
| 855 | 872 |
| 856 static void makeStringCore(unsigned char* start, unsigned char* end, SkPdfOb
ject* obj, ObjectType type) { | 873 static void makeStringCore(const unsigned char* start, const unsigned char*
end, SkPdfObject* obj, ObjectType type) { |
| 857 makeStringCore(start, end - start, obj, type); | 874 makeStringCore(start, end - start, obj, type); |
| 858 } | 875 } |
| 859 | 876 |
| 860 static void makeStringCore(unsigned char* start, size_t bytes, SkPdfObject*
obj, ObjectType type) { | 877 static void makeStringCore(const unsigned char* start, size_t bytes, SkPdfOb
ject* obj, ObjectType type) { |
| 861 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); | 878 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); |
| 862 | 879 |
| 863 obj->fObjectType = type; | 880 obj->fObjectType = type; |
| 864 obj->fStr.fBuffer = start; | 881 obj->fStr.fBuffer = start; |
| 865 obj->fStr.fBytes = bytes; | 882 obj->fStr.fBytes = bytes; |
| 866 } | 883 } |
| 867 | 884 |
| 868 bool applyFilter(const char* name, SkPdfAllocator* allocator); | 885 bool applyFilter(const char* name); |
| 869 bool applyFlateDecodeFilter(SkPdfAllocator* allocator); | 886 bool applyFlateDecodeFilter(); |
| 870 bool applyDCTDecodeFilter(SkPdfAllocator* allocator); | 887 bool applyDCTDecodeFilter(); |
| 871 }; | 888 }; |
| 872 | 889 |
| 873 class SkPdfStream : public SkPdfObject {}; | 890 class SkPdfStream : public SkPdfObject {}; |
| 874 class SkPdfArray : public SkPdfObject {}; | 891 class SkPdfArray : public SkPdfObject {}; |
| 875 class SkPdfString : public SkPdfObject {}; | 892 class SkPdfString : public SkPdfObject {}; |
| 876 class SkPdfHexString : public SkPdfObject {}; | 893 class SkPdfHexString : public SkPdfObject {}; |
| 877 class SkPdfInteger : public SkPdfObject {}; | 894 class SkPdfInteger : public SkPdfObject {}; |
| 878 class SkPdfReal : public SkPdfObject {}; | 895 class SkPdfReal : public SkPdfObject {}; |
| 879 class SkPdfNumber : public SkPdfObject {}; | 896 class SkPdfNumber : public SkPdfObject {}; |
| 880 | 897 |
| 881 class SkPdfName : public SkPdfObject { | 898 class SkPdfName : public SkPdfObject { |
| 882 SkPdfName() : SkPdfObject() { | 899 SkPdfName() : SkPdfObject() { |
| 883 SkPdfObject::makeName((unsigned char*)"", this); | 900 SkPdfObject::makeName((const unsigned char*)"", this); |
| 884 } | 901 } |
| 885 public: | 902 public: |
| 886 SkPdfName(char* name) : SkPdfObject() { | 903 SkPdfName(char* name) : SkPdfObject() { |
| 887 this->makeName((unsigned char*)name, this); | 904 this->makeName((const unsigned char*)name, this); |
| 888 } | 905 } |
| 889 }; | 906 }; |
| 890 | 907 |
| 891 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ | 908 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ |
| OLD | NEW |