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 SkPdfObject; |
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; |
| 23 |
22 class SkNativeParsedPDF { | 24 class SkNativeParsedPDF { |
23 private: | 25 private: |
24 struct PublicObjectEntry { | 26 struct PublicObjectEntry { |
25 long fOffset; | 27 long fOffset; |
26 // 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 |
27 SkPdfObject* fObj; | 29 SkPdfObject* fObj; |
28 // 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! |
29 SkPdfObject* fResolvedReference; | 31 SkPdfObject* fResolvedReference; |
30 }; | 32 }; |
31 | 33 |
32 public: | 34 public: |
33 // 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? |
34 // TODO(edisonn): read first page asap, linearized | 36 // TODO(edisonn): read first page asap, linearized |
35 // TODO(edisonn): read page N asap, read all file | 37 // TODO(edisonn): read page N asap, read all file |
36 // 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, ...) |
37 // TODO(edisonn): encryption | 39 // TODO(edisonn): encryption |
| 40 |
38 SkNativeParsedPDF(const char* path); | 41 SkNativeParsedPDF(const char* path); |
| 42 SkNativeParsedPDF(SkStream* stream); |
| 43 |
39 ~SkNativeParsedPDF(); | 44 ~SkNativeParsedPDF(); |
40 | 45 |
41 int pages() const; | 46 int pages() const; |
42 SkPdfResourceDictionary* pageResources(int page); | 47 SkPdfResourceDictionary* pageResources(int page); |
43 SkRect MediaBox(int page); | 48 SkRect MediaBox(int page); |
44 SkPdfNativeTokenizer* tokenizerOfPage(int n, SkPdfAllocator* allocator); | 49 SkPdfNativeTokenizer* tokenizerOfPage(int n, SkPdfAllocator* allocator); |
45 | 50 |
46 SkPdfNativeTokenizer* tokenizerOfStream(SkPdfObject* stream, SkPdfAllocator*
allocator); | 51 SkPdfNativeTokenizer* tokenizerOfStream(SkPdfObject* stream, SkPdfAllocator*
allocator); |
47 SkPdfNativeTokenizer* tokenizerOfBuffer(const unsigned char* buffer, size_t
len, | 52 SkPdfNativeTokenizer* tokenizerOfBuffer(const unsigned char* buffer, size_t
len, |
48 SkPdfAllocator* allocator); | 53 SkPdfAllocator* allocator); |
49 | 54 |
50 size_t objects() const; | 55 size_t objects() const; |
51 SkPdfObject* object(int i); | 56 SkPdfObject* object(int i); |
52 | 57 |
53 const SkPdfMapper* mapper() const; | 58 const SkPdfMapper* mapper() const; |
54 SkPdfAllocator* allocator() const; | 59 SkPdfAllocator* allocator() const; |
55 | 60 |
56 SkPdfReal* createReal(double value) const; | 61 SkPdfReal* createReal(double value) const; |
57 SkPdfInteger* createInteger(int value) const; | 62 SkPdfInteger* createInteger(int value) const; |
58 // the string does not own the char* | 63 // the string does not own the char* |
59 SkPdfString* createString(const unsigned char* sz, size_t len) const; | 64 SkPdfString* createString(const unsigned char* sz, size_t len) const; |
60 | 65 |
61 SkPdfObject* resolveReference(const SkPdfObject* ref); | 66 SkPdfObject* resolveReference(const SkPdfObject* ref); |
62 | 67 |
63 // Reports an approximation of all the memory usage. | 68 // Reports an approximation of all the memory usage. |
64 size_t bytesUsed() const; | 69 size_t bytesUsed() const; |
65 | 70 |
66 private: | 71 private: |
67 | 72 |
| 73 // Takes ownership of bytes. |
| 74 void init(const void* bytes, size_t length); |
| 75 |
68 const unsigned char* readCrossReferenceSection(const unsigned char* xrefStar
t, const unsigned char* trailerEnd); | 76 const unsigned char* readCrossReferenceSection(const unsigned char* xrefStar
t, const unsigned char* trailerEnd); |
69 long readTrailer(const unsigned char* trailerStart, const unsigned char* tra
ilerEnd, bool storeCatalog); | 77 long readTrailer(const unsigned char* trailerStart, const unsigned char* tra
ilerEnd, bool storeCatalog); |
70 | 78 |
71 // TODO(edisonn): updates not supported right now, generation ignored | 79 // TODO(edisonn): updates not supported right now, generation ignored |
72 void addCrossSectionInfo(int id, int generation, int offset, bool isFreed); | 80 void addCrossSectionInfo(int id, int generation, int offset, bool isFreed); |
73 static void reset(PublicObjectEntry* obj) { | 81 static void reset(PublicObjectEntry* obj) { |
74 obj->fObj = NULL; | 82 obj->fObj = NULL; |
75 obj->fResolvedReference = NULL; | 83 obj->fResolvedReference = NULL; |
76 obj->fOffset = -1; | 84 obj->fOffset = -1; |
77 } | 85 } |
78 | 86 |
79 SkPdfObject* readObject(int id/*, int generation*/); | 87 SkPdfObject* readObject(int id/*, int generation*/); |
80 | 88 |
81 void fillPages(SkPdfPageTreeNodeDictionary* tree); | 89 void fillPages(SkPdfPageTreeNodeDictionary* tree); |
82 | 90 |
83 // private fields | 91 // private fields |
84 SkPdfAllocator* fAllocator; | 92 SkPdfAllocator* fAllocator; |
85 SkPdfMapper* fMapper; | 93 SkPdfMapper* fMapper; |
86 const unsigned char* fFileContent; | 94 const unsigned char* fFileContent; |
87 size_t fContentLength; | 95 size_t fContentLength; |
88 const SkPdfObject* fRootCatalogRef; | 96 const SkPdfObject* fRootCatalogRef; |
89 SkPdfCatalogDictionary* fRootCatalog; | 97 SkPdfCatalogDictionary* fRootCatalog; |
90 | 98 |
91 mutable SkTDArray<PublicObjectEntry> fObjects; | 99 mutable SkTDArray<PublicObjectEntry> fObjects; |
92 SkTDArray<SkPdfPageObjectDictionary*> fPages; | 100 SkTDArray<SkPdfPageObjectDictionary*> fPages; |
93 }; | 101 }; |
94 | 102 |
95 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKNATIVEPARSEDPDF_H_ | 103 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKNATIVEPARSEDPDF_H_ |
OLD | NEW |