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