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