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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 return; | 2029 return; |
2030 } | 2030 } |
2031 if (ch == '\r' || ch == '\n') { | 2031 if (ch == '\r' || ch == '\n') { |
2032 break; | 2032 break; |
2033 } | 2033 } |
2034 } | 2034 } |
2035 type = PDF_CharType[ch]; | 2035 type = PDF_CharType[ch]; |
2036 } | 2036 } |
2037 m_Pos --; | 2037 m_Pos --; |
2038 } | 2038 } |
2039 CFX_ByteString CPDF_SyntaxParser::GetNextWord(FX_BOOL& bIsNumber) | 2039 CFX_ByteString CPDF_SyntaxParser::GetNextWord(bool& bIsNumber) |
2040 { | 2040 { |
2041 GetNextWord(); | 2041 GetNextWord(); |
2042 bIsNumber = m_bIsNumber; | 2042 bIsNumber = m_bIsNumber; |
2043 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); | 2043 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); |
2044 } | 2044 } |
2045 CFX_ByteString CPDF_SyntaxParser::GetKeyword() | 2045 CFX_ByteString CPDF_SyntaxParser::GetKeyword() |
2046 { | 2046 { |
2047 GetNextWord(); | 2047 GetNextWord(); |
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 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO
RD objnum, FX_DWORD gennum, PARSE_CONTEXT* pContext, FX_BOOL bDecrypt) | 2050 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, FX_DWO
RD objnum, FX_DWORD gennum, PARSE_CONTEXT* pContext, bool bDecrypt) |
2051 { | 2051 { |
2052 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2052 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
2053 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2053 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
2054 return NULL; | 2054 return NULL; |
2055 } | 2055 } |
2056 FX_FILESIZE SavedPos = m_Pos; | 2056 FX_FILESIZE SavedPos = m_Pos; |
2057 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2057 bool bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
2058 FX_BOOL bIsNumber; | 2058 bool bIsNumber; |
2059 CFX_ByteString word = GetNextWord(bIsNumber); | 2059 CFX_ByteString word = GetNextWord(bIsNumber); |
2060 if (word.GetLength() == 0) { | 2060 if (word.GetLength() == 0) { |
2061 if (bTypeOnly) { | 2061 if (bTypeOnly) { |
2062 return (CPDF_Object*)PDFOBJ_INVALID; | 2062 return (CPDF_Object*)PDFOBJ_INVALID; |
2063 } | 2063 } |
2064 return NULL; | 2064 return NULL; |
2065 } | 2065 } |
2066 if (bIsNumber) { | 2066 if (bIsNumber) { |
2067 FX_FILESIZE SavedPos = m_Pos; | 2067 FX_FILESIZE SavedPos = m_Pos; |
2068 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2068 CFX_ByteString nextword = GetNextWord(bIsNumber); |
(...skipping 26 matching lines...) Expand all Loading... |
2095 return CPDF_Null::Create(); | 2095 return CPDF_Null::Create(); |
2096 } | 2096 } |
2097 if (word == FX_BSTRC("(")) { | 2097 if (word == FX_BSTRC("(")) { |
2098 if (bTypeOnly) { | 2098 if (bTypeOnly) { |
2099 return (CPDF_Object*)PDFOBJ_STRING; | 2099 return (CPDF_Object*)PDFOBJ_STRING; |
2100 } | 2100 } |
2101 CFX_ByteString str = ReadString(); | 2101 CFX_ByteString str = ReadString(); |
2102 if (m_pCryptoHandler && bDecrypt) { | 2102 if (m_pCryptoHandler && bDecrypt) { |
2103 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2103 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2104 } | 2104 } |
2105 return CPDF_String::Create(str, FALSE); | 2105 return CPDF_String::Create(str, false); |
2106 } | 2106 } |
2107 if (word == FX_BSTRC("<")) { | 2107 if (word == FX_BSTRC("<")) { |
2108 if (bTypeOnly) { | 2108 if (bTypeOnly) { |
2109 return (CPDF_Object*)PDFOBJ_STRING; | 2109 return (CPDF_Object*)PDFOBJ_STRING; |
2110 } | 2110 } |
2111 CFX_ByteString str = ReadHexString(); | 2111 CFX_ByteString str = ReadHexString(); |
2112 if (m_pCryptoHandler && bDecrypt) { | 2112 if (m_pCryptoHandler && bDecrypt) { |
2113 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2113 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2114 } | 2114 } |
2115 return CPDF_String::Create(str, TRUE); | 2115 return CPDF_String::Create(str, true); |
2116 } | 2116 } |
2117 if (word == FX_BSTRC("[")) { | 2117 if (word == FX_BSTRC("[")) { |
2118 if (bTypeOnly) { | 2118 if (bTypeOnly) { |
2119 return (CPDF_Object*)PDFOBJ_ARRAY; | 2119 return (CPDF_Object*)PDFOBJ_ARRAY; |
2120 } | 2120 } |
2121 CPDF_Array* pArray = CPDF_Array::Create(); | 2121 CPDF_Array* pArray = CPDF_Array::Create(); |
2122 while (1) { | 2122 while (1) { |
2123 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); | 2123 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); |
2124 if (pObj == NULL) { | 2124 if (pObj == NULL) { |
2125 return pArray; | 2125 return pArray; |
(...skipping 12 matching lines...) Expand all Loading... |
2138 if (bTypeOnly) { | 2138 if (bTypeOnly) { |
2139 return (CPDF_Object*)PDFOBJ_DICTIONARY; | 2139 return (CPDF_Object*)PDFOBJ_DICTIONARY; |
2140 } | 2140 } |
2141 if (pContext) { | 2141 if (pContext) { |
2142 pContext->m_DictStart = SavedPos; | 2142 pContext->m_DictStart = SavedPos; |
2143 } | 2143 } |
2144 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); | 2144 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); |
2145 int32_t nKeys = 0; | 2145 int32_t nKeys = 0; |
2146 FX_FILESIZE dwSignValuePos = 0; | 2146 FX_FILESIZE dwSignValuePos = 0; |
2147 while (1) { | 2147 while (1) { |
2148 FX_BOOL bIsNumber; | 2148 bool bIsNumber; |
2149 CFX_ByteString key = GetNextWord(bIsNumber); | 2149 CFX_ByteString key = GetNextWord(bIsNumber); |
2150 if (key.IsEmpty()) { | 2150 if (key.IsEmpty()) { |
2151 if (pDict) | 2151 if (pDict) |
2152 pDict->Release(); | 2152 pDict->Release(); |
2153 return NULL; | 2153 return NULL; |
2154 } | 2154 } |
2155 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); | 2155 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); |
2156 if (key == FX_BSTRC(">>")) { | 2156 if (key == FX_BSTRC(">>")) { |
2157 break; | 2157 break; |
2158 } | 2158 } |
(...skipping 17 matching lines...) Expand all Loading... |
2176 if (nKeys < 32) { | 2176 if (nKeys < 32) { |
2177 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength(
) - 1), pObj); | 2177 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength(
) - 1), pObj); |
2178 } else { | 2178 } else { |
2179 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLeng
th() - 1), pObj); | 2179 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLeng
th() - 1), pObj); |
2180 } | 2180 } |
2181 } | 2181 } |
2182 } | 2182 } |
2183 if (IsSignatureDict(pDict)) { | 2183 if (IsSignatureDict(pDict)) { |
2184 FX_FILESIZE dwSavePos = m_Pos; | 2184 FX_FILESIZE dwSavePos = m_Pos; |
2185 m_Pos = dwSignValuePos; | 2185 m_Pos = dwSignValuePos; |
2186 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, NULL, FALSE)
; | 2186 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, NULL, false)
; |
2187 pDict->SetAt(FX_BSTRC("Contents"), pObj); | 2187 pDict->SetAt(FX_BSTRC("Contents"), pObj); |
2188 m_Pos = dwSavePos; | 2188 m_Pos = dwSavePos; |
2189 } | 2189 } |
2190 if (pContext) { | 2190 if (pContext) { |
2191 pContext->m_DictEnd = m_Pos; | 2191 pContext->m_DictEnd = m_Pos; |
2192 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2192 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
2193 return pDict; | 2193 return pDict; |
2194 } | 2194 } |
2195 } | 2195 } |
2196 FX_FILESIZE SavedPos = m_Pos; | 2196 FX_FILESIZE SavedPos = m_Pos; |
2197 FX_BOOL bIsNumber; | 2197 bool bIsNumber; |
2198 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2198 CFX_ByteString nextword = GetNextWord(bIsNumber); |
2199 if (nextword == FX_BSTRC("stream")) { | 2199 if (nextword == FX_BSTRC("stream")) { |
2200 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); | 2200 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); |
2201 if (pStream) { | 2201 if (pStream) { |
2202 return pStream; | 2202 return pStream; |
2203 } | 2203 } |
2204 if (pDict) | 2204 if (pDict) |
2205 pDict->Release(); | 2205 pDict->Release(); |
2206 return NULL; | 2206 return NULL; |
2207 } else { | 2207 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
2218 } | 2218 } |
2219 return NULL; | 2219 return NULL; |
2220 } | 2220 } |
2221 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList
, FX_DWORD objnum, FX_DWORD gennum, struct PARSE_CONTEXT* pContext) | 2221 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(CPDF_IndirectObjects* pObjList
, FX_DWORD objnum, FX_DWORD gennum, struct PARSE_CONTEXT* pContext) |
2222 { | 2222 { |
2223 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2223 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
2224 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2224 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
2225 return NULL; | 2225 return NULL; |
2226 } | 2226 } |
2227 FX_FILESIZE SavedPos = m_Pos; | 2227 FX_FILESIZE SavedPos = m_Pos; |
2228 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); | 2228 bool bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY); |
2229 FX_BOOL bIsNumber; | 2229 bool bIsNumber; |
2230 CFX_ByteString word = GetNextWord(bIsNumber); | 2230 CFX_ByteString word = GetNextWord(bIsNumber); |
2231 if (word.GetLength() == 0) { | 2231 if (word.GetLength() == 0) { |
2232 if (bTypeOnly) { | 2232 if (bTypeOnly) { |
2233 return (CPDF_Object*)PDFOBJ_INVALID; | 2233 return (CPDF_Object*)PDFOBJ_INVALID; |
2234 } | 2234 } |
2235 return NULL; | 2235 return NULL; |
2236 } | 2236 } |
2237 if (bIsNumber) { | 2237 if (bIsNumber) { |
2238 FX_FILESIZE SavedPos = m_Pos; | 2238 FX_FILESIZE SavedPos = m_Pos; |
2239 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2239 CFX_ByteString nextword = GetNextWord(bIsNumber); |
(...skipping 26 matching lines...) Expand all Loading... |
2266 return CPDF_Null::Create(); | 2266 return CPDF_Null::Create(); |
2267 } | 2267 } |
2268 if (word == FX_BSTRC("(")) { | 2268 if (word == FX_BSTRC("(")) { |
2269 if (bTypeOnly) { | 2269 if (bTypeOnly) { |
2270 return (CPDF_Object*)PDFOBJ_STRING; | 2270 return (CPDF_Object*)PDFOBJ_STRING; |
2271 } | 2271 } |
2272 CFX_ByteString str = ReadString(); | 2272 CFX_ByteString str = ReadString(); |
2273 if (m_pCryptoHandler) { | 2273 if (m_pCryptoHandler) { |
2274 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2274 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2275 } | 2275 } |
2276 return CPDF_String::Create(str, FALSE); | 2276 return CPDF_String::Create(str, false); |
2277 } | 2277 } |
2278 if (word == FX_BSTRC("<")) { | 2278 if (word == FX_BSTRC("<")) { |
2279 if (bTypeOnly) { | 2279 if (bTypeOnly) { |
2280 return (CPDF_Object*)PDFOBJ_STRING; | 2280 return (CPDF_Object*)PDFOBJ_STRING; |
2281 } | 2281 } |
2282 CFX_ByteString str = ReadHexString(); | 2282 CFX_ByteString str = ReadHexString(); |
2283 if (m_pCryptoHandler) { | 2283 if (m_pCryptoHandler) { |
2284 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2284 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2285 } | 2285 } |
2286 return CPDF_String::Create(str, TRUE); | 2286 return CPDF_String::Create(str, true); |
2287 } | 2287 } |
2288 if (word == FX_BSTRC("[")) { | 2288 if (word == FX_BSTRC("[")) { |
2289 if (bTypeOnly) { | 2289 if (bTypeOnly) { |
2290 return (CPDF_Object*)PDFOBJ_ARRAY; | 2290 return (CPDF_Object*)PDFOBJ_ARRAY; |
2291 } | 2291 } |
2292 CPDF_Array* pArray = CPDF_Array::Create(); | 2292 CPDF_Array* pArray = CPDF_Array::Create(); |
2293 while (1) { | 2293 while (1) { |
2294 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); | 2294 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); |
2295 if (pObj == NULL) { | 2295 if (pObj == NULL) { |
2296 if (m_WordBuffer[0] == ']') { | 2296 if (m_WordBuffer[0] == ']') { |
(...skipping 15 matching lines...) Expand all Loading... |
2312 } | 2312 } |
2313 if (word == FX_BSTRC("<<")) { | 2313 if (word == FX_BSTRC("<<")) { |
2314 if (bTypeOnly) { | 2314 if (bTypeOnly) { |
2315 return (CPDF_Object*)PDFOBJ_DICTIONARY; | 2315 return (CPDF_Object*)PDFOBJ_DICTIONARY; |
2316 } | 2316 } |
2317 if (pContext) { | 2317 if (pContext) { |
2318 pContext->m_DictStart = SavedPos; | 2318 pContext->m_DictStart = SavedPos; |
2319 } | 2319 } |
2320 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); | 2320 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); |
2321 while (1) { | 2321 while (1) { |
2322 FX_BOOL bIsNumber; | 2322 bool bIsNumber; |
2323 FX_FILESIZE SavedPos = m_Pos; | 2323 FX_FILESIZE SavedPos = m_Pos; |
2324 CFX_ByteString key = GetNextWord(bIsNumber); | 2324 CFX_ByteString key = GetNextWord(bIsNumber); |
2325 if (key.IsEmpty()) { | 2325 if (key.IsEmpty()) { |
2326 if (pDict) { | 2326 if (pDict) { |
2327 pDict->Release(); | 2327 pDict->Release(); |
2328 } | 2328 } |
2329 return NULL; | 2329 return NULL; |
2330 } | 2330 } |
2331 if (key == FX_BSTRC(">>")) { | 2331 if (key == FX_BSTRC(">>")) { |
2332 break; | 2332 break; |
(...skipping 26 matching lines...) Expand all Loading... |
2359 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLength()
- 1), pObj); | 2359 pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLength()
- 1), pObj); |
2360 } | 2360 } |
2361 } | 2361 } |
2362 if (pContext) { | 2362 if (pContext) { |
2363 pContext->m_DictEnd = m_Pos; | 2363 pContext->m_DictEnd = m_Pos; |
2364 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { | 2364 if (pContext->m_Flags & PDFPARSE_NOSTREAM) { |
2365 return pDict; | 2365 return pDict; |
2366 } | 2366 } |
2367 } | 2367 } |
2368 FX_FILESIZE SavedPos = m_Pos; | 2368 FX_FILESIZE SavedPos = m_Pos; |
2369 FX_BOOL bIsNumber; | 2369 bool bIsNumber; |
2370 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2370 CFX_ByteString nextword = GetNextWord(bIsNumber); |
2371 if (nextword == FX_BSTRC("stream")) { | 2371 if (nextword == FX_BSTRC("stream")) { |
2372 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); | 2372 CPDF_Stream* pStream = ReadStream(pDict, pContext, objnum, gennum); |
2373 if (pStream) { | 2373 if (pStream) { |
2374 return pStream; | 2374 return pStream; |
2375 } | 2375 } |
2376 if (pDict) { | 2376 if (pDict) { |
2377 pDict->Release(); | 2377 pDict->Release(); |
2378 } | 2378 } |
2379 return NULL; | 2379 return NULL; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2488 } | 2488 } |
2489 int32_t CPDF_SyntaxParser::GetDirectNum() | 2489 int32_t CPDF_SyntaxParser::GetDirectNum() |
2490 { | 2490 { |
2491 GetNextWord(); | 2491 GetNextWord(); |
2492 if (!m_bIsNumber) { | 2492 if (!m_bIsNumber) { |
2493 return 0; | 2493 return 0; |
2494 } | 2494 } |
2495 m_WordBuffer[m_WordSize] = 0; | 2495 m_WordBuffer[m_WordSize] = 0; |
2496 return FXSYS_atoi((const FX_CHAR*)m_WordBuffer); | 2496 return FXSYS_atoi((const FX_CHAR*)m_WordBuffer); |
2497 } | 2497 } |
2498 FX_BOOL CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, FX_FILESIZE limit,
const uint8_t* tag, FX_DWORD taglen) | 2498 bool CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, FX_FILESIZE limit, con
st uint8_t* tag, FX_DWORD taglen) |
2499 { | 2499 { |
2500 uint8_t type = PDF_CharType[tag[0]]; | 2500 uint8_t type = PDF_CharType[tag[0]]; |
2501 FX_BOOL bCheckLeft = type != 'D' && type != 'W'; | 2501 bool bCheckLeft = type != 'D' && type != 'W'; |
2502 type = PDF_CharType[tag[taglen - 1]]; | 2502 type = PDF_CharType[tag[taglen - 1]]; |
2503 FX_BOOL bCheckRight = type != 'D' && type != 'W'; | 2503 bool bCheckRight = type != 'D' && type != 'W'; |
2504 uint8_t ch; | 2504 uint8_t ch; |
2505 if (bCheckRight && startpos + (int32_t)taglen <= limit && GetCharAt(startpos
+ (int32_t)taglen, ch)) { | 2505 if (bCheckRight && startpos + (int32_t)taglen <= limit && GetCharAt(startpos
+ (int32_t)taglen, ch)) { |
2506 uint8_t type = PDF_CharType[ch]; | 2506 uint8_t type = PDF_CharType[ch]; |
2507 if (type == 'N' || type == 'R') { | 2507 if (type == 'N' || type == 'R') { |
2508 return FALSE; | 2508 return false; |
2509 } | 2509 } |
2510 } | 2510 } |
2511 if (bCheckLeft && startpos > 0 && GetCharAt(startpos - 1, ch)) { | 2511 if (bCheckLeft && startpos > 0 && GetCharAt(startpos - 1, ch)) { |
2512 uint8_t type = PDF_CharType[ch]; | 2512 uint8_t type = PDF_CharType[ch]; |
2513 if (type == 'N' || type == 'R') { | 2513 if (type == 'N' || type == 'R') { |
2514 return FALSE; | 2514 return false; |
2515 } | 2515 } |
2516 } | 2516 } |
2517 return TRUE; | 2517 return true; |
2518 } | 2518 } |
2519 FX_BOOL CPDF_SyntaxParser::SearchWord(const CFX_ByteStringC& tag, FX_BOOL bWhole
Word, FX_BOOL bForward, FX_FILESIZE limit) | 2519 bool CPDF_SyntaxParser::SearchWord(const CFX_ByteStringC& tag, bool bWholeWord,
bool bForward, FX_FILESIZE limit) |
2520 { | 2520 { |
2521 int32_t taglen = tag.GetLength(); | 2521 int32_t taglen = tag.GetLength(); |
2522 if (taglen == 0) { | 2522 if (taglen == 0) { |
2523 return FALSE; | 2523 return false; |
2524 } | 2524 } |
2525 FX_FILESIZE pos = m_Pos; | 2525 FX_FILESIZE pos = m_Pos; |
2526 int32_t offset = 0; | 2526 int32_t offset = 0; |
2527 if (!bForward) { | 2527 if (!bForward) { |
2528 offset = taglen - 1; | 2528 offset = taglen - 1; |
2529 } | 2529 } |
2530 const uint8_t* tag_data = tag.GetPtr(); | 2530 const uint8_t* tag_data = tag.GetPtr(); |
2531 uint8_t byte; | 2531 uint8_t byte; |
2532 while (1) { | 2532 while (1) { |
2533 if (bForward) { | 2533 if (bForward) { |
2534 if (limit) { | 2534 if (limit) { |
2535 if (pos >= m_Pos + limit) { | 2535 if (pos >= m_Pos + limit) { |
2536 return FALSE; | 2536 return false; |
2537 } | 2537 } |
2538 } | 2538 } |
2539 if (!GetCharAt(pos, byte)) { | 2539 if (!GetCharAt(pos, byte)) { |
2540 return FALSE; | 2540 return false; |
2541 } | 2541 } |
2542 } else { | 2542 } else { |
2543 if (limit) { | 2543 if (limit) { |
2544 if (pos <= m_Pos - limit) { | 2544 if (pos <= m_Pos - limit) { |
2545 return FALSE; | 2545 return false; |
2546 } | 2546 } |
2547 } | 2547 } |
2548 if (!GetCharAtBackward(pos, byte)) { | 2548 if (!GetCharAtBackward(pos, byte)) { |
2549 return FALSE; | 2549 return false; |
2550 } | 2550 } |
2551 } | 2551 } |
2552 if (byte == tag_data[offset]) { | 2552 if (byte == tag_data[offset]) { |
2553 if (bForward) { | 2553 if (bForward) { |
2554 offset ++; | 2554 offset ++; |
2555 if (offset < taglen) { | 2555 if (offset < taglen) { |
2556 pos ++; | 2556 pos ++; |
2557 continue; | 2557 continue; |
2558 } | 2558 } |
2559 } else { | 2559 } else { |
2560 offset --; | 2560 offset --; |
2561 if (offset >= 0) { | 2561 if (offset >= 0) { |
2562 pos --; | 2562 pos --; |
2563 continue; | 2563 continue; |
2564 } | 2564 } |
2565 } | 2565 } |
2566 FX_FILESIZE startpos = bForward ? pos - taglen + 1 : pos; | 2566 FX_FILESIZE startpos = bForward ? pos - taglen + 1 : pos; |
2567 if (!bWholeWord || IsWholeWord(startpos, limit, tag.GetPtr(), taglen
)) { | 2567 if (!bWholeWord || IsWholeWord(startpos, limit, tag.GetPtr(), taglen
)) { |
2568 m_Pos = startpos; | 2568 m_Pos = startpos; |
2569 return TRUE; | 2569 return true; |
2570 } | 2570 } |
2571 } | 2571 } |
2572 if (bForward) { | 2572 if (bForward) { |
2573 offset = byte == tag_data[0] ? 1 : 0; | 2573 offset = byte == tag_data[0] ? 1 : 0; |
2574 pos ++; | 2574 pos ++; |
2575 } else { | 2575 } else { |
2576 offset = byte == tag_data[taglen - 1] ? taglen - 2 : taglen - 1; | 2576 offset = byte == tag_data[taglen - 1] ? taglen - 2 : taglen - 1; |
2577 pos --; | 2577 pos --; |
2578 } | 2578 } |
2579 if (pos < 0) { | 2579 if (pos < 0) { |
2580 return FALSE; | 2580 return false; |
2581 } | 2581 } |
2582 } | 2582 } |
2583 return FALSE; | 2583 return false; |
2584 } | 2584 } |
2585 struct _SearchTagRecord { | 2585 struct _SearchTagRecord { |
2586 const uint8_t* m_pTag; | 2586 const uint8_t* m_pTag; |
2587 FX_DWORD m_Len; | 2587 FX_DWORD m_Len; |
2588 FX_DWORD m_Offset; | 2588 FX_DWORD m_Offset; |
2589 }; | 2589 }; |
2590 int32_t CPDF_SyntaxParser::SearchMultiWord(const CFX_ByteStringC& tags, FX_BOOL
bWholeWord, FX_FILESIZE limit) | 2590 int32_t CPDF_SyntaxParser::SearchMultiWord(const CFX_ByteStringC& tags, bool bWh
oleWord, FX_FILESIZE limit) |
2591 { | 2591 { |
2592 int32_t ntags = 1, i; | 2592 int32_t ntags = 1, i; |
2593 for (i = 0; i < tags.GetLength(); i ++) | 2593 for (i = 0; i < tags.GetLength(); i ++) |
2594 if (tags[i] == 0) { | 2594 if (tags[i] == 0) { |
2595 ntags ++; | 2595 ntags ++; |
2596 } | 2596 } |
2597 _SearchTagRecord* pPatterns = FX_Alloc(_SearchTagRecord, ntags); | 2597 _SearchTagRecord* pPatterns = FX_Alloc(_SearchTagRecord, ntags); |
2598 FX_DWORD start = 0, itag = 0, max_len = 0; | 2598 FX_DWORD start = 0, itag = 0, max_len = 0; |
2599 for (i = 0; i <= tags.GetLength(); i ++) { | 2599 for (i = 0; i <= tags.GetLength(); i ++) { |
2600 if (tags[i] == 0) { | 2600 if (tags[i] == 0) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2688 } | 2688 } |
2689 } | 2689 } |
2690 } | 2690 } |
2691 | 2691 |
2692 class CPDF_DataAvail final : public IPDF_DataAvail | 2692 class CPDF_DataAvail final : public IPDF_DataAvail |
2693 { | 2693 { |
2694 public: | 2694 public: |
2695 CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); | 2695 CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); |
2696 ~CPDF_DataAvail(); | 2696 ~CPDF_DataAvail(); |
2697 | 2697 |
2698 virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) o
verride; | 2698 virtual bool IsDocAvail(IFX_DownloadHints* pHints) over
ride; |
2699 | 2699 |
2700 virtual void SetDocument(CPDF_Document* pDoc) overri
de; | 2700 virtual void SetDocument(CPDF_Document* pDoc) overri
de; |
2701 | 2701 |
2702 virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints
* pHints) override; | 2702 virtual bool IsPageAvail(int iPage, IFX_DownloadHints* p
Hints) override; |
2703 | 2703 |
2704 virtual int32_t IsFormAvail(IFX_DownloadHints *pHints)
override; | 2704 virtual int32_t IsFormAvail(IFX_DownloadHints *pHints)
override; |
2705 | 2705 |
2706 virtual int32_t IsLinearizedPDF() override; | 2706 virtual int32_t IsLinearizedPDF() override; |
2707 | 2707 |
2708 virtual FX_BOOL IsLinearized() override | 2708 virtual bool IsLinearized() override |
2709 { | 2709 { |
2710 return m_bLinearized; | 2710 return m_bLinearized; |
2711 } | 2711 } |
2712 | 2712 |
2713 virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *p
Pos, FX_DWORD *pSize) override; | 2713 virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *p
Pos, FX_DWORD *pSize) override; |
2714 | 2714 |
2715 protected: | 2715 protected: |
2716 static const int kMaxDataAvailRecursionDepth = 64; | 2716 static const int kMaxDataAvailRecursionDepth = 64; |
2717 static int s_CurrentDataAvailRecursionDepth; | 2717 static int s_CurrentDataAvailRecursionDepth; |
2718 | 2718 |
2719 FX_DWORD GetObjectSize(FX_DWORD objnum, FX_FILESI
ZE& offset); | 2719 FX_DWORD GetObjectSize(FX_DWORD objnum, FX_FILESI
ZE& offset); |
2720 FX_BOOL IsObjectsAvail(CFX_PtrArray& obj_array,
FX_BOOL bParsePage, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array); | 2720 bool IsObjectsAvail(CFX_PtrArray& obj_array, boo
l bParsePage, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array); |
2721 FX_BOOL CheckDocStatus(IFX_DownloadHints *pHints
); | 2721 bool CheckDocStatus(IFX_DownloadHints *pHints); |
2722 FX_BOOL CheckHeader(IFX_DownloadHints* pHints); | 2722 bool CheckHeader(IFX_DownloadHints* pHints); |
2723 FX_BOOL CheckFirstPage(IFX_DownloadHints *pHints
); | 2723 bool CheckFirstPage(IFX_DownloadHints *pHints); |
2724 FX_BOOL CheckEnd(IFX_DownloadHints *pHints); | 2724 bool CheckEnd(IFX_DownloadHints *pHints); |
2725 FX_BOOL CheckCrossRef(IFX_DownloadHints* pHints)
; | 2725 bool CheckCrossRef(IFX_DownloadHints* pHints); |
2726 FX_BOOL CheckCrossRefItem(IFX_DownloadHints *pHi
nts); | 2726 bool CheckCrossRefItem(IFX_DownloadHints *pHints
); |
2727 FX_BOOL CheckTrailer(IFX_DownloadHints* pHints); | 2727 bool CheckTrailer(IFX_DownloadHints* pHints); |
2728 FX_BOOL CheckRoot(IFX_DownloadHints* pHints); | 2728 bool CheckRoot(IFX_DownloadHints* pHints); |
2729 FX_BOOL CheckInfo(IFX_DownloadHints* pHints); | 2729 bool CheckInfo(IFX_DownloadHints* pHints); |
2730 FX_BOOL CheckPages(IFX_DownloadHints* pHints); | 2730 bool CheckPages(IFX_DownloadHints* pHints); |
2731 FX_BOOL CheckPage(IFX_DownloadHints* pHints); | 2731 bool CheckPage(IFX_DownloadHints* pHints); |
2732 FX_BOOL CheckResources(IFX_DownloadHints* pHints
); | 2732 bool CheckResources(IFX_DownloadHints* pHints); |
2733 FX_BOOL CheckAnnots(IFX_DownloadHints* pHints); | 2733 bool CheckAnnots(IFX_DownloadHints* pHints); |
2734 FX_BOOL CheckAcroForm(IFX_DownloadHints* pHints)
; | 2734 bool CheckAcroForm(IFX_DownloadHints* pHints); |
2735 FX_BOOL CheckAcroFormSubObject(IFX_DownloadHints
* pHints); | 2735 bool CheckAcroFormSubObject(IFX_DownloadHints* p
Hints); |
2736 FX_BOOL CheckTrailerAppend(IFX_DownloadHints* pH
ints); | 2736 bool CheckTrailerAppend(IFX_DownloadHints* pHint
s); |
2737 FX_BOOL CheckPageStatus(IFX_DownloadHints* pHint
s); | 2737 bool CheckPageStatus(IFX_DownloadHints* pHints); |
2738 FX_BOOL CheckAllCrossRefStream(IFX_DownloadHints
*pHints); | 2738 bool CheckAllCrossRefStream(IFX_DownloadHints *p
Hints); |
2739 | 2739 |
2740 int32_t CheckCrossRefStream(IFX_DownloadHints *pH
ints, FX_FILESIZE &xref_offset); | 2740 int32_t CheckCrossRefStream(IFX_DownloadHints *pH
ints, FX_FILESIZE &xref_offset); |
2741 FX_BOOL IsLinearizedFile(uint8_t* pData, FX_DWOR
D dwLen); | 2741 bool IsLinearizedFile(uint8_t* pData, FX_DWORD d
wLen); |
2742 void SetStartOffset(FX_FILESIZE dwOffset); | 2742 void SetStartOffset(FX_FILESIZE dwOffset); |
2743 FX_BOOL GetNextToken(CFX_ByteString &token); | 2743 bool GetNextToken(CFX_ByteString &token); |
2744 FX_BOOL GetNextChar(uint8_t &ch); | 2744 bool GetNextChar(uint8_t &ch); |
2745 CPDF_Object * ParseIndirectObjectAt(FX_FILESIZE pos, F
X_DWORD objnum); | 2745 CPDF_Object * ParseIndirectObjectAt(FX_FILESIZE pos, F
X_DWORD objnum); |
2746 CPDF_Object»* GetObject(FX_DWORD objnum, IFX_DownloadH
ints* pHints, FX_BOOL *pExistInFile); | 2746 CPDF_Object»* GetObject(FX_DWORD objnum, IFX_DownloadH
ints* pHints, bool *pExistInFile); |
2747 FX_BOOL GetPageKids(CPDF_Parser *pParser, CPDF_O
bject *pPages); | 2747 bool GetPageKids(CPDF_Parser *pParser, CPDF_Obje
ct *pPages); |
2748 FX_BOOL PreparePageItem(); | 2748 bool PreparePageItem(); |
2749 FX_BOOL LoadPages(IFX_DownloadHints* pHints); | 2749 bool LoadPages(IFX_DownloadHints* pHints); |
2750 FX_BOOL LoadAllXref(IFX_DownloadHints* pHints); | 2750 bool LoadAllXref(IFX_DownloadHints* pHints); |
2751 FX_BOOL LoadAllFile(IFX_DownloadHints* pHints); | 2751 bool LoadAllFile(IFX_DownloadHints* pHints); |
2752 FX_BOOL CheckLinearizedData(IFX_DownloadHints* p
Hints); | 2752 bool CheckLinearizedData(IFX_DownloadHints* pHin
ts); |
2753 FX_BOOL CheckFileResources(IFX_DownloadHints* pH
ints); | 2753 bool CheckFileResources(IFX_DownloadHints* pHint
s); |
2754 FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadH
ints* pHints); | 2754 bool CheckPageAnnots(int iPage, IFX_DownloadHint
s* pHints); |
2755 | 2755 |
2756 FX_BOOL CheckLinearizedFirstPage(int iPage, IFX_
DownloadHints* pHints); | 2756 bool CheckLinearizedFirstPage(int iPage, IFX_Dow
nloadHints* pHints); |
2757 FX_BOOL HaveResourceAncestor(CPDF_Dictionary *pD
ict); | 2757 bool HaveResourceAncestor(CPDF_Dictionary *pDict
); |
2758 FX_BOOL CheckPage(int32_t iPage, IFX_DownloadHin
ts* pHints); | 2758 bool CheckPage(int32_t iPage, IFX_DownloadHints*
pHints); |
2759 FX_BOOL LoadDocPages(IFX_DownloadHints* pHints); | 2759 bool LoadDocPages(IFX_DownloadHints* pHints); |
2760 FX_BOOL LoadDocPage(int32_t iPage, IFX_DownloadH
ints* pHints); | 2760 bool LoadDocPage(int32_t iPage, IFX_DownloadHint
s* pHints); |
2761 FX_BOOL CheckPageNode(CPDF_PageNode &pageNodes,
int32_t iPage, int32_t &iCount, IFX_DownloadHints* pHints); | 2761 bool CheckPageNode(CPDF_PageNode &pageNodes, int
32_t iPage, int32_t &iCount, IFX_DownloadHints* pHints); |
2762 FX_BOOL CheckUnkownPageNode(FX_DWORD dwPageNo, C
PDF_PageNode *pPageNode, IFX_DownloadHints* pHints); | 2762 bool CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF
_PageNode *pPageNode, IFX_DownloadHints* pHints); |
2763 FX_BOOL CheckArrayPageNode(FX_DWORD dwPageNo, CP
DF_PageNode *pPageNode, IFX_DownloadHints* pHints); | 2763 bool CheckArrayPageNode(FX_DWORD dwPageNo, CPDF_
PageNode *pPageNode, IFX_DownloadHints* pHints); |
2764 FX_BOOL CheckPageCount(IFX_DownloadHints* pHints
); | 2764 bool CheckPageCount(IFX_DownloadHints* pHints); |
2765 FX_BOOL IsFirstCheck(int iPage); | 2765 bool IsFirstCheck(int iPage); |
2766 void ResetFirstCheck(int iPage); | 2766 void ResetFirstCheck(int iPage); |
2767 | 2767 |
2768 CPDF_Parser m_parser; | 2768 CPDF_Parser m_parser; |
2769 | 2769 |
2770 CPDF_SyntaxParser m_syntaxParser; | 2770 CPDF_SyntaxParser m_syntaxParser; |
2771 | 2771 |
2772 CPDF_Object *m_pRoot; | 2772 CPDF_Object *m_pRoot; |
2773 | 2773 |
2774 FX_DWORD m_dwRootObjNum; | 2774 FX_DWORD m_dwRootObjNum; |
2775 | 2775 |
2776 FX_DWORD m_dwInfoObjNum; | 2776 FX_DWORD m_dwInfoObjNum; |
2777 | 2777 |
2778 CPDF_Object *m_pLinearized; | 2778 CPDF_Object *m_pLinearized; |
2779 | 2779 |
2780 CPDF_Object *m_pTrailer; | 2780 CPDF_Object *m_pTrailer; |
2781 | 2781 |
2782 FX_BOOL m_bDocAvail; | 2782 bool m_bDocAvail; |
2783 | 2783 |
2784 FX_FILESIZE m_dwHeaderOffset; | 2784 FX_FILESIZE m_dwHeaderOffset; |
2785 | 2785 |
2786 FX_FILESIZE m_dwLastXRefOffset; | 2786 FX_FILESIZE m_dwLastXRefOffset; |
2787 | 2787 |
2788 FX_FILESIZE m_dwXRefOffset; | 2788 FX_FILESIZE m_dwXRefOffset; |
2789 | 2789 |
2790 FX_FILESIZE m_dwTrailerOffset; | 2790 FX_FILESIZE m_dwTrailerOffset; |
2791 | 2791 |
2792 FX_FILESIZE m_dwCurrentOffset; | 2792 FX_FILESIZE m_dwCurrentOffset; |
(...skipping 23 matching lines...) Expand all Loading... |
2816 uint8_t m_bufferData[512]; | 2816 uint8_t m_bufferData[512]; |
2817 | 2817 |
2818 CFX_FileSizeArray m_CrossOffset; | 2818 CFX_FileSizeArray m_CrossOffset; |
2819 | 2819 |
2820 CFX_DWordArray m_XRefStreamList; | 2820 CFX_DWordArray m_XRefStreamList; |
2821 | 2821 |
2822 CFX_DWordArray m_PageObjList; | 2822 CFX_DWordArray m_PageObjList; |
2823 | 2823 |
2824 FX_DWORD m_PagesObjNum; | 2824 FX_DWORD m_PagesObjNum; |
2825 | 2825 |
2826 FX_BOOL m_bLinearized; | 2826 bool m_bLinearized; |
2827 | 2827 |
2828 FX_DWORD m_dwFirstPageNo; | 2828 FX_DWORD m_dwFirstPageNo; |
2829 | 2829 |
2830 FX_BOOL m_bLinearedDataOK; | 2830 bool m_bLinearedDataOK; |
2831 | 2831 |
2832 FX_BOOL m_bMainXRefLoadTried; | 2832 bool m_bMainXRefLoadTried; |
2833 | 2833 |
2834 FX_BOOL m_bMainXRefLoadedOK; | 2834 bool m_bMainXRefLoadedOK; |
2835 | 2835 |
2836 FX_BOOL m_bPagesTreeLoad; | 2836 bool m_bPagesTreeLoad; |
2837 | 2837 |
2838 FX_BOOL m_bPagesLoad; | 2838 bool m_bPagesLoad; |
2839 | 2839 |
2840 CPDF_Parser * m_pCurrentParser; | 2840 CPDF_Parser * m_pCurrentParser; |
2841 | 2841 |
2842 FX_FILESIZE m_dwCurrentXRefSteam; | 2842 FX_FILESIZE m_dwCurrentXRefSteam; |
2843 | 2843 |
2844 FX_BOOL m_bAnnotsLoad; | 2844 bool m_bAnnotsLoad; |
2845 | 2845 |
2846 FX_BOOL m_bHaveAcroForm; | 2846 bool m_bHaveAcroForm; |
2847 | 2847 |
2848 FX_DWORD m_dwAcroFormObjNum; | 2848 FX_DWORD m_dwAcroFormObjNum; |
2849 | 2849 |
2850 FX_BOOL m_bAcroFormLoad; | 2850 bool m_bAcroFormLoad; |
2851 | 2851 |
2852 CPDF_Object * m_pAcroForm; | 2852 CPDF_Object * m_pAcroForm; |
2853 | 2853 |
2854 CFX_PtrArray m_arrayAcroforms; | 2854 CFX_PtrArray m_arrayAcroforms; |
2855 | 2855 |
2856 CPDF_Dictionary * m_pPageDict; | 2856 CPDF_Dictionary * m_pPageDict; |
2857 | 2857 |
2858 CPDF_Object * m_pPageResource; | 2858 CPDF_Object * m_pPageResource; |
2859 | 2859 |
2860 FX_BOOL m_bNeedDownLoadResource; | 2860 bool m_bNeedDownLoadResource; |
2861 | 2861 |
2862 FX_BOOL m_bPageLoadedOK; | 2862 bool m_bPageLoadedOK; |
2863 | 2863 |
2864 FX_BOOL m_bLinearizedFormParamLoad; | 2864 bool m_bLinearizedFormParamLoad; |
2865 | 2865 |
2866 CFX_PtrArray m_PagesArray; | 2866 CFX_PtrArray m_PagesArray; |
2867 | 2867 |
2868 FX_DWORD m_dwEncryptObjNum; | 2868 FX_DWORD m_dwEncryptObjNum; |
2869 | 2869 |
2870 FX_FILESIZE m_dwPrevXRefOffset; | 2870 FX_FILESIZE m_dwPrevXRefOffset; |
2871 | 2871 |
2872 FX_BOOL m_bTotalLoadPageTree; | 2872 bool m_bTotalLoadPageTree; |
2873 | 2873 |
2874 FX_BOOL m_bCurPageDictLoadOK; | 2874 bool m_bCurPageDictLoadOK; |
2875 | 2875 |
2876 CPDF_PageNode m_pageNodes; | 2876 CPDF_PageNode m_pageNodes; |
2877 | 2877 |
2878 CFX_CMapDWordToDWord * m_pageMapCheckState; | 2878 CFX_CMapDWordToDWord * m_pageMapCheckState; |
2879 | 2879 |
2880 CFX_CMapDWordToDWord * m_pagesLoadState; | 2880 CFX_CMapDWordToDWord * m_pagesLoadState; |
2881 }; | 2881 }; |
2882 | 2882 |
2883 IPDF_DataAvail::IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRea
d) : | 2883 IPDF_DataAvail::IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRea
d) : |
2884 m_pFileAvail(pFileAvail), | 2884 m_pFileAvail(pFileAvail), |
(...skipping 24 matching lines...) Expand all Loading... |
2909 m_dwFirstPageNo = 0; | 2909 m_dwFirstPageNo = 0; |
2910 m_bufferSize = 0; | 2910 m_bufferSize = 0; |
2911 m_PagesObjNum = 0; | 2911 m_PagesObjNum = 0; |
2912 m_dwCurrentXRefSteam = 0; | 2912 m_dwCurrentXRefSteam = 0; |
2913 m_dwAcroFormObjNum = 0; | 2913 m_dwAcroFormObjNum = 0; |
2914 m_dwInfoObjNum = 0; | 2914 m_dwInfoObjNum = 0; |
2915 m_pDocument = 0; | 2915 m_pDocument = 0; |
2916 m_dwEncryptObjNum = 0; | 2916 m_dwEncryptObjNum = 0; |
2917 m_dwPrevXRefOffset = 0; | 2917 m_dwPrevXRefOffset = 0; |
2918 m_dwLastXRefOffset = 0; | 2918 m_dwLastXRefOffset = 0; |
2919 m_bDocAvail = FALSE; | 2919 m_bDocAvail = false; |
2920 m_bMainXRefLoadTried = FALSE; | 2920 m_bMainXRefLoadTried = false; |
2921 m_bDocAvail = FALSE; | 2921 m_bDocAvail = false; |
2922 m_bLinearized = FALSE; | 2922 m_bLinearized = false; |
2923 m_bPagesLoad = FALSE; | 2923 m_bPagesLoad = false; |
2924 m_bPagesTreeLoad = FALSE; | 2924 m_bPagesTreeLoad = false; |
2925 m_bMainXRefLoadedOK = FALSE; | 2925 m_bMainXRefLoadedOK = false; |
2926 m_bAnnotsLoad = FALSE; | 2926 m_bAnnotsLoad = false; |
2927 m_bHaveAcroForm = FALSE; | 2927 m_bHaveAcroForm = false; |
2928 m_bAcroFormLoad = FALSE; | 2928 m_bAcroFormLoad = false; |
2929 m_bPageLoadedOK = FALSE; | 2929 m_bPageLoadedOK = false; |
2930 m_bNeedDownLoadResource = FALSE; | 2930 m_bNeedDownLoadResource = false; |
2931 m_bLinearizedFormParamLoad = FALSE; | 2931 m_bLinearizedFormParamLoad = false; |
2932 m_pLinearized = NULL; | 2932 m_pLinearized = NULL; |
2933 m_pRoot = NULL; | 2933 m_pRoot = NULL; |
2934 m_pTrailer = NULL; | 2934 m_pTrailer = NULL; |
2935 m_pCurrentParser = NULL; | 2935 m_pCurrentParser = NULL; |
2936 m_pAcroForm = NULL; | 2936 m_pAcroForm = NULL; |
2937 m_pPageDict = NULL; | 2937 m_pPageDict = NULL; |
2938 m_pPageResource = NULL; | 2938 m_pPageResource = NULL; |
2939 m_pageMapCheckState = NULL; | 2939 m_pageMapCheckState = NULL; |
2940 m_docStatus = PDF_DATAAVAIL_HEADER; | 2940 m_docStatus = PDF_DATAAVAIL_HEADER; |
2941 m_parser.m_bOwnFileRead = FALSE; | 2941 m_parser.m_bOwnFileRead = false; |
2942 m_bTotalLoadPageTree = FALSE; | 2942 m_bTotalLoadPageTree = false; |
2943 m_bCurPageDictLoadOK = FALSE; | 2943 m_bCurPageDictLoadOK = false; |
2944 m_bLinearedDataOK = FALSE; | 2944 m_bLinearedDataOK = false; |
2945 m_pagesLoadState = NULL; | 2945 m_pagesLoadState = NULL; |
2946 } | 2946 } |
2947 CPDF_DataAvail::~CPDF_DataAvail() | 2947 CPDF_DataAvail::~CPDF_DataAvail() |
2948 { | 2948 { |
2949 if (m_pLinearized) { | 2949 if (m_pLinearized) { |
2950 m_pLinearized->Release(); | 2950 m_pLinearized->Release(); |
2951 } | 2951 } |
2952 if (m_pRoot) { | 2952 if (m_pRoot) { |
2953 m_pRoot->Release(); | 2953 m_pRoot->Release(); |
2954 } | 2954 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2988 if (pResult == NULL) { | 2988 if (pResult == NULL) { |
2989 return 0; | 2989 return 0; |
2990 } | 2990 } |
2991 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)pParser->m_SortedOffset.GetDat
a() == pParser->m_SortedOffset.GetSize() - 1) { | 2991 if ((FX_FILESIZE*)pResult - (FX_FILESIZE*)pParser->m_SortedOffset.GetDat
a() == pParser->m_SortedOffset.GetSize() - 1) { |
2992 return 0; | 2992 return 0; |
2993 } | 2993 } |
2994 return (FX_DWORD)(((FX_FILESIZE*)pResult)[1] - offset); | 2994 return (FX_DWORD)(((FX_FILESIZE*)pResult)[1] - offset); |
2995 } | 2995 } |
2996 return 0; | 2996 return 0; |
2997 } | 2997 } |
2998 FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePa
ge, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array) | 2998 bool CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, bool bParsePage, IF
X_DownloadHints* pHints, CFX_PtrArray &ret_array) |
2999 { | 2999 { |
3000 if (!obj_array.GetSize()) { | 3000 if (!obj_array.GetSize()) { |
3001 return TRUE; | 3001 return true; |
3002 } | 3002 } |
3003 FX_DWORD count = 0; | 3003 FX_DWORD count = 0; |
3004 CFX_PtrArray new_obj_array; | 3004 CFX_PtrArray new_obj_array; |
3005 int32_t i = 0; | 3005 int32_t i = 0; |
3006 for (i = 0; i < obj_array.GetSize(); i++) { | 3006 for (i = 0; i < obj_array.GetSize(); i++) { |
3007 CPDF_Object *pObj = (CPDF_Object *)obj_array[i]; | 3007 CPDF_Object *pObj = (CPDF_Object *)obj_array[i]; |
3008 if (!pObj) { | 3008 if (!pObj) { |
3009 continue; | 3009 continue; |
3010 } | 3010 } |
3011 int32_t type = pObj->GetType(); | 3011 int32_t type = pObj->GetType(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3081 if (type == PDFOBJ_REFERENCE) { | 3081 if (type == PDFOBJ_REFERENCE) { |
3082 CPDF_Reference *pRef = (CPDF_Reference *)pObj; | 3082 CPDF_Reference *pRef = (CPDF_Reference *)pObj; |
3083 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3083 FX_DWORD dwNum = pRef->GetRefObjNum(); |
3084 if (!m_objnum_array.Find(dwNum)) { | 3084 if (!m_objnum_array.Find(dwNum)) { |
3085 ret_array.Add(pObj); | 3085 ret_array.Add(pObj); |
3086 } | 3086 } |
3087 } else { | 3087 } else { |
3088 ret_array.Add(pObj); | 3088 ret_array.Add(pObj); |
3089 } | 3089 } |
3090 } | 3090 } |
3091 return FALSE; | 3091 return false; |
3092 } | 3092 } |
3093 obj_array.RemoveAll(); | 3093 obj_array.RemoveAll(); |
3094 obj_array.Append(new_obj_array); | 3094 obj_array.Append(new_obj_array); |
3095 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); | 3095 return IsObjectsAvail(obj_array, false, pHints, ret_array); |
3096 } | 3096 } |
3097 FX_BOOL CPDF_DataAvail::IsDocAvail(IFX_DownloadHints* pHints) | 3097 bool CPDF_DataAvail::IsDocAvail(IFX_DownloadHints* pHints) |
3098 { | 3098 { |
3099 if (!m_dwFileLen && m_pFileRead) { | 3099 if (!m_dwFileLen && m_pFileRead) { |
3100 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); | 3100 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); |
3101 if (!m_dwFileLen) { | 3101 if (!m_dwFileLen) { |
3102 return TRUE; | 3102 return true; |
3103 } | 3103 } |
3104 } | 3104 } |
3105 while (!m_bDocAvail) { | 3105 while (!m_bDocAvail) { |
3106 if (!CheckDocStatus(pHints)) { | 3106 if (!CheckDocStatus(pHints)) { |
3107 return FALSE; | 3107 return false; |
3108 } | 3108 } |
3109 } | 3109 } |
3110 return TRUE; | 3110 return true; |
3111 } | 3111 } |
3112 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) | 3112 bool CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) |
3113 { | 3113 { |
3114 if (!m_objs_array.GetSize()) { | 3114 if (!m_objs_array.GetSize()) { |
3115 m_objs_array.RemoveAll(); | 3115 m_objs_array.RemoveAll(); |
3116 m_objnum_array.RemoveAll(); | 3116 m_objnum_array.RemoveAll(); |
3117 CFX_PtrArray obj_array; | 3117 CFX_PtrArray obj_array; |
3118 obj_array.Append(m_arrayAcroforms); | 3118 obj_array.Append(m_arrayAcroforms); |
3119 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 3119 bool bRet = IsObjectsAvail(obj_array, false, pHints, m_objs_array); |
3120 if (bRet) { | 3120 if (bRet) { |
3121 m_objs_array.RemoveAll(); | 3121 m_objs_array.RemoveAll(); |
3122 } | 3122 } |
3123 return bRet; | 3123 return bRet; |
3124 } | 3124 } |
3125 CFX_PtrArray new_objs_array; | 3125 CFX_PtrArray new_objs_array; |
3126 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 3126 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_array); |
3127 if (bRet) { | 3127 if (bRet) { |
3128 int32_t iSize = m_arrayAcroforms.GetSize(); | 3128 int32_t iSize = m_arrayAcroforms.GetSize(); |
3129 for (int32_t i = 0; i < iSize; ++i) { | 3129 for (int32_t i = 0; i < iSize; ++i) { |
3130 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); | 3130 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); |
3131 } | 3131 } |
3132 m_arrayAcroforms.RemoveAll(); | 3132 m_arrayAcroforms.RemoveAll(); |
3133 } else { | 3133 } else { |
3134 m_objs_array.RemoveAll(); | 3134 m_objs_array.RemoveAll(); |
3135 m_objs_array.Append(new_objs_array); | 3135 m_objs_array.Append(new_objs_array); |
3136 } | 3136 } |
3137 return bRet; | 3137 return bRet; |
3138 } | 3138 } |
3139 FX_BOOL CPDF_DataAvail::CheckAcroForm(IFX_DownloadHints* pHints) | 3139 bool CPDF_DataAvail::CheckAcroForm(IFX_DownloadHints* pHints) |
3140 { | 3140 { |
3141 FX_BOOL bExist = FALSE; | 3141 bool bExist = false; |
3142 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); | 3142 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); |
3143 if (!bExist) { | 3143 if (!bExist) { |
3144 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3144 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3145 return TRUE; | 3145 return true; |
3146 } | 3146 } |
3147 if (!m_pAcroForm) { | 3147 if (!m_pAcroForm) { |
3148 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3148 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3149 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3149 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3150 return TRUE; | 3150 return true; |
3151 } | 3151 } |
3152 return FALSE; | 3152 return false; |
3153 } | 3153 } |
3154 m_arrayAcroforms.Add(m_pAcroForm); | 3154 m_arrayAcroforms.Add(m_pAcroForm); |
3155 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3155 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3156 return TRUE; | 3156 return true; |
3157 } | 3157 } |
3158 FX_BOOL CPDF_DataAvail::CheckDocStatus(IFX_DownloadHints *pHints) | 3158 bool CPDF_DataAvail::CheckDocStatus(IFX_DownloadHints *pHints) |
3159 { | 3159 { |
3160 switch (m_docStatus) { | 3160 switch (m_docStatus) { |
3161 case PDF_DATAAVAIL_HEADER: | 3161 case PDF_DATAAVAIL_HEADER: |
3162 return CheckHeader(pHints); | 3162 return CheckHeader(pHints); |
3163 case PDF_DATAAVAIL_FIRSTPAGE: | 3163 case PDF_DATAAVAIL_FIRSTPAGE: |
3164 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: | 3164 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: |
3165 return CheckFirstPage(pHints); | 3165 return CheckFirstPage(pHints); |
3166 case PDF_DATAAVAIL_END: | 3166 case PDF_DATAAVAIL_END: |
3167 return CheckEnd(pHints); | 3167 return CheckEnd(pHints); |
3168 case PDF_DATAAVAIL_CROSSREF: | 3168 case PDF_DATAAVAIL_CROSSREF: |
(...skipping 19 matching lines...) Expand all Loading... |
3188 case PDF_DATAAVAIL_PAGETREE: | 3188 case PDF_DATAAVAIL_PAGETREE: |
3189 if (m_bTotalLoadPageTree) { | 3189 if (m_bTotalLoadPageTree) { |
3190 return CheckPages(pHints); | 3190 return CheckPages(pHints); |
3191 } | 3191 } |
3192 return LoadDocPages(pHints); | 3192 return LoadDocPages(pHints); |
3193 case PDF_DATAAVAIL_PAGE: | 3193 case PDF_DATAAVAIL_PAGE: |
3194 if (m_bTotalLoadPageTree) { | 3194 if (m_bTotalLoadPageTree) { |
3195 return CheckPage(pHints); | 3195 return CheckPage(pHints); |
3196 } | 3196 } |
3197 m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD; | 3197 m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD; |
3198 return TRUE; | 3198 return true; |
3199 case PDF_DATAAVAIL_ERROR: | 3199 case PDF_DATAAVAIL_ERROR: |
3200 return LoadAllFile(pHints); | 3200 return LoadAllFile(pHints); |
3201 case PDF_DATAAVAIL_PAGE_LATERLOAD: | 3201 case PDF_DATAAVAIL_PAGE_LATERLOAD: |
3202 m_docStatus = PDF_DATAAVAIL_PAGE; | 3202 m_docStatus = PDF_DATAAVAIL_PAGE; |
3203 default: | 3203 default: |
3204 m_bDocAvail = TRUE; | 3204 m_bDocAvail = true; |
3205 return TRUE; | 3205 return true; |
3206 } | 3206 } |
3207 } | 3207 } |
3208 FX_BOOL»CPDF_DataAvail::CheckPageStatus(IFX_DownloadHints* pHints) | 3208 bool» CPDF_DataAvail::CheckPageStatus(IFX_DownloadHints* pHints) |
3209 { | 3209 { |
3210 switch (m_docStatus) { | 3210 switch (m_docStatus) { |
3211 case PDF_DATAAVAIL_PAGETREE: | 3211 case PDF_DATAAVAIL_PAGETREE: |
3212 return CheckPages(pHints); | 3212 return CheckPages(pHints); |
3213 case PDF_DATAAVAIL_PAGE: | 3213 case PDF_DATAAVAIL_PAGE: |
3214 return CheckPage(pHints); | 3214 return CheckPage(pHints); |
3215 case PDF_DATAAVAIL_ERROR: | 3215 case PDF_DATAAVAIL_ERROR: |
3216 return LoadAllFile(pHints); | 3216 return LoadAllFile(pHints); |
3217 default: | 3217 default: |
3218 m_bPagesTreeLoad = TRUE; | 3218 m_bPagesTreeLoad = true; |
3219 m_bPagesLoad = TRUE; | 3219 m_bPagesLoad = true; |
3220 return TRUE; | 3220 return true; |
3221 } | 3221 } |
3222 } | 3222 } |
3223 FX_BOOL CPDF_DataAvail::LoadAllFile(IFX_DownloadHints* pHints) | 3223 bool CPDF_DataAvail::LoadAllFile(IFX_DownloadHints* pHints) |
3224 { | 3224 { |
3225 if (m_pFileAvail->IsDataAvail(0, (FX_DWORD)m_dwFileLen)) { | 3225 if (m_pFileAvail->IsDataAvail(0, (FX_DWORD)m_dwFileLen)) { |
3226 m_docStatus = PDF_DATAAVAIL_DONE; | 3226 m_docStatus = PDF_DATAAVAIL_DONE; |
3227 return TRUE; | 3227 return true; |
3228 } | 3228 } |
3229 pHints->AddSegment(0, (FX_DWORD)m_dwFileLen); | 3229 pHints->AddSegment(0, (FX_DWORD)m_dwFileLen); |
3230 return FALSE; | 3230 return false; |
3231 } | 3231 } |
3232 FX_BOOL CPDF_DataAvail::LoadAllXref(IFX_DownloadHints* pHints) | 3232 bool CPDF_DataAvail::LoadAllXref(IFX_DownloadHints* pHints) |
3233 { | 3233 { |
3234 m_parser.m_Syntax.InitParser(m_pFileRead, (FX_DWORD)m_dwHeaderOffset); | 3234 m_parser.m_Syntax.InitParser(m_pFileRead, (FX_DWORD)m_dwHeaderOffset); |
3235 m_parser.m_bOwnFileRead = FALSE; | 3235 m_parser.m_bOwnFileRead = false; |
3236 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && !m_parser.LoadAllCros
sRefV5(m_dwLastXRefOffset)) { | 3236 if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) && !m_parser.LoadAllCros
sRefV5(m_dwLastXRefOffset)) { |
3237 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3237 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3238 return FALSE; | 3238 return false; |
3239 } | 3239 } |
3240 FXSYS_qsort(m_parser.m_SortedOffset.GetData(), m_parser.m_SortedOffset.GetSi
ze(), sizeof(FX_FILESIZE), _CompareFileSize); | 3240 FXSYS_qsort(m_parser.m_SortedOffset.GetData(), m_parser.m_SortedOffset.GetSi
ze(), sizeof(FX_FILESIZE), _CompareFileSize); |
3241 m_dwRootObjNum = m_parser.GetRootObjNum(); | 3241 m_dwRootObjNum = m_parser.GetRootObjNum(); |
3242 m_dwInfoObjNum = m_parser.GetInfoObjNum(); | 3242 m_dwInfoObjNum = m_parser.GetInfoObjNum(); |
3243 m_pCurrentParser = &m_parser; | 3243 m_pCurrentParser = &m_parser; |
3244 m_docStatus = PDF_DATAAVAIL_ROOT; | 3244 m_docStatus = PDF_DATAAVAIL_ROOT; |
3245 return TRUE; | 3245 return true; |
3246 } | 3246 } |
3247 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, IFX_DownloadHints* pHint
s, FX_BOOL *pExistInFile) | 3247 CPDF_Object* CPDF_DataAvail::GetObject(FX_DWORD objnum, IFX_DownloadHints* pHint
s, bool *pExistInFile) |
3248 { | 3248 { |
3249 CPDF_Object *pRet = NULL; | 3249 CPDF_Object *pRet = NULL; |
3250 FX_DWORD original_size = 0; | 3250 FX_DWORD original_size = 0; |
3251 FX_FILESIZE offset = 0; | 3251 FX_FILESIZE offset = 0; |
3252 CPDF_Parser *pParser = NULL; | 3252 CPDF_Parser *pParser = NULL; |
3253 | 3253 |
3254 if (pExistInFile) { | 3254 if (pExistInFile) { |
3255 *pExistInFile = TRUE; | 3255 *pExistInFile = true; |
3256 } | 3256 } |
3257 | 3257 |
3258 if (m_pDocument == NULL) { | 3258 if (m_pDocument == NULL) { |
3259 original_size = (FX_DWORD)m_parser.GetObjectSize(objnum); | 3259 original_size = (FX_DWORD)m_parser.GetObjectSize(objnum); |
3260 offset = m_parser.GetObjectOffset(objnum); | 3260 offset = m_parser.GetObjectOffset(objnum); |
3261 pParser = &m_parser; | 3261 pParser = &m_parser; |
3262 } else { | 3262 } else { |
3263 original_size = GetObjectSize(objnum, offset); | 3263 original_size = GetObjectSize(objnum, offset); |
3264 pParser = (CPDF_Parser *)(m_pDocument->GetParser()); | 3264 pParser = (CPDF_Parser *)(m_pDocument->GetParser()); |
3265 } | 3265 } |
3266 | 3266 |
3267 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; | 3267 pdfium::base::CheckedNumeric<FX_DWORD> size = original_size; |
3268 if (size.ValueOrDefault(0) == 0 || offset < 0 || offset >= m_dwFileLen) { | 3268 if (size.ValueOrDefault(0) == 0 || offset < 0 || offset >= m_dwFileLen) { |
3269 if (pExistInFile) | 3269 if (pExistInFile) |
3270 *pExistInFile = FALSE; | 3270 *pExistInFile = false; |
3271 | 3271 |
3272 return NULL; | 3272 return NULL; |
3273 } | 3273 } |
3274 | 3274 |
3275 size += offset; | 3275 size += offset; |
3276 size += 512; | 3276 size += 512; |
3277 if (!size.IsValid()) { | 3277 if (!size.IsValid()) { |
3278 return NULL; | 3278 return NULL; |
3279 } | 3279 } |
3280 | 3280 |
(...skipping 10 matching lines...) Expand all Loading... |
3291 if (!m_pFileAvail->IsDataAvail(offset, size.ValueOrDie())) { | 3291 if (!m_pFileAvail->IsDataAvail(offset, size.ValueOrDie())) { |
3292 pHints->AddSegment(offset, size.ValueOrDie()); | 3292 pHints->AddSegment(offset, size.ValueOrDie()); |
3293 return NULL; | 3293 return NULL; |
3294 } | 3294 } |
3295 | 3295 |
3296 if (pParser) { | 3296 if (pParser) { |
3297 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL); | 3297 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL); |
3298 } | 3298 } |
3299 | 3299 |
3300 if (!pRet && pExistInFile) { | 3300 if (!pRet && pExistInFile) { |
3301 *pExistInFile = FALSE; | 3301 *pExistInFile = false; |
3302 } | 3302 } |
3303 | 3303 |
3304 return pRet; | 3304 return pRet; |
3305 } | 3305 } |
3306 | 3306 |
3307 FX_BOOL CPDF_DataAvail::CheckInfo(IFX_DownloadHints* pHints) | 3307 bool CPDF_DataAvail::CheckInfo(IFX_DownloadHints* pHints) |
3308 { | 3308 { |
3309 FX_BOOL bExist = FALSE; | 3309 bool bExist = false; |
3310 CPDF_Object *pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); | 3310 CPDF_Object *pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); |
3311 if (!bExist) { | 3311 if (!bExist) { |
3312 if (m_bHaveAcroForm) { | 3312 if (m_bHaveAcroForm) { |
3313 m_docStatus = PDF_DATAAVAIL_ACROFORM; | 3313 m_docStatus = PDF_DATAAVAIL_ACROFORM; |
3314 } else { | 3314 } else { |
3315 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3315 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3316 } | 3316 } |
3317 return TRUE; | 3317 return true; |
3318 } | 3318 } |
3319 if (!pInfo) { | 3319 if (!pInfo) { |
3320 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3320 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3321 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3321 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3322 return TRUE; | 3322 return true; |
3323 } | 3323 } |
3324 if (m_Pos == m_dwFileLen) { | 3324 if (m_Pos == m_dwFileLen) { |
3325 m_docStatus = PDF_DATAAVAIL_ERROR; | 3325 m_docStatus = PDF_DATAAVAIL_ERROR; |
3326 } | 3326 } |
3327 return FALSE; | 3327 return false; |
3328 } | 3328 } |
3329 if (pInfo) { | 3329 if (pInfo) { |
3330 pInfo->Release(); | 3330 pInfo->Release(); |
3331 } | 3331 } |
3332 if (m_bHaveAcroForm) { | 3332 if (m_bHaveAcroForm) { |
3333 m_docStatus = PDF_DATAAVAIL_ACROFORM; | 3333 m_docStatus = PDF_DATAAVAIL_ACROFORM; |
3334 } else { | 3334 } else { |
3335 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3335 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3336 } | 3336 } |
3337 return TRUE; | 3337 return true; |
3338 } | 3338 } |
3339 FX_BOOL CPDF_DataAvail::CheckRoot(IFX_DownloadHints* pHints) | 3339 bool CPDF_DataAvail::CheckRoot(IFX_DownloadHints* pHints) |
3340 { | 3340 { |
3341 FX_BOOL bExist = FALSE; | 3341 bool bExist = false; |
3342 m_pRoot = GetObject(m_dwRootObjNum, pHints, &bExist); | 3342 m_pRoot = GetObject(m_dwRootObjNum, pHints, &bExist); |
3343 if (!bExist) { | 3343 if (!bExist) { |
3344 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3344 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3345 return TRUE; | 3345 return true; |
3346 } | 3346 } |
3347 if (!m_pRoot) { | 3347 if (!m_pRoot) { |
3348 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3348 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3349 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3349 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3350 return TRUE; | 3350 return true; |
3351 } | 3351 } |
3352 return FALSE; | 3352 return false; |
3353 } | 3353 } |
3354 CPDF_Dictionary* pDict = m_pRoot->GetDict(); | 3354 CPDF_Dictionary* pDict = m_pRoot->GetDict(); |
3355 if (!pDict) { | 3355 if (!pDict) { |
3356 m_docStatus = PDF_DATAAVAIL_ERROR; | 3356 m_docStatus = PDF_DATAAVAIL_ERROR; |
3357 return FALSE; | 3357 return false; |
3358 } | 3358 } |
3359 CPDF_Reference* pRef = (CPDF_Reference*)pDict->GetElement(FX_BSTRC("Pages"))
; | 3359 CPDF_Reference* pRef = (CPDF_Reference*)pDict->GetElement(FX_BSTRC("Pages"))
; |
3360 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 3360 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
3361 m_docStatus = PDF_DATAAVAIL_ERROR; | 3361 m_docStatus = PDF_DATAAVAIL_ERROR; |
3362 return FALSE; | 3362 return false; |
3363 } | 3363 } |
3364 m_PagesObjNum = pRef->GetRefObjNum(); | 3364 m_PagesObjNum = pRef->GetRefObjNum(); |
3365 CPDF_Reference* pAcroFormRef = (CPDF_Reference*)m_pRoot->GetDict()->GetEleme
nt(FX_BSTRC("AcroForm")); | 3365 CPDF_Reference* pAcroFormRef = (CPDF_Reference*)m_pRoot->GetDict()->GetEleme
nt(FX_BSTRC("AcroForm")); |
3366 if (pAcroFormRef && pAcroFormRef->GetType() == PDFOBJ_REFERENCE) { | 3366 if (pAcroFormRef && pAcroFormRef->GetType() == PDFOBJ_REFERENCE) { |
3367 m_bHaveAcroForm = TRUE; | 3367 m_bHaveAcroForm = true; |
3368 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); | 3368 m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); |
3369 } | 3369 } |
3370 if (m_dwInfoObjNum) { | 3370 if (m_dwInfoObjNum) { |
3371 m_docStatus = PDF_DATAAVAIL_INFO; | 3371 m_docStatus = PDF_DATAAVAIL_INFO; |
3372 } else { | 3372 } else { |
3373 if (m_bHaveAcroForm) { | 3373 if (m_bHaveAcroForm) { |
3374 m_docStatus = PDF_DATAAVAIL_ACROFORM; | 3374 m_docStatus = PDF_DATAAVAIL_ACROFORM; |
3375 } else { | 3375 } else { |
3376 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3376 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3377 } | 3377 } |
3378 } | 3378 } |
3379 return TRUE; | 3379 return true; |
3380 } | 3380 } |
3381 FX_BOOL CPDF_DataAvail::PreparePageItem() | 3381 bool CPDF_DataAvail::PreparePageItem() |
3382 { | 3382 { |
3383 CPDF_Dictionary *pRoot = m_pDocument->GetRoot(); | 3383 CPDF_Dictionary *pRoot = m_pDocument->GetRoot(); |
3384 CPDF_Reference* pRef = pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("
Pages")) : NULL; | 3384 CPDF_Reference* pRef = pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("
Pages")) : NULL; |
3385 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { | 3385 if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
3386 m_docStatus = PDF_DATAAVAIL_ERROR; | 3386 m_docStatus = PDF_DATAAVAIL_ERROR; |
3387 return FALSE; | 3387 return false; |
3388 } | 3388 } |
3389 m_PagesObjNum = pRef->GetRefObjNum(); | 3389 m_PagesObjNum = pRef->GetRefObjNum(); |
3390 m_pCurrentParser = (CPDF_Parser *)m_pDocument->GetParser(); | 3390 m_pCurrentParser = (CPDF_Parser *)m_pDocument->GetParser(); |
3391 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3391 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
3392 return TRUE; | 3392 return true; |
3393 } | 3393 } |
3394 FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) | 3394 bool CPDF_DataAvail::IsFirstCheck(int iPage) |
3395 { | 3395 { |
3396 if (NULL == m_pageMapCheckState) { | 3396 if (NULL == m_pageMapCheckState) { |
3397 m_pageMapCheckState = new CFX_CMapDWordToDWord(); | 3397 m_pageMapCheckState = new CFX_CMapDWordToDWord(); |
3398 } | 3398 } |
3399 FX_DWORD dwValue = 0; | 3399 FX_DWORD dwValue = 0; |
3400 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { | 3400 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { |
3401 m_pageMapCheckState->SetAt(iPage, 1); | 3401 m_pageMapCheckState->SetAt(iPage, 1); |
3402 return TRUE; | 3402 return true; |
3403 } | 3403 } |
3404 if (dwValue != 0) { | 3404 if (dwValue != 0) { |
3405 return FALSE; | 3405 return false; |
3406 } | 3406 } |
3407 m_pageMapCheckState->SetAt(iPage, 1); | 3407 m_pageMapCheckState->SetAt(iPage, 1); |
3408 return TRUE; | 3408 return true; |
3409 } | 3409 } |
3410 void CPDF_DataAvail::ResetFirstCheck(int iPage) | 3410 void CPDF_DataAvail::ResetFirstCheck(int iPage) |
3411 { | 3411 { |
3412 if (NULL == m_pageMapCheckState) { | 3412 if (NULL == m_pageMapCheckState) { |
3413 m_pageMapCheckState = new CFX_CMapDWordToDWord(); | 3413 m_pageMapCheckState = new CFX_CMapDWordToDWord(); |
3414 } | 3414 } |
3415 FX_DWORD dwValue = 1; | 3415 FX_DWORD dwValue = 1; |
3416 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { | 3416 if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { |
3417 return; | 3417 return; |
3418 } | 3418 } |
3419 m_pageMapCheckState->SetAt(iPage, 0); | 3419 m_pageMapCheckState->SetAt(iPage, 0); |
3420 } | 3420 } |
3421 FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) | 3421 bool CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) |
3422 { | 3422 { |
3423 FX_DWORD iPageObjs = m_PageObjList.GetSize(); | 3423 FX_DWORD iPageObjs = m_PageObjList.GetSize(); |
3424 CFX_DWordArray UnavailObjList; | 3424 CFX_DWordArray UnavailObjList; |
3425 for (FX_DWORD i = 0; i < iPageObjs; ++i) { | 3425 for (FX_DWORD i = 0; i < iPageObjs; ++i) { |
3426 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); | 3426 FX_DWORD dwPageObjNum = m_PageObjList.GetAt(i); |
3427 FX_BOOL bExist = FALSE; | 3427 bool bExist = false; |
3428 CPDF_Object *pObj = GetObject(dwPageObjNum, pHints, &bExist); | 3428 CPDF_Object *pObj = GetObject(dwPageObjNum, pHints, &bExist); |
3429 if (!pObj) { | 3429 if (!pObj) { |
3430 if (bExist) { | 3430 if (bExist) { |
3431 UnavailObjList.Add(dwPageObjNum); | 3431 UnavailObjList.Add(dwPageObjNum); |
3432 } | 3432 } |
3433 continue; | 3433 continue; |
3434 } | 3434 } |
3435 if (pObj->GetType() == PDFOBJ_ARRAY) { | 3435 if (pObj->GetType() == PDFOBJ_ARRAY) { |
3436 CPDF_Array *pArray = pObj->GetArray(); | 3436 CPDF_Array *pArray = pObj->GetArray(); |
3437 if (pArray) { | 3437 if (pArray) { |
(...skipping 14 matching lines...) Expand all Loading... |
3452 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type")); | 3452 CFX_ByteString type = pObj->GetDict()->GetString(FX_BSTRC("Type")); |
3453 if (type == FX_BSTRC("Pages")) { | 3453 if (type == FX_BSTRC("Pages")) { |
3454 m_PagesArray.Add(pObj); | 3454 m_PagesArray.Add(pObj); |
3455 continue; | 3455 continue; |
3456 } | 3456 } |
3457 pObj->Release(); | 3457 pObj->Release(); |
3458 } | 3458 } |
3459 m_PageObjList.RemoveAll(); | 3459 m_PageObjList.RemoveAll(); |
3460 if (UnavailObjList.GetSize()) { | 3460 if (UnavailObjList.GetSize()) { |
3461 m_PageObjList.Append(UnavailObjList); | 3461 m_PageObjList.Append(UnavailObjList); |
3462 return FALSE; | 3462 return false; |
3463 } | 3463 } |
3464 FX_DWORD iPages = m_PagesArray.GetSize(); | 3464 FX_DWORD iPages = m_PagesArray.GetSize(); |
3465 for (FX_DWORD i = 0; i < iPages; i++) { | 3465 for (FX_DWORD i = 0; i < iPages; i++) { |
3466 CPDF_Object *pPages = (CPDF_Object *)m_PagesArray.GetAt(i); | 3466 CPDF_Object *pPages = (CPDF_Object *)m_PagesArray.GetAt(i); |
3467 if (!pPages) { | 3467 if (!pPages) { |
3468 continue; | 3468 continue; |
3469 } | 3469 } |
3470 if (!GetPageKids(m_pCurrentParser, pPages)) { | 3470 if (!GetPageKids(m_pCurrentParser, pPages)) { |
3471 pPages->Release(); | 3471 pPages->Release(); |
3472 while (++i < iPages) { | 3472 while (++i < iPages) { |
3473 pPages = (CPDF_Object *)m_PagesArray.GetAt(i); | 3473 pPages = (CPDF_Object *)m_PagesArray.GetAt(i); |
3474 pPages->Release(); | 3474 pPages->Release(); |
3475 } | 3475 } |
3476 m_PagesArray.RemoveAll(); | 3476 m_PagesArray.RemoveAll(); |
3477 m_docStatus = PDF_DATAAVAIL_ERROR; | 3477 m_docStatus = PDF_DATAAVAIL_ERROR; |
3478 return FALSE; | 3478 return false; |
3479 } | 3479 } |
3480 pPages->Release(); | 3480 pPages->Release(); |
3481 } | 3481 } |
3482 m_PagesArray.RemoveAll(); | 3482 m_PagesArray.RemoveAll(); |
3483 if (!m_PageObjList.GetSize()) { | 3483 if (!m_PageObjList.GetSize()) { |
3484 m_docStatus = PDF_DATAAVAIL_DONE; | 3484 m_docStatus = PDF_DATAAVAIL_DONE; |
3485 } | 3485 } |
3486 return TRUE; | 3486 return true; |
3487 } | 3487 } |
3488 FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages) | 3488 bool CPDF_DataAvail::GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages) |
3489 { | 3489 { |
3490 if (!pParser) { | 3490 if (!pParser) { |
3491 m_docStatus = PDF_DATAAVAIL_ERROR; | 3491 m_docStatus = PDF_DATAAVAIL_ERROR; |
3492 return FALSE; | 3492 return false; |
3493 } | 3493 } |
3494 CPDF_Dictionary* pDict = pPages->GetDict(); | 3494 CPDF_Dictionary* pDict = pPages->GetDict(); |
3495 CPDF_Object *pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; | 3495 CPDF_Object *pKids = pDict ? pDict->GetElement(FX_BSTRC("Kids")) : NULL; |
3496 if (!pKids) { | 3496 if (!pKids) { |
3497 return TRUE; | 3497 return true; |
3498 } | 3498 } |
3499 switch (pKids->GetType()) { | 3499 switch (pKids->GetType()) { |
3500 case PDFOBJ_REFERENCE: { | 3500 case PDFOBJ_REFERENCE: { |
3501 CPDF_Reference *pKid = (CPDF_Reference *)pKids; | 3501 CPDF_Reference *pKid = (CPDF_Reference *)pKids; |
3502 m_PageObjList.Add(pKid->GetRefObjNum()); | 3502 m_PageObjList.Add(pKid->GetRefObjNum()); |
3503 } | 3503 } |
3504 break; | 3504 break; |
3505 case PDFOBJ_ARRAY: { | 3505 case PDFOBJ_ARRAY: { |
3506 CPDF_Array *pKidsArray = (CPDF_Array *)pKids; | 3506 CPDF_Array *pKidsArray = (CPDF_Array *)pKids; |
3507 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { | 3507 for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { |
3508 CPDF_Object *pKid = (CPDF_Object *)pKidsArray->GetElement(i)
; | 3508 CPDF_Object *pKid = (CPDF_Object *)pKidsArray->GetElement(i)
; |
3509 if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) { | 3509 if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) { |
3510 m_PageObjList.Add(((CPDF_Reference *)pKid)->GetRefObjNum
()); | 3510 m_PageObjList.Add(((CPDF_Reference *)pKid)->GetRefObjNum
()); |
3511 } | 3511 } |
3512 } | 3512 } |
3513 } | 3513 } |
3514 break; | 3514 break; |
3515 default: | 3515 default: |
3516 m_docStatus = PDF_DATAAVAIL_ERROR; | 3516 m_docStatus = PDF_DATAAVAIL_ERROR; |
3517 return FALSE; | 3517 return false; |
3518 } | 3518 } |
3519 return TRUE; | 3519 return true; |
3520 } | 3520 } |
3521 FX_BOOL CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) | 3521 bool CPDF_DataAvail::CheckPages(IFX_DownloadHints* pHints) |
3522 { | 3522 { |
3523 FX_BOOL bExist = FALSE; | 3523 bool bExist = false; |
3524 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist); | 3524 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist); |
3525 if (!bExist) { | 3525 if (!bExist) { |
3526 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3526 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3527 return TRUE; | 3527 return true; |
3528 } | 3528 } |
3529 if (!pPages) { | 3529 if (!pPages) { |
3530 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3530 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3531 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3531 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3532 return TRUE; | 3532 return true; |
3533 } | 3533 } |
3534 return FALSE; | 3534 return false; |
3535 } | 3535 } |
3536 if (!GetPageKids(m_pCurrentParser, pPages)) { | 3536 if (!GetPageKids(m_pCurrentParser, pPages)) { |
3537 pPages->Release(); | 3537 pPages->Release(); |
3538 m_docStatus = PDF_DATAAVAIL_ERROR; | 3538 m_docStatus = PDF_DATAAVAIL_ERROR; |
3539 return FALSE; | 3539 return false; |
3540 } | 3540 } |
3541 pPages->Release(); | 3541 pPages->Release(); |
3542 m_docStatus = PDF_DATAAVAIL_PAGE; | 3542 m_docStatus = PDF_DATAAVAIL_PAGE; |
3543 return TRUE; | 3543 return true; |
3544 } | 3544 } |
3545 FX_BOOL CPDF_DataAvail::CheckHeader(IFX_DownloadHints* pHints) | 3545 bool CPDF_DataAvail::CheckHeader(IFX_DownloadHints* pHints) |
3546 { | 3546 { |
3547 FX_DWORD req_size = 1024; | 3547 FX_DWORD req_size = 1024; |
3548 if ((FX_FILESIZE)req_size > m_dwFileLen) { | 3548 if ((FX_FILESIZE)req_size > m_dwFileLen) { |
3549 req_size = (FX_DWORD)m_dwFileLen; | 3549 req_size = (FX_DWORD)m_dwFileLen; |
3550 } | 3550 } |
3551 if (m_pFileAvail->IsDataAvail(0, req_size)) { | 3551 if (m_pFileAvail->IsDataAvail(0, req_size)) { |
3552 uint8_t buffer[1024]; | 3552 uint8_t buffer[1024]; |
3553 m_pFileRead->ReadBlock(buffer, 0, req_size); | 3553 m_pFileRead->ReadBlock(buffer, 0, req_size); |
3554 if (IsLinearizedFile(buffer, req_size)) { | 3554 if (IsLinearizedFile(buffer, req_size)) { |
3555 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; | 3555 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; |
3556 } else { | 3556 } else { |
3557 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 3557 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
3558 return FALSE; | 3558 return false; |
3559 } | 3559 } |
3560 m_docStatus = PDF_DATAAVAIL_END; | 3560 m_docStatus = PDF_DATAAVAIL_END; |
3561 } | 3561 } |
3562 return TRUE; | 3562 return true; |
3563 } | 3563 } |
3564 pHints->AddSegment(0, req_size); | 3564 pHints->AddSegment(0, req_size); |
3565 return FALSE; | 3565 return false; |
3566 } | 3566 } |
3567 FX_BOOL CPDF_DataAvail::CheckFirstPage(IFX_DownloadHints *pHints) | 3567 bool CPDF_DataAvail::CheckFirstPage(IFX_DownloadHints *pHints) |
3568 { | 3568 { |
3569 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 3569 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
3570 CPDF_Object *pEndOffSet = pDict ? pDict->GetElement(FX_BSTRC("E")) : NULL; | 3570 CPDF_Object *pEndOffSet = pDict ? pDict->GetElement(FX_BSTRC("E")) : NULL; |
3571 if (!pEndOffSet) { | 3571 if (!pEndOffSet) { |
3572 m_docStatus = PDF_DATAAVAIL_ERROR; | 3572 m_docStatus = PDF_DATAAVAIL_ERROR; |
3573 return FALSE; | 3573 return false; |
3574 } | 3574 } |
3575 CPDF_Object *pXRefOffset = pDict ? pDict->GetElement(FX_BSTRC("T")) : NULL; | 3575 CPDF_Object *pXRefOffset = pDict ? pDict->GetElement(FX_BSTRC("T")) : NULL; |
3576 if (!pXRefOffset) { | 3576 if (!pXRefOffset) { |
3577 m_docStatus = PDF_DATAAVAIL_ERROR; | 3577 m_docStatus = PDF_DATAAVAIL_ERROR; |
3578 return FALSE; | 3578 return false; |
3579 } | 3579 } |
3580 CPDF_Object *pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL; | 3580 CPDF_Object *pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL; |
3581 if (!pFileLen) { | 3581 if (!pFileLen) { |
3582 m_docStatus = PDF_DATAAVAIL_ERROR; | 3582 m_docStatus = PDF_DATAAVAIL_ERROR; |
3583 return FALSE; | 3583 return false; |
3584 } | 3584 } |
3585 FX_BOOL bNeedDownLoad = FALSE; | 3585 bool bNeedDownLoad = false; |
3586 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) { | 3586 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) { |
3587 FX_DWORD dwEnd = pEndOffSet->GetInteger(); | 3587 FX_DWORD dwEnd = pEndOffSet->GetInteger(); |
3588 dwEnd += 512; | 3588 dwEnd += 512; |
3589 if ((FX_FILESIZE)dwEnd > m_dwFileLen) { | 3589 if ((FX_FILESIZE)dwEnd > m_dwFileLen) { |
3590 dwEnd = (FX_DWORD)m_dwFileLen; | 3590 dwEnd = (FX_DWORD)m_dwFileLen; |
3591 } | 3591 } |
3592 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); | 3592 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); |
3593 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; | 3593 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; |
3594 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { | 3594 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { |
3595 pHints->AddSegment(iStartPos, iSize); | 3595 pHints->AddSegment(iStartPos, iSize); |
3596 bNeedDownLoad = TRUE; | 3596 bNeedDownLoad = true; |
3597 } | 3597 } |
3598 } | 3598 } |
3599 m_dwLastXRefOffset = 0; | 3599 m_dwLastXRefOffset = 0; |
3600 FX_FILESIZE dwFileLen = 0; | 3600 FX_FILESIZE dwFileLen = 0; |
3601 if (pXRefOffset->GetType() == PDFOBJ_NUMBER) { | 3601 if (pXRefOffset->GetType() == PDFOBJ_NUMBER) { |
3602 m_dwLastXRefOffset = pXRefOffset->GetInteger(); | 3602 m_dwLastXRefOffset = pXRefOffset->GetInteger(); |
3603 } | 3603 } |
3604 if (pFileLen->GetType() == PDFOBJ_NUMBER) { | 3604 if (pFileLen->GetType() == PDFOBJ_NUMBER) { |
3605 dwFileLen = pFileLen->GetInteger(); | 3605 dwFileLen = pFileLen->GetInteger(); |
3606 } | 3606 } |
3607 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, (FX_DWORD)(dwFileLen - m_
dwLastXRefOffset))) { | 3607 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, (FX_DWORD)(dwFileLen - m_
dwLastXRefOffset))) { |
3608 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { | 3608 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { |
3609 FX_DWORD dwSize = (FX_DWORD)(dwFileLen - m_dwLastXRefOffset); | 3609 FX_DWORD dwSize = (FX_DWORD)(dwFileLen - m_dwLastXRefOffset); |
3610 FX_FILESIZE offset = m_dwLastXRefOffset; | 3610 FX_FILESIZE offset = m_dwLastXRefOffset; |
3611 if (dwSize < 512 && dwFileLen > 512) { | 3611 if (dwSize < 512 && dwFileLen > 512) { |
3612 dwSize = 512; | 3612 dwSize = 512; |
3613 offset = dwFileLen - 512; | 3613 offset = dwFileLen - 512; |
3614 } | 3614 } |
3615 pHints->AddSegment(offset, dwSize); | 3615 pHints->AddSegment(offset, dwSize); |
3616 } | 3616 } |
3617 } else { | 3617 } else { |
3618 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; | 3618 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; |
3619 } | 3619 } |
3620 if (!bNeedDownLoad && m_docStatus == PDF_DATAAVAIL_FIRSTPAGE_PREPARE) { | 3620 if (!bNeedDownLoad && m_docStatus == PDF_DATAAVAIL_FIRSTPAGE_PREPARE) { |
3621 m_docStatus = PDF_DATAAVAIL_DONE; | 3621 m_docStatus = PDF_DATAAVAIL_DONE; |
3622 return TRUE; | 3622 return true; |
3623 } | 3623 } |
3624 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; | 3624 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE_PREPARE; |
3625 return FALSE; | 3625 return false; |
3626 } | 3626 } |
3627 CPDF_Object * CPDF_DataAvail::ParseIndirectObjectAt(FX_FILESIZE pos, FX_DWOR
D objnum) | 3627 CPDF_Object * CPDF_DataAvail::ParseIndirectObjectAt(FX_FILESIZE pos, FX_DWOR
D objnum) |
3628 { | 3628 { |
3629 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); | 3629 FX_FILESIZE SavedPos = m_syntaxParser.SavePos(); |
3630 m_syntaxParser.RestorePos(pos); | 3630 m_syntaxParser.RestorePos(pos); |
3631 FX_BOOL bIsNumber; | 3631 bool bIsNumber; |
3632 CFX_ByteString word = m_syntaxParser.GetNextWord(bIsNumber); | 3632 CFX_ByteString word = m_syntaxParser.GetNextWord(bIsNumber); |
3633 if (!bIsNumber) { | 3633 if (!bIsNumber) { |
3634 return NULL; | 3634 return NULL; |
3635 } | 3635 } |
3636 FX_DWORD parser_objnum = FXSYS_atoi(word); | 3636 FX_DWORD parser_objnum = FXSYS_atoi(word); |
3637 if (objnum && parser_objnum != objnum) { | 3637 if (objnum && parser_objnum != objnum) { |
3638 return NULL; | 3638 return NULL; |
3639 } | 3639 } |
3640 word = m_syntaxParser.GetNextWord(bIsNumber); | 3640 word = m_syntaxParser.GetNextWord(bIsNumber); |
3641 if (!bIsNumber) { | 3641 if (!bIsNumber) { |
(...skipping 21 matching lines...) Expand all Loading... |
3663 if (dwSize < (FX_FILESIZE)req_size) { | 3663 if (dwSize < (FX_FILESIZE)req_size) { |
3664 return PDF_UNKNOW_LINEARIZED; | 3664 return PDF_UNKNOW_LINEARIZED; |
3665 } | 3665 } |
3666 uint8_t buffer[1024]; | 3666 uint8_t buffer[1024]; |
3667 m_pFileRead->ReadBlock(buffer, 0, req_size); | 3667 m_pFileRead->ReadBlock(buffer, 0, req_size); |
3668 if (IsLinearizedFile(buffer, req_size)) { | 3668 if (IsLinearizedFile(buffer, req_size)) { |
3669 return PDF_IS_LINEARIZED; | 3669 return PDF_IS_LINEARIZED; |
3670 } | 3670 } |
3671 return PDF_NOT_LINEARIZED; | 3671 return PDF_NOT_LINEARIZED; |
3672 } | 3672 } |
3673 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) | 3673 bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) |
3674 { | 3674 { |
3675 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pData, (size_t)d
wLen, FALSE)); | 3675 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pData, (size_t)d
wLen, false)); |
3676 int32_t offset = GetHeaderOffset(file.Get()); | 3676 int32_t offset = GetHeaderOffset(file.Get()); |
3677 if (offset == -1) { | 3677 if (offset == -1) { |
3678 m_docStatus = PDF_DATAAVAIL_ERROR; | 3678 m_docStatus = PDF_DATAAVAIL_ERROR; |
3679 return FALSE; | 3679 return false; |
3680 } | 3680 } |
3681 m_dwHeaderOffset = offset; | 3681 m_dwHeaderOffset = offset; |
3682 m_syntaxParser.InitParser(file.Get(), offset); | 3682 m_syntaxParser.InitParser(file.Get(), offset); |
3683 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); | 3683 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); |
3684 FX_BOOL bNumber = FALSE; | 3684 bool bNumber = false; |
3685 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(bNumber); | 3685 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(bNumber); |
3686 if (!bNumber) { | 3686 if (!bNumber) { |
3687 return FALSE; | 3687 return false; |
3688 } | 3688 } |
3689 FX_DWORD objnum = FXSYS_atoi(wordObjNum); | 3689 FX_DWORD objnum = FXSYS_atoi(wordObjNum); |
3690 if (m_pLinearized) { | 3690 if (m_pLinearized) { |
3691 m_pLinearized->Release(); | 3691 m_pLinearized->Release(); |
3692 m_pLinearized = NULL; | 3692 m_pLinearized = NULL; |
3693 } | 3693 } |
3694 m_pLinearized = ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, obj
num); | 3694 m_pLinearized = ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, obj
num); |
3695 if (!m_pLinearized) { | 3695 if (!m_pLinearized) { |
3696 return FALSE; | 3696 return false; |
3697 } | 3697 } |
3698 if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTR
C("Linearized"))) { | 3698 if (m_pLinearized->GetDict() && m_pLinearized->GetDict()->GetElement(FX_BSTR
C("Linearized"))) { |
3699 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); | 3699 CPDF_Object *pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); |
3700 if (!pLen) { | 3700 if (!pLen) { |
3701 return FALSE; | 3701 return false; |
3702 } | 3702 } |
3703 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) { | 3703 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) { |
3704 return FALSE; | 3704 return false; |
3705 } | 3705 } |
3706 m_bLinearized = TRUE; | 3706 m_bLinearized = true; |
3707 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); | 3707 CPDF_Object *pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); |
3708 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { | 3708 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { |
3709 m_dwFirstPageNo = pNo->GetInteger(); | 3709 m_dwFirstPageNo = pNo->GetInteger(); |
3710 } | 3710 } |
3711 return TRUE; | 3711 return true; |
3712 } | 3712 } |
3713 return FALSE; | 3713 return false; |
3714 } | 3714 } |
3715 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) | 3715 bool CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) |
3716 { | 3716 { |
3717 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 3717 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
3718 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); | 3718 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); |
3719 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 3719 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
3720 uint8_t buffer[1024]; | 3720 uint8_t buffer[1024]; |
3721 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 3721 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
3722 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(buffer, (siz
e_t)dwSize, FALSE)); | 3722 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(buffer, (siz
e_t)dwSize, false)); |
3723 m_syntaxParser.InitParser(file.Get(), 0); | 3723 m_syntaxParser.InitParser(file.Get(), 0); |
3724 m_syntaxParser.RestorePos(dwSize - 1); | 3724 m_syntaxParser.RestorePos(dwSize - 1); |
3725 if (m_syntaxParser.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, dwSize
)) { | 3725 if (m_syntaxParser.SearchWord(FX_BSTRC("startxref"), true, false, dwSize
)) { |
3726 FX_BOOL bNumber; | 3726 bool bNumber; |
3727 m_syntaxParser.GetNextWord(bNumber); | 3727 m_syntaxParser.GetNextWord(bNumber); |
3728 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(bNumber); | 3728 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(bNumber); |
3729 if (!bNumber) { | 3729 if (!bNumber) { |
3730 m_docStatus = PDF_DATAAVAIL_ERROR; | 3730 m_docStatus = PDF_DATAAVAIL_ERROR; |
3731 return FALSE; | 3731 return false; |
3732 } | 3732 } |
3733 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 3733 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); |
3734 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { | 3734 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { |
3735 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3735 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3736 return TRUE; | 3736 return true; |
3737 } | 3737 } |
3738 m_dwLastXRefOffset = m_dwXRefOffset; | 3738 m_dwLastXRefOffset = m_dwXRefOffset; |
3739 SetStartOffset(m_dwXRefOffset); | 3739 SetStartOffset(m_dwXRefOffset); |
3740 m_docStatus = PDF_DATAAVAIL_CROSSREF; | 3740 m_docStatus = PDF_DATAAVAIL_CROSSREF; |
3741 return TRUE; | 3741 return true; |
3742 } | 3742 } |
3743 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3743 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3744 return TRUE; | 3744 return true; |
3745 } | 3745 } |
3746 pHints->AddSegment(req_pos, dwSize); | 3746 pHints->AddSegment(req_pos, dwSize); |
3747 return FALSE; | 3747 return false; |
3748 } | 3748 } |
3749 int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILESI
ZE &xref_offset) | 3749 int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILESI
ZE &xref_offset) |
3750 { | 3750 { |
3751 xref_offset = 0; | 3751 xref_offset = 0; |
3752 FX_DWORD req_size = (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_P
os : 512); | 3752 FX_DWORD req_size = (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_P
os : 512); |
3753 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { | 3753 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { |
3754 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); | 3754 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); |
3755 CFX_BinaryBuf buf(iSize); | 3755 CFX_BinaryBuf buf(iSize); |
3756 uint8_t* pBuf = buf.GetBuffer(); | 3756 uint8_t* pBuf = buf.GetBuffer(); |
3757 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); | 3757 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); |
3758 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_
t)iSize, FALSE)); | 3758 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_
t)iSize, false)); |
3759 m_parser.m_Syntax.InitParser(file.Get(), 0); | 3759 m_parser.m_Syntax.InitParser(file.Get(), 0); |
3760 FX_BOOL bNumber = FALSE; | 3760 bool bNumber = false; |
3761 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber); | 3761 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber); |
3762 if (!bNumber) { | 3762 if (!bNumber) { |
3763 return -1; | 3763 return -1; |
3764 } | 3764 } |
3765 FX_DWORD objNum = FXSYS_atoi(objnum); | 3765 FX_DWORD objNum = FXSYS_atoi(objnum); |
3766 CPDF_Object *pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL
); | 3766 CPDF_Object *pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL
); |
3767 if (!pObj) { | 3767 if (!pObj) { |
3768 m_Pos += m_parser.m_Syntax.SavePos(); | 3768 m_Pos += m_parser.m_Syntax.SavePos(); |
3769 return 0; | 3769 return 0; |
3770 } | 3770 } |
(...skipping 11 matching lines...) Expand all Loading... |
3782 return -1; | 3782 return -1; |
3783 } | 3783 } |
3784 pHints->AddSegment(m_Pos, req_size); | 3784 pHints->AddSegment(m_Pos, req_size); |
3785 return 0; | 3785 return 0; |
3786 } | 3786 } |
3787 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) | 3787 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) |
3788 { | 3788 { |
3789 m_Pos = dwOffset; | 3789 m_Pos = dwOffset; |
3790 } | 3790 } |
3791 #define MAX_WORD_BUFFER 256 | 3791 #define MAX_WORD_BUFFER 256 |
3792 FX_BOOL CPDF_DataAvail::GetNextToken(CFX_ByteString &token) | 3792 bool CPDF_DataAvail::GetNextToken(CFX_ByteString &token) |
3793 { | 3793 { |
3794 m_WordSize = 0; | 3794 m_WordSize = 0; |
3795 uint8_t ch; | 3795 uint8_t ch; |
3796 if (!GetNextChar(ch)) { | 3796 if (!GetNextChar(ch)) { |
3797 return FALSE; | 3797 return false; |
3798 } | 3798 } |
3799 uint8_t type = PDF_CharType[ch]; | 3799 uint8_t type = PDF_CharType[ch]; |
3800 while (1) { | 3800 while (1) { |
3801 while (type == 'W') { | 3801 while (type == 'W') { |
3802 if (!GetNextChar(ch)) { | 3802 if (!GetNextChar(ch)) { |
3803 return FALSE; | 3803 return false; |
3804 } | 3804 } |
3805 type = PDF_CharType[ch]; | 3805 type = PDF_CharType[ch]; |
3806 } | 3806 } |
3807 if (ch != '%') { | 3807 if (ch != '%') { |
3808 break; | 3808 break; |
3809 } | 3809 } |
3810 while (1) { | 3810 while (1) { |
3811 if (!GetNextChar(ch)) { | 3811 if (!GetNextChar(ch)) { |
3812 return FALSE; | 3812 return false; |
3813 } | 3813 } |
3814 if (ch == '\r' || ch == '\n') { | 3814 if (ch == '\r' || ch == '\n') { |
3815 break; | 3815 break; |
3816 } | 3816 } |
3817 } | 3817 } |
3818 type = PDF_CharType[ch]; | 3818 type = PDF_CharType[ch]; |
3819 } | 3819 } |
3820 if (type == 'D') { | 3820 if (type == 'D') { |
3821 m_WordBuffer[m_WordSize++] = ch; | 3821 m_WordBuffer[m_WordSize++] = ch; |
3822 if (ch == '/') { | 3822 if (ch == '/') { |
3823 while (1) { | 3823 while (1) { |
3824 if (!GetNextChar(ch)) { | 3824 if (!GetNextChar(ch)) { |
3825 return FALSE; | 3825 return false; |
3826 } | 3826 } |
3827 type = PDF_CharType[ch]; | 3827 type = PDF_CharType[ch]; |
3828 if (type != 'R' && type != 'N') { | 3828 if (type != 'R' && type != 'N') { |
3829 m_Pos --; | 3829 m_Pos --; |
3830 CFX_ByteString ret(m_WordBuffer, m_WordSize); | 3830 CFX_ByteString ret(m_WordBuffer, m_WordSize); |
3831 token = ret; | 3831 token = ret; |
3832 return TRUE; | 3832 return true; |
3833 } | 3833 } |
3834 if (m_WordSize < MAX_WORD_BUFFER) { | 3834 if (m_WordSize < MAX_WORD_BUFFER) { |
3835 m_WordBuffer[m_WordSize++] = ch; | 3835 m_WordBuffer[m_WordSize++] = ch; |
3836 } | 3836 } |
3837 } | 3837 } |
3838 } else if (ch == '<') { | 3838 } else if (ch == '<') { |
3839 if (!GetNextChar(ch)) { | 3839 if (!GetNextChar(ch)) { |
3840 return FALSE; | 3840 return false; |
3841 } | 3841 } |
3842 if (ch == '<') { | 3842 if (ch == '<') { |
3843 m_WordBuffer[m_WordSize++] = ch; | 3843 m_WordBuffer[m_WordSize++] = ch; |
3844 } else { | 3844 } else { |
3845 m_Pos --; | 3845 m_Pos --; |
3846 } | 3846 } |
3847 } else if (ch == '>') { | 3847 } else if (ch == '>') { |
3848 if (!GetNextChar(ch)) { | 3848 if (!GetNextChar(ch)) { |
3849 return FALSE; | 3849 return false; |
3850 } | 3850 } |
3851 if (ch == '>') { | 3851 if (ch == '>') { |
3852 m_WordBuffer[m_WordSize++] = ch; | 3852 m_WordBuffer[m_WordSize++] = ch; |
3853 } else { | 3853 } else { |
3854 m_Pos --; | 3854 m_Pos --; |
3855 } | 3855 } |
3856 } | 3856 } |
3857 CFX_ByteString ret(m_WordBuffer, m_WordSize); | 3857 CFX_ByteString ret(m_WordBuffer, m_WordSize); |
3858 token = ret; | 3858 token = ret; |
3859 return TRUE; | 3859 return true; |
3860 } | 3860 } |
3861 while (1) { | 3861 while (1) { |
3862 if (m_WordSize < MAX_WORD_BUFFER) { | 3862 if (m_WordSize < MAX_WORD_BUFFER) { |
3863 m_WordBuffer[m_WordSize++] = ch; | 3863 m_WordBuffer[m_WordSize++] = ch; |
3864 } | 3864 } |
3865 if (!GetNextChar(ch)) { | 3865 if (!GetNextChar(ch)) { |
3866 return FALSE; | 3866 return false; |
3867 } | 3867 } |
3868 type = PDF_CharType[ch]; | 3868 type = PDF_CharType[ch]; |
3869 if (type == 'D' || type == 'W') { | 3869 if (type == 'D' || type == 'W') { |
3870 m_Pos --; | 3870 m_Pos --; |
3871 break; | 3871 break; |
3872 } | 3872 } |
3873 } | 3873 } |
3874 CFX_ByteString ret(m_WordBuffer, m_WordSize); | 3874 CFX_ByteString ret(m_WordBuffer, m_WordSize); |
3875 token = ret; | 3875 token = ret; |
3876 return TRUE; | 3876 return true; |
3877 } | 3877 } |
3878 FX_BOOL CPDF_DataAvail::GetNextChar(uint8_t &ch) | 3878 bool CPDF_DataAvail::GetNextChar(uint8_t &ch) |
3879 { | 3879 { |
3880 FX_FILESIZE pos = m_Pos; | 3880 FX_FILESIZE pos = m_Pos; |
3881 if (pos >= m_dwFileLen) { | 3881 if (pos >= m_dwFileLen) { |
3882 return FALSE; | 3882 return false; |
3883 } | 3883 } |
3884 if (m_bufferOffset >= pos || (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <=
pos) { | 3884 if (m_bufferOffset >= pos || (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <=
pos) { |
3885 FX_FILESIZE read_pos = pos; | 3885 FX_FILESIZE read_pos = pos; |
3886 FX_DWORD read_size = 512; | 3886 FX_DWORD read_size = 512; |
3887 if ((FX_FILESIZE)read_size > m_dwFileLen) { | 3887 if ((FX_FILESIZE)read_size > m_dwFileLen) { |
3888 read_size = (FX_DWORD)m_dwFileLen; | 3888 read_size = (FX_DWORD)m_dwFileLen; |
3889 } | 3889 } |
3890 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) { | 3890 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) { |
3891 read_pos = m_dwFileLen - read_size; | 3891 read_pos = m_dwFileLen - read_size; |
3892 } | 3892 } |
3893 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) { | 3893 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) { |
3894 return FALSE; | 3894 return false; |
3895 } | 3895 } |
3896 m_bufferOffset = read_pos; | 3896 m_bufferOffset = read_pos; |
3897 m_bufferSize = read_size; | 3897 m_bufferSize = read_size; |
3898 } | 3898 } |
3899 ch = m_bufferData[pos - m_bufferOffset]; | 3899 ch = m_bufferData[pos - m_bufferOffset]; |
3900 m_Pos ++; | 3900 m_Pos ++; |
3901 return TRUE; | 3901 return true; |
3902 } | 3902 } |
3903 FX_BOOL CPDF_DataAvail::CheckCrossRefItem(IFX_DownloadHints *pHints) | 3903 bool CPDF_DataAvail::CheckCrossRefItem(IFX_DownloadHints *pHints) |
3904 { | 3904 { |
3905 int32_t iSize = 0; | 3905 int32_t iSize = 0; |
3906 CFX_ByteString token; | 3906 CFX_ByteString token; |
3907 while (1) { | 3907 while (1) { |
3908 if (!GetNextToken(token)) { | 3908 if (!GetNextToken(token)) { |
3909 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos :
512); | 3909 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos :
512); |
3910 pHints->AddSegment(m_Pos, iSize); | 3910 pHints->AddSegment(m_Pos, iSize); |
3911 return FALSE; | 3911 return false; |
3912 } | 3912 } |
3913 if (token == "trailer") { | 3913 if (token == "trailer") { |
3914 m_dwTrailerOffset = m_Pos; | 3914 m_dwTrailerOffset = m_Pos; |
3915 m_docStatus = PDF_DATAAVAIL_TRAILER; | 3915 m_docStatus = PDF_DATAAVAIL_TRAILER; |
3916 return TRUE; | 3916 return true; |
3917 } | 3917 } |
3918 } | 3918 } |
3919 } | 3919 } |
3920 FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints *pHints) | 3920 bool CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints *pHints) |
3921 { | 3921 { |
3922 FX_FILESIZE xref_offset = 0; | 3922 FX_FILESIZE xref_offset = 0; |
3923 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); | 3923 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); |
3924 if (nRet == 1) { | 3924 if (nRet == 1) { |
3925 if (!xref_offset) { | 3925 if (!xref_offset) { |
3926 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; | 3926 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; |
3927 } else { | 3927 } else { |
3928 m_dwCurrentXRefSteam = xref_offset; | 3928 m_dwCurrentXRefSteam = xref_offset; |
3929 m_Pos = xref_offset; | 3929 m_Pos = xref_offset; |
3930 } | 3930 } |
3931 return TRUE; | 3931 return true; |
3932 } | 3932 } |
3933 if (nRet == -1) { | 3933 if (nRet == -1) { |
3934 m_docStatus = PDF_DATAAVAIL_ERROR; | 3934 m_docStatus = PDF_DATAAVAIL_ERROR; |
3935 } | 3935 } |
3936 return FALSE; | 3936 return false; |
3937 } | 3937 } |
3938 FX_BOOL CPDF_DataAvail::CheckCrossRef(IFX_DownloadHints* pHints) | 3938 bool CPDF_DataAvail::CheckCrossRef(IFX_DownloadHints* pHints) |
3939 { | 3939 { |
3940 int32_t iSize = 0; | 3940 int32_t iSize = 0; |
3941 CFX_ByteString token; | 3941 CFX_ByteString token; |
3942 if (!GetNextToken(token)) { | 3942 if (!GetNextToken(token)) { |
3943 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512)
; | 3943 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512)
; |
3944 pHints->AddSegment(m_Pos, iSize); | 3944 pHints->AddSegment(m_Pos, iSize); |
3945 return FALSE; | 3945 return false; |
3946 } | 3946 } |
3947 if (token == "xref") { | 3947 if (token == "xref") { |
3948 m_CrossOffset.InsertAt(0, m_dwXRefOffset); | 3948 m_CrossOffset.InsertAt(0, m_dwXRefOffset); |
3949 while (1) { | 3949 while (1) { |
3950 if (!GetNextToken(token)) { | 3950 if (!GetNextToken(token)) { |
3951 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Po
s : 512); | 3951 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Po
s : 512); |
3952 pHints->AddSegment(m_Pos, iSize); | 3952 pHints->AddSegment(m_Pos, iSize); |
3953 m_docStatus = PDF_DATAAVAIL_CROSSREF_ITEM; | 3953 m_docStatus = PDF_DATAAVAIL_CROSSREF_ITEM; |
3954 return FALSE; | 3954 return false; |
3955 } | 3955 } |
3956 if (token == "trailer") { | 3956 if (token == "trailer") { |
3957 m_dwTrailerOffset = m_Pos; | 3957 m_dwTrailerOffset = m_Pos; |
3958 m_docStatus = PDF_DATAAVAIL_TRAILER; | 3958 m_docStatus = PDF_DATAAVAIL_TRAILER; |
3959 return TRUE; | 3959 return true; |
3960 } | 3960 } |
3961 } | 3961 } |
3962 } else { | 3962 } else { |
3963 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3963 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
3964 return TRUE; | 3964 return true; |
3965 } | 3965 } |
3966 return FALSE; | 3966 return false; |
3967 } | 3967 } |
3968 FX_BOOL CPDF_DataAvail::CheckTrailerAppend(IFX_DownloadHints* pHints) | 3968 bool CPDF_DataAvail::CheckTrailerAppend(IFX_DownloadHints* pHints) |
3969 { | 3969 { |
3970 if (m_Pos < m_dwFileLen) { | 3970 if (m_Pos < m_dwFileLen) { |
3971 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos(); | 3971 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos(); |
3972 int32_t iSize = (int32_t)(dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen
- dwAppendPos : 512); | 3972 int32_t iSize = (int32_t)(dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen
- dwAppendPos : 512); |
3973 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { | 3973 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { |
3974 pHints->AddSegment(dwAppendPos, iSize); | 3974 pHints->AddSegment(dwAppendPos, iSize); |
3975 return FALSE; | 3975 return false; |
3976 } | 3976 } |
3977 } | 3977 } |
3978 if (m_dwPrevXRefOffset) { | 3978 if (m_dwPrevXRefOffset) { |
3979 SetStartOffset(m_dwPrevXRefOffset); | 3979 SetStartOffset(m_dwPrevXRefOffset); |
3980 m_docStatus = PDF_DATAAVAIL_CROSSREF; | 3980 m_docStatus = PDF_DATAAVAIL_CROSSREF; |
3981 } else { | 3981 } else { |
3982 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; | 3982 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; |
3983 } | 3983 } |
3984 return TRUE; | 3984 return true; |
3985 } | 3985 } |
3986 FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) | 3986 bool CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) |
3987 { | 3987 { |
3988 int32_t iTrailerSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m
_Pos : 512); | 3988 int32_t iTrailerSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m
_Pos : 512); |
3989 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { | 3989 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { |
3990 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); | 3990 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); |
3991 CFX_BinaryBuf buf(iSize); | 3991 CFX_BinaryBuf buf(iSize); |
3992 uint8_t* pBuf = buf.GetBuffer(); | 3992 uint8_t* pBuf = buf.GetBuffer(); |
3993 if (!pBuf) { | 3993 if (!pBuf) { |
3994 m_docStatus = PDF_DATAAVAIL_ERROR; | 3994 m_docStatus = PDF_DATAAVAIL_ERROR; |
3995 return FALSE; | 3995 return false; |
3996 } | 3996 } |
3997 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) { | 3997 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) { |
3998 return FALSE; | 3998 return false; |
3999 } | 3999 } |
4000 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_
t)iSize, FALSE)); | 4000 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_
t)iSize, false)); |
4001 m_syntaxParser.InitParser(file.Get(), 0); | 4001 m_syntaxParser.InitParser(file.Get(), 0); |
4002 CPDF_Object *pTrailer = m_syntaxParser.GetObject(NULL, 0, 0, 0); | 4002 CPDF_Object *pTrailer = m_syntaxParser.GetObject(NULL, 0, 0, 0); |
4003 if (!pTrailer) { | 4003 if (!pTrailer) { |
4004 m_Pos += m_syntaxParser.SavePos(); | 4004 m_Pos += m_syntaxParser.SavePos(); |
4005 pHints->AddSegment(m_Pos, iTrailerSize); | 4005 pHints->AddSegment(m_Pos, iTrailerSize); |
4006 return FALSE; | 4006 return false; |
4007 } | 4007 } |
4008 if (pTrailer->GetType() != PDFOBJ_DICTIONARY) { | 4008 if (pTrailer->GetType() != PDFOBJ_DICTIONARY) { |
4009 return FALSE; | 4009 return false; |
4010 } | 4010 } |
4011 CPDF_Dictionary *pTrailerDict = pTrailer->GetDict(); | 4011 CPDF_Dictionary *pTrailerDict = pTrailer->GetDict(); |
4012 if (pTrailerDict) { | 4012 if (pTrailerDict) { |
4013 CPDF_Object *pEncrypt = pTrailerDict->GetElement("Encrypt"); | 4013 CPDF_Object *pEncrypt = pTrailerDict->GetElement("Encrypt"); |
4014 if (pEncrypt && pEncrypt->GetType() == PDFOBJ_REFERENCE) { | 4014 if (pEncrypt && pEncrypt->GetType() == PDFOBJ_REFERENCE) { |
4015 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 4015 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
4016 pTrailer->Release(); | 4016 pTrailer->Release(); |
4017 return TRUE; | 4017 return true; |
4018 } | 4018 } |
4019 } | 4019 } |
4020 FX_DWORD xrefpos = GetDirectInteger(pTrailer->GetDict(), FX_BSTRC("Prev"
)); | 4020 FX_DWORD xrefpos = GetDirectInteger(pTrailer->GetDict(), FX_BSTRC("Prev"
)); |
4021 if (xrefpos) { | 4021 if (xrefpos) { |
4022 m_dwPrevXRefOffset = GetDirectInteger(pTrailer->GetDict(), FX_BSTRC(
"XRefStm")); | 4022 m_dwPrevXRefOffset = GetDirectInteger(pTrailer->GetDict(), FX_BSTRC(
"XRefStm")); |
4023 pTrailer->Release(); | 4023 pTrailer->Release(); |
4024 if (m_dwPrevXRefOffset) { | 4024 if (m_dwPrevXRefOffset) { |
4025 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 4025 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
4026 } else { | 4026 } else { |
4027 m_dwPrevXRefOffset = xrefpos; | 4027 m_dwPrevXRefOffset = xrefpos; |
4028 if (m_dwPrevXRefOffset >= m_dwFileLen) { | 4028 if (m_dwPrevXRefOffset >= m_dwFileLen) { |
4029 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 4029 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
4030 } else { | 4030 } else { |
4031 SetStartOffset(m_dwPrevXRefOffset); | 4031 SetStartOffset(m_dwPrevXRefOffset); |
4032 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | 4032 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; |
4033 } | 4033 } |
4034 } | 4034 } |
4035 return TRUE; | 4035 return true; |
4036 } | 4036 } |
4037 m_dwPrevXRefOffset = 0; | 4037 m_dwPrevXRefOffset = 0; |
4038 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | 4038 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; |
4039 pTrailer->Release(); | 4039 pTrailer->Release(); |
4040 return TRUE; | 4040 return true; |
4041 } | 4041 } |
4042 pHints->AddSegment(m_Pos, iTrailerSize); | 4042 pHints->AddSegment(m_Pos, iTrailerSize); |
4043 return FALSE; | 4043 return false; |
4044 } | 4044 } |
4045 FX_BOOL CPDF_DataAvail::CheckPage(int32_t iPage, IFX_DownloadHints* pHints) | 4045 bool CPDF_DataAvail::CheckPage(int32_t iPage, IFX_DownloadHints* pHints) |
4046 { | 4046 { |
4047 while (TRUE) { | 4047 while (true) { |
4048 switch (m_docStatus) { | 4048 switch (m_docStatus) { |
4049 case PDF_DATAAVAIL_PAGETREE: | 4049 case PDF_DATAAVAIL_PAGETREE: |
4050 if (!LoadDocPages(pHints)) { | 4050 if (!LoadDocPages(pHints)) { |
4051 return FALSE; | 4051 return false; |
4052 } | 4052 } |
4053 break; | 4053 break; |
4054 case PDF_DATAAVAIL_PAGE: | 4054 case PDF_DATAAVAIL_PAGE: |
4055 if (!LoadDocPage(iPage, pHints)) { | 4055 if (!LoadDocPage(iPage, pHints)) { |
4056 return FALSE; | 4056 return false; |
4057 } | 4057 } |
4058 break; | 4058 break; |
4059 case PDF_DATAAVAIL_ERROR: | 4059 case PDF_DATAAVAIL_ERROR: |
4060 return LoadAllFile(pHints); | 4060 return LoadAllFile(pHints); |
4061 default: | 4061 default: |
4062 m_bPagesTreeLoad = TRUE; | 4062 m_bPagesTreeLoad = true; |
4063 m_bPagesLoad = TRUE; | 4063 m_bPagesLoad = true; |
4064 m_bCurPageDictLoadOK = TRUE; | 4064 m_bCurPageDictLoadOK = true; |
4065 m_docStatus = PDF_DATAAVAIL_PAGE; | 4065 m_docStatus = PDF_DATAAVAIL_PAGE; |
4066 return TRUE; | 4066 return true; |
4067 } | 4067 } |
4068 } | 4068 } |
4069 } | 4069 } |
4070 FX_BOOL»CPDF_DataAvail::CheckArrayPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPa
geNode, IFX_DownloadHints* pHints) | 4070 bool» CPDF_DataAvail::CheckArrayPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPa
geNode, IFX_DownloadHints* pHints) |
4071 { | 4071 { |
4072 FX_BOOL bExist = FALSE; | 4072 bool bExist = false; |
4073 CPDF_Object *pPages = GetObject(dwPageNo, pHints, &bExist); | 4073 CPDF_Object *pPages = GetObject(dwPageNo, pHints, &bExist); |
4074 if (!bExist) { | 4074 if (!bExist) { |
4075 m_docStatus = PDF_DATAAVAIL_ERROR; | 4075 m_docStatus = PDF_DATAAVAIL_ERROR; |
4076 return FALSE; | 4076 return false; |
4077 } | 4077 } |
4078 if (!pPages) { | 4078 if (!pPages) { |
4079 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 4079 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
4080 m_docStatus = PDF_DATAAVAIL_ERROR; | 4080 m_docStatus = PDF_DATAAVAIL_ERROR; |
4081 return FALSE; | 4081 return false; |
4082 } | 4082 } |
4083 return FALSE; | 4083 return false; |
4084 } | 4084 } |
4085 if (pPages->GetType() != PDFOBJ_ARRAY) { | 4085 if (pPages->GetType() != PDFOBJ_ARRAY) { |
4086 pPages->Release(); | 4086 pPages->Release(); |
4087 m_docStatus = PDF_DATAAVAIL_ERROR; | 4087 m_docStatus = PDF_DATAAVAIL_ERROR; |
4088 return FALSE; | 4088 return false; |
4089 } | 4089 } |
4090 pPageNode->m_type = PDF_PAGENODE_PAGES; | 4090 pPageNode->m_type = PDF_PAGENODE_PAGES; |
4091 CPDF_Array* pArray = (CPDF_Array*)pPages; | 4091 CPDF_Array* pArray = (CPDF_Array*)pPages; |
4092 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { | 4092 for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { |
4093 CPDF_Object *pKid = (CPDF_Object *)pArray->GetElement(i); | 4093 CPDF_Object *pKid = (CPDF_Object *)pArray->GetElement(i); |
4094 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { | 4094 if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { |
4095 continue; | 4095 continue; |
4096 } | 4096 } |
4097 CPDF_PageNode *pNode = new CPDF_PageNode(); | 4097 CPDF_PageNode *pNode = new CPDF_PageNode(); |
4098 pPageNode->m_childNode.Add(pNode); | 4098 pPageNode->m_childNode.Add(pNode); |
4099 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); | 4099 pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); |
4100 } | 4100 } |
4101 pPages->Release(); | 4101 pPages->Release(); |
4102 return TRUE; | 4102 return true; |
4103 } | 4103 } |
4104 FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pP
ageNode, IFX_DownloadHints* pHints) | 4104 bool CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPage
Node, IFX_DownloadHints* pHints) |
4105 { | 4105 { |
4106 FX_BOOL bExist = FALSE; | 4106 bool bExist = false; |
4107 CPDF_Object *pPage = GetObject(dwPageNo, pHints, &bExist); | 4107 CPDF_Object *pPage = GetObject(dwPageNo, pHints, &bExist); |
4108 if (!bExist) { | 4108 if (!bExist) { |
4109 m_docStatus = PDF_DATAAVAIL_ERROR; | 4109 m_docStatus = PDF_DATAAVAIL_ERROR; |
4110 return FALSE; | 4110 return false; |
4111 } | 4111 } |
4112 if (!pPage) { | 4112 if (!pPage) { |
4113 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 4113 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
4114 m_docStatus = PDF_DATAAVAIL_ERROR; | 4114 m_docStatus = PDF_DATAAVAIL_ERROR; |
4115 return FALSE; | 4115 return false; |
4116 } | 4116 } |
4117 return FALSE; | 4117 return false; |
4118 } | 4118 } |
4119 if (pPage->GetType() == PDFOBJ_ARRAY) { | 4119 if (pPage->GetType() == PDFOBJ_ARRAY) { |
4120 pPageNode->m_dwPageNo = dwPageNo; | 4120 pPageNode->m_dwPageNo = dwPageNo; |
4121 pPageNode->m_type = PDF_PAGENODE_ARRAY; | 4121 pPageNode->m_type = PDF_PAGENODE_ARRAY; |
4122 pPage->Release(); | 4122 pPage->Release(); |
4123 return TRUE; | 4123 return true; |
4124 } | 4124 } |
4125 if (pPage->GetType() != PDFOBJ_DICTIONARY) { | 4125 if (pPage->GetType() != PDFOBJ_DICTIONARY) { |
4126 pPage->Release(); | 4126 pPage->Release(); |
4127 m_docStatus = PDF_DATAAVAIL_ERROR; | 4127 m_docStatus = PDF_DATAAVAIL_ERROR; |
4128 return FALSE; | 4128 return false; |
4129 } | 4129 } |
4130 pPageNode->m_dwPageNo = dwPageNo; | 4130 pPageNode->m_dwPageNo = dwPageNo; |
4131 CPDF_Dictionary* pDict = pPage->GetDict(); | 4131 CPDF_Dictionary* pDict = pPage->GetDict(); |
4132 CFX_ByteString type = pDict ? pDict->GetString(FX_BSTRC("Type")) : CFX_ByteS
tring(); | 4132 CFX_ByteString type = pDict ? pDict->GetString(FX_BSTRC("Type")) : CFX_ByteS
tring(); |
4133 if (type == FX_BSTRC("Pages")) { | 4133 if (type == FX_BSTRC("Pages")) { |
4134 pPageNode->m_type = PDF_PAGENODE_PAGES; | 4134 pPageNode->m_type = PDF_PAGENODE_PAGES; |
4135 CPDF_Object *pKids = pDict->GetElement(FX_BSTRC("Kids")); | 4135 CPDF_Object *pKids = pDict->GetElement(FX_BSTRC("Kids")); |
4136 if (!pKids) { | 4136 if (!pKids) { |
4137 m_docStatus = PDF_DATAAVAIL_PAGE; | 4137 m_docStatus = PDF_DATAAVAIL_PAGE; |
4138 return TRUE; | 4138 return true; |
4139 } | 4139 } |
4140 switch (pKids->GetType()) { | 4140 switch (pKids->GetType()) { |
4141 case PDFOBJ_REFERENCE: { | 4141 case PDFOBJ_REFERENCE: { |
4142 CPDF_Reference *pKid = (CPDF_Reference *)pKids; | 4142 CPDF_Reference *pKid = (CPDF_Reference *)pKids; |
4143 CPDF_PageNode *pNode = new CPDF_PageNode(); | 4143 CPDF_PageNode *pNode = new CPDF_PageNode(); |
4144 pPageNode->m_childNode.Add(pNode); | 4144 pPageNode->m_childNode.Add(pNode); |
4145 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 4145 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
4146 } | 4146 } |
4147 break; | 4147 break; |
4148 case PDFOBJ_ARRAY: { | 4148 case PDFOBJ_ARRAY: { |
(...skipping 10 matching lines...) Expand all Loading... |
4159 } | 4159 } |
4160 break; | 4160 break; |
4161 default: | 4161 default: |
4162 break; | 4162 break; |
4163 } | 4163 } |
4164 } else if (type == FX_BSTRC("Page")) { | 4164 } else if (type == FX_BSTRC("Page")) { |
4165 pPageNode->m_type = PDF_PAGENODE_PAGE; | 4165 pPageNode->m_type = PDF_PAGENODE_PAGE; |
4166 } else { | 4166 } else { |
4167 pPage->Release(); | 4167 pPage->Release(); |
4168 m_docStatus = PDF_DATAAVAIL_ERROR; | 4168 m_docStatus = PDF_DATAAVAIL_ERROR; |
4169 return FALSE; | 4169 return false; |
4170 } | 4170 } |
4171 pPage->Release(); | 4171 pPage->Release(); |
4172 return TRUE; | 4172 return true; |
4173 } | 4173 } |
4174 FX_BOOL CPDF_DataAvail::CheckPageNode(CPDF_PageNode &pageNodes, int32_t iPage, i
nt32_t &iCount, IFX_DownloadHints* pHints) | 4174 bool CPDF_DataAvail::CheckPageNode(CPDF_PageNode &pageNodes, int32_t iPage, int3
2_t &iCount, IFX_DownloadHints* pHints) |
4175 { | 4175 { |
4176 int32_t iSize = pageNodes.m_childNode.GetSize(); | 4176 int32_t iSize = pageNodes.m_childNode.GetSize(); |
4177 if (iSize <= 0 || iPage >= iSize) { | 4177 if (iSize <= 0 || iPage >= iSize) { |
4178 m_docStatus = PDF_DATAAVAIL_ERROR; | 4178 m_docStatus = PDF_DATAAVAIL_ERROR; |
4179 return FALSE; | 4179 return false; |
4180 } | 4180 } |
4181 for (int32_t i = 0; i < iSize; ++i) { | 4181 for (int32_t i = 0; i < iSize; ++i) { |
4182 CPDF_PageNode *pNode = (CPDF_PageNode*)pageNodes.m_childNode.GetAt(i); | 4182 CPDF_PageNode *pNode = (CPDF_PageNode*)pageNodes.m_childNode.GetAt(i); |
4183 if (!pNode) { | 4183 if (!pNode) { |
4184 continue; | 4184 continue; |
4185 } | 4185 } |
4186 switch (pNode->m_type) { | 4186 switch (pNode->m_type) { |
4187 case PDF_PAGENODE_UNKOWN: | 4187 case PDF_PAGENODE_UNKOWN: |
4188 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) { | 4188 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) { |
4189 return FALSE; | 4189 return false; |
4190 } | 4190 } |
4191 --i; | 4191 --i; |
4192 break; | 4192 break; |
4193 case PDF_PAGENODE_PAGE: | 4193 case PDF_PAGENODE_PAGE: |
4194 iCount++; | 4194 iCount++; |
4195 if (iPage == iCount && m_pDocument) { | 4195 if (iPage == iCount && m_pDocument) { |
4196 m_pDocument->m_PageList.SetAt(iPage, pNode->m_dwPageNo); | 4196 m_pDocument->m_PageList.SetAt(iPage, pNode->m_dwPageNo); |
4197 } | 4197 } |
4198 break; | 4198 break; |
4199 case PDF_PAGENODE_PAGES: | 4199 case PDF_PAGENODE_PAGES: |
4200 if (!CheckPageNode(*pNode, iPage, iCount, pHints)) { | 4200 if (!CheckPageNode(*pNode, iPage, iCount, pHints)) { |
4201 return FALSE; | 4201 return false; |
4202 } | 4202 } |
4203 break; | 4203 break; |
4204 case PDF_PAGENODE_ARRAY: | 4204 case PDF_PAGENODE_ARRAY: |
4205 if (!CheckArrayPageNode(pNode->m_dwPageNo, pNode, pHints)) { | 4205 if (!CheckArrayPageNode(pNode->m_dwPageNo, pNode, pHints)) { |
4206 return FALSE; | 4206 return false; |
4207 } | 4207 } |
4208 --i; | 4208 --i; |
4209 break; | 4209 break; |
4210 } | 4210 } |
4211 if (iPage == iCount) { | 4211 if (iPage == iCount) { |
4212 m_docStatus = PDF_DATAAVAIL_DONE; | 4212 m_docStatus = PDF_DATAAVAIL_DONE; |
4213 return TRUE; | 4213 return true; |
4214 } | 4214 } |
4215 } | 4215 } |
4216 return TRUE; | 4216 return true; |
4217 } | 4217 } |
4218 FX_BOOL CPDF_DataAvail::LoadDocPage(int32_t iPage, IFX_DownloadHints* pHints) | 4218 bool CPDF_DataAvail::LoadDocPage(int32_t iPage, IFX_DownloadHints* pHints) |
4219 { | 4219 { |
4220 if (m_pDocument->GetPageCount() <= iPage || m_pDocument->m_PageList.GetAt(iP
age)) { | 4220 if (m_pDocument->GetPageCount() <= iPage || m_pDocument->m_PageList.GetAt(iP
age)) { |
4221 m_docStatus = PDF_DATAAVAIL_DONE; | 4221 m_docStatus = PDF_DATAAVAIL_DONE; |
4222 return TRUE; | 4222 return true; |
4223 } | 4223 } |
4224 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) { | 4224 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) { |
4225 if (iPage == 0) { | 4225 if (iPage == 0) { |
4226 m_docStatus = PDF_DATAAVAIL_DONE; | 4226 m_docStatus = PDF_DATAAVAIL_DONE; |
4227 return TRUE; | 4227 return true; |
4228 } | 4228 } |
4229 m_docStatus = PDF_DATAAVAIL_ERROR; | 4229 m_docStatus = PDF_DATAAVAIL_ERROR; |
4230 return TRUE; | 4230 return true; |
4231 } | 4231 } |
4232 int32_t iCount = -1; | 4232 int32_t iCount = -1; |
4233 return CheckPageNode(m_pageNodes, iPage, iCount, pHints); | 4233 return CheckPageNode(m_pageNodes, iPage, iCount, pHints); |
4234 } | 4234 } |
4235 FX_BOOL CPDF_DataAvail::CheckPageCount(IFX_DownloadHints* pHints) | 4235 bool CPDF_DataAvail::CheckPageCount(IFX_DownloadHints* pHints) |
4236 { | 4236 { |
4237 FX_BOOL bExist = FALSE; | 4237 bool bExist = false; |
4238 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist); | 4238 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist); |
4239 if (!bExist) { | 4239 if (!bExist) { |
4240 m_docStatus = PDF_DATAAVAIL_ERROR; | 4240 m_docStatus = PDF_DATAAVAIL_ERROR; |
4241 return FALSE; | 4241 return false; |
4242 } | 4242 } |
4243 if (!pPages) { | 4243 if (!pPages) { |
4244 return FALSE; | 4244 return false; |
4245 } | 4245 } |
4246 CPDF_Dictionary* pPagesDict = pPages->GetDict(); | 4246 CPDF_Dictionary* pPagesDict = pPages->GetDict(); |
4247 if (!pPagesDict) { | 4247 if (!pPagesDict) { |
4248 pPages->Release(); | 4248 pPages->Release(); |
4249 m_docStatus = PDF_DATAAVAIL_ERROR; | 4249 m_docStatus = PDF_DATAAVAIL_ERROR; |
4250 return FALSE; | 4250 return false; |
4251 } | 4251 } |
4252 if (!pPagesDict->KeyExist(FX_BSTRC("Kids"))) { | 4252 if (!pPagesDict->KeyExist(FX_BSTRC("Kids"))) { |
4253 pPages->Release(); | 4253 pPages->Release(); |
4254 return TRUE; | 4254 return true; |
4255 } | 4255 } |
4256 int count = pPagesDict->GetInteger(FX_BSTRC("Count")); | 4256 int count = pPagesDict->GetInteger(FX_BSTRC("Count")); |
4257 if (count > 0) { | 4257 if (count > 0) { |
4258 pPages->Release(); | 4258 pPages->Release(); |
4259 return TRUE; | 4259 return true; |
4260 } | 4260 } |
4261 pPages->Release(); | 4261 pPages->Release(); |
4262 return FALSE; | 4262 return false; |
4263 } | 4263 } |
4264 FX_BOOL CPDF_DataAvail::LoadDocPages(IFX_DownloadHints* pHints) | 4264 bool CPDF_DataAvail::LoadDocPages(IFX_DownloadHints* pHints) |
4265 { | 4265 { |
4266 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) { | 4266 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) { |
4267 return FALSE; | 4267 return false; |
4268 } | 4268 } |
4269 if (CheckPageCount(pHints)) { | 4269 if (CheckPageCount(pHints)) { |
4270 m_docStatus = PDF_DATAAVAIL_PAGE; | 4270 m_docStatus = PDF_DATAAVAIL_PAGE; |
4271 return TRUE; | 4271 return true; |
4272 } | 4272 } |
4273 m_bTotalLoadPageTree = TRUE; | 4273 m_bTotalLoadPageTree = true; |
4274 return FALSE; | 4274 return false; |
4275 } | 4275 } |
4276 FX_BOOL CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints) | 4276 bool CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints) |
4277 { | 4277 { |
4278 while (!m_bPagesTreeLoad) { | 4278 while (!m_bPagesTreeLoad) { |
4279 if (!CheckPageStatus(pHints)) { | 4279 if (!CheckPageStatus(pHints)) { |
4280 return FALSE; | 4280 return false; |
4281 } | 4281 } |
4282 } | 4282 } |
4283 if (m_bPagesLoad) { | 4283 if (m_bPagesLoad) { |
4284 return TRUE; | 4284 return true; |
4285 } | 4285 } |
4286 m_pDocument->LoadPages(); | 4286 m_pDocument->LoadPages(); |
4287 return FALSE; | 4287 return false; |
4288 } | 4288 } |
4289 FX_BOOL CPDF_DataAvail::CheckLinearizedData(IFX_DownloadHints* pHints) | 4289 bool CPDF_DataAvail::CheckLinearizedData(IFX_DownloadHints* pHints) |
4290 { | 4290 { |
4291 if (m_bLinearedDataOK) { | 4291 if (m_bLinearedDataOK) { |
4292 return TRUE; | 4292 return true; |
4293 } | 4293 } |
4294 | 4294 |
4295 if (!m_bMainXRefLoadTried) { | 4295 if (!m_bMainXRefLoadTried) { |
4296 FX_SAFE_DWORD data_size = m_dwFileLen; | 4296 FX_SAFE_DWORD data_size = m_dwFileLen; |
4297 data_size -= m_dwLastXRefOffset; | 4297 data_size -= m_dwLastXRefOffset; |
4298 if (!data_size.IsValid()) { | 4298 if (!data_size.IsValid()) { |
4299 return FALSE; | 4299 return false; |
4300 } | 4300 } |
4301 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, data_size.ValueOrDie(
))) { | 4301 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, data_size.ValueOrDie(
))) { |
4302 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie()); | 4302 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie()); |
4303 return FALSE; | 4303 return false; |
4304 } | 4304 } |
4305 FX_DWORD dwRet = ((CPDF_Parser *)m_pDocument->GetParser())->LoadLineariz
edMainXRefTable(); | 4305 FX_DWORD dwRet = ((CPDF_Parser *)m_pDocument->GetParser())->LoadLineariz
edMainXRefTable(); |
4306 m_bMainXRefLoadTried = TRUE; | 4306 m_bMainXRefLoadTried = true; |
4307 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 4307 if (dwRet != PDFPARSE_ERROR_SUCCESS) { |
4308 return FALSE; | 4308 return false; |
4309 } | 4309 } |
4310 if (!PreparePageItem()) { | 4310 if (!PreparePageItem()) { |
4311 return FALSE; | 4311 return false; |
4312 } | 4312 } |
4313 m_bMainXRefLoadedOK = TRUE; | 4313 m_bMainXRefLoadedOK = true; |
4314 m_bLinearedDataOK = TRUE; | 4314 m_bLinearedDataOK = true; |
4315 } | 4315 } |
4316 | 4316 |
4317 return m_bLinearedDataOK; | 4317 return m_bLinearedDataOK; |
4318 } | 4318 } |
4319 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, IFX_DownloadHints* pHints
) | 4319 bool CPDF_DataAvail::CheckPageAnnots(int32_t iPage, IFX_DownloadHints* pHints) |
4320 { | 4320 { |
4321 if (!m_objs_array.GetSize()) { | 4321 if (!m_objs_array.GetSize()) { |
4322 m_objs_array.RemoveAll(); | 4322 m_objs_array.RemoveAll(); |
4323 m_objnum_array.RemoveAll(); | 4323 m_objnum_array.RemoveAll(); |
4324 CPDF_Dictionary *pPageDict = m_pDocument->GetPage(iPage); | 4324 CPDF_Dictionary *pPageDict = m_pDocument->GetPage(iPage); |
4325 if (!pPageDict) { | 4325 if (!pPageDict) { |
4326 return TRUE; | 4326 return true; |
4327 } | 4327 } |
4328 CPDF_Object *pAnnots = pPageDict->GetElement(FX_BSTRC("Annots")); | 4328 CPDF_Object *pAnnots = pPageDict->GetElement(FX_BSTRC("Annots")); |
4329 if (!pAnnots) { | 4329 if (!pAnnots) { |
4330 return TRUE; | 4330 return true; |
4331 } | 4331 } |
4332 CFX_PtrArray obj_array; | 4332 CFX_PtrArray obj_array; |
4333 obj_array.Add(pAnnots); | 4333 obj_array.Add(pAnnots); |
4334 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 4334 bool bRet = IsObjectsAvail(obj_array, false, pHints, m_objs_array); |
4335 if (bRet) { | 4335 if (bRet) { |
4336 m_objs_array.RemoveAll(); | 4336 m_objs_array.RemoveAll(); |
4337 } | 4337 } |
4338 return bRet; | 4338 return bRet; |
4339 } | 4339 } |
4340 CFX_PtrArray new_objs_array; | 4340 CFX_PtrArray new_objs_array; |
4341 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 4341 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_array); |
4342 m_objs_array.RemoveAll(); | 4342 m_objs_array.RemoveAll(); |
4343 if (!bRet) { | 4343 if (!bRet) { |
4344 m_objs_array.Append(new_objs_array); | 4344 m_objs_array.Append(new_objs_array); |
4345 } | 4345 } |
4346 return bRet; | 4346 return bRet; |
4347 } | 4347 } |
4348 FX_BOOL CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, IFX_DownloadHint
s* pHints) | 4348 bool CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, IFX_DownloadHints*
pHints) |
4349 { | 4349 { |
4350 if (!m_bAnnotsLoad) { | 4350 if (!m_bAnnotsLoad) { |
4351 if (!CheckPageAnnots(iPage, pHints)) { | 4351 if (!CheckPageAnnots(iPage, pHints)) { |
4352 return FALSE; | 4352 return false; |
4353 } | 4353 } |
4354 m_bAnnotsLoad = TRUE; | 4354 m_bAnnotsLoad = true; |
4355 } | 4355 } |
4356 if (m_bAnnotsLoad) { | 4356 if (m_bAnnotsLoad) { |
4357 if (!CheckLinearizedData(pHints)) | 4357 if (!CheckLinearizedData(pHints)) |
4358 return FALSE; | 4358 return false; |
4359 } | 4359 } |
4360 m_bPageLoadedOK = FALSE; | 4360 m_bPageLoadedOK = false; |
4361 return TRUE; | 4361 return true; |
4362 } | 4362 } |
4363 FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary *pDict) | 4363 bool CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary *pDict) |
4364 { | 4364 { |
4365 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); | 4365 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); |
4366 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) { | 4366 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) { |
4367 return FALSE; | 4367 return false; |
4368 } | 4368 } |
4369 CPDF_Object *pParent = pDict->GetElement("Parent"); | 4369 CPDF_Object *pParent = pDict->GetElement("Parent"); |
4370 if (!pParent) { | 4370 if (!pParent) { |
4371 return FALSE; | 4371 return false; |
4372 } | 4372 } |
4373 CPDF_Dictionary *pParentDict = pParent->GetDict(); | 4373 CPDF_Dictionary *pParentDict = pParent->GetDict(); |
4374 if (!pParentDict) { | 4374 if (!pParentDict) { |
4375 return FALSE; | 4375 return false; |
4376 } | 4376 } |
4377 CPDF_Object *pRet = pParentDict->GetElement("Resources"); | 4377 CPDF_Object *pRet = pParentDict->GetElement("Resources"); |
4378 if (pRet) { | 4378 if (pRet) { |
4379 m_pPageResource = pRet; | 4379 m_pPageResource = pRet; |
4380 return TRUE; | 4380 return true; |
4381 } | 4381 } |
4382 return HaveResourceAncestor(pParentDict); | 4382 return HaveResourceAncestor(pParentDict); |
4383 } | 4383 } |
4384 FX_BOOL CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) | 4384 bool CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) |
4385 { | 4385 { |
4386 if (!m_pDocument) { | 4386 if (!m_pDocument) { |
4387 return FALSE; | 4387 return false; |
4388 } | 4388 } |
4389 if (IsFirstCheck(iPage)) { | 4389 if (IsFirstCheck(iPage)) { |
4390 m_bCurPageDictLoadOK = FALSE; | 4390 m_bCurPageDictLoadOK = false; |
4391 m_bPageLoadedOK = FALSE; | 4391 m_bPageLoadedOK = false; |
4392 m_bAnnotsLoad = FALSE; | 4392 m_bAnnotsLoad = false; |
4393 m_bNeedDownLoadResource = FALSE; | 4393 m_bNeedDownLoadResource = false; |
4394 m_objs_array.RemoveAll(); | 4394 m_objs_array.RemoveAll(); |
4395 m_objnum_array.RemoveAll(); | 4395 m_objnum_array.RemoveAll(); |
4396 } | 4396 } |
4397 if (m_pagesLoadState == NULL) { | 4397 if (m_pagesLoadState == NULL) { |
4398 m_pagesLoadState = new CFX_CMapDWordToDWord(); | 4398 m_pagesLoadState = new CFX_CMapDWordToDWord(); |
4399 } | 4399 } |
4400 FX_DWORD dwPageLoad = 0; | 4400 FX_DWORD dwPageLoad = 0; |
4401 if (m_pagesLoadState->Lookup(iPage, dwPageLoad) && dwPageLoad != 0) { | 4401 if (m_pagesLoadState->Lookup(iPage, dwPageLoad) && dwPageLoad != 0) { |
4402 return TRUE; | 4402 return true; |
4403 } | 4403 } |
4404 if (m_bLinearized) { | 4404 if (m_bLinearized) { |
4405 if ((FX_DWORD)iPage == m_dwFirstPageNo) { | 4405 if ((FX_DWORD)iPage == m_dwFirstPageNo) { |
4406 m_pagesLoadState->SetAt(iPage, TRUE); | 4406 m_pagesLoadState->SetAt(iPage, true); |
4407 return TRUE; | 4407 return true; |
4408 } | 4408 } |
4409 if (!CheckLinearizedData(pHints)) { | 4409 if (!CheckLinearizedData(pHints)) { |
4410 return FALSE; | 4410 return false; |
4411 } | 4411 } |
4412 if (m_bMainXRefLoadedOK) { | 4412 if (m_bMainXRefLoadedOK) { |
4413 if (m_bTotalLoadPageTree) { | 4413 if (m_bTotalLoadPageTree) { |
4414 if (!LoadPages(pHints)) { | 4414 if (!LoadPages(pHints)) { |
4415 return FALSE; | 4415 return false; |
4416 } | 4416 } |
4417 } else { | 4417 } else { |
4418 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { | 4418 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { |
4419 return FALSE; | 4419 return false; |
4420 } | 4420 } |
4421 } | 4421 } |
4422 } else { | 4422 } else { |
4423 if (!LoadAllFile(pHints)) { | 4423 if (!LoadAllFile(pHints)) { |
4424 return FALSE; | 4424 return false; |
4425 } | 4425 } |
4426 ((CPDF_Parser *)m_pDocument->GetParser())->RebuildCrossRef(); | 4426 ((CPDF_Parser *)m_pDocument->GetParser())->RebuildCrossRef(); |
4427 ResetFirstCheck(iPage); | 4427 ResetFirstCheck(iPage); |
4428 return TRUE; | 4428 return true; |
4429 } | 4429 } |
4430 } else { | 4430 } else { |
4431 if (!m_bTotalLoadPageTree) { | 4431 if (!m_bTotalLoadPageTree) { |
4432 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { | 4432 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { |
4433 return FALSE; | 4433 return false; |
4434 } | 4434 } |
4435 } | 4435 } |
4436 } | 4436 } |
4437 if (m_bHaveAcroForm && !m_bAcroFormLoad) { | 4437 if (m_bHaveAcroForm && !m_bAcroFormLoad) { |
4438 if (!CheckAcroFormSubObject(pHints)) { | 4438 if (!CheckAcroFormSubObject(pHints)) { |
4439 return FALSE; | 4439 return false; |
4440 } | 4440 } |
4441 m_bAcroFormLoad = TRUE; | 4441 m_bAcroFormLoad = true; |
4442 } | 4442 } |
4443 if (!m_bPageLoadedOK) { | 4443 if (!m_bPageLoadedOK) { |
4444 if (!m_objs_array.GetSize()) { | 4444 if (!m_objs_array.GetSize()) { |
4445 m_objs_array.RemoveAll(); | 4445 m_objs_array.RemoveAll(); |
4446 m_objnum_array.RemoveAll(); | 4446 m_objnum_array.RemoveAll(); |
4447 m_pPageDict = m_pDocument->GetPage(iPage); | 4447 m_pPageDict = m_pDocument->GetPage(iPage); |
4448 if (!m_pPageDict) { | 4448 if (!m_pPageDict) { |
4449 ResetFirstCheck(iPage); | 4449 ResetFirstCheck(iPage); |
4450 return TRUE; | 4450 return true; |
4451 } | 4451 } |
4452 CFX_PtrArray obj_array; | 4452 CFX_PtrArray obj_array; |
4453 obj_array.Add(m_pPageDict); | 4453 obj_array.Add(m_pPageDict); |
4454 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array)
; | 4454 bool bRet = IsObjectsAvail(obj_array, true, pHints, m_objs_array); |
4455 if (bRet) { | 4455 if (bRet) { |
4456 m_objs_array.RemoveAll(); | 4456 m_objs_array.RemoveAll(); |
4457 m_bPageLoadedOK = TRUE; | 4457 m_bPageLoadedOK = true; |
4458 } else { | 4458 } else { |
4459 return bRet; | 4459 return bRet; |
4460 } | 4460 } |
4461 } else { | 4461 } else { |
4462 CFX_PtrArray new_objs_array; | 4462 CFX_PtrArray new_objs_array; |
4463 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_
array); | 4463 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_arr
ay); |
4464 m_objs_array.RemoveAll(); | 4464 m_objs_array.RemoveAll(); |
4465 if (bRet) { | 4465 if (bRet) { |
4466 m_bPageLoadedOK = TRUE; | 4466 m_bPageLoadedOK = true; |
4467 } else { | 4467 } else { |
4468 m_objs_array.Append(new_objs_array); | 4468 m_objs_array.Append(new_objs_array); |
4469 return bRet; | 4469 return bRet; |
4470 } | 4470 } |
4471 } | 4471 } |
4472 } | 4472 } |
4473 if (m_bPageLoadedOK) { | 4473 if (m_bPageLoadedOK) { |
4474 if (!m_bAnnotsLoad) { | 4474 if (!m_bAnnotsLoad) { |
4475 if (!CheckPageAnnots(iPage, pHints)) { | 4475 if (!CheckPageAnnots(iPage, pHints)) { |
4476 return FALSE; | 4476 return false; |
4477 } | 4477 } |
4478 m_bAnnotsLoad = TRUE; | 4478 m_bAnnotsLoad = true; |
4479 } | 4479 } |
4480 } | 4480 } |
4481 if (m_pPageDict && !m_bNeedDownLoadResource) { | 4481 if (m_pPageDict && !m_bNeedDownLoadResource) { |
4482 m_pPageResource = m_pPageDict->GetElement("Resources"); | 4482 m_pPageResource = m_pPageDict->GetElement("Resources"); |
4483 if (!m_pPageResource) { | 4483 if (!m_pPageResource) { |
4484 m_bNeedDownLoadResource = HaveResourceAncestor(m_pPageDict); | 4484 m_bNeedDownLoadResource = HaveResourceAncestor(m_pPageDict); |
4485 } else { | 4485 } else { |
4486 m_bNeedDownLoadResource = TRUE; | 4486 m_bNeedDownLoadResource = true; |
4487 } | 4487 } |
4488 } | 4488 } |
4489 if (m_bNeedDownLoadResource) { | 4489 if (m_bNeedDownLoadResource) { |
4490 FX_BOOL bRet = CheckResources(pHints); | 4490 bool bRet = CheckResources(pHints); |
4491 if (!bRet) { | 4491 if (!bRet) { |
4492 return FALSE; | 4492 return false; |
4493 } | 4493 } |
4494 m_bNeedDownLoadResource = FALSE; | 4494 m_bNeedDownLoadResource = false; |
4495 } | 4495 } |
4496 m_bPageLoadedOK = FALSE; | 4496 m_bPageLoadedOK = false; |
4497 m_bAnnotsLoad = FALSE; | 4497 m_bAnnotsLoad = false; |
4498 m_bCurPageDictLoadOK = FALSE; | 4498 m_bCurPageDictLoadOK = false; |
4499 ResetFirstCheck(iPage); | 4499 ResetFirstCheck(iPage); |
4500 m_pagesLoadState->SetAt(iPage, TRUE); | 4500 m_pagesLoadState->SetAt(iPage, true); |
4501 return TRUE; | 4501 return true; |
4502 } | 4502 } |
4503 FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) | 4503 bool CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) |
4504 { | 4504 { |
4505 if (!m_objs_array.GetSize()) { | 4505 if (!m_objs_array.GetSize()) { |
4506 m_objs_array.RemoveAll(); | 4506 m_objs_array.RemoveAll(); |
4507 CFX_PtrArray obj_array; | 4507 CFX_PtrArray obj_array; |
4508 obj_array.Add(m_pPageResource); | 4508 obj_array.Add(m_pPageResource); |
4509 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); | 4509 bool bRet = IsObjectsAvail(obj_array, true, pHints, m_objs_array); |
4510 if (bRet) { | 4510 if (bRet) { |
4511 m_objs_array.RemoveAll(); | 4511 m_objs_array.RemoveAll(); |
4512 } | 4512 } |
4513 return bRet; | 4513 return bRet; |
4514 } | 4514 } |
4515 CFX_PtrArray new_objs_array; | 4515 CFX_PtrArray new_objs_array; |
4516 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 4516 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_array); |
4517 m_objs_array.RemoveAll(); | 4517 m_objs_array.RemoveAll(); |
4518 if (!bRet) { | 4518 if (!bRet) { |
4519 m_objs_array.Append(new_objs_array); | 4519 m_objs_array.Append(new_objs_array); |
4520 } | 4520 } |
4521 return bRet; | 4521 return bRet; |
4522 } | 4522 } |
4523 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSiz
e) | 4523 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSiz
e) |
4524 { | 4524 { |
4525 if (pPos) { | 4525 if (pPos) { |
4526 *pPos = m_dwLastXRefOffset; | 4526 *pPos = m_dwLastXRefOffset; |
(...skipping 15 matching lines...) Expand all Loading... |
4542 CPDF_Object *pAcroForm = pRoot->GetElement(FX_BSTRC("AcroForm")); | 4542 CPDF_Object *pAcroForm = pRoot->GetElement(FX_BSTRC("AcroForm")); |
4543 if (!pAcroForm) { | 4543 if (!pAcroForm) { |
4544 return PDFFORM_NOTEXIST; | 4544 return PDFFORM_NOTEXIST; |
4545 } | 4545 } |
4546 if (!CheckLinearizedData(pHints)) { | 4546 if (!CheckLinearizedData(pHints)) { |
4547 return PDFFORM_NOTAVAIL; | 4547 return PDFFORM_NOTAVAIL; |
4548 } | 4548 } |
4549 if (!m_objs_array.GetSize()) { | 4549 if (!m_objs_array.GetSize()) { |
4550 m_objs_array.Add(pAcroForm->GetDict()); | 4550 m_objs_array.Add(pAcroForm->GetDict()); |
4551 } | 4551 } |
4552 m_bLinearizedFormParamLoad = TRUE; | 4552 m_bLinearizedFormParamLoad = true; |
4553 } | 4553 } |
4554 CFX_PtrArray new_objs_array; | 4554 CFX_PtrArray new_objs_array; |
4555 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 4555 bool bRet = IsObjectsAvail(m_objs_array, false, pHints, new_objs_array); |
4556 m_objs_array.RemoveAll(); | 4556 m_objs_array.RemoveAll(); |
4557 if (!bRet) { | 4557 if (!bRet) { |
4558 m_objs_array.Append(new_objs_array); | 4558 m_objs_array.Append(new_objs_array); |
4559 return PDFFORM_NOTAVAIL; | 4559 return PDFFORM_NOTAVAIL; |
4560 } | 4560 } |
4561 return PDFFORM_AVAIL; | 4561 return PDFFORM_AVAIL; |
4562 } | 4562 } |
4563 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) | 4563 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) |
4564 { | 4564 { |
4565 int32_t iNext = 0; | 4565 int32_t iNext = 0; |
4566 if (BinarySearch(dwObjNum, iNext)) { | 4566 if (BinarySearch(dwObjNum, iNext)) { |
4567 return; | 4567 return; |
4568 } | 4568 } |
4569 m_number_array.InsertAt(iNext, dwObjNum); | 4569 m_number_array.InsertAt(iNext, dwObjNum); |
4570 } | 4570 } |
4571 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) | 4571 bool CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) |
4572 { | 4572 { |
4573 int32_t iNext = 0; | 4573 int32_t iNext = 0; |
4574 return BinarySearch(dwObjNum, iNext); | 4574 return BinarySearch(dwObjNum, iNext); |
4575 } | 4575 } |
4576 FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t &iNext) | 4576 bool CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t &iNext) |
4577 { | 4577 { |
4578 int32_t iLow = 0; | 4578 int32_t iLow = 0; |
4579 int32_t iHigh = m_number_array.GetSize() - 1; | 4579 int32_t iHigh = m_number_array.GetSize() - 1; |
4580 while (iLow <= iHigh) { | 4580 while (iLow <= iHigh) { |
4581 int32_t iMid = (iLow + iHigh) / 2; | 4581 int32_t iMid = (iLow + iHigh) / 2; |
4582 if (m_number_array.GetAt(iMid) == value) { | 4582 if (m_number_array.GetAt(iMid) == value) { |
4583 iNext = iMid; | 4583 iNext = iMid; |
4584 return TRUE; | 4584 return true; |
4585 } | 4585 } |
4586 if (m_number_array.GetAt(iMid) > value) { | 4586 if (m_number_array.GetAt(iMid) > value) { |
4587 iHigh = iMid - 1; | 4587 iHigh = iMid - 1; |
4588 } else if (m_number_array.GetAt(iMid) < value) { | 4588 } else if (m_number_array.GetAt(iMid) < value) { |
4589 iLow = iMid + 1; | 4589 iLow = iMid + 1; |
4590 } | 4590 } |
4591 } | 4591 } |
4592 iNext = iLow; | 4592 iNext = iLow; |
4593 return FALSE; | 4593 return false; |
4594 } | 4594 } |
4595 CPDF_PageNode::~CPDF_PageNode() | 4595 CPDF_PageNode::~CPDF_PageNode() |
4596 { | 4596 { |
4597 int32_t iSize = m_childNode.GetSize(); | 4597 int32_t iSize = m_childNode.GetSize(); |
4598 for (int32_t i = 0; i < iSize; ++i) { | 4598 for (int32_t i = 0; i < iSize; ++i) { |
4599 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4599 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; |
4600 delete pNode; | 4600 delete pNode; |
4601 } | 4601 } |
4602 m_childNode.RemoveAll(); | 4602 m_childNode.RemoveAll(); |
4603 } | 4603 } |
OLD | NEW |