| 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 17 matching lines...) Expand all Loading... |
| 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 | 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 | 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. | 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) | 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 | 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. | 36 // page 100. |
| 37 | 37 |
| 38 /** \class SkPdfNativeDoc |
| 39 * |
| 40 * The SkPdfNativeDoc class is used to load a PDF in memory and it represents a
PDF Document. |
| 41 * |
| 42 */ |
| 38 class SkPdfNativeDoc { | 43 class SkPdfNativeDoc { |
| 39 private: | 44 private: |
| 45 // Information about public objects in pdf that can be referenced with ID GE
N R |
| 40 struct PublicObjectEntry { | 46 struct PublicObjectEntry { |
| 47 // Offset in the file where the object starts. |
| 41 long fOffset; | 48 long fOffset; |
| 49 |
| 50 // Offset in file where the object ends. Could be used to quickly fail i
f there is a |
| 51 // problem in pdf structure. |
| 42 // long endOffset; // TODO(edisonn): determine the end of the object, | 52 // long endOffset; // TODO(edisonn): determine the end of the object, |
| 43 // to be used when the doc is corrupted, for fast fa
ilure. | 53 // to be used when the doc is corrupted, for fast fa
ilure. |
| 54 |
| 55 // Refered object. |
| 44 SkPdfNativeObject* fObj; | 56 SkPdfNativeObject* fObj; |
| 57 |
| 58 // If refered object is a reference, we resolve recursively the referenc
e until we find |
| 59 // the real object. |
| 45 SkPdfNativeObject* fResolvedReference; | 60 SkPdfNativeObject* fResolvedReference; |
| 61 |
| 62 // Used to break a recursive reference to itself. |
| 46 bool fIsReferenceResolved; | 63 bool fIsReferenceResolved; |
| 47 }; | 64 }; |
| 48 | 65 |
| 49 public: | 66 public: |
| 67 // TODO(edisonn) should be deprecated |
| 50 SkPdfNativeDoc(const char* path); | 68 SkPdfNativeDoc(const char* path); |
| 69 |
| 70 // TODO(edisonn) should be deprecated |
| 51 SkPdfNativeDoc(SkStream* stream); | 71 SkPdfNativeDoc(SkStream* stream); |
| 52 | 72 |
| 53 ~SkPdfNativeDoc(); | 73 ~SkPdfNativeDoc(); |
| 54 | 74 |
| 75 // returns the number of pages in the pdf |
| 55 int pages() const; | 76 int pages() const; |
| 77 |
| 78 // returns the page resources |
| 56 SkPdfResourceDictionary* pageResources(int page); | 79 SkPdfResourceDictionary* pageResources(int page); |
| 80 |
| 81 // returns the page's mediabox i points - the page physical boundaries. |
| 57 SkRect MediaBox(int page); | 82 SkRect MediaBox(int page); |
| 83 |
| 84 // Returns a tokenizer of a page. The passed allocator will be used to alloc
ate objects that |
| 85 // are parsed. It should be destroyed after the tokenizer. |
| 58 SkPdfNativeTokenizer* tokenizerOfPage(int n, SkPdfAllocator* allocator); | 86 SkPdfNativeTokenizer* tokenizerOfPage(int n, SkPdfAllocator* allocator); |
| 59 | 87 |
| 88 // Returns a tokenizer of a pdf stream. The passed allocator will be used to
allocate objects |
| 89 // that are parsed. It should be destroyed after the tokenizer. |
| 60 SkPdfNativeTokenizer* tokenizerOfStream(SkPdfNativeObject* stream, SkPdfAllo
cator* allocator); | 90 SkPdfNativeTokenizer* tokenizerOfStream(SkPdfNativeObject* stream, SkPdfAllo
cator* allocator); |
| 91 |
| 92 // Returns a tokenizer of a memory buffer. The passed allocator will be used
to allocate objects |
| 93 // that are parsed. It should be destroyed after the tokenizer. |
| 61 SkPdfNativeTokenizer* tokenizerOfBuffer(const unsigned char* buffer, size_t
len, | 94 SkPdfNativeTokenizer* tokenizerOfBuffer(const unsigned char* buffer, size_t
len, |
| 62 SkPdfAllocator* allocator); | 95 SkPdfAllocator* allocator); |
| 63 | 96 |
| 97 |
| 98 //returns objects that are references and can be queried. |
| 64 size_t objects() const; | 99 size_t objects() const; |
| 65 SkPdfNativeObject* object(int i); | |
| 66 SkPdfPageObjectDictionary* page(int page); | |
| 67 | 100 |
| 101 // returns an object. |
| 102 // TODO(edisonn): pdf updates are not supported yet. |
| 103 // add generation parameter to support page updates. |
| 104 SkPdfNativeObject* object(int id /*, int generation*/ ); |
| 105 |
| 106 // returns the object that holds all the page informnation |
| 107 // TODO(edisonn): pdf updates are not supported yet. |
| 108 // add generation parameter to support page updates. |
| 109 SkPdfPageObjectDictionary* page(int page/*, int generation*/); |
| 110 |
| 111 // TODO(edisonn): deprecate the mapper - was used when we supported multiple |
| 112 // parsers (podofo) |
| 113 // The mapper maps allows an object to be mapped to a different dictionary t
ype |
| 114 // and it could verify the integrity of the object. |
| 68 const SkPdfMapper* mapper() const; | 115 const SkPdfMapper* mapper() const; |
| 116 |
| 117 // Allocator of the pdf - this holds all objects that are publicly reference
d |
| 118 // and all the objects that they refer |
| 69 SkPdfAllocator* allocator() const; | 119 SkPdfAllocator* allocator() const; |
| 70 | 120 |
| 121 // Allows a renderer to create values to be dumped on the stack for operator
s to process them. |
| 71 SkPdfReal* createReal(double value) const; | 122 SkPdfReal* createReal(double value) const; |
| 72 SkPdfInteger* createInteger(int value) const; | 123 SkPdfInteger* createInteger(int value) const; |
| 73 // the string does not own the char* | 124 // the string does not own the char* |
| 74 SkPdfString* createString(const unsigned char* sz, size_t len) const; | 125 SkPdfString* createString(const unsigned char* sz, size_t len) const; |
| 75 | 126 |
| 127 // Resolve a reference object. Will recursively resolve the reference |
| 128 // until a real object is found |
| 76 SkPdfNativeObject* resolveReference(SkPdfNativeObject* ref); | 129 SkPdfNativeObject* resolveReference(SkPdfNativeObject* ref); |
| 77 | 130 |
| 78 // Reports an approximation of all the memory usage. | 131 // Reports an approximation of all the memory usage. |
| 79 size_t bytesUsed() const; | 132 size_t bytesUsed() const; |
| 80 | 133 |
| 81 private: | 134 private: |
| 82 | 135 |
| 83 // Takes ownership of bytes. | 136 // Takes ownership of bytes. |
| 84 void init(const void* bytes, size_t length); | 137 void init(const void* bytes, size_t length); |
| 138 |
| 139 // loads a pdf that has missing xref |
| 85 void loadWithoutXRef(); | 140 void loadWithoutXRef(); |
| 86 | 141 |
| 87 const unsigned char* readCrossReferenceSection(const unsigned char* xrefStar
t, | 142 const unsigned char* readCrossReferenceSection(const unsigned char* xrefStar
t, |
| 88 const unsigned char* trailerE
nd); | 143 const unsigned char* trailerE
nd); |
| 89 const unsigned char* readTrailer(const unsigned char* trailerStart, | 144 const unsigned char* readTrailer(const unsigned char* trailerStart, |
| 90 const unsigned char* trailerEnd, | 145 const unsigned char* trailerEnd, |
| 91 bool storeCatalog, long* prev, bool skipKey
word); | 146 bool storeCatalog, long* prev, bool skipKey
word); |
| 92 | 147 |
| 93 // TODO(edisonn): pdfs with updates not supported right now, generation igno
red. | 148 // TODO(edisonn): pdfs with updates not supported right now, generation igno
red. |
| 94 void addCrossSectionInfo(int id, int generation, int offset, bool isFreed); | 149 void addCrossSectionInfo(int id, int generation, int offset, bool isFreed); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 const unsigned char* fFileContent; | 163 const unsigned char* fFileContent; |
| 109 size_t fContentLength; | 164 size_t fContentLength; |
| 110 SkPdfNativeObject* fRootCatalogRef; | 165 SkPdfNativeObject* fRootCatalogRef; |
| 111 SkPdfCatalogDictionary* fRootCatalog; | 166 SkPdfCatalogDictionary* fRootCatalog; |
| 112 | 167 |
| 113 mutable SkTDArray<PublicObjectEntry> fObjects; | 168 mutable SkTDArray<PublicObjectEntry> fObjects; |
| 114 SkTDArray<SkPdfPageObjectDictionary*> fPages; | 169 SkTDArray<SkPdfPageObjectDictionary*> fPages; |
| 115 }; | 170 }; |
| 116 | 171 |
| 117 #endif // SkPdfNativeDoc_DEFINED | 172 #endif // SkPdfNativeDoc_DEFINED |
| OLD | NEW |