OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/parser/cpdf_data_avail.h" | 7 #include "core/fpdfapi/parser/cpdf_data_avail.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "core/fpdfapi/cpdf_modulemgr.h" | 13 #include "core/fpdfapi/cpdf_modulemgr.h" |
14 #include "core/fpdfapi/parser/cpdf_array.h" | 14 #include "core/fpdfapi/parser/cpdf_array.h" |
15 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 15 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
16 #include "core/fpdfapi/parser/cpdf_document.h" | 16 #include "core/fpdfapi/parser/cpdf_document.h" |
17 #include "core/fpdfapi/parser/cpdf_hint_tables.h" | 17 #include "core/fpdfapi/parser/cpdf_hint_tables.h" |
| 18 #include "core/fpdfapi/parser/cpdf_linearized.h" |
18 #include "core/fpdfapi/parser/cpdf_name.h" | 19 #include "core/fpdfapi/parser/cpdf_name.h" |
19 #include "core/fpdfapi/parser/cpdf_number.h" | 20 #include "core/fpdfapi/parser/cpdf_number.h" |
20 #include "core/fpdfapi/parser/cpdf_reference.h" | 21 #include "core/fpdfapi/parser/cpdf_reference.h" |
21 #include "core/fpdfapi/parser/cpdf_stream.h" | 22 #include "core/fpdfapi/parser/cpdf_stream.h" |
22 #include "core/fpdfapi/parser/fpdf_parser_utility.h" | 23 #include "core/fpdfapi/parser/fpdf_parser_utility.h" |
23 #include "core/fxcrt/fx_ext.h" | 24 #include "core/fxcrt/fx_ext.h" |
24 #include "core/fxcrt/fx_safe_types.h" | 25 #include "core/fxcrt/fx_safe_types.h" |
25 #include "third_party/base/stl_util.h" | 26 #include "third_party/base/stl_util.h" |
26 | 27 |
27 CPDF_DataAvail::FileAvail::~FileAvail() {} | 28 CPDF_DataAvail::FileAvail::~FileAvail() {} |
28 | 29 |
29 CPDF_DataAvail::DownloadHints::~DownloadHints() {} | 30 CPDF_DataAvail::DownloadHints::~DownloadHints() {} |
30 | 31 |
31 // static | 32 // static |
32 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; | 33 int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0; |
33 | 34 |
34 CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail, | 35 CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail, |
35 IFX_SeekableReadStream* pFileRead, | 36 IFX_SeekableReadStream* pFileRead, |
36 bool bSupportHintTable) | 37 bool bSupportHintTable) |
37 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) { | 38 : m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) { |
38 m_Pos = 0; | 39 m_Pos = 0; |
39 m_dwFileLen = 0; | 40 m_dwFileLen = 0; |
40 if (m_pFileRead) { | 41 if (m_pFileRead) { |
41 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); | 42 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); |
42 } | 43 } |
43 m_dwCurrentOffset = 0; | 44 m_dwCurrentOffset = 0; |
44 m_dwXRefOffset = 0; | 45 m_dwXRefOffset = 0; |
45 m_bufferOffset = 0; | 46 m_bufferOffset = 0; |
46 m_dwFirstPageNo = 0; | |
47 m_bufferSize = 0; | 47 m_bufferSize = 0; |
48 m_PagesObjNum = 0; | 48 m_PagesObjNum = 0; |
49 m_dwCurrentXRefSteam = 0; | 49 m_dwCurrentXRefSteam = 0; |
50 m_dwAcroFormObjNum = 0; | 50 m_dwAcroFormObjNum = 0; |
51 m_dwInfoObjNum = 0; | 51 m_dwInfoObjNum = 0; |
52 m_pDocument = 0; | 52 m_pDocument = 0; |
53 m_dwEncryptObjNum = 0; | 53 m_dwEncryptObjNum = 0; |
54 m_dwPrevXRefOffset = 0; | 54 m_dwPrevXRefOffset = 0; |
55 m_dwLastXRefOffset = 0; | 55 m_dwLastXRefOffset = 0; |
56 m_bDocAvail = false; | 56 m_bDocAvail = false; |
57 m_bMainXRefLoadTried = false; | 57 m_bMainXRefLoadTried = false; |
58 m_bDocAvail = false; | 58 m_bDocAvail = false; |
59 m_bLinearized = false; | |
60 m_bPagesLoad = false; | 59 m_bPagesLoad = false; |
61 m_bPagesTreeLoad = false; | 60 m_bPagesTreeLoad = false; |
62 m_bMainXRefLoadedOK = false; | 61 m_bMainXRefLoadedOK = false; |
63 m_bAnnotsLoad = false; | 62 m_bAnnotsLoad = false; |
64 m_bHaveAcroForm = false; | 63 m_bHaveAcroForm = false; |
65 m_bAcroFormLoad = false; | 64 m_bAcroFormLoad = false; |
66 m_bPageLoadedOK = false; | 65 m_bPageLoadedOK = false; |
67 m_bNeedDownLoadResource = false; | 66 m_bNeedDownLoadResource = false; |
68 m_bLinearizedFormParamLoad = false; | 67 m_bLinearizedFormParamLoad = false; |
69 m_pLinearized = nullptr; | |
70 m_pRoot = nullptr; | 68 m_pRoot = nullptr; |
71 m_pTrailer = nullptr; | 69 m_pTrailer = nullptr; |
72 m_pCurrentParser = nullptr; | 70 m_pCurrentParser = nullptr; |
73 m_pAcroForm = nullptr; | 71 m_pAcroForm = nullptr; |
74 m_pPageDict = nullptr; | 72 m_pPageDict = nullptr; |
75 m_pPageResource = nullptr; | 73 m_pPageResource = nullptr; |
76 m_docStatus = PDF_DATAAVAIL_HEADER; | 74 m_docStatus = PDF_DATAAVAIL_HEADER; |
77 m_parser.m_bOwnFileRead = false; | 75 m_parser.m_bOwnFileRead = false; |
78 m_bTotalLoadPageTree = false; | 76 m_bTotalLoadPageTree = false; |
79 m_bCurPageDictLoadOK = false; | 77 m_bCurPageDictLoadOK = false; |
80 m_bLinearedDataOK = false; | 78 m_bLinearedDataOK = false; |
81 m_bSupportHintTable = bSupportHintTable; | 79 m_bSupportHintTable = bSupportHintTable; |
82 } | 80 } |
83 | 81 |
84 CPDF_DataAvail::~CPDF_DataAvail() { | 82 CPDF_DataAvail::~CPDF_DataAvail() { |
85 m_pHintTables.reset(); | 83 m_pHintTables.reset(); |
86 delete m_pLinearized; | |
87 delete m_pRoot; | |
88 delete m_pTrailer; | |
89 | 84 |
90 for (CPDF_Object* pObject : m_arrayAcroforms) | 85 for (CPDF_Object* pObject : m_arrayAcroforms) |
91 delete pObject; | 86 delete pObject; |
92 } | 87 } |
93 | 88 |
94 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { | 89 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { |
95 m_pDocument = pDoc; | 90 m_pDocument = pDoc; |
96 } | 91 } |
97 | 92 |
98 uint32_t CPDF_DataAvail::GetObjectSize(uint32_t objnum, FX_FILESIZE& offset) { | 93 uint32_t CPDF_DataAvail::GetObjectSize(uint32_t objnum, FX_FILESIZE& offset) { |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 m_docStatus = PDF_DATAAVAIL_END; | 601 m_docStatus = PDF_DATAAVAIL_END; |
607 } | 602 } |
608 return true; | 603 return true; |
609 } | 604 } |
610 | 605 |
611 pHints->AddSegment(0, kReqSize); | 606 pHints->AddSegment(0, kReqSize); |
612 return false; | 607 return false; |
613 } | 608 } |
614 | 609 |
615 bool CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { | 610 bool CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { |
616 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 611 if (!m_pLinearized->GetFirstPageEndOffset() || |
617 CPDF_Object* pEndOffSet = pDict ? pDict->GetObjectFor("E") : nullptr; | 612 !m_pLinearized->GetFileSize() || !m_pLinearized->GetLastXRefOffset()) { |
618 if (!pEndOffSet) { | |
619 m_docStatus = PDF_DATAAVAIL_ERROR; | |
620 return false; | |
621 } | |
622 | |
623 CPDF_Object* pXRefOffset = pDict ? pDict->GetObjectFor("T") : nullptr; | |
624 if (!pXRefOffset) { | |
625 m_docStatus = PDF_DATAAVAIL_ERROR; | |
626 return false; | |
627 } | |
628 | |
629 CPDF_Object* pFileLen = pDict ? pDict->GetObjectFor("L") : nullptr; | |
630 if (!pFileLen) { | |
631 m_docStatus = PDF_DATAAVAIL_ERROR; | 613 m_docStatus = PDF_DATAAVAIL_ERROR; |
632 return false; | 614 return false; |
633 } | 615 } |
634 | 616 |
635 bool bNeedDownLoad = false; | 617 bool bNeedDownLoad = false; |
636 if (pEndOffSet->IsNumber()) { | 618 uint32_t dwEnd = m_pLinearized->GetFirstPageEndOffset(); |
637 uint32_t dwEnd = pEndOffSet->GetInteger(); | 619 dwEnd += 512; |
638 dwEnd += 512; | 620 if ((FX_FILESIZE)dwEnd > m_dwFileLen) |
639 if ((FX_FILESIZE)dwEnd > m_dwFileLen) | 621 dwEnd = (uint32_t)m_dwFileLen; |
640 dwEnd = (uint32_t)m_dwFileLen; | |
641 | 622 |
642 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); | 623 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); |
643 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; | 624 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; |
644 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { | 625 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { |
645 pHints->AddSegment(iStartPos, iSize); | 626 pHints->AddSegment(iStartPos, iSize); |
646 bNeedDownLoad = true; | 627 bNeedDownLoad = true; |
647 } | |
648 } | 628 } |
649 | 629 |
650 m_dwLastXRefOffset = 0; | 630 m_dwLastXRefOffset = m_pLinearized->GetLastXRefOffset(); |
651 FX_FILESIZE dwFileLen = 0; | 631 FX_FILESIZE dwFileLen = m_pLinearized->GetFileSize(); |
652 if (pXRefOffset->IsNumber()) | |
653 m_dwLastXRefOffset = pXRefOffset->GetInteger(); | |
654 | |
655 if (pFileLen->IsNumber()) | |
656 dwFileLen = pFileLen->GetInteger(); | |
657 | |
658 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, | 632 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, |
659 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) { | 633 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) { |
660 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { | 634 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { |
661 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset); | 635 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset); |
662 FX_FILESIZE offset = m_dwLastXRefOffset; | 636 FX_FILESIZE offset = m_dwLastXRefOffset; |
663 if (dwSize < 512 && dwFileLen > 512) { | 637 if (dwSize < 512 && dwFileLen > 512) { |
664 dwSize = 512; | 638 dwSize = 512; |
665 offset = dwFileLen - 512; | 639 offset = dwFileLen - 512; |
666 } | 640 } |
667 pHints->AddSegment(offset, dwSize); | 641 pHints->AddSegment(offset, dwSize); |
(...skipping 27 matching lines...) Expand all Loading... |
695 size += 512; | 669 size += 512; |
696 | 670 |
697 if (!m_pFileAvail->IsDataAvail(offset, size)) { | 671 if (!m_pFileAvail->IsDataAvail(offset, size)) { |
698 pHints->AddSegment(offset, size); | 672 pHints->AddSegment(offset, size); |
699 return false; | 673 return false; |
700 } | 674 } |
701 return true; | 675 return true; |
702 } | 676 } |
703 | 677 |
704 bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { | 678 bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { |
705 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 679 if (m_pLinearized->GetPageCount() <= 1) { |
706 if (!pDict) { | 680 m_docStatus = PDF_DATAAVAIL_DONE; |
| 681 return true; |
| 682 } |
| 683 if (!m_pLinearized->HasHintTable()) { |
707 m_docStatus = PDF_DATAAVAIL_ERROR; | 684 m_docStatus = PDF_DATAAVAIL_ERROR; |
708 return false; | 685 return false; |
709 } | 686 } |
710 | 687 |
711 // The actual value is not required here, but validate its existence and type. | 688 FX_FILESIZE szHintStart = m_pLinearized->GetHintStart(); |
712 CPDF_Number* pFirstPage = ToNumber(pDict->GetDirectObjectFor("O")); | 689 FX_FILESIZE szHintLength = m_pLinearized->GetHintLength(); |
713 if (!pFirstPage || !pFirstPage->IsInteger()) { | |
714 m_docStatus = PDF_DATAAVAIL_ERROR; | |
715 return false; | |
716 } | |
717 | |
718 CPDF_Number* pPageCount = ToNumber(pDict->GetDirectObjectFor("N")); | |
719 if (!pPageCount || !pPageCount->IsInteger()) { | |
720 m_docStatus = PDF_DATAAVAIL_ERROR; | |
721 return false; | |
722 } | |
723 | |
724 int nPageCount = pPageCount->GetInteger(); | |
725 if (nPageCount <= 1) { | |
726 m_docStatus = PDF_DATAAVAIL_DONE; | |
727 return true; | |
728 } | |
729 | |
730 CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H"); | |
731 size_t nHintStreamSize = pHintStreamRange ? pHintStreamRange->GetCount() : 0; | |
732 if (nHintStreamSize != 2 && nHintStreamSize != 4) { | |
733 m_docStatus = PDF_DATAAVAIL_ERROR; | |
734 return false; | |
735 } | |
736 | |
737 for (const CPDF_Object* pArrayObject : *pHintStreamRange) { | |
738 const CPDF_Number* pNumber = ToNumber(pArrayObject->GetDirect()); | |
739 if (!pNumber || !pNumber->IsInteger()) { | |
740 m_docStatus = PDF_DATAAVAIL_ERROR; | |
741 return false; | |
742 } | |
743 } | |
744 | |
745 FX_FILESIZE szHintStart = pHintStreamRange->GetIntegerAt(0); | |
746 FX_FILESIZE szHintLength = pHintStreamRange->GetIntegerAt(1); | |
747 if (szHintStart < 0 || szHintLength <= 0) { | |
748 m_docStatus = PDF_DATAAVAIL_ERROR; | |
749 return false; | |
750 } | |
751 | 690 |
752 if (!IsDataAvail(szHintStart, szHintLength, pHints)) | 691 if (!IsDataAvail(szHintStart, szHintLength, pHints)) |
753 return false; | 692 return false; |
754 | 693 |
755 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); | 694 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); |
756 | 695 |
757 std::unique_ptr<CPDF_HintTables> pHintTables( | 696 std::unique_ptr<CPDF_HintTables> pHintTables( |
758 new CPDF_HintTables(this, pDict)); | 697 new CPDF_HintTables(this, m_pLinearized.get())); |
759 std::unique_ptr<CPDF_Object> pHintStream( | 698 std::unique_ptr<CPDF_Object> pHintStream( |
760 ParseIndirectObjectAt(szHintStart, 0)); | 699 ParseIndirectObjectAt(szHintStart, 0)); |
761 CPDF_Stream* pStream = ToStream(pHintStream.get()); | 700 CPDF_Stream* pStream = ToStream(pHintStream.get()); |
762 if (pStream && pHintTables->LoadHintStream(pStream)) | 701 if (pStream && pHintTables->LoadHintStream(pStream)) |
763 m_pHintTables = std::move(pHintTables); | 702 m_pHintTables = std::move(pHintTables); |
764 | 703 |
765 m_docStatus = PDF_DATAAVAIL_DONE; | 704 m_docStatus = PDF_DATAAVAIL_DONE; |
766 return true; | 705 return true; |
767 } | 706 } |
768 | 707 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 751 |
813 uint8_t buffer[1024]; | 752 uint8_t buffer[1024]; |
814 m_pFileRead->ReadBlock(buffer, 0, kReqSize); | 753 m_pFileRead->ReadBlock(buffer, 0, kReqSize); |
815 if (IsLinearizedFile(buffer, kReqSize)) | 754 if (IsLinearizedFile(buffer, kReqSize)) |
816 return Linearized; | 755 return Linearized; |
817 | 756 |
818 return NotLinearized; | 757 return NotLinearized; |
819 } | 758 } |
820 | 759 |
821 bool CPDF_DataAvail::IsLinearized() { | 760 bool CPDF_DataAvail::IsLinearized() { |
822 return m_bLinearized; | 761 return !!m_pLinearized; |
823 } | 762 } |
824 | 763 |
825 bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) { | 764 bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) { |
826 if (m_pLinearized) | 765 if (m_pLinearized) |
827 return m_bLinearized; | 766 return true; |
828 | 767 |
829 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, false)); | 768 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, false)); |
830 | 769 |
831 int32_t offset = GetHeaderOffset(file.get()); | 770 int32_t offset = GetHeaderOffset(file.get()); |
832 if (offset == -1) { | 771 if (offset == -1) { |
833 m_docStatus = PDF_DATAAVAIL_ERROR; | 772 m_docStatus = PDF_DATAAVAIL_ERROR; |
834 return false; | 773 return false; |
835 } | 774 } |
836 | 775 |
837 m_dwHeaderOffset = offset; | 776 m_dwHeaderOffset = offset; |
838 m_syntaxParser.InitParser(file.get(), offset); | 777 m_syntaxParser.InitParser(file.get(), offset); |
839 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); | 778 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); |
840 | 779 |
841 bool bNumber; | 780 bool bNumber; |
842 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); | 781 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); |
843 if (!bNumber) | 782 if (!bNumber) |
844 return false; | 783 return false; |
845 | 784 |
846 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); | 785 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); |
847 m_pLinearized = | 786 m_pLinearized = CPDF_Linearized::CreateForObject(pdfium::WrapUnique( |
848 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); | 787 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum))); |
849 if (!m_pLinearized) | 788 if (!m_pLinearized || |
| 789 m_pLinearized->GetFileSize() != m_pFileRead->GetSize()) { |
| 790 m_pLinearized.reset(); |
850 return false; | 791 return false; |
851 | 792 } |
852 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | |
853 if (!pDict || !pDict->GetObjectFor("Linearized")) | |
854 return false; | |
855 | |
856 CPDF_Object* pLen = pDict->GetObjectFor("L"); | |
857 if (!pLen) | |
858 return false; | |
859 | |
860 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize()) | |
861 return false; | |
862 | |
863 m_bLinearized = true; | |
864 | |
865 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) | |
866 m_dwFirstPageNo = pNo->GetInteger(); | |
867 | |
868 return true; | 793 return true; |
869 } | 794 } |
870 | 795 |
871 bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { | 796 bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { |
872 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); | 797 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); |
873 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); | 798 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); |
874 | 799 |
875 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { | 800 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { |
876 uint8_t buffer[1024]; | 801 uint8_t buffer[1024]; |
877 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); | 802 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 m_bPageLoadedOK = false; | 1518 m_bPageLoadedOK = false; |
1594 m_bAnnotsLoad = false; | 1519 m_bAnnotsLoad = false; |
1595 m_bNeedDownLoadResource = false; | 1520 m_bNeedDownLoadResource = false; |
1596 m_objs_array.clear(); | 1521 m_objs_array.clear(); |
1597 m_ObjectSet.clear(); | 1522 m_ObjectSet.clear(); |
1598 } | 1523 } |
1599 | 1524 |
1600 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) | 1525 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) |
1601 return DataAvailable; | 1526 return DataAvailable; |
1602 | 1527 |
1603 if (m_bLinearized) { | 1528 if (m_pLinearized) { |
1604 if (dwPage == m_dwFirstPageNo) { | 1529 if (dwPage == m_pLinearized->GetFirstPageNo()) { |
1605 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); | 1530 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); |
1606 if (nRet == DataAvailable) | 1531 if (nRet == DataAvailable) |
1607 m_pagesLoadState.insert(dwPage); | 1532 m_pagesLoadState.insert(dwPage); |
1608 return nRet; | 1533 return nRet; |
1609 } | 1534 } |
1610 | 1535 |
1611 DocAvailStatus nResult = CheckLinearizedData(pHints); | 1536 DocAvailStatus nResult = CheckLinearizedData(pHints); |
1612 if (nResult != DataAvailable) | 1537 if (nResult != DataAvailable) |
1613 return nResult; | 1538 return nResult; |
1614 | 1539 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 | 1649 |
1725 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, | 1650 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, |
1726 uint32_t* pSize) { | 1651 uint32_t* pSize) { |
1727 if (pPos) | 1652 if (pPos) |
1728 *pPos = m_dwLastXRefOffset; | 1653 *pPos = m_dwLastXRefOffset; |
1729 if (pSize) | 1654 if (pSize) |
1730 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); | 1655 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); |
1731 } | 1656 } |
1732 | 1657 |
1733 int CPDF_DataAvail::GetPageCount() const { | 1658 int CPDF_DataAvail::GetPageCount() const { |
1734 if (m_pLinearized) { | 1659 if (m_pLinearized) |
1735 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1660 return m_pLinearized->GetPageCount(); |
1736 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("N") : nullptr; | |
1737 return pObj ? pObj->GetInteger() : 0; | |
1738 } | |
1739 return m_pDocument ? m_pDocument->GetPageCount() : 0; | 1661 return m_pDocument ? m_pDocument->GetPageCount() : 0; |
1740 } | 1662 } |
1741 | 1663 |
1742 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { | 1664 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { |
1743 if (!m_pDocument || index < 0 || index >= GetPageCount()) | 1665 if (!m_pDocument || index < 0 || index >= GetPageCount()) |
1744 return nullptr; | 1666 return nullptr; |
1745 CPDF_Dictionary* page = m_pDocument->GetPage(index); | 1667 CPDF_Dictionary* page = m_pDocument->GetPage(index); |
1746 if (page) | 1668 if (page) |
1747 return page; | 1669 return page; |
1748 if (!m_pLinearized || !m_pHintTables) | 1670 if (!m_pLinearized || !m_pHintTables) |
1749 return nullptr; | 1671 return nullptr; |
1750 | 1672 |
1751 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1673 if (index == static_cast<int>(m_pLinearized->GetFirstPageNo())) |
1752 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("P") : nullptr; | |
1753 int firstPageNum = pObj ? pObj->GetInteger() : 0; | |
1754 if (index == firstPageNum) | |
1755 return nullptr; | 1674 return nullptr; |
1756 FX_FILESIZE szPageStartPos = 0; | 1675 FX_FILESIZE szPageStartPos = 0; |
1757 FX_FILESIZE szPageLength = 0; | 1676 FX_FILESIZE szPageLength = 0; |
1758 uint32_t dwObjNum = 0; | 1677 uint32_t dwObjNum = 0; |
1759 const bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, | 1678 const bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, |
1760 &szPageLength, &dwObjNum); | 1679 &szPageLength, &dwObjNum); |
1761 if (!bPagePosGot || !dwObjNum) | 1680 if (!bPagePosGot || !dwObjNum) |
1762 return nullptr; | 1681 return nullptr; |
1763 // We should say to the document, which object is the page. | 1682 // We should say to the document, which object is the page. |
1764 m_pDocument->SetPageObjNum(index, dwObjNum); | 1683 m_pDocument->SetPageObjNum(index, dwObjNum); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 return FormAvailable; | 1726 return FormAvailable; |
1808 } | 1727 } |
1809 | 1728 |
1810 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1729 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
1811 | 1730 |
1812 CPDF_DataAvail::PageNode::~PageNode() { | 1731 CPDF_DataAvail::PageNode::~PageNode() { |
1813 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1732 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
1814 delete m_childNode[i]; | 1733 delete m_childNode[i]; |
1815 m_childNode.RemoveAll(); | 1734 m_childNode.RemoveAll(); |
1816 } | 1735 } |
OLD | NEW |