OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkPdfNativeDoc_DEFINED | 8 #ifndef SkPdfNativeDoc_DEFINED |
9 #define SkPdfNativeDoc_DEFINED | 9 #define SkPdfNativeDoc_DEFINED |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 class SkPdfString; | 21 class SkPdfString; |
22 class SkPdfResourceDictionary; | 22 class SkPdfResourceDictionary; |
23 class SkPdfCatalogDictionary; | 23 class SkPdfCatalogDictionary; |
24 class SkPdfPageObjectDictionary; | 24 class SkPdfPageObjectDictionary; |
25 class SkPdfPageTreeNodeDictionary; | 25 class SkPdfPageTreeNodeDictionary; |
26 | 26 |
27 class SkPdfNativeTokenizer; | 27 class SkPdfNativeTokenizer; |
28 | 28 |
29 class SkStream; | 29 class SkStream; |
30 | 30 |
| 31 // TODO(edisonn): Implement a smart stream that can seek, and that can also fall
back to reading |
| 32 // the bytes in order. For example, we can try to read the stream optimistically
, but if there |
| 33 // are issues in the pdf, we must read the pdf from the beginning, and fix whate
ver errors we can. |
| 34 // This would be useful to show quickly page 100 in a pdf (www.example.com/foo.p
df#page100) |
| 35 // But if the pdf is missing the xref, then we will have to read most of pdf to
be able to render |
| 36 // page 100. |
| 37 |
31 class SkPdfNativeDoc { | 38 class SkPdfNativeDoc { |
32 private: | 39 private: |
33 struct PublicObjectEntry { | 40 struct PublicObjectEntry { |
34 long fOffset; | 41 long fOffset; |
35 // long endOffset; // TODO(edisonn): determine the end of the object, t
o be used when the doc is corrupted | 42 // long endOffset; // TODO(edisonn): determine the end of the object, |
| 43 // to be used when the doc is corrupted, for fast fa
ilure. |
36 SkPdfNativeObject* fObj; | 44 SkPdfNativeObject* fObj; |
37 // TODO(edisonn): perf ... probably it does not make sense to cache the
ref. test it! | |
38 SkPdfNativeObject* fResolvedReference; | 45 SkPdfNativeObject* fResolvedReference; |
39 bool fIsReferenceResolved; | 46 bool fIsReferenceResolved; |
40 }; | 47 }; |
41 | 48 |
42 public: | 49 public: |
43 // TODO(edisonn): read methods: file, stream, http(s)://url, url with seek? | |
44 // TODO(edisonn): read first page asap, linearized | |
45 // TODO(edisonn): read page N asap, read all file | |
46 // TODO(edisonn): allow corruptions of file (e.g. missing endobj, missing st
ream length, ...) | |
47 // TODO(edisonn): encryption | |
48 | |
49 SkPdfNativeDoc(const char* path); | 50 SkPdfNativeDoc(const char* path); |
50 SkPdfNativeDoc(SkStream* stream); | 51 SkPdfNativeDoc(SkStream* stream); |
51 | 52 |
52 ~SkPdfNativeDoc(); | 53 ~SkPdfNativeDoc(); |
53 | 54 |
54 int pages() const; | 55 int pages() const; |
55 SkPdfResourceDictionary* pageResources(int page); | 56 SkPdfResourceDictionary* pageResources(int page); |
56 SkRect MediaBox(int page); | 57 SkRect MediaBox(int page); |
57 SkPdfNativeTokenizer* tokenizerOfPage(int n, SkPdfAllocator* allocator); | 58 SkPdfNativeTokenizer* tokenizerOfPage(int n, SkPdfAllocator* allocator); |
58 | 59 |
(...skipping 17 matching lines...) Expand all Loading... |
76 | 77 |
77 // Reports an approximation of all the memory usage. | 78 // Reports an approximation of all the memory usage. |
78 size_t bytesUsed() const; | 79 size_t bytesUsed() const; |
79 | 80 |
80 private: | 81 private: |
81 | 82 |
82 // Takes ownership of bytes. | 83 // Takes ownership of bytes. |
83 void init(const void* bytes, size_t length); | 84 void init(const void* bytes, size_t length); |
84 void loadWithoutXRef(); | 85 void loadWithoutXRef(); |
85 | 86 |
86 const unsigned char* readCrossReferenceSection(const unsigned char* xrefStar
t, const unsigned char* trailerEnd); | 87 const unsigned char* readCrossReferenceSection(const unsigned char* xrefStar
t, |
87 const unsigned char* readTrailer(const unsigned char* trailerStart, const un
signed char* trailerEnd, bool storeCatalog, long* prev, bool skipKeyword); | 88 const unsigned char* trailerE
nd); |
| 89 const unsigned char* readTrailer(const unsigned char* trailerStart, |
| 90 const unsigned char* trailerEnd, |
| 91 bool storeCatalog, long* prev, bool skipKey
word); |
88 | 92 |
89 // TODO(edisonn): updates not supported right now, generation ignored | 93 // TODO(edisonn): pdfs with updates not supported right now, generation igno
red. |
90 void addCrossSectionInfo(int id, int generation, int offset, bool isFreed); | 94 void addCrossSectionInfo(int id, int generation, int offset, bool isFreed); |
91 static void reset(PublicObjectEntry* obj) { | 95 static void reset(PublicObjectEntry* obj) { |
92 obj->fObj = NULL; | 96 obj->fObj = NULL; |
93 obj->fResolvedReference = NULL; | 97 obj->fResolvedReference = NULL; |
94 obj->fOffset = -1; | 98 obj->fOffset = -1; |
95 obj->fIsReferenceResolved = false; | 99 obj->fIsReferenceResolved = false; |
96 } | 100 } |
97 | 101 |
98 SkPdfNativeObject* readObject(int id/*, int generation*/); | 102 SkPdfNativeObject* readObject(int id/*, int generation*/); |
99 | 103 |
100 void fillPages(SkPdfPageTreeNodeDictionary* tree); | 104 void fillPages(SkPdfPageTreeNodeDictionary* tree); |
101 | 105 |
102 // private fields | |
103 SkPdfAllocator* fAllocator; | 106 SkPdfAllocator* fAllocator; |
104 SkPdfMapper* fMapper; | 107 SkPdfMapper* fMapper; |
105 const unsigned char* fFileContent; | 108 const unsigned char* fFileContent; |
106 size_t fContentLength; | 109 size_t fContentLength; |
107 SkPdfNativeObject* fRootCatalogRef; | 110 SkPdfNativeObject* fRootCatalogRef; |
108 SkPdfCatalogDictionary* fRootCatalog; | 111 SkPdfCatalogDictionary* fRootCatalog; |
109 | 112 |
110 mutable SkTDArray<PublicObjectEntry> fObjects; | 113 mutable SkTDArray<PublicObjectEntry> fObjects; |
111 SkTDArray<SkPdfPageObjectDictionary*> fPages; | 114 SkTDArray<SkPdfPageObjectDictionary*> fPages; |
112 }; | 115 }; |
113 | 116 |
114 #endif // SkPdfNativeDoc_DEFINED | 117 #endif // SkPdfNativeDoc_DEFINED |
OLD | NEW |