| 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 421 |
| 422 SkPdfObject* get(const unsigned char* key, size_t len) { | 422 SkPdfObject* get(const unsigned char* key, size_t len) { |
| 423 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 423 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
| 424 SkASSERT(key); | 424 SkASSERT(key); |
| 425 if (fObjectType != kDictionary_PdfObjectType) { | 425 if (fObjectType != kDictionary_PdfObjectType) { |
| 426 // TODO(edisonn): report err | 426 // TODO(edisonn): report err |
| 427 return NULL; | 427 return NULL; |
| 428 } | 428 } |
| 429 SkPdfObject* ret = NULL; | 429 SkPdfObject* ret = NULL; |
| 430 fMap->find((const char*)key, len, &ret); | 430 fMap->find((const char*)key, len, &ret); |
| 431 |
| 432 #ifdef PDF_TRACE |
| 433 SkString _key; |
| 434 _key.append((const char*)key, len); |
| 435 printf("\nget(/%s) = %s\n", _key.c_str(), ret ? ret->toString(0, len + 9
).c_str() : "_NOT_FOUND"); |
| 436 #endif |
| 437 |
| 431 return ret; | 438 return ret; |
| 432 } | 439 } |
| 433 | 440 |
| 434 const SkPdfObject* get(const SkPdfObject* key) const { | 441 const SkPdfObject* get(const SkPdfObject* key) const { |
| 435 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 442 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
| 436 SkASSERT(key->fObjectType == kName_PdfObjectType); | 443 SkASSERT(key->fObjectType == kName_PdfObjectType); |
| 437 | 444 |
| 438 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { | 445 if (key->fObjectType != kName_PdfObjectType || fObjectType != kDictionar
y_PdfObjectType) { |
| 439 // TODO(edisonn): report err | 446 // TODO(edisonn): report err |
| 440 return NULL; | 447 return NULL; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 451 | 458 |
| 452 const SkPdfObject* get(const unsigned char* key, size_t len) const { | 459 const SkPdfObject* get(const unsigned char* key, size_t len) const { |
| 453 SkASSERT(fObjectType == kDictionary_PdfObjectType); | 460 SkASSERT(fObjectType == kDictionary_PdfObjectType); |
| 454 SkASSERT(key); | 461 SkASSERT(key); |
| 455 if (fObjectType != kDictionary_PdfObjectType) { | 462 if (fObjectType != kDictionary_PdfObjectType) { |
| 456 // TODO(edisonn): report err | 463 // TODO(edisonn): report err |
| 457 return NULL; | 464 return NULL; |
| 458 } | 465 } |
| 459 SkPdfObject* ret = NULL; | 466 SkPdfObject* ret = NULL; |
| 460 fMap->find((const char*)key, len, &ret); | 467 fMap->find((const char*)key, len, &ret); |
| 468 |
| 469 #ifdef PDF_TRACE |
| 470 SkString _key; |
| 471 _key.append((const char*)key, len); |
| 472 printf("\nget(/%s) = %s\n", _key.c_str(), ret ? ret->toString(0, len + 9
).c_str() : "_NOT_FOUND"); |
| 473 #endif |
| 474 |
| 461 return ret; | 475 return ret; |
| 462 } | 476 } |
| 463 | 477 |
| 464 const SkPdfObject* get(const char* key, const char* abr) const { | 478 const SkPdfObject* get(const char* key, const char* abr) const { |
| 465 const SkPdfObject* ret = get(key); | 479 const SkPdfObject* ret = get(key); |
| 466 // TODO(edisonn): / is a valid name, and it might be an abreviation, so
"" should not be like NULL | 480 // TODO(edisonn): / is a valid name, and it might be an abreviation, so
"" should not be like NULL |
| 467 // make this distiontion in generator, and remove "" from condition | 481 // make this distiontion in generator, and remove "" from condition |
| 468 if (ret != NULL || abr == NULL || *abr == '\0') { | 482 if (ret != NULL || abr == NULL || *abr == '\0') { |
| 469 return ret; | 483 return ret; |
| 470 } | 484 } |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 if (!isDictionary() || hasStream()) { | 823 if (!isDictionary() || hasStream()) { |
| 810 return false; | 824 return false; |
| 811 } | 825 } |
| 812 | 826 |
| 813 fStr.fBuffer = buffer; | 827 fStr.fBuffer = buffer; |
| 814 fStr.fBytes = (len << 2) + kUnfilteredStreamBit; | 828 fStr.fBytes = (len << 2) + kUnfilteredStreamBit; |
| 815 | 829 |
| 816 return true; | 830 return true; |
| 817 } | 831 } |
| 818 | 832 |
| 819 SkString toString() { | 833 void appendSpaces(SkString* str, int level) { |
| 834 for (int i = 0 ; i < level; i++) { |
| 835 str->append(" "); |
| 836 } |
| 837 } |
| 838 |
| 839 SkString toString(int firstRowLevel = 0, int level = 0) { |
| 820 SkString str; | 840 SkString str; |
| 841 appendSpaces(&str, firstRowLevel); |
| 821 switch (fObjectType) { | 842 switch (fObjectType) { |
| 822 case kInvalid_PdfObjectType: | 843 case kInvalid_PdfObjectType: |
| 823 str.append("Invalid"); | 844 str.append("__Invalid"); |
| 824 break; | 845 break; |
| 825 | 846 |
| 826 case kBoolean_PdfObjectType: | 847 case kBoolean_PdfObjectType: |
| 827 str.appendf("Boolean: %s", fBooleanValue ? "true" : "false"); | 848 str.appendf("%s", fBooleanValue ? "true" : "false"); |
| 828 break; | 849 break; |
| 829 | 850 |
| 830 case kInteger_PdfObjectType: | 851 case kInteger_PdfObjectType: |
| 831 str.appendf("Integer: %i", (int)fIntegerValue); | 852 str.appendf("%i", (int)fIntegerValue); |
| 832 break; | 853 break; |
| 833 | 854 |
| 834 case kReal_PdfObjectType: | 855 case kReal_PdfObjectType: |
| 835 str.appendf("Real: %f", fRealValue); | 856 str.appendf("%f", fRealValue); |
| 836 break; | 857 break; |
| 837 | 858 |
| 838 case kString_PdfObjectType: | 859 case kString_PdfObjectType: |
| 839 str.appendf("String, len() = %u: ", (unsigned int)fStr.fBytes); | 860 str.append("\""); |
| 840 str.append((const char*)fStr.fBuffer, fStr.fBytes); | 861 str.append((const char*)fStr.fBuffer, fStr.fBytes); |
| 862 str.append("\""); |
| 841 break; | 863 break; |
| 842 | 864 |
| 843 case kHexString_PdfObjectType: | 865 case kHexString_PdfObjectType: |
| 844 str.appendf("HexString, len() = %u: ", (unsigned int)fStr.fBytes
); | 866 str.append("<"); |
| 845 str.append((const char*)fStr.fBuffer, fStr.fBytes); | 867 str.append((const char*)fStr.fBuffer, fStr.fBytes); |
| 868 str.append(">"); |
| 846 break; | 869 break; |
| 847 | 870 |
| 848 case kName_PdfObjectType: | 871 case kName_PdfObjectType: |
| 849 str.appendf("Name, len() = %u: ", (unsigned int)fStr.fBytes); | 872 str.append("/"); |
| 850 str.append((const char*)fStr.fBuffer, fStr.fBytes); | 873 str.append((const char*)fStr.fBuffer, fStr.fBytes); |
| 851 break; | 874 break; |
| 852 | 875 |
| 853 case kKeyword_PdfObjectType: | 876 case kKeyword_PdfObjectType: |
| 854 str.appendf("Keyword, len() = %u: ", (unsigned int)fStr.fBytes); | |
| 855 str.append((const char*)fStr.fBuffer, fStr.fBytes); | 877 str.append((const char*)fStr.fBuffer, fStr.fBytes); |
| 856 break; | 878 break; |
| 857 | 879 |
| 858 case kArray_PdfObjectType: | 880 case kArray_PdfObjectType: |
| 859 str.append("Array, size() = %i [", size()); | 881 str.append("[\n"); |
| 860 for (unsigned int i = 0; i < size(); i++) { | 882 for (unsigned int i = 0; i < size(); i++) { |
| 861 str.append(objAtAIndex(i)->toString()); | 883 str.append(objAtAIndex(i)->toString(level + 1, level + 1)); |
| 884 if (i < size() - 1) { |
| 885 str.append(","); |
| 886 } |
| 887 str.append("\n"); |
| 862 } | 888 } |
| 889 appendSpaces(&str, level); |
| 863 str.append("]"); | 890 str.append("]"); |
| 864 break; | 891 break; |
| 865 | 892 |
| 866 case kDictionary_PdfObjectType: | 893 case kDictionary_PdfObjectType: { |
| 867 // TODO(edisonn): NYI | 894 SkTDict<SkPdfObject*>::Iter iter(*fMap); |
| 868 str.append("Dictionary: NYI"); | 895 SkPdfObject* obj = NULL; |
| 869 if (hasStream()) { | 896 const char* key = NULL; |
| 870 str.append(" HAS_STREAM"); | 897 str.append("<<\n"); |
| 898 while ((key = iter.next(&obj)) != NULL) { |
| 899 appendSpaces(&str, level + 2); |
| 900 str.appendf("/%s %s\n", key, obj->toString(0, level + st
rlen(key) + 4).c_str()); |
| 901 } |
| 902 appendSpaces(&str, level); |
| 903 str.append(">>"); |
| 904 if (hasStream()) { |
| 905 str.append("stream HAS_STREAM endstream"); |
| 906 } |
| 871 } | 907 } |
| 872 break; | 908 break; |
| 873 | 909 |
| 874 case kNull_PdfObjectType: | 910 case kNull_PdfObjectType: |
| 875 str = "NULL"; | 911 str = "NULL"; |
| 876 break; | 912 break; |
| 877 | 913 |
| 878 case kReference_PdfObjectType: | 914 case kReference_PdfObjectType: |
| 879 str.appendf("Reference: %i %i", fRef.fId, fRef.fGen); | 915 str.appendf("%i %i R", fRef.fId, fRef.fGen); |
| 880 break; | 916 break; |
| 881 | 917 |
| 882 case kUndefined_PdfObjectType: | 918 case kUndefined_PdfObjectType: |
| 883 str = "Undefined"; | 919 str = "Undefined"; |
| 884 break; | 920 break; |
| 885 | 921 |
| 886 default: | 922 default: |
| 887 str = "Internal Error Object Type"; | 923 str = "Error"; |
| 888 break; | 924 break; |
| 889 } | 925 } |
| 890 | 926 |
| 891 return str; | 927 return str; |
| 892 } | 928 } |
| 893 | 929 |
| 894 private: | 930 private: |
| 895 static void makeStringCore(const unsigned char* start, SkPdfObject* obj, Obj
ectType type) { | 931 static void makeStringCore(const unsigned char* start, SkPdfObject* obj, Obj
ectType type) { |
| 896 makeStringCore(start, strlen((const char*)start), obj, type); | 932 makeStringCore(start, strlen((const char*)start), obj, type); |
| 897 } | 933 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 925 SkPdfName() : SkPdfObject() { | 961 SkPdfName() : SkPdfObject() { |
| 926 SkPdfObject::makeName((const unsigned char*)"", this); | 962 SkPdfObject::makeName((const unsigned char*)"", this); |
| 927 } | 963 } |
| 928 public: | 964 public: |
| 929 SkPdfName(char* name) : SkPdfObject() { | 965 SkPdfName(char* name) : SkPdfObject() { |
| 930 this->makeName((const unsigned char*)name, this); | 966 this->makeName((const unsigned char*)name, this); |
| 931 } | 967 } |
| 932 }; | 968 }; |
| 933 | 969 |
| 934 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ | 970 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFOBJECT_H_ |
| OLD | NEW |