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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #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 FX_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 FX_INT32 _CompareDWord(const void* p1, const void* p2) 30 static int32_t _CompareDWord(const void* p1, const void* p2)
31 { 31 {
32 return (*(FX_DWORD*)p1) - (*(FX_DWORD*)p2); 32 return (*(FX_DWORD*)p1) - (*(FX_DWORD*)p2);
33 } 33 }
34 static int _CompareFileSize(const void* p1, const void* p2) 34 static int _CompareFileSize(const void* p1, const void* p2)
35 { 35 {
36 FX_FILESIZE ret = (*(FX_FILESIZE*)p1) - (*(FX_FILESIZE*)p2); 36 FX_FILESIZE ret = (*(FX_FILESIZE*)p1) - (*(FX_FILESIZE*)p2);
37 if (ret > 0) { 37 if (ret > 0) {
38 return 1; 38 return 1;
39 } 39 }
40 if (ret < 0) { 40 if (ret < 0) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 FX_LPVOID objnum; 91 FX_LPVOID objnum;
92 CPDF_StreamAcc* pStream; 92 CPDF_StreamAcc* pStream;
93 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); 93 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream);
94 delete pStream; 94 delete pStream;
95 } 95 }
96 m_ObjectStreamMap.RemoveAll(); 96 m_ObjectStreamMap.RemoveAll();
97 m_SortedOffset.RemoveAll(); 97 m_SortedOffset.RemoveAll();
98 m_CrossRef.RemoveAll(); 98 m_CrossRef.RemoveAll();
99 m_V5Type.RemoveAll(); 99 m_V5Type.RemoveAll();
100 m_ObjVersion.RemoveAll(); 100 m_ObjVersion.RemoveAll();
101 FX_INT32 iLen = m_Trailers.GetSize(); 101 int32_t iLen = m_Trailers.GetSize();
102 for (FX_INT32 i = 0; i < iLen; ++i) { 102 for (int32_t i = 0; i < iLen; ++i) {
103 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) 103 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i))
104 trailer->Release(); 104 trailer->Release();
105 } 105 }
106 m_Trailers.RemoveAll(); 106 m_Trailers.RemoveAll();
107 if (m_pLinearized) { 107 if (m_pLinearized) {
108 m_pLinearized->Release(); 108 m_pLinearized->Release();
109 m_pLinearized = NULL; 109 m_pLinearized = NULL;
110 } 110 }
111 } 111 }
112 static FX_INT32 GetHeaderOffset(IFX_FileRead* pFile) 112 static int32_t GetHeaderOffset(IFX_FileRead* pFile)
113 { 113 {
114 FX_DWORD tag = FXDWORD_FROM_LSBFIRST(0x46445025); 114 FX_DWORD tag = FXDWORD_FROM_LSBFIRST(0x46445025);
115 FX_BYTE buf[4]; 115 uint8_t buf[4];
116 FX_INT32 offset = 0; 116 int32_t offset = 0;
117 while (1) { 117 while (1) {
118 if (!pFile->ReadBlock(buf, offset, 4)) { 118 if (!pFile->ReadBlock(buf, offset, 4)) {
119 return -1; 119 return -1;
120 } 120 }
121 if (*(FX_DWORD*)buf == tag) { 121 if (*(FX_DWORD*)buf == tag) {
122 return offset; 122 return offset;
123 } 123 }
124 offset ++; 124 offset ++;
125 if (offset > 1024) { 125 if (offset > 1024) {
126 return -1; 126 return -1;
(...skipping 18 matching lines...) Expand all
145 return StartParse(pFileAccess, bReParse); 145 return StartParse(pFileAccess, bReParse);
146 } 146 }
147 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); 147 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler();
148 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*); 148 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*);
149 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, FX_BOOL bReParse, FX _BOOL bOwnFileRead) 149 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, FX_BOOL bReParse, FX _BOOL bOwnFileRead)
150 { 150 {
151 CloseParser(bReParse); 151 CloseParser(bReParse);
152 m_bXRefStream = FALSE; 152 m_bXRefStream = FALSE;
153 m_LastXRefOffset = 0; 153 m_LastXRefOffset = 0;
154 m_bOwnFileRead = bOwnFileRead; 154 m_bOwnFileRead = bOwnFileRead;
155 FX_INT32 offset = GetHeaderOffset(pFileAccess); 155 int32_t offset = GetHeaderOffset(pFileAccess);
156 if (offset == -1) { 156 if (offset == -1) {
157 if (bOwnFileRead && pFileAccess) { 157 if (bOwnFileRead && pFileAccess) {
158 pFileAccess->Release(); 158 pFileAccess->Release();
159 } 159 }
160 return PDFPARSE_ERROR_FORMAT; 160 return PDFPARSE_ERROR_FORMAT;
161 } 161 }
162 m_Syntax.InitParser(pFileAccess, offset); 162 m_Syntax.InitParser(pFileAccess, offset);
163 FX_BYTE ch; 163 uint8_t ch;
164 if (!m_Syntax.GetCharAt(5, ch)) { 164 if (!m_Syntax.GetCharAt(5, ch)) {
165 return PDFPARSE_ERROR_FORMAT; 165 return PDFPARSE_ERROR_FORMAT;
166 } 166 }
167 if (ch >= '0' && ch <= '9') { 167 if (ch >= '0' && ch <= '9') {
168 m_FileVersion = (ch - '0') * 10; 168 m_FileVersion = (ch - '0') * 10;
169 } 169 }
170 if (!m_Syntax.GetCharAt(7, ch)) { 170 if (!m_Syntax.GetCharAt(7, ch)) {
171 return PDFPARSE_ERROR_FORMAT; 171 return PDFPARSE_ERROR_FORMAT;
172 } 172 }
173 if (ch >= '0' && ch <= '9') { 173 if (ch >= '0' && ch <= '9') {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 324 }
325 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum) 325 FX_FILESIZE CPDF_Parser::GetObjectOffset(FX_DWORD objnum)
326 { 326 {
327 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { 327 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) {
328 return 0; 328 return 0;
329 } 329 }
330 if (m_V5Type[objnum] == 1) { 330 if (m_V5Type[objnum] == 1) {
331 return m_CrossRef[objnum]; 331 return m_CrossRef[objnum];
332 } 332 }
333 if (m_V5Type[objnum] == 2) { 333 if (m_V5Type[objnum] == 2) {
334 return m_CrossRef[(FX_INT32)m_CrossRef[objnum]]; 334 return m_CrossRef[(int32_t)m_CrossRef[objnum]];
335 } 335 }
336 return 0; 336 return 0;
337 } 337 }
338 static FX_INT32 GetDirectInteger(CPDF_Dictionary* pDict, FX_BSTR key) 338 static int32_t GetDirectInteger(CPDF_Dictionary* pDict, FX_BSTR key)
339 { 339 {
340 CPDF_Object* pObj = pDict->GetElement(key); 340 CPDF_Object* pObj = pDict->GetElement(key);
341 if (pObj == NULL) { 341 if (pObj == NULL) {
342 return 0; 342 return 0;
343 } 343 }
344 if (pObj->GetType() == PDFOBJ_NUMBER) { 344 if (pObj->GetType() == PDFOBJ_NUMBER) {
345 return ((CPDF_Number*)pObj)->GetInteger(); 345 return ((CPDF_Number*)pObj)->GetInteger();
346 } 346 }
347 return 0; 347 return 0;
348 } 348 }
349 static FX_BOOL CheckDirectType(CPDF_Dictionary* pDict, FX_BSTR key, FX_INT32 iTy pe) 349 static FX_BOOL CheckDirectType(CPDF_Dictionary* pDict, FX_BSTR key, int32_t iTyp e)
350 { 350 {
351 CPDF_Object* pObj = pDict->GetElement(key); 351 CPDF_Object* pObj = pDict->GetElement(key);
352 if (!pObj) { 352 if (!pObj) {
353 return TRUE; 353 return TRUE;
354 } 354 }
355 return pObj->GetType() == iType; 355 return pObj->GetType() == iType;
356 } 356 }
357 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos) 357 FX_BOOL CPDF_Parser::LoadAllCrossRefV4(FX_FILESIZE xrefpos)
358 { 358 {
359 if (!LoadCrossRefV4(xrefpos, 0, TRUE, FALSE)) { 359 if (!LoadCrossRefV4(xrefpos, 0, TRUE, FALSE)) {
360 return FALSE; 360 return FALSE;
361 } 361 }
362 m_pTrailer = LoadTrailerV4(); 362 m_pTrailer = LoadTrailerV4();
363 if (m_pTrailer == NULL) { 363 if (m_pTrailer == NULL) {
364 return FALSE; 364 return FALSE;
365 } 365 }
366 FX_INT32 xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size")); 366 int32_t xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size"));
367 if (xrefsize <= 0 || xrefsize > (1 << 20)) { 367 if (xrefsize <= 0 || xrefsize > (1 << 20)) {
368 return FALSE; 368 return FALSE;
369 } 369 }
370 m_CrossRef.SetSize(xrefsize); 370 m_CrossRef.SetSize(xrefsize);
371 m_V5Type.SetSize(xrefsize); 371 m_V5Type.SetSize(xrefsize);
372 CFX_FileSizeArray CrossRefList, XRefStreamList; 372 CFX_FileSizeArray CrossRefList, XRefStreamList;
373 CrossRefList.Add(xrefpos); 373 CrossRefList.Add(xrefpos);
374 XRefStreamList.Add(GetDirectInteger(m_pTrailer, FX_BSTRC("XRefStm"))); 374 XRefStreamList.Add(GetDirectInteger(m_pTrailer, FX_BSTRC("XRefStm")));
375 if (!CheckDirectType(m_pTrailer, FX_BSTRC("Prev"), PDFOBJ_NUMBER)) { 375 if (!CheckDirectType(m_pTrailer, FX_BSTRC("Prev"), PDFOBJ_NUMBER)) {
376 return FALSE; 376 return FALSE;
(...skipping 16 matching lines...) Expand all
393 } 393 }
394 newxrefpos = GetDirectInteger(pDict, FX_BSTRC("Prev")); 394 newxrefpos = GetDirectInteger(pDict, FX_BSTRC("Prev"));
395 if (newxrefpos == xrefpos) { 395 if (newxrefpos == xrefpos) {
396 pDict->Release(); 396 pDict->Release();
397 return FALSE; 397 return FALSE;
398 } 398 }
399 xrefpos = newxrefpos; 399 xrefpos = newxrefpos;
400 XRefStreamList.InsertAt(0, pDict->GetInteger(FX_BSTRC("XRefStm"))); 400 XRefStreamList.InsertAt(0, pDict->GetInteger(FX_BSTRC("XRefStm")));
401 m_Trailers.Add(pDict); 401 m_Trailers.Add(pDict);
402 } 402 }
403 for (FX_INT32 i = 0; i < CrossRefList.GetSize(); i ++) 403 for (int32_t i = 0; i < CrossRefList.GetSize(); i ++)
404 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0)) { 404 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0)) {
405 return FALSE; 405 return FALSE;
406 } 406 }
407 return TRUE; 407 return TRUE;
408 } 408 }
409 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, FX_DWORD d wObjCount) 409 FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV4(FX_FILESIZE xrefpos, FX_DWORD d wObjCount)
410 { 410 {
411 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) { 411 if (!LoadLinearizedCrossRefV4(xrefpos, dwObjCount)) {
412 return FALSE; 412 return FALSE;
413 } 413 }
414 m_pTrailer = LoadTrailerV4(); 414 m_pTrailer = LoadTrailerV4();
415 if (m_pTrailer == NULL) { 415 if (m_pTrailer == NULL) {
416 return FALSE; 416 return FALSE;
417 } 417 }
418 FX_INT32 xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size")); 418 int32_t xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size"));
419 if (xrefsize == 0) { 419 if (xrefsize == 0) {
420 return FALSE; 420 return FALSE;
421 } 421 }
422 CFX_FileSizeArray CrossRefList, XRefStreamList; 422 CFX_FileSizeArray CrossRefList, XRefStreamList;
423 CrossRefList.Add(xrefpos); 423 CrossRefList.Add(xrefpos);
424 XRefStreamList.Add(GetDirectInteger(m_pTrailer, FX_BSTRC("XRefStm"))); 424 XRefStreamList.Add(GetDirectInteger(m_pTrailer, FX_BSTRC("XRefStm")));
425 xrefpos = GetDirectInteger(m_pTrailer, FX_BSTRC("Prev")); 425 xrefpos = GetDirectInteger(m_pTrailer, FX_BSTRC("Prev"));
426 while (xrefpos) { 426 while (xrefpos) {
427 CrossRefList.InsertAt(0, xrefpos); 427 CrossRefList.InsertAt(0, xrefpos);
428 LoadCrossRefV4(xrefpos, 0, TRUE, FALSE); 428 LoadCrossRefV4(xrefpos, 0, TRUE, FALSE);
429 CPDF_Dictionary* pDict = LoadTrailerV4(); 429 CPDF_Dictionary* pDict = LoadTrailerV4();
430 if (pDict == NULL) { 430 if (pDict == NULL) {
431 return FALSE; 431 return FALSE;
432 } 432 }
433 xrefpos = GetDirectInteger(pDict, FX_BSTRC("Prev")); 433 xrefpos = GetDirectInteger(pDict, FX_BSTRC("Prev"));
434 XRefStreamList.InsertAt(0, pDict->GetInteger(FX_BSTRC("XRefStm"))); 434 XRefStreamList.InsertAt(0, pDict->GetInteger(FX_BSTRC("XRefStm")));
435 m_Trailers.Add(pDict); 435 m_Trailers.Add(pDict);
436 } 436 }
437 for (FX_INT32 i = 1; i < CrossRefList.GetSize(); i ++) 437 for (int32_t i = 1; i < CrossRefList.GetSize(); i ++)
438 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0)) { 438 if (!LoadCrossRefV4(CrossRefList[i], XRefStreamList[i], FALSE, i == 0)) {
439 return FALSE; 439 return FALSE;
440 } 440 }
441 return TRUE; 441 return TRUE;
442 } 442 }
443 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCou nt) 443 FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCou nt)
444 { 444 {
445 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset; 445 FX_FILESIZE dwStartPos = pos - m_Syntax.m_HeaderOffset;
446 m_Syntax.RestorePos(dwStartPos); 446 m_Syntax.RestorePos(dwStartPos);
447 FX_LPVOID pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOf fset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); 447 FX_LPVOID pResult = FXSYS_bsearch(&pos, m_SortedOffset.GetData(), m_SortedOf fset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize);
448 if (pResult == NULL) { 448 if (pResult == NULL) {
449 m_SortedOffset.Add(pos); 449 m_SortedOffset.Add(pos);
450 } 450 }
451 FX_DWORD start_objnum = 0; 451 FX_DWORD start_objnum = 0;
452 FX_DWORD count = dwObjCount; 452 FX_DWORD count = dwObjCount;
453 FX_FILESIZE SavedPos = m_Syntax.SavePos(); 453 FX_FILESIZE SavedPos = m_Syntax.SavePos();
454 FX_INT32 recordsize = 20; 454 int32_t recordsize = 20;
455 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1); 455 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1);
456 pBuf[1024 * recordsize] = '\0'; 456 pBuf[1024 * recordsize] = '\0';
457 FX_INT32 nBlocks = count / 1024 + 1; 457 int32_t nBlocks = count / 1024 + 1;
458 for (FX_INT32 block = 0; block < nBlocks; block ++) { 458 for (int32_t block = 0; block < nBlocks; block ++) {
459 FX_INT32 block_size = block == nBlocks - 1 ? count % 1024 : 1024; 459 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024;
460 FX_DWORD dwReadSize = block_size * recordsize; 460 FX_DWORD dwReadSize = block_size * recordsize;
461 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) { 461 if ((FX_FILESIZE)(dwStartPos + dwReadSize) > m_Syntax.m_FileLen) {
462 FX_Free(pBuf); 462 FX_Free(pBuf);
463 return FALSE; 463 return FALSE;
464 } 464 }
465 if (!m_Syntax.ReadBlock((FX_LPBYTE)pBuf, dwReadSize)) { 465 if (!m_Syntax.ReadBlock((FX_LPBYTE)pBuf, dwReadSize)) {
466 FX_Free(pBuf); 466 FX_Free(pBuf);
467 return FALSE; 467 return FALSE;
468 } 468 }
469 for (FX_INT32 i = 0; i < block_size; i ++) { 469 for (int32_t i = 0; i < block_size; i ++) {
470 FX_DWORD objnum = start_objnum + block * 1024 + i; 470 FX_DWORD objnum = start_objnum + block * 1024 + i;
471 char* pEntry = pBuf + i * recordsize; 471 char* pEntry = pBuf + i * recordsize;
472 if (pEntry[17] == 'f') { 472 if (pEntry[17] == 'f') {
473 m_CrossRef.SetAtGrow(objnum, 0); 473 m_CrossRef.SetAtGrow(objnum, 0);
474 m_V5Type.SetAtGrow(objnum, 0); 474 m_V5Type.SetAtGrow(objnum, 0);
475 } else { 475 } else {
476 FX_INT32 offset = FXSYS_atoi(pEntry); 476 int32_t offset = FXSYS_atoi(pEntry);
477 if (offset == 0) { 477 if (offset == 0) {
478 for (FX_INT32 c = 0; c < 10; c ++) { 478 for (int32_t c = 0; c < 10; c ++) {
479 if (pEntry[c] < '0' || pEntry[c] > '9') { 479 if (pEntry[c] < '0' || pEntry[c] > '9') {
480 FX_Free(pBuf); 480 FX_Free(pBuf);
481 return FALSE; 481 return FALSE;
482 } 482 }
483 } 483 }
484 } 484 }
485 m_CrossRef.SetAtGrow(objnum, offset); 485 m_CrossRef.SetAtGrow(objnum, offset);
486 FX_INT32 version = FXSYS_atoi(pEntry + 11); 486 int32_t version = FXSYS_atoi(pEntry + 11);
487 if (version >= 1) { 487 if (version >= 1) {
488 m_bVersionUpdated = TRUE; 488 m_bVersionUpdated = TRUE;
489 } 489 }
490 m_ObjVersion.SetAtGrow(objnum, version); 490 m_ObjVersion.SetAtGrow(objnum, version);
491 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { 491 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) {
492 FX_LPVOID pResult = FXSYS_bsearch(&m_CrossRef[objnum], m_Sor tedOffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFile Size); 492 FX_LPVOID pResult = FXSYS_bsearch(&m_CrossRef[objnum], m_Sor tedOffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFile Size);
493 if (pResult == NULL) { 493 if (pResult == NULL) {
494 m_SortedOffset.Add(m_CrossRef[objnum]); 494 m_SortedOffset.Add(m_CrossRef[objnum]);
495 } 495 }
496 } 496 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 break; 530 break;
531 } 531 }
532 FX_DWORD start_objnum = FXSYS_atoi(word); 532 FX_DWORD start_objnum = FXSYS_atoi(word);
533 if (start_objnum >= (1 << 20)) { 533 if (start_objnum >= (1 << 20)) {
534 return FALSE; 534 return FALSE;
535 } 535 }
536 FX_DWORD count = m_Syntax.GetDirectNum(); 536 FX_DWORD count = m_Syntax.GetDirectNum();
537 m_Syntax.ToNextWord(); 537 m_Syntax.ToNextWord();
538 SavedPos = m_Syntax.SavePos(); 538 SavedPos = m_Syntax.SavePos();
539 FX_BOOL bFirstItem = FALSE; 539 FX_BOOL bFirstItem = FALSE;
540 FX_INT32 recordsize = 20; 540 int32_t recordsize = 20;
541 if (bFirst) { 541 if (bFirst) {
542 bFirstItem = TRUE; 542 bFirstItem = TRUE;
543 } 543 }
544 m_dwXrefStartObjNum = start_objnum; 544 m_dwXrefStartObjNum = start_objnum;
545 if (!bSkip) { 545 if (!bSkip) {
546 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1); 546 char* pBuf = FX_Alloc(char, 1024 * recordsize + 1);
547 pBuf[1024 * recordsize] = '\0'; 547 pBuf[1024 * recordsize] = '\0';
548 FX_INT32 nBlocks = count / 1024 + 1; 548 int32_t nBlocks = count / 1024 + 1;
549 FX_BOOL bFirstBlock = TRUE; 549 FX_BOOL bFirstBlock = TRUE;
550 for (FX_INT32 block = 0; block < nBlocks; block ++) { 550 for (int32_t block = 0; block < nBlocks; block ++) {
551 FX_INT32 block_size = block == nBlocks - 1 ? count % 1024 : 1024 ; 551 int32_t block_size = block == nBlocks - 1 ? count % 1024 : 1024;
552 m_Syntax.ReadBlock((FX_LPBYTE)pBuf, block_size * recordsize); 552 m_Syntax.ReadBlock((FX_LPBYTE)pBuf, block_size * recordsize);
553 for (FX_INT32 i = 0; i < block_size; i ++) { 553 for (int32_t i = 0; i < block_size; i ++) {
554 FX_DWORD objnum = start_objnum + block * 1024 + i; 554 FX_DWORD objnum = start_objnum + block * 1024 + i;
555 char* pEntry = pBuf + i * recordsize; 555 char* pEntry = pBuf + i * recordsize;
556 if (pEntry[17] == 'f') { 556 if (pEntry[17] == 'f') {
557 if (bFirstItem) { 557 if (bFirstItem) {
558 objnum = 0; 558 objnum = 0;
559 bFirstItem = FALSE; 559 bFirstItem = FALSE;
560 } 560 }
561 if (bFirstBlock) { 561 if (bFirstBlock) {
562 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntr y); 562 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntr y);
563 FX_INT32 version = FXSYS_atoi(pEntry + 11); 563 int32_t version = FXSYS_atoi(pEntry + 11);
564 if (offset == 0 && version == 65535 && start_objnum != 0) { 564 if (offset == 0 && version == 65535 && start_objnum != 0) {
565 start_objnum--; 565 start_objnum--;
566 objnum = 0; 566 objnum = 0;
567 } 567 }
568 } 568 }
569 m_CrossRef.SetAtGrow(objnum, 0); 569 m_CrossRef.SetAtGrow(objnum, 0);
570 m_V5Type.SetAtGrow(objnum, 0); 570 m_V5Type.SetAtGrow(objnum, 0);
571 } else { 571 } else {
572 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); 572 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry);
573 if (offset == 0) { 573 if (offset == 0) {
574 for (FX_INT32 c = 0; c < 10; c ++) { 574 for (int32_t c = 0; c < 10; c ++) {
575 if (pEntry[c] < '0' || pEntry[c] > '9') { 575 if (pEntry[c] < '0' || pEntry[c] > '9') {
576 FX_Free(pBuf); 576 FX_Free(pBuf);
577 return FALSE; 577 return FALSE;
578 } 578 }
579 } 579 }
580 } 580 }
581 m_CrossRef.SetAtGrow(objnum, offset); 581 m_CrossRef.SetAtGrow(objnum, offset);
582 FX_INT32 version = FXSYS_atoi(pEntry + 11); 582 int32_t version = FXSYS_atoi(pEntry + 11);
583 if (version >= 1) { 583 if (version >= 1) {
584 m_bVersionUpdated = TRUE; 584 m_bVersionUpdated = TRUE;
585 } 585 }
586 m_ObjVersion.SetAtGrow(objnum, version); 586 m_ObjVersion.SetAtGrow(objnum, version);
587 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { 587 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) {
588 FX_LPVOID pResult = FXSYS_bsearch(&m_CrossRef[objnum ], m_SortedOffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _Com pareFileSize); 588 FX_LPVOID pResult = FXSYS_bsearch(&m_CrossRef[objnum ], m_SortedOffset.GetData(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _Com pareFileSize);
589 if (pResult == NULL) { 589 if (pResult == NULL) {
590 m_SortedOffset.Add(m_CrossRef[objnum]); 590 m_SortedOffset.Add(m_CrossRef[objnum]);
591 } 591 }
592 } 592 }
(...skipping 30 matching lines...) Expand all
623 FX_BOOL CPDF_Parser::RebuildCrossRef() 623 FX_BOOL CPDF_Parser::RebuildCrossRef()
624 { 624 {
625 m_CrossRef.RemoveAll(); 625 m_CrossRef.RemoveAll();
626 m_V5Type.RemoveAll(); 626 m_V5Type.RemoveAll();
627 m_SortedOffset.RemoveAll(); 627 m_SortedOffset.RemoveAll();
628 m_ObjVersion.RemoveAll(); 628 m_ObjVersion.RemoveAll();
629 if (m_pTrailer) { 629 if (m_pTrailer) {
630 m_pTrailer->Release(); 630 m_pTrailer->Release();
631 m_pTrailer = NULL; 631 m_pTrailer = NULL;
632 } 632 }
633 FX_INT32 status = 0; 633 int32_t status = 0;
634 FX_INT32 inside_index = 0; 634 int32_t inside_index = 0;
635 FX_DWORD objnum = 0, gennum = 0; 635 FX_DWORD objnum = 0, gennum = 0;
636 FX_INT32 depth = 0; 636 int32_t depth = 0;
637 FX_LPBYTE buffer = FX_Alloc(FX_BYTE, 4096); 637 FX_LPBYTE buffer = FX_Alloc(uint8_t, 4096);
638 FX_FILESIZE pos = m_Syntax.m_HeaderOffset; 638 FX_FILESIZE pos = m_Syntax.m_HeaderOffset;
639 FX_FILESIZE start_pos = 0, start_pos1 = 0; 639 FX_FILESIZE start_pos = 0, start_pos1 = 0;
640 FX_FILESIZE last_obj = -1, last_xref = -1, last_trailer = -1; 640 FX_FILESIZE last_obj = -1, last_xref = -1, last_trailer = -1;
641 while (pos < m_Syntax.m_FileLen) { 641 while (pos < m_Syntax.m_FileLen) {
642 FX_BOOL bOverFlow = FALSE; 642 FX_BOOL bOverFlow = FALSE;
643 FX_DWORD size = (FX_DWORD)(m_Syntax.m_FileLen - pos); 643 FX_DWORD size = (FX_DWORD)(m_Syntax.m_FileLen - pos);
644 if (size > 4096) { 644 if (size > 4096) {
645 size = 4096; 645 size = 4096;
646 } 646 }
647 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) { 647 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) {
648 break; 648 break;
649 } 649 }
650 for (FX_DWORD i = 0; i < size; i ++) { 650 for (FX_DWORD i = 0; i < size; i ++) {
651 FX_BYTE byte = buffer[i]; 651 uint8_t byte = buffer[i];
652 switch (status) { 652 switch (status) {
653 case 0: 653 case 0:
654 if (PDF_CharType[byte] == 'W') { 654 if (PDF_CharType[byte] == 'W') {
655 status = 1; 655 status = 1;
656 } 656 }
657 if (byte <= '9' && byte >= '0') { 657 if (byte <= '9' && byte >= '0') {
658 --i; 658 --i;
659 status = 1; 659 status = 1;
660 } 660 }
661 if (byte == '%') { 661 if (byte == '%') {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 } else { 815 } else {
816 offset += 3; 816 offset += 3;
817 } 817 }
818 FX_FILESIZE nLen = obj_end - obj_pos - offset; 818 FX_FILESIZE nLen = obj_end - obj_pos - offset;
819 if ((FX_DWORD)nLen > size - i) { 819 if ((FX_DWORD)nLen > size - i) {
820 pos = obj_end + m_Syntax.m_HeaderOffset; 820 pos = obj_end + m_Syntax.m_HeaderOffset;
821 bOverFlow = TRUE; 821 bOverFlow = TRUE;
822 } else { 822 } else {
823 i += (FX_DWORD)nLen; 823 i += (FX_DWORD)nLen;
824 } 824 }
825 if (m_CrossRef.GetSize() > (FX_INT32)objnum && m _CrossRef[objnum]) { 825 if (m_CrossRef.GetSize() > (int32_t)objnum && m_ CrossRef[objnum]) {
826 if (pObject) { 826 if (pObject) {
827 FX_DWORD oldgen = m_ObjVersion.GetAt(obj num); 827 FX_DWORD oldgen = m_ObjVersion.GetAt(obj num);
828 m_CrossRef[objnum] = obj_pos; 828 m_CrossRef[objnum] = obj_pos;
829 m_ObjVersion.SetAt(objnum, (FX_SHORT)gen num); 829 m_ObjVersion.SetAt(objnum, (int16_t)genn um);
830 if (oldgen != gennum) { 830 if (oldgen != gennum) {
831 m_bVersionUpdated = TRUE; 831 m_bVersionUpdated = TRUE;
832 } 832 }
833 } 833 }
834 } else { 834 } else {
835 m_CrossRef.SetAtGrow(objnum, obj_pos); 835 m_CrossRef.SetAtGrow(objnum, obj_pos);
836 m_V5Type.SetAtGrow(objnum, 1); 836 m_V5Type.SetAtGrow(objnum, 1);
837 m_ObjVersion.SetAtGrow(objnum, (FX_SHORT)gen num); 837 m_ObjVersion.SetAtGrow(objnum, (int16_t)genn um);
838 } 838 }
839 if (pObject) { 839 if (pObject) {
840 pObject->Release(); 840 pObject->Release();
841 } 841 }
842 } 842 }
843 --i; 843 --i;
844 status = 0; 844 status = 0;
845 break; 845 break;
846 } 846 }
847 break; 847 break;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 last_trailer = m_Syntax.m_FileLen; 983 last_trailer = m_Syntax.m_FileLen;
984 } 984 }
985 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset; 985 FX_FILESIZE offset = last_trailer - m_Syntax.m_HeaderOffset;
986 FX_LPVOID pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_Sorte dOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); 986 FX_LPVOID pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_Sorte dOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize);
987 if (pResult == NULL) { 987 if (pResult == NULL) {
988 m_SortedOffset.Add(offset); 988 m_SortedOffset.Add(offset);
989 } 989 }
990 FX_Free(buffer); 990 FX_Free(buffer);
991 return TRUE; 991 return TRUE;
992 } 992 }
993 static FX_DWORD _GetVarInt(FX_LPCBYTE p, FX_INT32 n) 993 static FX_DWORD _GetVarInt(FX_LPCBYTE p, int32_t n)
994 { 994 {
995 FX_DWORD result = 0; 995 FX_DWORD result = 0;
996 for (FX_INT32 i = 0; i < n; i ++) { 996 for (int32_t i = 0; i < n; i ++) {
997 result = result * 256 + p[i]; 997 result = result * 256 + p[i];
998 } 998 }
999 return result; 999 return result;
1000 } 1000 }
1001 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL bMainXRef) 1001 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL bMainXRef)
1002 { 1002 {
1003 CPDF_Stream* pStream = (CPDF_Stream*)ParseIndirectObjectAt(m_pDocument, pos, 0, NULL); 1003 CPDF_Stream* pStream = (CPDF_Stream*)ParseIndirectObjectAt(m_pDocument, pos, 0, NULL);
1004 if (!pStream) { 1004 if (!pStream) {
1005 return FALSE; 1005 return FALSE;
1006 } 1006 }
1007 if (m_pDocument) { 1007 if (m_pDocument) {
1008 CPDF_Dictionary * pDict = m_pDocument->GetRoot(); 1008 CPDF_Dictionary * pDict = m_pDocument->GetRoot();
1009 if (!pDict || pDict->GetObjNum() != pStream->m_ObjNum) { 1009 if (!pDict || pDict->GetObjNum() != pStream->m_ObjNum) {
1010 m_pDocument->InsertIndirectObject(pStream->m_ObjNum, pStream); 1010 m_pDocument->InsertIndirectObject(pStream->m_ObjNum, pStream);
1011 } else { 1011 } else {
1012 if (pStream->GetType() == PDFOBJ_STREAM) { 1012 if (pStream->GetType() == PDFOBJ_STREAM) {
1013 pStream->Release(); 1013 pStream->Release();
1014 } 1014 }
1015 return FALSE; 1015 return FALSE;
1016 } 1016 }
1017 } 1017 }
1018 if (pStream->GetType() != PDFOBJ_STREAM) { 1018 if (pStream->GetType() != PDFOBJ_STREAM) {
1019 return FALSE; 1019 return FALSE;
1020 } 1020 }
1021 prev = pStream->GetDict()->GetInteger(FX_BSTRC("Prev")); 1021 prev = pStream->GetDict()->GetInteger(FX_BSTRC("Prev"));
1022 FX_INT32 size = pStream->GetDict()->GetInteger(FX_BSTRC("Size")); 1022 int32_t size = pStream->GetDict()->GetInteger(FX_BSTRC("Size"));
1023 if (size < 0) { 1023 if (size < 0) {
1024 pStream->Release(); 1024 pStream->Release();
1025 return FALSE; 1025 return FALSE;
1026 } 1026 }
1027 if (bMainXRef) { 1027 if (bMainXRef) {
1028 m_pTrailer = (CPDF_Dictionary*)pStream->GetDict()->Clone(); 1028 m_pTrailer = (CPDF_Dictionary*)pStream->GetDict()->Clone();
1029 m_CrossRef.SetSize(size); 1029 m_CrossRef.SetSize(size);
1030 if (m_V5Type.SetSize(size)) { 1030 if (m_V5Type.SetSize(size)) {
1031 FXSYS_memset32(m_V5Type.GetData(), 0, size); 1031 FXSYS_memset32(m_V5Type.GetData(), 0, size);
1032 } 1032 }
1033 } else { 1033 } else {
1034 m_Trailers.Add((CPDF_Dictionary*)pStream->GetDict()->Clone()); 1034 m_Trailers.Add((CPDF_Dictionary*)pStream->GetDict()->Clone());
1035 } 1035 }
1036 std::vector<std::pair<FX_INT32, FX_INT32> > arrIndex; 1036 std::vector<std::pair<int32_t, int32_t> > arrIndex;
1037 CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index")); 1037 CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index"));
1038 if (pArray) { 1038 if (pArray) {
1039 FX_DWORD nPairSize = pArray->GetCount() / 2; 1039 FX_DWORD nPairSize = pArray->GetCount() / 2;
1040 for (FX_DWORD i = 0; i < nPairSize; i++) { 1040 for (FX_DWORD i = 0; i < nPairSize; i++) {
1041 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2); 1041 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2);
1042 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1); 1042 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1);
1043 if (pStartNumObj && pStartNumObj->GetType() == PDFOBJ_NUMBER 1043 if (pStartNumObj && pStartNumObj->GetType() == PDFOBJ_NUMBER
1044 && pCountObj && pCountObj->GetType() == PDFOBJ_NUMBER) { 1044 && pCountObj && pCountObj->GetType() == PDFOBJ_NUMBER) {
1045 int nStartNum = pStartNumObj->GetInteger(); 1045 int nStartNum = pStartNumObj->GetInteger();
1046 int nCount = pCountObj->GetInteger(); 1046 int nCount = pCountObj->GetInteger();
(...skipping 21 matching lines...) Expand all
1068 pStream->Release(); 1068 pStream->Release();
1069 return FALSE; 1069 return FALSE;
1070 } 1070 }
1071 FX_DWORD totalWidth = dwAccWidth.ValueOrDie(); 1071 FX_DWORD totalWidth = dwAccWidth.ValueOrDie();
1072 CPDF_StreamAcc acc; 1072 CPDF_StreamAcc acc;
1073 acc.LoadAllData(pStream); 1073 acc.LoadAllData(pStream);
1074 FX_LPCBYTE pData = acc.GetData(); 1074 FX_LPCBYTE pData = acc.GetData();
1075 FX_DWORD dwTotalSize = acc.GetSize(); 1075 FX_DWORD dwTotalSize = acc.GetSize();
1076 FX_DWORD segindex = 0; 1076 FX_DWORD segindex = 0;
1077 for (FX_DWORD i = 0; i < arrIndex.size(); i ++) { 1077 for (FX_DWORD i = 0; i < arrIndex.size(); i ++) {
1078 FX_INT32 startnum = arrIndex[i].first; 1078 int32_t startnum = arrIndex[i].first;
1079 if (startnum < 0) { 1079 if (startnum < 0) {
1080 continue; 1080 continue;
1081 } 1081 }
1082 m_dwXrefStartObjNum = pdfium::base::checked_cast<FX_DWORD, FX_INT32> (st artnum); 1082 m_dwXrefStartObjNum = pdfium::base::checked_cast<FX_DWORD, int32_t> (sta rtnum);
1083 FX_DWORD count = pdfium::base::checked_cast<FX_DWORD, FX_INT32> (arrInde x[i].second); 1083 FX_DWORD count = pdfium::base::checked_cast<FX_DWORD, int32_t> (arrIndex [i].second);
1084 FX_SAFE_DWORD dwCaculatedSize = segindex; 1084 FX_SAFE_DWORD dwCaculatedSize = segindex;
1085 dwCaculatedSize += count; 1085 dwCaculatedSize += count;
1086 dwCaculatedSize *= totalWidth; 1086 dwCaculatedSize *= totalWidth;
1087 if (!dwCaculatedSize.IsValid() || dwCaculatedSize.ValueOrDie() > dwTotal Size) { 1087 if (!dwCaculatedSize.IsValid() || dwCaculatedSize.ValueOrDie() > dwTotal Size) {
1088 continue; 1088 continue;
1089 } 1089 }
1090 FX_LPCBYTE segstart = pData + segindex * totalWidth; 1090 FX_LPCBYTE segstart = pData + segindex * totalWidth;
1091 FX_SAFE_DWORD dwMaxObjNum = startnum; 1091 FX_SAFE_DWORD dwMaxObjNum = startnum;
1092 dwMaxObjNum += count; 1092 dwMaxObjNum += count;
1093 FX_DWORD dwV5Size = pdfium::base::checked_cast<FX_DWORD, FX_INT32> (m_V5 Type.GetSize()); 1093 FX_DWORD dwV5Size = pdfium::base::checked_cast<FX_DWORD, int32_t> (m_V5T ype.GetSize());
1094 if (!dwMaxObjNum.IsValid() || dwMaxObjNum.ValueOrDie() > dwV5Size) { 1094 if (!dwMaxObjNum.IsValid() || dwMaxObjNum.ValueOrDie() > dwV5Size) {
1095 continue; 1095 continue;
1096 } 1096 }
1097 for (FX_DWORD j = 0; j < count; j ++) { 1097 for (FX_DWORD j = 0; j < count; j ++) {
1098 FX_INT32 type = 1; 1098 int32_t type = 1;
1099 FX_LPCBYTE entrystart = segstart + j * totalWidth; 1099 FX_LPCBYTE entrystart = segstart + j * totalWidth;
1100 if (WidthArray[0]) { 1100 if (WidthArray[0]) {
1101 type = _GetVarInt(entrystart, WidthArray[0]); 1101 type = _GetVarInt(entrystart, WidthArray[0]);
1102 } 1102 }
1103 if (m_V5Type[startnum + j] == 255) { 1103 if (m_V5Type[startnum + j] == 255) {
1104 FX_FILESIZE offset = _GetVarInt(entrystart + WidthArray[0], Widt hArray[1]); 1104 FX_FILESIZE offset = _GetVarInt(entrystart + WidthArray[0], Widt hArray[1]);
1105 m_CrossRef[startnum + j] = offset; 1105 m_CrossRef[startnum + j] = offset;
1106 FX_LPVOID pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetDat a(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize); 1106 FX_LPVOID pResult = FXSYS_bsearch(&offset, m_SortedOffset.GetDat a(), m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), _CompareFileSize);
1107 if (pResult == NULL) { 1107 if (pResult == NULL) {
1108 m_SortedOffset.Add(offset); 1108 m_SortedOffset.Add(offset);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 if (pos <= 0) { 1205 if (pos <= 0) {
1206 return NULL; 1206 return NULL;
1207 } 1207 }
1208 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); 1208 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext);
1209 } 1209 }
1210 if (m_V5Type[objnum] == 2) { 1210 if (m_V5Type[objnum] == 2) {
1211 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum ]); 1211 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum ]);
1212 if (pObjStream == NULL) { 1212 if (pObjStream == NULL) {
1213 return NULL; 1213 return NULL;
1214 } 1214 }
1215 FX_INT32 n = pObjStream->GetDict()->GetInteger(FX_BSTRC("N")); 1215 int32_t n = pObjStream->GetDict()->GetInteger(FX_BSTRC("N"));
1216 FX_INT32 offset = pObjStream->GetDict()->GetInteger(FX_BSTRC("First")); 1216 int32_t offset = pObjStream->GetDict()->GetInteger(FX_BSTRC("First"));
1217 CPDF_SyntaxParser syntax; 1217 CPDF_SyntaxParser syntax;
1218 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream((FX_LPBYTE)p ObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); 1218 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream((FX_LPBYTE)p ObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE));
1219 syntax.InitParser(file.Get(), 0); 1219 syntax.InitParser(file.Get(), 0);
1220 CPDF_Object* pRet = NULL; 1220 CPDF_Object* pRet = NULL;
1221 while (n) { 1221 while (n) {
1222 FX_DWORD thisnum = syntax.GetDirectNum(); 1222 FX_DWORD thisnum = syntax.GetDirectNum();
1223 FX_DWORD thisoff = syntax.GetDirectNum(); 1223 FX_DWORD thisoff = syntax.GetDirectNum();
1224 if (thisnum == objnum) { 1224 if (thisnum == objnum) {
1225 syntax.RestorePos(offset + thisoff); 1225 syntax.RestorePos(offset + thisoff);
1226 pRet = syntax.GetObject(pObjList, 0, 0, pContext); 1226 pRet = syntax.GetObject(pObjList, 0, 0, pContext);
1227 break; 1227 break;
1228 } 1228 }
1229 n --; 1229 n --;
1230 } 1230 }
1231 return pRet; 1231 return pRet;
1232 } 1232 }
1233 return NULL; 1233 return NULL;
1234 } 1234 }
1235 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) 1235 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum)
1236 { 1236 {
1237 CPDF_StreamAcc* pStreamAcc = NULL; 1237 CPDF_StreamAcc* pStreamAcc = NULL;
1238 if (m_ObjectStreamMap.Lookup((void*)(FX_UINTPTR)objnum, (void*&)pStreamAcc)) { 1238 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) {
1239 return pStreamAcc; 1239 return pStreamAcc;
1240 } 1240 }
1241 const CPDF_Stream* pStream = m_pDocument ? (CPDF_Stream*)m_pDocument->GetInd irectObject(objnum) : NULL; 1241 const CPDF_Stream* pStream = m_pDocument ? (CPDF_Stream*)m_pDocument->GetInd irectObject(objnum) : NULL;
1242 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) { 1242 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) {
1243 return NULL; 1243 return NULL;
1244 } 1244 }
1245 pStreamAcc = new CPDF_StreamAcc; 1245 pStreamAcc = new CPDF_StreamAcc;
1246 pStreamAcc->LoadAllData(pStream); 1246 pStreamAcc->LoadAllData(pStream);
1247 m_ObjectStreamMap.SetAt((void*)(FX_UINTPTR)objnum, pStreamAcc); 1247 m_ObjectStreamMap.SetAt((void*)(uintptr_t)objnum, pStreamAcc);
1248 return pStreamAcc; 1248 return pStreamAcc;
1249 } 1249 }
1250 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) 1250 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum)
1251 { 1251 {
1252 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { 1252 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) {
1253 return 0; 1253 return 0;
1254 } 1254 }
1255 if (m_V5Type[objnum] == 2) { 1255 if (m_V5Type[objnum] == 2) {
1256 objnum = (FX_DWORD)m_CrossRef[objnum]; 1256 objnum = (FX_DWORD)m_CrossRef[objnum];
1257 } 1257 }
(...skipping 18 matching lines...) Expand all
1276 pBuffer = NULL; 1276 pBuffer = NULL;
1277 size = 0; 1277 size = 0;
1278 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) { 1278 if (objnum >= (FX_DWORD)m_CrossRef.GetSize()) {
1279 return; 1279 return;
1280 } 1280 }
1281 if (m_V5Type[objnum] == 2) { 1281 if (m_V5Type[objnum] == 2) {
1282 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum ]); 1282 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum ]);
1283 if (pObjStream == NULL) { 1283 if (pObjStream == NULL) {
1284 return; 1284 return;
1285 } 1285 }
1286 FX_INT32 n = pObjStream->GetDict()->GetInteger(FX_BSTRC("N")); 1286 int32_t n = pObjStream->GetDict()->GetInteger(FX_BSTRC("N"));
1287 FX_INT32 offset = pObjStream->GetDict()->GetInteger(FX_BSTRC("First")); 1287 int32_t offset = pObjStream->GetDict()->GetInteger(FX_BSTRC("First"));
1288 CPDF_SyntaxParser syntax; 1288 CPDF_SyntaxParser syntax;
1289 FX_LPCBYTE pData = pObjStream->GetData(); 1289 FX_LPCBYTE pData = pObjStream->GetData();
1290 FX_DWORD totalsize = pObjStream->GetSize(); 1290 FX_DWORD totalsize = pObjStream->GetSize();
1291 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream((FX_LPBYTE)p Data, (size_t)totalsize, FALSE)); 1291 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream((FX_LPBYTE)p Data, (size_t)totalsize, FALSE));
1292 syntax.InitParser(file.Get(), 0); 1292 syntax.InitParser(file.Get(), 0);
1293 while (n) { 1293 while (n) {
1294 FX_DWORD thisnum = syntax.GetDirectNum(); 1294 FX_DWORD thisnum = syntax.GetDirectNum();
1295 FX_DWORD thisoff = syntax.GetDirectNum(); 1295 FX_DWORD thisoff = syntax.GetDirectNum();
1296 if (thisnum == objnum) { 1296 if (thisnum == objnum) {
1297 if (n == 1) { 1297 if (n == 1) {
1298 size = totalsize - (thisoff + offset); 1298 size = totalsize - (thisoff + offset);
1299 } else { 1299 } else {
1300 syntax.GetDirectNum(); // Skip nextnum. 1300 syntax.GetDirectNum(); // Skip nextnum.
1301 FX_DWORD nextoff = syntax.GetDirectNum(); 1301 FX_DWORD nextoff = syntax.GetDirectNum();
1302 size = nextoff - thisoff; 1302 size = nextoff - thisoff;
1303 } 1303 }
1304 pBuffer = FX_Alloc(FX_BYTE, size); 1304 pBuffer = FX_Alloc(uint8_t, size);
1305 FXSYS_memcpy32(pBuffer, pData + thisoff + offset, size); 1305 FXSYS_memcpy32(pBuffer, pData + thisoff + offset, size);
1306 return; 1306 return;
1307 } 1307 }
1308 n --; 1308 n --;
1309 } 1309 }
1310 return; 1310 return;
1311 } 1311 }
1312 if (m_V5Type[objnum] == 1) { 1312 if (m_V5Type[objnum] == 1) {
1313 FX_FILESIZE pos = m_CrossRef[objnum]; 1313 FX_FILESIZE pos = m_CrossRef[objnum];
1314 if (pos == 0) { 1314 if (pos == 0) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 if (m_Syntax.GetKeyword() == FX_BSTRC("endobj")) { 1361 if (m_Syntax.GetKeyword() == FX_BSTRC("endobj")) {
1362 break; 1362 break;
1363 } 1363 }
1364 if (m_Syntax.SavePos() == m_Syntax.m_FileLen) { 1364 if (m_Syntax.SavePos() == m_Syntax.m_FileLen) {
1365 break; 1365 break;
1366 } 1366 }
1367 } 1367 }
1368 nextoff = m_Syntax.SavePos(); 1368 nextoff = m_Syntax.SavePos();
1369 } 1369 }
1370 size = (FX_DWORD)(nextoff - pos); 1370 size = (FX_DWORD)(nextoff - pos);
1371 pBuffer = FX_Alloc(FX_BYTE, size); 1371 pBuffer = FX_Alloc(uint8_t, size);
1372 m_Syntax.RestorePos(pos); 1372 m_Syntax.RestorePos(pos);
1373 m_Syntax.ReadBlock(pBuffer, size); 1373 m_Syntax.ReadBlock(pBuffer, size);
1374 m_Syntax.RestorePos(SavedPos); 1374 m_Syntax.RestorePos(SavedPos);
1375 } 1375 }
1376 } 1376 }
1377 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, FX_FILESIZE pos, FX_DWORD objnum, 1377 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, FX_FILESIZE pos, FX_DWORD objnum,
1378 PARSE_CONTEXT* pContext) 1378 PARSE_CONTEXT* pContext)
1379 { 1379 {
1380 FX_FILESIZE SavedPos = m_Syntax.SavePos(); 1380 FX_FILESIZE SavedPos = m_Syntax.SavePos();
1381 m_Syntax.RestorePos(pos); 1381 m_Syntax.RestorePos(pos);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 m_pLinearized->Release(); 1546 m_pLinearized->Release();
1547 m_pLinearized = NULL; 1547 m_pLinearized = NULL;
1548 return FALSE; 1548 return FALSE;
1549 } 1549 }
1550 FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, FX_BOOL bReParse , FX_BOOL bOwnFileRead) 1550 FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, FX_BOOL bReParse , FX_BOOL bOwnFileRead)
1551 { 1551 {
1552 CloseParser(bReParse); 1552 CloseParser(bReParse);
1553 m_bXRefStream = FALSE; 1553 m_bXRefStream = FALSE;
1554 m_LastXRefOffset = 0; 1554 m_LastXRefOffset = 0;
1555 m_bOwnFileRead = bOwnFileRead; 1555 m_bOwnFileRead = bOwnFileRead;
1556 FX_INT32 offset = GetHeaderOffset(pFileAccess); 1556 int32_t offset = GetHeaderOffset(pFileAccess);
1557 if (offset == -1) { 1557 if (offset == -1) {
1558 return PDFPARSE_ERROR_FORMAT; 1558 return PDFPARSE_ERROR_FORMAT;
1559 } 1559 }
1560 if (!IsLinearizedFile(pFileAccess, offset)) { 1560 if (!IsLinearizedFile(pFileAccess, offset)) {
1561 m_Syntax.m_pFileAccess = NULL; 1561 m_Syntax.m_pFileAccess = NULL;
1562 return StartParse(pFileAccess, bReParse, bOwnFileRead); 1562 return StartParse(pFileAccess, bReParse, bOwnFileRead);
1563 } 1563 }
1564 if (!bReParse) { 1564 if (!bReParse) {
1565 m_pDocument = new CPDF_Document(this); 1565 m_pDocument = new CPDF_Document(this);
1566 } 1566 }
1567 FX_FILESIZE dwFirstXRefOffset = m_Syntax.SavePos(); 1567 FX_FILESIZE dwFirstXRefOffset = m_Syntax.SavePos();
1568 FX_BOOL bXRefRebuilt = FALSE; 1568 FX_BOOL bXRefRebuilt = FALSE;
1569 FX_BOOL bLoadV4 = FALSE; 1569 FX_BOOL bLoadV4 = FALSE;
1570 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE, FALSE)) && !Load CrossRefV5(dwFirstXRefOffset, dwFirstXRefOffset, TRUE)) { 1570 if (!(bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, FALSE, FALSE)) && !Load CrossRefV5(dwFirstXRefOffset, dwFirstXRefOffset, TRUE)) {
1571 if (!RebuildCrossRef()) { 1571 if (!RebuildCrossRef()) {
1572 return PDFPARSE_ERROR_FORMAT; 1572 return PDFPARSE_ERROR_FORMAT;
1573 } 1573 }
1574 bXRefRebuilt = TRUE; 1574 bXRefRebuilt = TRUE;
1575 m_LastXRefOffset = 0; 1575 m_LastXRefOffset = 0;
1576 } 1576 }
1577 if (bLoadV4) { 1577 if (bLoadV4) {
1578 m_pTrailer = LoadTrailerV4(); 1578 m_pTrailer = LoadTrailerV4();
1579 if (m_pTrailer == NULL) { 1579 if (m_pTrailer == NULL) {
1580 return FALSE; 1580 return FALSE;
1581 } 1581 }
1582 FX_INT32 xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size")); 1582 int32_t xrefsize = GetDirectInteger(m_pTrailer, FX_BSTRC("Size"));
1583 if (xrefsize > 0) { 1583 if (xrefsize > 0) {
1584 m_CrossRef.SetSize(xrefsize); 1584 m_CrossRef.SetSize(xrefsize);
1585 m_V5Type.SetSize(xrefsize); 1585 m_V5Type.SetSize(xrefsize);
1586 } 1586 }
1587 } 1587 }
1588 FX_DWORD dwRet = SetEncryptHandler(); 1588 FX_DWORD dwRet = SetEncryptHandler();
1589 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 1589 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
1590 return dwRet; 1590 return dwRet;
1591 } 1591 }
1592 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict()); 1592 m_pDocument->LoadAsynDoc(m_pLinearized->GetDict());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 } 1644 }
1645 FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() 1645 FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable()
1646 { 1646 {
1647 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum; 1647 FX_DWORD dwSaveMetadataObjnum = m_Syntax.m_MetadataObjnum;
1648 m_Syntax.m_MetadataObjnum = 0; 1648 m_Syntax.m_MetadataObjnum = 0;
1649 if (m_pTrailer) { 1649 if (m_pTrailer) {
1650 m_pTrailer->Release(); 1650 m_pTrailer->Release();
1651 m_pTrailer = NULL; 1651 m_pTrailer = NULL;
1652 } 1652 }
1653 m_Syntax.RestorePos(m_LastXRefOffset - m_Syntax.m_HeaderOffset); 1653 m_Syntax.RestorePos(m_LastXRefOffset - m_Syntax.m_HeaderOffset);
1654 FX_BYTE ch = 0; 1654 uint8_t ch = 0;
1655 FX_DWORD dwCount = 0; 1655 FX_DWORD dwCount = 0;
1656 m_Syntax.GetNextChar(ch); 1656 m_Syntax.GetNextChar(ch);
1657 FX_INT32 type = PDF_CharType[ch]; 1657 int32_t type = PDF_CharType[ch];
1658 while (type == 'W') { 1658 while (type == 'W') {
1659 ++dwCount; 1659 ++dwCount;
1660 if (m_Syntax.m_FileLen >= (FX_FILESIZE)(m_Syntax.SavePos() + m_Syntax.m_ HeaderOffset)) { 1660 if (m_Syntax.m_FileLen >= (FX_FILESIZE)(m_Syntax.SavePos() + m_Syntax.m_ HeaderOffset)) {
1661 break; 1661 break;
1662 } 1662 }
1663 m_Syntax.GetNextChar(ch); 1663 m_Syntax.GetNextChar(ch);
1664 type = PDF_CharType[ch]; 1664 type = PDF_CharType[ch];
1665 } 1665 }
1666 m_LastXRefOffset += dwCount; 1666 m_LastXRefOffset += dwCount;
1667 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); 1667 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition();
(...skipping 27 matching lines...) Expand all
1695 m_MetadataObjnum = 0; 1695 m_MetadataObjnum = 0;
1696 m_dwWordPos = 0; 1696 m_dwWordPos = 0;
1697 m_bFileStream = FALSE; 1697 m_bFileStream = FALSE;
1698 } 1698 }
1699 CPDF_SyntaxParser::~CPDF_SyntaxParser() 1699 CPDF_SyntaxParser::~CPDF_SyntaxParser()
1700 { 1700 {
1701 if (m_pFileBuf) { 1701 if (m_pFileBuf) {
1702 FX_Free(m_pFileBuf); 1702 FX_Free(m_pFileBuf);
1703 } 1703 }
1704 } 1704 }
1705 FX_BOOL CPDF_SyntaxParser::GetCharAt(FX_FILESIZE pos, FX_BYTE& ch) 1705 FX_BOOL CPDF_SyntaxParser::GetCharAt(FX_FILESIZE pos, uint8_t& ch)
1706 { 1706 {
1707 FX_FILESIZE save_pos = m_Pos; 1707 FX_FILESIZE save_pos = m_Pos;
1708 m_Pos = pos; 1708 m_Pos = pos;
1709 FX_BOOL ret = GetNextChar(ch); 1709 FX_BOOL ret = GetNextChar(ch);
1710 m_Pos = save_pos; 1710 m_Pos = save_pos;
1711 return ret; 1711 return ret;
1712 } 1712 }
1713 FX_BOOL CPDF_SyntaxParser::GetNextChar(FX_BYTE& ch) 1713 FX_BOOL CPDF_SyntaxParser::GetNextChar(uint8_t& ch)
1714 { 1714 {
1715 FX_FILESIZE pos = m_Pos + m_HeaderOffset; 1715 FX_FILESIZE pos = m_Pos + m_HeaderOffset;
1716 if (pos >= m_FileLen) { 1716 if (pos >= m_FileLen) {
1717 return FALSE; 1717 return FALSE;
1718 } 1718 }
1719 if (m_BufOffset >= pos || (FX_FILESIZE)(m_BufOffset + m_BufSize) <= pos) { 1719 if (m_BufOffset >= pos || (FX_FILESIZE)(m_BufOffset + m_BufSize) <= pos) {
1720 FX_FILESIZE read_pos = pos; 1720 FX_FILESIZE read_pos = pos;
1721 FX_DWORD read_size = m_BufSize; 1721 FX_DWORD read_size = m_BufSize;
1722 if ((FX_FILESIZE)read_size > m_FileLen) { 1722 if ((FX_FILESIZE)read_size > m_FileLen) {
1723 read_size = (FX_DWORD)m_FileLen; 1723 read_size = (FX_DWORD)m_FileLen;
1724 } 1724 }
1725 if ((FX_FILESIZE)(read_pos + read_size) > m_FileLen) { 1725 if ((FX_FILESIZE)(read_pos + read_size) > m_FileLen) {
1726 if (m_FileLen < (FX_FILESIZE)read_size) { 1726 if (m_FileLen < (FX_FILESIZE)read_size) {
1727 read_pos = 0; 1727 read_pos = 0;
1728 read_size = (FX_DWORD)m_FileLen; 1728 read_size = (FX_DWORD)m_FileLen;
1729 } else { 1729 } else {
1730 read_pos = m_FileLen - read_size; 1730 read_pos = m_FileLen - read_size;
1731 } 1731 }
1732 } 1732 }
1733 if (!m_pFileAccess->ReadBlock(m_pFileBuf, read_pos, read_size)) { 1733 if (!m_pFileAccess->ReadBlock(m_pFileBuf, read_pos, read_size)) {
1734 return FALSE; 1734 return FALSE;
1735 } 1735 }
1736 m_BufOffset = read_pos; 1736 m_BufOffset = read_pos;
1737 } 1737 }
1738 ch = m_pFileBuf[pos - m_BufOffset]; 1738 ch = m_pFileBuf[pos - m_BufOffset];
1739 m_Pos ++; 1739 m_Pos ++;
1740 return TRUE; 1740 return TRUE;
1741 } 1741 }
1742 FX_BOOL CPDF_SyntaxParser::GetCharAtBackward(FX_FILESIZE pos, FX_BYTE& ch) 1742 FX_BOOL CPDF_SyntaxParser::GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch)
1743 { 1743 {
1744 pos += m_HeaderOffset; 1744 pos += m_HeaderOffset;
1745 if (pos >= m_FileLen) { 1745 if (pos >= m_FileLen) {
1746 return FALSE; 1746 return FALSE;
1747 } 1747 }
1748 if (m_BufOffset >= pos || (FX_FILESIZE)(m_BufOffset + m_BufSize) <= pos) { 1748 if (m_BufOffset >= pos || (FX_FILESIZE)(m_BufOffset + m_BufSize) <= pos) {
1749 FX_FILESIZE read_pos; 1749 FX_FILESIZE read_pos;
1750 if (pos < (FX_FILESIZE)m_BufSize) { 1750 if (pos < (FX_FILESIZE)m_BufSize) {
1751 read_pos = 0; 1751 read_pos = 0;
1752 } else { 1752 } else {
(...skipping 22 matching lines...) Expand all
1775 return FALSE; 1775 return FALSE;
1776 } 1776 }
1777 m_Pos += size; 1777 m_Pos += size;
1778 return TRUE; 1778 return TRUE;
1779 } 1779 }
1780 #define MAX_WORD_BUFFER 256 1780 #define MAX_WORD_BUFFER 256
1781 void CPDF_SyntaxParser::GetNextWord() 1781 void CPDF_SyntaxParser::GetNextWord()
1782 { 1782 {
1783 m_WordSize = 0; 1783 m_WordSize = 0;
1784 m_bIsNumber = TRUE; 1784 m_bIsNumber = TRUE;
1785 FX_BYTE ch; 1785 uint8_t ch;
1786 if (!GetNextChar(ch)) { 1786 if (!GetNextChar(ch)) {
1787 return; 1787 return;
1788 } 1788 }
1789 FX_BYTE type = PDF_CharType[ch]; 1789 uint8_t type = PDF_CharType[ch];
1790 while (1) { 1790 while (1) {
1791 while (type == 'W') { 1791 while (type == 'W') {
1792 if (!GetNextChar(ch)) { 1792 if (!GetNextChar(ch)) {
1793 return; 1793 return;
1794 } 1794 }
1795 type = PDF_CharType[ch]; 1795 type = PDF_CharType[ch];
1796 } 1796 }
1797 if (ch != '%') { 1797 if (ch != '%') {
1798 break; 1798 break;
1799 } 1799 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 } 1857 }
1858 type = PDF_CharType[ch]; 1858 type = PDF_CharType[ch];
1859 if (type == 'D' || type == 'W') { 1859 if (type == 'D' || type == 'W') {
1860 m_Pos --; 1860 m_Pos --;
1861 break; 1861 break;
1862 } 1862 }
1863 } 1863 }
1864 } 1864 }
1865 CFX_ByteString CPDF_SyntaxParser::ReadString() 1865 CFX_ByteString CPDF_SyntaxParser::ReadString()
1866 { 1866 {
1867 FX_BYTE ch; 1867 uint8_t ch;
1868 if (!GetNextChar(ch)) { 1868 if (!GetNextChar(ch)) {
1869 return CFX_ByteString(); 1869 return CFX_ByteString();
1870 } 1870 }
1871 CFX_ByteTextBuf buf; 1871 CFX_ByteTextBuf buf;
1872 FX_INT32 parlevel = 0; 1872 int32_t parlevel = 0;
1873 FX_INT32 status = 0, iEscCode = 0; 1873 int32_t status = 0, iEscCode = 0;
1874 while (1) { 1874 while (1) {
1875 switch (status) { 1875 switch (status) {
1876 case 0: 1876 case 0:
1877 if (ch == ')') { 1877 if (ch == ')') {
1878 if (parlevel == 0) { 1878 if (parlevel == 0) {
1879 return buf.GetByteString(); 1879 return buf.GetByteString();
1880 } 1880 }
1881 parlevel --; 1881 parlevel --;
1882 buf.AppendChar(')'); 1882 buf.AppendChar(')');
1883 } else if (ch == '(') { 1883 } else if (ch == '(') {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 } 1944 }
1945 if (!GetNextChar(ch)) { 1945 if (!GetNextChar(ch)) {
1946 break; 1946 break;
1947 } 1947 }
1948 } 1948 }
1949 GetNextChar(ch); 1949 GetNextChar(ch);
1950 return buf.GetByteString(); 1950 return buf.GetByteString();
1951 } 1951 }
1952 CFX_ByteString CPDF_SyntaxParser::ReadHexString() 1952 CFX_ByteString CPDF_SyntaxParser::ReadHexString()
1953 { 1953 {
1954 FX_BYTE ch; 1954 uint8_t ch;
1955 if (!GetNextChar(ch)) { 1955 if (!GetNextChar(ch)) {
1956 return CFX_ByteString(); 1956 return CFX_ByteString();
1957 } 1957 }
1958 CFX_BinaryBuf buf; 1958 CFX_BinaryBuf buf;
1959 FX_BOOL bFirst = TRUE; 1959 FX_BOOL bFirst = TRUE;
1960 FX_BYTE code = 0; 1960 uint8_t code = 0;
1961 while (1) { 1961 while (1) {
1962 if (ch == '>') { 1962 if (ch == '>') {
1963 break; 1963 break;
1964 } 1964 }
1965 if (ch >= '0' && ch <= '9') { 1965 if (ch >= '0' && ch <= '9') {
1966 if (bFirst) { 1966 if (bFirst) {
1967 code = (ch - '0') * 16; 1967 code = (ch - '0') * 16;
1968 } else { 1968 } else {
1969 code += ch - '0'; 1969 code += ch - '0';
1970 buf.AppendByte((FX_BYTE)code); 1970 buf.AppendByte((uint8_t)code);
1971 } 1971 }
1972 bFirst = !bFirst; 1972 bFirst = !bFirst;
1973 } else if (ch >= 'A' && ch <= 'F') { 1973 } else if (ch >= 'A' && ch <= 'F') {
1974 if (bFirst) { 1974 if (bFirst) {
1975 code = (ch - 'A' + 10) * 16; 1975 code = (ch - 'A' + 10) * 16;
1976 } else { 1976 } else {
1977 code += ch - 'A' + 10; 1977 code += ch - 'A' + 10;
1978 buf.AppendByte((FX_BYTE)code); 1978 buf.AppendByte((uint8_t)code);
1979 } 1979 }
1980 bFirst = !bFirst; 1980 bFirst = !bFirst;
1981 } else if (ch >= 'a' && ch <= 'f') { 1981 } else if (ch >= 'a' && ch <= 'f') {
1982 if (bFirst) { 1982 if (bFirst) {
1983 code = (ch - 'a' + 10) * 16; 1983 code = (ch - 'a' + 10) * 16;
1984 } else { 1984 } else {
1985 code += ch - 'a' + 10; 1985 code += ch - 'a' + 10;
1986 buf.AppendByte((FX_BYTE)code); 1986 buf.AppendByte((uint8_t)code);
1987 } 1987 }
1988 bFirst = !bFirst; 1988 bFirst = !bFirst;
1989 } 1989 }
1990 if (!GetNextChar(ch)) { 1990 if (!GetNextChar(ch)) {
1991 break; 1991 break;
1992 } 1992 }
1993 } 1993 }
1994 if (!bFirst) { 1994 if (!bFirst) {
1995 buf.AppendByte((FX_BYTE)code); 1995 buf.AppendByte((uint8_t)code);
1996 } 1996 }
1997 return buf.GetByteString(); 1997 return buf.GetByteString();
1998 } 1998 }
1999 void CPDF_SyntaxParser::ToNextLine() 1999 void CPDF_SyntaxParser::ToNextLine()
2000 { 2000 {
2001 FX_BYTE ch; 2001 uint8_t ch;
2002 while (1) { 2002 while (1) {
2003 if (!GetNextChar(ch)) { 2003 if (!GetNextChar(ch)) {
2004 return; 2004 return;
2005 } 2005 }
2006 if (ch == '\n') { 2006 if (ch == '\n') {
2007 return; 2007 return;
2008 } 2008 }
2009 if (ch == '\r') { 2009 if (ch == '\r') {
2010 GetNextChar(ch); 2010 GetNextChar(ch);
2011 if (ch == '\n') { 2011 if (ch == '\n') {
2012 return; 2012 return;
2013 } else { 2013 } else {
2014 m_Pos --; 2014 m_Pos --;
2015 return; 2015 return;
2016 } 2016 }
2017 } 2017 }
2018 } 2018 }
2019 } 2019 }
2020 void CPDF_SyntaxParser::ToNextWord() 2020 void CPDF_SyntaxParser::ToNextWord()
2021 { 2021 {
2022 FX_BYTE ch; 2022 uint8_t ch;
2023 if (!GetNextChar(ch)) { 2023 if (!GetNextChar(ch)) {
2024 return; 2024 return;
2025 } 2025 }
2026 FX_BYTE type = PDF_CharType[ch]; 2026 uint8_t type = PDF_CharType[ch];
2027 while (1) { 2027 while (1) {
2028 while (type == 'W') { 2028 while (type == 'W') {
2029 m_dwWordPos = m_Pos; 2029 m_dwWordPos = m_Pos;
2030 if (!GetNextChar(ch)) { 2030 if (!GetNextChar(ch)) {
2031 return; 2031 return;
2032 } 2032 }
2033 type = PDF_CharType[ch]; 2033 type = PDF_CharType[ch];
2034 } 2034 }
2035 if (ch != '%') { 2035 if (ch != '%') {
2036 break; 2036 break;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 return pRet; 2161 return pRet;
2162 } 2162 }
2163 if (word == FX_BSTRC("<<")) { 2163 if (word == FX_BSTRC("<<")) {
2164 if (bTypeOnly) { 2164 if (bTypeOnly) {
2165 return (CPDF_Object*)PDFOBJ_DICTIONARY; 2165 return (CPDF_Object*)PDFOBJ_DICTIONARY;
2166 } 2166 }
2167 if (pContext) { 2167 if (pContext) {
2168 pContext->m_DictStart = SavedPos; 2168 pContext->m_DictStart = SavedPos;
2169 } 2169 }
2170 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); 2170 CPDF_Dictionary* pDict = CPDF_Dictionary::Create();
2171 FX_INT32 nKeys = 0; 2171 int32_t nKeys = 0;
2172 FX_FILESIZE dwSignValuePos = 0; 2172 FX_FILESIZE dwSignValuePos = 0;
2173 while (1) { 2173 while (1) {
2174 FX_BOOL bIsNumber; 2174 FX_BOOL bIsNumber;
2175 CFX_ByteString key = GetNextWord(bIsNumber); 2175 CFX_ByteString key = GetNextWord(bIsNumber);
2176 if (key.IsEmpty()) { 2176 if (key.IsEmpty()) {
2177 if (pDict) 2177 if (pDict)
2178 pDict->Release(); 2178 pDict->Release();
2179 return NULL; 2179 return NULL;
2180 } 2180 }
2181 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); 2181 FX_FILESIZE SavedPos = m_Pos - key.GetLength();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2370 } 2370 }
2371 if (key[0] != '/') { 2371 if (key[0] != '/') {
2372 continue; 2372 continue;
2373 } 2373 }
2374 key = PDF_NameDecode(key); 2374 key = PDF_NameDecode(key);
2375 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum); 2375 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum);
2376 if (pObj == NULL) { 2376 if (pObj == NULL) {
2377 if (pDict) { 2377 if (pDict) {
2378 pDict->Release(); 2378 pDict->Release();
2379 } 2379 }
2380 FX_BYTE ch; 2380 uint8_t ch;
2381 while (1) { 2381 while (1) {
2382 if (!GetNextChar(ch)) { 2382 if (!GetNextChar(ch)) {
2383 break; 2383 break;
2384 } 2384 }
2385 if (ch == 0x0A || ch == 0x0D) { 2385 if (ch == 0x0A || ch == 0x0D) {
2386 break; 2386 break;
2387 } 2387 }
2388 } 2388 }
2389 return NULL; 2389 return NULL;
2390 } 2390 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2454 FX_FILESIZE offset = FindTag(FX_BSTRC("endstream"), 0); 2454 FX_FILESIZE offset = FindTag(FX_BSTRC("endstream"), 0);
2455 if (offset >= 0) { 2455 if (offset >= 0) {
2456 FX_FILESIZE curPos = m_Pos; 2456 FX_FILESIZE curPos = m_Pos;
2457 m_Pos = StreamStartPos; 2457 m_Pos = StreamStartPos;
2458 FX_FILESIZE endobjOffset = FindTag(FX_BSTRC("endobj"), 0); 2458 FX_FILESIZE endobjOffset = FindTag(FX_BSTRC("endobj"), 0);
2459 if (endobjOffset < offset && endobjOffset >= 0) { 2459 if (endobjOffset < offset && endobjOffset >= 0) {
2460 offset = endobjOffset; 2460 offset = endobjOffset;
2461 } else { 2461 } else {
2462 m_Pos = curPos; 2462 m_Pos = curPos;
2463 } 2463 }
2464 FX_BYTE byte1, byte2; 2464 uint8_t byte1, byte2;
2465 GetCharAt(StreamStartPos + offset - 1, byte1); 2465 GetCharAt(StreamStartPos + offset - 1, byte1);
2466 GetCharAt(StreamStartPos + offset - 2, byte2); 2466 GetCharAt(StreamStartPos + offset - 2, byte2);
2467 if (byte1 == 0x0a && byte2 == 0x0d) { 2467 if (byte1 == 0x0a && byte2 == 0x0d) {
2468 len -= 2; 2468 len -= 2;
2469 } else if (byte1 == 0x0a || byte1 == 0x0d) { 2469 } else if (byte1 == 0x0a || byte1 == 0x0d) {
2470 len --; 2470 len --;
2471 } 2471 }
2472 len = (FX_DWORD)offset; 2472 len = (FX_DWORD)offset;
2473 pDict->SetAtInteger(FX_BSTRC("Length"), len); 2473 pDict->SetAtInteger(FX_BSTRC("Length"), len);
2474 } else { 2474 } else {
2475 m_Pos = StreamStartPos; 2475 m_Pos = StreamStartPos;
2476 if (FindTag(FX_BSTRC("endobj"), 0) < 0) { 2476 if (FindTag(FX_BSTRC("endobj"), 0) < 0) {
2477 return NULL; 2477 return NULL;
2478 } 2478 }
2479 } 2479 }
2480 } 2480 }
2481 m_Pos = StreamStartPos; 2481 m_Pos = StreamStartPos;
2482 } 2482 }
2483 CPDF_Stream* pStream; 2483 CPDF_Stream* pStream;
2484 FX_LPBYTE pData = FX_Alloc(FX_BYTE, len); 2484 FX_LPBYTE pData = FX_Alloc(uint8_t, len);
2485 ReadBlock(pData, len); 2485 ReadBlock(pData, len);
2486 if (pCryptoHandler) { 2486 if (pCryptoHandler) {
2487 CFX_BinaryBuf dest_buf; 2487 CFX_BinaryBuf dest_buf;
2488 dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len)); 2488 dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len));
2489 FX_LPVOID context = pCryptoHandler->DecryptStart(objnum, gennum); 2489 FX_LPVOID context = pCryptoHandler->DecryptStart(objnum, gennum);
2490 pCryptoHandler->DecryptStream(context, pData, len, dest_buf); 2490 pCryptoHandler->DecryptStream(context, pData, len, dest_buf);
2491 pCryptoHandler->DecryptFinish(context, dest_buf); 2491 pCryptoHandler->DecryptFinish(context, dest_buf);
2492 FX_Free(pData); 2492 FX_Free(pData);
2493 pData = dest_buf.GetBuffer(); 2493 pData = dest_buf.GetBuffer();
2494 len = dest_buf.GetSize(); 2494 len = dest_buf.GetSize();
2495 dest_buf.DetachBuffer(); 2495 dest_buf.DetachBuffer();
2496 } 2496 }
2497 pStream = new CPDF_Stream(pData, len, pDict); 2497 pStream = new CPDF_Stream(pData, len, pDict);
2498 if (pContext) { 2498 if (pContext) {
2499 pContext->m_DataEnd = pContext->m_DataStart + len; 2499 pContext->m_DataEnd = pContext->m_DataStart + len;
2500 } 2500 }
2501 StreamStartPos = m_Pos; 2501 StreamStartPos = m_Pos;
2502 GetNextWord(); 2502 GetNextWord();
2503 if (m_WordSize == 6 && 0 == FXSYS_memcmp32(m_WordBuffer, "endobj", 6)) { 2503 if (m_WordSize == 6 && 0 == FXSYS_memcmp32(m_WordBuffer, "endobj", 6)) {
2504 m_Pos = StreamStartPos; 2504 m_Pos = StreamStartPos;
2505 } 2505 }
2506 return pStream; 2506 return pStream;
2507 } 2507 }
2508 void CPDF_SyntaxParser::InitParser(IFX_FileRead* pFileAccess, FX_DWORD HeaderOff set) 2508 void CPDF_SyntaxParser::InitParser(IFX_FileRead* pFileAccess, FX_DWORD HeaderOff set)
2509 { 2509 {
2510 if (m_pFileBuf) { 2510 if (m_pFileBuf) {
2511 FX_Free(m_pFileBuf); 2511 FX_Free(m_pFileBuf);
2512 m_pFileBuf = NULL; 2512 m_pFileBuf = NULL;
2513 } 2513 }
2514 m_pFileBuf = FX_Alloc(FX_BYTE, m_BufSize); 2514 m_pFileBuf = FX_Alloc(uint8_t, m_BufSize);
2515 m_HeaderOffset = HeaderOffset; 2515 m_HeaderOffset = HeaderOffset;
2516 m_FileLen = pFileAccess->GetSize(); 2516 m_FileLen = pFileAccess->GetSize();
2517 m_Pos = 0; 2517 m_Pos = 0;
2518 m_pFileAccess = pFileAccess; 2518 m_pFileAccess = pFileAccess;
2519 m_BufOffset = 0; 2519 m_BufOffset = 0;
2520 pFileAccess->ReadBlock(m_pFileBuf, 0, (size_t)((FX_FILESIZE)m_BufSize > m_Fi leLen ? m_FileLen : m_BufSize)); 2520 pFileAccess->ReadBlock(m_pFileBuf, 0, (size_t)((FX_FILESIZE)m_BufSize > m_Fi leLen ? m_FileLen : m_BufSize));
2521 } 2521 }
2522 FX_INT32 CPDF_SyntaxParser::GetDirectNum() 2522 int32_t CPDF_SyntaxParser::GetDirectNum()
2523 { 2523 {
2524 GetNextWord(); 2524 GetNextWord();
2525 if (!m_bIsNumber) { 2525 if (!m_bIsNumber) {
2526 return 0; 2526 return 0;
2527 } 2527 }
2528 m_WordBuffer[m_WordSize] = 0; 2528 m_WordBuffer[m_WordSize] = 0;
2529 return FXSYS_atoi((FX_LPCSTR)m_WordBuffer); 2529 return FXSYS_atoi((FX_LPCSTR)m_WordBuffer);
2530 } 2530 }
2531 FX_BOOL CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, FX_FILESIZE limit, FX_LPCBYTE tag, FX_DWORD taglen) 2531 FX_BOOL CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos, FX_FILESIZE limit, FX_LPCBYTE tag, FX_DWORD taglen)
2532 { 2532 {
2533 FX_BYTE type = PDF_CharType[tag[0]]; 2533 uint8_t type = PDF_CharType[tag[0]];
2534 FX_BOOL bCheckLeft = type != 'D' && type != 'W'; 2534 FX_BOOL bCheckLeft = type != 'D' && type != 'W';
2535 type = PDF_CharType[tag[taglen - 1]]; 2535 type = PDF_CharType[tag[taglen - 1]];
2536 FX_BOOL bCheckRight = type != 'D' && type != 'W'; 2536 FX_BOOL bCheckRight = type != 'D' && type != 'W';
2537 FX_BYTE ch; 2537 uint8_t ch;
2538 if (bCheckRight && startpos + (FX_INT32)taglen <= limit && GetCharAt(startpo s + (FX_INT32)taglen, ch)) { 2538 if (bCheckRight && startpos + (int32_t)taglen <= limit && GetCharAt(startpos + (int32_t)taglen, ch)) {
2539 FX_BYTE type = PDF_CharType[ch]; 2539 uint8_t type = PDF_CharType[ch];
2540 if (type == 'N' || type == 'R') { 2540 if (type == 'N' || type == 'R') {
2541 return FALSE; 2541 return FALSE;
2542 } 2542 }
2543 } 2543 }
2544 if (bCheckLeft && startpos > 0 && GetCharAt(startpos - 1, ch)) { 2544 if (bCheckLeft && startpos > 0 && GetCharAt(startpos - 1, ch)) {
2545 FX_BYTE type = PDF_CharType[ch]; 2545 uint8_t type = PDF_CharType[ch];
2546 if (type == 'N' || type == 'R') { 2546 if (type == 'N' || type == 'R') {
2547 return FALSE; 2547 return FALSE;
2548 } 2548 }
2549 } 2549 }
2550 return TRUE; 2550 return TRUE;
2551 } 2551 }
2552 FX_BOOL CPDF_SyntaxParser::SearchWord(FX_BSTR tag, FX_BOOL bWholeWord, FX_BOOL b Forward, FX_FILESIZE limit) 2552 FX_BOOL CPDF_SyntaxParser::SearchWord(FX_BSTR tag, FX_BOOL bWholeWord, FX_BOOL b Forward, FX_FILESIZE limit)
2553 { 2553 {
2554 FX_INT32 taglen = tag.GetLength(); 2554 int32_t taglen = tag.GetLength();
2555 if (taglen == 0) { 2555 if (taglen == 0) {
2556 return FALSE; 2556 return FALSE;
2557 } 2557 }
2558 FX_FILESIZE pos = m_Pos; 2558 FX_FILESIZE pos = m_Pos;
2559 FX_INT32 offset = 0; 2559 int32_t offset = 0;
2560 if (!bForward) { 2560 if (!bForward) {
2561 offset = taglen - 1; 2561 offset = taglen - 1;
2562 } 2562 }
2563 FX_LPCBYTE tag_data = tag.GetPtr(); 2563 FX_LPCBYTE tag_data = tag.GetPtr();
2564 FX_BYTE byte; 2564 uint8_t byte;
2565 while (1) { 2565 while (1) {
2566 if (bForward) { 2566 if (bForward) {
2567 if (limit) { 2567 if (limit) {
2568 if (pos >= m_Pos + limit) { 2568 if (pos >= m_Pos + limit) {
2569 return FALSE; 2569 return FALSE;
2570 } 2570 }
2571 } 2571 }
2572 if (!GetCharAt(pos, byte)) { 2572 if (!GetCharAt(pos, byte)) {
2573 return FALSE; 2573 return FALSE;
2574 } 2574 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2613 return FALSE; 2613 return FALSE;
2614 } 2614 }
2615 } 2615 }
2616 return FALSE; 2616 return FALSE;
2617 } 2617 }
2618 struct _SearchTagRecord { 2618 struct _SearchTagRecord {
2619 FX_LPCBYTE m_pTag; 2619 FX_LPCBYTE m_pTag;
2620 FX_DWORD m_Len; 2620 FX_DWORD m_Len;
2621 FX_DWORD m_Offset; 2621 FX_DWORD m_Offset;
2622 }; 2622 };
2623 FX_INT32 CPDF_SyntaxParser::SearchMultiWord(FX_BSTR tags, FX_BOOL bWholeWord, FX _FILESIZE limit) 2623 int32_t CPDF_SyntaxParser::SearchMultiWord(FX_BSTR tags, FX_BOOL bWholeWord, FX_ FILESIZE limit)
2624 { 2624 {
2625 FX_INT32 ntags = 1, i; 2625 int32_t ntags = 1, i;
2626 for (i = 0; i < tags.GetLength(); i ++) 2626 for (i = 0; i < tags.GetLength(); i ++)
2627 if (tags[i] == 0) { 2627 if (tags[i] == 0) {
2628 ntags ++; 2628 ntags ++;
2629 } 2629 }
2630 _SearchTagRecord* pPatterns = FX_Alloc(_SearchTagRecord, ntags); 2630 _SearchTagRecord* pPatterns = FX_Alloc(_SearchTagRecord, ntags);
2631 FX_DWORD start = 0, itag = 0, max_len = 0; 2631 FX_DWORD start = 0, itag = 0, max_len = 0;
2632 for (i = 0; i <= tags.GetLength(); i ++) { 2632 for (i = 0; i <= tags.GetLength(); i ++) {
2633 if (tags[i] == 0) { 2633 if (tags[i] == 0) {
2634 FX_DWORD len = i - start; 2634 FX_DWORD len = i - start;
2635 if (len > max_len) { 2635 if (len > max_len) {
2636 max_len = len; 2636 max_len = len;
2637 } 2637 }
2638 pPatterns[itag].m_pTag = tags.GetPtr() + start; 2638 pPatterns[itag].m_pTag = tags.GetPtr() + start;
2639 pPatterns[itag].m_Len = len; 2639 pPatterns[itag].m_Len = len;
2640 pPatterns[itag].m_Offset = 0; 2640 pPatterns[itag].m_Offset = 0;
2641 start = i + 1; 2641 start = i + 1;
2642 itag ++; 2642 itag ++;
2643 } 2643 }
2644 } 2644 }
2645 FX_FILESIZE pos = m_Pos; 2645 FX_FILESIZE pos = m_Pos;
2646 FX_BYTE byte; 2646 uint8_t byte;
2647 GetCharAt(pos++, byte); 2647 GetCharAt(pos++, byte);
2648 FX_INT32 found = -1; 2648 int32_t found = -1;
2649 while (1) { 2649 while (1) {
2650 for (i = 0; i < ntags; i ++) { 2650 for (i = 0; i < ntags; i ++) {
2651 if (pPatterns[i].m_pTag[pPatterns[i].m_Offset] == byte) { 2651 if (pPatterns[i].m_pTag[pPatterns[i].m_Offset] == byte) {
2652 pPatterns[i].m_Offset ++; 2652 pPatterns[i].m_Offset ++;
2653 if (pPatterns[i].m_Offset == pPatterns[i].m_Len) { 2653 if (pPatterns[i].m_Offset == pPatterns[i].m_Len) {
2654 if (!bWholeWord || IsWholeWord(pos - pPatterns[i].m_Len, lim it, pPatterns[i].m_pTag, pPatterns[i].m_Len)) { 2654 if (!bWholeWord || IsWholeWord(pos - pPatterns[i].m_Len, lim it, pPatterns[i].m_pTag, pPatterns[i].m_Len)) {
2655 found = i; 2655 found = i;
2656 goto end; 2656 goto end;
2657 } else { 2657 } else {
2658 if (pPatterns[i].m_pTag[0] == byte) { 2658 if (pPatterns[i].m_pTag[0] == byte) {
(...skipping 18 matching lines...) Expand all
2677 goto end; 2677 goto end;
2678 } 2678 }
2679 pos ++; 2679 pos ++;
2680 } 2680 }
2681 end: 2681 end:
2682 FX_Free(pPatterns); 2682 FX_Free(pPatterns);
2683 return found; 2683 return found;
2684 } 2684 }
2685 FX_FILESIZE CPDF_SyntaxParser::FindTag(FX_BSTR tag, FX_FILESIZE limit) 2685 FX_FILESIZE CPDF_SyntaxParser::FindTag(FX_BSTR tag, FX_FILESIZE limit)
2686 { 2686 {
2687 FX_INT32 taglen = tag.GetLength(); 2687 int32_t taglen = tag.GetLength();
2688 FX_INT32 match = 0; 2688 int32_t match = 0;
2689 limit += m_Pos; 2689 limit += m_Pos;
2690 FX_FILESIZE startpos = m_Pos; 2690 FX_FILESIZE startpos = m_Pos;
2691 while (1) { 2691 while (1) {
2692 FX_BYTE ch; 2692 uint8_t ch;
2693 if (!GetNextChar(ch)) { 2693 if (!GetNextChar(ch)) {
2694 return -1; 2694 return -1;
2695 } 2695 }
2696 if (ch == tag[match]) { 2696 if (ch == tag[match]) {
2697 match ++; 2697 match ++;
2698 if (match == taglen) { 2698 if (match == taglen) {
2699 return m_Pos - startpos - taglen; 2699 return m_Pos - startpos - taglen;
2700 } 2700 }
2701 } else { 2701 } else {
2702 match = ch == tag[0] ? 1 : 0; 2702 match = ch == tag[0] ? 1 : 0;
2703 } 2703 }
2704 if (limit && m_Pos == limit) { 2704 if (limit && m_Pos == limit) {
2705 return -1; 2705 return -1;
2706 } 2706 }
2707 } 2707 }
2708 return -1; 2708 return -1;
2709 } 2709 }
2710 void CPDF_SyntaxParser::GetBinary(FX_BYTE* buffer, FX_DWORD size) 2710 void CPDF_SyntaxParser::GetBinary(uint8_t* buffer, FX_DWORD size)
2711 { 2711 {
2712 FX_DWORD offset = 0; 2712 FX_DWORD offset = 0;
2713 FX_BYTE ch; 2713 uint8_t ch;
2714 while (1) { 2714 while (1) {
2715 if (!GetNextChar(ch)) { 2715 if (!GetNextChar(ch)) {
2716 return; 2716 return;
2717 } 2717 }
2718 buffer[offset++] = ch; 2718 buffer[offset++] = ch;
2719 if (offset == size) { 2719 if (offset == size) {
2720 break; 2720 break;
2721 } 2721 }
2722 } 2722 }
2723 } 2723 }
2724 2724
2725 class CPDF_DataAvail final : public IPDF_DataAvail 2725 class CPDF_DataAvail final : public IPDF_DataAvail
2726 { 2726 {
2727 public: 2727 public:
2728 CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); 2728 CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead);
2729 ~CPDF_DataAvail(); 2729 ~CPDF_DataAvail();
2730 2730
2731 virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) o verride; 2731 virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) o verride;
2732 2732
2733 virtual void SetDocument(CPDF_Document* pDoc) overri de; 2733 virtual void SetDocument(CPDF_Document* pDoc) overri de;
2734 2734
2735 virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints * pHints) override; 2735 virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints * pHints) override;
2736 2736
2737 virtual FX_INT32 IsFormAvail(IFX_DownloadHints *pHints) override; 2737 virtual int32_t IsFormAvail(IFX_DownloadHints *pHints) override;
2738 2738
2739 virtual FX_INT32 IsLinearizedPDF() override; 2739 virtual int32_t IsLinearizedPDF() override;
2740 2740
2741 virtual FX_BOOL IsLinearized() override 2741 virtual FX_BOOL IsLinearized() override
2742 { 2742 {
2743 return m_bLinearized; 2743 return m_bLinearized;
2744 } 2744 }
2745 2745
2746 virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *p Pos, FX_DWORD *pSize) override; 2746 virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *p Pos, FX_DWORD *pSize) override;
2747 2747
2748 protected: 2748 protected:
2749 static const int kMaxDataAvailRecursionDepth = 64; 2749 static const int kMaxDataAvailRecursionDepth = 64;
(...skipping 13 matching lines...) Expand all
2763 FX_BOOL CheckPages(IFX_DownloadHints* pHints); 2763 FX_BOOL CheckPages(IFX_DownloadHints* pHints);
2764 FX_BOOL CheckPage(IFX_DownloadHints* pHints); 2764 FX_BOOL CheckPage(IFX_DownloadHints* pHints);
2765 FX_BOOL CheckResources(IFX_DownloadHints* pHints ); 2765 FX_BOOL CheckResources(IFX_DownloadHints* pHints );
2766 FX_BOOL CheckAnnots(IFX_DownloadHints* pHints); 2766 FX_BOOL CheckAnnots(IFX_DownloadHints* pHints);
2767 FX_BOOL CheckAcroForm(IFX_DownloadHints* pHints) ; 2767 FX_BOOL CheckAcroForm(IFX_DownloadHints* pHints) ;
2768 FX_BOOL CheckAcroFormSubObject(IFX_DownloadHints * pHints); 2768 FX_BOOL CheckAcroFormSubObject(IFX_DownloadHints * pHints);
2769 FX_BOOL CheckTrailerAppend(IFX_DownloadHints* pH ints); 2769 FX_BOOL CheckTrailerAppend(IFX_DownloadHints* pH ints);
2770 FX_BOOL CheckPageStatus(IFX_DownloadHints* pHint s); 2770 FX_BOOL CheckPageStatus(IFX_DownloadHints* pHint s);
2771 FX_BOOL CheckAllCrossRefStream(IFX_DownloadHints *pHints); 2771 FX_BOOL CheckAllCrossRefStream(IFX_DownloadHints *pHints);
2772 2772
2773 FX_INT32 CheckCrossRefStream(IFX_DownloadHints *p Hints, FX_FILESIZE &xref_offset); 2773 int32_t CheckCrossRefStream(IFX_DownloadHints *pH ints, FX_FILESIZE &xref_offset);
2774 FX_BOOL IsLinearizedFile(FX_LPBYTE pData, FX_DWO RD dwLen); 2774 FX_BOOL IsLinearizedFile(FX_LPBYTE pData, FX_DWO RD dwLen);
2775 void SetStartOffset(FX_FILESIZE dwOffset); 2775 void SetStartOffset(FX_FILESIZE dwOffset);
2776 FX_BOOL GetNextToken(CFX_ByteString &token); 2776 FX_BOOL GetNextToken(CFX_ByteString &token);
2777 FX_BOOL GetNextChar(FX_BYTE &ch); 2777 FX_BOOL GetNextChar(uint8_t &ch);
2778 CPDF_Object * ParseIndirectObjectAt(FX_FILESIZE pos, F X_DWORD objnum); 2778 CPDF_Object * ParseIndirectObjectAt(FX_FILESIZE pos, F X_DWORD objnum);
2779 CPDF_Object * GetObject(FX_DWORD objnum, IFX_DownloadH ints* pHints, FX_BOOL *pExistInFile); 2779 CPDF_Object * GetObject(FX_DWORD objnum, IFX_DownloadH ints* pHints, FX_BOOL *pExistInFile);
2780 FX_BOOL GetPageKids(CPDF_Parser *pParser, CPDF_O bject *pPages); 2780 FX_BOOL GetPageKids(CPDF_Parser *pParser, CPDF_O bject *pPages);
2781 FX_BOOL PreparePageItem(); 2781 FX_BOOL PreparePageItem();
2782 FX_BOOL LoadPages(IFX_DownloadHints* pHints); 2782 FX_BOOL LoadPages(IFX_DownloadHints* pHints);
2783 FX_BOOL LoadAllXref(IFX_DownloadHints* pHints); 2783 FX_BOOL LoadAllXref(IFX_DownloadHints* pHints);
2784 FX_BOOL LoadAllFile(IFX_DownloadHints* pHints); 2784 FX_BOOL LoadAllFile(IFX_DownloadHints* pHints);
2785 FX_BOOL CheckLinearizedData(IFX_DownloadHints* p Hints); 2785 FX_BOOL CheckLinearizedData(IFX_DownloadHints* p Hints);
2786 FX_BOOL CheckFileResources(IFX_DownloadHints* pH ints); 2786 FX_BOOL CheckFileResources(IFX_DownloadHints* pH ints);
2787 FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadH ints* pHints); 2787 FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadH ints* pHints);
2788 2788
2789 FX_BOOL CheckLinearizedFirstPage(int iPage, IFX_ DownloadHints* pHints); 2789 FX_BOOL CheckLinearizedFirstPage(int iPage, IFX_ DownloadHints* pHints);
2790 FX_BOOL HaveResourceAncestor(CPDF_Dictionary *pD ict); 2790 FX_BOOL HaveResourceAncestor(CPDF_Dictionary *pD ict);
2791 FX_BOOL CheckPage(FX_INT32 iPage, IFX_DownloadHi nts* pHints); 2791 FX_BOOL CheckPage(int32_t iPage, IFX_DownloadHin ts* pHints);
2792 FX_BOOL LoadDocPages(IFX_DownloadHints* pHints); 2792 FX_BOOL LoadDocPages(IFX_DownloadHints* pHints);
2793 FX_BOOL LoadDocPage(FX_INT32 iPage, IFX_Download Hints* pHints); 2793 FX_BOOL LoadDocPage(int32_t iPage, IFX_DownloadH ints* pHints);
2794 FX_BOOL CheckPageNode(CPDF_PageNode &pageNodes, FX_INT32 iPage, FX_INT32 &iCount, IFX_DownloadHints* pHints); 2794 FX_BOOL CheckPageNode(CPDF_PageNode &pageNodes, int32_t iPage, int32_t &iCount, IFX_DownloadHints* pHints);
2795 FX_BOOL CheckUnkownPageNode(FX_DWORD dwPageNo, C PDF_PageNode *pPageNode, IFX_DownloadHints* pHints); 2795 FX_BOOL CheckUnkownPageNode(FX_DWORD dwPageNo, C PDF_PageNode *pPageNode, IFX_DownloadHints* pHints);
2796 FX_BOOL CheckArrayPageNode(FX_DWORD dwPageNo, CP DF_PageNode *pPageNode, IFX_DownloadHints* pHints); 2796 FX_BOOL CheckArrayPageNode(FX_DWORD dwPageNo, CP DF_PageNode *pPageNode, IFX_DownloadHints* pHints);
2797 FX_BOOL CheckPageCount(IFX_DownloadHints* pHints ); 2797 FX_BOOL CheckPageCount(IFX_DownloadHints* pHints );
2798 FX_BOOL IsFirstCheck(int iPage); 2798 FX_BOOL IsFirstCheck(int iPage);
2799 void ResetFirstCheck(int iPage); 2799 void ResetFirstCheck(int iPage);
2800 2800
2801 CPDF_Parser m_parser; 2801 CPDF_Parser m_parser;
2802 2802
2803 CPDF_SyntaxParser m_syntaxParser; 2803 CPDF_SyntaxParser m_syntaxParser;
2804 2804
(...skipping 30 matching lines...) Expand all
2835 CFX_PtrArray m_objs_array; 2835 CFX_PtrArray m_objs_array;
2836 2836
2837 FX_FILESIZE m_Pos; 2837 FX_FILESIZE m_Pos;
2838 2838
2839 FX_FILESIZE m_bufferOffset; 2839 FX_FILESIZE m_bufferOffset;
2840 2840
2841 FX_DWORD m_bufferSize; 2841 FX_DWORD m_bufferSize;
2842 2842
2843 CFX_ByteString m_WordBuf; 2843 CFX_ByteString m_WordBuf;
2844 2844
2845 FX_BYTE m_WordBuffer[257]; 2845 uint8_t m_WordBuffer[257];
2846 2846
2847 FX_DWORD m_WordSize; 2847 FX_DWORD m_WordSize;
2848 2848
2849 FX_BYTE m_bufferData[512]; 2849 uint8_t m_bufferData[512];
2850 2850
2851 CFX_FileSizeArray m_CrossOffset; 2851 CFX_FileSizeArray m_CrossOffset;
2852 2852
2853 CFX_DWordArray m_XRefStreamList; 2853 CFX_DWordArray m_XRefStreamList;
2854 2854
2855 CFX_DWordArray m_PageObjList; 2855 CFX_DWordArray m_PageObjList;
2856 2856
2857 FX_DWORD m_PagesObjNum; 2857 FX_DWORD m_PagesObjNum;
2858 2858
2859 FX_BOOL m_bLinearized; 2859 FX_BOOL m_bLinearized;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2987 } 2987 }
2988 if (m_pTrailer) { 2988 if (m_pTrailer) {
2989 m_pTrailer->Release(); 2989 m_pTrailer->Release();
2990 } 2990 }
2991 if (m_pageMapCheckState) { 2991 if (m_pageMapCheckState) {
2992 delete m_pageMapCheckState; 2992 delete m_pageMapCheckState;
2993 } 2993 }
2994 if (m_pagesLoadState) { 2994 if (m_pagesLoadState) {
2995 delete m_pagesLoadState; 2995 delete m_pagesLoadState;
2996 } 2996 }
2997 FX_INT32 i = 0; 2997 int32_t i = 0;
2998 FX_INT32 iSize = m_arrayAcroforms.GetSize(); 2998 int32_t iSize = m_arrayAcroforms.GetSize();
2999 for (i = 0; i < iSize; ++i) { 2999 for (i = 0; i < iSize; ++i) {
3000 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); 3000 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release();
3001 } 3001 }
3002 } 3002 }
3003 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) 3003 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc)
3004 { 3004 {
3005 m_pDocument = pDoc; 3005 m_pDocument = pDoc;
3006 } 3006 }
3007 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) 3007 FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset)
3008 { 3008 {
(...skipping 23 matching lines...) Expand all
3032 } 3032 }
3033 return 0; 3033 return 0;
3034 } 3034 }
3035 FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePa ge, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array) 3035 FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePa ge, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array)
3036 { 3036 {
3037 if (!obj_array.GetSize()) { 3037 if (!obj_array.GetSize()) {
3038 return TRUE; 3038 return TRUE;
3039 } 3039 }
3040 FX_DWORD count = 0; 3040 FX_DWORD count = 0;
3041 CFX_PtrArray new_obj_array; 3041 CFX_PtrArray new_obj_array;
3042 FX_INT32 i = 0; 3042 int32_t i = 0;
3043 for (i = 0; i < obj_array.GetSize(); i++) { 3043 for (i = 0; i < obj_array.GetSize(); i++) {
3044 CPDF_Object *pObj = (CPDF_Object *)obj_array[i]; 3044 CPDF_Object *pObj = (CPDF_Object *)obj_array[i];
3045 if (!pObj) { 3045 if (!pObj) {
3046 continue; 3046 continue;
3047 } 3047 }
3048 FX_INT32 type = pObj->GetType(); 3048 int32_t type = pObj->GetType();
3049 switch (type) { 3049 switch (type) {
3050 case PDFOBJ_ARRAY: { 3050 case PDFOBJ_ARRAY: {
3051 CPDF_Array *pArray = pObj->GetArray(); 3051 CPDF_Array *pArray = pObj->GetArray();
3052 for (FX_DWORD k = 0; k < pArray->GetCount(); k++) { 3052 for (FX_DWORD k = 0; k < pArray->GetCount(); k++) {
3053 new_obj_array.Add(pArray->GetElement(k)); 3053 new_obj_array.Add(pArray->GetElement(k));
3054 } 3054 }
3055 } 3055 }
3056 break; 3056 break;
3057 case PDFOBJ_STREAM: 3057 case PDFOBJ_STREAM:
3058 pObj = pObj->GetDict(); 3058 pObj = pObj->GetDict();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3104 CPDF_Object *pReferred = m_pDocument->GetIndirectObject( pRef->GetRefObjNum(), NULL); 3104 CPDF_Object *pReferred = m_pDocument->GetIndirectObject( pRef->GetRefObjNum(), NULL);
3105 if (pReferred) { 3105 if (pReferred) {
3106 new_obj_array.Add(pReferred); 3106 new_obj_array.Add(pReferred);
3107 } 3107 }
3108 } 3108 }
3109 } 3109 }
3110 break; 3110 break;
3111 } 3111 }
3112 } 3112 }
3113 if (count > 0) { 3113 if (count > 0) {
3114 FX_INT32 iSize = new_obj_array.GetSize(); 3114 int32_t iSize = new_obj_array.GetSize();
3115 for (i = 0; i < iSize; ++i) { 3115 for (i = 0; i < iSize; ++i) {
3116 CPDF_Object *pObj = (CPDF_Object *)new_obj_array[i]; 3116 CPDF_Object *pObj = (CPDF_Object *)new_obj_array[i];
3117 FX_INT32 type = pObj->GetType(); 3117 int32_t type = pObj->GetType();
3118 if (type == PDFOBJ_REFERENCE) { 3118 if (type == PDFOBJ_REFERENCE) {
3119 CPDF_Reference *pRef = (CPDF_Reference *)pObj; 3119 CPDF_Reference *pRef = (CPDF_Reference *)pObj;
3120 FX_DWORD dwNum = pRef->GetRefObjNum(); 3120 FX_DWORD dwNum = pRef->GetRefObjNum();
3121 if (!m_objnum_array.Find(dwNum)) { 3121 if (!m_objnum_array.Find(dwNum)) {
3122 ret_array.Add(pObj); 3122 ret_array.Add(pObj);
3123 } 3123 }
3124 } else { 3124 } else {
3125 ret_array.Add(pObj); 3125 ret_array.Add(pObj);
3126 } 3126 }
3127 } 3127 }
(...skipping 27 matching lines...) Expand all
3155 obj_array.Append(m_arrayAcroforms); 3155 obj_array.Append(m_arrayAcroforms);
3156 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); 3156 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array);
3157 if (bRet) { 3157 if (bRet) {
3158 m_objs_array.RemoveAll(); 3158 m_objs_array.RemoveAll();
3159 } 3159 }
3160 return bRet; 3160 return bRet;
3161 } else { 3161 } else {
3162 CFX_PtrArray new_objs_array; 3162 CFX_PtrArray new_objs_array;
3163 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra y); 3163 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra y);
3164 if (bRet) { 3164 if (bRet) {
3165 FX_INT32 iSize = m_arrayAcroforms.GetSize(); 3165 int32_t iSize = m_arrayAcroforms.GetSize();
3166 for (FX_INT32 i = 0; i < iSize; ++i) { 3166 for (int32_t i = 0; i < iSize; ++i) {
3167 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); 3167 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release();
3168 } 3168 }
3169 m_arrayAcroforms.RemoveAll(); 3169 m_arrayAcroforms.RemoveAll();
3170 } else { 3170 } else {
3171 m_objs_array.RemoveAll(); 3171 m_objs_array.RemoveAll();
3172 m_objs_array.Append(new_objs_array); 3172 m_objs_array.Append(new_objs_array);
3173 } 3173 }
3174 return bRet; 3174 return bRet;
3175 } 3175 }
3176 } 3176 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
3468 CPDF_Object *pObj = GetObject(dwPageObjNum, pHints, &bExist); 3468 CPDF_Object *pObj = GetObject(dwPageObjNum, pHints, &bExist);
3469 if (!pObj) { 3469 if (!pObj) {
3470 if (bExist) { 3470 if (bExist) {
3471 UnavailObjList.Add(dwPageObjNum); 3471 UnavailObjList.Add(dwPageObjNum);
3472 } 3472 }
3473 continue; 3473 continue;
3474 } 3474 }
3475 if (pObj->GetType() == PDFOBJ_ARRAY) { 3475 if (pObj->GetType() == PDFOBJ_ARRAY) {
3476 CPDF_Array *pArray = pObj->GetArray(); 3476 CPDF_Array *pArray = pObj->GetArray();
3477 if (pArray) { 3477 if (pArray) {
3478 FX_INT32 iSize = pArray->GetCount(); 3478 int32_t iSize = pArray->GetCount();
3479 CPDF_Object *pItem = NULL; 3479 CPDF_Object *pItem = NULL;
3480 for (FX_INT32 j = 0; j < iSize; ++j) { 3480 for (int32_t j = 0; j < iSize; ++j) {
3481 pItem = pArray->GetElement(j); 3481 pItem = pArray->GetElement(j);
3482 if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) { 3482 if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) {
3483 UnavailObjList.Add(((CPDF_Reference *)pItem)->GetRefObjN um()); 3483 UnavailObjList.Add(((CPDF_Reference *)pItem)->GetRefObjN um());
3484 } 3484 }
3485 } 3485 }
3486 } 3486 }
3487 } 3487 }
3488 if (pObj->GetType() != PDFOBJ_DICTIONARY) { 3488 if (pObj->GetType() != PDFOBJ_DICTIONARY) {
3489 pObj->Release(); 3489 pObj->Release();
3490 continue; 3490 continue;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3582 m_docStatus = PDF_DATAAVAIL_PAGE; 3582 m_docStatus = PDF_DATAAVAIL_PAGE;
3583 return TRUE; 3583 return TRUE;
3584 } 3584 }
3585 FX_BOOL CPDF_DataAvail::CheckHeader(IFX_DownloadHints* pHints) 3585 FX_BOOL CPDF_DataAvail::CheckHeader(IFX_DownloadHints* pHints)
3586 { 3586 {
3587 FX_DWORD req_size = 1024; 3587 FX_DWORD req_size = 1024;
3588 if ((FX_FILESIZE)req_size > m_dwFileLen) { 3588 if ((FX_FILESIZE)req_size > m_dwFileLen) {
3589 req_size = (FX_DWORD)m_dwFileLen; 3589 req_size = (FX_DWORD)m_dwFileLen;
3590 } 3590 }
3591 if (m_pFileAvail->IsDataAvail(0, req_size)) { 3591 if (m_pFileAvail->IsDataAvail(0, req_size)) {
3592 FX_BYTE buffer[1024]; 3592 uint8_t buffer[1024];
3593 m_pFileRead->ReadBlock(buffer, 0, req_size); 3593 m_pFileRead->ReadBlock(buffer, 0, req_size);
3594 if (IsLinearizedFile(buffer, req_size)) { 3594 if (IsLinearizedFile(buffer, req_size)) {
3595 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE; 3595 m_docStatus = PDF_DATAAVAIL_FIRSTPAGE;
3596 } else { 3596 } else {
3597 if (m_docStatus == PDF_DATAAVAIL_ERROR) { 3597 if (m_docStatus == PDF_DATAAVAIL_ERROR) {
3598 return FALSE; 3598 return FALSE;
3599 } 3599 }
3600 m_docStatus = PDF_DATAAVAIL_END; 3600 m_docStatus = PDF_DATAAVAIL_END;
3601 } 3601 }
3602 return TRUE; 3602 return TRUE;
(...skipping 19 matching lines...) Expand all
3622 m_docStatus = PDF_DATAAVAIL_ERROR; 3622 m_docStatus = PDF_DATAAVAIL_ERROR;
3623 return FALSE; 3623 return FALSE;
3624 } 3624 }
3625 FX_BOOL bNeedDownLoad = FALSE; 3625 FX_BOOL bNeedDownLoad = FALSE;
3626 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) { 3626 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) {
3627 FX_DWORD dwEnd = pEndOffSet->GetInteger(); 3627 FX_DWORD dwEnd = pEndOffSet->GetInteger();
3628 dwEnd += 512; 3628 dwEnd += 512;
3629 if ((FX_FILESIZE)dwEnd > m_dwFileLen) { 3629 if ((FX_FILESIZE)dwEnd > m_dwFileLen) {
3630 dwEnd = (FX_DWORD)m_dwFileLen; 3630 dwEnd = (FX_DWORD)m_dwFileLen;
3631 } 3631 }
3632 FX_INT32 iStartPos = (FX_INT32)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen) ; 3632 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen);
3633 FX_INT32 iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; 3633 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0;
3634 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { 3634 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) {
3635 pHints->AddSegment(iStartPos, iSize); 3635 pHints->AddSegment(iStartPos, iSize);
3636 bNeedDownLoad = TRUE; 3636 bNeedDownLoad = TRUE;
3637 } 3637 }
3638 } 3638 }
3639 m_dwLastXRefOffset = 0; 3639 m_dwLastXRefOffset = 0;
3640 FX_FILESIZE dwFileLen = 0; 3640 FX_FILESIZE dwFileLen = 0;
3641 if (pXRefOffset->GetType() == PDFOBJ_NUMBER) { 3641 if (pXRefOffset->GetType() == PDFOBJ_NUMBER) {
3642 m_dwLastXRefOffset = pXRefOffset->GetInteger(); 3642 m_dwLastXRefOffset = pXRefOffset->GetInteger();
3643 } 3643 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3683 } 3683 }
3684 FX_DWORD gennum = FXSYS_atoi(word); 3684 FX_DWORD gennum = FXSYS_atoi(word);
3685 if (m_syntaxParser.GetKeyword() != FX_BSTRC("obj")) { 3685 if (m_syntaxParser.GetKeyword() != FX_BSTRC("obj")) {
3686 m_syntaxParser.RestorePos(SavedPos); 3686 m_syntaxParser.RestorePos(SavedPos);
3687 return NULL; 3687 return NULL;
3688 } 3688 }
3689 CPDF_Object* pObj = m_syntaxParser.GetObject(NULL, objnum, gennum, 0); 3689 CPDF_Object* pObj = m_syntaxParser.GetObject(NULL, objnum, gennum, 0);
3690 m_syntaxParser.RestorePos(SavedPos); 3690 m_syntaxParser.RestorePos(SavedPos);
3691 return pObj; 3691 return pObj;
3692 } 3692 }
3693 FX_INT32 CPDF_DataAvail::IsLinearizedPDF() 3693 int32_t CPDF_DataAvail::IsLinearizedPDF()
3694 { 3694 {
3695 FX_DWORD req_size = 1024; 3695 FX_DWORD req_size = 1024;
3696 if (!m_pFileAvail->IsDataAvail(0, req_size)) { 3696 if (!m_pFileAvail->IsDataAvail(0, req_size)) {
3697 return PDF_UNKNOW_LINEARIZED; 3697 return PDF_UNKNOW_LINEARIZED;
3698 } 3698 }
3699 if (!m_pFileRead) { 3699 if (!m_pFileRead) {
3700 return PDF_NOT_LINEARIZED; 3700 return PDF_NOT_LINEARIZED;
3701 } 3701 }
3702 FX_FILESIZE dwSize = m_pFileRead->GetSize(); 3702 FX_FILESIZE dwSize = m_pFileRead->GetSize();
3703 if (dwSize < (FX_FILESIZE)req_size) { 3703 if (dwSize < (FX_FILESIZE)req_size) {
3704 return PDF_UNKNOW_LINEARIZED; 3704 return PDF_UNKNOW_LINEARIZED;
3705 } 3705 }
3706 FX_BYTE buffer[1024]; 3706 uint8_t buffer[1024];
3707 m_pFileRead->ReadBlock(buffer, 0, req_size); 3707 m_pFileRead->ReadBlock(buffer, 0, req_size);
3708 if (IsLinearizedFile(buffer, req_size)) { 3708 if (IsLinearizedFile(buffer, req_size)) {
3709 return PDF_IS_LINEARIZED; 3709 return PDF_IS_LINEARIZED;
3710 } 3710 }
3711 return PDF_NOT_LINEARIZED; 3711 return PDF_NOT_LINEARIZED;
3712 } 3712 }
3713 FX_BOOL CPDF_DataAvail::IsLinearizedFile(FX_LPBYTE pData, FX_DWORD dwLen) 3713 FX_BOOL CPDF_DataAvail::IsLinearizedFile(FX_LPBYTE pData, FX_DWORD dwLen)
3714 { 3714 {
3715 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pData, (size_t)d wLen, FALSE)); 3715 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pData, (size_t)d wLen, FALSE));
3716 FX_INT32 offset = GetHeaderOffset(file.Get()); 3716 int32_t offset = GetHeaderOffset(file.Get());
3717 if (offset == -1) { 3717 if (offset == -1) {
3718 m_docStatus = PDF_DATAAVAIL_ERROR; 3718 m_docStatus = PDF_DATAAVAIL_ERROR;
3719 return FALSE; 3719 return FALSE;
3720 } 3720 }
3721 m_dwHeaderOffset = offset; 3721 m_dwHeaderOffset = offset;
3722 m_syntaxParser.InitParser(file.Get(), offset); 3722 m_syntaxParser.InitParser(file.Get(), offset);
3723 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); 3723 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9);
3724 FX_BOOL bNumber = FALSE; 3724 FX_BOOL bNumber = FALSE;
3725 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(bNumber); 3725 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(bNumber);
3726 if (!bNumber) { 3726 if (!bNumber) {
(...skipping 23 matching lines...) Expand all
3750 } 3750 }
3751 return TRUE; 3751 return TRUE;
3752 } 3752 }
3753 return FALSE; 3753 return FALSE;
3754 } 3754 }
3755 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) 3755 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints)
3756 { 3756 {
3757 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); 3757 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0);
3758 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); 3758 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos);
3759 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { 3759 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) {
3760 FX_BYTE buffer[1024]; 3760 uint8_t buffer[1024];
3761 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); 3761 m_pFileRead->ReadBlock(buffer, req_pos, dwSize);
3762 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(buffer, (siz e_t)dwSize, FALSE)); 3762 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(buffer, (siz e_t)dwSize, FALSE));
3763 m_syntaxParser.InitParser(file.Get(), 0); 3763 m_syntaxParser.InitParser(file.Get(), 0);
3764 m_syntaxParser.RestorePos(dwSize - 1); 3764 m_syntaxParser.RestorePos(dwSize - 1);
3765 if (m_syntaxParser.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, dwSize )) { 3765 if (m_syntaxParser.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, dwSize )) {
3766 FX_BOOL bNumber; 3766 FX_BOOL bNumber;
3767 m_syntaxParser.GetNextWord(bNumber); 3767 m_syntaxParser.GetNextWord(bNumber);
3768 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(bNumber); 3768 CFX_ByteString xrefpos_str = m_syntaxParser.GetNextWord(bNumber);
3769 if (!bNumber) { 3769 if (!bNumber) {
3770 m_docStatus = PDF_DATAAVAIL_ERROR; 3770 m_docStatus = PDF_DATAAVAIL_ERROR;
3771 return FALSE; 3771 return FALSE;
3772 } 3772 }
3773 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); 3773 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str);
3774 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { 3774 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) {
3775 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 3775 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
3776 return TRUE; 3776 return TRUE;
3777 } 3777 }
3778 m_dwLastXRefOffset = m_dwXRefOffset; 3778 m_dwLastXRefOffset = m_dwXRefOffset;
3779 SetStartOffset(m_dwXRefOffset); 3779 SetStartOffset(m_dwXRefOffset);
3780 m_docStatus = PDF_DATAAVAIL_CROSSREF; 3780 m_docStatus = PDF_DATAAVAIL_CROSSREF;
3781 return TRUE; 3781 return TRUE;
3782 } else { 3782 } else {
3783 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 3783 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
3784 return TRUE; 3784 return TRUE;
3785 } 3785 }
3786 } 3786 }
3787 pHints->AddSegment(req_pos, dwSize); 3787 pHints->AddSegment(req_pos, dwSize);
3788 return FALSE; 3788 return FALSE;
3789 } 3789 }
3790 FX_INT32 CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILES IZE &xref_offset) 3790 int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILESI ZE &xref_offset)
3791 { 3791 {
3792 xref_offset = 0; 3792 xref_offset = 0;
3793 FX_DWORD req_size = (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_P os : 512); 3793 FX_DWORD req_size = (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_P os : 512);
3794 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { 3794 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) {
3795 FX_INT32 iSize = (FX_INT32)(m_Pos + req_size - m_dwCurrentXRefSteam); 3795 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam);
3796 CFX_BinaryBuf buf(iSize); 3796 CFX_BinaryBuf buf(iSize);
3797 FX_LPBYTE pBuf = buf.GetBuffer(); 3797 FX_LPBYTE pBuf = buf.GetBuffer();
3798 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); 3798 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize);
3799 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_ t)iSize, FALSE)); 3799 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_ t)iSize, FALSE));
3800 m_parser.m_Syntax.InitParser(file.Get(), 0); 3800 m_parser.m_Syntax.InitParser(file.Get(), 0);
3801 FX_BOOL bNumber = FALSE; 3801 FX_BOOL bNumber = FALSE;
3802 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber); 3802 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(bNumber);
3803 if (!bNumber) { 3803 if (!bNumber) {
3804 return -1; 3804 return -1;
3805 } 3805 }
(...skipping 23 matching lines...) Expand all
3829 return 0; 3829 return 0;
3830 } 3830 }
3831 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) 3831 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset)
3832 { 3832 {
3833 m_Pos = dwOffset; 3833 m_Pos = dwOffset;
3834 } 3834 }
3835 #define MAX_WORD_BUFFER 256 3835 #define MAX_WORD_BUFFER 256
3836 FX_BOOL CPDF_DataAvail::GetNextToken(CFX_ByteString &token) 3836 FX_BOOL CPDF_DataAvail::GetNextToken(CFX_ByteString &token)
3837 { 3837 {
3838 m_WordSize = 0; 3838 m_WordSize = 0;
3839 FX_BYTE ch; 3839 uint8_t ch;
3840 if (!GetNextChar(ch)) { 3840 if (!GetNextChar(ch)) {
3841 return FALSE; 3841 return FALSE;
3842 } 3842 }
3843 FX_BYTE type = PDF_CharType[ch]; 3843 uint8_t type = PDF_CharType[ch];
3844 while (1) { 3844 while (1) {
3845 while (type == 'W') { 3845 while (type == 'W') {
3846 if (!GetNextChar(ch)) { 3846 if (!GetNextChar(ch)) {
3847 return FALSE; 3847 return FALSE;
3848 } 3848 }
3849 type = PDF_CharType[ch]; 3849 type = PDF_CharType[ch];
3850 } 3850 }
3851 if (ch != '%') { 3851 if (ch != '%') {
3852 break; 3852 break;
3853 } 3853 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3912 type = PDF_CharType[ch]; 3912 type = PDF_CharType[ch];
3913 if (type == 'D' || type == 'W') { 3913 if (type == 'D' || type == 'W') {
3914 m_Pos --; 3914 m_Pos --;
3915 break; 3915 break;
3916 } 3916 }
3917 } 3917 }
3918 CFX_ByteString ret(m_WordBuffer, m_WordSize); 3918 CFX_ByteString ret(m_WordBuffer, m_WordSize);
3919 token = ret; 3919 token = ret;
3920 return TRUE; 3920 return TRUE;
3921 } 3921 }
3922 FX_BOOL CPDF_DataAvail::GetNextChar(FX_BYTE &ch) 3922 FX_BOOL CPDF_DataAvail::GetNextChar(uint8_t &ch)
3923 { 3923 {
3924 FX_FILESIZE pos = m_Pos; 3924 FX_FILESIZE pos = m_Pos;
3925 if (pos >= m_dwFileLen) { 3925 if (pos >= m_dwFileLen) {
3926 return FALSE; 3926 return FALSE;
3927 } 3927 }
3928 if (m_bufferOffset >= pos || (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) { 3928 if (m_bufferOffset >= pos || (FX_FILESIZE)(m_bufferOffset + m_bufferSize) <= pos) {
3929 FX_FILESIZE read_pos = pos; 3929 FX_FILESIZE read_pos = pos;
3930 FX_DWORD read_size = 512; 3930 FX_DWORD read_size = 512;
3931 if ((FX_FILESIZE)read_size > m_dwFileLen) { 3931 if ((FX_FILESIZE)read_size > m_dwFileLen) {
3932 read_size = (FX_DWORD)m_dwFileLen; 3932 read_size = (FX_DWORD)m_dwFileLen;
3933 } 3933 }
3934 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) { 3934 if ((FX_FILESIZE)(read_pos + read_size) > m_dwFileLen) {
3935 read_pos = m_dwFileLen - read_size; 3935 read_pos = m_dwFileLen - read_size;
3936 } 3936 }
3937 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) { 3937 if (!m_pFileRead->ReadBlock(m_bufferData, read_pos, read_size)) {
3938 return FALSE; 3938 return FALSE;
3939 } 3939 }
3940 m_bufferOffset = read_pos; 3940 m_bufferOffset = read_pos;
3941 m_bufferSize = read_size; 3941 m_bufferSize = read_size;
3942 } 3942 }
3943 ch = m_bufferData[pos - m_bufferOffset]; 3943 ch = m_bufferData[pos - m_bufferOffset];
3944 m_Pos ++; 3944 m_Pos ++;
3945 return TRUE; 3945 return TRUE;
3946 } 3946 }
3947 FX_BOOL CPDF_DataAvail::CheckCrossRefItem(IFX_DownloadHints *pHints) 3947 FX_BOOL CPDF_DataAvail::CheckCrossRefItem(IFX_DownloadHints *pHints)
3948 { 3948 {
3949 FX_INT32 iSize = 0; 3949 int32_t iSize = 0;
3950 CFX_ByteString token; 3950 CFX_ByteString token;
3951 while (1) { 3951 while (1) {
3952 if (!GetNextToken(token)) { 3952 if (!GetNextToken(token)) {
3953 iSize = (FX_INT32)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); 3953 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512);
3954 pHints->AddSegment(m_Pos, iSize); 3954 pHints->AddSegment(m_Pos, iSize);
3955 return FALSE; 3955 return FALSE;
3956 } 3956 }
3957 if (token == "trailer") { 3957 if (token == "trailer") {
3958 m_dwTrailerOffset = m_Pos; 3958 m_dwTrailerOffset = m_Pos;
3959 m_docStatus = PDF_DATAAVAIL_TRAILER; 3959 m_docStatus = PDF_DATAAVAIL_TRAILER;
3960 return TRUE; 3960 return TRUE;
3961 } 3961 }
3962 } 3962 }
3963 } 3963 }
3964 FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints *pHints) 3964 FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints *pHints)
3965 { 3965 {
3966 FX_FILESIZE xref_offset = 0; 3966 FX_FILESIZE xref_offset = 0;
3967 FX_INT32 nRet = CheckCrossRefStream(pHints, xref_offset); 3967 int32_t nRet = CheckCrossRefStream(pHints, xref_offset);
3968 if (nRet == 1) { 3968 if (nRet == 1) {
3969 if (!xref_offset) { 3969 if (!xref_offset) {
3970 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; 3970 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF;
3971 } else { 3971 } else {
3972 m_dwCurrentXRefSteam = xref_offset; 3972 m_dwCurrentXRefSteam = xref_offset;
3973 m_Pos = xref_offset; 3973 m_Pos = xref_offset;
3974 } 3974 }
3975 return TRUE; 3975 return TRUE;
3976 } else if (nRet == -1) { 3976 } else if (nRet == -1) {
3977 m_docStatus = PDF_DATAAVAIL_ERROR; 3977 m_docStatus = PDF_DATAAVAIL_ERROR;
3978 } 3978 }
3979 return FALSE; 3979 return FALSE;
3980 } 3980 }
3981 FX_BOOL CPDF_DataAvail::CheckCrossRef(IFX_DownloadHints* pHints) 3981 FX_BOOL CPDF_DataAvail::CheckCrossRef(IFX_DownloadHints* pHints)
3982 { 3982 {
3983 FX_INT32 iSize = 0; 3983 int32_t iSize = 0;
3984 CFX_ByteString token; 3984 CFX_ByteString token;
3985 if (!GetNextToken(token)) { 3985 if (!GetNextToken(token)) {
3986 iSize = (FX_INT32)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512 ); 3986 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512) ;
3987 pHints->AddSegment(m_Pos, iSize); 3987 pHints->AddSegment(m_Pos, iSize);
3988 return FALSE; 3988 return FALSE;
3989 } 3989 }
3990 if (token == "xref") { 3990 if (token == "xref") {
3991 m_CrossOffset.InsertAt(0, m_dwXRefOffset); 3991 m_CrossOffset.InsertAt(0, m_dwXRefOffset);
3992 while (1) { 3992 while (1) {
3993 if (!GetNextToken(token)) { 3993 if (!GetNextToken(token)) {
3994 iSize = (FX_INT32)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_P os : 512); 3994 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Po s : 512);
3995 pHints->AddSegment(m_Pos, iSize); 3995 pHints->AddSegment(m_Pos, iSize);
3996 m_docStatus = PDF_DATAAVAIL_CROSSREF_ITEM; 3996 m_docStatus = PDF_DATAAVAIL_CROSSREF_ITEM;
3997 return FALSE; 3997 return FALSE;
3998 } 3998 }
3999 if (token == "trailer") { 3999 if (token == "trailer") {
4000 m_dwTrailerOffset = m_Pos; 4000 m_dwTrailerOffset = m_Pos;
4001 m_docStatus = PDF_DATAAVAIL_TRAILER; 4001 m_docStatus = PDF_DATAAVAIL_TRAILER;
4002 return TRUE; 4002 return TRUE;
4003 } 4003 }
4004 } 4004 }
4005 } else { 4005 } else {
4006 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 4006 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
4007 return TRUE; 4007 return TRUE;
4008 } 4008 }
4009 return FALSE; 4009 return FALSE;
4010 } 4010 }
4011 FX_BOOL CPDF_DataAvail::CheckTrailerAppend(IFX_DownloadHints* pHints) 4011 FX_BOOL CPDF_DataAvail::CheckTrailerAppend(IFX_DownloadHints* pHints)
4012 { 4012 {
4013 if (m_Pos < m_dwFileLen) { 4013 if (m_Pos < m_dwFileLen) {
4014 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos(); 4014 FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.SavePos();
4015 FX_INT32 iSize = (FX_INT32)(dwAppendPos + 512 > m_dwFileLen ? m_dwFileLe n - dwAppendPos : 512); 4015 int32_t iSize = (int32_t)(dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen - dwAppendPos : 512);
4016 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { 4016 if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) {
4017 pHints->AddSegment(dwAppendPos, iSize); 4017 pHints->AddSegment(dwAppendPos, iSize);
4018 return FALSE; 4018 return FALSE;
4019 } 4019 }
4020 } 4020 }
4021 if (m_dwPrevXRefOffset) { 4021 if (m_dwPrevXRefOffset) {
4022 SetStartOffset(m_dwPrevXRefOffset); 4022 SetStartOffset(m_dwPrevXRefOffset);
4023 m_docStatus = PDF_DATAAVAIL_CROSSREF; 4023 m_docStatus = PDF_DATAAVAIL_CROSSREF;
4024 } else { 4024 } else {
4025 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; 4025 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF;
4026 } 4026 }
4027 return TRUE; 4027 return TRUE;
4028 } 4028 }
4029 FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) 4029 FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints)
4030 { 4030 {
4031 FX_INT32 iTrailerSize = (FX_INT32)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); 4031 int32_t iTrailerSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m _Pos : 512);
4032 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { 4032 if (m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) {
4033 FX_INT32 iSize = (FX_INT32)(m_Pos + iTrailerSize - m_dwTrailerOffset); 4033 int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset);
4034 CFX_BinaryBuf buf(iSize); 4034 CFX_BinaryBuf buf(iSize);
4035 FX_LPBYTE pBuf = buf.GetBuffer(); 4035 FX_LPBYTE pBuf = buf.GetBuffer();
4036 if (!pBuf) { 4036 if (!pBuf) {
4037 m_docStatus = PDF_DATAAVAIL_ERROR; 4037 m_docStatus = PDF_DATAAVAIL_ERROR;
4038 return FALSE; 4038 return FALSE;
4039 } 4039 }
4040 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) { 4040 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) {
4041 return FALSE; 4041 return FALSE;
4042 } 4042 }
4043 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_ t)iSize, FALSE)); 4043 CFX_SmartPointer<IFX_FileStream> file(FX_CreateMemoryStream(pBuf, (size_ t)iSize, FALSE));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4079 } else { 4079 } else {
4080 m_dwPrevXRefOffset = 0; 4080 m_dwPrevXRefOffset = 0;
4081 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; 4081 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND;
4082 pTrailer->Release(); 4082 pTrailer->Release();
4083 } 4083 }
4084 return TRUE; 4084 return TRUE;
4085 } 4085 }
4086 pHints->AddSegment(m_Pos, iTrailerSize); 4086 pHints->AddSegment(m_Pos, iTrailerSize);
4087 return FALSE; 4087 return FALSE;
4088 } 4088 }
4089 FX_BOOL CPDF_DataAvail::CheckPage(FX_INT32 iPage, IFX_DownloadHints* pHints) 4089 FX_BOOL CPDF_DataAvail::CheckPage(int32_t iPage, IFX_DownloadHints* pHints)
4090 { 4090 {
4091 while (TRUE) { 4091 while (TRUE) {
4092 switch (m_docStatus) { 4092 switch (m_docStatus) {
4093 case PDF_DATAAVAIL_PAGETREE: 4093 case PDF_DATAAVAIL_PAGETREE:
4094 if (!LoadDocPages(pHints)) { 4094 if (!LoadDocPages(pHints)) {
4095 return FALSE; 4095 return FALSE;
4096 } 4096 }
4097 break; 4097 break;
4098 case PDF_DATAAVAIL_PAGE: 4098 case PDF_DATAAVAIL_PAGE:
4099 if (!LoadDocPage(iPage, pHints)) { 4099 if (!LoadDocPage(iPage, pHints)) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
4208 } else if (type == FX_BSTRC("Page")) { 4208 } else if (type == FX_BSTRC("Page")) {
4209 pPageNode->m_type = PDF_PAGENODE_PAGE; 4209 pPageNode->m_type = PDF_PAGENODE_PAGE;
4210 } else { 4210 } else {
4211 pPage->Release(); 4211 pPage->Release();
4212 m_docStatus = PDF_DATAAVAIL_ERROR; 4212 m_docStatus = PDF_DATAAVAIL_ERROR;
4213 return FALSE; 4213 return FALSE;
4214 } 4214 }
4215 pPage->Release(); 4215 pPage->Release();
4216 return TRUE; 4216 return TRUE;
4217 } 4217 }
4218 FX_BOOL CPDF_DataAvail::CheckPageNode(CPDF_PageNode &pageNodes, FX_INT32 iPage, FX_INT32 &iCount, IFX_DownloadHints* pHints) 4218 FX_BOOL CPDF_DataAvail::CheckPageNode(CPDF_PageNode &pageNodes, int32_t iPage, i nt32_t &iCount, IFX_DownloadHints* pHints)
4219 { 4219 {
4220 FX_INT32 iSize = pageNodes.m_childNode.GetSize(); 4220 int32_t iSize = pageNodes.m_childNode.GetSize();
4221 if (iSize <= 0 || iPage >= iSize) { 4221 if (iSize <= 0 || iPage >= iSize) {
4222 m_docStatus = PDF_DATAAVAIL_ERROR; 4222 m_docStatus = PDF_DATAAVAIL_ERROR;
4223 return FALSE; 4223 return FALSE;
4224 } 4224 }
4225 for (FX_INT32 i = 0; i < iSize; ++i) { 4225 for (int32_t i = 0; i < iSize; ++i) {
4226 CPDF_PageNode *pNode = (CPDF_PageNode*)pageNodes.m_childNode.GetAt(i); 4226 CPDF_PageNode *pNode = (CPDF_PageNode*)pageNodes.m_childNode.GetAt(i);
4227 if (!pNode) { 4227 if (!pNode) {
4228 continue; 4228 continue;
4229 } 4229 }
4230 switch (pNode->m_type) { 4230 switch (pNode->m_type) {
4231 case PDF_PAGENODE_UNKOWN: 4231 case PDF_PAGENODE_UNKOWN:
4232 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) { 4232 if (!CheckUnkownPageNode(pNode->m_dwPageNo, pNode, pHints)) {
4233 return FALSE; 4233 return FALSE;
4234 } 4234 }
4235 --i; 4235 --i;
(...skipping 16 matching lines...) Expand all
4252 --i; 4252 --i;
4253 break; 4253 break;
4254 } 4254 }
4255 if (iPage == iCount) { 4255 if (iPage == iCount) {
4256 m_docStatus = PDF_DATAAVAIL_DONE; 4256 m_docStatus = PDF_DATAAVAIL_DONE;
4257 return TRUE; 4257 return TRUE;
4258 } 4258 }
4259 } 4259 }
4260 return TRUE; 4260 return TRUE;
4261 } 4261 }
4262 FX_BOOL CPDF_DataAvail::LoadDocPage(FX_INT32 iPage, IFX_DownloadHints* pHints) 4262 FX_BOOL CPDF_DataAvail::LoadDocPage(int32_t iPage, IFX_DownloadHints* pHints)
4263 { 4263 {
4264 if (m_pDocument->GetPageCount() <= iPage || m_pDocument->m_PageList.GetAt(iP age)) { 4264 if (m_pDocument->GetPageCount() <= iPage || m_pDocument->m_PageList.GetAt(iP age)) {
4265 m_docStatus = PDF_DATAAVAIL_DONE; 4265 m_docStatus = PDF_DATAAVAIL_DONE;
4266 return TRUE; 4266 return TRUE;
4267 } 4267 }
4268 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) { 4268 if (m_pageNodes.m_type == PDF_PAGENODE_PAGE) {
4269 if (iPage == 0) { 4269 if (iPage == 0) {
4270 m_docStatus = PDF_DATAAVAIL_DONE; 4270 m_docStatus = PDF_DATAAVAIL_DONE;
4271 return TRUE; 4271 return TRUE;
4272 } 4272 }
4273 m_docStatus = PDF_DATAAVAIL_ERROR; 4273 m_docStatus = PDF_DATAAVAIL_ERROR;
4274 return TRUE; 4274 return TRUE;
4275 } 4275 }
4276 FX_INT32 iCount = -1; 4276 int32_t iCount = -1;
4277 return CheckPageNode(m_pageNodes, iPage, iCount, pHints); 4277 return CheckPageNode(m_pageNodes, iPage, iCount, pHints);
4278 } 4278 }
4279 FX_BOOL CPDF_DataAvail::CheckPageCount(IFX_DownloadHints* pHints) 4279 FX_BOOL CPDF_DataAvail::CheckPageCount(IFX_DownloadHints* pHints)
4280 { 4280 {
4281 FX_BOOL bExist = FALSE; 4281 FX_BOOL bExist = FALSE;
4282 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist); 4282 CPDF_Object *pPages = GetObject(m_PagesObjNum, pHints, &bExist);
4283 if (!bExist) { 4283 if (!bExist) {
4284 m_docStatus = PDF_DATAAVAIL_ERROR; 4284 m_docStatus = PDF_DATAAVAIL_ERROR;
4285 return FALSE; 4285 return FALSE;
4286 } 4286 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
4354 } 4354 }
4355 if (!PreparePageItem()) { 4355 if (!PreparePageItem()) {
4356 return FALSE; 4356 return FALSE;
4357 } 4357 }
4358 m_bMainXRefLoadedOK = TRUE; 4358 m_bMainXRefLoadedOK = TRUE;
4359 m_bLinearedDataOK = TRUE; 4359 m_bLinearedDataOK = TRUE;
4360 } 4360 }
4361 4361
4362 return m_bLinearedDataOK; 4362 return m_bLinearedDataOK;
4363 } 4363 }
4364 FX_BOOL CPDF_DataAvail::CheckPageAnnots(FX_INT32 iPage, IFX_DownloadHints* pHint s) 4364 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, IFX_DownloadHints* pHints )
4365 { 4365 {
4366 if (!m_objs_array.GetSize()) { 4366 if (!m_objs_array.GetSize()) {
4367 m_objs_array.RemoveAll(); 4367 m_objs_array.RemoveAll();
4368 m_objnum_array.RemoveAll(); 4368 m_objnum_array.RemoveAll();
4369 CPDF_Dictionary *pPageDict = m_pDocument->GetPage(iPage); 4369 CPDF_Dictionary *pPageDict = m_pDocument->GetPage(iPage);
4370 if (!pPageDict) { 4370 if (!pPageDict) {
4371 return TRUE; 4371 return TRUE;
4372 } 4372 }
4373 CPDF_Object *pAnnots = pPageDict->GetElement(FX_BSTRC("Annots")); 4373 CPDF_Object *pAnnots = pPageDict->GetElement(FX_BSTRC("Annots"));
4374 if (!pAnnots) { 4374 if (!pAnnots) {
4375 return TRUE; 4375 return TRUE;
4376 } 4376 }
4377 CFX_PtrArray obj_array; 4377 CFX_PtrArray obj_array;
4378 obj_array.Add(pAnnots); 4378 obj_array.Add(pAnnots);
4379 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); 4379 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array);
4380 if (bRet) { 4380 if (bRet) {
4381 m_objs_array.RemoveAll(); 4381 m_objs_array.RemoveAll();
4382 } 4382 }
4383 return bRet; 4383 return bRet;
4384 } else { 4384 } else {
4385 CFX_PtrArray new_objs_array; 4385 CFX_PtrArray new_objs_array;
4386 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra y); 4386 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra y);
4387 m_objs_array.RemoveAll(); 4387 m_objs_array.RemoveAll();
4388 if (!bRet) { 4388 if (!bRet) {
4389 m_objs_array.Append(new_objs_array); 4389 m_objs_array.Append(new_objs_array);
4390 } 4390 }
4391 return bRet; 4391 return bRet;
4392 } 4392 }
4393 } 4393 }
4394 FX_BOOL CPDF_DataAvail::CheckLinearizedFirstPage(FX_INT32 iPage, IFX_DownloadHin ts* pHints) 4394 FX_BOOL CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, IFX_DownloadHint s* pHints)
4395 { 4395 {
4396 if (!m_bAnnotsLoad) { 4396 if (!m_bAnnotsLoad) {
4397 if (!CheckPageAnnots(iPage, pHints)) { 4397 if (!CheckPageAnnots(iPage, pHints)) {
4398 return FALSE; 4398 return FALSE;
4399 } 4399 }
4400 m_bAnnotsLoad = TRUE; 4400 m_bAnnotsLoad = TRUE;
4401 } 4401 }
4402 if (m_bAnnotsLoad) 4402 if (m_bAnnotsLoad)
4403 if (!CheckLinearizedData(pHints)) { 4403 if (!CheckLinearizedData(pHints)) {
4404 return FALSE; 4404 return FALSE;
(...skipping 15 matching lines...) Expand all
4420 if (!pParentDict) { 4420 if (!pParentDict) {
4421 return FALSE; 4421 return FALSE;
4422 } 4422 }
4423 CPDF_Object *pRet = pParentDict->GetElement("Resources"); 4423 CPDF_Object *pRet = pParentDict->GetElement("Resources");
4424 if (pRet) { 4424 if (pRet) {
4425 m_pPageResource = pRet; 4425 m_pPageResource = pRet;
4426 return TRUE; 4426 return TRUE;
4427 } 4427 }
4428 return HaveResourceAncestor(pParentDict); 4428 return HaveResourceAncestor(pParentDict);
4429 } 4429 }
4430 FX_BOOL CPDF_DataAvail::IsPageAvail(FX_INT32 iPage, IFX_DownloadHints* pHints) 4430 FX_BOOL CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints)
4431 { 4431 {
4432 if (!m_pDocument) { 4432 if (!m_pDocument) {
4433 return FALSE; 4433 return FALSE;
4434 } 4434 }
4435 if (IsFirstCheck(iPage)) { 4435 if (IsFirstCheck(iPage)) {
4436 m_bCurPageDictLoadOK = FALSE; 4436 m_bCurPageDictLoadOK = FALSE;
4437 m_bPageLoadedOK = FALSE; 4437 m_bPageLoadedOK = FALSE;
4438 m_bAnnotsLoad = FALSE; 4438 m_bAnnotsLoad = FALSE;
4439 m_bNeedDownLoadResource = FALSE; 4439 m_bNeedDownLoadResource = FALSE;
4440 m_objs_array.RemoveAll(); 4440 m_objs_array.RemoveAll();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
4569 } 4569 }
4570 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSiz e) 4570 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSiz e)
4571 { 4571 {
4572 if (pPos) { 4572 if (pPos) {
4573 *pPos = m_dwLastXRefOffset; 4573 *pPos = m_dwLastXRefOffset;
4574 } 4574 }
4575 if (pSize) { 4575 if (pSize) {
4576 *pSize = (FX_DWORD)(m_dwFileLen - m_dwLastXRefOffset); 4576 *pSize = (FX_DWORD)(m_dwFileLen - m_dwLastXRefOffset);
4577 } 4577 }
4578 } 4578 }
4579 FX_INT32 CPDF_DataAvail::IsFormAvail(IFX_DownloadHints *pHints) 4579 int32_t CPDF_DataAvail::IsFormAvail(IFX_DownloadHints *pHints)
4580 { 4580 {
4581 if (!m_pDocument) { 4581 if (!m_pDocument) {
4582 return PDFFORM_AVAIL; 4582 return PDFFORM_AVAIL;
4583 } 4583 }
4584 if (!m_bLinearizedFormParamLoad) { 4584 if (!m_bLinearizedFormParamLoad) {
4585 CPDF_Dictionary *pRoot = m_pDocument->GetRoot(); 4585 CPDF_Dictionary *pRoot = m_pDocument->GetRoot();
4586 if (!pRoot) { 4586 if (!pRoot) {
4587 return PDFFORM_AVAIL; 4587 return PDFFORM_AVAIL;
4588 } 4588 }
4589 CPDF_Object *pAcroForm = pRoot->GetElement(FX_BSTRC("AcroForm")); 4589 CPDF_Object *pAcroForm = pRoot->GetElement(FX_BSTRC("AcroForm"));
(...skipping 12 matching lines...) Expand all
4602 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); 4602 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
4603 m_objs_array.RemoveAll(); 4603 m_objs_array.RemoveAll();
4604 if (!bRet) { 4604 if (!bRet) {
4605 m_objs_array.Append(new_objs_array); 4605 m_objs_array.Append(new_objs_array);
4606 return PDFFORM_NOTAVAIL; 4606 return PDFFORM_NOTAVAIL;
4607 } 4607 }
4608 return PDFFORM_AVAIL; 4608 return PDFFORM_AVAIL;
4609 } 4609 }
4610 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) 4610 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum)
4611 { 4611 {
4612 FX_INT32 iNext = 0; 4612 int32_t iNext = 0;
4613 if (BinarySearch(dwObjNum, iNext)) { 4613 if (BinarySearch(dwObjNum, iNext)) {
4614 return; 4614 return;
4615 } 4615 }
4616 m_number_array.InsertAt(iNext, dwObjNum); 4616 m_number_array.InsertAt(iNext, dwObjNum);
4617 } 4617 }
4618 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) 4618 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum)
4619 { 4619 {
4620 FX_INT32 iNext = 0; 4620 int32_t iNext = 0;
4621 return BinarySearch(dwObjNum, iNext); 4621 return BinarySearch(dwObjNum, iNext);
4622 } 4622 }
4623 FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, FX_INT32 &iNext) 4623 FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t &iNext)
4624 { 4624 {
4625 FX_INT32 iLen = m_number_array.GetSize(); 4625 int32_t iLen = m_number_array.GetSize();
4626 FX_INT32 iLow = 0; 4626 int32_t iLow = 0;
4627 FX_INT32 iHigh = iLen - 1; 4627 int32_t iHigh = iLen - 1;
4628 FX_INT32 iMid = 0; 4628 int32_t iMid = 0;
4629 while (iLow <= iHigh) { 4629 while (iLow <= iHigh) {
4630 iMid = (iLow + iHigh) / 2; 4630 iMid = (iLow + iHigh) / 2;
4631 if (m_number_array.GetAt(iMid) == value) { 4631 if (m_number_array.GetAt(iMid) == value) {
4632 iNext = iMid; 4632 iNext = iMid;
4633 return TRUE; 4633 return TRUE;
4634 } else if (m_number_array.GetAt(iMid) > value) { 4634 } else if (m_number_array.GetAt(iMid) > value) {
4635 iHigh = iMid - 1; 4635 iHigh = iMid - 1;
4636 } else if (m_number_array.GetAt(iMid) < value) { 4636 } else if (m_number_array.GetAt(iMid) < value) {
4637 iLow = iMid + 1; 4637 iLow = iMid + 1;
4638 } 4638 }
4639 } 4639 }
4640 iNext = iLow; 4640 iNext = iLow;
4641 return FALSE; 4641 return FALSE;
4642 } 4642 }
4643 CPDF_PageNode::~CPDF_PageNode() 4643 CPDF_PageNode::~CPDF_PageNode()
4644 { 4644 {
4645 FX_INT32 iSize = m_childNode.GetSize(); 4645 int32_t iSize = m_childNode.GetSize();
4646 for (FX_INT32 i = 0; i < iSize; ++i) { 4646 for (int32_t i = 0; i < iSize; ++i) {
4647 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i]; 4647 CPDF_PageNode *pNode = (CPDF_PageNode*)m_childNode[i];
4648 if (pNode) { 4648 if (pNode) {
4649 delete pNode; 4649 delete pNode;
4650 } 4650 }
4651 } 4651 }
4652 m_childNode.RemoveAll(); 4652 m_childNode.RemoveAll();
4653 } 4653 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698