OLD | NEW |
1 #ifndef EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFNATIVETOKENIZER_H_ | 1 #ifndef EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFNATIVETOKENIZER_H_ |
2 #define EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFNATIVETOKENIZER_H_ | 2 #define EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFNATIVETOKENIZER_H_ |
3 | 3 |
4 #include "SkTDArray.h" | 4 #include "SkTDArray.h" |
5 #include "SkTDict.h" | 5 #include "SkTDict.h" |
6 #include <math.h> | 6 #include <math.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 class SkPdfMapper; | 9 class SkPdfMapper; |
10 class SkPdfDictionary; | 10 class SkPdfDictionary; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 const unsigned char* endOfPdfToken(int level, const unsigned char* start, const
unsigned char* end); | 66 const unsigned char* endOfPdfToken(int level, const unsigned char* start, const
unsigned char* end); |
67 | 67 |
68 // TODO(edisonn): typedef read and integer tyepes? make less readable... | 68 // TODO(edisonn): typedef read and integer tyepes? make less readable... |
69 //typedef double SkPdfReal; | 69 //typedef double SkPdfReal; |
70 //typedef int64_t SkPdfInteger; | 70 //typedef int64_t SkPdfInteger; |
71 | 71 |
72 // an allocator only allocates memory, and it deletes it all when the allocator
is destroyed | 72 // an allocator only allocates memory, and it deletes it all when the allocator
is destroyed |
73 // this would allow us not to do any garbage collection while we parse or draw a
pdf, and defere it | 73 // this would allow us not to do any garbage collection while we parse or draw a
pdf, and defere it |
74 // while the user is looking at the image | 74 // while the user is looking at the image |
75 | 75 |
76 class SkPdfObject; | 76 class SkPdfNativeObject; |
77 | 77 |
78 class SkPdfAllocator { | 78 class SkPdfAllocator { |
79 #define BUFFER_SIZE 1024 | 79 #define BUFFER_SIZE 1024 |
80 SkTDArray<SkPdfObject*> fHistory; | 80 SkTDArray<SkPdfNativeObject*> fHistory; |
81 SkTDArray<void*> fHandles; | 81 SkTDArray<void*> fHandles; |
82 SkPdfObject* fCurrent; | 82 SkPdfNativeObject* fCurrent; |
83 int fCurrentUsed; | 83 int fCurrentUsed; |
84 | 84 |
85 SkPdfObject* allocBlock(); | 85 SkPdfNativeObject* allocBlock(); |
86 size_t fSizeInBytes; | 86 size_t fSizeInBytes; |
87 | 87 |
88 public: | 88 public: |
89 SkPdfAllocator() { | 89 SkPdfAllocator() { |
90 fSizeInBytes = sizeof(*this); | 90 fSizeInBytes = sizeof(*this); |
91 fCurrent = allocBlock(); | 91 fCurrent = allocBlock(); |
92 fCurrentUsed = 0; | 92 fCurrentUsed = 0; |
93 } | 93 } |
94 | 94 |
95 ~SkPdfAllocator(); | 95 ~SkPdfAllocator(); |
96 | 96 |
97 SkPdfObject* allocObject(); | 97 SkPdfNativeObject* allocObject(); |
98 | 98 |
99 // TODO(edisonn): free this memory in destructor, track the usage? | 99 // TODO(edisonn): free this memory in destructor, track the usage? |
100 void* alloc(size_t bytes) { | 100 void* alloc(size_t bytes) { |
101 void* data = malloc(bytes); | 101 void* data = malloc(bytes); |
102 fHandles.push(data); | 102 fHandles.push(data); |
103 fSizeInBytes += bytes; | 103 fSizeInBytes += bytes; |
104 return data; | 104 return data; |
105 } | 105 } |
106 | 106 |
107 size_t bytesUsed() const { | 107 size_t bytesUsed() const { |
108 return fSizeInBytes; | 108 return fSizeInBytes; |
109 } | 109 } |
110 }; | 110 }; |
111 | 111 |
112 class SkNativeParsedPDF; | 112 class SkPdfNativeDoc; |
113 const unsigned char* nextObject(int level, const unsigned char* start, const uns
igned char* end, SkPdfObject* token, SkPdfAllocator* allocator, SkNativeParsedPD
F* doc); | 113 const unsigned char* nextObject(int level, const unsigned char* start, const uns
igned char* end, SkPdfNativeObject* token, SkPdfAllocator* allocator, SkPdfNativ
eDoc* doc); |
114 | 114 |
115 enum SkPdfTokenType { | 115 enum SkPdfTokenType { |
116 kKeyword_TokenType, | 116 kKeyword_TokenType, |
117 kObject_TokenType, | 117 kObject_TokenType, |
118 }; | 118 }; |
119 | 119 |
120 struct PdfToken { | 120 struct PdfToken { |
121 const char* fKeyword; | 121 const char* fKeyword; |
122 size_t fKeywordLength; | 122 size_t fKeywordLength; |
123 SkPdfObject* fObject; | 123 SkPdfNativeObject* fObject; |
124 SkPdfTokenType fType; | 124 SkPdfTokenType fType; |
125 | 125 |
126 PdfToken() : fKeyword(NULL), fKeywordLength(0), fObject(NULL) {} | 126 PdfToken() : fKeyword(NULL), fKeywordLength(0), fObject(NULL) {} |
127 }; | 127 }; |
128 | 128 |
129 class SkPdfNativeTokenizer { | 129 class SkPdfNativeTokenizer { |
130 public: | 130 public: |
131 SkPdfNativeTokenizer(SkPdfObject* objWithStream, const SkPdfMapper* mapper,
SkPdfAllocator* allocator, SkNativeParsedPDF* doc); | 131 SkPdfNativeTokenizer(SkPdfNativeObject* objWithStream, const SkPdfMapper* ma
pper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc); |
132 SkPdfNativeTokenizer(const unsigned char* buffer, int len, const SkPdfMapper
* mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc); | 132 SkPdfNativeTokenizer(const unsigned char* buffer, int len, const SkPdfMapper
* mapper, SkPdfAllocator* allocator, SkPdfNativeDoc* doc); |
133 | 133 |
134 virtual ~SkPdfNativeTokenizer(); | 134 virtual ~SkPdfNativeTokenizer(); |
135 | 135 |
136 bool readToken(PdfToken* token); | 136 bool readToken(PdfToken* token); |
137 bool readTokenCore(PdfToken* token); | 137 bool readTokenCore(PdfToken* token); |
138 void PutBack(PdfToken token); | 138 void PutBack(PdfToken token); |
139 SkPdfImageDictionary* readInlineImage(); | 139 SkPdfImageDictionary* readInlineImage(); |
140 | 140 |
141 private: | 141 private: |
142 SkNativeParsedPDF* fDoc; | 142 SkPdfNativeDoc* fDoc; |
143 const SkPdfMapper* fMapper; | 143 const SkPdfMapper* fMapper; |
144 SkPdfAllocator* fAllocator; | 144 SkPdfAllocator* fAllocator; |
145 | 145 |
146 const unsigned char* fUncompressedStreamStart; | 146 const unsigned char* fUncompressedStreamStart; |
147 const unsigned char* fUncompressedStream; | 147 const unsigned char* fUncompressedStream; |
148 const unsigned char* fUncompressedStreamEnd; | 148 const unsigned char* fUncompressedStreamEnd; |
149 | 149 |
150 bool fEmpty; | 150 bool fEmpty; |
151 bool fHasPutBack; | 151 bool fHasPutBack; |
152 PdfToken fPutBack; | 152 PdfToken fPutBack; |
153 }; | 153 }; |
154 | 154 |
155 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFNATIVETOKENIZER_H_ | 155 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFNATIVETOKENIZER_H_ |
OLD | NEW |