OLD | NEW |
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 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "../../../include/fpdfapi/fpdf_module.h" | 10 #include "../../../include/fpdfapi/fpdf_module.h" |
11 #include "../../../include/fpdfapi/fpdf_page.h" | 11 #include "../../../include/fpdfapi/fpdf_page.h" |
12 #include "../../../include/fpdfapi/fpdf_parser.h" | 12 #include "../../../include/fpdfapi/fpdf_parser.h" |
13 #include "../../../include/fxcrt/fx_safe_types.h" | 13 #include "../../../include/fxcrt/fx_safe_types.h" |
14 #include "../fpdf_page/pageint.h" | 14 #include "../fpdf_page/pageint.h" |
15 | 15 |
16 FX_BOOL IsSignatureDict(const CPDF_Dictionary* pDict) | 16 bool IsSignatureDict(const CPDF_Dictionary* pDict) |
17 { | 17 { |
18 CPDF_Object* pType = pDict->GetElementValue(FX_BSTRC("Type")); | 18 CPDF_Object* pType = pDict->GetElementValue(FX_BSTRC("Type")); |
19 if (!pType) { | 19 if (!pType) { |
20 pType = pDict->GetElementValue(FX_BSTRC("FT")); | 20 pType = pDict->GetElementValue(FX_BSTRC("FT")); |
21 if (!pType) { | 21 if (!pType) { |
22 return FALSE; | 22 return false; |
23 } | 23 } |
24 } | 24 } |
25 if (pType->GetString() == FX_BSTRC("Sig")) { | 25 if (pType->GetString() == FX_BSTRC("Sig")) { |
26 return TRUE; | 26 return true; |
27 } | 27 } |
28 return FALSE; | 28 return false; |
29 } | 29 } |
30 static int _CompareFileSize(const void* p1, const void* p2) | 30 static int _CompareFileSize(const void* p1, const void* p2) |
31 { | 31 { |
32 FX_FILESIZE ret = (*(FX_FILESIZE*)p1) - (*(FX_FILESIZE*)p2); | 32 FX_FILESIZE ret = (*(FX_FILESIZE*)p1) - (*(FX_FILESIZE*)p2); |
33 if (ret > 0) { | 33 if (ret > 0) { |
34 return 1; | 34 return 1; |
35 } | 35 } |
36 if (ret < 0) { | 36 if (ret < 0) { |
37 return -1; | 37 return -1; |
38 } | 38 } |
39 return 0; | 39 return 0; |
40 } | 40 } |
41 | 41 |
42 CPDF_Parser::CPDF_Parser() | 42 CPDF_Parser::CPDF_Parser() |
43 { | 43 { |
44 m_pDocument = NULL; | 44 m_pDocument = NULL; |
45 m_pTrailer = NULL; | 45 m_pTrailer = NULL; |
46 m_pEncryptDict = NULL; | 46 m_pEncryptDict = NULL; |
47 m_pSecurityHandler = NULL; | 47 m_pSecurityHandler = NULL; |
48 m_pLinearized = NULL; | 48 m_pLinearized = NULL; |
49 m_dwFirstPageNo = 0; | 49 m_dwFirstPageNo = 0; |
50 m_dwXrefStartObjNum = 0; | 50 m_dwXrefStartObjNum = 0; |
51 m_bOwnFileRead = TRUE; | 51 m_bOwnFileRead = true; |
52 m_FileVersion = 0; | 52 m_FileVersion = 0; |
53 m_bForceUseSecurityHandler = FALSE; | 53 m_bForceUseSecurityHandler = false; |
54 } | 54 } |
55 CPDF_Parser::~CPDF_Parser() | 55 CPDF_Parser::~CPDF_Parser() |
56 { | 56 { |
57 CloseParser(FALSE); | 57 CloseParser(false); |
58 } | 58 } |
59 FX_DWORD CPDF_Parser::GetLastObjNum() | 59 FX_DWORD CPDF_Parser::GetLastObjNum() |
60 { | 60 { |
61 FX_DWORD dwSize = m_CrossRef.GetSize(); | 61 FX_DWORD dwSize = m_CrossRef.GetSize(); |
62 return dwSize ? dwSize - 1 : 0; | 62 return dwSize ? dwSize - 1 : 0; |
63 } | 63 } |
64 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) | 64 void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) |
65 { | 65 { |
66 m_pEncryptDict = pDict; | 66 m_pEncryptDict = pDict; |
67 } | 67 } |
68 void CPDF_Parser::CloseParser(FX_BOOL bReParse) | 68 void CPDF_Parser::CloseParser(bool bReParse) |
69 { | 69 { |
70 m_bVersionUpdated = FALSE; | 70 m_bVersionUpdated = false; |
71 if (!bReParse) { | 71 if (!bReParse) { |
72 delete m_pDocument; | 72 delete m_pDocument; |
73 m_pDocument = NULL; | 73 m_pDocument = NULL; |
74 } | 74 } |
75 if (m_pTrailer) { | 75 if (m_pTrailer) { |
76 m_pTrailer->Release(); | 76 m_pTrailer->Release(); |
77 m_pTrailer = NULL; | 77 m_pTrailer = NULL; |
78 } | 78 } |
79 ReleaseEncryptHandler(); | 79 ReleaseEncryptHandler(); |
80 SetEncryptDictionary(NULL); | 80 SetEncryptDictionary(NULL); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 if (*(FX_DWORD*)buf == tag) { | 117 if (*(FX_DWORD*)buf == tag) { |
118 return offset; | 118 return offset; |
119 } | 119 } |
120 offset ++; | 120 offset ++; |
121 if (offset > 1024) { | 121 if (offset > 1024) { |
122 return -1; | 122 return -1; |
123 } | 123 } |
124 } | 124 } |
125 return -1; | 125 return -1; |
126 } | 126 } |
127 FX_DWORD CPDF_Parser::StartParse(const FX_CHAR* filename, FX_BOOL bReParse) | 127 FX_DWORD CPDF_Parser::StartParse(const FX_CHAR* filename, bool bReParse) |
128 { | 128 { |
129 IFX_FileRead* pFileAccess = FX_CreateFileRead(filename); | 129 IFX_FileRead* pFileAccess = FX_CreateFileRead(filename); |
130 if (!pFileAccess) { | 130 if (!pFileAccess) { |
131 return PDFPARSE_ERROR_FILE; | 131 return PDFPARSE_ERROR_FILE; |
132 } | 132 } |
133 return StartParse(pFileAccess, bReParse); | 133 return StartParse(pFileAccess, bReParse); |
134 } | 134 } |
135 FX_DWORD CPDF_Parser::StartParse(const FX_WCHAR* filename, FX_BOOL bReParse) | 135 FX_DWORD CPDF_Parser::StartParse(const FX_WCHAR* filename, bool bReParse) |
136 { | 136 { |
137 IFX_FileRead* pFileAccess = FX_CreateFileRead(filename); | 137 IFX_FileRead* pFileAccess = FX_CreateFileRead(filename); |
138 if (!pFileAccess) { | 138 if (!pFileAccess) { |
139 return PDFPARSE_ERROR_FILE; | 139 return PDFPARSE_ERROR_FILE; |
140 } | 140 } |
141 return StartParse(pFileAccess, bReParse); | 141 return StartParse(pFileAccess, bReParse); |
142 } | 142 } |
143 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); | 143 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); |
144 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*); | 144 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*); |
145 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, FX_BOOL bReParse, FX
_BOOL bOwnFileRead) | 145 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, bool bReParse, bool
bOwnFileRead) |
146 { | 146 { |
147 CloseParser(bReParse); | 147 CloseParser(bReParse); |
148 m_bXRefStream = FALSE; | 148 m_bXRefStream = false; |
149 m_LastXRefOffset = 0; | 149 m_LastXRefOffset = 0; |
150 m_bOwnFileRead = bOwnFileRead; | 150 m_bOwnFileRead = bOwnFileRead; |
151 int32_t offset = GetHeaderOffset(pFileAccess); | 151 int32_t offset = GetHeaderOffset(pFileAccess); |
152 if (offset == -1) { | 152 if (offset == -1) { |
153 if (bOwnFileRead && pFileAccess) { | 153 if (bOwnFileRead && pFileAccess) { |
154 pFileAccess->Release(); | 154 pFileAccess->Release(); |
155 } | 155 } |
156 return PDFPARSE_ERROR_FORMAT; | 156 return PDFPARSE_ERROR_FORMAT; |
157 } | 157 } |
158 m_Syntax.InitParser(pFileAccess, offset); | 158 m_Syntax.InitParser(pFileAccess, offset); |
(...skipping 10 matching lines...) Expand all Loading... |
169 if (ch >= '0' && ch <= '9') { | 169 if (ch >= '0' && ch <= '9') { |
170 m_FileVersion += ch - '0'; | 170 m_FileVersion += ch - '0'; |
171 } | 171 } |
172 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) { | 172 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) { |
173 return PDFPARSE_ERROR_FORMAT; | 173 return PDFPARSE_ERROR_FORMAT; |
174 } | 174 } |
175 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9); | 175 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9); |
176 if (!bReParse) { | 176 if (!bReParse) { |
177 m_pDocument = new CPDF_Document(this); | 177 m_pDocument = new CPDF_Document(this); |
178 } | 178 } |
179 FX_BOOL bXRefRebuilt = FALSE; | 179 bool bXRefRebuilt = false; |
180 if (m_Syntax.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, 4096)) { | 180 if (m_Syntax.SearchWord(FX_BSTRC("startxref"), true, false, 4096)) { |
181 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); | 181 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); |
182 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(
), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); | 182 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(
), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); |
183 if (pResult == NULL) { | 183 if (pResult == NULL) { |
184 m_SortedOffset.Add(startxref_offset); | 184 m_SortedOffset.Add(startxref_offset); |
185 } | 185 } |
186 m_Syntax.GetKeyword(); | 186 m_Syntax.GetKeyword(); |
187 FX_BOOL bNumber; | 187 bool bNumber; |
188 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(bNumber); | 188 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(bNumber); |
189 if (!bNumber) { | 189 if (!bNumber) { |
190 return PDFPARSE_ERROR_FORMAT; | 190 return PDFPARSE_ERROR_FORMAT; |
191 } | 191 } |
192 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 192 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); |
193 if (!LoadAllCrossRefV4(m_LastXRefOffset) && !LoadAllCrossRefV5(m_LastXRe
fOffset)) { | 193 if (!LoadAllCrossRefV4(m_LastXRefOffset) && !LoadAllCrossRefV5(m_LastXRe
fOffset)) { |
194 if (!RebuildCrossRef()) { | 194 if (!RebuildCrossRef()) { |
195 return PDFPARSE_ERROR_FORMAT; | 195 return PDFPARSE_ERROR_FORMAT; |
196 } | 196 } |
197 bXRefRebuilt = TRUE; | 197 bXRefRebuilt = true; |
198 m_LastXRefOffset = 0; | 198 m_LastXRefOffset = 0; |
199 } | 199 } |
200 } else { | 200 } else { |
201 if (!RebuildCrossRef()) { | 201 if (!RebuildCrossRef()) { |
202 return PDFPARSE_ERROR_FORMAT; | 202 return PDFPARSE_ERROR_FORMAT; |
203 } | 203 } |
204 bXRefRebuilt = TRUE; | 204 bXRefRebuilt = true; |
205 } | 205 } |
206 FX_DWORD dwRet = SetEncryptHandler(); | 206 FX_DWORD dwRet = SetEncryptHandler(); |
207 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 207 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
208 return dwRet; | 208 return dwRet; |
209 } | 209 } |
210 m_pDocument->LoadDoc(); | 210 m_pDocument->LoadDoc(); |
211 if (m_pDocument->GetRoot() == NULL || m_pDocument->GetPageCount() == 0) { | 211 if (m_pDocument->GetRoot() == NULL || m_pDocument->GetPageCount() == 0) { |
212 if (bXRefRebuilt) { | 212 if (bXRefRebuilt) { |
213 return PDFPARSE_ERROR_FORMAT; | 213 return PDFPARSE_ERROR_FORMAT; |
214 } | 214 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 { | 333 { |
334 CPDF_Object* pObj = pDict->GetElement(key); | 334 CPDF_Object* pObj = pDict->GetElement(key); |
335 if (pObj == NULL) { | 335 if (pObj == NULL) { |
336 return 0; | 336 return 0; |
337 } | 337 } |
338 if (pObj->GetType() == PDFOBJ_NUMBER) { | 338 if (pObj->GetType() == PDFOBJ_NUMBER) { |
339 return ((CPDF_Number*)pObj)->GetInteger(); | 339 return ((CPDF_Number*)pObj)->GetInteger(); |
340 } | 340 } |
341 return 0; | 341 return 0; |
342 } | 342 } |
343 static FX_BOOL CheckDirectType(CPDF_Dictionary* pDict, const CFX_ByteStringC& ke
y, int32_t iType) | 343 static bool CheckDirectType(CPDF_Dictionary* pDict, const CFX_ByteStringC& key,
int32_t iType) |
344 { | 344 { |
345 CPDF_Object* pObj = pDict->GetElement(key); | 345 CPDF_Object* pObj = pDict->GetElement(key); |
346 if (!pObj) { | 346 if (!pObj) { |
347 return TRUE; | 347 return true; |
348 } | 348 } |
349 return pObj->GetType() == iType; | 349 return pObj->GetType() == iType; |
350 } | 350 } |
351 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) | 351 bool CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) |
352 { | 352 { |
353 if (!LoadCrossRefV4(xrefpos, 0, TRUE, FALSE)) { | 353 if (!LoadCrossRefV4(xrefpos, 0, true, false)) { |
354 return FALSE; | 354 return false; |
355 } | 355 } |
356 m_pTrailer = LoadTrailerV4(); | 356 m_pTrailer = LoadTrailerV4(); |
357 if (m_pTrailer == NULL) { | 357 if (m_pTrailer == NULL) { |
358 return FALSE; | 358 return false; |
359 } | 359 } |
360 int32_t xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size")); | 360 int32_t xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size")); |
361 if (xrefsize <= 0 || xrefsize > (1 << 20)) { | 361 if (xrefsize <= 0 || xrefsize > (1 << 20)) { |
362 return FALSE; | 362 return false; |
363 } | 363 } |
364 m_CrossRef.SetSize(xrefsize); | 364 m_CrossRef.SetSize(xrefsize); |
365 m_V5Type.SetSize(xrefsize); | 365 m_V5Type.SetSize(xrefsize); |
366 CFX_FileSizeArray CrossRefList, XRefStreamList; | 366 CFX_FileSizeArray CrossRefList, XRefStreamList; |
367 CrossRefList.Add(xrefpos); | 367 CrossRefList.Add(xrefpos); |
368 XRefStreamList.Add(GetDirectInteger(m_pTrailer, FX_BSTRC("XRefStm"))); | 368 XRefStreamList.Add(GetDirectInteger(m_pTrailer, FX_BSTRC("XRefStm"))); |
369 if (!CheckDirectType(m_pTrailer, FX_BSTRC("Prev"), PDFOBJ_NUMBER)) { | 369 if (!CheckDirectType(m_pTrailer, FX_BSTRC("Prev"), PDFOBJ_NUMBER)) { |
370 return FALSE; | 370 return false; |
371 } | 371 } |
372 FX_FILESIZE newxrefpos = GetDirectInteger(m_pTrailer, FX_BSTRC("Prev")); | 372 FX_FILESIZE newxrefpos = GetDirectInteger(m_pTrailer, FX_BSTRC("Prev")); |
373 if (newxrefpos == xrefpos) { | 373 if (newxrefpos == xrefpos) { |
374 return FALSE; | 374 return false; |
375 } | 375 } |
376 xrefpos = newxrefpos; | 376 xrefpos = newxrefpos; |
377 while (xrefpos) { | 377 while (xrefpos) { |
378 CrossRefList.InsertAt(0, xrefpos); | 378 CrossRefList.InsertAt(0, xrefpos); |
379 LoadCrossRefV4(xrefpos, 0, TRUE, FALSE); | 379 LoadCrossRefV4(xrefpos, 0, true, false); |
380 CPDF_Dictionary* pDict = LoadTrailerV4(); | 380 CPDF_Dictionary* pDict = LoadTrailerV4(); |
381 if (pDict == NULL) { | 381 if (pDict == NULL) { |
382 return FALSE; | 382 return false; |
383 } | 383 } |
384 if (!CheckDirectType(pDict, FX_BSTRC("Prev"), PDFOBJ_NUMBER)) { | 384 if (!CheckDirectType(pDict, FX_BSTRC("Prev"), PDFOBJ_NUMBER)) { |
385 pDict->Release(); | 385 pDict->Release(); |
386 return FALSE; | 386 return false; |
387 } | 387 } |
388 newxrefpos = GetDirectInteger(pDict, FX_BSTRC("Prev")); | 388 newxrefpos = GetDirectInteger(pDict, FX_BSTRC("Prev")); |
389 if (newxrefpos == xrefpos) { | 389 if (newxrefpos == xrefpos) { |
390 pDict->Release(); | 390 pDict->Release(); |
391 return FALSE; | 391 return false; |
392 } | 392 } |
393 xrefpos = newxrefpos; | 393 xrefpos = newxrefpos; |
394 XRefStreamList.InsertAt(0, pDict->GetInteger(FX_BSTRC("XRefStm"))); | 394 XRefStreamList.InsertAt(0, pDict->GetInteger(FX_BSTRC("XRefStm"))); |
395 m_Trailers.Add(pDict); | 395 m_Trailers.Add(pDict); |
396 } | 396 } |
397 for (int32_t i = 0; i < CrossRefList.GetSize(); i ++) | 397 for (int32_t i = 0; i < CrossRefList.GetSize(); i ++) |
398 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0))
{ | 398 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], false, i == 0))
{ |
399 return FALSE; | 399 return false; |
400 } | 400 } |
401 return TRUE; | 401 return true; |
402 } | 402 } |
403 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, FX_DWORD d
wObjCount) | 403 bool CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, FX_DWORD dwOb
jCount) |
404 { | 404 { |
405 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) { | 405 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) { |
406 return FALSE; | 406 return false; |
407 } | 407 } |
408 m_pTrailer = LoadTrailerV4(); | 408 m_pTrailer = LoadTrailerV4(); |
409 if (m_pTrailer == NULL) { | 409 if (m_pTrailer == NULL) { |
410 return FALSE; | 410 return false; |
411 } | 411 } |
412 int32_t xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size")); | 412 int32_t xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size")); |
413 if (xrefsize == 0) { | 413 if (xrefsize == 0) { |
414 return FALSE; | 414 return false; |
415 } | 415 } |
416 CFX_FileSizeArray CrossRefList, XRefStreamList; | 416 CFX_FileSizeArray CrossRefList, XRefStreamList; |
417 CrossRefList.Add(xrefpos); | 417 CrossRefList.Add(xrefpos); |
418 XRefStreamList.Add(GetDirectInteger(m_pTrailer, FX_BSTRC("XRefStm"))); | 418 XRefStreamList.Add(GetDirectInteger(m_pTrailer, FX_BSTRC("XRefStm"))); |
419 xrefpos = GetDirectInteger(m_pTrailer, FX_BSTRC("Prev")); | 419 xrefpos = GetDirectInteger(m_pTrailer, FX_BSTRC("Prev")); |
420 while (xrefpos) { | 420 while (xrefpos) { |
421 CrossRefList.InsertAt(0, xrefpos); | 421 CrossRefList.InsertAt(0, xrefpos); |
422 LoadCrossRefV4(xrefpos, 0, TRUE, FALSE); | 422 LoadCrossRefV4(xrefpos, 0, true, false); |
423 CPDF_Dictionary* pDict = LoadTrailerV4(); | 423 CPDF_Dictionary* pDict = LoadTrailerV4(); |
424 if (pDict == NULL) { | 424 if (pDict == NULL) { |
425 return FALSE; | 425 return false; |
426 } | 426 } |
427 xrefpos = GetDirectInteger(pDict, FX_BSTRC("Prev")); | 427 xrefpos = GetDirectInteger(pDict, FX_BSTRC("Prev")); |
428 XRefStreamList.InsertAt(0, pDict->GetInteger(FX_BSTRC("XRefStm"))); | 428 XRefStreamList.InsertAt(0, pDict->GetInteger(FX_BSTRC("XRefStm"))); |
429 m_Trailers.Add(pDict); | 429 m_Trailers.Add(pDict); |
430 } | 430 } |
431 for (int32_t i = 1; i < CrossRefList.GetSize(); i ++) | 431 for (int32_t i = 1; i < CrossRefList.GetSize(); i ++) |
432 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0))
{ | 432 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], false, i == 0))
{ |
433 return FALSE; | 433 return false; |
434 } | 434 } |
435 return TRUE; | 435 return true; |
436 } | 436 } |
437 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCou
nt) | 437 bool CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount) |
438 { | 438 { |
439 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset; | 439 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset; |
440 m_Syntax.RestorePos(dwStartPos); | 440 m_Syntax.RestorePos(dwStartPos); |
441 void* pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset
.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); | 441 void* pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset
.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); |
442 if (pResult == NULL) { | 442 if (pResult == NULL) { |
443 m_SortedOffset.Add(pos); | 443 m_SortedOffset.Add(pos); |
444 } | 444 } |
445 FX_DWORD start_objnum = 0; | 445 FX_DWORD start_objnum = 0; |
446 FX_DWORD count = dwObjCount; | 446 FX_DWORD count = dwObjCount; |
447 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 447 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
448 int32_t recordsize = 20; | 448 int32_t recordsize = 20; |
449 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1); | 449 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1); |
450 pBuf[1024 * recordsize] = '\0'; | 450 pBuf[1024 * recordsize] = '\0'; |
451 int32_t nBlocks = count / 1024 + 1; | 451 int32_t nBlocks = count / 1024 + 1; |
452 for (int32_t block = 0; block < nBlocks; block ++) { | 452 for (int32_t block = 0; block < nBlocks; block ++) { |
453 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 453 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
454 FX_DWORD dwReadSize = block_size * recordsize; | 454 FX_DWORD dwReadSize = block_size * recordsize; |
455 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { | 455 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { |
456 FX_Free(pBuf); | 456 FX_Free(pBuf); |
457 return FALSE; | 457 return false; |
458 } | 458 } |
459 if (!m_Syntax.ReadBlock((uint8_t*)pBuf, dwReadSize)) { | 459 if (!m_Syntax.ReadBlock((uint8_t*)pBuf, dwReadSize)) { |
460 FX_Free(pBuf); | 460 FX_Free(pBuf); |
461 return FALSE; | 461 return false; |
462 } | 462 } |
463 for (int32_t i = 0; i < block_size; i ++) { | 463 for (int32_t i = 0; i < block_size; i ++) { |
464 FX_DWORD objnum = start_objnum + block * 1024 + i; | 464 FX_DWORD objnum = start_objnum + block * 1024 + i; |
465 char* pEntry = pBuf + i * recordsize; | 465 char* pEntry = pBuf + i * recordsize; |
466 if (pEntry[17] == 'f') { | 466 if (pEntry[17] == 'f') { |
467 m_CrossRef.SetAtGrow(objnum, 0); | 467 m_CrossRef.SetAtGrow(objnum, 0); |
468 m_V5Type.SetAtGrow(objnum, 0); | 468 m_V5Type.SetAtGrow(objnum, 0); |
469 } else { | 469 } else { |
470 int32_t offset = FXSYS_atoi(pEntry); | 470 int32_t offset = FXSYS_atoi(pEntry); |
471 if (offset == 0) { | 471 if (offset == 0) { |
472 for (int32_t c = 0; c < 10; c ++) { | 472 for (int32_t c = 0; c < 10; c ++) { |
473 if (pEntry[c] < '0' || pEntry[c] > '9') { | 473 if (pEntry[c] < '0' || pEntry[c] > '9') { |
474 FX_Free(pBuf); | 474 FX_Free(pBuf); |
475 return FALSE; | 475 return false; |
476 } | 476 } |
477 } | 477 } |
478 } | 478 } |
479 m_CrossRef.SetAtGrow(objnum, offset); | 479 m_CrossRef.SetAtGrow(objnum, offset); |
480 int32_t version = FXSYS_atoi(pEntry + 11); | 480 int32_t version = FXSYS_atoi(pEntry + 11); |
481 if (version >= 1) { | 481 if (version >= 1) { |
482 m_bVersionUpdated = TRUE; | 482 m_bVersionUpdated = true; |
483 } | 483 } |
484 m_ObjVersion.SetAtGrow(objnum, version); | 484 m_ObjVersion.SetAtGrow(objnum, version); |
485 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { | 485 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { |
486 void* pResult = FXSYS_bsearch(&m_CrossRef[objnum], m_SortedO
ffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize
); | 486 void* pResult = FXSYS_bsearch(&m_CrossRef[objnum], m_SortedO
ffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize
); |
487 if (pResult == NULL) { | 487 if (pResult == NULL) { |
488 m_SortedOffset.Add(m_CrossRef[objnum]); | 488 m_SortedOffset.Add(m_CrossRef[objnum]); |
489 } | 489 } |
490 } | 490 } |
491 m_V5Type.SetAtGrow(objnum, 1); | 491 m_V5Type.SetAtGrow(objnum, 1); |
492 } | 492 } |
493 } | 493 } |
494 } | 494 } |
495 FX_Free(pBuf); | 495 FX_Free(pBuf); |
496 m_Syntax.RestorePos(SavedPos + count * recordsize); | 496 m_Syntax.RestorePos(SavedPos + count * recordsize); |
497 return TRUE; | 497 return true; |
498 } | 498 } |
499 FX_BOOL CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, FX_B
OOL bSkip, FX_BOOL bFirst) | 499 bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, bool bS
kip, bool bFirst) |
500 { | 500 { |
501 m_Syntax.RestorePos(pos); | 501 m_Syntax.RestorePos(pos); |
502 if (m_Syntax.GetKeyword() != FX_BSTRC("xref")) { | 502 if (m_Syntax.GetKeyword() != FX_BSTRC("xref")) { |
503 return FALSE; | 503 return false; |
504 } | 504 } |
505 void* pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset
.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); | 505 void* pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset
.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); |
506 if (pResult == NULL) { | 506 if (pResult == NULL) { |
507 m_SortedOffset.Add(pos); | 507 m_SortedOffset.Add(pos); |
508 } | 508 } |
509 if (streampos) { | 509 if (streampos) { |
510 void* pResult = FXSYS_bsearch(&streampos, m_SortedOffset.GetData(), m_So
rtedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); | 510 void* pResult = FXSYS_bsearch(&streampos, m_SortedOffset.GetData(), m_So
rtedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); |
511 if (pResult == NULL) { | 511 if (pResult == NULL) { |
512 m_SortedOffset.Add(streampos); | 512 m_SortedOffset.Add(streampos); |
513 } | 513 } |
514 } | 514 } |
515 while (1) { | 515 while (1) { |
516 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 516 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
517 FX_BOOL bIsNumber; | 517 bool bIsNumber; |
518 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 518 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); |
519 if (word.IsEmpty()) { | 519 if (word.IsEmpty()) { |
520 return FALSE; | 520 return false; |
521 } | 521 } |
522 if (!bIsNumber) { | 522 if (!bIsNumber) { |
523 m_Syntax.RestorePos(SavedPos); | 523 m_Syntax.RestorePos(SavedPos); |
524 break; | 524 break; |
525 } | 525 } |
526 FX_DWORD start_objnum = FXSYS_atoi(word); | 526 FX_DWORD start_objnum = FXSYS_atoi(word); |
527 if (start_objnum >= (1 << 20)) { | 527 if (start_objnum >= (1 << 20)) { |
528 return FALSE; | 528 return false; |
529 } | 529 } |
530 FX_DWORD count = m_Syntax.GetDirectNum(); | 530 FX_DWORD count = m_Syntax.GetDirectNum(); |
531 m_Syntax.ToNextWord(); | 531 m_Syntax.ToNextWord(); |
532 SavedPos = m_Syntax.SavePos(); | 532 SavedPos = m_Syntax.SavePos(); |
533 FX_BOOL bFirstItem = FALSE; | 533 bool bFirstItem = false; |
534 int32_t recordsize = 20; | 534 int32_t recordsize = 20; |
535 if (bFirst) { | 535 if (bFirst) { |
536 bFirstItem = TRUE; | 536 bFirstItem = true; |
537 } | 537 } |
538 m_dwXrefStartObjNum = start_objnum; | 538 m_dwXrefStartObjNum = start_objnum; |
539 if (!bSkip) { | 539 if (!bSkip) { |
540 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1); | 540 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1); |
541 pBuf[1024 * recordsize] = '\0'; | 541 pBuf[1024 * recordsize] = '\0'; |
542 int32_t nBlocks = count / 1024 + 1; | 542 int32_t nBlocks = count / 1024 + 1; |
543 FX_BOOL bFirstBlock = TRUE; | 543 bool bFirstBlock = true; |
544 for (int32_t block = 0; block < nBlocks; block ++) { | 544 for (int32_t block = 0; block < nBlocks; block ++) { |
545 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; | 545 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024; |
546 m_Syntax.ReadBlock((uint8_t*)pBuf, block_size * recordsize); | 546 m_Syntax.ReadBlock((uint8_t*)pBuf, block_size * recordsize); |
547 for (int32_t i = 0; i < block_size; i ++) { | 547 for (int32_t i = 0; i < block_size; i ++) { |
548 FX_DWORD objnum = start_objnum + block * 1024 + i; | 548 FX_DWORD objnum = start_objnum + block * 1024 + i; |
549 char* pEntry = pBuf + i * recordsize; | 549 char* pEntry = pBuf + i * recordsize; |
550 if (pEntry[17] == 'f') { | 550 if (pEntry[17] == 'f') { |
551 if (bFirstItem) { | 551 if (bFirstItem) { |
552 objnum = 0; | 552 objnum = 0; |
553 bFirstItem = FALSE; | 553 bFirstItem = false; |
554 } | 554 } |
555 if (bFirstBlock) { | 555 if (bFirstBlock) { |
556 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntr
y); | 556 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntr
y); |
557 int32_t version = FXSYS_atoi(pEntry + 11); | 557 int32_t version = FXSYS_atoi(pEntry + 11); |
558 if (offset == 0 && version == 65535 && start_objnum
!= 0) { | 558 if (offset == 0 && version == 65535 && start_objnum
!= 0) { |
559 start_objnum--; | 559 start_objnum--; |
560 objnum = 0; | 560 objnum = 0; |
561 } | 561 } |
562 } | 562 } |
563 m_CrossRef.SetAtGrow(objnum, 0); | 563 m_CrossRef.SetAtGrow(objnum, 0); |
564 m_V5Type.SetAtGrow(objnum, 0); | 564 m_V5Type.SetAtGrow(objnum, 0); |
565 } else { | 565 } else { |
566 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); | 566 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); |
567 if (offset == 0) { | 567 if (offset == 0) { |
568 for (int32_t c = 0; c < 10; c ++) { | 568 for (int32_t c = 0; c < 10; c ++) { |
569 if (pEntry[c] < '0' || pEntry[c] > '9') { | 569 if (pEntry[c] < '0' || pEntry[c] > '9') { |
570 FX_Free(pBuf); | 570 FX_Free(pBuf); |
571 return FALSE; | 571 return false; |
572 } | 572 } |
573 } | 573 } |
574 } | 574 } |
575 m_CrossRef.SetAtGrow(objnum, offset); | 575 m_CrossRef.SetAtGrow(objnum, offset); |
576 int32_t version = FXSYS_atoi(pEntry + 11); | 576 int32_t version = FXSYS_atoi(pEntry + 11); |
577 if (version >= 1) { | 577 if (version >= 1) { |
578 m_bVersionUpdated = TRUE; | 578 m_bVersionUpdated = true; |
579 } | 579 } |
580 m_ObjVersion.SetAtGrow(objnum, version); | 580 m_ObjVersion.SetAtGrow(objnum, version); |
581 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { | 581 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { |
582 void* pResult = FXSYS_bsearch(&m_CrossRef[objnum], m
_SortedOffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _Compare
FileSize); | 582 void* pResult = FXSYS_bsearch(&m_CrossRef[objnum], m
_SortedOffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _Compare
FileSize); |
583 if (pResult == NULL) { | 583 if (pResult == NULL) { |
584 m_SortedOffset.Add(m_CrossRef[objnum]); | 584 m_SortedOffset.Add(m_CrossRef[objnum]); |
585 } | 585 } |
586 } | 586 } |
587 m_V5Type.SetAtGrow(objnum, 1); | 587 m_V5Type.SetAtGrow(objnum, 1); |
588 } | 588 } |
589 if (bFirstBlock) { | 589 if (bFirstBlock) { |
590 bFirstBlock = FALSE; | 590 bFirstBlock = false; |
591 } | 591 } |
592 } | 592 } |
593 } | 593 } |
594 FX_Free(pBuf); | 594 FX_Free(pBuf); |
595 } | 595 } |
596 m_Syntax.RestorePos(SavedPos + count * recordsize); | 596 m_Syntax.RestorePos(SavedPos + count * recordsize); |
597 } | 597 } |
598 if (streampos) | 598 if (streampos) |
599 if (!LoadCrossRefV5(streampos, streampos, FALSE)) { | 599 if (!LoadCrossRefV5(streampos, streampos, false)) { |
600 return FALSE; | 600 return false; |
601 } | 601 } |
602 return TRUE; | 602 return true; |
603 } | 603 } |
604 FX_BOOL CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) | 604 bool CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) |
605 { | 605 { |
606 if (!LoadCrossRefV5(xrefpos, xrefpos, TRUE)) { | 606 if (!LoadCrossRefV5(xrefpos, xrefpos, true)) { |
607 return FALSE; | 607 return false; |
608 } | 608 } |
609 while (xrefpos) | 609 while (xrefpos) |
610 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { | 610 if (!LoadCrossRefV5(xrefpos, xrefpos, false)) { |
611 return FALSE; | 611 return false; |
612 } | 612 } |
613 m_ObjectStreamMap.InitHashTable(101, FALSE); | 613 m_ObjectStreamMap.InitHashTable(101, false); |
614 m_bXRefStream = TRUE; | 614 m_bXRefStream = true; |
615 return TRUE; | 615 return true; |
616 } | 616 } |
617 FX_BOOL CPDF_Parser::RebuildCrossRef() | 617 bool CPDF_Parser::RebuildCrossRef() |
618 { | 618 { |
619 m_CrossRef.RemoveAll(); | 619 m_CrossRef.RemoveAll(); |
620 m_V5Type.RemoveAll(); | 620 m_V5Type.RemoveAll(); |
621 m_SortedOffset.RemoveAll(); | 621 m_SortedOffset.RemoveAll(); |
622 m_ObjVersion.RemoveAll(); | 622 m_ObjVersion.RemoveAll(); |
623 if (m_pTrailer) { | 623 if (m_pTrailer) { |
624 m_pTrailer->Release(); | 624 m_pTrailer->Release(); |
625 m_pTrailer = NULL; | 625 m_pTrailer = NULL; |
626 } | 626 } |
627 int32_t status = 0; | 627 int32_t status = 0; |
628 int32_t inside_index = 0; | 628 int32_t inside_index = 0; |
629 FX_DWORD objnum = 0, gennum = 0; | 629 FX_DWORD objnum = 0, gennum = 0; |
630 int32_t depth = 0; | 630 int32_t depth = 0; |
631 uint8_t* buffer = FX_Alloc(uint8_t, 4096); | 631 uint8_t* buffer = FX_Alloc(uint8_t, 4096); |
632 FX_FILESIZE pos = m_Syntax.m_HeaderOffset; | 632 FX_FILESIZE pos = m_Syntax.m_HeaderOffset; |
633 FX_FILESIZE start_pos = 0, start_pos1 = 0; | 633 FX_FILESIZE start_pos = 0, start_pos1 = 0; |
634 FX_FILESIZE last_obj = -1, last_xref = -1, last_trailer = -1; | 634 FX_FILESIZE last_obj = -1, last_xref = -1, last_trailer = -1; |
635 while (pos < m_Syntax.m_FileLen) { | 635 while (pos < m_Syntax.m_FileLen) { |
636 FX_BOOL bOverFlow = FALSE; | 636 bool bOverFlow = false; |
637 FX_DWORD size = (FX_DWORD)(m_Syntax.m_FileLen - pos); | 637 FX_DWORD size = (FX_DWORD)(m_Syntax.m_FileLen - pos); |
638 if (size > 4096) { | 638 if (size > 4096) { |
639 size = 4096; | 639 size = 4096; |
640 } | 640 } |
641 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) { | 641 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) { |
642 break; | 642 break; |
643 } | 643 } |
644 for (FX_DWORD i = 0; i < size; i ++) { | 644 for (FX_DWORD i = 0; i < size; i ++) { |
645 uint8_t byte = buffer[i]; | 645 uint8_t byte = buffer[i]; |
646 switch (status) { | 646 switch (status) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 m_Syntax.RestorePos(obj_pos); | 805 m_Syntax.RestorePos(obj_pos); |
806 offset = m_Syntax.FindTag(FX_BSTRC("obj"), 0); | 806 offset = m_Syntax.FindTag(FX_BSTRC("obj"), 0); |
807 if (offset == -1) { | 807 if (offset == -1) { |
808 offset = 0; | 808 offset = 0; |
809 } else { | 809 } else { |
810 offset += 3; | 810 offset += 3; |
811 } | 811 } |
812 FX_FILESIZE nLen = obj_end - obj_pos - offset; | 812 FX_FILESIZE nLen = obj_end - obj_pos - offset; |
813 if ((FX_DWORD)nLen > size - i) { | 813 if ((FX_DWORD)nLen > size - i) { |
814 pos = obj_end + m_Syntax.m_HeaderOffset; | 814 pos = obj_end + m_Syntax.m_HeaderOffset; |
815 bOverFlow = TRUE; | 815 bOverFlow = true; |
816 } else { | 816 } else { |
817 i += (FX_DWORD)nLen; | 817 i += (FX_DWORD)nLen; |
818 } | 818 } |
819 if (m_CrossRef.GetSize() > (int32_t)objnum && m_
CrossRef[objnum]) { | 819 if (m_CrossRef.GetSize() > (int32_t)objnum && m_
CrossRef[objnum]) { |
820 if (pObject) { | 820 if (pObject) { |
821 FX_DWORD oldgen = m_ObjVersion.GetAt(obj
num); | 821 FX_DWORD oldgen = m_ObjVersion.GetAt(obj
num); |
822 m_CrossRef[objnum] = obj_pos; | 822 m_CrossRef[objnum] = obj_pos; |
823 m_ObjVersion.SetAt(objnum, (int16_t)genn
um); | 823 m_ObjVersion.SetAt(objnum, (int16_t)genn
um); |
824 if (oldgen != gennum) { | 824 if (oldgen != gennum) { |
825 m_bVersionUpdated = TRUE; | 825 m_bVersionUpdated = true; |
826 } | 826 } |
827 } | 827 } |
828 } else { | 828 } else { |
829 m_CrossRef.SetAtGrow(objnum, obj_pos); | 829 m_CrossRef.SetAtGrow(objnum, obj_pos); |
830 m_V5Type.SetAtGrow(objnum, 1); | 830 m_V5Type.SetAtGrow(objnum, 1); |
831 m_ObjVersion.SetAtGrow(objnum, (int16_t)genn
um); | 831 m_ObjVersion.SetAtGrow(objnum, (int16_t)genn
um); |
832 } | 832 } |
833 if (pObject) { | 833 if (pObject) { |
834 pObject->Release(); | 834 pObject->Release(); |
835 } | 835 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 } else { | 874 } else { |
875 if (pObj->GetType() == PDFOBJ_STREAM
) { | 875 if (pObj->GetType() == PDFOBJ_STREAM
) { |
876 m_pTrailer = (CPDF_Dictionary*)p
Trailer->Clone(); | 876 m_pTrailer = (CPDF_Dictionary*)p
Trailer->Clone(); |
877 pObj->Release(); | 877 pObj->Release(); |
878 } else { | 878 } else { |
879 m_pTrailer = pTrailer; | 879 m_pTrailer = pTrailer; |
880 } | 880 } |
881 FX_FILESIZE dwSavePos = m_Syntax.Sav
ePos(); | 881 FX_FILESIZE dwSavePos = m_Syntax.Sav
ePos(); |
882 CFX_ByteString strWord = m_Syntax.Ge
tKeyword(); | 882 CFX_ByteString strWord = m_Syntax.Ge
tKeyword(); |
883 if (!strWord.Compare(FX_BSTRC("start
xref"))) { | 883 if (!strWord.Compare(FX_BSTRC("start
xref"))) { |
884 FX_BOOL bNumber = FALSE; | 884 bool bNumber = false; |
885 CFX_ByteString bsOffset = m_Synt
ax.GetNextWord(bNumber); | 885 CFX_ByteString bsOffset = m_Synt
ax.GetNextWord(bNumber); |
886 if (bNumber) { | 886 if (bNumber) { |
887 m_LastXRefOffset = FXSYS_ato
i(bsOffset); | 887 m_LastXRefOffset = FXSYS_ato
i(bsOffset); |
888 } | 888 } |
889 } | 889 } |
890 m_Syntax.RestorePos(dwSavePos); | 890 m_Syntax.RestorePos(dwSavePos); |
891 } | 891 } |
892 } else { | 892 } else { |
893 pObj->Release(); | 893 pObj->Release(); |
894 } | 894 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 last_trailer = last_xref; | 975 last_trailer = last_xref; |
976 } else if (last_trailer == -1 || last_xref < last_obj) { | 976 } else if (last_trailer == -1 || last_xref < last_obj) { |
977 last_trailer = m_Syntax.m_FileLen; | 977 last_trailer = m_Syntax.m_FileLen; |
978 } | 978 } |
979 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; | 979 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; |
980 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOff
set.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); | 980 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOff
set.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); |
981 if (pResult == NULL) { | 981 if (pResult == NULL) { |
982 m_SortedOffset.Add(offset); | 982 m_SortedOffset.Add(offset); |
983 } | 983 } |
984 FX_Free(buffer); | 984 FX_Free(buffer); |
985 return TRUE; | 985 return true; |
986 } | 986 } |
987 static FX_DWORD _GetVarInt(const uint8_t* p, int32_t n) | 987 static FX_DWORD _GetVarInt(const uint8_t* p, int32_t n) |
988 { | 988 { |
989 FX_DWORD result = 0; | 989 FX_DWORD result = 0; |
990 for (int32_t i = 0; i < n; i ++) { | 990 for (int32_t i = 0; i < n; i ++) { |
991 result = result * 256 + p[i]; | 991 result = result * 256 + p[i]; |
992 } | 992 } |
993 return result; | 993 return result; |
994 } | 994 } |
995 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL
bMainXRef) | 995 bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, bool bMainX
Ref) |
996 { | 996 { |
997 CPDF_Stream* pStream = (CPDF_Stream*)ParseIndirectObjectAt(m_pDocument, pos,
0, NULL); | 997 CPDF_Stream* pStream = (CPDF_Stream*)ParseIndirectObjectAt(m_pDocument, pos,
0, NULL); |
998 if (!pStream) { | 998 if (!pStream) { |
999 return FALSE; | 999 return false; |
1000 } | 1000 } |
1001 if (m_pDocument) { | 1001 if (m_pDocument) { |
1002 CPDF_Dictionary * pDict = m_pDocument->GetRoot(); | 1002 CPDF_Dictionary * pDict = m_pDocument->GetRoot(); |
1003 if (!pDict || pDict->GetObjNum() != pStream->m_ObjNum) { | 1003 if (!pDict || pDict->GetObjNum() != pStream->m_ObjNum) { |
1004 m_pDocument->InsertIndirectObject(pStream->m_ObjNum, pStream); | 1004 m_pDocument->InsertIndirectObject(pStream->m_ObjNum, pStream); |
1005 } else { | 1005 } else { |
1006 if (pStream->GetType() == PDFOBJ_STREAM) { | 1006 if (pStream->GetType() == PDFOBJ_STREAM) { |
1007 pStream->Release(); | 1007 pStream->Release(); |
1008 } | 1008 } |
1009 return FALSE; | 1009 return false; |
1010 } | 1010 } |
1011 } | 1011 } |
1012 if (pStream->GetType() != PDFOBJ_STREAM) { | 1012 if (pStream->GetType() != PDFOBJ_STREAM) { |
1013 return FALSE; | 1013 return false; |
1014 } | 1014 } |
1015 prev = pStream->GetDict()->GetInteger(FX_BSTRC("Prev")); | 1015 prev = pStream->GetDict()->GetInteger(FX_BSTRC("Prev")); |
1016 int32_t size = pStream->GetDict()->GetInteger(FX_BSTRC("Size")); | 1016 int32_t size = pStream->GetDict()->GetInteger(FX_BSTRC("Size")); |
1017 if (size < 0) { | 1017 if (size < 0) { |
1018 pStream->Release(); | 1018 pStream->Release(); |
1019 return FALSE; | 1019 return false; |
1020 } | 1020 } |
1021 if (bMainXRef) { | 1021 if (bMainXRef) { |
1022 m_pTrailer = (CPDF_Dictionary*)pStream->GetDict()->Clone(); | 1022 m_pTrailer = (CPDF_Dictionary*)pStream->GetDict()->Clone(); |
1023 m_CrossRef.SetSize(size); | 1023 m_CrossRef.SetSize(size); |
1024 if (m_V5Type.SetSize(size)) { | 1024 if (m_V5Type.SetSize(size)) { |
1025 FXSYS_memset(m_V5Type.GetData(), 0, size); | 1025 FXSYS_memset(m_V5Type.GetData(), 0, size); |
1026 } | 1026 } |
1027 } else { | 1027 } else { |
1028 m_Trailers.Add((CPDF_Dictionary*)pStream->GetDict()->Clone()); | 1028 m_Trailers.Add((CPDF_Dictionary*)pStream->GetDict()->Clone()); |
1029 } | 1029 } |
(...skipping 13 matching lines...) Expand all Loading... |
1043 } | 1043 } |
1044 } | 1044 } |
1045 } | 1045 } |
1046 } | 1046 } |
1047 if (arrIndex.size() == 0) { | 1047 if (arrIndex.size() == 0) { |
1048 arrIndex.push_back(std::make_pair(0, size)); | 1048 arrIndex.push_back(std::make_pair(0, size)); |
1049 } | 1049 } |
1050 pArray = pStream->GetDict()->GetArray(FX_BSTRC("W")); | 1050 pArray = pStream->GetDict()->GetArray(FX_BSTRC("W")); |
1051 if (pArray == NULL) { | 1051 if (pArray == NULL) { |
1052 pStream->Release(); | 1052 pStream->Release(); |
1053 return FALSE; | 1053 return false; |
1054 } | 1054 } |
1055 CFX_DWordArray WidthArray; | 1055 CFX_DWordArray WidthArray; |
1056 FX_SAFE_DWORD dwAccWidth = 0; | 1056 FX_SAFE_DWORD dwAccWidth = 0; |
1057 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) { | 1057 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) { |
1058 WidthArray.Add(pArray->GetInteger(i)); | 1058 WidthArray.Add(pArray->GetInteger(i)); |
1059 dwAccWidth += WidthArray[i]; | 1059 dwAccWidth += WidthArray[i]; |
1060 } | 1060 } |
1061 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { | 1061 if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3) { |
1062 pStream->Release(); | 1062 pStream->Release(); |
1063 return FALSE; | 1063 return false; |
1064 } | 1064 } |
1065 FX_DWORD totalWidth = dwAccWidth.ValueOrDie(); | 1065 FX_DWORD totalWidth = dwAccWidth.ValueOrDie(); |
1066 CPDF_StreamAcc acc; | 1066 CPDF_StreamAcc acc; |
1067 acc.LoadAllData(pStream); | 1067 acc.LoadAllData(pStream); |
1068 const uint8_t* pData = acc.GetData(); | 1068 const uint8_t* pData = acc.GetData(); |
1069 FX_DWORD dwTotalSize = acc.GetSize(); | 1069 FX_DWORD dwTotalSize = acc.GetSize(); |
1070 FX_DWORD segindex = 0; | 1070 FX_DWORD segindex = 0; |
1071 for (FX_DWORD i = 0; i < arrIndex.size(); i ++) { | 1071 for (FX_DWORD i = 0; i < arrIndex.size(); i ++) { |
1072 int32_t startnum = arrIndex[i].first; | 1072 int32_t startnum = arrIndex[i].first; |
1073 if (startnum < 0) { | 1073 if (startnum < 0) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 FX_FILESIZE offset = _GetVarInt(entrystart + WidthArray[0], Widt
hArray[1]); | 1113 FX_FILESIZE offset = _GetVarInt(entrystart + WidthArray[0], Widt
hArray[1]); |
1114 m_CrossRef[startnum + j] = offset; | 1114 m_CrossRef[startnum + j] = offset; |
1115 if (type == 1) { | 1115 if (type == 1) { |
1116 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetDat
a(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); | 1116 void* pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetDat
a(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); |
1117 if (pResult == NULL) { | 1117 if (pResult == NULL) { |
1118 m_SortedOffset.Add(offset); | 1118 m_SortedOffset.Add(offset); |
1119 } | 1119 } |
1120 } else { | 1120 } else { |
1121 if (offset < 0 || offset >= m_V5Type.GetSize()) { | 1121 if (offset < 0 || offset >= m_V5Type.GetSize()) { |
1122 pStream->Release(); | 1122 pStream->Release(); |
1123 return FALSE; | 1123 return false; |
1124 } | 1124 } |
1125 m_V5Type[offset] = 255; | 1125 m_V5Type[offset] = 255; |
1126 } | 1126 } |
1127 } | 1127 } |
1128 } | 1128 } |
1129 segindex += count; | 1129 segindex += count; |
1130 } | 1130 } |
1131 pStream->Release(); | 1131 pStream->Release(); |
1132 return TRUE; | 1132 return true; |
1133 } | 1133 } |
1134 CPDF_Array* CPDF_Parser::GetIDArray() | 1134 CPDF_Array* CPDF_Parser::GetIDArray() |
1135 { | 1135 { |
1136 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NUL
L; | 1136 CPDF_Object* pID = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("ID")) : NUL
L; |
1137 if (pID == NULL) { | 1137 if (pID == NULL) { |
1138 return NULL; | 1138 return NULL; |
1139 } | 1139 } |
1140 if (pID->GetType() == PDFOBJ_REFERENCE) { | 1140 if (pID->GetType() == PDFOBJ_REFERENCE) { |
1141 pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum()); | 1141 pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum()); |
1142 m_pTrailer->SetAt(FX_BSTRC("ID"), pID); | 1142 m_pTrailer->SetAt(FX_BSTRC("ID"), pID); |
(...skipping 12 matching lines...) Expand all Loading... |
1155 return ((CPDF_Reference*) pRef)->GetRefObjNum(); | 1155 return ((CPDF_Reference*) pRef)->GetRefObjNum(); |
1156 } | 1156 } |
1157 FX_DWORD CPDF_Parser::GetInfoObjNum() | 1157 FX_DWORD CPDF_Parser::GetInfoObjNum() |
1158 { | 1158 { |
1159 CPDF_Object* pRef = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) :
NULL; | 1159 CPDF_Object* pRef = m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) :
NULL; |
1160 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 1160 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
1161 return 0; | 1161 return 0; |
1162 } | 1162 } |
1163 return ((CPDF_Reference*) pRef)->GetRefObjNum(); | 1163 return ((CPDF_Reference*) pRef)->GetRefObjNum(); |
1164 } | 1164 } |
1165 FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) | 1165 bool CPDF_Parser::IsFormStream(FX_DWORD objnum, bool& bForm) |
1166 { | 1166 { |
1167 bForm = FALSE; | 1167 bForm = false; |
1168 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1168 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { |
1169 return TRUE; | 1169 return true; |
1170 } | 1170 } |
1171 if (m_V5Type[objnum] == 0) { | 1171 if (m_V5Type[objnum] == 0) { |
1172 return TRUE; | 1172 return true; |
1173 } | 1173 } |
1174 if (m_V5Type[objnum] == 2) { | 1174 if (m_V5Type[objnum] == 2) { |
1175 return TRUE; | 1175 return true; |
1176 } | 1176 } |
1177 FX_FILESIZE pos = m_CrossRef[objnum]; | 1177 FX_FILESIZE pos = m_CrossRef[objnum]; |
1178 void* pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset
.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); | 1178 void* pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOffset
.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); |
1179 if (pResult == NULL) { | 1179 if (pResult == NULL) { |
1180 return TRUE; | 1180 return true; |
1181 } | 1181 } |
1182 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == m_Sort
edOffset.GetSize() - 1) { | 1182 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)m_SortedOffset.GetData() == m_Sort
edOffset.GetSize() - 1) { |
1183 return FALSE; | 1183 return false; |
1184 } | 1184 } |
1185 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; | 1185 FX_FILESIZE size = ((FX_FILESIZE*)pResult)[1] - pos; |
1186 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1186 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1187 m_Syntax.RestorePos(pos); | 1187 m_Syntax.RestorePos(pos); |
1188 bForm = m_Syntax.SearchMultiWord(FX_BSTRC("/Form\0stream"), TRUE, size) == 0
; | 1188 bForm = m_Syntax.SearchMultiWord(FX_BSTRC("/Form\0stream"), true, size) == 0
; |
1189 m_Syntax.RestorePos(SavedPos); | 1189 m_Syntax.RestorePos(SavedPos); |
1190 return TRUE; | 1190 return true; |
1191 } | 1191 } |
1192 CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, FX
_DWORD objnum, PARSE_CONTEXT* pContext) | 1192 CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, FX
_DWORD objnum, PARSE_CONTEXT* pContext) |
1193 { | 1193 { |
1194 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { | 1194 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { |
1195 return NULL; | 1195 return NULL; |
1196 } | 1196 } |
1197 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1197 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
1198 FX_FILESIZE pos = m_CrossRef[objnum]; | 1198 FX_FILESIZE pos = m_CrossRef[objnum]; |
1199 if (pos <= 0) { | 1199 if (pos <= 0) { |
1200 return NULL; | 1200 return NULL; |
1201 } | 1201 } |
1202 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); | 1202 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); |
1203 } | 1203 } |
1204 if (m_V5Type[objnum] == 2) { | 1204 if (m_V5Type[objnum] == 2) { |
1205 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum
]); | 1205 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum
]); |
1206 if (pObjStream == NULL) { | 1206 if (pObjStream == NULL) { |
1207 return NULL; | 1207 return NULL; |
1208 } | 1208 } |
1209 int32_t n = pObjStream->GetDict()->GetInteger(FX_BSTRC("N")); | 1209 int32_t n = pObjStream->GetDict()->GetInteger(FX_BSTRC("N")); |
1210 int32_t offset = pObjStream->GetDict()->GetInteger(FX_BSTRC("First")); | 1210 int32_t offset = pObjStream->GetDict()->GetInteger(FX_BSTRC("First")); |
1211 CPDF_SyntaxParser syntax; | 1211 CPDF_SyntaxParser syntax; |
1212 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream((uint8_t*)pO
bjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); | 1212 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream((uint8_t*)pO
bjStream->GetData(), (size_t)pObjStream->GetSize(), false)); |
1213 syntax.InitParser(file.Get(), 0); | 1213 syntax.InitParser(file.Get(), 0); |
1214 CPDF_Object* pRet = NULL; | 1214 CPDF_Object* pRet = NULL; |
1215 while (n) { | 1215 while (n) { |
1216 FX_DWORD thisnum = syntax.GetDirectNum(); | 1216 FX_DWORD thisnum = syntax.GetDirectNum(); |
1217 FX_DWORD thisoff = syntax.GetDirectNum(); | 1217 FX_DWORD thisoff = syntax.GetDirectNum(); |
1218 if (thisnum == objnum) { | 1218 if (thisnum == objnum) { |
1219 syntax.RestorePos(offset + thisoff); | 1219 syntax.RestorePos(offset + thisoff); |
1220 pRet = syntax.GetObject(pObjList, 0, 0, pContext); | 1220 pRet = syntax.GetObject(pObjList, 0, 0, pContext); |
1221 break; | 1221 break; |
1222 } | 1222 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 if (m_V5Type[objnum] == 2) { | 1275 if (m_V5Type[objnum] == 2) { |
1276 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum
]); | 1276 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum
]); |
1277 if (pObjStream == NULL) { | 1277 if (pObjStream == NULL) { |
1278 return; | 1278 return; |
1279 } | 1279 } |
1280 int32_t n = pObjStream->GetDict()->GetInteger(FX_BSTRC("N")); | 1280 int32_t n = pObjStream->GetDict()->GetInteger(FX_BSTRC("N")); |
1281 int32_t offset = pObjStream->GetDict()->GetInteger(FX_BSTRC("First")); | 1281 int32_t offset = pObjStream->GetDict()->GetInteger(FX_BSTRC("First")); |
1282 CPDF_SyntaxParser syntax; | 1282 CPDF_SyntaxParser syntax; |
1283 const uint8_t* pData = pObjStream->GetData(); | 1283 const uint8_t* pData = pObjStream->GetData(); |
1284 FX_DWORD totalsize = pObjStream->GetSize(); | 1284 FX_DWORD totalsize = pObjStream->GetSize(); |
1285 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream((uint8_t*)pD
ata, (size_t)totalsize, FALSE)); | 1285 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream((uint8_t*)pD
ata, (size_t)totalsize, false)); |
1286 syntax.InitParser(file.Get(), 0); | 1286 syntax.InitParser(file.Get(), 0); |
1287 while (n) { | 1287 while (n) { |
1288 FX_DWORD thisnum = syntax.GetDirectNum(); | 1288 FX_DWORD thisnum = syntax.GetDirectNum(); |
1289 FX_DWORD thisoff = syntax.GetDirectNum(); | 1289 FX_DWORD thisoff = syntax.GetDirectNum(); |
1290 if (thisnum == objnum) { | 1290 if (thisnum == objnum) { |
1291 if (n == 1) { | 1291 if (n == 1) { |
1292 size = totalsize - (thisoff + offset); | 1292 size = totalsize - (thisoff + offset); |
1293 } else { | 1293 } else { |
1294 syntax.GetDirectNum(); // Skip nextnum. | 1294 syntax.GetDirectNum(); // Skip nextnum. |
1295 FX_DWORD nextoff = syntax.GetDirectNum(); | 1295 FX_DWORD nextoff = syntax.GetDirectNum(); |
1296 size = nextoff - thisoff; | 1296 size = nextoff - thisoff; |
1297 } | 1297 } |
1298 pBuffer = FX_Alloc(uint8_t, size); | 1298 pBuffer = FX_Alloc(uint8_t, size); |
1299 FXSYS_memcpy(pBuffer, pData + thisoff + offset, size); | 1299 FXSYS_memcpy(pBuffer, pData + thisoff + offset, size); |
1300 return; | 1300 return; |
1301 } | 1301 } |
1302 n --; | 1302 n --; |
1303 } | 1303 } |
1304 return; | 1304 return; |
1305 } | 1305 } |
1306 if (m_V5Type[objnum] == 1) { | 1306 if (m_V5Type[objnum] == 1) { |
1307 FX_FILESIZE pos = m_CrossRef[objnum]; | 1307 FX_FILESIZE pos = m_CrossRef[objnum]; |
1308 if (pos == 0) { | 1308 if (pos == 0) { |
1309 return; | 1309 return; |
1310 } | 1310 } |
1311 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1311 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1312 m_Syntax.RestorePos(pos); | 1312 m_Syntax.RestorePos(pos); |
1313 FX_BOOL bIsNumber; | 1313 bool bIsNumber; |
1314 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1314 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); |
1315 if (!bIsNumber) { | 1315 if (!bIsNumber) { |
1316 m_Syntax.RestorePos(SavedPos); | 1316 m_Syntax.RestorePos(SavedPos); |
1317 return; | 1317 return; |
1318 } | 1318 } |
1319 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1319 FX_DWORD parser_objnum = FXSYS_atoi(word); |
1320 if (parser_objnum && parser_objnum != objnum) { | 1320 if (parser_objnum && parser_objnum != objnum) { |
1321 m_Syntax.RestorePos(SavedPos); | 1321 m_Syntax.RestorePos(SavedPos); |
1322 return; | 1322 return; |
1323 } | 1323 } |
1324 word = m_Syntax.GetNextWord(bIsNumber); | 1324 word = m_Syntax.GetNextWord(bIsNumber); |
1325 if (!bIsNumber) { | 1325 if (!bIsNumber) { |
1326 m_Syntax.RestorePos(SavedPos); | 1326 m_Syntax.RestorePos(SavedPos); |
1327 return; | 1327 return; |
1328 } | 1328 } |
1329 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) { | 1329 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) { |
1330 m_Syntax.RestorePos(SavedPos); | 1330 m_Syntax.RestorePos(SavedPos); |
1331 return; | 1331 return; |
1332 } | 1332 } |
1333 void* pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOf
fset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); | 1333 void* pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOf
fset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); |
1334 if (pResult == NULL) { | 1334 if (pResult == NULL) { |
1335 m_Syntax.RestorePos(SavedPos); | 1335 m_Syntax.RestorePos(SavedPos); |
1336 return; | 1336 return; |
1337 } | 1337 } |
1338 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1]; | 1338 FX_FILESIZE nextoff = ((FX_FILESIZE*)pResult)[1]; |
1339 FX_BOOL bNextOffValid = FALSE; | 1339 bool bNextOffValid = false; |
1340 if (nextoff != pos) { | 1340 if (nextoff != pos) { |
1341 m_Syntax.RestorePos(nextoff); | 1341 m_Syntax.RestorePos(nextoff); |
1342 word = m_Syntax.GetNextWord(bIsNumber); | 1342 word = m_Syntax.GetNextWord(bIsNumber); |
1343 if (word == FX_BSTRC("xref")) { | 1343 if (word == FX_BSTRC("xref")) { |
1344 bNextOffValid = TRUE; | 1344 bNextOffValid = true; |
1345 } else if (bIsNumber) { | 1345 } else if (bIsNumber) { |
1346 word = m_Syntax.GetNextWord(bIsNumber); | 1346 word = m_Syntax.GetNextWord(bIsNumber); |
1347 if (bIsNumber && m_Syntax.GetKeyword() == FX_BSTRC("obj")) { | 1347 if (bIsNumber && m_Syntax.GetKeyword() == FX_BSTRC("obj")) { |
1348 bNextOffValid = TRUE; | 1348 bNextOffValid = true; |
1349 } | 1349 } |
1350 } | 1350 } |
1351 } | 1351 } |
1352 if (!bNextOffValid) { | 1352 if (!bNextOffValid) { |
1353 m_Syntax.RestorePos(pos); | 1353 m_Syntax.RestorePos(pos); |
1354 while (1) { | 1354 while (1) { |
1355 if (m_Syntax.GetKeyword() == FX_BSTRC("endobj")) { | 1355 if (m_Syntax.GetKeyword() == FX_BSTRC("endobj")) { |
1356 break; | 1356 break; |
1357 } | 1357 } |
1358 if (m_Syntax.SavePos() == m_Syntax.m_FileLen) { | 1358 if (m_Syntax.SavePos() == m_Syntax.m_FileLen) { |
1359 break; | 1359 break; |
1360 } | 1360 } |
1361 } | 1361 } |
1362 nextoff = m_Syntax.SavePos(); | 1362 nextoff = m_Syntax.SavePos(); |
1363 } | 1363 } |
1364 size = (FX_DWORD)(nextoff - pos); | 1364 size = (FX_DWORD)(nextoff - pos); |
1365 pBuffer = FX_Alloc(uint8_t, size); | 1365 pBuffer = FX_Alloc(uint8_t, size); |
1366 m_Syntax.RestorePos(pos); | 1366 m_Syntax.RestorePos(pos); |
1367 m_Syntax.ReadBlock(pBuffer, size); | 1367 m_Syntax.ReadBlock(pBuffer, size); |
1368 m_Syntax.RestorePos(SavedPos); | 1368 m_Syntax.RestorePos(SavedPos); |
1369 } | 1369 } |
1370 } | 1370 } |
1371 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList,
FX_FILESIZE pos, FX_DWORD objnum, | 1371 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList,
FX_FILESIZE pos, FX_DWORD objnum, |
1372 PARSE_CONTEXT* pContext) | 1372 PARSE_CONTEXT* pContext) |
1373 { | 1373 { |
1374 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1374 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1375 m_Syntax.RestorePos(pos); | 1375 m_Syntax.RestorePos(pos); |
1376 FX_BOOL bIsNumber; | 1376 bool bIsNumber; |
1377 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1377 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); |
1378 if (!bIsNumber) { | 1378 if (!bIsNumber) { |
1379 m_Syntax.RestorePos(SavedPos); | 1379 m_Syntax.RestorePos(SavedPos); |
1380 return NULL; | 1380 return NULL; |
1381 } | 1381 } |
1382 FX_FILESIZE objOffset = m_Syntax.SavePos(); | 1382 FX_FILESIZE objOffset = m_Syntax.SavePos(); |
1383 objOffset -= word.GetLength(); | 1383 objOffset -= word.GetLength(); |
1384 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1384 FX_DWORD parser_objnum = FXSYS_atoi(word); |
1385 if (objnum && parser_objnum != objnum) { | 1385 if (objnum && parser_objnum != objnum) { |
1386 m_Syntax.RestorePos(SavedPos); | 1386 m_Syntax.RestorePos(SavedPos); |
(...skipping 22 matching lines...) Expand all Loading... |
1409 } | 1409 } |
1410 pObj->m_GenNum = parser_gennum; | 1410 pObj->m_GenNum = parser_gennum; |
1411 } | 1411 } |
1412 return pObj; | 1412 return pObj; |
1413 } | 1413 } |
1414 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict(CPDF_IndirectObjects* pO
bjList, FX_FILESIZE pos, FX_DWORD objnum, | 1414 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict(CPDF_IndirectObjects* pO
bjList, FX_FILESIZE pos, FX_DWORD objnum, |
1415 struct PARSE_CONTEXT* pContext, FX_FILESIZE *pResultPos) | 1415 struct PARSE_CONTEXT* pContext, FX_FILESIZE *pResultPos) |
1416 { | 1416 { |
1417 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1417 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1418 m_Syntax.RestorePos(pos); | 1418 m_Syntax.RestorePos(pos); |
1419 FX_BOOL bIsNumber; | 1419 bool bIsNumber; |
1420 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1420 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); |
1421 if (!bIsNumber) { | 1421 if (!bIsNumber) { |
1422 m_Syntax.RestorePos(SavedPos); | 1422 m_Syntax.RestorePos(SavedPos); |
1423 return NULL; | 1423 return NULL; |
1424 } | 1424 } |
1425 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1425 FX_DWORD parser_objnum = FXSYS_atoi(word); |
1426 if (objnum && parser_objnum != objnum) { | 1426 if (objnum && parser_objnum != objnum) { |
1427 m_Syntax.RestorePos(SavedPos); | 1427 m_Syntax.RestorePos(SavedPos); |
1428 return NULL; | 1428 return NULL; |
1429 } | 1429 } |
(...skipping 21 matching lines...) Expand all Loading... |
1451 } | 1451 } |
1452 CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, 0); | 1452 CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, 0); |
1453 if (pObj == NULL || pObj->GetType() != PDFOBJ_DICTIONARY) { | 1453 if (pObj == NULL || pObj->GetType() != PDFOBJ_DICTIONARY) { |
1454 if (pObj) { | 1454 if (pObj) { |
1455 pObj->Release(); | 1455 pObj->Release(); |
1456 } | 1456 } |
1457 return NULL; | 1457 return NULL; |
1458 } | 1458 } |
1459 return (CPDF_Dictionary*)pObj; | 1459 return (CPDF_Dictionary*)pObj; |
1460 } | 1460 } |
1461 FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) | 1461 FX_DWORD CPDF_Parser::GetPermissions(bool bCheckRevision) |
1462 { | 1462 { |
1463 if (m_pSecurityHandler == NULL) { | 1463 if (m_pSecurityHandler == NULL) { |
1464 return (FX_DWORD) - 1; | 1464 return (FX_DWORD) - 1; |
1465 } | 1465 } |
1466 FX_DWORD dwPermission = m_pSecurityHandler->GetPermissions(); | 1466 FX_DWORD dwPermission = m_pSecurityHandler->GetPermissions(); |
1467 if (m_pEncryptDict && m_pEncryptDict->GetString(FX_BSTRC("Filter")) == FX_BS
TRC("Standard")) { | 1467 if (m_pEncryptDict && m_pEncryptDict->GetString(FX_BSTRC("Filter")) == FX_BS
TRC("Standard")) { |
1468 dwPermission &= 0xFFFFFFFC; | 1468 dwPermission &= 0xFFFFFFFC; |
1469 dwPermission |= 0xFFFFF0C0; | 1469 dwPermission |= 0xFFFFF0C0; |
1470 if(bCheckRevision && m_pEncryptDict->GetInteger(FX_BSTRC("R")) == 2) { | 1470 if(bCheckRevision && m_pEncryptDict->GetInteger(FX_BSTRC("R")) == 2) { |
1471 dwPermission &= 0xFFFFF0FF; | 1471 dwPermission &= 0xFFFFF0FF; |
1472 } | 1472 } |
1473 } | 1473 } |
1474 return dwPermission; | 1474 return dwPermission; |
1475 } | 1475 } |
1476 FX_BOOL CPDF_Parser::IsOwner() | 1476 bool CPDF_Parser::IsOwner() |
1477 { | 1477 { |
1478 return m_pSecurityHandler == NULL ? TRUE : m_pSecurityHandler->IsOwner(); | 1478 return m_pSecurityHandler == NULL ? true : m_pSecurityHandler->IsOwner(); |
1479 } | 1479 } |
1480 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, FX_
BOOL bForced) | 1480 void CPDF_Parser::SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, boo
l bForced) |
1481 { | 1481 { |
1482 ASSERT(m_pSecurityHandler == NULL); | 1482 ASSERT(m_pSecurityHandler == NULL); |
1483 if (!m_bForceUseSecurityHandler) { | 1483 if (!m_bForceUseSecurityHandler) { |
1484 delete m_pSecurityHandler; | 1484 delete m_pSecurityHandler; |
1485 m_pSecurityHandler = NULL; | 1485 m_pSecurityHandler = NULL; |
1486 } | 1486 } |
1487 m_bForceUseSecurityHandler = bForced; | 1487 m_bForceUseSecurityHandler = bForced; |
1488 m_pSecurityHandler = pSecurityHandler; | 1488 m_pSecurityHandler = pSecurityHandler; |
1489 if (m_bForceUseSecurityHandler) { | 1489 if (m_bForceUseSecurityHandler) { |
1490 return; | 1490 return; |
1491 } | 1491 } |
1492 m_Syntax.m_pCryptoHandler = pSecurityHandler->CreateCryptoHandler(); | 1492 m_Syntax.m_pCryptoHandler = pSecurityHandler->CreateCryptoHandler(); |
1493 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); | 1493 m_Syntax.m_pCryptoHandler->Init(NULL, pSecurityHandler); |
1494 } | 1494 } |
1495 FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset
) | 1495 bool CPDF_Parser::IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset) |
1496 { | 1496 { |
1497 m_Syntax.InitParser(pFileAccess, offset); | 1497 m_Syntax.InitParser(pFileAccess, offset); |
1498 m_Syntax.RestorePos(m_Syntax.m_HeaderOffset + 9); | 1498 m_Syntax.RestorePos(m_Syntax.m_HeaderOffset + 9); |
1499 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1499 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1500 FX_BOOL bIsNumber; | 1500 bool bIsNumber; |
1501 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); | 1501 CFX_ByteString word = m_Syntax.GetNextWord(bIsNumber); |
1502 if (!bIsNumber) { | 1502 if (!bIsNumber) { |
1503 return FALSE; | 1503 return false; |
1504 } | 1504 } |
1505 FX_DWORD objnum = FXSYS_atoi(word); | 1505 FX_DWORD objnum = FXSYS_atoi(word); |
1506 word = m_Syntax.GetNextWord(bIsNumber); | 1506 word = m_Syntax.GetNextWord(bIsNumber); |
1507 if (!bIsNumber) { | 1507 if (!bIsNumber) { |
1508 return FALSE; | 1508 return false; |
1509 } | 1509 } |
1510 FX_DWORD gennum = FXSYS_atoi(word); | 1510 FX_DWORD gennum = FXSYS_atoi(word); |
1511 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) { | 1511 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) { |
1512 m_Syntax.RestorePos(SavedPos); | 1512 m_Syntax.RestorePos(SavedPos); |
1513 return FALSE; | 1513 return false; |
1514 } | 1514 } |
1515 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0); | 1515 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0); |
1516 if (!m_pLinearized) { | 1516 if (!m_pLinearized) { |
1517 return FALSE; | 1517 return false; |
1518 } | 1518 } |
1519 if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTR
C("Linearized"))) { | 1519 if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTR
C("Linearized"))) { |
1520 m_Syntax.GetNextWord(bIsNumber); | 1520 m_Syntax.GetNextWord(bIsNumber); |
1521 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); | 1521 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); |
1522 if (!pLen) { | 1522 if (!pLen) { |
1523 m_pLinearized->Release(); | 1523 m_pLinearized->Release(); |
1524 m_pLinearized = NULL; | 1524 m_pLinearized = NULL; |
1525 return FALSE; | 1525 return false; |
1526 } | 1526 } |
1527 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { | 1527 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { |
1528 return FALSE; | 1528 return false; |
1529 } | 1529 } |
1530 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); | 1530 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); |
1531 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { | 1531 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { |
1532 m_dwFirstPageNo = pNo->GetInteger(); | 1532 m_dwFirstPageNo = pNo->GetInteger(); |
1533 } | 1533 } |
1534 CPDF_Object *pTable = m_pLinearized->GetDict()->GetElement(FX_BSTRC("T")
); | 1534 CPDF_Object *pTable = m_pLinearized->GetDict()->GetElement(FX_BSTRC("T")
); |
1535 if (pTable && pTable->GetType() == PDFOBJ_NUMBER) { | 1535 if (pTable && pTable->GetType() == PDFOBJ_NUMBER) { |
1536 m_LastXRefOffset = pTable->GetInteger(); | 1536 m_LastXRefOffset = pTable->GetInteger(); |
1537 } | 1537 } |
1538 return TRUE; | 1538 return true; |
1539 } | 1539 } |
1540 m_pLinearized->Release(); | 1540 m_pLinearized->Release(); |
1541 m_pLinearized = NULL; | 1541 m_pLinearized = NULL; |
1542 return FALSE; | 1542 return false; |
1543 } | 1543 } |
1544 FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, FX_BOOL bReParse
, FX_BOOL bOwnFileRead) | 1544 FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, bool bReParse, b
ool bOwnFileRead) |
1545 { | 1545 { |
1546 CloseParser(bReParse); | 1546 CloseParser(bReParse); |
1547 m_bXRefStream = FALSE; | 1547 m_bXRefStream = false; |
1548 m_LastXRefOffset = 0; | 1548 m_LastXRefOffset = 0; |
1549 m_bOwnFileRead = bOwnFileRead; | 1549 m_bOwnFileRead = bOwnFileRead; |
1550 int32_t offset = GetHeaderOffset(pFileAccess); | 1550 int32_t offset = GetHeaderOffset(pFileAccess); |
1551 if (offset == -1) { | 1551 if (offset == -1) { |
1552 return PDFPARSE_ERROR_FORMAT; | 1552 return PDFPARSE_ERROR_FORMAT; |
1553 } | 1553 } |
1554 if (!IsLinearizedFile(pFileAccess, offset)) { | 1554 if (!IsLinearizedFile(pFileAccess, offset)) { |
1555 m_Syntax.m_pFileAccess = NULL; | 1555 m_Syntax.m_pFileAccess = NULL; |
1556 return StartParse(pFileAccess, bReParse, bOwnFileRead); | 1556 return StartParse(pFileAccess, bReParse, bOwnFileRead); |
1557 } | 1557 } |
1558 if (!bReParse) { | 1558 if (!bReParse) { |
1559 m_pDocument = new CPDF_Document(this); | 1559 m_pDocument = new CPDF_Document(this); |
1560 } | 1560 } |
1561 FX_FILESIZE dwFirstXRefOffset = m_Syntax.SavePos(); | 1561 FX_FILESIZE dwFirstXRefOffset = m_Syntax.SavePos(); |
1562 FX_BOOL bXRefRebuilt = FALSE; | 1562 bool bXRefRebuilt = false; |
1563 FX_BOOL bLoadV4 = FALSE; | 1563 bool bLoadV4 = false; |
1564 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE, FALSE)) && !Load
CrossRefV5(dwFirstXRefOffset, dwFirstXRefOffset, TRUE)) { | 1564 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, false, false)) && !Load
CrossRefV5(dwFirstXRefOffset, dwFirstXRefOffset, true)) { |
1565 if (!RebuildCrossRef()) { | 1565 if (!RebuildCrossRef()) { |
1566 return PDFPARSE_ERROR_FORMAT; | 1566 return PDFPARSE_ERROR_FORMAT; |
1567 } | 1567 } |
1568 bXRefRebuilt = TRUE; | 1568 bXRefRebuilt = true; |
1569 m_LastXRefOffset = 0; | 1569 m_LastXRefOffset = 0; |
1570 } | 1570 } |
1571 if (bLoadV4) { | 1571 if (bLoadV4) { |
1572 m_pTrailer = LoadTrailerV4(); | 1572 m_pTrailer = LoadTrailerV4(); |
1573 if (m_pTrailer == NULL) { | 1573 if (m_pTrailer == NULL) { |
1574 return FALSE; | 1574 return false; |
1575 } | 1575 } |
1576 int32_t xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size")); | 1576 int32_t xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size")); |
1577 if (xrefsize > 0) { | 1577 if (xrefsize > 0) { |
1578 m_CrossRef.SetSize(xrefsize); | 1578 m_CrossRef.SetSize(xrefsize); |
1579 m_V5Type.SetSize(xrefsize); | 1579 m_V5Type.SetSize(xrefsize); |
1580 } | 1580 } |
1581 } | 1581 } |
1582 FX_DWORD dwRet = SetEncryptHandler(); | 1582 FX_DWORD dwRet = SetEncryptHandler(); |
1583 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 1583 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
1584 return dwRet; | 1584 return dwRet; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 } | 1616 } |
1617 } | 1617 } |
1618 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { | 1618 if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { |
1619 CPDF_Object* pMetadata = m_pDocument->GetRoot()->GetElement(FX_BSTRC("Me
tadata")); | 1619 CPDF_Object* pMetadata = m_pDocument->GetRoot()->GetElement(FX_BSTRC("Me
tadata")); |
1620 if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) { | 1620 if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) { |
1621 m_Syntax.m_MetadataObjnum = ((CPDF_Reference*) pMetadata)->GetRefObj
Num(); | 1621 m_Syntax.m_MetadataObjnum = ((CPDF_Reference*) pMetadata)->GetRefObj
Num(); |
1622 } | 1622 } |
1623 } | 1623 } |
1624 return PDFPARSE_ERROR_SUCCESS; | 1624 return PDFPARSE_ERROR_SUCCESS; |
1625 } | 1625 } |
1626 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) | 1626 bool CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) |
1627 { | 1627 { |
1628 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { | 1628 if (!LoadCrossRefV5(xrefpos, xrefpos, false)) { |
1629 return FALSE; | 1629 return false; |
1630 } | 1630 } |
1631 while (xrefpos) | 1631 while (xrefpos) |
1632 if (!LoadCrossRefV5(xrefpos, xrefpos, FALSE)) { | 1632 if (!LoadCrossRefV5(xrefpos, xrefpos, false)) { |
1633 return FALSE; | 1633 return false; |
1634 } | 1634 } |
1635 m_ObjectStreamMap.InitHashTable(101, FALSE); | 1635 m_ObjectStreamMap.InitHashTable(101, false); |
1636 m_bXRefStream = TRUE; | 1636 m_bXRefStream = true; |
1637 return TRUE; | 1637 return true; |
1638 } | 1638 } |
1639 FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() | 1639 FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() |
1640 { | 1640 { |
1641 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum; | 1641 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum; |
1642 m_Syntax.m_MetadataObjnum = 0; | 1642 m_Syntax.m_MetadataObjnum = 0; |
1643 if (m_pTrailer) { | 1643 if (m_pTrailer) { |
1644 m_pTrailer->Release(); | 1644 m_pTrailer->Release(); |
1645 m_pTrailer = NULL; | 1645 m_pTrailer = NULL; |
1646 } | 1646 } |
1647 m_Syntax.RestorePos(m_LastXRefOffset - m_Syntax.m_HeaderOffset); | 1647 m_Syntax.RestorePos(m_LastXRefOffset - m_Syntax.m_HeaderOffset); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 | 1681 |
1682 CPDF_SyntaxParser::CPDF_SyntaxParser() | 1682 CPDF_SyntaxParser::CPDF_SyntaxParser() |
1683 { | 1683 { |
1684 m_pFileAccess = NULL; | 1684 m_pFileAccess = NULL; |
1685 m_pCryptoHandler = NULL; | 1685 m_pCryptoHandler = NULL; |
1686 m_pFileBuf = NULL; | 1686 m_pFileBuf = NULL; |
1687 m_BufSize = CPDF_ModuleMgr::kFileBufSize; | 1687 m_BufSize = CPDF_ModuleMgr::kFileBufSize; |
1688 m_pFileBuf = NULL; | 1688 m_pFileBuf = NULL; |
1689 m_MetadataObjnum = 0; | 1689 m_MetadataObjnum = 0; |
1690 m_dwWordPos = 0; | 1690 m_dwWordPos = 0; |
1691 m_bFileStream = FALSE; | 1691 m_bFileStream = false; |
1692 } | 1692 } |
1693 CPDF_SyntaxParser::~CPDF_SyntaxParser() | 1693 CPDF_SyntaxParser::~CPDF_SyntaxParser() |
1694 { | 1694 { |
1695 if (m_pFileBuf) { | 1695 if (m_pFileBuf) { |
1696 FX_Free(m_pFileBuf); | 1696 FX_Free(m_pFileBuf); |
1697 } | 1697 } |
1698 } | 1698 } |
1699 FX_BOOL CPDF_SyntaxParser::GetCharAt(FX_FILESIZE pos, uint8_t& ch) | 1699 bool CPDF_SyntaxParser::GetCharAt(FX_FILESIZE pos, uint8_t& ch) |
1700 { | 1700 { |
1701 FX_FILESIZE save_pos = m_Pos; | 1701 FX_FILESIZE save_pos = m_Pos; |
1702 m_Pos = pos; | 1702 m_Pos = pos; |
1703 FX_BOOL ret = GetNextChar(ch); | 1703 bool ret = GetNextChar(ch); |
1704 m_Pos = save_pos; | 1704 m_Pos = save_pos; |
1705 return ret; | 1705 return ret; |
1706 } | 1706 } |
1707 FX_BOOL CPDF_SyntaxParser::GetNextChar(uint8_t& ch) | 1707 bool CPDF_SyntaxParser::GetNextChar(uint8_t& ch) |
1708 { | 1708 { |
1709 FX_FILESIZE pos = m_Pos + m_HeaderOffset; | 1709 FX_FILESIZE pos = m_Pos + m_HeaderOffset; |
1710 if (pos >= m_FileLen) { | 1710 if (pos >= m_FileLen) { |
1711 return FALSE; | 1711 return false; |
1712 } | 1712 } |
1713 if (m_BufOffset >= pos || (FX_FILESIZE)(m_BufOffset + m_BufSize) <= pos) { | 1713 if (m_BufOffset >= pos || (FX_FILESIZE)(m_BufOffset + m_BufSize) <= pos) { |
1714 FX_FILESIZE read_pos = pos; | 1714 FX_FILESIZE read_pos = pos; |
1715 FX_DWORD read_size = m_BufSize; | 1715 FX_DWORD read_size = m_BufSize; |
1716 if ((FX_FILESIZE)read_size > m_FileLen) { | 1716 if ((FX_FILESIZE)read_size > m_FileLen) { |
1717 read_size = (FX_DWORD)m_FileLen; | 1717 read_size = (FX_DWORD)m_FileLen; |
1718 } | 1718 } |
1719 if ((FX_FILESIZE)(read_pos + read_size) > m_FileLen) { | 1719 if ((FX_FILESIZE)(read_pos + read_size) > m_FileLen) { |
1720 if (m_FileLen < (FX_FILESIZE)read_size) { | 1720 if (m_FileLen < (FX_FILESIZE)read_size) { |
1721 read_pos = 0; | 1721 read_pos = 0; |
1722 read_size = (FX_DWORD)m_FileLen; | 1722 read_size = (FX_DWORD)m_FileLen; |
1723 } else { | 1723 } else { |
1724 read_pos = m_FileLen - read_size; | 1724 read_pos = m_FileLen - read_size; |
1725 } | 1725 } |
1726 } | 1726 } |
1727 if (!m_pFileAccess->ReadBlock(m_pFileBuf, read_pos, read_size)) { | 1727 if (!m_pFileAccess->ReadBlock(m_pFileBuf, read_pos, read_size)) { |
1728 return FALSE; | 1728 return false; |
1729 } | 1729 } |
1730 m_BufOffset = read_pos; | 1730 m_BufOffset = read_pos; |
1731 } | 1731 } |
1732 ch = m_pFileBuf[pos - m_BufOffset]; | 1732 ch = m_pFileBuf[pos - m_BufOffset]; |
1733 m_Pos ++; | 1733 m_Pos ++; |
1734 return TRUE; | 1734 return true; |
1735 } | 1735 } |
1736 FX_BOOL CPDF_SyntaxParser::GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch) | 1736 bool CPDF_SyntaxParser::GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch) |
1737 { | 1737 { |
1738 pos += m_HeaderOffset; | 1738 pos += m_HeaderOffset; |
1739 if (pos >= m_FileLen) { | 1739 if (pos >= m_FileLen) { |
1740 return FALSE; | 1740 return false; |
1741 } | 1741 } |
1742 if (m_BufOffset >= pos || (FX_FILESIZE)(m_BufOffset + m_BufSize) <= pos) { | 1742 if (m_BufOffset >= pos || (FX_FILESIZE)(m_BufOffset + m_BufSize) <= pos) { |
1743 FX_FILESIZE read_pos; | 1743 FX_FILESIZE read_pos; |
1744 if (pos < (FX_FILESIZE)m_BufSize) { | 1744 if (pos < (FX_FILESIZE)m_BufSize) { |
1745 read_pos = 0; | 1745 read_pos = 0; |
1746 } else { | 1746 } else { |
1747 read_pos = pos - m_BufSize + 1; | 1747 read_pos = pos - m_BufSize + 1; |
1748 } | 1748 } |
1749 FX_DWORD read_size = m_BufSize; | 1749 FX_DWORD read_size = m_BufSize; |
1750 if ((FX_FILESIZE)(read_pos + read_size) > m_FileLen) { | 1750 if ((FX_FILESIZE)(read_pos + read_size) > m_FileLen) { |
1751 if (m_FileLen < (FX_FILESIZE)read_size) { | 1751 if (m_FileLen < (FX_FILESIZE)read_size) { |
1752 read_pos = 0; | 1752 read_pos = 0; |
1753 read_size = (FX_DWORD)m_FileLen; | 1753 read_size = (FX_DWORD)m_FileLen; |
1754 } else { | 1754 } else { |
1755 read_pos = m_FileLen - read_size; | 1755 read_pos = m_FileLen - read_size; |
1756 } | 1756 } |
1757 } | 1757 } |
1758 if (!m_pFileAccess->ReadBlock(m_pFileBuf, read_pos, read_size)) { | 1758 if (!m_pFileAccess->ReadBlock(m_pFileBuf, read_pos, read_size)) { |
1759 return FALSE; | 1759 return false; |
1760 } | 1760 } |
1761 m_BufOffset = read_pos; | 1761 m_BufOffset = read_pos; |
1762 } | 1762 } |
1763 ch = m_pFileBuf[pos - m_BufOffset]; | 1763 ch = m_pFileBuf[pos - m_BufOffset]; |
1764 return TRUE; | 1764 return true; |
1765 } | 1765 } |
1766 FX_BOOL CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, FX_DWORD size) | 1766 bool CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, FX_DWORD size) |
1767 { | 1767 { |
1768 if (!m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size)) { | 1768 if (!m_pFileAccess->ReadBlock(pBuf, m_Pos + m_HeaderOffset, size)) { |
1769 return FALSE; | 1769 return false; |
1770 } | 1770 } |
1771 m_Pos += size; | 1771 m_Pos += size; |
1772 return TRUE; | 1772 return true; |
1773 } | 1773 } |
1774 #define MAX_WORD_BUFFER 256 | 1774 #define MAX_WORD_BUFFER 256 |
1775 void CPDF_SyntaxParser::GetNextWord() | 1775 void CPDF_SyntaxParser::GetNextWord() |
1776 { | 1776 { |
1777 m_WordSize = 0; | 1777 m_WordSize = 0; |
1778 m_bIsNumber = TRUE; | 1778 m_bIsNumber = true; |
1779 uint8_t ch; | 1779 uint8_t ch; |
1780 if (!GetNextChar(ch)) { | 1780 if (!GetNextChar(ch)) { |
1781 return; | 1781 return; |
1782 } | 1782 } |
1783 uint8_t type = PDF_CharType[ch]; | 1783 uint8_t type = PDF_CharType[ch]; |
1784 while (1) { | 1784 while (1) { |
1785 while (type == 'W') { | 1785 while (type == 'W') { |
1786 if (!GetNextChar(ch)) { | 1786 if (!GetNextChar(ch)) { |
1787 return; | 1787 return; |
1788 } | 1788 } |
1789 type = PDF_CharType[ch]; | 1789 type = PDF_CharType[ch]; |
1790 } | 1790 } |
1791 if (ch != '%') { | 1791 if (ch != '%') { |
1792 break; | 1792 break; |
1793 } | 1793 } |
1794 while (1) { | 1794 while (1) { |
1795 if (!GetNextChar(ch)) { | 1795 if (!GetNextChar(ch)) { |
1796 return; | 1796 return; |
1797 } | 1797 } |
1798 if (ch == '\r' || ch == '\n') { | 1798 if (ch == '\r' || ch == '\n') { |
1799 break; | 1799 break; |
1800 } | 1800 } |
1801 } | 1801 } |
1802 type = PDF_CharType[ch]; | 1802 type = PDF_CharType[ch]; |
1803 } | 1803 } |
1804 if (type == 'D') { | 1804 if (type == 'D') { |
1805 m_bIsNumber = FALSE; | 1805 m_bIsNumber = false; |
1806 m_WordBuffer[m_WordSize++] = ch; | 1806 m_WordBuffer[m_WordSize++] = ch; |
1807 if (ch == '/') { | 1807 if (ch == '/') { |
1808 while (1) { | 1808 while (1) { |
1809 if (!GetNextChar(ch)) { | 1809 if (!GetNextChar(ch)) { |
1810 return; | 1810 return; |
1811 } | 1811 } |
1812 type = PDF_CharType[ch]; | 1812 type = PDF_CharType[ch]; |
1813 if (type != 'R' && type != 'N') { | 1813 if (type != 'R' && type != 'N') { |
1814 m_Pos --; | 1814 m_Pos --; |
1815 return; | 1815 return; |
(...skipping 21 matching lines...) Expand all Loading... |
1837 m_Pos --; | 1837 m_Pos --; |
1838 } | 1838 } |
1839 } | 1839 } |
1840 return; | 1840 return; |
1841 } | 1841 } |
1842 while (1) { | 1842 while (1) { |
1843 if (m_WordSize < MAX_WORD_BUFFER) { | 1843 if (m_WordSize < MAX_WORD_BUFFER) { |
1844 m_WordBuffer[m_WordSize++] = ch; | 1844 m_WordBuffer[m_WordSize++] = ch; |
1845 } | 1845 } |
1846 if (type != 'N') { | 1846 if (type != 'N') { |
1847 m_bIsNumber = FALSE; | 1847 m_bIsNumber = false; |
1848 } | 1848 } |
1849 if (!GetNextChar(ch)) { | 1849 if (!GetNextChar(ch)) { |
1850 return; | 1850 return; |
1851 } | 1851 } |
1852 type = PDF_CharType[ch]; | 1852 type = PDF_CharType[ch]; |
1853 if (type == 'D' || type == 'W') { | 1853 if (type == 'D' || type == 'W') { |
1854 m_Pos --; | 1854 m_Pos --; |
1855 break; | 1855 break; |
1856 } | 1856 } |
1857 } | 1857 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 GetNextChar(ch); | 1943 GetNextChar(ch); |
1944 return buf.GetByteString(); | 1944 return buf.GetByteString(); |
1945 } | 1945 } |
1946 CFX_ByteString CPDF_SyntaxParser::ReadHexString() | 1946 CFX_ByteString CPDF_SyntaxParser::ReadHexString() |
1947 { | 1947 { |
1948 uint8_t ch; | 1948 uint8_t ch; |
1949 if (!GetNextChar(ch)) { | 1949 if (!GetNextChar(ch)) { |
1950 return CFX_ByteString(); | 1950 return CFX_ByteString(); |
1951 } | 1951 } |
1952 CFX_BinaryBuf buf; | 1952 CFX_BinaryBuf buf; |
1953 FX_BOOL bFirst = TRUE; | 1953 bool bFirst = true; |
1954 uint8_t code = 0; | 1954 uint8_t code = 0; |
1955 while (1) { | 1955 while (1) { |
1956 if (ch == '>') { | 1956 if (ch == '>') { |
1957 break; | 1957 break; |
1958 } | 1958 } |
1959 if (ch >= '0' && ch <= '9') { | 1959 if (ch >= '0' && ch <= '9') { |
1960 if (bFirst) { | 1960 if (bFirst) { |
1961 code = (ch - '0') * 16; | 1961 code = (ch - '0') * 16; |
1962 } else { | 1962 } else { |
1963 code += ch - '0'; | 1963 code += ch - '0'; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2034 return; | 2034 return; |
2035 } | 2035 } |
2036 if (ch == '\r' || ch == '\n') { | 2036 if (ch == '\r' || ch == '\n') { |
2037 break; | 2037 break; |
2038 } | 2038 } |
2039 } | 2039 } |
2040 type = PDF_CharType[ch]; | 2040 type = PDF_CharType[ch]; |
2041 } | 2041 } |
2042 m_Pos --; | 2042 m_Pos --; |
2043 } | 2043 } |
2044 CFX_ByteString CPDF_SyntaxParser::GetNextWord(FX_BOOL& bIsNumber) | 2044 CFX_ByteString CPDF_SyntaxParser::GetNextWord(bool& bIsNumber) |
2045 { | 2045 { |
2046 GetNextWord(); | 2046 GetNextWord(); |
2047 bIsNumber = m_bIsNumber; | 2047 bIsNumber = m_bIsNumber; |
2048 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); | 2048 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); |
2049 } | 2049 } |
2050 CFX_ByteString CPDF_SyntaxParser::GetKeyword() | 2050 CFX_ByteString CPDF_SyntaxParser::GetKeyword() |
2051 { | 2051 { |
2052 GetNextWord(); | 2052 GetNextWord(); |
2053 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); | 2053 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); |
2054 } | 2054 } |
2055 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO
RD objnum, FX_DWORD gennum, PARSE_CONTEXT* pContext, FX_BOOL bDecrypt) | 2055 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO
RD objnum, FX_DWORD gennum, PARSE_CONTEXT* pContext, bool bDecrypt) |
2056 { | 2056 { |
2057 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2057 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
2058 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2058 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
2059 return NULL; | 2059 return NULL; |
2060 } | 2060 } |
2061 FX_FILESIZE SavedPos = m_Pos; | 2061 FX_FILESIZE SavedPos = m_Pos; |
2062 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2062 bool bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
2063 FX_BOOL bIsNumber; | 2063 bool bIsNumber; |
2064 CFX_ByteString word = GetNextWord(bIsNumber); | 2064 CFX_ByteString word = GetNextWord(bIsNumber); |
2065 if (word.GetLength() == 0) { | 2065 if (word.GetLength() == 0) { |
2066 if (bTypeOnly) { | 2066 if (bTypeOnly) { |
2067 return (CPDF_Object*)PDFOBJ_INVALID; | 2067 return (CPDF_Object*)PDFOBJ_INVALID; |
2068 } | 2068 } |
2069 return NULL; | 2069 return NULL; |
2070 } | 2070 } |
2071 if (bIsNumber) { | 2071 if (bIsNumber) { |
2072 FX_FILESIZE SavedPos = m_Pos; | 2072 FX_FILESIZE SavedPos = m_Pos; |
2073 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2073 CFX_ByteString nextword = GetNextWord(bIsNumber); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2107 return CPDF_Null::Create(); | 2107 return CPDF_Null::Create(); |
2108 } | 2108 } |
2109 if (word == FX_BSTRC("(")) { | 2109 if (word == FX_BSTRC("(")) { |
2110 if (bTypeOnly) { | 2110 if (bTypeOnly) { |
2111 return (CPDF_Object*)PDFOBJ_STRING; | 2111 return (CPDF_Object*)PDFOBJ_STRING; |
2112 } | 2112 } |
2113 CFX_ByteString str = ReadString(); | 2113 CFX_ByteString str = ReadString(); |
2114 if (m_pCryptoHandler && bDecrypt) { | 2114 if (m_pCryptoHandler && bDecrypt) { |
2115 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2115 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2116 } | 2116 } |
2117 return CPDF_String::Create(str, FALSE); | 2117 return CPDF_String::Create(str, false); |
2118 } | 2118 } |
2119 if (word == FX_BSTRC("<")) { | 2119 if (word == FX_BSTRC("<")) { |
2120 if (bTypeOnly) { | 2120 if (bTypeOnly) { |
2121 return (CPDF_Object*)PDFOBJ_STRING; | 2121 return (CPDF_Object*)PDFOBJ_STRING; |
2122 } | 2122 } |
2123 CFX_ByteString str = ReadHexString(); | 2123 CFX_ByteString str = ReadHexString(); |
2124 if (m_pCryptoHandler && bDecrypt) { | 2124 if (m_pCryptoHandler && bDecrypt) { |
2125 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2125 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2126 } | 2126 } |
2127 return CPDF_String::Create(str, TRUE); | 2127 return CPDF_String::Create(str, true); |
2128 } | 2128 } |
2129 if (word == FX_BSTRC("[")) { | 2129 if (word == FX_BSTRC("[")) { |
2130 if (bTypeOnly) { | 2130 if (bTypeOnly) { |
2131 return (CPDF_Object*)PDFOBJ_ARRAY; | 2131 return (CPDF_Object*)PDFOBJ_ARRAY; |
2132 } | 2132 } |
2133 CPDF_Array* pArray = CPDF_Array::Create(); | 2133 CPDF_Array* pArray = CPDF_Array::Create(); |
2134 while (1) { | 2134 while (1) { |
2135 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); | 2135 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); |
2136 if (pObj == NULL) { | 2136 if (pObj == NULL) { |
2137 return pArray; | 2137 return pArray; |
(...skipping 12 matching lines...) Expand all Loading... |
2150 if (bTypeOnly) { | 2150 if (bTypeOnly) { |
2151 return (CPDF_Object*)PDFOBJ_DICTIONARY; | 2151 return (CPDF_Object*)PDFOBJ_DICTIONARY; |
2152 } | 2152 } |
2153 if (pContext) { | 2153 if (pContext) { |
2154 pContext->m_DictStart = SavedPos; | 2154 pContext->m_DictStart = SavedPos; |
2155 } | 2155 } |
2156 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); | 2156 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); |
2157 int32_t nKeys = 0; | 2157 int32_t nKeys = 0; |
2158 FX_FILESIZE dwSignValuePos = 0; | 2158 FX_FILESIZE dwSignValuePos = 0; |
2159 while (1) { | 2159 while (1) { |
2160 FX_BOOL bIsNumber; | 2160 bool bIsNumber; |
2161 CFX_ByteString key = GetNextWord(bIsNumber); | 2161 CFX_ByteString key = GetNextWord(bIsNumber); |
2162 if (key.IsEmpty()) { | 2162 if (key.IsEmpty()) { |
2163 if (pDict) | 2163 if (pDict) |
2164 pDict->Release(); | 2164 pDict->Release(); |
2165 return NULL; | 2165 return NULL; |
2166 } | 2166 } |
2167 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); | 2167 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); |
2168 if (key == FX_BSTRC(">>")) { | 2168 if (key == FX_BSTRC(">>")) { |
2169 break; | 2169 break; |
2170 } | 2170 } |
(...skipping 17 matching lines...) Expand all Loading... |
2188 if (nKeys < 32) { | 2188 if (nKeys < 32) { |
2189 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength(
) - 1), pObj); | 2189 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength(
) - 1), pObj); |
2190 } else { | 2190 } else { |
2191 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLeng
th() - 1), pObj); | 2191 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLeng
th() - 1), pObj); |
2192 } | 2192 } |
2193 } | 2193 } |
2194 } | 2194 } |
2195 if (IsSignatureDict(pDict)) { | 2195 if (IsSignatureDict(pDict)) { |
2196 FX_FILESIZE dwSavePos = m_Pos; | 2196 FX_FILESIZE dwSavePos = m_Pos; |
2197 m_Pos = dwSignValuePos; | 2197 m_Pos = dwSignValuePos; |
2198 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, NULL, FALSE)
; | 2198 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, NULL, false)
; |
2199 pDict->SetAt(FX_BSTRC("Contents"), pObj); | 2199 pDict->SetAt(FX_BSTRC("Contents"), pObj); |
2200 m_Pos = dwSavePos; | 2200 m_Pos = dwSavePos; |
2201 } | 2201 } |
2202 if (pContext) { | 2202 if (pContext) { |
2203 pContext->m_DictEnd = m_Pos; | 2203 pContext->m_DictEnd = m_Pos; |
2204 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2204 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
2205 return pDict; | 2205 return pDict; |
2206 } | 2206 } |
2207 } | 2207 } |
2208 FX_FILESIZE SavedPos = m_Pos; | 2208 FX_FILESIZE SavedPos = m_Pos; |
2209 FX_BOOL bIsNumber; | 2209 bool bIsNumber; |
2210 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2210 CFX_ByteString nextword = GetNextWord(bIsNumber); |
2211 if (nextword == FX_BSTRC("stream")) { | 2211 if (nextword == FX_BSTRC("stream")) { |
2212 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); | 2212 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); |
2213 if (pStream) { | 2213 if (pStream) { |
2214 return pStream; | 2214 return pStream; |
2215 } | 2215 } |
2216 if (pDict) | 2216 if (pDict) |
2217 pDict->Release(); | 2217 pDict->Release(); |
2218 return NULL; | 2218 return NULL; |
2219 } else { | 2219 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
2230 } | 2230 } |
2231 return NULL; | 2231 return NULL; |
2232 } | 2232 } |
2233 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList
, FX_DWORD objnum, FX_DWORD gennum, struct PARSE_CONTEXT* pContext) | 2233 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList
, FX_DWORD objnum, FX_DWORD gennum, struct PARSE_CONTEXT* pContext) |
2234 { | 2234 { |
2235 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2235 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
2236 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2236 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
2237 return NULL; | 2237 return NULL; |
2238 } | 2238 } |
2239 FX_FILESIZE SavedPos = m_Pos; | 2239 FX_FILESIZE SavedPos = m_Pos; |
2240 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2240 bool bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
2241 FX_BOOL bIsNumber; | 2241 bool bIsNumber; |
2242 CFX_ByteString word = GetNextWord(bIsNumber); | 2242 CFX_ByteString word = GetNextWord(bIsNumber); |
2243 if (word.GetLength() == 0) { | 2243 if (word.GetLength() == 0) { |
2244 if (bTypeOnly) { | 2244 if (bTypeOnly) { |
2245 return (CPDF_Object*)PDFOBJ_INVALID; | 2245 return (CPDF_Object*)PDFOBJ_INVALID; |
2246 } | 2246 } |
2247 return NULL; | 2247 return NULL; |
2248 } | 2248 } |
2249 if (bIsNumber) { | 2249 if (bIsNumber) { |
2250 FX_FILESIZE SavedPos = m_Pos; | 2250 FX_FILESIZE SavedPos = m_Pos; |
2251 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2251 CFX_ByteString nextword = GetNextWord(bIsNumber); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 return CPDF_Null::Create(); | 2285 return CPDF_Null::Create(); |
2286 } | 2286 } |
2287 if (word == FX_BSTRC("(")) { | 2287 if (word == FX_BSTRC("(")) { |
2288 if (bTypeOnly) { | 2288 if (bTypeOnly) { |
2289 return (CPDF_Object*)PDFOBJ_STRING; | 2289 return (CPDF_Object*)PDFOBJ_STRING; |
2290 } | 2290 } |
2291 CFX_ByteString str = ReadString(); | 2291 CFX_ByteString str = ReadString(); |
2292 if (m_pCryptoHandler) { | 2292 if (m_pCryptoHandler) { |
2293 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2293 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2294 } | 2294 } |
2295 return CPDF_String::Create(str, FALSE); | 2295 return CPDF_String::Create(str, false); |
2296 } | 2296 } |
2297 if (word == FX_BSTRC("<")) { | 2297 if (word == FX_BSTRC("<")) { |
2298 if (bTypeOnly) { | 2298 if (bTypeOnly) { |
2299 return (CPDF_Object*)PDFOBJ_STRING; | 2299 return (CPDF_Object*)PDFOBJ_STRING; |
2300 } | 2300 } |
2301 CFX_ByteString str = ReadHexString(); | 2301 CFX_ByteString str = ReadHexString(); |
2302 if (m_pCryptoHandler) { | 2302 if (m_pCryptoHandler) { |
2303 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2303 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2304 } | 2304 } |
2305 return CPDF_String::Create(str, TRUE); | 2305 return CPDF_String::Create(str, true); |
2306 } | 2306 } |
2307 if (word == FX_BSTRC("[")) { | 2307 if (word == FX_BSTRC("[")) { |
2308 if (bTypeOnly) { | 2308 if (bTypeOnly) { |
2309 return (CPDF_Object*)PDFOBJ_ARRAY; | 2309 return (CPDF_Object*)PDFOBJ_ARRAY; |
2310 } | 2310 } |
2311 CPDF_Array* pArray = CPDF_Array::Create(); | 2311 CPDF_Array* pArray = CPDF_Array::Create(); |
2312 while (1) { | 2312 while (1) { |
2313 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); | 2313 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); |
2314 if (pObj == NULL) { | 2314 if (pObj == NULL) { |
2315 if (m_WordBuffer[0] == ']') { | 2315 if (m_WordBuffer[0] == ']') { |
(...skipping 15 matching lines...) Expand all Loading... |
2331 } | 2331 } |
2332 if (word == FX_BSTRC("<<")) { | 2332 if (word == FX_BSTRC("<<")) { |
2333 if (bTypeOnly) { | 2333 if (bTypeOnly) { |
2334 return (CPDF_Object*)PDFOBJ_DICTIONARY; | 2334 return (CPDF_Object*)PDFOBJ_DICTIONARY; |
2335 } | 2335 } |
2336 if (pContext) { | 2336 if (pContext) { |
2337 pContext->m_DictStart = SavedPos; | 2337 pContext->m_DictStart = SavedPos; |
2338 } | 2338 } |
2339 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); | 2339 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); |
2340 while (1) { | 2340 while (1) { |
2341 FX_BOOL bIsNumber; | 2341 bool bIsNumber; |
2342 FX_FILESIZE SavedPos = m_Pos; | 2342 FX_FILESIZE SavedPos = m_Pos; |
2343 CFX_ByteString key = GetNextWord(bIsNumber); | 2343 CFX_ByteString key = GetNextWord(bIsNumber); |
2344 if (key.IsEmpty()) { | 2344 if (key.IsEmpty()) { |
2345 if (pDict) { | 2345 if (pDict) { |
2346 pDict->Release(); | 2346 pDict->Release(); |
2347 } | 2347 } |
2348 return NULL; | 2348 return NULL; |
2349 } | 2349 } |
2350 if (key == FX_BSTRC(">>")) { | 2350 if (key == FX_BSTRC(">>")) { |
2351 break; | 2351 break; |
(...skipping 26 matching lines...) Expand all Loading... |
2378 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLength()
- 1), pObj); | 2378 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLength()
- 1), pObj); |
2379 } | 2379 } |
2380 } | 2380 } |
2381 if (pContext) { | 2381 if (pContext) { |
2382 pContext->m_DictEnd = m_Pos; | 2382 pContext->m_DictEnd = m_Pos; |
2383 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2383 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
2384 return pDict; | 2384 return pDict; |
2385 } | 2385 } |
2386 } | 2386 } |
2387 FX_FILESIZE SavedPos = m_Pos; | 2387 FX_FILESIZE SavedPos = m_Pos; |
2388 FX_BOOL bIsNumber; | 2388 bool bIsNumber; |
2389 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2389 CFX_ByteString nextword = GetNextWord(bIsNumber); |
2390 if (nextword == FX_BSTRC("stream")) { | 2390 if (nextword == FX_BSTRC("stream")) { |
2391 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); | 2391 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); |
2392 if (pStream) { | 2392 if (pStream) { |
2393 return pStream; | 2393 return pStream; |
2394 } | 2394 } |
2395 if (pDict) { | 2395 if (pDict) { |
2396 pDict->Release(); | 2396 pDict->Release(); |
2397 } | 2397 } |
2398 return NULL; | 2398 return NULL; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2507 } | 2507 } |
2508 int32_t CPDF_SyntaxParser::GetDirectNum() | 2508 int32_t CPDF_SyntaxParser::GetDirectNum() |
2509 { | 2509 { |
2510 GetNextWord(); | 2510 GetNextWord(); |
2511 if (!m_bIsNumber) { | 2511 if (!m_bIsNumber) { |
2512 return 0; | 2512 return 0; |
2513 } | 2513 } |
2514 m_WordBuffer[m_WordSize] = 0; | 2514 m_WordBuffer[m_WordSize] = 0; |
2515 return FXSYS_atoi((const FX_CHAR*)m_WordBuffer); | 2515 return FXSYS_atoi((const FX_CHAR*)m_WordBuffer); |
2516 } | 2516 } |
2517 FX_BOOL CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, FX_FILESIZE limit,
const uint8_t* tag, FX_DWORD taglen) | 2517 bool CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, FX_FILESIZE limit, con
st uint8_t* tag, FX_DWORD taglen) |
2518 { | 2518 { |
2519 uint8_t type = PDF_CharType[tag[0]]; | 2519 uint8_t type = PDF_CharType[tag[0]]; |
2520 FX_BOOL bCheckLeft = type != 'D' && type != 'W'; | 2520 bool bCheckLeft = type != 'D' && type != 'W'; |
2521 type = PDF_CharType[tag[taglen - 1]]; | 2521 type = PDF_CharType[tag[taglen - 1]]; |
2522 FX_BOOL bCheckRight = type != 'D' && type != 'W'; | 2522 bool bCheckRight = type != 'D' && type != 'W'; |
2523 uint8_t ch; | 2523 uint8_t ch; |
2524 if (bCheckRight && startpos + (int32_t)taglen <= limit && GetCharAt(startpos
+ (int32_t)taglen, ch)) { | 2524 if (bCheckRight && startpos + (int32_t)taglen <= limit && GetCharAt(startpos
+ (int32_t)taglen, ch)) { |
2525 uint8_t type = PDF_CharType[ch]; | 2525 uint8_t type = PDF_CharType[ch]; |
2526 if (type == 'N' || type == 'R') { | 2526 if (type == 'N' || type == 'R') { |
2527 return FALSE; | 2527 return false; |
2528 } | 2528 } |
2529 } | 2529 } |
2530 if (bCheckLeft && startpos > 0 && GetCharAt(startpos - 1, ch)) { | 2530 if (bCheckLeft && startpos > 0 && GetCharAt(startpos - 1, ch)) { |
2531 uint8_t type = PDF_CharType[ch]; | 2531 uint8_t type = PDF_CharType[ch]; |
2532 if (type == 'N' || type == 'R') { | 2532 if (type == 'N' || type == 'R') { |
2533 return FALSE; | 2533 return false; |
2534 } | 2534 } |
2535 } | 2535 } |
2536 return TRUE; | 2536 return true; |
2537 } | 2537 } |
2538 FX_BOOL CPDF_SyntaxParser::SearchWord(const CFX_ByteStringC& tag, FX_BOOL bWhole
Word, FX_BOOL bForward, FX_FILESIZE limit) | 2538 bool CPDF_SyntaxParser::SearchWord(const CFX_ByteStringC& tag, bool bWholeWord,
bool bForward, FX_FILESIZE limit) |
2539 { | 2539 { |
2540 int32_t taglen = tag.GetLength(); | 2540 int32_t taglen = tag.GetLength(); |
2541 if (taglen == 0) { | 2541 if (taglen == 0) { |
2542 return FALSE; | 2542 return false; |
2543 } | 2543 } |
2544 FX_FILESIZE pos = m_Pos; | 2544 FX_FILESIZE pos = m_Pos; |
2545 int32_t offset = 0; | 2545 int32_t offset = 0; |
2546 if (!bForward) { | 2546 if (!bForward) { |
2547 offset = taglen - 1; | 2547 offset = taglen - 1; |
2548 } | 2548 } |
2549 const uint8_t* tag_data = tag.GetPtr(); | 2549 const uint8_t* tag_data = tag.GetPtr(); |
2550 uint8_t byte; | 2550 uint8_t byte; |
2551 while (1) { | 2551 while (1) { |
2552 if (bForward) { | 2552 if (bForward) { |
2553 if (limit) { | 2553 if (limit) { |
2554 if (pos >= m_Pos + limit) { | 2554 if (pos >= m_Pos + limit) { |
2555 return FALSE; | 2555 return false; |
2556 } | 2556 } |
2557 } | 2557 } |
2558 if (!GetCharAt(pos, byte)) { | 2558 if (!GetCharAt(pos, byte)) { |
2559 return FALSE; | 2559 return false; |
2560 } | 2560 } |
2561 } else { | 2561 } else { |
2562 if (limit) { | 2562 if (limit) { |
2563 if (pos <= m_Pos - limit) { | 2563 if (pos <= m_Pos - limit) { |
2564 return FALSE; | 2564 return false; |
2565 } | 2565 } |
2566 } | 2566 } |
2567 if (!GetCharAtBackward(pos, byte)) { | 2567 if (!GetCharAtBackward(pos, byte)) { |
2568 return FALSE; | 2568 return false; |
2569 } | 2569 } |
2570 } | 2570 } |
2571 if (byte == tag_data[offset]) { | 2571 if (byte == tag_data[offset]) { |
2572 if (bForward) { | 2572 if (bForward) { |
2573 offset ++; | 2573 offset ++; |
2574 if (offset < taglen) { | 2574 if (offset < taglen) { |
2575 pos ++; | 2575 pos ++; |
2576 continue; | 2576 continue; |
2577 } | 2577 } |
2578 } else { | 2578 } else { |
2579 offset --; | 2579 offset --; |
2580 if (offset >= 0) { | 2580 if (offset >= 0) { |
2581 pos --; | 2581 pos --; |
2582 continue; | 2582 continue; |
2583 } | 2583 } |
2584 } | 2584 } |
2585 FX_FILESIZE startpos = bForward ? pos - taglen + 1 : pos; | 2585 FX_FILESIZE startpos = bForward ? pos - taglen + 1 : pos; |
2586 if (!bWholeWord || IsWholeWord(startpos, limit, tag.GetPtr(), taglen
)) { | 2586 if (!bWholeWord || IsWholeWord(startpos, limit, tag.GetPtr(), taglen
)) { |
2587 m_Pos = startpos; | 2587 m_Pos = startpos; |
2588 return TRUE; | 2588 return true; |
2589 } | 2589 } |
2590 } | 2590 } |
2591 if (bForward) { | 2591 if (bForward) { |
2592 offset = byte == tag_data[0] ? 1 : 0; | 2592 offset = byte == tag_data[0] ? 1 : 0; |
2593 pos ++; | 2593 pos ++; |
2594 } else { | 2594 } else { |
2595 offset = byte == tag_data[taglen - 1] ? taglen - 2 : taglen - 1; | 2595 offset = byte == tag_data[taglen - 1] ? taglen - 2 : taglen - 1; |
2596 pos --; | 2596 pos --; |
2597 } | 2597 } |
2598 if (pos < 0) { | 2598 if (pos < 0) { |
2599 return FALSE; | 2599 return false; |
2600 } | 2600 } |
2601 } | 2601 } |
2602 return FALSE; | 2602 return false; |
2603 } | 2603 } |
2604 struct _SearchTagRecord { | 2604 struct _SearchTagRecord { |
2605 const uint8_t* m_pTag; | 2605 const uint8_t* m_pTag; |
2606 FX_DWORD m_Len; | 2606 FX_DWORD m_Len; |
2607 FX_DWORD m_Offset; | 2607 FX_DWORD m_Offset; |
2608 }; | 2608 }; |
2609 int32_t CPDF_SyntaxParser::SearchMultiWord(const CFX_ByteStringC& tags, FX_BOOL
bWholeWord, FX_FILESIZE limit) | 2609 int32_t CPDF_SyntaxParser::SearchMultiWord(const CFX_ByteStringC& tags, bool bWh
oleWord, FX_FILESIZE limit) |
2610 { | 2610 { |
2611 int32_t ntags = 1, i; | 2611 int32_t ntags = 1, i; |
2612 for (i = 0; i < tags.GetLength(); i ++) | 2612 for (i = 0; i < tags.GetLength(); i ++) |
2613 if (tags[i] == 0) { | 2613 if (tags[i] == 0) { |
2614 ntags ++; | 2614 ntags ++; |
2615 } | 2615 } |
2616 _SearchTagRecord* pPatterns = FX_Alloc(_SearchTagRecord, ntags); | 2616 _SearchTagRecord* pPatterns = FX_Alloc(_SearchTagRecord, ntags); |
2617 FX_DWORD start = 0, itag = 0, max_len = 0; | 2617 FX_DWORD start = 0, itag = 0, max_len = 0; |
2618 for (i = 0; i <= tags.GetLength(); i ++) { | 2618 for (i = 0; i <= tags.GetLength(); i ++) { |
2619 if (tags[i] == 0) { | 2619 if (tags[i] == 0) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2707 } | 2707 } |
2708 } | 2708 } |
2709 } | 2709 } |
2710 | 2710 |
2711 class CPDF_DataAvail final : public IPDF_DataAvail | 2711 class CPDF_DataAvail final : public IPDF_DataAvail |
2712 { | 2712 { |
2713 public: | 2713 public: |
2714 CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); | 2714 CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); |
2715 ~CPDF_DataAvail(); | 2715 ~CPDF_DataAvail(); |
2716 | 2716 |
2717 virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) o
verride; | 2717 virtual bool IsDocAvail(IFX_DownloadHints* pHints) over
ride; |
2718 | 2718 |
2719 virtual void SetDocument(CPDF_Document* pDoc) overri
de; | 2719 virtual void SetDocument(CPDF_Document* pDoc) overri
de; |
2720 | 2720 |
2721 virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints
* pHints) override; | 2721 virtual bool IsPageAvail(int iPage, IFX_DownloadHints* p
Hints) override; |
2722 | 2722 |
2723 virtual int32_t IsFormAvail(IFX_DownloadHints *pHints)
override; | 2723 virtual int32_t IsFormAvail(IFX_DownloadHints *pHints)
override; |
2724 | 2724 |
2725 virtual int32_t IsLinearizedPDF() override; | 2725 virtual int32_t IsLinearizedPDF() override; |
2726 | 2726 |
2727 virtual FX_BOOL IsLinearized() override | 2727 virtual bool IsLinearized() override |
2728 { | 2728 { |
2729 return m_bLinearized; | 2729 return m_bLinearized; |
2730 } | 2730 } |
2731 | 2731 |
2732 virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *p
Pos, FX_DWORD *pSize) override; | 2732 virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *p
Pos, FX_DWORD *pSize) override; |
2733 | 2733 |
2734 protected: | 2734 protected: |
2735 static const int kMaxDataAvailRecursionDepth = 64; | 2735 static const int kMaxDataAvailRecursionDepth = 64; |
2736 static int s_CurrentDataAvailRecursionDepth; | 2736 static int s_CurrentDataAvailRecursionDepth; |
2737 | 2737 |
2738 FX_DWORD GetObjectSize(FX_DWORD objnum, FX_FILESI
ZE& offset); | 2738 FX_DWORD GetObjectSize(FX_DWORD objnum, FX_FILESI
ZE& offset); |
2739 FX_BOOL IsObjectsAvail(CFX_PtrArray& obj_array,
FX_BOOL bParsePage, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array); | 2739 bool IsObjectsAvail(CFX_PtrArray& obj_array, boo
l bParsePage, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array); |
2740 FX_BOOL CheckDocStatus(IFX_DownloadHints *pHints
); | 2740 bool CheckDocStatus(IFX_DownloadHints *pHints); |
2741 FX_BOOL CheckHeader(IFX_DownloadHints* pHints); | 2741 bool CheckHeader(IFX_DownloadHints* pHints); |
2742 FX_BOOL CheckFirstPage(IFX_DownloadHints *pHints
); | 2742 bool CheckFirstPage(IFX_DownloadHints *pHints); |
2743 FX_BOOL CheckEnd(IFX_DownloadHints *pHints); | 2743 bool CheckEnd(IFX_DownloadHints *pHints); |
2744 FX_BOOL CheckCrossRef(IFX_DownloadHints* pHints)
; | 2744 bool CheckCrossRef(IFX_DownloadHints* pHints); |
2745 FX_BOOL CheckCrossRefItem(IFX_DownloadHints *pHi
nts); | 2745 bool CheckCrossRefItem(IFX_DownloadHints *pHints
); |
2746 FX_BOOL CheckTrailer(IFX_DownloadHints* pHints); | 2746 bool CheckTrailer(IFX_DownloadHints* pHints); |
2747 FX_BOOL CheckRoot(IFX_DownloadHints* pHints); | 2747 bool CheckRoot(IFX_DownloadHints* pHints); |
2748 FX_BOOL CheckInfo(IFX_DownloadHints* pHints); | 2748 bool CheckInfo(IFX_DownloadHints* pHints); |
2749 FX_BOOL CheckPages(IFX_DownloadHints* pHints); | 2749 bool CheckPages(IFX_DownloadHints* pHints); |
2750 FX_BOOL CheckPage(IFX_DownloadHints* pHints); | 2750 bool CheckPage(IFX_DownloadHints* pHints); |
2751 FX_BOOL CheckResources(IFX_DownloadHints* pHints
); | 2751 bool CheckResources(IFX_DownloadHints* pHints); |
2752 FX_BOOL CheckAnnots(IFX_DownloadHints* pHints); | 2752 bool CheckAnnots(IFX_DownloadHints* pHints); |
2753 FX_BOOL CheckAcroForm(IFX_DownloadHints* pHints)
; | 2753 bool CheckAcroForm(IFX_DownloadHints* pHints); |
2754 FX_BOOL CheckAcroFormSubObject(IFX_DownloadHints
* pHints); | 2754 bool CheckAcroFormSubObject(IFX_DownloadHints* p
Hints); |
2755 FX_BOOL CheckTrailerAppend(IFX_DownloadHints* pH
ints); | 2755 bool CheckTrailerAppend(IFX_DownloadHints* pHint
s); |
2756 FX_BOOL CheckPageStatus(IFX_DownloadHints* pHint
s); | 2756 bool CheckPageStatus(IFX_DownloadHints* pHints); |
2757 FX_BOOL CheckAllCrossRefStream(IFX_DownloadHints
*pHints); | 2757 bool CheckAllCrossRefStream(IFX_DownloadHints *p
Hints); |
2758 | 2758 |
2759 int32_t CheckCrossRefStream(IFX_DownloadHints *pH
ints, FX_FILESIZE &xref_offset); | 2759 int32_t CheckCrossRefStream(IFX_DownloadHints *pH
ints, FX_FILESIZE &xref_offset); |
2760 FX_BOOL IsLinearizedFile(uint8_t* pData, FX_DWOR
D dwLen); | 2760 bool IsLinearizedFile(uint8_t* pData, FX_DWORD d
wLen); |
2761 void SetStartOffset(FX_FILESIZE dwOffset); | 2761 void SetStartOffset(FX_FILESIZE dwOffset); |
2762 FX_BOOL GetNextToken(CFX_ByteString &token); | 2762 bool GetNextToken(CFX_ByteString &token); |
2763 FX_BOOL GetNextChar(uint8_t &ch); | 2763 bool GetNextChar(uint8_t &ch); |
2764 CPDF_Object * ParseIndirectObjectAt(FX_FILESIZE pos, F
X_DWORD objnum); | 2764 CPDF_Object * ParseIndirectObjectAt(FX_FILESIZE pos, F
X_DWORD objnum); |
2765 CPDF_Object»* GetObject(FX_DWORD objnum, IFX_DownloadH
ints* pHints, FX_BOOL *pExistInFile); | 2765 CPDF_Object»* GetObject(FX_DWORD objnum, IFX_DownloadH
ints* pHints, bool *pExistInFile); |
2766 FX_BOOL GetPageKids(CPDF_Parser *pParser, CPDF_O
bject *pPages); | 2766 bool GetPageKids(CPDF_Parser *pParser, CPDF_Obje
ct *pPages); |
2767 FX_BOOL PreparePageItem(); | 2767 bool PreparePageItem(); |
2768 FX_BOOL LoadPages(IFX_DownloadHints* pHints); | 2768 bool LoadPages(IFX_DownloadHints* pHints); |
2769 FX_BOOL LoadAllXref(IFX_DownloadHints* pHints); | 2769 bool LoadAllXref(IFX_DownloadHints* pHints); |
2770 FX_BOOL LoadAllFile(IFX_DownloadHints* pHints); | 2770 bool LoadAllFile(IFX_DownloadHints* pHints); |
2771 FX_BOOL CheckLinearizedData(IFX_DownloadHints* p
Hints); | 2771 bool CheckLinearizedData(IFX_DownloadHints* pHin
ts); |
2772 FX_BOOL CheckFileResources(IFX_DownloadHints* pH
ints); | 2772 bool CheckFileResources(IFX_DownloadHints* pHint
s); |
2773 FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadH
ints* pHints); | 2773 bool CheckPageAnnots(int iPage, IFX_DownloadHint
s* pHints); |
2774 | 2774 |
2775 FX_BOOL CheckLinearizedFirstPage(int iPage, IFX_
DownloadHints* pHints); | 2775 bool CheckLinearizedFirstPage(int iPage, IFX_Dow
nloadHints* pHints); |
2776 FX_BOOL HaveResourceAncestor(CPDF_Dictionary *pD
ict); | 2776 bool HaveResourceAncestor(CPDF_Dictionary *pDict
); |
2777 FX_BOOL CheckPage(int32_t iPage, IFX_DownloadHin
ts* pHints); | 2777 bool CheckPage(int32_t iPage, IFX_DownloadHints*
pHints); |
2778 FX_BOOL LoadDocPages(IFX_DownloadHints* pHints); | 2778 bool LoadDocPages(IFX_DownloadHints* pHints); |
2779 FX_BOOL LoadDocPage(int32_t iPage, IFX_DownloadH
ints* pHints); | 2779 bool LoadDocPage(int32_t iPage, IFX_DownloadHint
s* pHints); |
2780 FX_BOOL CheckPageNode(CPDF_PageNode &pageNodes,
int32_t iPage, int32_t &iCount, IFX_DownloadHints* pHints); | 2780 bool CheckPageNode(CPDF_PageNode &pageNodes, int
32_t iPage, int32_t &iCount, IFX_DownloadHints* pHints); |
2781 FX_BOOL CheckUnkownPageNode(FX_DWORD dwPageNo, C
PDF_PageNode *pPageNode, IFX_DownloadHints* pHints); | 2781 bool CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF
_PageNode *pPageNode, IFX_DownloadHints* pHints); |
2782 FX_BOOL CheckArrayPageNode(FX_DWORD dwPageNo, CP
DF_PageNode *pPageNode, IFX_DownloadHints* pHints); | 2782 bool CheckArrayPageNode(FX_DWORD dwPageNo, CPDF_
PageNode *pPageNode, IFX_DownloadHints* pHints); |
2783 FX_BOOL CheckPageCount(IFX_DownloadHints* pHints
); | 2783 bool CheckPageCount(IFX_DownloadHints* pHints); |
2784 FX_BOOL IsFirstCheck(int iPage); | 2784 bool IsFirstCheck(int iPage); |
2785 void ResetFirstCheck(int iPage); | 2785 void ResetFirstCheck(int iPage); |
2786 | 2786 |
2787 CPDF_Parser m_parser; | 2787 CPDF_Parser m_parser; |
2788 | 2788 |
2789 CPDF_SyntaxParser m_syntaxParser; | 2789 CPDF_SyntaxParser m_syntaxParser; |
2790 | 2790 |
2791 CPDF_Object *m_pRoot; | 2791 CPDF_Object *m_pRoot; |
2792 | 2792 |
2793 FX_DWORD m_dwRootObjNum; | 2793 FX_DWORD m_dwRootObjNum; |
2794 | 2794 |
2795 FX_DWORD m_dwInfoObjNum; | 2795 FX_DWORD m_dwInfoObjNum; |
2796 | 2796 |
2797 CPDF_Object *m_pLinearized; | 2797 CPDF_Object *m_pLinearized; |
2798 | 2798 |
2799 CPDF_Object *m_pTrailer; | 2799 CPDF_Object *m_pTrailer; |
2800 | 2800 |
2801 FX_BOOL m_bDocAvail; | 2801 bool m_bDocAvail; |
2802 | 2802 |
2803 FX_FILESIZE m_dwHeaderOffset; | 2803 FX_FILESIZE m_dwHeaderOffset; |
2804 | 2804 |
2805 FX_FILESIZE m_dwLastXRefOffset; | 2805 FX_FILESIZE m_dwLastXRefOffset; |
2806 | 2806 |
2807 FX_FILESIZE m_dwXRefOffset; | 2807 FX_FILESIZE m_dwXRefOffset; |
2808 | 2808 |
2809 FX_FILESIZE m_dwTrailerOffset; | 2809 FX_FILESIZE m_dwTrailerOffset; |
2810 | 2810 |
2811 FX_FILESIZE m_dwCurrentOffset; | 2811 FX_FILESIZE m_dwCurrentOffset; |
(...skipping 23 matching lines...) Expand all Loading... |
2835 uint8_t m_bufferData[512]; | 2835 uint8_t m_bufferData[512]; |
2836 | 2836 |
2837 CFX_FileSizeArray m_CrossOffset; | 2837 CFX_FileSizeArray m_CrossOffset; |
2838 | 2838 |
2839 CFX_DWordArray m_XRefStreamList; | 2839 CFX_DWordArray m_XRefStreamList; |
2840 | 2840 |
2841 CFX_DWordArray m_PageObjList; | 2841 CFX_DWordArray m_PageObjList; |
2842 | 2842 |
2843 FX_DWORD m_PagesObjNum; | 2843 FX_DWORD m_PagesObjNum; |
2844 | 2844 |
2845 FX_BOOL m_bLinearized; | 2845 bool m_bLinearized; |
2846 | 2846 |
2847 FX_DWORD m_dwFirstPageNo; | 2847 FX_DWORD m_dwFirstPageNo; |
2848 | 2848 |
2849 FX_BOOL m_bLinearedDataOK; | 2849 bool m_bLinearedDataOK; |
2850 | 2850 |
2851 FX_BOOL m_bMainXRefLoadTried; | 2851 bool m_bMainXRefLoadTried; |
2852 | 2852 |
2853 FX_BOOL m_bMainXRefLoadedOK; | 2853 bool m_bMainXRefLoadedOK; |
2854 | 2854 |
2855 FX_BOOL m_bPagesTreeLoad; | 2855 bool m_bPagesTreeLoad; |
2856 | 2856 |
2857 FX_BOOL m_bPagesLoad; | 2857 bool m_bPagesLoad; |
2858 | 2858 |
2859 CPDF_Parser * m_pCurrentParser; | 2859 CPDF_Parser * m_pCurrentParser; |
2860 | 2860 |
2861 FX_FILESIZE m_dwCurrentXRefSteam; | 2861 FX_FILESIZE m_dwCurrentXRefSteam; |
2862 | 2862 |
2863 FX_BOOL m_bAnnotsLoad; | 2863 bool m_bAnnotsLoad; |
2864 | 2864 |
2865 FX_BOOL m_bHaveAcroForm; | 2865 bool m_bHaveAcroForm; |
2866 | 2866 |
2867 FX_DWORD m_dwAcroFormObjNum; | 2867 FX_DWORD m_dwAcroFormObjNum; |
2868 | 2868 |
2869 FX_BOOL m_bAcroFormLoad; | 2869 bool m_bAcroFormLoad; |
2870 | 2870 |
2871 CPDF_Object * m_pAcroForm; | 2871 CPDF_Object * m_pAcroForm; |
2872 | 2872 |
2873 CFX_PtrArray m_arrayAcroforms; | 2873 CFX_PtrArray m_arrayAcroforms; |
2874 | 2874 |
2875 CPDF_Dictionary * m_pPageDict; | 2875 CPDF_Dictionary * m_pPageDict; |
2876 | 2876 |
2877 CPDF_Object * m_pPageResource; | 2877 CPDF_Object * m_pPageResource; |
2878 | 2878 |
2879 FX_BOOL m_bNeedDownLoadResource; | 2879 bool m_bNeedDownLoadResource; |
2880 | 2880 |
2881 FX_BOOL m_bPageLoadedOK; | 2881 bool m_bPageLoadedOK; |
2882 | 2882 |
2883 FX_BOOL m_bLinearizedFormParamLoad; | 2883 bool m_bLinearizedFormParamLoad; |
2884 | 2884 |
2885 CFX_PtrArray m_PagesArray; | 2885 CFX_PtrArray m_PagesArray; |
2886 | 2886 |
2887 FX_DWORD m_dwEncryptObjNum; | 2887 FX_DWORD m_dwEncryptObjNum; |
2888 | 2888 |
2889 FX_FILESIZE m_dwPrevXRefOffset; | 2889 FX_FILESIZE m_dwPrevXRefOffset; |
2890 | 2890 |
2891 FX_BOOL m_bTotalLoadPageTree; | 2891 bool m_bTotalLoadPageTree; |
2892 | 2892 |
2893 FX_BOOL m_bCurPageDictLoadOK; | 2893 bool m_bCurPageDictLoadOK; |
2894 | 2894 |
2895 CPDF_PageNode m_pageNodes; | 2895 CPDF_PageNode m_pageNodes; |
2896 | 2896 |
2897 CFX_CMapDWordToDWord * m_pageMapCheckState; | 2897 CFX_CMapDWordToDWord * m_pageMapCheckState; |
2898 | 2898 |
2899 CFX_CMapDWordToDWord * m_pagesLoadState; | 2899 CFX_CMapDWordToDWord * m_pagesLoadState; |
2900 }; | 2900 }; |
2901 | 2901 |
2902 IPDF_DataAvail::IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRea
d) : | 2902 IPDF_DataAvail::IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRea
d) : |
2903 m_pFileAvail(pFileAvail), | 2903 m_pFileAvail(pFileAvail), |
(...skipping 24 matching lines...) Expand all Loading... |
2928 m_dwFirstPageNo = 0; | 2928 m_dwFirstPageNo = 0; |
2929 m_bufferSize = 0; | 2929 m_bufferSize = 0; |
2930 m_PagesObjNum = 0; | 2930 m_PagesObjNum = 0; |
2931 m_dwCurrentXRefSteam = 0; | 2931 m_dwCurrentXRefSteam = 0; |
2932 m_dwAcroFormObjNum = 0; | 2932 m_dwAcroFormObjNum = 0; |
2933 m_dwInfoObjNum = 0; | 2933 m_dwInfoObjNum = 0; |
2934 m_pDocument = 0; | 2934 m_pDocument = 0; |
2935 m_dwEncryptObjNum = 0; | 2935 m_dwEncryptObjNum = 0; |
2936 m_dwPrevXRefOffset = 0; | 2936 m_dwPrevXRefOffset = 0; |
2937 m_dwLastXRefOffset = 0; | 2937 m_dwLastXRefOffset = 0; |
2938 m_bDocAvail = FALSE; | 2938 m_bDocAvail = false; |
2939 m_bMainXRefLoadTried = FALSE; | 2939 m_bMainXRefLoadTried = false; |
2940 m_bDocAvail = FALSE; | 2940 m_bDocAvail = false; |
2941 m_bLinearized = FALSE; | 2941 m_bLinearized = false; |
2942 m_bPagesLoad = FALSE; | 2942 m_bPagesLoad = false; |
2943 m_bPagesTreeLoad = FALSE; | 2943 m_bPagesTreeLoad = false; |
2944 m_bMainXRefLoadedOK = FALSE; | 2944 m_bMainXRefLoadedOK = false; |
2945 m_bAnnotsLoad = FALSE; | 2945 m_bAnnotsLoad = false; |
2946 m_bHaveAcroForm = FALSE; | 2946 m_bHaveAcroForm = false; |
2947 m_bAcroFormLoad = FALSE; | 2947 m_bAcroFormLoad = false; |
2948 m_bPageLoadedOK = FALSE; | 2948 m_bPageLoadedOK = false; |
2949 m_bNeedDownLoadResource = FALSE; | 2949 m_bNeedDownLoadResource = false; |
2950 m_bLinearizedFormParamLoad = FALSE; | 2950 m_bLinearizedFormParamLoad = false; |
2951 m_pLinearized = NULL; | 2951 m_pLinearized = NULL; |
2952 m_pRoot = NULL; | 2952 m_pRoot = NULL; |
2953 m_pTrailer = NULL; | 2953 m_pTrailer = NULL; |
2954 m_pCurrentParser = NULL; | 2954 m_pCurrentParser = NULL; |
2955 m_pAcroForm = NULL; | 2955 m_pAcroForm = NULL; |
2956 m_pPageDict = NULL; | 2956 m_pPageDict = NULL; |
2957 m_pPageResource = NULL; | 2957 m_pPageResource = NULL; |
2958 m_pageMapCheckState = NULL; | 2958 m_pageMapCheckState = NULL; |
2959 m_docStatus = PDF_DATAAVAIL_HEADER; | 2959 m_docStatus = PDF_DATAAVAIL_HEADER; |
2960 m_parser.m_bOwnFileRead = FALSE; | 2960 m_parser.m_bOwnFileRead = false; |
2961 m_bTotalLoadPageTree = FALSE; | 2961 m_bTotalLoadPageTree = false; |
2962 m_bCurPageDictLoadOK = FALSE; | 2962 m_bCurPageDictLoadOK = false; |
2963 m_bLinearedDataOK = FALSE; | 2963 m_bLinearedDataOK = false; |
2964 m_pagesLoadState = NULL; | 2964 m_pagesLoadState = NULL; |
2965 } | 2965 } |
2966 CPDF_DataAvail::~CPDF_DataAvail() | 2966 CPDF_DataAvail::~CPDF_DataAvail() |
2967 { | 2967 { |
2968 if (m_pLinearized) { | 2968 if (m_pLinearized) { |
2969 m_pLinearized->Release(); | 2969 m_pLinearized->Release(); |
2970 } | 2970 } |
2971 if (m_pRoot) { | 2971 if (m_pRoot) { |
2972 m_pRoot->Release(); | 2972 m_pRoot->Release(); |
2973 } | 2973 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3007 if (pResult == NULL) { | 3007 if (pResult == NULL) { |
3008 return 0; | 3008 return 0; |
3009 } | 3009 } |
3010 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)pParser->m_SortedOffset.GetDat
a() == pParser->m_SortedOffset.GetSize() - 1) { | 3010 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)pParser->m_SortedOffset.GetDat
a() == pParser->m_SortedOffset.GetSize() - 1) { |
3011 return 0; | 3011 return 0; |
3012 } | 3012 } |
3013 return (FX_DWORD)(((FX_FILESIZE*)pResult)[1] - offset); | 3013 return (FX_DWORD)(((FX_FILESIZE*)pResult)[1] - offset); |
3014 } | 3014 } |
3015 return 0; | 3015 return 0; |
3016 } | 3016 } |
3017 FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePa
ge, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array) | 3017 bool CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, bool bParsePage, IF
X_DownloadHints* pHints, CFX_PtrArray &ret_array) |
3018 { | 3018 { |
3019 if (!obj_array.GetSize()) { | 3019 if (!obj_array.GetSize()) { |
3020 return TRUE; | 3020 return true; |
3021 } | 3021 } |
3022 FX_DWORD count = 0; | 3022 FX_DWORD count = 0; |
3023 CFX_PtrArray new_obj_array; | 3023 CFX_PtrArray new_obj_array; |
3024 int32_t i = 0; | 3024 int32_t i = 0; |
3025 for (i = 0; i < obj_array.GetSize(); i++) { | 3025 for (i = 0; i < obj_array.GetSize(); i++) { |
3026 CPDF_Object *pObj = (CPDF_Object *)obj_array[i]; | 3026 CPDF_Object *pObj = (CPDF_Object *)obj_array[i]; |
3027 if (!pObj) { | 3027 if (!pObj) { |
3028 continue; | 3028 continue; |
3029 } | 3029 } |
3030 int32_t type = pObj->GetType(); | 3030 int32_t type = pObj->GetType(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3100 if (type == PDFOBJ_REFERENCE) { | 3100 if (type == PDFOBJ_REFERENCE) { |
3101 CPDF_Reference *pRef = (CPDF_Reference *)pObj; | 3101 CPDF_Reference *pRef = (CPDF_Reference *)pObj; |
3102 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3102 FX_DWORD dwNum = pRef->GetRefObjNum(); |
3103 if (!m_objnum_array.Find(dwNum)) { | 3103 if (!m_objnum_array.Find(dwNum)) { |
3104 ret_array.Add(pObj); | 3104 ret_array.Add(pObj); |
3105 } | 3105 } |
3106 } else { | 3106 } else { |
3107 ret_array.Add(pObj); | 3107 ret_array.Add(pObj); |
3108 } | 3108 } |
3109 } | 3109 } |
3110 return FALSE; | 3110 return false; |
3111 } | 3111 } |
3112 obj_array.RemoveAll(); | 3112 obj_array.RemoveAll(); |
3113 obj_array.Append(new_obj_array); | 3113 obj_array.Append(new_obj_array); |
3114 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); | 3114 return IsObjectsAvail(obj_array, false, pHints, ret_array); |
3115 } | 3115 } |
3116 FX_BOOL CPDF_DataAvail::IsDocAvail(IFX_DownloadHints* pHints) | 3116 bool CPDF_DataAvail::IsDocAvail(IFX_DownloadHints* pHints) |
3117 { | 3117 { |
3118 if (!m_dwFileLen && m_pFileRead) { | 3118 if (!m_dwFileLen && m_pFileRead) { |
3119 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); | 3119 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); |
3120 if (!m_dwFileLen) { | 3120 if (!m_dwFileLen) { |
3121 return TRUE; | 3121 return true; |
3122 } | 3122 } |
3123 } | 3123 } |
3124 while (!m_bDocAvail) { | 3124 while (!m_bDocAvail) { |
3125 if (!CheckDocStatus(pHints)) { | 3125 if (!CheckDocStatus(pHints)) { |
3126 return FALSE; | 3126 return false; |
3127 } | 3127 } |
3128 } | 3128 } |
3129 return TRUE; | 3129 return true; |
3130 } | 3130 } |
3131 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) | 3131 bool CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) |
3132 { | 3132 { |
3133 if (!m_objs_array.GetSize()) { | 3133 if (!m_objs_array.GetSize()) { |
3134 m_objs_array.RemoveAll(); | 3134 m_objs_array.RemoveAll(); |
3135 m_objnum_array.RemoveAll(); | 3135 m_objnum_array.RemoveAll(); |
3136 CFX_PtrArray obj_array; | 3136 CFX_PtrArray obj_array; |
3137 obj_array.Append(m_arrayAcroforms); | 3137 obj_array.Append(m_arrayAcroforms); |
3138 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 3138 bool bRet = IsObjectsAvail(obj_array, false, pHints, m_objs_array); |
3139 if (bRet) { | 3139 if (bRet) { |
3140 m_objs_array.RemoveAll(); | 3140 m_objs_array.RemoveAll(); |
3141 } | 3141 } |
3142 return bRet; | 3142 return bRet; |
3143 } else { | 3143 } else { |
3144 CFX_PtrArray new_objs_array; | 3144 CFX_PtrArray new_objs_array; |
3145 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra
y); | 3145 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_array); |
3146 if (bRet) { | 3146 if (bRet) { |
3147 int32_t iSize = m_arrayAcroforms.GetSize(); | 3147 int32_t iSize = m_arrayAcroforms.GetSize(); |
3148 for (int32_t i = 0; i < iSize; ++i) { | 3148 for (int32_t i = 0; i < iSize; ++i) { |
3149 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); | 3149 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); |
3150 } | 3150 } |
3151 m_arrayAcroforms.RemoveAll(); | 3151 m_arrayAcroforms.RemoveAll(); |
3152 } else { | 3152 } else { |
3153 m_objs_array.RemoveAll(); | 3153 m_objs_array.RemoveAll(); |
3154 m_objs_array.Append(new_objs_array); | 3154 m_objs_array.Append(new_objs_array); |
3155 } | 3155 } |
3156 return bRet; | 3156 return bRet; |
3157 } | 3157 } |
3158 } | 3158 } |
3159 FX_BOOL CPDF_DataAvail::CheckAcroForm(IFX_DownloadHints* pHints) | 3159 bool CPDF_DataAvail::CheckAcroForm(IFX_DownloadHints* pHints) |
3160 { | 3160 { |
3161 FX_BOOL bExist = FALSE; | 3161 bool bExist = false; |
3162 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); | 3162 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); |
3163 if (!bExist) { | 3163 if (!bExist) { |
3164 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3164 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3165 return TRUE; | 3165 return true; |
3166 } | 3166 } |
3167 if (!m_pAcroForm) { | 3167 if (!m_pAcroForm) { |
3168 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3168 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3169 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3169 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3170 return TRUE; | 3170 return true; |
3171 } | 3171 } |
3172 return FALSE; | 3172 return false; |
3173 } | 3173 } |
3174 m_arrayAcroforms.Add(m_pAcroForm); | 3174 m_arrayAcroforms.Add(m_pAcroForm); |
3175 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3175 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3176 return TRUE; | 3176 return true; |
3177 } | 3177 } |
3178 FX_BOOL CPDF_DataAvail::CheckDocStatus(IFX_DownloadHints *pHints) | 3178 bool CPDF_DataAvail::CheckDocStatus(IFX_DownloadHints *pHints) |
3179 { | 3179 { |
3180 switch (m_docStatus) { | 3180 switch (m_docStatus) { |
3181 case PDF_DATAAVAIL_HEADER: | 3181 case PDF_DATAAVAIL_HEADER: |
3182 return CheckHeader(pHints); | 3182 return CheckHeader(pHints); |
3183 case PDF_DATAAVAIL_FIRSTPAGE: | 3183 case PDF_DATAAVAIL_FIRSTPAGE: |
3184 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: | 3184 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: |
3185 return CheckFirstPage(pHints); | 3185 return CheckFirstPage(pHints); |
3186 case PDF_DATAAVAIL_END: | 3186 case PDF_DATAAVAIL_END: |
3187 return CheckEnd(pHints); | 3187 return CheckEnd(pHints); |
3188 case PDF_DATAAVAIL_CROSSREF: | 3188 case PDF_DATAAVAIL_CROSSREF: |
(...skipping 20 matching lines...) Expand all Loading... |
3209 if (m_bTotalLoadPageTree) { | 3209 if (m_bTotalLoadPageTree) { |
3210 return CheckPages(pHints); | 3210 return CheckPages(pHints); |
3211 } else { | 3211 } else { |
3212 return LoadDocPages(pHints); | 3212 return LoadDocPages(pHints); |
3213 } | 3213 } |
3214 case PDF_DATAAVAIL_PAGE: | 3214 case PDF_DATAAVAIL_PAGE: |
3215 if (m_bTotalLoadPageTree) { | 3215 if (m_bTotalLoadPageTree) { |
3216 return CheckPage(pHints); | 3216 return CheckPage(pHints); |
3217 } else { | 3217 } else { |
3218 m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD; | 3218 m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD; |
3219 return TRUE; | 3219 return true; |
3220 } | 3220 } |
3221 case PDF_DATAAVAIL_ERROR: | 3221 case PDF_DATAAVAIL_ERROR: |
3222 return LoadAllFile(pHints); | 3222 return LoadAllFile(pHints); |
3223 case PDF_DATAAVAIL_PAGE_LATERLOAD: | 3223 case PDF_DATAAVAIL_PAGE_LATERLOAD: |
3224 m_docStatus = PDF_DATAAVAIL_PAGE; | 3224 m_docStatus = PDF_DATAAVAIL_PAGE; |
3225 default: | 3225 default: |
3226 m_bDocAvail = TRUE; | 3226 m_bDocAvail = true; |
3227 return TRUE; | 3227 return true; |
3228 } | 3228 } |
3229 } | 3229 } |
3230 FX_BOOL»CPDF_DataAvail::CheckPageStatus(IFX_DownloadHints* pHints) | 3230 bool» CPDF_DataAvail::CheckPageStatus(IFX_DownloadHints* pHints) |
3231 { | 3231 { |
3232 switch (m_docStatus) { | 3232 switch (m_docStatus) { |
3233 case PDF_DATAAVAIL_PAGETREE: | 3233 case PDF_DATAAVAIL_PAGETREE: |
3234 return CheckPages(pHints); | 3234 return CheckPages(pHints); |
3235 case PDF_DATAAVAIL_PAGE: | 3235 case PDF_DATAAVAIL_PAGE: |
3236 return CheckPage(pHints); | 3236 return CheckPage(pHints); |
3237 case PDF_DATAAVAIL_ERROR: | 3237 case PDF_DATAAVAIL_ERROR: |
3238 return LoadAllFile(pHints); | 3238 return LoadAllFile(pHints); |
3239 default: | 3239 default: |
3240 m_bPagesTreeLoad = TRUE; | 3240 m_bPagesTreeLoad = true; |
3241 m_bPagesLoad = TRUE; | 3241 m_bPagesLoad = true; |
3242 return TRUE; | 3242 return true; |
3243 } | 3243 } |
3244 } | 3244 } |
3245 FX_BOOL CPDF_DataAvail::LoadAllFile(IFX_DownloadHints* pHints) | 3245 bool CPDF_DataAvail::LoadAllFile(IFX_DownloadHints* pHints) |
3246 { | 3246 { |
3247 if (m_pFileAvail->IsDataAvail(0, (FX_DWORD)m_dwFileLen)) { | 3247 if (m_pFileAvail->IsDataAvail(0, (FX_DWORD)m_dwFileLen)) { |
3248 m_docStatus = PDF_DATAAVAIL_DONE; | 3248 m_docStatus = PDF_DATAAVAIL_DONE; |
3249 return TRUE; | 3249 return true; |
3250 } | 3250 } |
3251 pHints->AddSegment(0, (FX_DWORD)m_dwFileLen); | 3251 pHints->AddSegment(0, (FX_DWORD)m_dwFileLen); |
3252 return FALSE; | 3252 return false; |
3253 } | 3253 } |
3254 FX_BOOL CPDF_DataAvail::LoadAllXref(IFX_DownloadHints* pHints) | 3254 bool CPDF_DataAvail::LoadAllXref(IFX_DownloadHints* pHints) |
3255 { | 3255 { |
3256 m_parser.m_Syntax.InitParser(m_pFileRead, (FX_DWORD)m_dwHeaderOffset); | 3256 m_parser.m_Syntax.InitParser(m_pFileRead, (FX_DWORD)m_dwHeaderOffset); |
3257 m_parser.m_bOwnFileRead = FALSE; | 3257 m_parser.m_bOwnFileRead = false; |
3258 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && !m_parser.LoadAllCros
sRefV5(m_dwLastXRefOffset)) { | 3258 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && !m_parser.LoadAllCros
sRefV5(m_dwLastXRefOffset)) { |
3259 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3259 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3260 return FALSE; | 3260 return false; |
3261 } | 3261 } |
3262 FXSYS_qsort(m_parser.m_SortedOffset.GetData(), m_parser.m_SortedOffset.GetSi
ze(), sizeof(FX_FILESIZE), _CompareFileSize); | 3262 FXSYS_qsort(m_parser.m_SortedOffset.GetData(), m_parser.m_SortedOffset.GetSi
ze(), sizeof(FX_FILESIZE), _CompareFileSize); |
3263 m_dwRootObjNum = m_parser.GetRootObjNum(); | 3263 m_dwRootObjNum = m_parser.GetRootObjNum(); |
3264 m_dwInfoObjNum = m_parser.GetInfoObjNum(); | 3264 m_dwInfoObjNum = m_parser.GetInfoObjNum(); |
3265 m_pCurrentParser = &m_parser; | 3265 m_pCurrentParser = &m_parser; |
3266 m_docStatus = PDF_DATAAVAIL_ROOT; | 3266 m_docStatus = PDF_DATAAVAIL_ROOT; |
3267 return TRUE; | 3267 return true; |
3268 } | 3268 } |
3269 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, IFX_DownloadHints* pHint
s, FX_BOOL *pExistInFile) | 3269 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, IFX_DownloadHints* pHint
s, bool *pExistInFile) |
3270 { | 3270 { |
3271 CPDF_Object *pRet = NULL; | 3271 CPDF_Object *pRet = NULL; |
3272 FX_DWORD original_size = 0; | 3272 FX_DWORD original_size = 0; |
3273 FX_FILESIZE offset = 0; | 3273 FX_FILESIZE offset = 0; |
3274 CPDF_Parser *pParser = NULL; | 3274 CPDF_Parser *pParser = NULL; |
3275 | 3275 |
3276 if (pExistInFile) { | 3276 if (pExistInFile) { |
3277 *pExistInFile = TRUE; | 3277 *pExistInFile = true; |
3278 } | 3278 } |
3279 | 3279 |
3280 if (m_pDocument == NULL) { | 3280 if (m_pDocument == NULL) { |
3281 original_size = (FX_DWORD)m_parser.GetObjectSize(objnum); | 3281 original_size = (FX_DWORD)m_parser.GetObjectSize(objnum); |
3282 offset = m_parser.GetObjectOffset(objnum); | 3282 offset = m_parser.GetObjectOffset(objnum); |
3283 pParser = &m_parser; | 3283 pParser = &m_parser; |
3284 } else { | 3284 } else { |
3285 original_size = GetObjectSize(objnum, offset); | 3285 original_size = GetObjectSize(objnum, offset); |
3286 pParser = (CPDF_Parser *)(m_pDocument->GetParser()); | 3286 pParser = (CPDF_Parser *)(m_pDocument->GetParser()); |
3287 } | 3287 } |
3288 | 3288 |
3289 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; | 3289 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; |
3290 if (size.ValueOrDefault(0) == 0 || offset < 0 || offset >= m_dwFileLen) { | 3290 if (size.ValueOrDefault(0) == 0 || offset < 0 || offset >= m_dwFileLen) { |
3291 if (pExistInFile) | 3291 if (pExistInFile) |
3292 *pExistInFile = FALSE; | 3292 *pExistInFile = false; |
3293 | 3293 |
3294 return NULL; | 3294 return NULL; |
3295 } | 3295 } |
3296 | 3296 |
3297 size += offset; | 3297 size += offset; |
3298 size += 512; | 3298 size += 512; |
3299 if (!size.IsValid()) { | 3299 if (!size.IsValid()) { |
3300 return NULL; | 3300 return NULL; |
3301 } | 3301 } |
3302 | 3302 |
(...skipping 10 matching lines...) Expand all Loading... |
3313 if (!m_pFileAvail->IsDataAvail(offset, size.ValueOrDie())) { | 3313 if (!m_pFileAvail->IsDataAvail(offset, size.ValueOrDie())) { |
3314 pHints->AddSegment(offset, size.ValueOrDie()); | 3314 pHints->AddSegment(offset, size.ValueOrDie()); |
3315 return NULL; | 3315 return NULL; |
3316 } | 3316 } |
3317 | 3317 |
3318 if (pParser) { | 3318 if (pParser) { |
3319 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL); | 3319 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL); |
3320 } | 3320 } |
3321 | 3321 |
3322 if (!pRet && pExistInFile) { | 3322 if (!pRet && pExistInFile) { |
3323 *pExistInFile = FALSE; | 3323 *pExistInFile = false; |
3324 } | 3324 } |
3325 | 3325 |
3326 return pRet; | 3326 return pRet; |
3327 } | 3327 } |
3328 | 3328 |
3329 FX_BOOL CPDF_DataAvail::CheckInfo(IFX_DownloadHints* pHints) | 3329 bool CPDF_DataAvail::CheckInfo(IFX_DownloadHints* pHints) |
3330 { | 3330 { |
3331 FX_BOOL bExist = FALSE; | 3331 bool bExist = false; |
3332 CPDF_Object *pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); | 3332 CPDF_Object *pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); |
3333 if (!bExist) { | 3333 if (!bExist) { |
3334 if (m_bHaveAcroForm) { | 3334 if (m_bHaveAcroForm) { |
3335 m_docStatus = PDF_DATAAVAIL_ACROFORM; | 3335 m_docStatus = PDF_DATAAVAIL_ACROFORM; |
3336 } else { | 3336 } else { |
3337 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3337 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3338 } | 3338 } |
3339 return TRUE; | 3339 return true; |
3340 } | 3340 } |
3341 if (!pInfo) { | 3341 if (!pInfo) { |
3342 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3342 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3343 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3343 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3344 return TRUE; | 3344 return true; |
3345 } | 3345 } |
3346 if (m_Pos == m_dwFileLen) { | 3346 if (m_Pos == m_dwFileLen) { |
3347 m_docStatus = PDF_DATAAVAIL_ERROR; | 3347 m_docStatus = PDF_DATAAVAIL_ERROR; |
3348 } | 3348 } |
3349 return FALSE; | 3349 return false; |
3350 } | 3350 } |
3351 if (pInfo) { | 3351 if (pInfo) { |
3352 pInfo->Release(); | 3352 pInfo->Release(); |
3353 } | 3353 } |
3354 if (m_bHaveAcroForm) { | 3354 if (m_bHaveAcroForm) { |
3355 m_docStatus = PDF_DATAAVAIL_ACROFORM; | 3355 m_docStatus = PDF_DATAAVAIL_ACROFORM; |
3356 } else { | 3356 } else { |
3357 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3357 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3358 } | 3358 } |
3359 return TRUE; | 3359 return true; |
3360 } | 3360 } |
3361 FX_BOOL CPDF_DataAvail::CheckRoot(IFX_DownloadHints* pHints) | 3361 bool CPDF_DataAvail::CheckRoot(IFX_DownloadHints* pHints) |
3362 { | 3362 { |
3363 FX_BOOL bExist = FALSE; | 3363 bool bExist = false; |
3364 m_pRoot = GetObject(m_dwRootObjNum, pHints, &bExist); | 3364 m_pRoot = GetObject(m_dwRootObjNum, pHints, &bExist); |
3365 if (!bExist) { | 3365 if (!bExist) { |
3366 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3366 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3367 return TRUE; | 3367 return true; |
3368 } | 3368 } |
3369 if (!m_pRoot) { | 3369 if (!m_pRoot) { |
3370 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3370 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3371 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3371 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3372 return TRUE; | 3372 return true; |
3373 } | 3373 } |
3374 return FALSE; | 3374 return false; |
3375 } | 3375 } |
3376 CPDF_Dictionary* pDict = m_pRoot->GetDict(); | 3376 CPDF_Dictionary* pDict = m_pRoot->GetDict(); |
3377 if (!pDict) { | 3377 if (!pDict) { |
3378 m_docStatus = PDF_DATAAVAIL_ERROR; | 3378 m_docStatus = PDF_DATAAVAIL_ERROR; |
3379 return FALSE; | 3379 return false; |
3380 } | 3380 } |
3381 CPDF_Reference* pRef = (CPDF_Reference*)pDict->GetElement(FX_BSTRC("Pages"))
; | 3381 CPDF_Reference* pRef = (CPDF_Reference*)pDict->GetElement(FX_BSTRC("Pages"))
; |
3382 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 3382 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
3383 m_docStatus = PDF_DATAAVAIL_ERROR; | 3383 m_docStatus = PDF_DATAAVAIL_ERROR; |
3384 return FALSE; | 3384 return false; |
3385 } | 3385 } |
3386 m_PagesObjNum = pRef->GetRefObjNum(); | 3386 m_PagesObjNum = pRef->GetRefObjNum(); |
3387 CPDF_Reference* pAcroFormRef = (CPDF_Reference*)m_pRoot->GetDict()->GetEleme
nt(FX_BSTRC("AcroForm")); | 3387 CPDF_Reference* pAcroFormRef = (CPDF_Reference*)m_pRoot->GetDict()->GetEleme
nt(FX_BSTRC("AcroForm")); |
3388 if (pAcroFormRef && pAcroFormRef->GetType() == PDFOBJ_REFERENCE) { | 3388 if (pAcroFormRef && pAcroFormRef->GetType() == PDFOBJ_REFERENCE) { |
3389 m_bHaveAcroForm = TRUE; | 3389 m_bHaveAcroForm = true; |
3390 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); | 3390 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); |
3391 } | 3391 } |
3392 if (m_dwInfoObjNum) { | 3392 if (m_dwInfoObjNum) { |
3393 m_docStatus = PDF_DATAAVAIL_INFO; | 3393 m_docStatus = PDF_DATAAVAIL_INFO; |
3394 } else { | 3394 } else { |
3395 if (m_bHaveAcroForm) { | 3395 if (m_bHaveAcroForm) { |
3396 m_docStatus = PDF_DATAAVAIL_ACROFORM; | 3396 m_docStatus = PDF_DATAAVAIL_ACROFORM; |
3397 } else { | 3397 } else { |
3398 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3398 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3399 } | 3399 } |
3400 } | 3400 } |
3401 return TRUE; | 3401 return true; |
3402 } | 3402 } |
3403 FX_BOOL CPDF_DataAvail::PreparePageItem() | 3403 bool CPDF_DataAvail::PreparePageItem() |
3404 { | 3404 { |
3405 CPDF_Dictionary *pRoot = m_pDocument->GetRoot(); | 3405 CPDF_Dictionary *pRoot = m_pDocument->GetRoot(); |
3406 CPDF_Reference* pRef = pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("
Pages")) : NULL; | 3406 CPDF_Reference* pRef = pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("
Pages")) : NULL; |
3407 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 3407 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
3408 m_docStatus = PDF_DATAAVAIL_ERROR; | 3408 m_docStatus = PDF_DATAAVAIL_ERROR; |
3409 return FALSE; | 3409 return false; |
3410 } | 3410 } |
3411 m_PagesObjNum = pRef->GetRefObjNum(); | 3411 m_PagesObjNum = pRef->GetRefObjNum(); |
3412 m_pCurrentParser = (CPDF_Parser *)m_pDocument->GetParser(); | 3412 m_pCurrentParser = (CPDF_Parser *)m_pDocument->GetParser(); |
3413 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3413 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3414 return TRUE; | 3414 return true; |
3415 } | 3415 } |
3416 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) | 3416 bool CPDF_DataAvail::IsFirstCheck(int iPage) |
3417 { | 3417 { |
3418 if (NULL == m_pageMapCheckState) { | 3418 if (NULL == m_pageMapCheckState) { |
3419 m_pageMapCheckState = new CFX_CMapDWordToDWord(); | 3419 m_pageMapCheckState = new CFX_CMapDWordToDWord(); |
3420 } | 3420 } |
3421 FX_DWORD dwValue = 0; | 3421 FX_DWORD dwValue = 0; |
3422 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { | 3422 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { |
3423 m_pageMapCheckState->SetAt(iPage, 1); | 3423 m_pageMapCheckState->SetAt(iPage, 1); |
3424 return TRUE; | 3424 return true; |
3425 } | 3425 } |
3426 if (dwValue != 0) { | 3426 if (dwValue != 0) { |
3427 return FALSE; | 3427 return false; |
3428 } | 3428 } |
3429 m_pageMapCheckState->SetAt(iPage, 1); | 3429 m_pageMapCheckState->SetAt(iPage, 1); |
3430 return TRUE; | 3430 return true; |
3431 } | 3431 } |
3432 void CPDF_DataAvail::ResetFirstCheck(int iPage) | 3432 void CPDF_DataAvail::ResetFirstCheck(int iPage) |
3433 { | 3433 { |
3434 if (NULL == m_pageMapCheckState) { | 3434 if (NULL == m_pageMapCheckState) { |
3435 m_pageMapCheckState = new CFX_CMapDWordToDWord(); | 3435 m_pageMapCheckState = new CFX_CMapDWordToDWord(); |
3436 } | 3436 } |
3437 FX_DWORD dwValue = 1; | 3437 FX_DWORD dwValue = 1; |
3438 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { | 3438 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { |
3439 return; | 3439 return; |
3440 } | 3440 } |
3441 m_pageMapCheckState->SetAt(iPage, 0); | 3441 m_pageMapCheckState->SetAt(iPage, 0); |
3442 } | 3442 } |
3443 FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) | 3443 bool CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) |
3444 { | 3444 { |
3445 FX_DWORD iPageObjs = m_PageObjList.GetSize(); | 3445 FX_DWORD iPageObjs = m_PageObjList.GetSize(); |
3446 CFX_DWordArray UnavailObjList; | 3446 CFX_DWordArray UnavailObjList; |
3447 for (FX_DWORD i = 0; i < iPageObjs; ++i) { | 3447 for (FX_DWORD i = 0; i < iPageObjs; ++i) { |
3448 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); | 3448 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); |
3449 FX_BOOL bExist = FALSE; | 3449 bool bExist = false; |
3450 CPDF_Object *pObj = GetObject(dwPageObjNum, pHints, &bExist); | 3450 CPDF_Object *pObj = GetObject(dwPageObjNum, pHints, &bExist); |
3451 if (!pObj) { | 3451 if (!pObj) { |
3452 if (bExist) { | 3452 if (bExist) { |
3453 UnavailObjList.Add(dwPageObjNum); | 3453 UnavailObjList.Add(dwPageObjNum); |
3454 } | 3454 } |
3455 continue; | 3455 continue; |
3456 } | 3456 } |
3457 if (pObj->GetType() == PDFOBJ_ARRAY) { | 3457 if (pObj->GetType() == PDFOBJ_ARRAY) { |
3458 CPDF_Array *pArray = pObj->GetArray(); | 3458 CPDF_Array *pArray = pObj->GetArray(); |
3459 if (pArray) { | 3459 if (pArray) { |
(...skipping 14 matching lines...) Expand all Loading... |
3474 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type")); | 3474 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type")); |
3475 if (type == FX_BSTRC("Pages")) { | 3475 if (type == FX_BSTRC("Pages")) { |
3476 m_PagesArray.Add(pObj); | 3476 m_PagesArray.Add(pObj); |
3477 continue; | 3477 continue; |
3478 } | 3478 } |
3479 pObj->Release(); | 3479 pObj->Release(); |
3480 } | 3480 } |
3481 m_PageObjList.RemoveAll(); | 3481 m_PageObjList.RemoveAll(); |
3482 if (UnavailObjList.GetSize()) { | 3482 if (UnavailObjList.GetSize()) { |
3483 m_PageObjList.Append(UnavailObjList); | 3483 m_PageObjList.Append(UnavailObjList); |
3484 return FALSE; | 3484 return false; |
3485 } | 3485 } |
3486 FX_DWORD iPages = m_PagesArray.GetSize(); | 3486 FX_DWORD iPages = m_PagesArray.GetSize(); |
3487 for (FX_DWORD i = 0; i < iPages; i++) { | 3487 for (FX_DWORD i = 0; i < iPages; i++) { |
3488 CPDF_Object *pPages = (CPDF_Object *)m_PagesArray.GetAt(i); | 3488 CPDF_Object *pPages = (CPDF_Object *)m_PagesArray.GetAt(i); |
3489 if (!pPages) { | 3489 if (!pPages) { |
3490 continue; | 3490 continue; |
3491 } | 3491 } |
3492 if (!GetPageKids(m_pCurrentParser, pPages)) { | 3492 if (!GetPageKids(m_pCurrentParser, pPages)) { |
3493 pPages->Release(); | 3493 pPages->Release(); |
3494 while (++i < iPages) { | 3494 while (++i < iPages) { |
3495 pPages = (CPDF_Object *)m_PagesArray.GetAt(i); | 3495 pPages = (CPDF_Object *)m_PagesArray.GetAt(i); |
3496 pPages->Release(); | 3496 pPages->Release(); |
3497 } | 3497 } |
3498 m_PagesArray.RemoveAll(); | 3498 m_PagesArray.RemoveAll(); |
3499 m_docStatus = PDF_DATAAVAIL_ERROR; | 3499 m_docStatus = PDF_DATAAVAIL_ERROR; |
3500 return FALSE; | 3500 return false; |
3501 } | 3501 } |
3502 pPages->Release(); | 3502 pPages->Release(); |
3503 } | 3503 } |
3504 m_PagesArray.RemoveAll(); | 3504 m_PagesArray.RemoveAll(); |
3505 if (!m_PageObjList.GetSize()) { | 3505 if (!m_PageObjList.GetSize()) { |
3506 m_docStatus = PDF_DATAAVAIL_DONE; | 3506 m_docStatus = PDF_DATAAVAIL_DONE; |
3507 } | 3507 } |
3508 return TRUE; | 3508 return true; |
3509 } | 3509 } |
3510 FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages) | 3510 bool CPDF_DataAvail::GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages) |
3511 { | 3511 { |
3512 if (!pParser) { | 3512 if (!pParser) { |
3513 m_docStatus = PDF_DATAAVAIL_ERROR; | 3513 m_docStatus = PDF_DATAAVAIL_ERROR; |
3514 return FALSE; | 3514 return false; |
3515 } | 3515 } |
3516 CPDF_Dictionary* pDict = pPages->GetDict(); | 3516 CPDF_Dictionary* pDict = pPages->GetDict(); |
3517 CPDF_Object *pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; | 3517 CPDF_Object *pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; |
3518 if (!pKids) { | 3518 if (!pKids) { |
3519 return TRUE; | 3519 return true; |
3520 } | 3520 } |
3521 switch (pKids->GetType()) { | 3521 switch (pKids->GetType()) { |
3522 case PDFOBJ_REFERENCE: { | 3522 case PDFOBJ_REFERENCE: { |
3523 CPDF_Reference *pKid = (CPDF_Reference *)pKids; | 3523 CPDF_Reference *pKid = (CPDF_Reference *)pKids; |
3524 m_PageObjList.Add(pKid->GetRefObjNum()); | 3524 m_PageObjList.Add(pKid->GetRefObjNum()); |
3525 } | 3525 } |
3526 break; | 3526 break; |
3527 case PDFOBJ_ARRAY: { | 3527 case PDFOBJ_ARRAY: { |
3528 CPDF_Array *pKidsArray = (CPDF_Array *)pKids; | 3528 CPDF_Array *pKidsArray = (CPDF_Array *)pKids; |
3529 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { | 3529 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { |
3530 CPDF_Object *pKid = (CPDF_Object *)pKidsArray->GetElement(i)
; | 3530 CPDF_Object *pKid = (CPDF_Object *)pKidsArray->GetElement(i)
; |
3531 if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) { | 3531 if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) { |
3532 m_PageObjList.Add(((CPDF_Reference *)pKid)->GetRefObjNum
()); | 3532 m_PageObjList.Add(((CPDF_Reference *)pKid)->GetRefObjNum
()); |
3533 } | 3533 } |
3534 } | 3534 } |
3535 } | 3535 } |
3536 break; | 3536 break; |
3537 default: | 3537 default: |
3538 m_docStatus = PDF_DATAAVAIL_ERROR; | 3538 m_docStatus = PDF_DATAAVAIL_ERROR; |
3539 return FALSE; | 3539 return false; |
3540 } | 3540 } |
3541 return TRUE; | 3541 return true; |
3542 } | 3542 } |
3543 FX_BOOL CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) | 3543 bool CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) |
3544 { | 3544 { |
3545 FX_BOOL bExist = FALSE; | 3545 bool bExist = false; |
3546 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist); | 3546 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist); |
3547 if (!bExist) { | 3547 if (!bExist) { |
3548 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3548 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3549 return TRUE; | 3549 return true; |
3550 } | 3550 } |
3551 if (!pPages) { | 3551 if (!pPages) { |
3552 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3552 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3553 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3553 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3554 return TRUE; | 3554 return true; |
3555 } | 3555 } |
3556 return FALSE; | 3556 return false; |
3557 } | 3557 } |
3558 if (!GetPageKids(m_pCurrentParser, pPages)) { | 3558 if (!GetPageKids(m_pCurrentParser, pPages)) { |
3559 pPages->Release(); | 3559 pPages->Release(); |
3560 m_docStatus = PDF_DATAAVAIL_ERROR; | 3560 m_docStatus = PDF_DATAAVAIL_ERROR; |
3561 return FALSE; | 3561 return false; |
3562 } | 3562 } |
3563 pPages->Release(); | 3563 pPages->Release(); |
3564 m_docStatus = PDF_DATAAVAIL_PAGE; | 3564 m_docStatus = PDF_DATAAVAIL_PAGE; |
3565 return TRUE; | 3565 return true; |
3566 } | 3566 } |
3567 FX_BOOL CPDF_DataAvail::CheckHeader(IFX_DownloadHints* pHints) | 3567 bool CPDF_DataAvail::CheckHeader(IFX_DownloadHints* pHints) |
3568 { | 3568 { |
3569 FX_DWORD req_size = 1024; | 3569 FX_DWORD req_size = 1024; |
3570 if ((FX_FILESIZE)req_size > m_dwFileLen) { | 3570 if ((FX_FILESIZE)req_size > m_dwFileLen) { |
3571 req_size = (FX_DWORD)m_dwFileLen; | 3571 req_size = (FX_DWORD)m_dwFileLen; |
3572 } | 3572 } |
3573 if (m_pFileAvail->IsDataAvail(0, req_size)) { | 3573 if (m_pFileAvail->IsDataAvail(0, req_size)) { |
3574 uint8_t buffer[1024]; | 3574 uint8_t buffer[1024]; |
3575 m_pFileRead->ReadBlock(buffer, 0, req_size); | 3575 m_pFileRead->ReadBlock(buffer, 0, req_size); |
3576 if (IsLinearizedFile(buffer, req_size)) { | 3576 if (IsLinearizedFile(buffer, req_size)) { |
3577 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; | 3577 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; |
3578 } else { | 3578 } else { |
3579 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3579 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3580 return FALSE; | 3580 return false; |
3581 } | 3581 } |
3582 m_docStatus = PDF_DATAAVAIL_END; | 3582 m_docStatus = PDF_DATAAVAIL_END; |
3583 } | 3583 } |
3584 return TRUE; | 3584 return true; |
3585 } | 3585 } |
3586 pHints->AddSegment(0, req_size); | 3586 pHints->AddSegment(0, req_size); |
3587 return FALSE; | 3587 return false; |
3588 } | 3588 } |
3589 FX_BOOL CPDF_DataAvail::CheckFirstPage(IFX_DownloadHints *pHints) | 3589 bool CPDF_DataAvail::CheckFirstPage(IFX_DownloadHints *pHints) |
3590 { | 3590 { |
3591 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 3591 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
3592 CPDF_Object *pEndOffSet = pDict ? pDict->GetElement(FX_BSTRC("E")) : NULL; | 3592 CPDF_Object *pEndOffSet = pDict ? pDict->GetElement(FX_BSTRC("E")) : NULL; |
3593 if (!pEndOffSet) { | 3593 if (!pEndOffSet) { |
3594 m_docStatus = PDF_DATAAVAIL_ERROR; | 3594 m_docStatus = PDF_DATAAVAIL_ERROR; |
3595 return FALSE; | 3595 return false; |
3596 } | 3596 } |
3597 CPDF_Object *pXRefOffset = pDict ? pDict->GetElement(FX_BSTRC("T")) : NULL; | 3597 CPDF_Object *pXRefOffset = pDict ? pDict->GetElement(FX_BSTRC("T")) : NULL; |
3598 if (!pXRefOffset) { | 3598 if (!pXRefOffset) { |
3599 m_docStatus = PDF_DATAAVAIL_ERROR; | 3599 m_docStatus = PDF_DATAAVAIL_ERROR; |
3600 return FALSE; | 3600 return false; |
3601 } | 3601 } |
3602 CPDF_Object *pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL; | 3602 CPDF_Object *pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL; |
3603 if (!pFileLen) { | 3603 if (!pFileLen) { |
3604 m_docStatus = PDF_DATAAVAIL_ERROR; | 3604 m_docStatus = PDF_DATAAVAIL_ERROR; |
3605 return FALSE; | 3605 return false; |
3606 } | 3606 } |
3607 FX_BOOL bNeedDownLoad = FALSE; | 3607 bool bNeedDownLoad = false; |
3608 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) { | 3608 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) { |
3609 FX_DWORD dwEnd = pEndOffSet->GetInteger(); | 3609 FX_DWORD dwEnd = pEndOffSet->GetInteger(); |
3610 dwEnd += 512; | 3610 dwEnd += 512; |
3611 if ((FX_FILESIZE)dwEnd > m_dwFileLen) { | 3611 if ((FX_FILESIZE)dwEnd > m_dwFileLen) { |
3612 dwEnd = (FX_DWORD)m_dwFileLen; | 3612 dwEnd = (FX_DWORD)m_dwFileLen; |
3613 } | 3613 } |
3614 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); | 3614 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); |
3615 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; | 3615 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; |
3616 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { | 3616 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { |
3617 pHints->AddSegment(iStartPos, iSize); | 3617 pHints->AddSegment(iStartPos, iSize); |
3618 bNeedDownLoad = TRUE; | 3618 bNeedDownLoad = true; |
3619 } | 3619 } |
3620 } | 3620 } |
3621 m_dwLastXRefOffset = 0; | 3621 m_dwLastXRefOffset = 0; |
3622 FX_FILESIZE dwFileLen = 0; | 3622 FX_FILESIZE dwFileLen = 0; |
3623 if (pXRefOffset->GetType() == PDFOBJ_NUMBER) { | 3623 if (pXRefOffset->GetType() == PDFOBJ_NUMBER) { |
3624 m_dwLastXRefOffset = pXRefOffset->GetInteger(); | 3624 m_dwLastXRefOffset = pXRefOffset->GetInteger(); |
3625 } | 3625 } |
3626 if (pFileLen->GetType() == PDFOBJ_NUMBER) { | 3626 if (pFileLen->GetType() == PDFOBJ_NUMBER) { |
3627 dwFileLen = pFileLen->GetInteger(); | 3627 dwFileLen = pFileLen->GetInteger(); |
3628 } | 3628 } |
3629 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, (FX_DWORD)(dwFileLen - m_
dwLastXRefOffset))) { | 3629 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, (FX_DWORD)(dwFileLen - m_
dwLastXRefOffset))) { |
3630 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { | 3630 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { |
3631 FX_DWORD dwSize = (FX_DWORD)(dwFileLen - m_dwLastXRefOffset); | 3631 FX_DWORD dwSize = (FX_DWORD)(dwFileLen - m_dwLastXRefOffset); |
3632 FX_FILESIZE offset = m_dwLastXRefOffset; | 3632 FX_FILESIZE offset = m_dwLastXRefOffset; |
3633 if (dwSize < 512 && dwFileLen > 512) { | 3633 if (dwSize < 512 && dwFileLen > 512) { |
3634 dwSize = 512; | 3634 dwSize = 512; |
3635 offset = dwFileLen - 512; | 3635 offset = dwFileLen - 512; |
3636 } | 3636 } |
3637 pHints->AddSegment(offset, dwSize); | 3637 pHints->AddSegment(offset, dwSize); |
3638 } | 3638 } |
3639 } else { | 3639 } else { |
3640 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; | 3640 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; |
3641 } | 3641 } |
3642 if (!bNeedDownLoad && m_docStatus == PDF_DATAAVAIL_FIRSTPAGE_PREPARE) { | 3642 if (!bNeedDownLoad && m_docStatus == PDF_DATAAVAIL_FIRSTPAGE_PREPARE) { |
3643 m_docStatus = PDF_DATAAVAIL_DONE; | 3643 m_docStatus = PDF_DATAAVAIL_DONE; |
3644 return TRUE; | 3644 return true; |
3645 } | 3645 } |
3646 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; | 3646 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; |
3647 return FALSE; | 3647 return false; |
3648 } | 3648 } |
3649 CPDF_Object * CPDF_DataAvail::ParseIndirectObjectAt(FX_FILESIZE pos, FX_DWOR
D objnum) | 3649 CPDF_Object * CPDF_DataAvail::ParseIndirectObjectAt(FX_FILESIZE pos, FX_DWOR
D objnum) |
3650 { | 3650 { |
3651 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); | 3651 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); |
3652 m_syntaxParser.RestorePos(pos); | 3652 m_syntaxParser.RestorePos(pos); |
3653 FX_BOOL bIsNumber; | 3653 bool bIsNumber; |
3654 CFX_ByteString word = m_syntaxParser.GetNextWord(bIsNumber); | 3654 CFX_ByteString word = m_syntaxParser.GetNextWord(bIsNumber); |
3655 if (!bIsNumber) { | 3655 if (!bIsNumber) { |
3656 return NULL; | 3656 return NULL; |
3657 } | 3657 } |
3658 FX_DWORD parser_objnum = FXSYS_atoi(word); | 3658 FX_DWORD parser_objnum = FXSYS_atoi(word); |
3659 if (objnum && parser_objnum != objnum) { | 3659 if (objnum && parser_objnum != objnum) { |
3660 return NULL; | 3660 return NULL; |
3661 } | 3661 } |
3662 word = m_syntaxParser.GetNextWord(bIsNumber); | 3662 word = m_syntaxParser.GetNextWord(bIsNumber); |
3663 if (!bIsNumber) { | 3663 if (!bIsNumber) { |
(...skipping 21 matching lines...) Expand all Loading... |
3685 if (dwSize < (FX_FILESIZE)req_size) { | 3685 if (dwSize < (FX_FILESIZE)req_size) { |
3686 return PDF_UNKNOW_LINEARIZED; | 3686 return PDF_UNKNOW_LINEARIZED; |
3687 } | 3687 } |
3688 uint8_t buffer[1024]; | 3688 uint8_t buffer[1024]; |
3689 m_pFileRead->ReadBlock(buffer, 0, req_size); | 3689 m_pFileRead->ReadBlock(buffer, 0, req_size); |
3690 if (IsLinearizedFile(buffer, req_size)) { | 3690 if (IsLinearizedFile(buffer, req_size)) { |
3691 return PDF_IS_LINEARIZED; | 3691 return PDF_IS_LINEARIZED; |
3692 } | 3692 } |
3693 return PDF_NOT_LINEARIZED; | 3693 return PDF_NOT_LINEARIZED; |
3694 } | 3694 } |
3695 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) | 3695 bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) |
3696 { | 3696 { |
3697 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pData, (size_t)d
wLen, FALSE)); | 3697 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pData, (size_t)d
wLen, false)); |
3698 int32_t offset = GetHeaderOffset(file.Get()); | 3698 int32_t offset = GetHeaderOffset(file.Get()); |
3699 if (offset == -1) { | 3699 if (offset == -1) { |
3700 m_docStatus = PDF_DATAAVAIL_ERROR; | 3700 m_docStatus = PDF_DATAAVAIL_ERROR; |
3701 return FALSE; | 3701 return false; |
3702 } | 3702 } |
3703 m_dwHeaderOffset = offset; | 3703 m_dwHeaderOffset = offset; |
3704 m_syntaxParser.InitParser(file.Get(), offset); | 3704 m_syntaxParser.InitParser(file.Get(), offset); |
3705 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); | 3705 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); |
3706 FX_BOOL bNumber = FALSE; | 3706 bool bNumber = false; |
3707 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(bNumber); | 3707 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(bNumber); |
3708 if (!bNumber) { | 3708 if (!bNumber) { |
3709 return FALSE; | 3709 return false; |
3710 } | 3710 } |
3711 FX_DWORD objnum = FXSYS_atoi(wordObjNum); | 3711 FX_DWORD objnum = FXSYS_atoi(wordObjNum); |
3712 if (m_pLinearized) { | 3712 if (m_pLinearized) { |
3713 m_pLinearized->Release(); | 3713 m_pLinearized->Release(); |
3714 m_pLinearized = NULL; | 3714 m_pLinearized = NULL; |
3715 } | 3715 } |
3716 m_pLinearized = ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, obj
num); | 3716 m_pLinearized = ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, obj
num); |
3717 if (!m_pLinearized) { | 3717 if (!m_pLinearized) { |
3718 return FALSE; | 3718 return false; |
3719 } | 3719 } |
3720 if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTR
C("Linearized"))) { | 3720 if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTR
C("Linearized"))) { |
3721 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); | 3721 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); |
3722 if (!pLen) { | 3722 if (!pLen) { |
3723 return FALSE; | 3723 return false; |
3724 } | 3724 } |
3725 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) { | 3725 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) { |
3726 return FALSE; | 3726 return false; |
3727 } | 3727 } |
3728 m_bLinearized = TRUE; | 3728 m_bLinearized = true; |
3729 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); | 3729 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); |
3730 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { | 3730 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { |
3731 m_dwFirstPageNo = pNo->GetInteger(); | 3731 m_dwFirstPageNo = pNo->GetInteger(); |
3732 } | 3732 } |
3733 return TRUE; | 3733 return true; |
3734 } | 3734 } |
3735 return FALSE; | 3735 return false; |
3736 } | 3736 } |
3737 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) | 3737 bool CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) |
3738 { | 3738 { |
3739 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 3739 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
3740 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); | 3740 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); |
3741 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 3741 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
3742 uint8_t buffer[1024]; | 3742 uint8_t buffer[1024]; |
3743 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 3743 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
3744 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(buffer, (siz
e_t)dwSize, FALSE)); | 3744 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(buffer, (siz
e_t)dwSize, false)); |
3745 m_syntaxParser.InitParser(file.Get(), 0); | 3745 m_syntaxParser.InitParser(file.Get(), 0); |
3746 m_syntaxParser.RestorePos(dwSize - 1); | 3746 m_syntaxParser.RestorePos(dwSize - 1); |
3747 if (m_syntaxParser.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, dwSize
)) { | 3747 if (m_syntaxParser.SearchWord(FX_BSTRC("startxref"), true, false, dwSize
)) { |
3748 FX_BOOL bNumber; | 3748 bool bNumber; |
3749 m_syntaxParser.GetNextWord(bNumber); | 3749 m_syntaxParser.GetNextWord(bNumber); |
3750 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(bNumber); | 3750 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(bNumber); |
3751 if (!bNumber) { | 3751 if (!bNumber) { |
3752 m_docStatus = PDF_DATAAVAIL_ERROR; | 3752 m_docStatus = PDF_DATAAVAIL_ERROR; |
3753 return FALSE; | 3753 return false; |
3754 } | 3754 } |
3755 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 3755 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); |
3756 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { | 3756 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { |
3757 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3757 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3758 return TRUE; | 3758 return true; |
3759 } | 3759 } |
3760 m_dwLastXRefOffset = m_dwXRefOffset; | 3760 m_dwLastXRefOffset = m_dwXRefOffset; |
3761 SetStartOffset(m_dwXRefOffset); | 3761 SetStartOffset(m_dwXRefOffset); |
3762 m_docStatus = PDF_DATAAVAIL_CROSSREF; | 3762 m_docStatus = PDF_DATAAVAIL_CROSSREF; |
3763 return TRUE; | 3763 return true; |
3764 } else { | 3764 } else { |
3765 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3765 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3766 return TRUE; | 3766 return true; |
3767 } | 3767 } |
3768 } | 3768 } |
3769 pHints->AddSegment(req_pos, dwSize); | 3769 pHints->AddSegment(req_pos, dwSize); |
3770 return FALSE; | 3770 return false; |
3771 } | 3771 } |
3772 int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILESI
ZE &xref_offset) | 3772 int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILESI
ZE &xref_offset) |
3773 { | 3773 { |
3774 xref_offset = 0; | 3774 xref_offset = 0; |
3775 FX_DWORD req_size = (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_P
os : 512); | 3775 FX_DWORD req_size = (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_P
os : 512); |
3776 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { | 3776 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { |
3777 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); | 3777 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); |
3778 CFX_BinaryBuf buf(iSize); | 3778 CFX_BinaryBuf buf(iSize); |
3779 uint8_t* pBuf = buf.GetBuffer(); | 3779 uint8_t* pBuf = buf.GetBuffer(); |
3780 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); | 3780 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); |
3781 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_
t)iSize, FALSE)); | 3781 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_
t)iSize, false)); |
3782 m_parser.m_Syntax.InitParser(file.Get(), 0); | 3782 m_parser.m_Syntax.InitParser(file.Get(), 0); |
3783 FX_BOOL bNumber = FALSE; | 3783 bool bNumber = false; |
3784 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber); | 3784 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber); |
3785 if (!bNumber) { | 3785 if (!bNumber) { |
3786 return -1; | 3786 return -1; |
3787 } | 3787 } |
3788 FX_DWORD objNum = FXSYS_atoi(objnum); | 3788 FX_DWORD objNum = FXSYS_atoi(objnum); |
3789 CPDF_Object *pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL
); | 3789 CPDF_Object *pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL
); |
3790 if (!pObj) { | 3790 if (!pObj) { |
3791 m_Pos += m_parser.m_Syntax.SavePos(); | 3791 m_Pos += m_parser.m_Syntax.SavePos(); |
3792 return 0; | 3792 return 0; |
3793 } | 3793 } |
(...skipping 14 matching lines...) Expand all Loading... |
3808 return -1; | 3808 return -1; |
3809 } | 3809 } |
3810 pHints->AddSegment(m_Pos, req_size); | 3810 pHints->AddSegment(m_Pos, req_size); |
3811 return 0; | 3811 return 0; |
3812 } | 3812 } |
3813 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) | 3813 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) |
3814 { | 3814 { |
3815 m_Pos = dwOffset; | 3815 m_Pos = dwOffset; |
3816 } | 3816 } |
3817 #define MAX_WORD_BUFFER 256 | 3817 #define MAX_WORD_BUFFER 256 |
3818 FX_BOOL CPDF_DataAvail::GetNextToken(CFX_ByteString &token) | 3818 bool CPDF_DataAvail::GetNextToken(CFX_ByteString &token) |
3819 { | 3819 { |
3820 m_WordSize = 0; | 3820 m_WordSize = 0; |
3821 uint8_t ch; | 3821 uint8_t ch; |
3822 if (!GetNextChar(ch)) { | 3822 if (!GetNextChar(ch)) { |
3823 return FALSE; | 3823 return false; |
3824 } | 3824 } |
3825 uint8_t type = PDF_CharType[ch]; | 3825 uint8_t type = PDF_CharType[ch]; |
3826 while (1) { | 3826 while (1) { |
3827 while (type == 'W') { | 3827 while (type == 'W') { |
3828 if (!GetNextChar(ch)) { | 3828 if (!GetNextChar(ch)) { |
3829 return FALSE; | 3829 return false; |
3830 } | 3830 } |
3831 type = PDF_CharType[ch]; | 3831 type = PDF_CharType[ch]; |
3832 } | 3832 } |
3833 if (ch != '%') { | 3833 if (ch != '%') { |
3834 break; | 3834 break; |
3835 } | 3835 } |
3836 while (1) { | 3836 while (1) { |
3837 if (!GetNextChar(ch)) { | 3837 if (!GetNextChar(ch)) { |
3838 return FALSE; | 3838 return false; |
3839 } | 3839 } |
3840 if (ch == '\r' || ch == '\n') { | 3840 if (ch == '\r' || ch == '\n') { |
3841 break; | 3841 break; |
3842 } | 3842 } |
3843 } | 3843 } |
3844 type = PDF_CharType[ch]; | 3844 type = PDF_CharType[ch]; |
3845 } | 3845 } |
3846 if (type == 'D') { | 3846 if (type == 'D') { |
3847 m_WordBuffer[m_WordSize++] = ch; | 3847 m_WordBuffer[m_WordSize++] = ch; |
3848 if (ch == '/') { | 3848 if (ch == '/') { |
3849 while (1) { | 3849 while (1) { |
3850 if (!GetNextChar(ch)) { | 3850 if (!GetNextChar(ch)) { |
3851 return FALSE; | 3851 return false; |
3852 } | 3852 } |
3853 type = PDF_CharType[ch]; | 3853 type = PDF_CharType[ch]; |
3854 if (type != 'R' && type != 'N') { | 3854 if (type != 'R' && type != 'N') { |
3855 m_Pos --; | 3855 m_Pos --; |
3856 CFX_ByteString ret(m_WordBuffer, m_WordSize); | 3856 CFX_ByteString ret(m_WordBuffer, m_WordSize); |
3857 token = ret; | 3857 token = ret; |
3858 return TRUE; | 3858 return true; |
3859 } | 3859 } |
3860 if (m_WordSize < MAX_WORD_BUFFER) { | 3860 if (m_WordSize < MAX_WORD_BUFFER) { |
3861 m_WordBuffer[m_WordSize++] = ch; | 3861 m_WordBuffer[m_WordSize++] = ch; |
3862 } | 3862 } |
3863 } | 3863 } |
3864 } else if (ch == '<') { | 3864 } else if (ch == '<') { |
3865 if (!GetNextChar(ch)) { | 3865 if (!GetNextChar(ch)) { |
3866 return FALSE; | 3866 return false; |
3867 } | 3867 } |
3868 if (ch == '<') { | 3868 if (ch == '<') { |
3869 m_WordBuffer[m_WordSize++] = ch; | 3869 m_WordBuffer[m_WordSize++] = ch; |
3870 } else { | 3870 } else { |
3871 m_Pos --; | 3871 m_Pos --; |
3872 } | 3872 } |
3873 } else if (ch == '>') { | 3873 } else if (ch == '>') { |
3874 if (!GetNextChar(ch)) { | 3874 if (!GetNextChar(ch)) { |
3875 return FALSE; | 3875 return false; |
3876 } | 3876 } |
3877 if (ch == '>') { | 3877 if (ch == '>') { |
3878 m_WordBuffer[m_WordSize++] = ch; | 3878 m_WordBuffer[m_WordSize++] = ch; |
3879 } else { | 3879 } else { |
3880 m_Pos --; | 3880 m_Pos --; |
3881 } | 3881 } |
3882 } | 3882 } |
3883 CFX_ByteString ret(m_WordBuffer, m_WordSize); | 3883 CFX_ByteString ret(m_WordBuffer, m_WordSize); |
3884 token = ret; | 3884 token = ret; |
3885 return TRUE; | 3885 return true; |
3886 } | 3886 } |
3887 while (1) { | 3887 while (1) { |
3888 if (m_WordSize < MAX_WORD_BUFFER) { | 3888 if (m_WordSize < MAX_WORD_BUFFER) { |
3889 m_WordBuffer[m_WordSize++] = ch; | 3889 m_WordBuffer[m_WordSize++] = ch; |
3890 } | 3890 } |
3891 if (!GetNextChar(ch)) { | 3891 if (!GetNextChar(ch)) { |
3892 return FALSE; | 3892 return false; |
3893 } | 3893 } |
3894 type = PDF_CharType[ch]; | 3894 type = PDF_CharType[ch]; |
3895 if (type == 'D' || type == 'W') { | 3895 if (type == 'D' || type == 'W') { |
3896 m_Pos --; | 3896 m_Pos --; |
3897 break; | 3897 break; |
3898 } | 3898 } |
3899 } | 3899 } |
3900 CFX_ByteString ret(m_WordBuffer, m_WordSize); | 3900 CFX_ByteString ret(m_WordBuffer, m_WordSize); |
3901 token = ret; | 3901 token = ret; |
3902 return TRUE; | 3902 return true; |
3903 } | 3903 } |
3904 FX_BOOL CPDF_DataAvail::GetNextChar(uint8_t &ch) | 3904 bool CPDF_DataAvail::GetNextChar(uint8_t &ch) |
3905 { | 3905 { |
3906 FX_FILESIZE pos = m_Pos; | 3906 FX_FILESIZE pos = m_Pos; |
3907 if (pos >= m_dwFileLen) { | 3907 if (pos >= m_dwFileLen) { |
3908 return FALSE; | 3908 return false; |
3909 } | 3909 } |
3910 if (m_bufferOffset >= pos || (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <=
pos) { | 3910 if (m_bufferOffset >= pos || (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <=
pos) { |
3911 FX_FILESIZE read_pos = pos; | 3911 FX_FILESIZE read_pos = pos; |
3912 FX_DWORD read_size = 512; | 3912 FX_DWORD read_size = 512; |
3913 if ((FX_FILESIZE)read_size > m_dwFileLen) { | 3913 if ((FX_FILESIZE)read_size > m_dwFileLen) { |
3914 read_size = (FX_DWORD)m_dwFileLen; | 3914 read_size = (FX_DWORD)m_dwFileLen; |
3915 } | 3915 } |
3916 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) { | 3916 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) { |
3917 read_pos = m_dwFileLen - read_size; | 3917 read_pos = m_dwFileLen - read_size; |
3918 } | 3918 } |
3919 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) { | 3919 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) { |
3920 return FALSE; | 3920 return false; |
3921 } | 3921 } |
3922 m_bufferOffset = read_pos; | 3922 m_bufferOffset = read_pos; |
3923 m_bufferSize = read_size; | 3923 m_bufferSize = read_size; |
3924 } | 3924 } |
3925 ch = m_bufferData[pos - m_bufferOffset]; | 3925 ch = m_bufferData[pos - m_bufferOffset]; |
3926 m_Pos ++; | 3926 m_Pos ++; |
3927 return TRUE; | 3927 return true; |
3928 } | 3928 } |
3929 FX_BOOL CPDF_DataAvail::CheckCrossRefItem(IFX_DownloadHints *pHints) | 3929 bool CPDF_DataAvail::CheckCrossRefItem(IFX_DownloadHints *pHints) |
3930 { | 3930 { |
3931 int32_t iSize = 0; | 3931 int32_t iSize = 0; |
3932 CFX_ByteString token; | 3932 CFX_ByteString token; |
3933 while (1) { | 3933 while (1) { |
3934 if (!GetNextToken(token)) { | 3934 if (!GetNextToken(token)) { |
3935 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos :
512); | 3935 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos :
512); |
3936 pHints->AddSegment(m_Pos, iSize); | 3936 pHints->AddSegment(m_Pos, iSize); |
3937 return FALSE; | 3937 return false; |
3938 } | 3938 } |
3939 if (token == "trailer") { | 3939 if (token == "trailer") { |
3940 m_dwTrailerOffset = m_Pos; | 3940 m_dwTrailerOffset = m_Pos; |
3941 m_docStatus = PDF_DATAAVAIL_TRAILER; | 3941 m_docStatus = PDF_DATAAVAIL_TRAILER; |
3942 return TRUE; | 3942 return true; |
3943 } | 3943 } |
3944 } | 3944 } |
3945 } | 3945 } |
3946 FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints *pHints) | 3946 bool CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints *pHints) |
3947 { | 3947 { |
3948 FX_FILESIZE xref_offset = 0; | 3948 FX_FILESIZE xref_offset = 0; |
3949 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); | 3949 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); |
3950 if (nRet == 1) { | 3950 if (nRet == 1) { |
3951 if (!xref_offset) { | 3951 if (!xref_offset) { |
3952 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; | 3952 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; |
3953 } else { | 3953 } else { |
3954 m_dwCurrentXRefSteam = xref_offset; | 3954 m_dwCurrentXRefSteam = xref_offset; |
3955 m_Pos = xref_offset; | 3955 m_Pos = xref_offset; |
3956 } | 3956 } |
3957 return TRUE; | 3957 return true; |
3958 } else if (nRet == -1) { | 3958 } else if (nRet == -1) { |
3959 m_docStatus = PDF_DATAAVAIL_ERROR; | 3959 m_docStatus = PDF_DATAAVAIL_ERROR; |
3960 } | 3960 } |
3961 return FALSE; | 3961 return false; |
3962 } | 3962 } |
3963 FX_BOOL CPDF_DataAvail::CheckCrossRef(IFX_DownloadHints* pHints) | 3963 bool CPDF_DataAvail::CheckCrossRef(IFX_DownloadHints* pHints) |
3964 { | 3964 { |
3965 int32_t iSize = 0; | 3965 int32_t iSize = 0; |
3966 CFX_ByteString token; | 3966 CFX_ByteString token; |
3967 if (!GetNextToken(token)) { | 3967 if (!GetNextToken(token)) { |
3968 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512)
; | 3968 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512)
; |
3969 pHints->AddSegment(m_Pos, iSize); | 3969 pHints->AddSegment(m_Pos, iSize); |
3970 return FALSE; | 3970 return false; |
3971 } | 3971 } |
3972 if (token == "xref") { | 3972 if (token == "xref") { |
3973 m_CrossOffset.InsertAt(0, m_dwXRefOffset); | 3973 m_CrossOffset.InsertAt(0, m_dwXRefOffset); |
3974 while (1) { | 3974 while (1) { |
3975 if (!GetNextToken(token)) { | 3975 if (!GetNextToken(token)) { |
3976 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Po
s : 512); | 3976 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Po
s : 512); |
3977 pHints->AddSegment(m_Pos, iSize); | 3977 pHints->AddSegment(m_Pos, iSize); |
3978 m_docStatus = PDF_DATAAVAIL_CROSSREF_ITEM; | 3978 m_docStatus = PDF_DATAAVAIL_CROSSREF_ITEM; |
3979 return FALSE; | 3979 return false; |
3980 } | 3980 } |
3981 if (token == "trailer") { | 3981 if (token == "trailer") { |
3982 m_dwTrailerOffset = m_Pos; | 3982 m_dwTrailerOffset = m_Pos; |
3983 m_docStatus = PDF_DATAAVAIL_TRAILER; | 3983 m_docStatus = PDF_DATAAVAIL_TRAILER; |
3984 return TRUE; | 3984 return true; |
3985 } | 3985 } |
3986 } | 3986 } |
3987 } else { | 3987 } else { |
3988 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3988 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3989 return TRUE; | 3989 return true; |
3990 } | 3990 } |
3991 return FALSE; | 3991 return false; |
3992 } | 3992 } |
3993 FX_BOOL CPDF_DataAvail::CheckTrailerAppend(IFX_DownloadHints* pHints) | 3993 bool CPDF_DataAvail::CheckTrailerAppend(IFX_DownloadHints* pHints) |
3994 { | 3994 { |
3995 if (m_Pos < m_dwFileLen) { | 3995 if (m_Pos < m_dwFileLen) { |
3996 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos(); | 3996 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos(); |
3997 int32_t iSize = (int32_t)(dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen
- dwAppendPos : 512); | 3997 int32_t iSize = (int32_t)(dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen
- dwAppendPos : 512); |
3998 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { | 3998 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { |
3999 pHints->AddSegment(dwAppendPos, iSize); | 3999 pHints->AddSegment(dwAppendPos, iSize); |
4000 return FALSE; | 4000 return false; |
4001 } | 4001 } |
4002 } | 4002 } |
4003 if (m_dwPrevXRefOffset) { | 4003 if (m_dwPrevXRefOffset) { |
4004 SetStartOffset(m_dwPrevXRefOffset); | 4004 SetStartOffset(m_dwPrevXRefOffset); |
4005 m_docStatus = PDF_DATAAVAIL_CROSSREF; | 4005 m_docStatus = PDF_DATAAVAIL_CROSSREF; |
4006 } else { | 4006 } else { |
4007 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; | 4007 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; |
4008 } | 4008 } |
4009 return TRUE; | 4009 return true; |
4010 } | 4010 } |
4011 FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) | 4011 bool CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) |
4012 { | 4012 { |
4013 int32_t iTrailerSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m
_Pos : 512); | 4013 int32_t iTrailerSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m
_Pos : 512); |
4014 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { | 4014 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { |
4015 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); | 4015 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); |
4016 CFX_BinaryBuf buf(iSize); | 4016 CFX_BinaryBuf buf(iSize); |
4017 uint8_t* pBuf = buf.GetBuffer(); | 4017 uint8_t* pBuf = buf.GetBuffer(); |
4018 if (!pBuf) { | 4018 if (!pBuf) { |
4019 m_docStatus = PDF_DATAAVAIL_ERROR; | 4019 m_docStatus = PDF_DATAAVAIL_ERROR; |
4020 return FALSE; | 4020 return false; |
4021 } | 4021 } |
4022 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) { | 4022 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) { |
4023 return FALSE; | 4023 return false; |
4024 } | 4024 } |
4025 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_
t)iSize, FALSE)); | 4025 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_
t)iSize, false)); |
4026 m_syntaxParser.InitParser(file.Get(), 0); | 4026 m_syntaxParser.InitParser(file.Get(), 0); |
4027 CPDF_Object *pTrailer = m_syntaxParser.GetObject(NULL, 0, 0, 0); | 4027 CPDF_Object *pTrailer = m_syntaxParser.GetObject(NULL, 0, 0, 0); |
4028 if (!pTrailer) { | 4028 if (!pTrailer) { |
4029 m_Pos += m_syntaxParser.SavePos(); | 4029 m_Pos += m_syntaxParser.SavePos(); |
4030 pHints->AddSegment(m_Pos, iTrailerSize); | 4030 pHints->AddSegment(m_Pos, iTrailerSize); |
4031 return FALSE; | 4031 return false; |
4032 } | 4032 } |
4033 if (pTrailer->GetType() != PDFOBJ_DICTIONARY) { | 4033 if (pTrailer->GetType() != PDFOBJ_DICTIONARY) { |
4034 return FALSE; | 4034 return false; |
4035 } | 4035 } |
4036 CPDF_Dictionary *pTrailerDict = pTrailer->GetDict(); | 4036 CPDF_Dictionary *pTrailerDict = pTrailer->GetDict(); |
4037 if (pTrailerDict) { | 4037 if (pTrailerDict) { |
4038 CPDF_Object *pEncrypt = pTrailerDict->GetElement("Encrypt"); | 4038 CPDF_Object *pEncrypt = pTrailerDict->GetElement("Encrypt"); |
4039 if (pEncrypt && pEncrypt->GetType() == PDFOBJ_REFERENCE) { | 4039 if (pEncrypt && pEncrypt->GetType() == PDFOBJ_REFERENCE) { |
4040 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 4040 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
4041 pTrailer->Release(); | 4041 pTrailer->Release(); |
4042 return TRUE; | 4042 return true; |
4043 } | 4043 } |
4044 } | 4044 } |
4045 FX_DWORD xrefpos = GetDirectInteger(pTrailer->GetDict(), FX_BSTRC("Prev"
)); | 4045 FX_DWORD xrefpos = GetDirectInteger(pTrailer->GetDict(), FX_BSTRC("Prev"
)); |
4046 if (xrefpos) { | 4046 if (xrefpos) { |
4047 m_dwPrevXRefOffset = GetDirectInteger(pTrailer->GetDict(), FX_BSTRC(
"XRefStm")); | 4047 m_dwPrevXRefOffset = GetDirectInteger(pTrailer->GetDict(), FX_BSTRC(
"XRefStm")); |
4048 pTrailer->Release(); | 4048 pTrailer->Release(); |
4049 if (m_dwPrevXRefOffset) { | 4049 if (m_dwPrevXRefOffset) { |
4050 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 4050 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
4051 } else { | 4051 } else { |
4052 m_dwPrevXRefOffset = xrefpos; | 4052 m_dwPrevXRefOffset = xrefpos; |
4053 if (m_dwPrevXRefOffset >= m_dwFileLen) { | 4053 if (m_dwPrevXRefOffset >= m_dwFileLen) { |
4054 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 4054 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
4055 } else { | 4055 } else { |
4056 SetStartOffset(m_dwPrevXRefOffset); | 4056 SetStartOffset(m_dwPrevXRefOffset); |
4057 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | 4057 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; |
4058 } | 4058 } |
4059 } | 4059 } |
4060 return TRUE; | 4060 return true; |
4061 } else { | 4061 } else { |
4062 m_dwPrevXRefOffset = 0; | 4062 m_dwPrevXRefOffset = 0; |
4063 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | 4063 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; |
4064 pTrailer->Release(); | 4064 pTrailer->Release(); |
4065 } | 4065 } |
4066 return TRUE; | 4066 return true; |
4067 } | 4067 } |
4068 pHints->AddSegment(m_Pos, iTrailerSize); | 4068 pHints->AddSegment(m_Pos, iTrailerSize); |
4069 return FALSE; | 4069 return false; |
4070 } | 4070 } |
4071 FX_BOOL CPDF_DataAvail::CheckPage(int32_t iPage, IFX_DownloadHints* pHints) | 4071 bool CPDF_DataAvail::CheckPage(int32_t iPage, IFX_DownloadHints* pHints) |
4072 { | 4072 { |
4073 while (TRUE) { | 4073 while (true) { |
4074 switch (m_docStatus) { | 4074 switch (m_docStatus) { |
4075 case PDF_DATAAVAIL_PAGETREE: | 4075 case PDF_DATAAVAIL_PAGETREE: |
4076 if (!LoadDocPages(pHints)) { | 4076 if (!LoadDocPages(pHints)) { |
4077 return FALSE; | 4077 return false; |
4078 } | 4078 } |
4079 break; | 4079 break; |
4080 case PDF_DATAAVAIL_PAGE: | 4080 case PDF_DATAAVAIL_PAGE: |
4081 if (!LoadDocPage(iPage, pHints)) { | 4081 if (!LoadDocPage(iPage, pHints)) { |
4082 return FALSE; | 4082 return false; |
4083 } | 4083 } |
4084 break; | 4084 break; |
4085 case PDF_DATAAVAIL_ERROR: | 4085 case PDF_DATAAVAIL_ERROR: |
4086 return LoadAllFile(pHints); | 4086 return LoadAllFile(pHints); |
4087 default: | 4087 default: |
4088 m_bPagesTreeLoad = TRUE; | 4088 m_bPagesTreeLoad = true; |
4089 m_bPagesLoad = TRUE; | 4089 m_bPagesLoad = true; |
4090 m_bCurPageDictLoadOK = TRUE; | 4090 m_bCurPageDictLoadOK = true; |
4091 m_docStatus = PDF_DATAAVAIL_PAGE; | 4091 m_docStatus = PDF_DATAAVAIL_PAGE; |
4092 return TRUE; | 4092 return true; |
4093 } | 4093 } |
4094 } | 4094 } |
4095 } | 4095 } |
4096 FX_BOOL»CPDF_DataAvail::CheckArrayPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPa
geNode, IFX_DownloadHints* pHints) | 4096 bool» CPDF_DataAvail::CheckArrayPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPa
geNode, IFX_DownloadHints* pHints) |
4097 { | 4097 { |
4098 FX_BOOL bExist = FALSE; | 4098 bool bExist = false; |
4099 CPDF_Object *pPages = GetObject(dwPageNo, pHints, &bExist); | 4099 CPDF_Object *pPages = GetObject(dwPageNo, pHints, &bExist); |
4100 if (!bExist) { | 4100 if (!bExist) { |
4101 m_docStatus = PDF_DATAAVAIL_ERROR; | 4101 m_docStatus = PDF_DATAAVAIL_ERROR; |
4102 return FALSE; | 4102 return false; |
4103 } | 4103 } |
4104 if (!pPages) { | 4104 if (!pPages) { |
4105 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 4105 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
4106 m_docStatus = PDF_DATAAVAIL_ERROR; | 4106 m_docStatus = PDF_DATAAVAIL_ERROR; |
4107 return FALSE; | 4107 return false; |
4108 } | 4108 } |
4109 return FALSE; | 4109 return false; |
4110 } | 4110 } |
4111 if (pPages->GetType() != PDFOBJ_ARRAY) { | 4111 if (pPages->GetType() != PDFOBJ_ARRAY) { |
4112 pPages->Release(); | 4112 pPages->Release(); |
4113 m_docStatus = PDF_DATAAVAIL_ERROR; | 4113 m_docStatus = PDF_DATAAVAIL_ERROR; |
4114 return FALSE; | 4114 return false; |
4115 } | 4115 } |
4116 pPageNode->m_type = PDF_PAGENODE_PAGES; | 4116 pPageNode->m_type = PDF_PAGENODE_PAGES; |
4117 CPDF_Array* pArray = (CPDF_Array*)pPages; | 4117 CPDF_Array* pArray = (CPDF_Array*)pPages; |
4118 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { | 4118 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { |
4119 CPDF_Object *pKid = (CPDF_Object *)pArray->GetElement(i); | 4119 CPDF_Object *pKid = (CPDF_Object *)pArray->GetElement(i); |
4120 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { | 4120 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { |
4121 continue; | 4121 continue; |
4122 } | 4122 } |
4123 CPDF_PageNode *pNode = new CPDF_PageNode(); | 4123 CPDF_PageNode *pNode = new CPDF_PageNode(); |
4124 pPageNode->m_childNode.Add(pNode); | 4124 pPageNode->m_childNode.Add(pNode); |
4125 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); | 4125 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); |
4126 } | 4126 } |
4127 pPages->Release(); | 4127 pPages->Release(); |
4128 return TRUE; | 4128 return true; |
4129 } | 4129 } |
4130 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pP
ageNode, IFX_DownloadHints* pHints) | 4130 bool CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPage
Node, IFX_DownloadHints* pHints) |
4131 { | 4131 { |
4132 FX_BOOL bExist = FALSE; | 4132 bool bExist = false; |
4133 CPDF_Object *pPage = GetObject(dwPageNo, pHints, &bExist); | 4133 CPDF_Object *pPage = GetObject(dwPageNo, pHints, &bExist); |
4134 if (!bExist) { | 4134 if (!bExist) { |
4135 m_docStatus = PDF_DATAAVAIL_ERROR; | 4135 m_docStatus = PDF_DATAAVAIL_ERROR; |
4136 return FALSE; | 4136 return false; |
4137 } | 4137 } |
4138 if (!pPage) { | 4138 if (!pPage) { |
4139 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 4139 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
4140 m_docStatus = PDF_DATAAVAIL_ERROR; | 4140 m_docStatus = PDF_DATAAVAIL_ERROR; |
4141 return FALSE; | 4141 return false; |
4142 } | 4142 } |
4143 return FALSE; | 4143 return false; |
4144 } | 4144 } |
4145 if (pPage->GetType() == PDFOBJ_ARRAY) { | 4145 if (pPage->GetType() == PDFOBJ_ARRAY) { |
4146 pPageNode->m_dwPageNo = dwPageNo; | 4146 pPageNode->m_dwPageNo = dwPageNo; |
4147 pPageNode->m_type = PDF_PAGENODE_ARRAY; | 4147 pPageNode->m_type = PDF_PAGENODE_ARRAY; |
4148 pPage->Release(); | 4148 pPage->Release(); |
4149 return TRUE; | 4149 return true; |
4150 } | 4150 } |
4151 if (pPage->GetType() != PDFOBJ_DICTIONARY) { | 4151 if (pPage->GetType() != PDFOBJ_DICTIONARY) { |
4152 pPage->Release(); | 4152 pPage->Release(); |
4153 m_docStatus = PDF_DATAAVAIL_ERROR; | 4153 m_docStatus = PDF_DATAAVAIL_ERROR; |
4154 return FALSE; | 4154 return false; |
4155 } | 4155 } |
4156 pPageNode->m_dwPageNo = dwPageNo; | 4156 pPageNode->m_dwPageNo = dwPageNo; |
4157 CPDF_Dictionary* pDict = pPage->GetDict(); | 4157 CPDF_Dictionary* pDict = pPage->GetDict(); |
4158 CFX_ByteString type = pDict ? pDict->GetString(FX_BSTRC("Type")) : CFX_ByteS
tring(); | 4158 CFX_ByteString type = pDict ? pDict->GetString(FX_BSTRC("Type")) : CFX_ByteS
tring(); |
4159 if (type == FX_BSTRC("Pages")) { | 4159 if (type == FX_BSTRC("Pages")) { |
4160 pPageNode->m_type = PDF_PAGENODE_PAGES; | 4160 pPageNode->m_type = PDF_PAGENODE_PAGES; |
4161 CPDF_Object *pKids = pDict->GetElement(FX_BSTRC("Kids")); | 4161 CPDF_Object *pKids = pDict->GetElement(FX_BSTRC("Kids")); |
4162 if (!pKids) { | 4162 if (!pKids) { |
4163 m_docStatus = PDF_DATAAVAIL_PAGE; | 4163 m_docStatus = PDF_DATAAVAIL_PAGE; |
4164 return TRUE; | 4164 return true; |
4165 } | 4165 } |
4166 switch (pKids->GetType()) { | 4166 switch (pKids->GetType()) { |
4167 case PDFOBJ_REFERENCE: { | 4167 case PDFOBJ_REFERENCE: { |
4168 CPDF_Reference *pKid = (CPDF_Reference *)pKids; | 4168 CPDF_Reference *pKid = (CPDF_Reference *)pKids; |
4169 CPDF_PageNode *pNode = new CPDF_PageNode(); | 4169 CPDF_PageNode *pNode = new CPDF_PageNode(); |
4170 pPageNode->m_childNode.Add(pNode); | 4170 pPageNode->m_childNode.Add(pNode); |
4171 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 4171 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
4172 } | 4172 } |
4173 break; | 4173 break; |
4174 case PDFOBJ_ARRAY: { | 4174 case PDFOBJ_ARRAY: { |
(...skipping 10 matching lines...) Expand all Loading... |
4185 } | 4185 } |
4186 break; | 4186 break; |
4187 default: | 4187 default: |
4188 break; | 4188 break; |
4189 } | 4189 } |
4190 } else if (type == FX_BSTRC("Page")) { | 4190 } else if (type == FX_BSTRC("Page")) { |
4191 pPageNode->m_type = PDF_PAGENODE_PAGE; | 4191 pPageNode->m_type = PDF_PAGENODE_PAGE; |
4192 } else { | 4192 } else { |
4193 pPage->Release(); | 4193 pPage->Release(); |
4194 m_docStatus = PDF_DATAAVAIL_ERROR; | 4194 m_docStatus = PDF_DATAAVAIL_ERROR; |
4195 return FALSE; | 4195 return false; |
4196 } | 4196 } |
4197 pPage->Release(); | 4197 pPage->Release(); |
4198 return TRUE; | 4198 return true; |
4199 } | 4199 } |
4200 FX_BOOL CPDF_DataAvail::CheckPageNode(CPDF_PageNode &pageNodes, int32_t iPage, i
nt32_t &iCount, IFX_DownloadHints* pHints) | 4200 bool CPDF_DataAvail::CheckPageNode(CPDF_PageNode &pageNodes, int32_t iPage, int3
2_t &iCount, IFX_DownloadHints* pHints) |
4201 { | 4201 { |
4202 int32_t iSize = pageNodes.m_childNode.GetSize(); | 4202 int32_t iSize = pageNodes.m_childNode.GetSize(); |
4203 if (iSize <= 0 || iPage >= iSize) { | 4203 if (iSize <= 0 || iPage >= iSize) { |
4204 m_docStatus = PDF_DATAAVAIL_ERROR; | 4204 m_docStatus = PDF_DATAAVAIL_ERROR; |
4205 return FALSE; | 4205 return false; |
4206 } | 4206 } |
4207 for (int32_t i = 0; i < iSize; ++i) { | 4207 for (int32_t i = 0; i < iSize; ++i) { |
4208 CPDF_PageNode *pNode = (CPDF_PageNode*)pageNodes.m_childNode.GetAt(i); | 4208 CPDF_PageNode *pNode = (CPDF_PageNode*)pageNodes.m_childNode.GetAt(i); |
4209 if (!pNode) { | 4209 if (!pNode) { |
4210 continue; | 4210 continue; |
4211 } | 4211 } |
4212 switch (pNode->m_type) { | 4212 switch (pNode->m_type) { |
4213 case PDF_PAGENODE_UNKOWN: | 4213 case PDF_PAGENODE_UNKOWN: |
4214 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) { | 4214 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) { |
4215 return FALSE; | 4215 return false; |
4216 } | 4216 } |
4217 --i; | 4217 --i; |
4218 break; | 4218 break; |
4219 case PDF_PAGENODE_PAGE: | 4219 case PDF_PAGENODE_PAGE: |
4220 iCount++; | 4220 iCount++; |
4221 if (iPage == iCount && m_pDocument) { | 4221 if (iPage == iCount && m_pDocument) { |
4222 m_pDocument->m_PageList.SetAt(iPage, pNode->m_dwPageNo); | 4222 m_pDocument->m_PageList.SetAt(iPage, pNode->m_dwPageNo); |
4223 } | 4223 } |
4224 break; | 4224 break; |
4225 case PDF_PAGENODE_PAGES: | 4225 case PDF_PAGENODE_PAGES: |
4226 if (!CheckPageNode(*pNode, iPage, iCount, pHints)) { | 4226 if (!CheckPageNode(*pNode, iPage, iCount, pHints)) { |
4227 return FALSE; | 4227 return false; |
4228 } | 4228 } |
4229 break; | 4229 break; |
4230 case PDF_PAGENODE_ARRAY: | 4230 case PDF_PAGENODE_ARRAY: |
4231 if (!CheckArrayPageNode(pNode->m_dwPageNo, pNode, pHints)) { | 4231 if (!CheckArrayPageNode(pNode->m_dwPageNo, pNode, pHints)) { |
4232 return FALSE; | 4232 return false; |
4233 } | 4233 } |
4234 --i; | 4234 --i; |
4235 break; | 4235 break; |
4236 } | 4236 } |
4237 if (iPage == iCount) { | 4237 if (iPage == iCount) { |
4238 m_docStatus = PDF_DATAAVAIL_DONE; | 4238 m_docStatus = PDF_DATAAVAIL_DONE; |
4239 return TRUE; | 4239 return true; |
4240 } | 4240 } |
4241 } | 4241 } |
4242 return TRUE; | 4242 return true; |
4243 } | 4243 } |
4244 FX_BOOL CPDF_DataAvail::LoadDocPage(int32_t iPage, IFX_DownloadHints* pHints) | 4244 bool CPDF_DataAvail::LoadDocPage(int32_t iPage, IFX_DownloadHints* pHints) |
4245 { | 4245 { |
4246 if (m_pDocument->GetPageCount() <= iPage || m_pDocument->m_PageList.GetAt(iP
age)) { | 4246 if (m_pDocument->GetPageCount() <= iPage || m_pDocument->m_PageList.GetAt(iP
age)) { |
4247 m_docStatus = PDF_DATAAVAIL_DONE; | 4247 m_docStatus = PDF_DATAAVAIL_DONE; |
4248 return TRUE; | 4248 return true; |
4249 } | 4249 } |
4250 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) { | 4250 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) { |
4251 if (iPage == 0) { | 4251 if (iPage == 0) { |
4252 m_docStatus = PDF_DATAAVAIL_DONE; | 4252 m_docStatus = PDF_DATAAVAIL_DONE; |
4253 return TRUE; | 4253 return true; |
4254 } | 4254 } |
4255 m_docStatus = PDF_DATAAVAIL_ERROR; | 4255 m_docStatus = PDF_DATAAVAIL_ERROR; |
4256 return TRUE; | 4256 return true; |
4257 } | 4257 } |
4258 int32_t iCount = -1; | 4258 int32_t iCount = -1; |
4259 return CheckPageNode(m_pageNodes, iPage, iCount, pHints); | 4259 return CheckPageNode(m_pageNodes, iPage, iCount, pHints); |
4260 } | 4260 } |
4261 FX_BOOL CPDF_DataAvail::CheckPageCount(IFX_DownloadHints* pHints) | 4261 bool CPDF_DataAvail::CheckPageCount(IFX_DownloadHints* pHints) |
4262 { | 4262 { |
4263 FX_BOOL bExist = FALSE; | 4263 bool bExist = false; |
4264 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist); | 4264 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist); |
4265 if (!bExist) { | 4265 if (!bExist) { |
4266 m_docStatus = PDF_DATAAVAIL_ERROR; | 4266 m_docStatus = PDF_DATAAVAIL_ERROR; |
4267 return FALSE; | 4267 return false; |
4268 } | 4268 } |
4269 if (!pPages) { | 4269 if (!pPages) { |
4270 return FALSE; | 4270 return false; |
4271 } | 4271 } |
4272 CPDF_Dictionary* pPagesDict = pPages->GetDict(); | 4272 CPDF_Dictionary* pPagesDict = pPages->GetDict(); |
4273 if (!pPagesDict) { | 4273 if (!pPagesDict) { |
4274 pPages->Release(); | 4274 pPages->Release(); |
4275 m_docStatus = PDF_DATAAVAIL_ERROR; | 4275 m_docStatus = PDF_DATAAVAIL_ERROR; |
4276 return FALSE; | 4276 return false; |
4277 } | 4277 } |
4278 if (!pPagesDict->KeyExist(FX_BSTRC("Kids"))) { | 4278 if (!pPagesDict->KeyExist(FX_BSTRC("Kids"))) { |
4279 pPages->Release(); | 4279 pPages->Release(); |
4280 return TRUE; | 4280 return true; |
4281 } | 4281 } |
4282 int count = pPagesDict->GetInteger(FX_BSTRC("Count")); | 4282 int count = pPagesDict->GetInteger(FX_BSTRC("Count")); |
4283 if (count > 0) { | 4283 if (count > 0) { |
4284 pPages->Release(); | 4284 pPages->Release(); |
4285 return TRUE; | 4285 return true; |
4286 } | 4286 } |
4287 pPages->Release(); | 4287 pPages->Release(); |
4288 return FALSE; | 4288 return false; |
4289 } | 4289 } |
4290 FX_BOOL CPDF_DataAvail::LoadDocPages(IFX_DownloadHints* pHints) | 4290 bool CPDF_DataAvail::LoadDocPages(IFX_DownloadHints* pHints) |
4291 { | 4291 { |
4292 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) { | 4292 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) { |
4293 return FALSE; | 4293 return false; |
4294 } | 4294 } |
4295 if (CheckPageCount(pHints)) { | 4295 if (CheckPageCount(pHints)) { |
4296 m_docStatus = PDF_DATAAVAIL_PAGE; | 4296 m_docStatus = PDF_DATAAVAIL_PAGE; |
4297 return TRUE; | 4297 return true; |
4298 } else { | 4298 } else { |
4299 m_bTotalLoadPageTree = TRUE; | 4299 m_bTotalLoadPageTree = true; |
4300 } | 4300 } |
4301 return FALSE; | 4301 return false; |
4302 } | 4302 } |
4303 FX_BOOL CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints) | 4303 bool CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints) |
4304 { | 4304 { |
4305 while (!m_bPagesTreeLoad) { | 4305 while (!m_bPagesTreeLoad) { |
4306 if (!CheckPageStatus(pHints)) { | 4306 if (!CheckPageStatus(pHints)) { |
4307 return FALSE; | 4307 return false; |
4308 } | 4308 } |
4309 } | 4309 } |
4310 if (m_bPagesLoad) { | 4310 if (m_bPagesLoad) { |
4311 return TRUE; | 4311 return true; |
4312 } | 4312 } |
4313 m_pDocument->LoadPages(); | 4313 m_pDocument->LoadPages(); |
4314 return FALSE; | 4314 return false; |
4315 } | 4315 } |
4316 FX_BOOL CPDF_DataAvail::CheckLinearizedData(IFX_DownloadHints* pHints) | 4316 bool CPDF_DataAvail::CheckLinearizedData(IFX_DownloadHints* pHints) |
4317 { | 4317 { |
4318 if (m_bLinearedDataOK) { | 4318 if (m_bLinearedDataOK) { |
4319 return TRUE; | 4319 return true; |
4320 } | 4320 } |
4321 | 4321 |
4322 if (!m_bMainXRefLoadTried) { | 4322 if (!m_bMainXRefLoadTried) { |
4323 FX_SAFE_DWORD data_size = m_dwFileLen; | 4323 FX_SAFE_DWORD data_size = m_dwFileLen; |
4324 data_size -= m_dwLastXRefOffset; | 4324 data_size -= m_dwLastXRefOffset; |
4325 if (!data_size.IsValid()) { | 4325 if (!data_size.IsValid()) { |
4326 return FALSE; | 4326 return false; |
4327 } | 4327 } |
4328 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, data_size.ValueOrDie(
))) { | 4328 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, data_size.ValueOrDie(
))) { |
4329 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie()); | 4329 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie()); |
4330 return FALSE; | 4330 return false; |
4331 } | 4331 } |
4332 FX_DWORD dwRet = ((CPDF_Parser *)m_pDocument->GetParser())->LoadLineariz
edMainXRefTable(); | 4332 FX_DWORD dwRet = ((CPDF_Parser *)m_pDocument->GetParser())->LoadLineariz
edMainXRefTable(); |
4333 m_bMainXRefLoadTried = TRUE; | 4333 m_bMainXRefLoadTried = true; |
4334 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 4334 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
4335 return FALSE; | 4335 return false; |
4336 } | 4336 } |
4337 if (!PreparePageItem()) { | 4337 if (!PreparePageItem()) { |
4338 return FALSE; | 4338 return false; |
4339 } | 4339 } |
4340 m_bMainXRefLoadedOK = TRUE; | 4340 m_bMainXRefLoadedOK = true; |
4341 m_bLinearedDataOK = TRUE; | 4341 m_bLinearedDataOK = true; |
4342 } | 4342 } |
4343 | 4343 |
4344 return m_bLinearedDataOK; | 4344 return m_bLinearedDataOK; |
4345 } | 4345 } |
4346 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, IFX_DownloadHints* pHints
) | 4346 bool CPDF_DataAvail::CheckPageAnnots(int32_t iPage, IFX_DownloadHints* pHints) |
4347 { | 4347 { |
4348 if (!m_objs_array.GetSize()) { | 4348 if (!m_objs_array.GetSize()) { |
4349 m_objs_array.RemoveAll(); | 4349 m_objs_array.RemoveAll(); |
4350 m_objnum_array.RemoveAll(); | 4350 m_objnum_array.RemoveAll(); |
4351 CPDF_Dictionary *pPageDict = m_pDocument->GetPage(iPage); | 4351 CPDF_Dictionary *pPageDict = m_pDocument->GetPage(iPage); |
4352 if (!pPageDict) { | 4352 if (!pPageDict) { |
4353 return TRUE; | 4353 return true; |
4354 } | 4354 } |
4355 CPDF_Object *pAnnots = pPageDict->GetElement(FX_BSTRC("Annots")); | 4355 CPDF_Object *pAnnots = pPageDict->GetElement(FX_BSTRC("Annots")); |
4356 if (!pAnnots) { | 4356 if (!pAnnots) { |
4357 return TRUE; | 4357 return true; |
4358 } | 4358 } |
4359 CFX_PtrArray obj_array; | 4359 CFX_PtrArray obj_array; |
4360 obj_array.Add(pAnnots); | 4360 obj_array.Add(pAnnots); |
4361 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 4361 bool bRet = IsObjectsAvail(obj_array, false, pHints, m_objs_array); |
4362 if (bRet) { | 4362 if (bRet) { |
4363 m_objs_array.RemoveAll(); | 4363 m_objs_array.RemoveAll(); |
4364 } | 4364 } |
4365 return bRet; | 4365 return bRet; |
4366 } else { | 4366 } else { |
4367 CFX_PtrArray new_objs_array; | 4367 CFX_PtrArray new_objs_array; |
4368 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra
y); | 4368 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_array); |
4369 m_objs_array.RemoveAll(); | 4369 m_objs_array.RemoveAll(); |
4370 if (!bRet) { | 4370 if (!bRet) { |
4371 m_objs_array.Append(new_objs_array); | 4371 m_objs_array.Append(new_objs_array); |
4372 } | 4372 } |
4373 return bRet; | 4373 return bRet; |
4374 } | 4374 } |
4375 } | 4375 } |
4376 FX_BOOL CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, IFX_DownloadHint
s* pHints) | 4376 bool CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, IFX_DownloadHints*
pHints) |
4377 { | 4377 { |
4378 if (!m_bAnnotsLoad) { | 4378 if (!m_bAnnotsLoad) { |
4379 if (!CheckPageAnnots(iPage, pHints)) { | 4379 if (!CheckPageAnnots(iPage, pHints)) { |
4380 return FALSE; | 4380 return false; |
4381 } | 4381 } |
4382 m_bAnnotsLoad = TRUE; | 4382 m_bAnnotsLoad = true; |
4383 } | 4383 } |
4384 if (m_bAnnotsLoad) | 4384 if (m_bAnnotsLoad) |
4385 if (!CheckLinearizedData(pHints)) { | 4385 if (!CheckLinearizedData(pHints)) { |
4386 return FALSE; | 4386 return false; |
4387 } | 4387 } |
4388 m_bPageLoadedOK = FALSE; | 4388 m_bPageLoadedOK = false; |
4389 return TRUE; | 4389 return true; |
4390 } | 4390 } |
4391 FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary *pDict) | 4391 bool CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary *pDict) |
4392 { | 4392 { |
4393 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); | 4393 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); |
4394 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) { | 4394 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) { |
4395 return FALSE; | 4395 return false; |
4396 } | 4396 } |
4397 CPDF_Object *pParent = pDict->GetElement("Parent"); | 4397 CPDF_Object *pParent = pDict->GetElement("Parent"); |
4398 if (!pParent) { | 4398 if (!pParent) { |
4399 return FALSE; | 4399 return false; |
4400 } | 4400 } |
4401 CPDF_Dictionary *pParentDict = pParent->GetDict(); | 4401 CPDF_Dictionary *pParentDict = pParent->GetDict(); |
4402 if (!pParentDict) { | 4402 if (!pParentDict) { |
4403 return FALSE; | 4403 return false; |
4404 } | 4404 } |
4405 CPDF_Object *pRet = pParentDict->GetElement("Resources"); | 4405 CPDF_Object *pRet = pParentDict->GetElement("Resources"); |
4406 if (pRet) { | 4406 if (pRet) { |
4407 m_pPageResource = pRet; | 4407 m_pPageResource = pRet; |
4408 return TRUE; | 4408 return true; |
4409 } | 4409 } |
4410 return HaveResourceAncestor(pParentDict); | 4410 return HaveResourceAncestor(pParentDict); |
4411 } | 4411 } |
4412 FX_BOOL CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) | 4412 bool CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) |
4413 { | 4413 { |
4414 if (!m_pDocument) { | 4414 if (!m_pDocument) { |
4415 return FALSE; | 4415 return false; |
4416 } | 4416 } |
4417 if (IsFirstCheck(iPage)) { | 4417 if (IsFirstCheck(iPage)) { |
4418 m_bCurPageDictLoadOK = FALSE; | 4418 m_bCurPageDictLoadOK = false; |
4419 m_bPageLoadedOK = FALSE; | 4419 m_bPageLoadedOK = false; |
4420 m_bAnnotsLoad = FALSE; | 4420 m_bAnnotsLoad = false; |
4421 m_bNeedDownLoadResource = FALSE; | 4421 m_bNeedDownLoadResource = false; |
4422 m_objs_array.RemoveAll(); | 4422 m_objs_array.RemoveAll(); |
4423 m_objnum_array.RemoveAll(); | 4423 m_objnum_array.RemoveAll(); |
4424 } | 4424 } |
4425 if (m_pagesLoadState == NULL) { | 4425 if (m_pagesLoadState == NULL) { |
4426 m_pagesLoadState = new CFX_CMapDWordToDWord(); | 4426 m_pagesLoadState = new CFX_CMapDWordToDWord(); |
4427 } | 4427 } |
4428 FX_DWORD dwPageLoad = 0; | 4428 FX_DWORD dwPageLoad = 0; |
4429 if (m_pagesLoadState->Lookup(iPage, dwPageLoad) && dwPageLoad != 0) { | 4429 if (m_pagesLoadState->Lookup(iPage, dwPageLoad) && dwPageLoad != 0) { |
4430 return TRUE; | 4430 return true; |
4431 } | 4431 } |
4432 if (m_bLinearized) { | 4432 if (m_bLinearized) { |
4433 if ((FX_DWORD)iPage == m_dwFirstPageNo) { | 4433 if ((FX_DWORD)iPage == m_dwFirstPageNo) { |
4434 m_pagesLoadState->SetAt(iPage, TRUE); | 4434 m_pagesLoadState->SetAt(iPage, true); |
4435 return TRUE; | 4435 return true; |
4436 } | 4436 } |
4437 if (!CheckLinearizedData(pHints)) { | 4437 if (!CheckLinearizedData(pHints)) { |
4438 return FALSE; | 4438 return false; |
4439 } | 4439 } |
4440 if (m_bMainXRefLoadedOK) { | 4440 if (m_bMainXRefLoadedOK) { |
4441 if (m_bTotalLoadPageTree) { | 4441 if (m_bTotalLoadPageTree) { |
4442 if (!LoadPages(pHints)) { | 4442 if (!LoadPages(pHints)) { |
4443 return FALSE; | 4443 return false; |
4444 } | 4444 } |
4445 } else { | 4445 } else { |
4446 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { | 4446 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { |
4447 return FALSE; | 4447 return false; |
4448 } | 4448 } |
4449 } | 4449 } |
4450 } else { | 4450 } else { |
4451 if (!LoadAllFile(pHints)) { | 4451 if (!LoadAllFile(pHints)) { |
4452 return FALSE; | 4452 return false; |
4453 } | 4453 } |
4454 ((CPDF_Parser *)m_pDocument->GetParser())->RebuildCrossRef(); | 4454 ((CPDF_Parser *)m_pDocument->GetParser())->RebuildCrossRef(); |
4455 ResetFirstCheck(iPage); | 4455 ResetFirstCheck(iPage); |
4456 return TRUE; | 4456 return true; |
4457 } | 4457 } |
4458 } else { | 4458 } else { |
4459 if (!m_bTotalLoadPageTree) { | 4459 if (!m_bTotalLoadPageTree) { |
4460 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { | 4460 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { |
4461 return FALSE; | 4461 return false; |
4462 } | 4462 } |
4463 } | 4463 } |
4464 } | 4464 } |
4465 if (m_bHaveAcroForm && !m_bAcroFormLoad) { | 4465 if (m_bHaveAcroForm && !m_bAcroFormLoad) { |
4466 if (!CheckAcroFormSubObject(pHints)) { | 4466 if (!CheckAcroFormSubObject(pHints)) { |
4467 return FALSE; | 4467 return false; |
4468 } | 4468 } |
4469 m_bAcroFormLoad = TRUE; | 4469 m_bAcroFormLoad = true; |
4470 } | 4470 } |
4471 if (!m_bPageLoadedOK) { | 4471 if (!m_bPageLoadedOK) { |
4472 if (!m_objs_array.GetSize()) { | 4472 if (!m_objs_array.GetSize()) { |
4473 m_objs_array.RemoveAll(); | 4473 m_objs_array.RemoveAll(); |
4474 m_objnum_array.RemoveAll(); | 4474 m_objnum_array.RemoveAll(); |
4475 m_pPageDict = m_pDocument->GetPage(iPage); | 4475 m_pPageDict = m_pDocument->GetPage(iPage); |
4476 if (!m_pPageDict) { | 4476 if (!m_pPageDict) { |
4477 ResetFirstCheck(iPage); | 4477 ResetFirstCheck(iPage); |
4478 return TRUE; | 4478 return true; |
4479 } | 4479 } |
4480 CFX_PtrArray obj_array; | 4480 CFX_PtrArray obj_array; |
4481 obj_array.Add(m_pPageDict); | 4481 obj_array.Add(m_pPageDict); |
4482 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array)
; | 4482 bool bRet = IsObjectsAvail(obj_array, true, pHints, m_objs_array); |
4483 if (bRet) { | 4483 if (bRet) { |
4484 m_objs_array.RemoveAll(); | 4484 m_objs_array.RemoveAll(); |
4485 m_bPageLoadedOK = TRUE; | 4485 m_bPageLoadedOK = true; |
4486 } else { | 4486 } else { |
4487 return bRet; | 4487 return bRet; |
4488 } | 4488 } |
4489 } else { | 4489 } else { |
4490 CFX_PtrArray new_objs_array; | 4490 CFX_PtrArray new_objs_array; |
4491 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_
array); | 4491 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_arr
ay); |
4492 m_objs_array.RemoveAll(); | 4492 m_objs_array.RemoveAll(); |
4493 if (bRet) { | 4493 if (bRet) { |
4494 m_bPageLoadedOK = TRUE; | 4494 m_bPageLoadedOK = true; |
4495 } else { | 4495 } else { |
4496 m_objs_array.Append(new_objs_array); | 4496 m_objs_array.Append(new_objs_array); |
4497 return bRet; | 4497 return bRet; |
4498 } | 4498 } |
4499 } | 4499 } |
4500 } | 4500 } |
4501 if (m_bPageLoadedOK) { | 4501 if (m_bPageLoadedOK) { |
4502 if (!m_bAnnotsLoad) { | 4502 if (!m_bAnnotsLoad) { |
4503 if (!CheckPageAnnots(iPage, pHints)) { | 4503 if (!CheckPageAnnots(iPage, pHints)) { |
4504 return FALSE; | 4504 return false; |
4505 } | 4505 } |
4506 m_bAnnotsLoad = TRUE; | 4506 m_bAnnotsLoad = true; |
4507 } | 4507 } |
4508 } | 4508 } |
4509 if (m_pPageDict && !m_bNeedDownLoadResource) { | 4509 if (m_pPageDict && !m_bNeedDownLoadResource) { |
4510 m_pPageResource = m_pPageDict->GetElement("Resources"); | 4510 m_pPageResource = m_pPageDict->GetElement("Resources"); |
4511 if (!m_pPageResource) { | 4511 if (!m_pPageResource) { |
4512 m_bNeedDownLoadResource = HaveResourceAncestor(m_pPageDict); | 4512 m_bNeedDownLoadResource = HaveResourceAncestor(m_pPageDict); |
4513 } else { | 4513 } else { |
4514 m_bNeedDownLoadResource = TRUE; | 4514 m_bNeedDownLoadResource = true; |
4515 } | 4515 } |
4516 } | 4516 } |
4517 if (m_bNeedDownLoadResource) { | 4517 if (m_bNeedDownLoadResource) { |
4518 FX_BOOL bRet = CheckResources(pHints); | 4518 bool bRet = CheckResources(pHints); |
4519 if (!bRet) { | 4519 if (!bRet) { |
4520 return FALSE; | 4520 return false; |
4521 } | 4521 } |
4522 m_bNeedDownLoadResource = FALSE; | 4522 m_bNeedDownLoadResource = false; |
4523 } | 4523 } |
4524 m_bPageLoadedOK = FALSE; | 4524 m_bPageLoadedOK = false; |
4525 m_bAnnotsLoad = FALSE; | 4525 m_bAnnotsLoad = false; |
4526 m_bCurPageDictLoadOK = FALSE; | 4526 m_bCurPageDictLoadOK = false; |
4527 ResetFirstCheck(iPage); | 4527 ResetFirstCheck(iPage); |
4528 m_pagesLoadState->SetAt(iPage, TRUE); | 4528 m_pagesLoadState->SetAt(iPage, true); |
4529 return TRUE; | 4529 return true; |
4530 } | 4530 } |
4531 FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) | 4531 bool CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) |
4532 { | 4532 { |
4533 if (!m_objs_array.GetSize()) { | 4533 if (!m_objs_array.GetSize()) { |
4534 m_objs_array.RemoveAll(); | 4534 m_objs_array.RemoveAll(); |
4535 CFX_PtrArray obj_array; | 4535 CFX_PtrArray obj_array; |
4536 obj_array.Add(m_pPageResource); | 4536 obj_array.Add(m_pPageResource); |
4537 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); | 4537 bool bRet = IsObjectsAvail(obj_array, true, pHints, m_objs_array); |
4538 if (bRet) { | 4538 if (bRet) { |
4539 m_objs_array.RemoveAll(); | 4539 m_objs_array.RemoveAll(); |
4540 } | 4540 } |
4541 return bRet; | 4541 return bRet; |
4542 } else { | 4542 } else { |
4543 CFX_PtrArray new_objs_array; | 4543 CFX_PtrArray new_objs_array; |
4544 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra
y); | 4544 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_array); |
4545 m_objs_array.RemoveAll(); | 4545 m_objs_array.RemoveAll(); |
4546 if (!bRet) { | 4546 if (!bRet) { |
4547 m_objs_array.Append(new_objs_array); | 4547 m_objs_array.Append(new_objs_array); |
4548 } | 4548 } |
4549 return bRet; | 4549 return bRet; |
4550 } | 4550 } |
4551 } | 4551 } |
4552 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSiz
e) | 4552 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSiz
e) |
4553 { | 4553 { |
4554 if (pPos) { | 4554 if (pPos) { |
(...skipping 16 matching lines...) Expand all Loading... |
4571 CPDF_Object *pAcroForm = pRoot->GetElement(FX_BSTRC("AcroForm")); | 4571 CPDF_Object *pAcroForm = pRoot->GetElement(FX_BSTRC("AcroForm")); |
4572 if (!pAcroForm) { | 4572 if (!pAcroForm) { |
4573 return PDFFORM_NOTEXIST; | 4573 return PDFFORM_NOTEXIST; |
4574 } | 4574 } |
4575 if (!CheckLinearizedData(pHints)) { | 4575 if (!CheckLinearizedData(pHints)) { |
4576 return PDFFORM_NOTAVAIL; | 4576 return PDFFORM_NOTAVAIL; |
4577 } | 4577 } |
4578 if (!m_objs_array.GetSize()) { | 4578 if (!m_objs_array.GetSize()) { |
4579 m_objs_array.Add(pAcroForm->GetDict()); | 4579 m_objs_array.Add(pAcroForm->GetDict()); |
4580 } | 4580 } |
4581 m_bLinearizedFormParamLoad = TRUE; | 4581 m_bLinearizedFormParamLoad = true; |
4582 } | 4582 } |
4583 CFX_PtrArray new_objs_array; | 4583 CFX_PtrArray new_objs_array; |
4584 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 4584 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_array); |
4585 m_objs_array.RemoveAll(); | 4585 m_objs_array.RemoveAll(); |
4586 if (!bRet) { | 4586 if (!bRet) { |
4587 m_objs_array.Append(new_objs_array); | 4587 m_objs_array.Append(new_objs_array); |
4588 return PDFFORM_NOTAVAIL; | 4588 return PDFFORM_NOTAVAIL; |
4589 } | 4589 } |
4590 return PDFFORM_AVAIL; | 4590 return PDFFORM_AVAIL; |
4591 } | 4591 } |
4592 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) | 4592 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) |
4593 { | 4593 { |
4594 int32_t iNext = 0; | 4594 int32_t iNext = 0; |
4595 if (BinarySearch(dwObjNum, iNext)) { | 4595 if (BinarySearch(dwObjNum, iNext)) { |
4596 return; | 4596 return; |
4597 } | 4597 } |
4598 m_number_array.InsertAt(iNext, dwObjNum); | 4598 m_number_array.InsertAt(iNext, dwObjNum); |
4599 } | 4599 } |
4600 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) | 4600 bool CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) |
4601 { | 4601 { |
4602 int32_t iNext = 0; | 4602 int32_t iNext = 0; |
4603 return BinarySearch(dwObjNum, iNext); | 4603 return BinarySearch(dwObjNum, iNext); |
4604 } | 4604 } |
4605 FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t &iNext) | 4605 bool CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t &iNext) |
4606 { | 4606 { |
4607 int32_t iLen = m_number_array.GetSize(); | 4607 int32_t iLen = m_number_array.GetSize(); |
4608 int32_t iLow = 0; | 4608 int32_t iLow = 0; |
4609 int32_t iHigh = iLen - 1; | 4609 int32_t iHigh = iLen - 1; |
4610 int32_t iMid = 0; | 4610 int32_t iMid = 0; |
4611 while (iLow <= iHigh) { | 4611 while (iLow <= iHigh) { |
4612 iMid = (iLow + iHigh) / 2; | 4612 iMid = (iLow + iHigh) / 2; |
4613 if (m_number_array.GetAt(iMid) == value) { | 4613 if (m_number_array.GetAt(iMid) == value) { |
4614 iNext = iMid; | 4614 iNext = iMid; |
4615 return TRUE; | 4615 return true; |
4616 } else if (m_number_array.GetAt(iMid) > value) { | 4616 } else if (m_number_array.GetAt(iMid) > value) { |
4617 iHigh = iMid - 1; | 4617 iHigh = iMid - 1; |
4618 } else if (m_number_array.GetAt(iMid) < value) { | 4618 } else if (m_number_array.GetAt(iMid) < value) { |
4619 iLow = iMid + 1; | 4619 iLow = iMid + 1; |
4620 } | 4620 } |
4621 } | 4621 } |
4622 iNext = iLow; | 4622 iNext = iLow; |
4623 return FALSE; | 4623 return false; |
4624 } | 4624 } |
4625 CPDF_PageNode::~CPDF_PageNode() | 4625 CPDF_PageNode::~CPDF_PageNode() |
4626 { | 4626 { |
4627 int32_t iSize = m_childNode.GetSize(); | 4627 int32_t iSize = m_childNode.GetSize(); |
4628 for (int32_t i = 0; i < iSize; ++i) { | 4628 for (int32_t i = 0; i < iSize; ++i) { |
4629 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4629 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; |
4630 delete pNode; | 4630 delete pNode; |
4631 } | 4631 } |
4632 m_childNode.RemoveAll(); | 4632 m_childNode.RemoveAll(); |
4633 } | 4633 } |
OLD | NEW |