| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // 2) recoverable corupt file: remove endobj, endsteam, remove other keywords, u
se other white spaces, insert comments randomly, ... | 68 // 2) recoverable corupt file: remove endobj, endsteam, remove other keywords, u
se other white spaces, insert comments randomly, ... |
| 69 // 3) irrecoverable corrupt file | 69 // 3) irrecoverable corrupt file |
| 70 SkNativeParsedPDF::SkNativeParsedPDF(const char* path) | 70 SkNativeParsedPDF::SkNativeParsedPDF(const char* path) |
| 71 : fAllocator(new SkPdfAllocator()) | 71 : fAllocator(new SkPdfAllocator()) |
| 72 , fRootCatalogRef(NULL) | 72 , fRootCatalogRef(NULL) |
| 73 , fRootCatalog(NULL) { | 73 , fRootCatalog(NULL) { |
| 74 gDoc = this; | 74 gDoc = this; |
| 75 FILE* file = fopen(path, "r"); | 75 FILE* file = fopen(path, "r"); |
| 76 fContentLength = getFileSize(path); | 76 fContentLength = getFileSize(path); |
| 77 fFileContent = new unsigned char[fContentLength + 1]; | 77 fFileContent = new unsigned char[fContentLength + 1]; |
| 78 fread(fFileContent, fContentLength, 1, file); | 78 bool ok = (0 != fread(fFileContent, fContentLength, 1, file)); |
| 79 fFileContent[fContentLength] = '\0'; | 79 fFileContent[fContentLength] = '\0'; |
| 80 fclose(file); | 80 fclose(file); |
| 81 file = NULL; | 81 file = NULL; |
| 82 | 82 |
| 83 if (!ok) { |
| 84 // TODO(edisonn): report read error |
| 85 return; // Doc will have 0 pages |
| 86 } |
| 87 |
| 83 unsigned char* eofLine = lineHome(fFileContent, fFileContent + fContentLengt
h - 1); | 88 unsigned char* eofLine = lineHome(fFileContent, fFileContent + fContentLengt
h - 1); |
| 84 unsigned char* xrefByteOffsetLine = previousLineHome(fFileContent, eofLine); | 89 unsigned char* xrefByteOffsetLine = previousLineHome(fFileContent, eofLine); |
| 85 unsigned char* xrefstartKeywordLine = previousLineHome(fFileContent, xrefByt
eOffsetLine); | 90 unsigned char* xrefstartKeywordLine = previousLineHome(fFileContent, xrefByt
eOffsetLine); |
| 86 | 91 |
| 87 if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) { | 92 if (strcmp((char*)xrefstartKeywordLine, "startxref") != 0) { |
| 88 // TODO(edisonn): report/issue | 93 // TODO(edisonn): report/issue |
| 89 } | 94 } |
| 90 | 95 |
| 91 long xrefByteOffset = atol((const char*)xrefByteOffsetLine); | 96 long xrefByteOffset = atol((const char*)xrefByteOffsetLine); |
| 92 | 97 |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 return (SkPdfObject*)ref; | 422 return (SkPdfObject*)ref; |
| 418 } | 423 } |
| 419 | 424 |
| 420 size_t SkNativeParsedPDF::bytesUsed() const { | 425 size_t SkNativeParsedPDF::bytesUsed() const { |
| 421 return fAllocator->bytesUsed() + | 426 return fAllocator->bytesUsed() + |
| 422 fContentLength + | 427 fContentLength + |
| 423 fObjects.count() * sizeof(PublicObjectEntry) + | 428 fObjects.count() * sizeof(PublicObjectEntry) + |
| 424 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + | 429 fPages.count() * sizeof(SkPdfPageObjectDictionary*) + |
| 425 sizeof(*this); | 430 sizeof(*this); |
| 426 } | 431 } |
| OLD | NEW |