Chromium Code Reviews| 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 <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 if (*(FX_DWORD*)buf == tag) | 39 if (*(FX_DWORD*)buf == tag) |
| 40 return offset; | 40 return offset; |
| 41 | 41 |
| 42 ++offset; | 42 ++offset; |
| 43 } | 43 } |
| 44 return -1; | 44 return -1; |
| 45 } | 45 } |
| 46 | 46 |
| 47 int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) { | 47 int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) { |
| 48 CPDF_Object* pObj = pDict->GetElement(key); | 48 if (CPDF_Number* pObj = ToNumber(pDict->GetElement(key))) |
|
Lei Zhang
2015/10/21 14:45:50
drop the if and return pObj ? pObj->GetInteger() :
dsinclair
2015/10/21 15:00:11
Done.
| |
| 49 if (pObj && (pObj->GetType() == PDFOBJ_NUMBER)) | 49 return pObj->GetInteger(); |
| 50 return ((CPDF_Number*)pObj)->GetInteger(); | |
| 51 return 0; | 50 return 0; |
| 52 } | 51 } |
| 53 | 52 |
| 54 bool CheckDirectType(CPDF_Dictionary* pDict, | 53 bool CheckDirectType(CPDF_Dictionary* pDict, |
| 55 const CFX_ByteStringC& key, | 54 const CFX_ByteStringC& key, |
| 56 int32_t iType) { | 55 int32_t iType) { |
| 57 CPDF_Object* pObj = pDict->GetElement(key); | 56 CPDF_Object* pObj = pDict->GetElement(key); |
| 58 return !pObj || pObj->GetType() == iType; | 57 return !pObj || pObj->GetType() == iType; |
| 59 } | 58 } |
| 60 | 59 |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1041 } else { | 1040 } else { |
| 1042 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); | 1041 m_Trailers.Add(ToDictionary(pStream->GetDict()->Clone())); |
| 1043 } | 1042 } |
| 1044 std::vector<std::pair<int32_t, int32_t> > arrIndex; | 1043 std::vector<std::pair<int32_t, int32_t> > arrIndex; |
| 1045 CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index")); | 1044 CPDF_Array* pArray = pStream->GetDict()->GetArray(FX_BSTRC("Index")); |
| 1046 if (pArray) { | 1045 if (pArray) { |
| 1047 FX_DWORD nPairSize = pArray->GetCount() / 2; | 1046 FX_DWORD nPairSize = pArray->GetCount() / 2; |
| 1048 for (FX_DWORD i = 0; i < nPairSize; i++) { | 1047 for (FX_DWORD i = 0; i < nPairSize; i++) { |
| 1049 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2); | 1048 CPDF_Object* pStartNumObj = pArray->GetElement(i * 2); |
| 1050 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1); | 1049 CPDF_Object* pCountObj = pArray->GetElement(i * 2 + 1); |
| 1051 if (pStartNumObj && pStartNumObj->GetType() == PDFOBJ_NUMBER && | 1050 if (ToNumber(pStartNumObj) && ToNumber(pCountObj)) { |
| 1052 pCountObj && pCountObj->GetType() == PDFOBJ_NUMBER) { | |
| 1053 int nStartNum = pStartNumObj->GetInteger(); | 1051 int nStartNum = pStartNumObj->GetInteger(); |
| 1054 int nCount = pCountObj->GetInteger(); | 1052 int nCount = pCountObj->GetInteger(); |
| 1055 if (nStartNum >= 0 && nCount > 0) { | 1053 if (nStartNum >= 0 && nCount > 0) { |
| 1056 arrIndex.push_back(std::make_pair(nStartNum, nCount)); | 1054 arrIndex.push_back(std::make_pair(nStartNum, nCount)); |
| 1057 } | 1055 } |
| 1058 } | 1056 } |
| 1059 } | 1057 } |
| 1060 } | 1058 } |
| 1061 if (arrIndex.size() == 0) { | 1059 if (arrIndex.size() == 0) { |
| 1062 arrIndex.push_back(std::make_pair(0, size)); | 1060 arrIndex.push_back(std::make_pair(0, size)); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1544 } | 1542 } |
| 1545 FX_DWORD gennum = FXSYS_atoi(word); | 1543 FX_DWORD gennum = FXSYS_atoi(word); |
| 1546 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) { | 1544 if (m_Syntax.GetKeyword() != FX_BSTRC("obj")) { |
| 1547 m_Syntax.RestorePos(SavedPos); | 1545 m_Syntax.RestorePos(SavedPos); |
| 1548 return FALSE; | 1546 return FALSE; |
| 1549 } | 1547 } |
| 1550 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0); | 1548 m_pLinearized = m_Syntax.GetObject(NULL, objnum, gennum, 0); |
| 1551 if (!m_pLinearized) { | 1549 if (!m_pLinearized) { |
| 1552 return FALSE; | 1550 return FALSE; |
| 1553 } | 1551 } |
| 1554 if (m_pLinearized->GetDict() && | 1552 |
| 1555 m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { | 1553 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 1554 if (pDict && pDict->GetElement(FX_BSTRC("Linearized"))) { | |
| 1556 m_Syntax.GetNextWord(bIsNumber); | 1555 m_Syntax.GetNextWord(bIsNumber); |
| 1557 CPDF_Object* pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); | 1556 |
| 1557 CPDF_Object* pLen = pDict->GetElement(FX_BSTRC("L")); | |
| 1558 if (!pLen) { | 1558 if (!pLen) { |
| 1559 m_pLinearized->Release(); | 1559 m_pLinearized->Release(); |
| 1560 m_pLinearized = NULL; | 1560 m_pLinearized = NULL; |
| 1561 return FALSE; | 1561 return FALSE; |
| 1562 } | 1562 } |
| 1563 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { | 1563 if (pLen->GetInteger() != (int)pFileAccess->GetSize()) { |
| 1564 return FALSE; | 1564 return FALSE; |
| 1565 } | 1565 } |
| 1566 CPDF_Object* pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); | 1566 |
| 1567 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { | 1567 if (CPDF_Number* pNo = ToNumber(pDict->GetElement(FX_BSTRC("P")))) |
| 1568 m_dwFirstPageNo = pNo->GetInteger(); | 1568 m_dwFirstPageNo = pNo->GetInteger(); |
| 1569 } | 1569 |
| 1570 CPDF_Object* pTable = m_pLinearized->GetDict()->GetElement(FX_BSTRC("T")); | 1570 if (CPDF_Number* pTable = ToNumber(pDict->GetElement(FX_BSTRC("T")))) |
| 1571 if (pTable && pTable->GetType() == PDFOBJ_NUMBER) { | |
| 1572 m_LastXRefOffset = pTable->GetInteger(); | 1571 m_LastXRefOffset = pTable->GetInteger(); |
| 1573 } | 1572 |
| 1574 return TRUE; | 1573 return TRUE; |
| 1575 } | 1574 } |
| 1576 m_pLinearized->Release(); | 1575 m_pLinearized->Release(); |
| 1577 m_pLinearized = NULL; | 1576 m_pLinearized = NULL; |
| 1578 return FALSE; | 1577 return FALSE; |
| 1579 } | 1578 } |
| 1580 FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, | 1579 FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, |
| 1581 FX_BOOL bReParse, | 1580 FX_BOOL bReParse, |
| 1582 FX_BOOL bOwnFileRead) { | 1581 FX_BOOL bOwnFileRead) { |
| 1583 CloseParser(bReParse); | 1582 CloseParser(bReParse); |
| (...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3614 if (!pXRefOffset) { | 3613 if (!pXRefOffset) { |
| 3615 m_docStatus = PDF_DATAAVAIL_ERROR; | 3614 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 3616 return FALSE; | 3615 return FALSE; |
| 3617 } | 3616 } |
| 3618 CPDF_Object* pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL; | 3617 CPDF_Object* pFileLen = pDict ? pDict->GetElement(FX_BSTRC("L")) : NULL; |
| 3619 if (!pFileLen) { | 3618 if (!pFileLen) { |
| 3620 m_docStatus = PDF_DATAAVAIL_ERROR; | 3619 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 3621 return FALSE; | 3620 return FALSE; |
| 3622 } | 3621 } |
| 3623 FX_BOOL bNeedDownLoad = FALSE; | 3622 FX_BOOL bNeedDownLoad = FALSE; |
| 3624 if (pEndOffSet->GetType() == PDFOBJ_NUMBER) { | 3623 if (pEndOffSet->IsNumber()) { |
| 3625 FX_DWORD dwEnd = pEndOffSet->GetInteger(); | 3624 FX_DWORD dwEnd = pEndOffSet->GetInteger(); |
| 3626 dwEnd += 512; | 3625 dwEnd += 512; |
| 3627 if ((FX_FILESIZE)dwEnd > m_dwFileLen) { | 3626 if ((FX_FILESIZE)dwEnd > m_dwFileLen) { |
| 3628 dwEnd = (FX_DWORD)m_dwFileLen; | 3627 dwEnd = (FX_DWORD)m_dwFileLen; |
| 3629 } | 3628 } |
| 3630 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); | 3629 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); |
| 3631 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; | 3630 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; |
| 3632 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { | 3631 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { |
| 3633 pHints->AddSegment(iStartPos, iSize); | 3632 pHints->AddSegment(iStartPos, iSize); |
| 3634 bNeedDownLoad = TRUE; | 3633 bNeedDownLoad = TRUE; |
| 3635 } | 3634 } |
| 3636 } | 3635 } |
| 3637 m_dwLastXRefOffset = 0; | 3636 m_dwLastXRefOffset = 0; |
| 3638 FX_FILESIZE dwFileLen = 0; | 3637 FX_FILESIZE dwFileLen = 0; |
| 3639 if (pXRefOffset->GetType() == PDFOBJ_NUMBER) { | 3638 if (pXRefOffset->IsNumber()) |
| 3640 m_dwLastXRefOffset = pXRefOffset->GetInteger(); | 3639 m_dwLastXRefOffset = pXRefOffset->GetInteger(); |
| 3641 } | 3640 |
| 3642 if (pFileLen->GetType() == PDFOBJ_NUMBER) { | 3641 if (pFileLen->IsNumber()) |
| 3643 dwFileLen = pFileLen->GetInteger(); | 3642 dwFileLen = pFileLen->GetInteger(); |
| 3644 } | 3643 |
| 3645 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, | 3644 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, |
| 3646 (FX_DWORD)(dwFileLen - m_dwLastXRefOffset))) { | 3645 (FX_DWORD)(dwFileLen - m_dwLastXRefOffset))) { |
| 3647 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { | 3646 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { |
| 3648 FX_DWORD dwSize = (FX_DWORD)(dwFileLen - m_dwLastXRefOffset); | 3647 FX_DWORD dwSize = (FX_DWORD)(dwFileLen - m_dwLastXRefOffset); |
| 3649 FX_FILESIZE offset = m_dwLastXRefOffset; | 3648 FX_FILESIZE offset = m_dwLastXRefOffset; |
| 3650 if (dwSize < 512 && dwFileLen > 512) { | 3649 if (dwSize < 512 && dwFileLen > 512) { |
| 3651 dwSize = 512; | 3650 dwSize = 512; |
| 3652 offset = dwFileLen - 512; | 3651 offset = dwFileLen - 512; |
| 3653 } | 3652 } |
| 3654 pHints->AddSegment(offset, dwSize); | 3653 pHints->AddSegment(offset, dwSize); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3726 FX_DWORD objnum = FXSYS_atoi(wordObjNum); | 3725 FX_DWORD objnum = FXSYS_atoi(wordObjNum); |
| 3727 if (m_pLinearized) { | 3726 if (m_pLinearized) { |
| 3728 m_pLinearized->Release(); | 3727 m_pLinearized->Release(); |
| 3729 m_pLinearized = NULL; | 3728 m_pLinearized = NULL; |
| 3730 } | 3729 } |
| 3731 m_pLinearized = | 3730 m_pLinearized = |
| 3732 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); | 3731 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); |
| 3733 if (!m_pLinearized) { | 3732 if (!m_pLinearized) { |
| 3734 return FALSE; | 3733 return FALSE; |
| 3735 } | 3734 } |
| 3736 if (m_pLinearized->GetDict() && | 3735 |
| 3737 m_pLinearized->GetDict()->GetElement(FX_BSTRC("Linearized"))) { | 3736 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| 3738 CPDF_Object* pLen = m_pLinearized->GetDict()->GetElement(FX_BSTRC("L")); | 3737 if (pDict && pDict->GetElement(FX_BSTRC("Linearized"))) { |
| 3738 CPDF_Object* pLen = pDict->GetElement(FX_BSTRC("L")); | |
| 3739 if (!pLen) { | 3739 if (!pLen) { |
| 3740 return FALSE; | 3740 return FALSE; |
| 3741 } | 3741 } |
| 3742 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) { | 3742 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) { |
| 3743 return FALSE; | 3743 return FALSE; |
| 3744 } | 3744 } |
| 3745 m_bLinearized = TRUE; | 3745 m_bLinearized = TRUE; |
| 3746 CPDF_Object* pNo = m_pLinearized->GetDict()->GetElement(FX_BSTRC("P")); | 3746 |
| 3747 if (pNo && pNo->GetType() == PDFOBJ_NUMBER) { | 3747 if (CPDF_Number* pNo = ToNumber(pDict->GetElement(FX_BSTRC("P")))) |
| 3748 m_dwFirstPageNo = pNo->GetInteger(); | 3748 m_dwFirstPageNo = pNo->GetInteger(); |
| 3749 } | 3749 |
| 3750 return TRUE; | 3750 return TRUE; |
| 3751 } | 3751 } |
| 3752 return FALSE; | 3752 return FALSE; |
| 3753 } | 3753 } |
| 3754 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) { | 3754 FX_BOOL CPDF_DataAvail::CheckEnd(IFX_DownloadHints* pHints) { |
| 3755 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 3755 FX_DWORD req_pos = (FX_DWORD)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
| 3756 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); | 3756 FX_DWORD dwSize = (FX_DWORD)(m_dwFileLen - req_pos); |
| 3757 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 3757 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
| 3758 uint8_t buffer[1024]; | 3758 uint8_t buffer[1024]; |
| 3759 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 3759 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4616 return FALSE; | 4616 return FALSE; |
| 4617 } | 4617 } |
| 4618 CPDF_PageNode::~CPDF_PageNode() { | 4618 CPDF_PageNode::~CPDF_PageNode() { |
| 4619 int32_t iSize = m_childNode.GetSize(); | 4619 int32_t iSize = m_childNode.GetSize(); |
| 4620 for (int32_t i = 0; i < iSize; ++i) { | 4620 for (int32_t i = 0; i < iSize; ++i) { |
| 4621 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4621 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; |
| 4622 delete pNode; | 4622 delete pNode; |
| 4623 } | 4623 } |
| 4624 m_childNode.RemoveAll(); | 4624 m_childNode.RemoveAll(); |
| 4625 } | 4625 } |
| OLD | NEW |