OLD | NEW |
1 #include "SkNativeParsedPDF.h" | 1 #include "SkNativeParsedPDF.h" |
2 #include "SkPdfNativeTokenizer.h" | 2 #include "SkPdfNativeTokenizer.h" |
3 #include "SkPdfBasics.h" | 3 #include "SkPdfBasics.h" |
4 #include "SkPdfObject.h" | 4 #include "SkPdfObject.h" |
5 | 5 |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 | 10 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 | 84 |
85 SkNativeParsedPDF::SkNativeParsedPDF(const char* path) | 85 SkNativeParsedPDF::SkNativeParsedPDF(const char* path) |
86 : fAllocator(new SkPdfAllocator()) | 86 : fAllocator(new SkPdfAllocator()) |
87 , fFileContent(NULL) | 87 , fFileContent(NULL) |
88 , fContentLength(0) | 88 , fContentLength(0) |
89 , fRootCatalogRef(NULL) | 89 , fRootCatalogRef(NULL) |
90 , fRootCatalog(NULL) { | 90 , fRootCatalog(NULL) { |
91 gDoc = this; | 91 gDoc = this; |
92 FILE* file = fopen(path, "r"); | 92 FILE* file = fopen(path, "r"); |
93 size_t size = getFileSize(path); | 93 // TODO(edisonn): put this in a function that can return NULL |
94 void* content = sk_malloc_throw(size); | 94 if (file) { |
95 bool ok = (0 != fread(content, size, 1, file)); | 95 size_t size = getFileSize(path); |
96 fclose(file); | 96 void* content = sk_malloc_throw(size); |
97 file = NULL; | 97 bool ok = (0 != fread(content, size, 1, file)); |
| 98 fclose(file); |
| 99 if (!ok) { |
| 100 sk_free(content); |
| 101 // TODO(edisonn): report read error |
| 102 // TODO(edisonn): not nice to return like this from constructor, cre
ate a static |
| 103 // function that can report NULL for failures. |
| 104 return; // Doc will have 0 pages |
| 105 } |
98 | 106 |
99 if (!ok) { | 107 init(content, size); |
100 sk_free(content); | |
101 // TODO(edisonn): report read error | |
102 // TODO(edisonn): not nice to return like this from constructor, create
a static | |
103 // function that can report NULL for failures. | |
104 return; // Doc will have 0 pages | |
105 } | 108 } |
106 | |
107 init(content, size); | |
108 } | 109 } |
109 | 110 |
110 void SkNativeParsedPDF::init(const void* bytes, size_t length) { | 111 void SkNativeParsedPDF::init(const void* bytes, size_t length) { |
111 fFileContent = (const unsigned char*)bytes; | 112 fFileContent = (const unsigned char*)bytes; |
112 fContentLength = length; | 113 fContentLength = length; |
113 const unsigned char* eofLine = lineHome(fFileContent, fFileContent + fConten
tLength - 1); | 114 const unsigned char* eofLine = lineHome(fFileContent, fFileContent + fConten
tLength - 1); |
114 const unsigned char* xrefByteOffsetLine = previousLineHome(fFileContent, eof
Line); | 115 const unsigned char* xrefByteOffsetLine = previousLineHome(fFileContent, eof
Line); |
115 const unsigned char* xrefstartKeywordLine = previousLineHome(fFileContent, x
refByteOffsetLine); | 116 const unsigned char* xrefstartKeywordLine = previousLineHome(fFileContent, x
refByteOffsetLine); |
116 | 117 |
117 if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) { | 118 if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 return (SkPdfObject*)ref; | 557 return (SkPdfObject*)ref; |
557 } | 558 } |
558 | 559 |
559 size_t SkNativeParsedPDF::bytesUsed() const { | 560 size_t SkNativeParsedPDF::bytesUsed() const { |
560 return fAllocator->bytesUsed() + | 561 return fAllocator->bytesUsed() + |
561 fContentLength + | 562 fContentLength + |
562 fObjects.count() * sizeof(PublicObjectEntry) + | 563 fObjects.count() * sizeof(PublicObjectEntry) + |
563 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + | 564 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + |
564 sizeof(*this); | 565 sizeof(*this); |
565 } | 566 } |
OLD | NEW |