Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h

Issue 19793011: (upload draf code for backup) pdfviewer: improve memory, son't allocate extra buffers, and put the … (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 ((ch)==kOpenedCurlyBracket_PdfDelimiter)||\ 55 ((ch)==kOpenedCurlyBracket_PdfDelimiter)||\
56 ((ch)==kClosedCurlyBracket_PdfDelimiter)||\ 56 ((ch)==kClosedCurlyBracket_PdfDelimiter)||\
57 ((ch)==kNamed_PdfDelimiter)||\ 57 ((ch)==kNamed_PdfDelimiter)||\
58 ((ch)==kComment_PdfDelimiter)) 58 ((ch)==kComment_PdfDelimiter))
59 59
60 #define isPdfWhiteSpaceOrPdfDelimiter(ch) (isPdfWhiteSpace(ch)||isPdfDelimiter(c h)) 60 #define isPdfWhiteSpaceOrPdfDelimiter(ch) (isPdfWhiteSpace(ch)||isPdfDelimiter(c h))
61 61
62 #define isPdfDigit(ch) ((ch)>='0'&&(ch)<='9') 62 #define isPdfDigit(ch) ((ch)>='0'&&(ch)<='9')
63 #define isPdfNumeric(ch) (isPdfDigit(ch)||(ch)=='+'||(ch)=='-') 63 #define isPdfNumeric(ch) (isPdfDigit(ch)||(ch)=='+'||(ch)=='-')
64 64
65 unsigned char* skipPdfWhiteSpaces(unsigned char* buffer, size_t len); 65 const unsigned char* skipPdfWhiteSpaces(int level, const unsigned char* buffer, size_t len);
66 unsigned char* endOfPdfToken(unsigned char* start, size_t len); 66 const unsigned char* endOfPdfToken(int level, const unsigned char* start, size_t len);
67 unsigned char* skipPdfComment(unsigned char* start, size_t len); 67 const unsigned char* skipPdfComment(int level, const unsigned char* start, size_ t len);
68 68
69 // TODO(edisonn): typedef read and integer tyepes? make less readable... 69 // TODO(edisonn): typedef read and integer tyepes? make less readable...
70 //typedef double SkPdfReal; 70 //typedef double SkPdfReal;
71 //typedef int64_t SkPdfInteger; 71 //typedef int64_t SkPdfInteger;
72 72
73 // an allocator only allocates memory, and it deletes it all when the allocator is destroyed 73 // an allocator only allocates memory, and it deletes it all when the allocator is destroyed
74 // this would allow us not to do any garbage collection while we parse or draw a pdf, and defere it 74 // this would allow us not to do any garbage collection while we parse or draw a pdf, and defere it
75 // while the user is looking at the image 75 // while the user is looking at the image
76 76
77 class SkPdfObject; 77 class SkPdfObject;
(...skipping 26 matching lines...) Expand all
104 fSizeInBytes += bytes; 104 fSizeInBytes += bytes;
105 return data; 105 return data;
106 } 106 }
107 107
108 size_t bytesUsed() const { 108 size_t bytesUsed() const {
109 return fSizeInBytes; 109 return fSizeInBytes;
110 } 110 }
111 }; 111 };
112 112
113 class SkNativeParsedPDF; 113 class SkNativeParsedPDF;
114 unsigned char* nextObject(unsigned char* start, unsigned char* end, SkPdfObject* token, SkPdfAllocator* allocator, SkNativeParsedPDF* doc); 114 const unsigned char* nextObject(int level, const unsigned char* start, const uns igned char* end, SkPdfObject* token, SkPdfAllocator* allocator, SkNativeParsedPD F* doc);
115 115
116 enum SkPdfTokenType { 116 enum SkPdfTokenType {
117 kKeyword_TokenType, 117 kKeyword_TokenType,
118 kObject_TokenType, 118 kObject_TokenType,
119 }; 119 };
120 120
121 struct PdfToken { 121 struct PdfToken {
122 const char* fKeyword; 122 const char* fKeyword;
123 size_t fKeywordLength; 123 size_t fKeywordLength;
124 SkPdfObject* fObject; 124 SkPdfObject* fObject;
125 SkPdfTokenType fType; 125 SkPdfTokenType fType;
126 126
127 PdfToken() : fKeyword(NULL), fKeywordLength(0), fObject(NULL) {} 127 PdfToken() : fKeyword(NULL), fKeywordLength(0), fObject(NULL) {}
128 }; 128 };
129 129
130 class SkPdfNativeTokenizer { 130 class SkPdfNativeTokenizer {
131 public: 131 public:
132 SkPdfNativeTokenizer(SkPdfObject* objWithStream, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc); 132 SkPdfNativeTokenizer(SkPdfObject* objWithStream, const SkPdfMapper* mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc);
133 SkPdfNativeTokenizer(unsigned char* buffer, int len, const SkPdfMapper* mapp er, SkPdfAllocator* allocator, SkNativeParsedPDF* doc); 133 SkPdfNativeTokenizer(const unsigned char* buffer, int len, const SkPdfMapper * mapper, SkPdfAllocator* allocator, SkNativeParsedPDF* doc);
134 134
135 virtual ~SkPdfNativeTokenizer(); 135 virtual ~SkPdfNativeTokenizer();
136 136
137 bool readToken(PdfToken* token); 137 bool readToken(PdfToken* token);
138 bool readTokenCore(PdfToken* token); 138 bool readTokenCore(PdfToken* token);
139 void PutBack(PdfToken token); 139 void PutBack(PdfToken token);
140 SkPdfImageDictionary* readInlineImage(); 140 SkPdfImageDictionary* readInlineImage();
141 141
142 private: 142 private:
143 SkNativeParsedPDF* fDoc; 143 SkNativeParsedPDF* fDoc;
144 const SkPdfMapper* fMapper; 144 const SkPdfMapper* fMapper;
145 SkPdfAllocator* fAllocator; 145 SkPdfAllocator* fAllocator;
146 146
147 unsigned char* fUncompressedStreamStart; 147 const unsigned char* fUncompressedStreamStart;
148 unsigned char* fUncompressedStream; 148 const unsigned char* fUncompressedStream;
149 unsigned char* fUncompressedStreamEnd; 149 const unsigned char* fUncompressedStreamEnd;
150 150
151 bool fEmpty; 151 bool fEmpty;
152 bool fHasPutBack; 152 bool fHasPutBack;
153 PdfToken fPutBack; 153 PdfToken fPutBack;
154 }; 154 };
155 155
156 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFNATIVETOKENIZER_H_ 156 #endif // EXPERIMENTAL_PDFVIEWER_PDFPARSER_NATIVE_SKPDFNATIVETOKENIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698