| OLD | NEW |
| 1 #ifndef EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKNATIVEPARSEDPDF_H_ | 1 #ifndef EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKNATIVEPARSEDPDF_H_ |
| 2 #define EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKNATIVEPARSEDPDF_H_ | 2 #define EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKNATIVEPARSEDPDF_H_ |
| 3 | 3 |
| 4 #include "SkRect.h" | 4 #include "SkRect.h" |
| 5 #include "SkTDArray.h" | 5 #include "SkTDArray.h" |
| 6 | 6 |
| 7 class SkCanvas; | 7 class SkCanvas; |
| 8 | 8 |
| 9 class SkPdfAllocator; | 9 class SkPdfAllocator; |
| 10 class SkPdfMapper; | 10 class SkPdfMapper; |
| 11 class SkPdfObject; | 11 class SkPdfNativeObject; |
| 12 class SkPdfReal; | 12 class SkPdfReal; |
| 13 class SkPdfInteger; | 13 class SkPdfInteger; |
| 14 class SkPdfString; | 14 class SkPdfString; |
| 15 class SkPdfResourceDictionary; | 15 class SkPdfResourceDictionary; |
| 16 class SkPdfCatalogDictionary; | 16 class SkPdfCatalogDictionary; |
| 17 class SkPdfPageObjectDictionary; | 17 class SkPdfPageObjectDictionary; |
| 18 class SkPdfPageTreeNodeDictionary; | 18 class SkPdfPageTreeNodeDictionary; |
| 19 | 19 |
| 20 class SkPdfNativeTokenizer; | 20 class SkPdfNativeTokenizer; |
| 21 | 21 |
| 22 class SkStream; | 22 class SkStream; |
| 23 | 23 |
| 24 class SkNativeParsedPDF { | 24 class SkPdfNativeDoc { |
| 25 private: | 25 private: |
| 26 struct PublicObjectEntry { | 26 struct PublicObjectEntry { |
| 27 long fOffset; | 27 long fOffset; |
| 28 // long endOffset; // TODO(edisonn): determine the end of the object, t
o be used when the doc is corrupted | 28 // long endOffset; // TODO(edisonn): determine the end of the object, t
o be used when the doc is corrupted |
| 29 SkPdfObject* fObj; | 29 SkPdfNativeObject* fObj; |
| 30 // TODO(edisonn): perf ... probably it does not make sense to cache the
ref. test it! | 30 // TODO(edisonn): perf ... probably it does not make sense to cache the
ref. test it! |
| 31 SkPdfObject* fResolvedReference; | 31 SkPdfNativeObject* fResolvedReference; |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 public: | 34 public: |
| 35 // TODO(edisonn): read methods: file, stream, http(s)://url, url with seek? | 35 // TODO(edisonn): read methods: file, stream, http(s)://url, url with seek? |
| 36 // TODO(edisonn): read first page asap, linearized | 36 // TODO(edisonn): read first page asap, linearized |
| 37 // TODO(edisonn): read page N asap, read all file | 37 // TODO(edisonn): read page N asap, read all file |
| 38 // TODO(edisonn): allow corruptions of file (e.g. missing endobj, missing st
ream length, ...) | 38 // TODO(edisonn): allow corruptions of file (e.g. missing endobj, missing st
ream length, ...) |
| 39 // TODO(edisonn): encryption | 39 // TODO(edisonn): encryption |
| 40 | 40 |
| 41 SkNativeParsedPDF(const char* path); | 41 SkPdfNativeDoc(const char* path); |
| 42 SkNativeParsedPDF(SkStream* stream); | 42 SkPdfNativeDoc(SkStream* stream); |
| 43 | 43 |
| 44 ~SkNativeParsedPDF(); | 44 ~SkPdfNativeDoc(); |
| 45 | 45 |
| 46 int pages() const; | 46 int pages() const; |
| 47 SkPdfResourceDictionary* pageResources(int page); | 47 SkPdfResourceDictionary* pageResources(int page); |
| 48 SkRect MediaBox(int page); | 48 SkRect MediaBox(int page); |
| 49 SkPdfNativeTokenizer* tokenizerOfPage(int n, SkPdfAllocator* allocator); | 49 SkPdfNativeTokenizer* tokenizerOfPage(int n, SkPdfAllocator* allocator); |
| 50 | 50 |
| 51 SkPdfNativeTokenizer* tokenizerOfStream(SkPdfObject* stream, SkPdfAllocator*
allocator); | 51 SkPdfNativeTokenizer* tokenizerOfStream(SkPdfNativeObject* stream, SkPdfAllo
cator* allocator); |
| 52 SkPdfNativeTokenizer* tokenizerOfBuffer(const unsigned char* buffer, size_t
len, | 52 SkPdfNativeTokenizer* tokenizerOfBuffer(const unsigned char* buffer, size_t
len, |
| 53 SkPdfAllocator* allocator); | 53 SkPdfAllocator* allocator); |
| 54 | 54 |
| 55 size_t objects() const; | 55 size_t objects() const; |
| 56 SkPdfObject* object(int i); | 56 SkPdfNativeObject* object(int i); |
| 57 SkPdfPageObjectDictionary* page(int page); | 57 SkPdfPageObjectDictionary* page(int page); |
| 58 | 58 |
| 59 const SkPdfMapper* mapper() const; | 59 const SkPdfMapper* mapper() const; |
| 60 SkPdfAllocator* allocator() const; | 60 SkPdfAllocator* allocator() const; |
| 61 | 61 |
| 62 SkPdfReal* createReal(double value) const; | 62 SkPdfReal* createReal(double value) const; |
| 63 SkPdfInteger* createInteger(int value) const; | 63 SkPdfInteger* createInteger(int value) const; |
| 64 // the string does not own the char* | 64 // the string does not own the char* |
| 65 SkPdfString* createString(const unsigned char* sz, size_t len) const; | 65 SkPdfString* createString(const unsigned char* sz, size_t len) const; |
| 66 | 66 |
| 67 SkPdfObject* resolveReference(SkPdfObject* ref); | 67 SkPdfNativeObject* resolveReference(SkPdfNativeObject* ref); |
| 68 | 68 |
| 69 // Reports an approximation of all the memory usage. | 69 // Reports an approximation of all the memory usage. |
| 70 size_t bytesUsed() const; | 70 size_t bytesUsed() const; |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 | 73 |
| 74 // Takes ownership of bytes. | 74 // Takes ownership of bytes. |
| 75 void init(const void* bytes, size_t length); | 75 void init(const void* bytes, size_t length); |
| 76 void loadWithoutXRef(); | 76 void loadWithoutXRef(); |
| 77 | 77 |
| 78 const unsigned char* readCrossReferenceSection(const unsigned char* xrefStar
t, const unsigned char* trailerEnd); | 78 const unsigned char* readCrossReferenceSection(const unsigned char* xrefStar
t, const unsigned char* trailerEnd); |
| 79 const unsigned char* readTrailer(const unsigned char* trailerStart, const un
signed char* trailerEnd, bool storeCatalog, long* prev, bool skipKeyword); | 79 const unsigned char* readTrailer(const unsigned char* trailerStart, const un
signed char* trailerEnd, bool storeCatalog, long* prev, bool skipKeyword); |
| 80 | 80 |
| 81 // TODO(edisonn): updates not supported right now, generation ignored | 81 // TODO(edisonn): updates not supported right now, generation ignored |
| 82 void addCrossSectionInfo(int id, int generation, int offset, bool isFreed); | 82 void addCrossSectionInfo(int id, int generation, int offset, bool isFreed); |
| 83 static void reset(PublicObjectEntry* obj) { | 83 static void reset(PublicObjectEntry* obj) { |
| 84 obj->fObj = NULL; | 84 obj->fObj = NULL; |
| 85 obj->fResolvedReference = NULL; | 85 obj->fResolvedReference = NULL; |
| 86 obj->fOffset = -1; | 86 obj->fOffset = -1; |
| 87 } | 87 } |
| 88 | 88 |
| 89 SkPdfObject* readObject(int id/*, int generation*/); | 89 SkPdfNativeObject* readObject(int id/*, int generation*/); |
| 90 | 90 |
| 91 void fillPages(SkPdfPageTreeNodeDictionary* tree); | 91 void fillPages(SkPdfPageTreeNodeDictionary* tree); |
| 92 | 92 |
| 93 // private fields | 93 // private fields |
| 94 SkPdfAllocator* fAllocator; | 94 SkPdfAllocator* fAllocator; |
| 95 SkPdfMapper* fMapper; | 95 SkPdfMapper* fMapper; |
| 96 const unsigned char* fFileContent; | 96 const unsigned char* fFileContent; |
| 97 size_t fContentLength; | 97 size_t fContentLength; |
| 98 SkPdfObject* fRootCatalogRef; | 98 SkPdfNativeObject* fRootCatalogRef; |
| 99 SkPdfCatalogDictionary* fRootCatalog; | 99 SkPdfCatalogDictionary* fRootCatalog; |
| 100 | 100 |
| 101 mutable SkTDArray<PublicObjectEntry> fObjects; | 101 mutable SkTDArray<PublicObjectEntry> fObjects; |
| 102 SkTDArray<SkPdfPageObjectDictionary*> fPages; | 102 SkTDArray<SkPdfPageObjectDictionary*> fPages; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKNATIVEPARSEDPDF_H_ | 105 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKNATIVEPARSEDPDF_H_ |
| OLD | NEW |