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

Side by Side Diff: core/include/fpdfapi/fpdf_parser.h

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 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
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ 7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
8 #define CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ 8 #define CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
9 9
10 #include "../fxcrt/fx_system.h" 10 #include "../fxcrt/fx_system.h"
(...skipping 16 matching lines...) Expand all
27 class CPDF_DocRenderData; 27 class CPDF_DocRenderData;
28 class CPDF_ModuleMgr; 28 class CPDF_ModuleMgr;
29 class CFX_DIBSource; 29 class CFX_DIBSource;
30 class CPDF_Font; 30 class CPDF_Font;
31 class CPDF_Image; 31 class CPDF_Image;
32 class CPDF_ColorSpace; 32 class CPDF_ColorSpace;
33 class CPDF_Pattern; 33 class CPDF_Pattern;
34 class CPDF_FontEncoding; 34 class CPDF_FontEncoding;
35 class CPDF_IccProfile; 35 class CPDF_IccProfile;
36 class CFX_PrivateData; 36 class CFX_PrivateData;
37 #define FPDFPERM_PRINT» » » 0x0004 37 #define FPDFPERM_PRINT 0x0004
38 #define FPDFPERM_MODIFY»» » 0x0008 38 #define FPDFPERM_MODIFY 0x0008
39 #define FPDFPERM_EXTRACT» » 0x0010 39 #define FPDFPERM_EXTRACT 0x0010
40 #define FPDFPERM_ANNOT_FORM» » 0x0020 40 #define FPDFPERM_ANNOT_FORM 0x0020
41 #define FPDFPERM_FILL_FORM» » 0x0100 41 #define FPDFPERM_FILL_FORM 0x0100
42 #define FPDFPERM_EXTRACT_ACCESS»0x0200 42 #define FPDFPERM_EXTRACT_ACCESS 0x0200
43 #define FPDFPERM_ASSEMBLE» » 0x0400 43 #define FPDFPERM_ASSEMBLE 0x0400
44 #define FPDFPERM_PRINT_HIGH» » 0x0800 44 #define FPDFPERM_PRINT_HIGH 0x0800
45 #define FPDF_PAGE_MAX_NUM» » 0xFFFFF 45 #define FPDF_PAGE_MAX_NUM 0xFFFFF
46 46
47 // Indexed by 8-bit character code, contains either: 47 // Indexed by 8-bit character code, contains either:
48 // 'W' - for whitespace: NUL, TAB, CR, LF, FF, 0x80, 0xff 48 // 'W' - for whitespace: NUL, TAB, CR, LF, FF, 0x80, 0xff
49 // 'N' - for numeric: 0123456789+-. 49 // 'N' - for numeric: 0123456789+-.
50 // 'D' - for delimiter: %()/<>[]{} 50 // 'D' - for delimiter: %()/<>[]{}
51 // 'R' - otherwise. 51 // 'R' - otherwise.
52 extern const char PDF_CharType[256]; 52 extern const char PDF_CharType[256];
53 53
54 class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjects 54 class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjects {
55 { 55 public:
56 public: 56 CPDF_Document();
57 CPDF_Document(); 57 explicit CPDF_Document(CPDF_Parser* pParser);
58 explicit CPDF_Document(CPDF_Parser* pParser); 58
59 59 ~CPDF_Document();
60 ~CPDF_Document(); 60
61 61 CPDF_Parser* GetParser() const { return m_pParser; }
62 CPDF_Parser*» » » GetParser() const 62
63 { 63 CPDF_Dictionary* GetRoot() const { return m_pRootDict; }
64 return m_pParser; 64
65 } 65 CPDF_Dictionary* GetInfo() const { return m_pInfoDict; }
66 66
67 CPDF_Dictionary*» » GetRoot() const 67 void GetID(CFX_ByteString& id1, CFX_ByteString& id2) const {
68 { 68 id1 = m_ID1;
69 return m_pRootDict; 69 id2 = m_ID2;
70 } 70 }
71 71
72 CPDF_Dictionary*» » GetInfo() const 72 int GetPageCount() const;
73 { 73
74 return m_pInfoDict; 74 CPDF_Dictionary* GetPage(int iPage);
75 } 75
76 76 int GetPageIndex(FX_DWORD objnum);
77 void» » » » » GetID(CFX_ByteString& id1, CFX_B yteString& id2) const 77
78 { 78 FX_DWORD GetUserPermissions(FX_BOOL bCheckRevision = FALSE) const;
79 id1 = m_ID1; 79
80 id2 = m_ID2; 80 FX_BOOL IsOwner() const;
81 } 81
82 82 CPDF_DocPageData* GetPageData() { return GetValidatePageData(); }
83 int»» » » » » GetPageCount() const; 83
84 84 void ClearPageData();
85 CPDF_Dictionary*» » GetPage(int iPage); 85
86 86 void RemoveColorSpaceFromPageData(CPDF_Object* pObject);
87 int»» » » » » GetPageIndex(FX_DWORD objnum); 87
88 88 CPDF_DocRenderData* GetRenderData() { return GetValidateRenderData(); }
89 FX_DWORD» » » » GetUserPermissions(FX_BOOL bCheckRevisio n = FALSE) const; 89
90 90 void ClearRenderData();
91 FX_BOOL» » » » » IsOwner() const; 91
92 92 void ClearRenderFont();
93 93
94 94 FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const;
95 CPDF_DocPageData*» » GetPageData() 95
96 { 96 // |pFontDict| must not be null.
97 return GetValidatePageData(); 97 CPDF_Font* LoadFont(CPDF_Dictionary* pFontDict);
98 } 98
99 99 CPDF_ColorSpace* LoadColorSpace(CPDF_Object* pCSObj,
100 void» » » » » ClearPageData(); 100 CPDF_Dictionary* pResources = NULL);
101 101
102 void» » » » » RemoveColorSpaceFromPageData(CPD F_Object* pObject); 102 CPDF_Pattern* LoadPattern(CPDF_Object* pObj,
103 103 FX_BOOL bShading,
104 104 const CFX_AffineMatrix* matrix = NULL);
105 CPDF_DocRenderData*»» GetRenderData() 105
106 { 106 CPDF_Image* LoadImageF(CPDF_Object* pObj);
107 return GetValidateRenderData(); 107
108 } 108 CPDF_StreamAcc* LoadFontFile(CPDF_Stream* pStream);
109 109
110 void» » » » » ClearRenderData(); 110 CPDF_IccProfile* LoadIccProfile(CPDF_Stream* pStream);
111
112 void» » » » » ClearRenderFont();
113
114
115 FX_BOOL» » » » » IsFormStream(FX_DWORD objnum, FX _BOOL& bForm) const;
116
117 // |pFontDict| must not be null.
118 CPDF_Font* LoadFont(CPDF_Dictionary* pFontDict);
119
120 CPDF_ColorSpace*» » LoadColorSpace(CPDF_Object* pCSObj, CPDF_Diction ary* pResources = NULL);
121
122 CPDF_Pattern*» » » LoadPattern(CPDF_Object* pObj, FX_BOOL b Shading, const CFX_AffineMatrix* matrix = NULL);
123
124 CPDF_Image*»» » » LoadImageF(CPDF_Object* pObj);
125
126 CPDF_StreamAcc*» » » LoadFontFile(CPDF_Stream* pStream);
127
128 CPDF_IccProfile*» » LoadIccProfile(CPDF_Stream* pStream);
129 111
130 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 112 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
131 113
132 CPDF_Font*» » » » AddWindowsFont(LOGFONTA* pLogFont, FX_BO OL bVert, FX_BOOL bTranslateName = FALSE); 114 CPDF_Font* AddWindowsFont(LOGFONTA* pLogFont,
133 CPDF_Font*» » » » AddWindowsFont(LOGFONTW* pLogFont, FX_BO OL bVert, FX_BOOL bTranslateName = FALSE); 115 FX_BOOL bVert,
116 FX_BOOL bTranslateName = FALSE);
117 CPDF_Font* AddWindowsFont(LOGFONTW* pLogFont,
118 FX_BOOL bVert,
119 FX_BOOL bTranslateName = FALSE);
134 #endif 120 #endif
135 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 121 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
136 CPDF_Font* AddMacFont(CTFontRef pFont, FX_BOOL bVert, FX_BOOL b TranslateName = FALSE); 122 CPDF_Font* AddMacFont(CTFontRef pFont,
123 FX_BOOL bVert,
124 FX_BOOL bTranslateName = FALSE);
137 #endif 125 #endif
138 126
139 CPDF_Font* AddStandardFont(const FX_CHAR* font, CPD F_FontEncoding* pEncoding); 127 CPDF_Font* AddStandardFont(const FX_CHAR* font, CPDF_FontEncoding* pEncoding);
140 128
141 129 CPDF_Font* AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert);
142 CPDF_Font* AddFont(CFX_Font* pFont, int charset, FX _BOOL bVert); 130
143 131 void CreateNewDoc();
144 void CreateNewDoc(); 132
145 133 CPDF_Dictionary* CreateNewPage(int iPage);
146 CPDF_Dictionary* CreateNewPage(int iPage); 134
147 135 void DeletePage(int iPage);
148 void DeletePage(int iPage); 136
149 137 void LoadDoc();
150 void LoadDoc(); 138 void LoadAsynDoc(CPDF_Dictionary* pLinearized);
151 void LoadAsynDoc(CPDF_Dictionary *pLi nearized); 139 void LoadPages();
152 void LoadPages(); 140
153 protected: 141 protected:
154 142 CPDF_Dictionary* m_pRootDict;
155 CPDF_Dictionary* m_pRootDict; 143
156 144 CPDF_Dictionary* m_pInfoDict;
157 CPDF_Dictionary* m_pInfoDict; 145
158 146 CFX_ByteString m_ID1;
159 CFX_ByteString m_ID1; 147
160 148 CFX_ByteString m_ID2;
161 CFX_ByteString m_ID2; 149
162 150 FX_BOOL m_bLinearized;
163 151
164 FX_BOOL m_bLinearized; 152 FX_DWORD m_dwFirstPageNo;
165 153
166 FX_DWORD m_dwFirstPageNo; 154 FX_DWORD m_dwFirstPageObjNum;
167 155
168 FX_DWORD m_dwFirstPageObjNum; 156 CFX_DWordArray m_PageList;
169 157
170 CFX_DWordArray m_PageList; 158 int _GetPageCount() const;
171 159 CPDF_Dictionary* _FindPDFPage(CPDF_Dictionary* pPages,
172 int _GetPageCount() const; 160 int iPage,
173 CPDF_Dictionary* _FindPDFPage(CPDF_Dictionary* pPages, int iPage, int nPagesToGo, int level); 161 int nPagesToGo,
174 int _FindPageIndex(CPDF_Dictionary* pNode, FX_DWORD& skip_count, FX_DWORD objnum, int& index, int level = 0); 162 int level);
175 FX_BOOL IsContentUsedElsewhere(FX_DWORD objnum, CPDF_Dictionary* pPageDict); 163 int _FindPageIndex(CPDF_Dictionary* pNode,
176 FX_BOOL CheckOCGVisible(CPDF_Dictionary* pOCG, FX_BOOL bPrinting); 164 FX_DWORD& skip_count,
177 CPDF_DocPageData* GetValidatePageData(); 165 FX_DWORD objnum,
178 CPDF_DocRenderData* GetValidateRenderData(); 166 int& index,
179 friend class CPDF_Creator; 167 int level = 0);
180 friend class CPDF_Parser; 168 FX_BOOL IsContentUsedElsewhere(FX_DWORD objnum, CPDF_Dictionary* pPageDict);
181 friend class CPDF_DataAvail; 169 FX_BOOL CheckOCGVisible(CPDF_Dictionary* pOCG, FX_BOOL bPrinting);
182 friend class CPDF_OCContext; 170 CPDF_DocPageData* GetValidatePageData();
183 171 CPDF_DocRenderData* GetValidateRenderData();
184 172 friend class CPDF_Creator;
185 173 friend class CPDF_Parser;
186 CPDF_DocPageData* m_pDocPage; 174 friend class CPDF_DataAvail;
187 175 friend class CPDF_OCContext;
188 CPDF_DocRenderData* m_pDocRender; 176
189 177 CPDF_DocPageData* m_pDocPage;
190 }; 178
191 179 CPDF_DocRenderData* m_pDocRender;
192 #define PDFWORD_EOF 0 180 };
193 #define PDFWORD_NUMBER 1 181
194 #define PDFWORD_TEXT 2 182 #define PDFWORD_EOF 0
195 #define PDFWORD_DELIMITER 3 183 #define PDFWORD_NUMBER 1
196 #define PDFWORD_NAME 4 184 #define PDFWORD_TEXT 2
197 class CPDF_SimpleParser 185 #define PDFWORD_DELIMITER 3
198 { 186 #define PDFWORD_NAME 4
199 public: 187 class CPDF_SimpleParser {
200 188 public:
201 CPDF_SimpleParser(const uint8_t* pData, FX_DWORD dwSize); 189 CPDF_SimpleParser(const uint8_t* pData, FX_DWORD dwSize);
202 190
203 CPDF_SimpleParser(const CFX_ByteStringC& str); 191 CPDF_SimpleParser(const CFX_ByteStringC& str);
204 192
205 CFX_ByteStringC GetWord(); 193 CFX_ByteStringC GetWord();
206 194
207 FX_BOOL SearchToken(const CFX_ByteStringC& token ); 195 FX_BOOL SearchToken(const CFX_ByteStringC& token);
208 196
209 FX_BOOL SkipWord(const CFX_ByteStringC& token); 197 FX_BOOL SkipWord(const CFX_ByteStringC& token);
210 198
211 FX_BOOL FindTagPair(const CFX_ByteStringC& start _token, const CFX_ByteStringC& end_token, 199 FX_BOOL FindTagPair(const CFX_ByteStringC& start_token,
212 FX_DWORD& start_pos, FX_DWORD& end_pos); 200 const CFX_ByteStringC& end_token,
213 201 FX_DWORD& start_pos,
214 FX_BOOL FindTagParam(const CFX_ByteStringC& toke n, int nParams); 202 FX_DWORD& end_pos);
215 203
216 FX_DWORD GetPos() 204 FX_BOOL FindTagParam(const CFX_ByteStringC& token, int nParams);
217 { 205
218 return m_dwCurPos; 206 FX_DWORD GetPos() { return m_dwCurPos; }
219 } 207
220 208 void SetPos(FX_DWORD pos) {
221 void SetPos(FX_DWORD pos) 209 ASSERT(pos <= m_dwSize);
222 { 210 m_dwCurPos = pos;
223 ASSERT(pos <= m_dwSize); 211 }
224 m_dwCurPos = pos; 212
225 } 213 private:
226 private: 214 void ParseWord(const uint8_t*& pStart, FX_DWORD& dwSize, int& type);
227 215
228 void ParseWord(const uint8_t*& pStart, FX_DWO RD& dwSize, int& type); 216 const uint8_t* m_pData;
229 217
230 const uint8_t* m_pData; 218 FX_DWORD m_dwSize;
231 219
232 FX_DWORD m_dwSize; 220 FX_DWORD m_dwCurPos;
233 221 };
234 FX_DWORD m_dwCurPos; 222 class CPDF_SyntaxParser {
235 }; 223 public:
236 class CPDF_SyntaxParser 224 CPDF_SyntaxParser();
237 { 225 virtual ~CPDF_SyntaxParser();
238 public: 226
239 227 void InitParser(IFX_FileRead* pFileAccess, FX_DWORD HeaderOffset);
240 CPDF_SyntaxParser(); 228
241 virtual ~CPDF_SyntaxParser(); 229 FX_FILESIZE SavePos() { return m_Pos; }
242 230
243 void InitParser(IFX_FileRead* pFileAccess, FX _DWORD HeaderOffset); 231 void RestorePos(FX_FILESIZE pos) { m_Pos = pos; }
244 232
245 FX_FILESIZE SavePos() 233 CPDF_Object* GetObject(CPDF_IndirectObjects* pObjList,
246 { 234 FX_DWORD objnum,
247 return m_Pos; 235 FX_DWORD gennum,
248 } 236 struct PARSE_CONTEXT* pContext = NULL,
249 237 FX_BOOL bDecrypt = TRUE);
250 void RestorePos(FX_FILESIZE pos) 238
251 { 239 CPDF_Object* GetObjectByStrict(CPDF_IndirectObjects* pObjList,
252 m_Pos = pos; 240 FX_DWORD objnum,
253 } 241 FX_DWORD gennum,
254 242 struct PARSE_CONTEXT* pContext = NULL);
255 CPDF_Object* GetObject(CPDF_IndirectObjects* pObjList, FX_DWO RD objnum, FX_DWORD gennum, struct PARSE_CONTEXT* pContext = NULL, FX_BOOL bDecr ypt = TRUE); 243
256 244 int GetDirectNum();
257 245
258 CPDF_Object* GetObjectByStrict(CPDF_IndirectObjects* pObjList , FX_DWORD objnum, FX_DWORD gennum, struct PARSE_CONTEXT* pContext = NULL); 246 CFX_ByteString GetString(FX_DWORD objnum, FX_DWORD gennum);
259 247
260 int GetDirectNum(); 248 CFX_ByteString GetName();
261 249
262 CFX_ByteString GetString(FX_DWORD objnum, FX_DWORD gennum); 250 CFX_ByteString GetKeyword();
263 251
264 CFX_ByteString GetName(); 252 void GetBinary(uint8_t* buffer, FX_DWORD size);
265 253
266 CFX_ByteString GetKeyword(); 254 void ToNextLine();
267 255
268 void GetBinary(uint8_t* buffer, FX_DWORD size ); 256 void ToNextWord();
269 257
270 void ToNextLine(); 258 FX_BOOL SearchWord(const CFX_ByteStringC& word,
271 259 FX_BOOL bWholeWord,
272 void ToNextWord(); 260 FX_BOOL bForward,
273 261 FX_FILESIZE limit);
274 FX_BOOL SearchWord(const CFX_ByteStringC& word, FX_BOOL bWholeWord, FX_BOOL bForward, FX_FILESIZE limit); 262
275 263 int SearchMultiWord(const CFX_ByteStringC& words,
276 int SearchMultiWord(const CFX_ByteStringC& w ords, FX_BOOL bWholeWord, FX_FILESIZE limit); 264 FX_BOOL bWholeWord,
277 265 FX_FILESIZE limit);
278 FX_FILESIZE FindTag(const CFX_ByteStringC& tag, FX_FILESIZE limit); 266
279 267 FX_FILESIZE FindTag(const CFX_ByteStringC& tag, FX_FILESIZE limit);
280 void SetEncrypt(CPDF_CryptoHandler* pCryptoHa ndler) 268
281 { 269 void SetEncrypt(CPDF_CryptoHandler* pCryptoHandler) {
282 m_pCryptoHandler = pCryptoHandler; 270 m_pCryptoHandler = pCryptoHandler;
283 } 271 }
284 272
285 FX_BOOL IsEncrypted() 273 FX_BOOL IsEncrypted() { return m_pCryptoHandler != NULL; }
286 { 274
287 return m_pCryptoHandler != NULL; 275 FX_BOOL GetCharAt(FX_FILESIZE pos, uint8_t& ch);
288 } 276
289 277 FX_BOOL ReadBlock(uint8_t* pBuf, FX_DWORD size);
290 FX_BOOL GetCharAt(FX_FILESIZE pos, uint8_t& ch); 278
291 279 CFX_ByteString GetNextWord(FX_BOOL& bIsNumber);
292 FX_BOOL ReadBlock(uint8_t* pBuf, FX_DWORD size); 280
293 281 protected:
294 CFX_ByteString GetNextWord(FX_BOOL& bIsNumber); 282 static const int kParserMaxRecursionDepth = 64;
295 protected: 283 static int s_CurrentRecursionDepth;
296 static const int kParserMaxRecursionDepth = 64; 284
297 static int s_CurrentRecursionDepth; 285 virtual FX_BOOL GetNextChar(uint8_t& ch);
298 286
299 virtual FX_BOOL GetNextChar(uint8_t& ch); 287 FX_BOOL GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch);
300 288
301 FX_BOOL GetCharAtBackward(FX_FILESIZE pos, uint8 _t& ch); 289 void GetNextWord();
302 290
303 void GetNextWord(); 291 FX_BOOL IsWholeWord(FX_FILESIZE startpos,
304 292 FX_FILESIZE limit,
305 FX_BOOL IsWholeWord(FX_FILESIZE startpos, FX_FIL ESIZE limit, const uint8_t* tag, FX_DWORD taglen); 293 const uint8_t* tag,
306 294 FX_DWORD taglen);
307 CFX_ByteString ReadString(); 295
308 296 CFX_ByteString ReadString();
309 CFX_ByteString ReadHexString(); 297
310 298 CFX_ByteString ReadHexString();
311 CPDF_Stream* ReadStream(CPDF_Dictionary* pDict, PARSE_CONTEXT * pContext, FX_DWORD objnum, FX_DWORD gennum); 299
312 300 CPDF_Stream* ReadStream(CPDF_Dictionary* pDict,
313 FX_FILESIZE m_Pos; 301 PARSE_CONTEXT* pContext,
314 302 FX_DWORD objnum,
315 FX_BOOL m_bFileStream; 303 FX_DWORD gennum);
316 304
317 int m_MetadataObjnum; 305 FX_FILESIZE m_Pos;
318 306
319 IFX_FileRead* m_pFileAccess; 307 FX_BOOL m_bFileStream;
320 308
321 FX_DWORD m_HeaderOffset; 309 int m_MetadataObjnum;
322 310
323 FX_FILESIZE m_FileLen; 311 IFX_FileRead* m_pFileAccess;
324 312
325 uint8_t* m_pFileBuf; 313 FX_DWORD m_HeaderOffset;
326 314
327 FX_DWORD m_BufSize; 315 FX_FILESIZE m_FileLen;
328 316
329 FX_FILESIZE m_BufOffset; 317 uint8_t* m_pFileBuf;
330 318
331 CPDF_CryptoHandler* m_pCryptoHandler; 319 FX_DWORD m_BufSize;
332 320
333 uint8_t m_WordBuffer[257]; 321 FX_FILESIZE m_BufOffset;
334 322
335 FX_DWORD m_WordSize; 323 CPDF_CryptoHandler* m_pCryptoHandler;
336 324
337 FX_BOOL m_bIsNumber; 325 uint8_t m_WordBuffer[257];
338 326
339 FX_FILESIZE m_dwWordPos; 327 FX_DWORD m_WordSize;
340 friend class CPDF_Parser; 328
341 friend class CPDF_DataAvail; 329 FX_BOOL m_bIsNumber;
342 }; 330
343 331 FX_FILESIZE m_dwWordPos;
344 #define PDFPARSE_TYPEONLY 1 332 friend class CPDF_Parser;
345 #define PDFPARSE_NOSTREAM 2 333 friend class CPDF_DataAvail;
334 };
335
336 #define PDFPARSE_TYPEONLY 1
337 #define PDFPARSE_NOSTREAM 2
346 struct PARSE_CONTEXT { 338 struct PARSE_CONTEXT {
347 uint32_t m_Flags; 339 uint32_t m_Flags;
348 FX_FILESIZE m_DictStart; 340 FX_FILESIZE m_DictStart;
349 FX_FILESIZE m_DictEnd; 341 FX_FILESIZE m_DictEnd;
350 FX_FILESIZE m_DataStart; 342 FX_FILESIZE m_DataStart;
351 FX_FILESIZE m_DataEnd; 343 FX_FILESIZE m_DataEnd;
352 }; 344 };
353 345
354 #define PDFPARSE_ERROR_SUCCESS 0 346 #define PDFPARSE_ERROR_SUCCESS 0
355 #define PDFPARSE_ERROR_FILE 1 347 #define PDFPARSE_ERROR_FILE 1
356 #define PDFPARSE_ERROR_FORMAT 2 348 #define PDFPARSE_ERROR_FORMAT 2
357 #define PDFPARSE_ERROR_PASSWORD 3 349 #define PDFPARSE_ERROR_PASSWORD 3
358 #define PDFPARSE_ERROR_HANDLER 4 350 #define PDFPARSE_ERROR_HANDLER 4
359 #define PDFPARSE_ERROR_CERT 5 351 #define PDFPARSE_ERROR_CERT 5
360 352
361 class CPDF_Parser 353 class CPDF_Parser {
362 { 354 public:
363 public: 355 CPDF_Parser();
364 CPDF_Parser(); 356 ~CPDF_Parser();
365 ~CPDF_Parser(); 357
366 358 FX_DWORD StartParse(const FX_CHAR* filename, FX_BOOL bReParse = FALSE);
367 FX_DWORD StartParse(const FX_CHAR* filename, FX_BOOL bReP arse = FALSE); 359 FX_DWORD StartParse(const FX_WCHAR* filename, FX_BOOL bReParse = FALSE);
368 FX_DWORD StartParse(const FX_WCHAR* filename, FX_BOOL bRe Parse = FALSE); 360 FX_DWORD StartParse(IFX_FileRead* pFile,
369 FX_DWORD StartParse(IFX_FileRead* pFile, FX_BOOL bReParse = FALSE, FX_BOOL bOwnFileRead = TRUE); 361 FX_BOOL bReParse = FALSE,
370 362 FX_BOOL bOwnFileRead = TRUE);
371 void CloseParser(FX_BOOL bReParse = FALSE); 363
372 364 void CloseParser(FX_BOOL bReParse = FALSE);
373 FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE); 365
374 366 FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE);
375 FX_BOOL IsOwner(); 367
376 368 FX_BOOL IsOwner();
377 void SetPassword(const FX_CHAR* password) 369
378 { 370 void SetPassword(const FX_CHAR* password) { m_Password = password; }
379 m_Password = password; 371
380 } 372 CFX_ByteString GetPassword() { return m_Password; }
381 373
382 CFX_ByteString GetPassword() 374 CPDF_SecurityHandler* GetSecurityHandler() { return m_pSecurityHandler; }
383 { 375
384 return m_Password; 376 CPDF_CryptoHandler* GetCryptoHandler() { return m_Syntax.m_pCryptoHandler; }
385 } 377
386 378 void SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler,
387 CPDF_SecurityHandler* GetSecurityHandler() 379 FX_BOOL bForced = FALSE);
388 { 380
389 return m_pSecurityHandler; 381 CFX_ByteString GetRecipient() { return m_bsRecipient; }
390 } 382
391 383 CPDF_Dictionary* GetTrailer() { return m_pTrailer; }
392 CPDF_CryptoHandler* GetCryptoHandler() 384
393 { 385 FX_FILESIZE GetLastXRefOffset() { return m_LastXRefOffset; }
394 return m_Syntax.m_pCryptoHandler; 386
395 } 387 CPDF_Document* GetDocument() { return m_pDocument; }
396 388
397 void SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, FX_BOOL bForced = FALSE); 389 CFX_ArrayTemplate<CPDF_Dictionary*>* GetOtherTrailers() {
398 390 return &m_Trailers;
399 CFX_ByteString GetRecipient() 391 }
400 { 392
401 return m_bsRecipient; 393 FX_DWORD GetRootObjNum();
402 } 394 FX_DWORD GetInfoObjNum();
403 395 CPDF_Array* GetIDArray();
404 CPDF_Dictionary* GetTrailer() 396
405 { 397 CPDF_Dictionary* GetEncryptDict() { return m_pEncryptDict; }
406 return m_pTrailer; 398
407 } 399 FX_BOOL IsEncrypted() { return GetEncryptDict() != NULL; }
408 400
409 FX_FILESIZE GetLastXRefOffset() 401 CPDF_Object* ParseIndirectObject(CPDF_IndirectObjects* pObjList,
410 { 402 FX_DWORD objnum,
411 return m_LastXRefOffset; 403 PARSE_CONTEXT* pContext = NULL);
412 } 404 FX_DWORD GetLastObjNum();
413 405 FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm);
414 CPDF_Document* GetDocument() 406
415 { 407 FX_FILESIZE GetObjectOffset(FX_DWORD objnum);
416 return m_pDocument; 408
417 } 409 FX_FILESIZE GetObjectSize(FX_DWORD objnum);
418 410
419 CFX_ArrayTemplate<CPDF_Dictionary*>* GetOtherTrailers() 411 int GetObjectVersion(FX_DWORD objnum) { return m_ObjVersion[objnum]; }
420 { 412
421 return &m_Trailers; 413 void GetIndirectBinary(FX_DWORD objnum, uint8_t*& pBuffer, FX_DWORD& size);
422 } 414
423 415 FX_BOOL GetFileStreamOption() { return m_Syntax.m_bFileStream; }
424 FX_DWORD GetRootObjNum(); 416
425 FX_DWORD GetInfoObjNum() ; 417 void SetFileStreamOption(FX_BOOL b) { m_Syntax.m_bFileStream = b; }
426 CPDF_Array* GetIDArray() ; 418
427 419 IFX_FileRead* GetFileAccess() const { return m_Syntax.m_pFileAccess; }
428 CPDF_Dictionary* GetEncryptDict() 420
429 { 421 int GetFileVersion() const { return m_FileVersion; }
430 return m_pEncryptDict; 422
431 } 423 FX_BOOL IsXRefStream() const { return m_bXRefStream; }
432 424 CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList,
433 FX_BOOL IsEncrypted() 425 FX_FILESIZE pos,
434 { 426 FX_DWORD objnum,
435 return GetEncryptDict() != NULL; 427 struct PARSE_CONTEXT* pContext);
436 } 428
437 429 CPDF_Object* ParseIndirectObjectAtByStrict(CPDF_IndirectObjects* pObjList,
438 430 FX_FILESIZE pos,
439 CPDF_Object* ParseIndirectObject(CPDF_IndirectObjects* pObjLi st, FX_DWORD objnum, PARSE_CONTEXT* pContext = NULL) ; 431 FX_DWORD objnum,
440 FX_DWORD GetLastObjNum(); 432 struct PARSE_CONTEXT* pContext,
441 FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& b Form); 433 FX_FILESIZE* pResultPos);
442 434
443 FX_FILESIZE GetObjectOffset(FX_DWORD objnum); 435 FX_DWORD StartAsynParse(IFX_FileRead* pFile,
444 436 FX_BOOL bReParse = FALSE,
445 FX_FILESIZE GetObjectSize(FX_DWORD objnum); 437 FX_BOOL bOwnFileRead = TRUE);
446 438
447 int GetObjectVersion(FX_DWORD objnum) 439 FX_DWORD GetFirstPageNo() { return m_dwFirstPageNo; }
448 { 440
449 return m_ObjVersion[objnum]; 441 protected:
450 } 442 CPDF_Document* m_pDocument;
451 443
452 void GetIndirectBinary(FX_DWORD objnum, uint8 _t*& pBuffer, FX_DWORD& size); 444 CPDF_SyntaxParser m_Syntax;
453 445 FX_BOOL m_bOwnFileRead;
454 FX_BOOL GetFileStreamOption() 446 CPDF_Object* ParseDirect(CPDF_Object* pObj);
455 { 447
456 return m_Syntax.m_bFileStream; 448 FX_BOOL LoadAllCrossRefV4(FX_FILESIZE pos);
457 } 449
458 450 FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos);
459 void SetFileStreamOption(FX_BOOL b) 451
460 { 452 FX_BOOL LoadCrossRefV4(FX_FILESIZE pos,
461 m_Syntax.m_bFileStream = b; 453 FX_FILESIZE streampos,
462 } 454 FX_BOOL bSkip,
463 455 FX_BOOL bFirst);
464 IFX_FileRead* GetFileAccess() const 456
465 { 457 FX_BOOL LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL bMainXRef);
466 return m_Syntax.m_pFileAccess; 458
467 } 459 CPDF_Dictionary* LoadTrailerV4();
468 460
469 int GetFileVersion() const 461 FX_BOOL RebuildCrossRef();
470 { 462
471 return m_FileVersion; 463 FX_DWORD SetEncryptHandler();
472 } 464
473 465 void ReleaseEncryptHandler();
474 FX_BOOL IsXRefStream() const 466
475 { 467 FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);
476 return m_bXRefStream; 468
477 } 469 FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);
478 CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjects* pObj List, FX_FILESIZE pos, FX_DWORD objnum, 470
479 struct PARSE_CONTEXT* pContext); 471 FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos);
480 472
481 CPDF_Object* ParseIndirectObjectAtByStrict(CPDF_IndirectObjec ts* pObjList, FX_FILESIZE pos, FX_DWORD objnum, 473 FX_DWORD LoadLinearizedMainXRefTable();
482 struct PARSE_CONTEXT* pContext, FX_FILESIZE *pResultPos); 474
483 475 CFX_MapPtrToPtr m_ObjectStreamMap;
484 FX_DWORD StartAsynParse(IFX_FileRead* pFile, FX_BOOL bReP arse = FALSE, FX_BOOL bOwnFileRead = TRUE); 476
485 477 CPDF_StreamAcc* GetObjectStream(FX_DWORD number);
486 FX_DWORD GetFirstPageNo() 478
487 { 479 FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset);
488 return m_dwFirstPageNo; 480
489 } 481 int m_FileVersion;
490 protected: 482
491 CPDF_Document* m_pDocument; 483 CPDF_Dictionary* m_pTrailer;
492 484
493 CPDF_SyntaxParser m_Syntax; 485 CPDF_Dictionary* m_pEncryptDict;
494 FX_BOOL m_bOwnFileRead; 486 void SetEncryptDictionary(CPDF_Dictionary* pDict);
495 CPDF_Object* ParseDirect(CPDF_Object* pObj); 487
496 488 FX_FILESIZE m_LastXRefOffset;
497 FX_BOOL LoadAllCrossRefV4(FX_FILESIZE pos); 489
498 490 FX_BOOL m_bXRefStream;
499 FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos); 491
500 492 CPDF_SecurityHandler* m_pSecurityHandler;
501 FX_BOOL LoadCrossRefV4(FX_FILESIZE pos, FX_FILES IZE streampos, FX_BOOL bSkip, FX_BOOL bFirst); 493
502 494 FX_BOOL m_bForceUseSecurityHandler;
503 FX_BOOL LoadCrossRefV5(FX_FILESIZE pos, FX_FILES IZE& prev, FX_BOOL bMainXRef); 495
504 496 CFX_ByteString m_bsRecipient;
505 CPDF_Dictionary* LoadTrailerV4(); 497
506 498 CFX_ByteString m_FilePath;
507 FX_BOOL RebuildCrossRef(); 499
508 500 CFX_ByteString m_Password;
509 FX_DWORD SetEncryptHandler(); 501
510 502 CFX_FileSizeArray m_CrossRef;
511 void ReleaseEncryptHandler(); 503
512 504 CFX_ByteArray m_V5Type;
513 FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); 505
514 506 CFX_FileSizeArray m_SortedOffset;
515 FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos , FX_DWORD dwObjCount); 507
516 508 CFX_WordArray m_ObjVersion;
517 FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); 509 CFX_ArrayTemplate<CPDF_Dictionary*> m_Trailers;
518 510
519 FX_DWORD LoadLinearizedMainXRefTable(); 511 FX_BOOL m_bVersionUpdated;
520 512
521 CFX_MapPtrToPtr m_ObjectStreamMap; 513 CPDF_Object* m_pLinearized;
522 514
523 CPDF_StreamAcc* GetObjectStream(FX_DWORD number); 515 FX_DWORD m_dwFirstPageNo;
524 516
525 FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAcce ss, FX_DWORD offset); 517 FX_DWORD m_dwXrefStartObjNum;
526 518 friend class CPDF_Creator;
527 519 friend class CPDF_DataAvail;
528 520 };
529 int m_FileVersion; 521 #define FXCIPHER_NONE 0
530 522 #define FXCIPHER_RC4 1
531 CPDF_Dictionary* m_pTrailer; 523 #define FXCIPHER_AES 2
532 524 #define FXCIPHER_AES2 3
533 CPDF_Dictionary* m_pEncryptDict; 525 class CPDF_SecurityHandler {
534 void SetEncryptDictionary(CPDF_Dictionary* pDict); 526 public:
535 527 virtual ~CPDF_SecurityHandler() {}
536 FX_FILESIZE m_LastXRefOffset; 528
537 529 virtual FX_BOOL OnInit(CPDF_Parser* pParser,
538 FX_BOOL m_bXRefStream; 530 CPDF_Dictionary* pEncryptDict) = 0;
539 531
540 532 virtual FX_DWORD GetPermissions() = 0;
541 CPDF_SecurityHandler* m_pSecurityHandler; 533
542 534 virtual FX_BOOL IsOwner() = 0;
543 FX_BOOL m_bForceUseSecurityHandler; 535
544 536 virtual FX_BOOL GetCryptInfo(int& cipher,
545 CFX_ByteString m_bsRecipient; 537 const uint8_t*& buffer,
546 538 int& keylen) = 0;
547 CFX_ByteString m_FilePath; 539
548 540 virtual FX_BOOL IsMetadataEncrypted() { return TRUE; }
549 CFX_ByteString m_Password; 541
550 542 virtual CPDF_CryptoHandler* CreateCryptoHandler() = 0;
551 CFX_FileSizeArray m_CrossRef; 543
552 544 virtual CPDF_StandardSecurityHandler* GetStandardHandler() { return NULL; }
553 CFX_ByteArray m_V5Type; 545 };
554 546 #define PDF_ENCRYPT_CONTENT 0
555 CFX_FileSizeArray m_SortedOffset; 547 class CPDF_StandardSecurityHandler : public CPDF_SecurityHandler {
556 548 public:
557 CFX_WordArray m_ObjVersion; 549 CPDF_StandardSecurityHandler();
558 CFX_ArrayTemplate<CPDF_Dictionary *> m_Trailers; 550
559 551 virtual ~CPDF_StandardSecurityHandler();
560 FX_BOOL m_bVersionUpdated; 552 virtual FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict);
561 553 virtual FX_DWORD GetPermissions();
562 CPDF_Object* m_pLinearized; 554 virtual FX_BOOL IsOwner() { return m_bOwner; }
563 555 virtual FX_BOOL GetCryptInfo(int& cipher,
564 FX_DWORD m_dwFirstPageNo; 556 const uint8_t*& buffer,
565 557 int& keylen);
566 FX_DWORD m_dwXrefStartObjNum; 558 virtual FX_BOOL IsMetadataEncrypted();
567 friend class CPDF_Creator; 559 virtual CPDF_CryptoHandler* CreateCryptoHandler();
568 friend class CPDF_DataAvail; 560 virtual CPDF_StandardSecurityHandler* GetStandardHandler() { return this; }
569 }; 561
570 #define FXCIPHER_NONE 0 562 void OnCreate(CPDF_Dictionary* pEncryptDict,
571 #define FXCIPHER_RC4 1 563 CPDF_Array* pIdArray,
572 #define FXCIPHER_AES 2 564 const uint8_t* user_pass,
573 #define FXCIPHER_AES2 3 565 FX_DWORD user_size,
574 class CPDF_SecurityHandler 566 const uint8_t* owner_pass,
575 { 567 FX_DWORD owner_size,
576 public: 568 FX_DWORD type = PDF_ENCRYPT_CONTENT);
577 569
578 virtual ~CPDF_SecurityHandler() {} 570 void OnCreate(CPDF_Dictionary* pEncryptDict,
579 571 CPDF_Array* pIdArray,
580 virtual FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pE ncryptDict) = 0; 572 const uint8_t* user_pass,
581 573 FX_DWORD user_size,
582 virtual FX_DWORD GetPermissions() = 0; 574 FX_DWORD type = PDF_ENCRYPT_CONTENT);
583 575
584 virtual FX_BOOL IsOwner() = 0; 576 CFX_ByteString GetUserPassword(const uint8_t* owner_pass, FX_DWORD pass_size);
585 577 CFX_ByteString GetUserPassword(const uint8_t* owner_pass,
586 virtual FX_BOOL GetCryptInfo(int& cipher, const uint8_t*& buffer , int& keylen) = 0; 578 FX_DWORD pass_size,
587 579 int32_t key_len);
588 virtual FX_BOOL IsMetadataEncrypted() 580 int GetVersion() { return m_Version; }
589 { 581 int GetRevision() { return m_Revision; }
590 return TRUE; 582
591 } 583 int CheckPassword(const uint8_t* password,
592 584 FX_DWORD pass_size,
593 virtual CPDF_CryptoHandler* CreateCryptoHandler() = 0; 585 FX_BOOL bOwner,
594 586 uint8_t* key);
595 virtual CPDF_StandardSecurityHandler* GetStandardHandler() 587 int CheckPassword(const uint8_t* password,
596 { 588 FX_DWORD pass_size,
597 return NULL; 589 FX_BOOL bOwner,
598 } 590 uint8_t* key,
599 }; 591 int key_len);
600 #define PDF_ENCRYPT_CONTENT 0 592
601 class CPDF_StandardSecurityHandler : public CPDF_SecurityHandler 593 private:
602 { 594 int m_Version;
603 public: 595
604 CPDF_StandardSecurityHandler(); 596 int m_Revision;
605 597
606 virtual ~CPDF_StandardSecurityHandler(); 598 CPDF_Parser* m_pParser;
607 virtual FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pE ncryptDict); 599
608 virtual FX_DWORD GetPermissions(); 600 CPDF_Dictionary* m_pEncryptDict;
609 virtual FX_BOOL IsOwner() 601
610 { 602 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict);
611 return m_bOwner; 603 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict,
612 } 604 FX_DWORD type,
613 virtual FX_BOOL GetCryptInfo(int& cipher, const uint8_t*& buffer , int& keylen); 605 int& cipher,
614 virtual FX_BOOL IsMetadataEncrypted(); 606 int& key_len);
615 virtual CPDF_CryptoHandler* CreateCryptoHandler(); 607
616 virtual CPDF_StandardSecurityHandler* GetStandardHandler() 608 FX_BOOL CheckUserPassword(const uint8_t* password,
617 { 609 FX_DWORD pass_size,
618 return this; 610 FX_BOOL bIgnoreEncryptMeta,
619 } 611 uint8_t* key,
620 612 int32_t key_len);
621 void OnCreate(CPDF_Dictionary* pEncryptDict, CPDF_Array* pIdArray, 613
622 const uint8_t* user_pass, FX_DWORD user_size, 614 FX_BOOL CheckOwnerPassword(const uint8_t* password,
623 const uint8_t* owner_pass, FX_DWORD owner_size, FX_DWORD type = PDF_ENCRYPT_CONTENT); 615 FX_DWORD pass_size,
624 616 uint8_t* key,
625 void OnCreate(CPDF_Dictionary* pEncryptDict, CPDF_Array* pIdArray, 617 int32_t key_len);
626 const uint8_t* user_pass, FX_DWORD user_size, F X_DWORD type = PDF_ENCRYPT_CONTENT); 618 FX_BOOL AES256_CheckPassword(const uint8_t* password,
627 619 FX_DWORD size,
628 CFX_ByteString GetUserPassword(const uint8_t* owner_pass, FX_DW ORD pass_size); 620 FX_BOOL bOwner,
629 CFX_ByteString GetUserPassword(const uint8_t* owner_pass, FX_DW ORD pass_size, int32_t key_len); 621 uint8_t* key);
630 int GetVersion() 622 void AES256_SetPassword(CPDF_Dictionary* pEncryptDict,
631 { 623 const uint8_t* password,
632 return m_Version; 624 FX_DWORD size,
633 } 625 FX_BOOL bOwner,
634 int GetRevision() 626 const uint8_t* key);
635 { 627 void AES256_SetPerms(CPDF_Dictionary* pEncryptDict,
636 return m_Revision; 628 FX_DWORD permission,
637 } 629 FX_BOOL bEncryptMetadata,
638 630 const uint8_t* key);
639 int CheckPassword(const uint8_t* password, F X_DWORD pass_size, FX_BOOL bOwner, uint8_t* key); 631 void OnCreate(CPDF_Dictionary* pEncryptDict,
640 int CheckPassword(const uint8_t* password, F X_DWORD pass_size, FX_BOOL bOwner, uint8_t* key, int key_len); 632 CPDF_Array* pIdArray,
641 private: 633 const uint8_t* user_pass,
642 634 FX_DWORD user_size,
643 int m_Version; 635 const uint8_t* owner_pass,
644 636 FX_DWORD owner_size,
645 int m_Revision; 637 FX_BOOL bDefault,
646 638 FX_DWORD type);
647 CPDF_Parser* m_pParser; 639 FX_BOOL CheckSecurity(int32_t key_len);
648 640
649 CPDF_Dictionary* m_pEncryptDict; 641 FX_BOOL m_bOwner;
650 642
651 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict); 643 FX_DWORD m_Permissions;
652 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict, FX_DWORD type, int& cipher, int& key_len); 644
653 645 int m_Cipher;
654 FX_BOOL CheckUserPassword(const uint8_t* passwor d, FX_DWORD pass_size, 646
655 FX_BOOL bIgnoreEncryptMeta, uint8_t* k ey, int32_t key_len); 647 uint8_t m_EncryptKey[32];
656 648
657 FX_BOOL CheckOwnerPassword(const uint8_t* passwo rd, FX_DWORD pass_size, uint8_t* key, int32_t key_len); 649 int m_KeyLen;
658 FX_BOOL AES256_CheckPassword(const uint8_t* pass word, FX_DWORD size, FX_BOOL bOwner, uint8_t* key); 650 };
659 void AES256_SetPassword(CPDF_Dictionary* pEnc ryptDict, const uint8_t* password, FX_DWORD size, FX_BOOL bOwner, const uint8_t* key); 651 class CPDF_CryptoHandler {
660 void AES256_SetPerms(CPDF_Dictionary* pEncryp tDict, FX_DWORD permission, FX_BOOL bEncryptMetadata, const uint8_t* key); 652 public:
661 void OnCreate(CPDF_Dictionary* pEncryptDict, CPDF_Array* pIdArray, 653 virtual ~CPDF_CryptoHandler() {}
662 const uint8_t* user_pass, FX_DWORD user_size, 654
663 const uint8_t* owner_pass, FX_DWORD owner_size, FX_BOOL bDefault, FX_DWORD type); 655 virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict,
664 FX_BOOL CheckSecurity(int32_t key_len); 656 CPDF_SecurityHandler* pSecurityHandler) = 0;
665 657
666 FX_BOOL m_bOwner; 658 virtual FX_DWORD DecryptGetSize(FX_DWORD src_size) = 0;
667 659
668 FX_DWORD m_Permissions; 660 virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) = 0;
669 661
670 int m_Cipher; 662 virtual FX_BOOL DecryptStream(void* context,
671 663 const uint8_t* src_buf,
672 uint8_t m_EncryptKey[32]; 664 FX_DWORD src_size,
673 665 CFX_BinaryBuf& dest_buf) = 0;
674 int m_KeyLen; 666
675 }; 667 virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest_buf) = 0;
676 class CPDF_CryptoHandler 668
677 { 669 virtual FX_DWORD EncryptGetSize(FX_DWORD objnum,
678 public: 670 FX_DWORD version,
679 671 const uint8_t* src_buf,
680 virtual ~CPDF_CryptoHandler() {} 672 FX_DWORD src_size) = 0;
681 673
682 virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict, CPDF_Securit yHandler* pSecurityHandler) = 0; 674 virtual FX_BOOL EncryptContent(FX_DWORD objnum,
683 675 FX_DWORD version,
684 virtual FX_DWORD DecryptGetSize(FX_DWORD src_size) = 0; 676 const uint8_t* src_buf,
685 677 FX_DWORD src_size,
686 virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) = 0; 678 uint8_t* dest_buf,
687 679 FX_DWORD& dest_size) = 0;
688 virtual FX_BOOL DecryptStream(void* context, const uint8_t* src_ buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf) = 0; 680
689 681 void Decrypt(FX_DWORD objnum, FX_DWORD version, CFX_ByteString& str);
690 virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest _buf) = 0; 682 };
691 683 class CPDF_StandardCryptoHandler : public CPDF_CryptoHandler {
692 684 public:
693 virtual FX_DWORD EncryptGetSize(FX_DWORD objnum, FX_DWORD version, const uint8_t* src_buf, FX_DWORD src_size) = 0; 685 CPDF_StandardCryptoHandler();
694 686
695 virtual FX_BOOL EncryptContent(FX_DWORD objnum, FX_DWORD version , const uint8_t* src_buf, FX_DWORD src_size, 687 virtual ~CPDF_StandardCryptoHandler();
696 uint8_t* dest_buf, FX_DWORD& dest_size) = 0; 688
697 689 FX_BOOL Init(int cipher, const uint8_t* key, int keylen);
698 void Decrypt(FX_DWORD objnum, FX_DWORD versio n, CFX_ByteString& str); 690 virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict,
699 }; 691 CPDF_SecurityHandler* pSecurityHandler);
700 class CPDF_StandardCryptoHandler : public CPDF_CryptoHandler 692 virtual FX_DWORD DecryptGetSize(FX_DWORD src_size);
701 { 693 virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum);
702 public: 694 virtual FX_BOOL DecryptStream(void* context,
703 695 const uint8_t* src_buf,
704 CPDF_StandardCryptoHandler(); 696 FX_DWORD src_size,
705 697 CFX_BinaryBuf& dest_buf);
706 virtual ~CPDF_StandardCryptoHandler(); 698 virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest_buf);
707 699 virtual FX_DWORD EncryptGetSize(FX_DWORD objnum,
708 FX_BOOL Init(int cipher, const uint8_t* key, int keylen); 700 FX_DWORD version,
709 virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict, CPDF_Securit yHandler* pSecurityHandler); 701 const uint8_t* src_buf,
710 virtual FX_DWORD DecryptGetSize(FX_DWORD src_size); 702 FX_DWORD src_size);
711 virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum); 703 virtual FX_BOOL EncryptContent(FX_DWORD objnum,
712 virtual FX_BOOL DecryptStream(void* context, const uint8_t* src_ buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf); 704 FX_DWORD version,
713 virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest _buf); 705 const uint8_t* src_buf,
714 virtual FX_DWORD EncryptGetSize(FX_DWORD objnum, FX_DWORD version, const uint8_t* src_buf, FX_DWORD src_size); 706 FX_DWORD src_size,
715 virtual FX_BOOL EncryptContent(FX_DWORD objnum, FX_DWORD version , const uint8_t* src_buf, FX_DWORD src_size, 707 uint8_t* dest_buf,
716 uint8_t* dest_buf, FX_DWORD& dest_size); 708 FX_DWORD& dest_size);
717 protected: 709
718 710 protected:
719 virtual void CryptBlock(FX_BOOL bEncrypt, FX_DWORD objnum, FX _DWORD gennum, const uint8_t* src_buf, FX_DWORD src_size, 711 virtual void CryptBlock(FX_BOOL bEncrypt,
720 uint8_t* dest_buf, FX_DWORD& dest_size); 712 FX_DWORD objnum,
721 virtual void* CryptStart(FX_DWORD objnum, FX_DWORD gennum, FX_BOOL bEn crypt); 713 FX_DWORD gennum,
722 virtual FX_BOOL CryptStream(void* context, const uint8_t* src_bu f, FX_DWORD src_size, CFX_BinaryBuf& dest_buf, FX_BOOL bEncrypt); 714 const uint8_t* src_buf,
723 virtual FX_BOOL CryptFinish(void* context, CFX_BinaryBuf& dest_b uf, FX_BOOL bEncrypt); 715 FX_DWORD src_size,
724 716 uint8_t* dest_buf,
725 uint8_t m_EncryptKey[32]; 717 FX_DWORD& dest_size);
726 718 virtual void* CryptStart(FX_DWORD objnum, FX_DWORD gennum, FX_BOOL bEncrypt);
727 int m_KeyLen; 719 virtual FX_BOOL CryptStream(void* context,
728 720 const uint8_t* src_buf,
729 int m_Cipher; 721 FX_DWORD src_size,
730 722 CFX_BinaryBuf& dest_buf,
731 uint8_t* m_pAESContext; 723 FX_BOOL bEncrypt);
732 }; 724 virtual FX_BOOL CryptFinish(void* context,
733 class CPDF_Point 725 CFX_BinaryBuf& dest_buf,
734 { 726 FX_BOOL bEncrypt);
735 public: 727
736 728 uint8_t m_EncryptKey[32];
737 CPDF_Point(FX_FLOAT xx, FX_FLOAT yy) 729
738 { 730 int m_KeyLen;
739 x = xx; 731
740 y = yy; 732 int m_Cipher;
741 } 733
742 734 uint8_t* m_pAESContext;
743 FX_FLOAT x; 735 };
744 736 class CPDF_Point {
745 FX_FLOAT y; 737 public:
746 }; 738 CPDF_Point(FX_FLOAT xx, FX_FLOAT yy) {
747 739 x = xx;
748 #define CPDF_Rect CFX_FloatRect 740 y = yy;
749 #define CPDF_Matrix CFX_AffineMatrix 741 }
742
743 FX_FLOAT x;
744
745 FX_FLOAT y;
746 };
747
748 #define CPDF_Rect CFX_FloatRect
749 #define CPDF_Matrix CFX_AffineMatrix
750 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& orig); 750 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& orig);
751 CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig); 751 CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig);
752 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig); 752 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig);
753 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex = FALSE) ; 753 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src,
754 CFX_WideString PDF_DecodeText(const uint8_t* pData, FX_DWORD size, CFX_CharMap* pCharMap = NULL); 754 FX_BOOL bHex = FALSE);
755 inline CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr, CFX_CharMap* pC harMap = NULL) { 755 CFX_WideString PDF_DecodeText(const uint8_t* pData,
756 return PDF_DecodeText((const uint8_t*)bstr.c_str(), bstr.GetLength(), pCharM ap); 756 FX_DWORD size,
757 CFX_CharMap* pCharMap = NULL);
758 inline CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr,
759 CFX_CharMap* pCharMap = NULL) {
760 return PDF_DecodeText((const uint8_t*)bstr.c_str(), bstr.GetLength(),
761 pCharMap);
757 } 762 }
758 CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len = -1, CFX_CharMap * pCharMap = NULL); 763 CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString,
759 inline CFX_ByteString PDF_EncodeText(const CFX_WideString& str, CFX_CharMap* pCh arMap = NULL) { 764 int len = -1,
760 return PDF_EncodeText(str.c_str(), str.GetLength(), pCharMap); 765 CFX_CharMap* pCharMap = NULL);
766 inline CFX_ByteString PDF_EncodeText(const CFX_WideString& str,
767 CFX_CharMap* pCharMap = NULL) {
768 return PDF_EncodeText(str.c_str(), str.GetLength(), pCharMap);
761 } 769 }
762 FX_FLOAT PDF_ClipFloat(FX_FLOAT f); 770 FX_FLOAT PDF_ClipFloat(FX_FLOAT f);
763 class CFDF_Document : public CPDF_IndirectObjects 771 class CFDF_Document : public CPDF_IndirectObjects {
764 { 772 public:
765 public: 773 static CFDF_Document* CreateNewDoc();
766 static CFDF_Document* CreateNewDoc(); 774 static CFDF_Document* ParseFile(IFX_FileRead* pFile,
767 static CFDF_Document* ParseFile(IFX_FileRead *pFile, FX_BOOL bOwnFile = FALS E); 775 FX_BOOL bOwnFile = FALSE);
768 static CFDF_Document* ParseMemory(const uint8_t* pData, FX_DWORD size); 776 static CFDF_Document* ParseMemory(const uint8_t* pData, FX_DWORD size);
769 777
770 ~CFDF_Document(); 778 ~CFDF_Document();
771 779
772 FX_BOOL» » » » » WriteBuf(CFX_ByteTextBuf& buf) c onst; 780 FX_BOOL WriteBuf(CFX_ByteTextBuf& buf) const;
773 781
774 CPDF_Dictionary*» » GetRoot() const 782 CPDF_Dictionary* GetRoot() const { return m_pRootDict; }
775 { 783
776 return m_pRootDict; 784 CFX_WideString GetWin32Path() const;
777 } 785
778 786 protected:
779 CFX_WideString» » » GetWin32Path() const; 787 CFDF_Document();
780 protected: 788 void ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile);
781 789 CPDF_Dictionary* m_pRootDict;
782 CFDF_Document(); 790 IFX_FileRead* m_pFile;
783 void» ParseStream(IFX_FileRead *pFile, FX_BOOL bOwnFile); 791 FX_BOOL m_bOwnFile;
784 CPDF_Dictionary*» » m_pRootDict; 792 };
785 IFX_FileRead*» » » m_pFile; 793
786 FX_BOOL» » » » » m_bOwnFile; 794 CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec);
787 }; 795 void FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec,
788 796 const CFX_WideString& fullpath);
789 CFX_WideString» FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec); 797
790 void» » » FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec, const CFX_WideString& fullpath); 798 void FlateEncode(const uint8_t* src_buf,
791 799 FX_DWORD src_size,
792 void FlateEncode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, FX_DWORD& dest_size); 800 uint8_t*& dest_buf,
793 FX_DWORD FlateDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_b uf, FX_DWORD& dest_size); 801 FX_DWORD& dest_size);
794 FX_DWORD RunLengthDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& de st_buf, FX_DWORD& dest_size); 802 FX_DWORD FlateDecode(const uint8_t* src_buf,
795 class CPDF_NumberTree 803 FX_DWORD src_size,
796 { 804 uint8_t*& dest_buf,
797 public: 805 FX_DWORD& dest_size);
798 806 FX_DWORD RunLengthDecode(const uint8_t* src_buf,
799 CPDF_NumberTree(CPDF_Dictionary* pRoot) 807 FX_DWORD src_size,
800 { 808 uint8_t*& dest_buf,
801 m_pRoot = pRoot; 809 FX_DWORD& dest_size);
802 } 810 class CPDF_NumberTree {
803 811 public:
804 CPDF_Object*» » LookupValue(int num); 812 CPDF_NumberTree(CPDF_Dictionary* pRoot) { m_pRoot = pRoot; }
805 protected: 813
806 814 CPDF_Object* LookupValue(int num);
807 CPDF_Dictionary*» m_pRoot; 815
808 }; 816 protected:
809 817 CPDF_Dictionary* m_pRoot;
810 class IFX_FileAvail 818 };
811 { 819
812 public: 820 class IFX_FileAvail {
813 virtual ~IFX_FileAvail() { } 821 public:
814 virtual FX_BOOL» » » IsDataAvail( FX_FILESIZE offset, FX_DWOR D size) = 0; 822 virtual ~IFX_FileAvail() {}
815 }; 823 virtual FX_BOOL IsDataAvail(FX_FILESIZE offset, FX_DWORD size) = 0;
816 class IFX_DownloadHints 824 };
817 { 825 class IFX_DownloadHints {
818 public: 826 public:
819 virtual ~IFX_DownloadHints() { } 827 virtual ~IFX_DownloadHints() {}
820 virtual void» » » AddSegment(FX_FILESIZE offset, FX_DWORD size) = 0; 828 virtual void AddSegment(FX_FILESIZE offset, FX_DWORD size) = 0;
821 }; 829 };
822 #define PDF_IS_LINEARIZED» » » 1 830 #define PDF_IS_LINEARIZED 1
823 #define PDF_NOT_LINEARIZED» » » 0 831 #define PDF_NOT_LINEARIZED 0
824 #define PDF_UNKNOW_LINEARIZED» » -1 832 #define PDF_UNKNOW_LINEARIZED -1
825 #define PDFFORM_NOTAVAIL» » 0 833 #define PDFFORM_NOTAVAIL 0
826 #define PDFFORM_AVAIL» » » 1 834 #define PDFFORM_AVAIL 1
827 #define PDFFORM_NOTEXIST» » 2 835 #define PDFFORM_NOTEXIST 2
828 class IPDF_DataAvail 836 class IPDF_DataAvail {
829 { 837 public:
830 public: 838 static IPDF_DataAvail* Create(IFX_FileAvail* pFileAvail,
831 static IPDF_DataAvail* Create(IFX_FileAvail* pFileAvail, IFX_FileRead* pFile Read); 839 IFX_FileRead* pFileRead);
832 virtual ~IPDF_DataAvail() { } 840 virtual ~IPDF_DataAvail() {}
833 841
834 IFX_FileAvail* GetFileAvail() const { return m_pFileAvail; } 842 IFX_FileAvail* GetFileAvail() const { return m_pFileAvail; }
835 IFX_FileRead* GetFileRead() const { return m_pFileRead; } 843 IFX_FileRead* GetFileRead() const { return m_pFileRead; }
836 844
837 virtual FX_BOOL» » » IsDocAvail(IFX_DownloadHints* pHints) = 0; 845 virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) = 0;
838 virtual void» » » SetDocument(CPDF_Document* pDoc) = 0; 846 virtual void SetDocument(CPDF_Document* pDoc) = 0;
839 virtual FX_BOOL» » » IsPageAvail(int iPage, IFX_DownloadHints * pHints) = 0; 847 virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) = 0;
840 virtual FX_BOOL» » » IsLinearized() = 0; 848 virtual FX_BOOL IsLinearized() = 0;
841 virtual int32_t» » IsFormAvail(IFX_DownloadHints *pHints) = 0; 849 virtual int32_t IsFormAvail(IFX_DownloadHints* pHints) = 0;
842 virtual int32_t» » IsLinearizedPDF() = 0; 850 virtual int32_t IsLinearizedPDF() = 0;
843 virtual void» » » » GetLinearizedMainXRefInfo(FX_FIL ESIZE *pPos, FX_DWORD *pSize) = 0; 851 virtual void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos,
844 852 FX_DWORD* pSize) = 0;
845 protected: 853
846 IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); 854 protected:
847 855 IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead);
848 IFX_FileAvail* m_pFileAvail; 856
849 IFX_FileRead* m_pFileRead; 857 IFX_FileAvail* m_pFileAvail;
850 }; 858 IFX_FileRead* m_pFileRead;
851 class CPDF_SortObjNumArray 859 };
852 { 860 class CPDF_SortObjNumArray {
853 public: 861 public:
854 862 void AddObjNum(FX_DWORD dwObjNum);
855 void AddObjNum(FX_DWORD dwObjNum); 863
856 864 FX_BOOL Find(FX_DWORD dwObjNum);
857 FX_BOOL Find(FX_DWORD dwObjNum); 865
858 866 void RemoveAll() { m_number_array.RemoveAll(); }
859 void RemoveAll() 867
860 { 868 protected:
861 m_number_array.RemoveAll(); 869 FX_BOOL BinarySearch(FX_DWORD value, int& iNext);
862 } 870
863 protected: 871 protected:
864 872 CFX_DWordArray m_number_array;
865 FX_BOOL BinarySearch(FX_DWORD value, int &iNext);
866 protected:
867
868 CFX_DWordArray» » » m_number_array;
869 }; 873 };
870 enum PDF_PAGENODE_TYPE { 874 enum PDF_PAGENODE_TYPE {
871 PDF_PAGENODE_UNKOWN = 0, 875 PDF_PAGENODE_UNKOWN = 0,
872 PDF_PAGENODE_PAGE, 876 PDF_PAGENODE_PAGE,
873 PDF_PAGENODE_PAGES, 877 PDF_PAGENODE_PAGES,
874 PDF_PAGENODE_ARRAY, 878 PDF_PAGENODE_ARRAY,
875 }; 879 };
876 class CPDF_PageNode 880 class CPDF_PageNode {
877 { 881 public:
878 public: 882 CPDF_PageNode() : m_type(PDF_PAGENODE_UNKOWN) {}
879 CPDF_PageNode() : m_type(PDF_PAGENODE_UNKOWN) {} 883 ~CPDF_PageNode();
880 ~CPDF_PageNode(); 884 PDF_PAGENODE_TYPE m_type;
881 PDF_PAGENODE_TYPE» m_type; 885 FX_DWORD m_dwPageNo;
882 FX_DWORD» » » m_dwPageNo; 886 CFX_PtrArray m_childNode;
883 CFX_PtrArray» » m_childNode;
884 }; 887 };
885 enum PDF_DATAAVAIL_STATUS { 888 enum PDF_DATAAVAIL_STATUS {
886 PDF_DATAAVAIL_HEADER = 0, 889 PDF_DATAAVAIL_HEADER = 0,
887 PDF_DATAAVAIL_FIRSTPAGE, 890 PDF_DATAAVAIL_FIRSTPAGE,
888 PDF_DATAAVAIL_FIRSTPAGE_PREPARE, 891 PDF_DATAAVAIL_FIRSTPAGE_PREPARE,
889 PDF_DATAAVAIL_END, 892 PDF_DATAAVAIL_END,
890 PDF_DATAAVAIL_CROSSREF, 893 PDF_DATAAVAIL_CROSSREF,
891 PDF_DATAAVAIL_CROSSREF_ITEM, 894 PDF_DATAAVAIL_CROSSREF_ITEM,
892 PDF_DATAAVAIL_CROSSREF_STREAM, 895 PDF_DATAAVAIL_CROSSREF_STREAM,
893 PDF_DATAAVAIL_TRAILER, 896 PDF_DATAAVAIL_TRAILER,
894 PDF_DATAAVAIL_LOADALLCRSOSSREF, 897 PDF_DATAAVAIL_LOADALLCRSOSSREF,
895 PDF_DATAAVAIL_ROOT, 898 PDF_DATAAVAIL_ROOT,
896 PDF_DATAAVAIL_INFO, 899 PDF_DATAAVAIL_INFO,
897 PDF_DATAAVAIL_ACROFORM, 900 PDF_DATAAVAIL_ACROFORM,
898 PDF_DATAAVAIL_ACROFORM_SUBOBJECT, 901 PDF_DATAAVAIL_ACROFORM_SUBOBJECT,
899 PDF_DATAAVAIL_PAGETREE, 902 PDF_DATAAVAIL_PAGETREE,
900 PDF_DATAAVAIL_PAGE, 903 PDF_DATAAVAIL_PAGE,
901 PDF_DATAAVAIL_PAGE_LATERLOAD, 904 PDF_DATAAVAIL_PAGE_LATERLOAD,
902 PDF_DATAAVAIL_RESOURCES, 905 PDF_DATAAVAIL_RESOURCES,
903 PDF_DATAAVAIL_DONE, 906 PDF_DATAAVAIL_DONE,
904 PDF_DATAAVAIL_ERROR, 907 PDF_DATAAVAIL_ERROR,
905 PDF_DATAAVAIL_LOADALLFILE, 908 PDF_DATAAVAIL_LOADALLFILE,
906 PDF_DATAAVAIL_TRAILER_APPEND 909 PDF_DATAAVAIL_TRAILER_APPEND
907 }; 910 };
908 911
909 #endif // CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ 912 #endif // CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698