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" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 obj->fStr.fBytes = 0; | 365 obj->fStr.fBytes = 0; |
366 } | 366 } |
367 | 367 |
368 // TODO(edisonn): get all the possible names from spec, and compute a hash f
unction | 368 // TODO(edisonn): get all the possible names from spec, and compute a hash f
unction |
369 // that would create no overlaps in the same dictionary | 369 // that would create no overlaps in the same dictionary |
370 // or build a tree of chars that when followed goes to a unique id/index/has
h | 370 // or build a tree of chars that when followed goes to a unique id/index/has
h |
371 // TODO(edisonn): generate constants like kDictFoo, kNameDict_name | 371 // TODO(edisonn): generate constants like kDictFoo, kNameDict_name |
372 // which will be used in code | 372 // which will be used in code |
373 // add function SkPdfFastNameKey key(const char* key); | 373 // add function SkPdfFastNameKey key(const char* key); |
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(const 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
the 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(const 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(const 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 |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 SkPdfName() : SkPdfObject() { | 899 SkPdfName() : SkPdfObject() { |
900 SkPdfObject::makeName((const unsigned char*)"", this); | 900 SkPdfObject::makeName((const unsigned char*)"", this); |
901 } | 901 } |
902 public: | 902 public: |
903 SkPdfName(char* name) : SkPdfObject() { | 903 SkPdfName(char* name) : SkPdfObject() { |
904 this->makeName((const unsigned char*)name, this); | 904 this->makeName((const unsigned char*)name, this); |
905 } | 905 } |
906 }; | 906 }; |
907 | 907 |
908 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ | 908 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ |
OLD | NEW |