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

Side by Side Diff: core/fpdfapi/parser/cpdf_data_avail.cpp

Issue 2466023002: Unify some code (Closed)
Patch Set: Fix compilation Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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 FX_BOOL bSupportHintTable) 37 FX_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 if (m_pLinearized)
87 m_pLinearized->Release();
88 84
89 if (m_pRoot) 85 if (m_pRoot)
90 m_pRoot->Release(); 86 m_pRoot->Release();
91 87
92 if (m_pTrailer) 88 if (m_pTrailer)
93 m_pTrailer->Release(); 89 m_pTrailer->Release();
94 90
95 for (CPDF_Object* pObject : m_arrayAcroforms) 91 for (CPDF_Object* pObject : m_arrayAcroforms)
96 pObject->Release(); 92 pObject->Release();
97 } 93 }
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 m_docStatus = PDF_DATAAVAIL_END; 610 m_docStatus = PDF_DATAAVAIL_END;
615 } 611 }
616 return TRUE; 612 return TRUE;
617 } 613 }
618 614
619 pHints->AddSegment(0, kReqSize); 615 pHints->AddSegment(0, kReqSize);
620 return FALSE; 616 return FALSE;
621 } 617 }
622 618
623 FX_BOOL CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) { 619 FX_BOOL CPDF_DataAvail::CheckFirstPage(DownloadHints* pHints) {
624 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); 620 if (!m_pLinearized->GetFirstPageEndOffset() ||
625 CPDF_Object* pEndOffSet = pDict ? pDict->GetObjectFor("E") : nullptr; 621 !m_pLinearized->GetFileSize() || !m_pLinearized->GetLastXRefOffset()) {
626 if (!pEndOffSet) {
627 m_docStatus = PDF_DATAAVAIL_ERROR;
628 return FALSE;
629 }
630
631 CPDF_Object* pXRefOffset = pDict ? pDict->GetObjectFor("T") : nullptr;
632 if (!pXRefOffset) {
633 m_docStatus = PDF_DATAAVAIL_ERROR;
634 return FALSE;
635 }
636
637 CPDF_Object* pFileLen = pDict ? pDict->GetObjectFor("L") : nullptr;
638 if (!pFileLen) {
639 m_docStatus = PDF_DATAAVAIL_ERROR; 622 m_docStatus = PDF_DATAAVAIL_ERROR;
640 return FALSE; 623 return FALSE;
641 } 624 }
642 625
643 FX_BOOL bNeedDownLoad = FALSE; 626 FX_BOOL bNeedDownLoad = FALSE;
644 if (pEndOffSet->IsNumber()) { 627 uint32_t dwEnd = m_pLinearized->GetFirstPageEndOffset();
645 uint32_t dwEnd = pEndOffSet->GetInteger(); 628 dwEnd += 512;
646 dwEnd += 512; 629 if ((FX_FILESIZE)dwEnd > m_dwFileLen)
647 if ((FX_FILESIZE)dwEnd > m_dwFileLen) 630 dwEnd = (uint32_t)m_dwFileLen;
648 dwEnd = (uint32_t)m_dwFileLen;
649 631
650 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen); 632 int32_t iStartPos = (int32_t)(m_dwFileLen > 1024 ? 1024 : m_dwFileLen);
651 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0; 633 int32_t iSize = dwEnd > 1024 ? dwEnd - 1024 : 0;
652 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) { 634 if (!m_pFileAvail->IsDataAvail(iStartPos, iSize)) {
653 pHints->AddSegment(iStartPos, iSize); 635 pHints->AddSegment(iStartPos, iSize);
654 bNeedDownLoad = TRUE; 636 bNeedDownLoad = TRUE;
655 }
656 } 637 }
657 638
658 m_dwLastXRefOffset = 0; 639 m_dwLastXRefOffset = m_pLinearized->GetLastXRefOffset();
659 FX_FILESIZE dwFileLen = 0; 640 FX_FILESIZE dwFileLen = m_pLinearized->GetFileSize();
660 if (pXRefOffset->IsNumber())
661 m_dwLastXRefOffset = pXRefOffset->GetInteger();
662
663 if (pFileLen->IsNumber())
664 dwFileLen = pFileLen->GetInteger();
665
666 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, 641 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset,
667 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) { 642 (uint32_t)(dwFileLen - m_dwLastXRefOffset))) {
668 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) { 643 if (m_docStatus == PDF_DATAAVAIL_FIRSTPAGE) {
669 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset); 644 uint32_t dwSize = (uint32_t)(dwFileLen - m_dwLastXRefOffset);
670 FX_FILESIZE offset = m_dwLastXRefOffset; 645 FX_FILESIZE offset = m_dwLastXRefOffset;
671 if (dwSize < 512 && dwFileLen > 512) { 646 if (dwSize < 512 && dwFileLen > 512) {
672 dwSize = 512; 647 dwSize = 512;
673 offset = dwFileLen - 512; 648 offset = dwFileLen - 512;
674 } 649 }
675 pHints->AddSegment(offset, dwSize); 650 pHints->AddSegment(offset, dwSize);
(...skipping 27 matching lines...) Expand all
703 size += 512; 678 size += 512;
704 679
705 if (!m_pFileAvail->IsDataAvail(offset, size)) { 680 if (!m_pFileAvail->IsDataAvail(offset, size)) {
706 pHints->AddSegment(offset, size); 681 pHints->AddSegment(offset, size);
707 return FALSE; 682 return FALSE;
708 } 683 }
709 return TRUE; 684 return TRUE;
710 } 685 }
711 686
712 FX_BOOL CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { 687 FX_BOOL CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) {
713 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); 688 if (m_pLinearized->GetPageCount() <= 1) {
714 if (!pDict) { 689 m_docStatus = PDF_DATAAVAIL_DONE;
690 return TRUE;
691 }
692 if (!m_pLinearized->HasHintTable()) {
715 m_docStatus = PDF_DATAAVAIL_ERROR; 693 m_docStatus = PDF_DATAAVAIL_ERROR;
716 return FALSE; 694 return FALSE;
717 } 695 }
718 696
719 // The actual value is not required here, but validate its existence and type. 697 FX_FILESIZE szHintStart = m_pLinearized->GetHintStart();
720 CPDF_Number* pFirstPage = ToNumber(pDict->GetDirectObjectFor("O")); 698 FX_FILESIZE szHintLength = m_pLinearized->GetHintLength();
721 if (!pFirstPage || !pFirstPage->IsInteger()) {
722 m_docStatus = PDF_DATAAVAIL_ERROR;
723 return FALSE;
724 }
725
726 CPDF_Number* pPageCount = ToNumber(pDict->GetDirectObjectFor("N"));
727 if (!pPageCount || !pPageCount->IsInteger()) {
728 m_docStatus = PDF_DATAAVAIL_ERROR;
729 return FALSE;
730 }
731
732 int nPageCount = pPageCount->GetInteger();
733 if (nPageCount <= 1) {
734 m_docStatus = PDF_DATAAVAIL_DONE;
735 return TRUE;
736 }
737
738 CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H");
739 size_t nHintStreamSize = pHintStreamRange ? pHintStreamRange->GetCount() : 0;
740 if (nHintStreamSize != 2 && nHintStreamSize != 4) {
741 m_docStatus = PDF_DATAAVAIL_ERROR;
742 return FALSE;
743 }
744
745 for (const CPDF_Object* pArrayObject : *pHintStreamRange) {
746 const CPDF_Number* pNumber = ToNumber(pArrayObject->GetDirect());
747 if (!pNumber || !pNumber->IsInteger()) {
748 m_docStatus = PDF_DATAAVAIL_ERROR;
749 return FALSE;
750 }
751 }
752
753 FX_FILESIZE szHintStart = pHintStreamRange->GetIntegerAt(0);
754 FX_FILESIZE szHintLength = pHintStreamRange->GetIntegerAt(1);
755 if (szHintStart < 0 || szHintLength <= 0) {
756 m_docStatus = PDF_DATAAVAIL_ERROR;
757 return FALSE;
758 }
759 699
760 if (!IsDataAvail(szHintStart, szHintLength, pHints)) 700 if (!IsDataAvail(szHintStart, szHintLength, pHints))
761 return FALSE; 701 return FALSE;
762 702
763 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); 703 m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset);
764 704
765 std::unique_ptr<CPDF_HintTables> pHintTables( 705 std::unique_ptr<CPDF_HintTables> pHintTables(
766 new CPDF_HintTables(this, pDict)); 706 new CPDF_HintTables(this, m_pLinearized.get()));
767 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pHintStream( 707 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pHintStream(
768 ParseIndirectObjectAt(szHintStart, 0)); 708 ParseIndirectObjectAt(szHintStart, 0));
769 CPDF_Stream* pStream = ToStream(pHintStream.get()); 709 CPDF_Stream* pStream = ToStream(pHintStream.get());
770 if (pStream && pHintTables->LoadHintStream(pStream)) 710 if (pStream && pHintTables->LoadHintStream(pStream))
771 m_pHintTables = std::move(pHintTables); 711 m_pHintTables = std::move(pHintTables);
772 712
773 m_docStatus = PDF_DATAAVAIL_DONE; 713 m_docStatus = PDF_DATAAVAIL_DONE;
774 return TRUE; 714 return TRUE;
775 } 715 }
776 716
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 760
821 uint8_t buffer[1024]; 761 uint8_t buffer[1024];
822 m_pFileRead->ReadBlock(buffer, 0, kReqSize); 762 m_pFileRead->ReadBlock(buffer, 0, kReqSize);
823 if (IsLinearizedFile(buffer, kReqSize)) 763 if (IsLinearizedFile(buffer, kReqSize))
824 return Linearized; 764 return Linearized;
825 765
826 return NotLinearized; 766 return NotLinearized;
827 } 767 }
828 768
829 FX_BOOL CPDF_DataAvail::IsLinearized() { 769 FX_BOOL CPDF_DataAvail::IsLinearized() {
830 return m_bLinearized; 770 return !!m_pLinearized;
831 } 771 }
832 772
833 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) { 773 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) {
834 if (m_pLinearized) 774 if (m_pLinearized)
835 return m_bLinearized; 775 return TRUE;
836 776
837 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE)); 777 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE));
838 778
839 int32_t offset = GetHeaderOffset(file.get()); 779 int32_t offset = GetHeaderOffset(file.get());
840 if (offset == -1) { 780 if (offset == -1) {
841 m_docStatus = PDF_DATAAVAIL_ERROR; 781 m_docStatus = PDF_DATAAVAIL_ERROR;
842 return FALSE; 782 return FALSE;
843 } 783 }
844 784
845 m_dwHeaderOffset = offset; 785 m_dwHeaderOffset = offset;
846 m_syntaxParser.InitParser(file.get(), offset); 786 m_syntaxParser.InitParser(file.get(), offset);
847 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9); 787 m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9);
848 788
849 bool bNumber; 789 bool bNumber;
850 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber); 790 CFX_ByteString wordObjNum = m_syntaxParser.GetNextWord(&bNumber);
851 if (!bNumber) 791 if (!bNumber)
852 return FALSE; 792 return FALSE;
853 793
854 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str()); 794 uint32_t objnum = FXSYS_atoui(wordObjNum.c_str());
855 m_pLinearized = 795 m_pLinearized = CPDF_Linearized::CreateForObject(UniqueObject(
856 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum); 796 ParseIndirectObjectAt(m_syntaxParser.m_HeaderOffset + 9, objnum)));
857 if (!m_pLinearized) 797 if (!m_pLinearized || !m_pLinearized->IsValid() ||
798 m_pLinearized->GetFileSize() != m_pFileRead->GetSize()) {
799 m_pLinearized.reset();
858 return FALSE; 800 return FALSE;
859 801 }
860 CPDF_Dictionary* pDict = m_pLinearized->GetDict();
861 if (!pDict || !pDict->GetObjectFor("Linearized"))
862 return FALSE;
863
864 CPDF_Object* pLen = pDict->GetObjectFor("L");
865 if (!pLen)
866 return FALSE;
867
868 if ((FX_FILESIZE)pLen->GetInteger() != m_pFileRead->GetSize())
869 return FALSE;
870
871 m_bLinearized = TRUE;
872
873 if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P")))
874 m_dwFirstPageNo = pNo->GetInteger();
875
876 return TRUE; 802 return TRUE;
877 } 803 }
878 804
879 FX_BOOL CPDF_DataAvail::CheckEnd(DownloadHints* pHints) { 805 FX_BOOL CPDF_DataAvail::CheckEnd(DownloadHints* pHints) {
880 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0); 806 uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0);
881 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos); 807 uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos);
882 808
883 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) { 809 if (m_pFileAvail->IsDataAvail(req_pos, dwSize)) {
884 uint8_t buffer[1024]; 810 uint8_t buffer[1024];
885 m_pFileRead->ReadBlock(buffer, req_pos, dwSize); 811 m_pFileRead->ReadBlock(buffer, req_pos, dwSize);
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 m_bPageLoadedOK = FALSE; 1528 m_bPageLoadedOK = FALSE;
1603 m_bAnnotsLoad = FALSE; 1529 m_bAnnotsLoad = FALSE;
1604 m_bNeedDownLoadResource = FALSE; 1530 m_bNeedDownLoadResource = FALSE;
1605 m_objs_array.clear(); 1531 m_objs_array.clear();
1606 m_ObjectSet.clear(); 1532 m_ObjectSet.clear();
1607 } 1533 }
1608 1534
1609 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) 1535 if (pdfium::ContainsKey(m_pagesLoadState, dwPage))
1610 return DataAvailable; 1536 return DataAvailable;
1611 1537
1612 if (m_bLinearized) { 1538 if (m_pLinearized) {
1613 if (dwPage == m_dwFirstPageNo) { 1539 if (dwPage == m_pLinearized->GetFirstPageNo()) {
1614 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); 1540 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints);
1615 if (nRet == DataAvailable) 1541 if (nRet == DataAvailable)
1616 m_pagesLoadState.insert(dwPage); 1542 m_pagesLoadState.insert(dwPage);
1617 return nRet; 1543 return nRet;
1618 } 1544 }
1619 1545
1620 DocAvailStatus nResult = CheckLinearizedData(pHints); 1546 DocAvailStatus nResult = CheckLinearizedData(pHints);
1621 if (nResult != DataAvailable) 1547 if (nResult != DataAvailable)
1622 return nResult; 1548 return nResult;
1623 1549
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 1659
1734 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, 1660 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos,
1735 uint32_t* pSize) { 1661 uint32_t* pSize) {
1736 if (pPos) 1662 if (pPos)
1737 *pPos = m_dwLastXRefOffset; 1663 *pPos = m_dwLastXRefOffset;
1738 if (pSize) 1664 if (pSize)
1739 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); 1665 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset);
1740 } 1666 }
1741 1667
1742 int CPDF_DataAvail::GetPageCount() const { 1668 int CPDF_DataAvail::GetPageCount() const {
1743 if (m_pLinearized) { 1669 if (m_pLinearized)
1744 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); 1670 return m_pLinearized->GetPageCount();
1745 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("N") : nullptr;
1746 return pObj ? pObj->GetInteger() : 0;
1747 }
1748 return m_pDocument ? m_pDocument->GetPageCount() : 0; 1671 return m_pDocument ? m_pDocument->GetPageCount() : 0;
1749 } 1672 }
1750 1673
1751 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { 1674 CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) {
1752 if (!m_pDocument || index < 0 || index >= GetPageCount()) 1675 if (!m_pDocument || index < 0 || index >= GetPageCount())
1753 return nullptr; 1676 return nullptr;
1754 CPDF_Dictionary* page = m_pDocument->GetPage(index); 1677 CPDF_Dictionary* page = m_pDocument->GetPage(index);
1755 if (page) 1678 if (page)
1756 return page; 1679 return page;
1757 if (!m_pLinearized || !m_pHintTables) 1680 if (!m_pLinearized || !m_pHintTables)
1758 return nullptr; 1681 return nullptr;
1759 1682
1760 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); 1683 if (index == static_cast<int>(m_pLinearized->GetFirstPageNo()))
1761 CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("P") : nullptr;
1762 int firstPageNum = pObj ? pObj->GetInteger() : 0;
1763 if (index == firstPageNum)
1764 return nullptr; 1684 return nullptr;
1765 FX_FILESIZE szPageStartPos = 0; 1685 FX_FILESIZE szPageStartPos = 0;
1766 FX_FILESIZE szPageLength = 0; 1686 FX_FILESIZE szPageLength = 0;
1767 uint32_t dwObjNum = 0; 1687 uint32_t dwObjNum = 0;
1768 const bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, 1688 const bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos,
1769 &szPageLength, &dwObjNum); 1689 &szPageLength, &dwObjNum);
1770 if (!bPagePosGot || !dwObjNum) 1690 if (!bPagePosGot || !dwObjNum)
1771 return nullptr; 1691 return nullptr;
1772 // We should say to the document, which object is the page. 1692 // We should say to the document, which object is the page.
1773 m_pDocument->SetPageObjNum(index, dwObjNum); 1693 m_pDocument->SetPageObjNum(index, dwObjNum);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 return FormAvailable; 1738 return FormAvailable;
1819 } 1739 }
1820 1740
1821 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} 1741 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {}
1822 1742
1823 CPDF_DataAvail::PageNode::~PageNode() { 1743 CPDF_DataAvail::PageNode::~PageNode() {
1824 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) 1744 for (int32_t i = 0; i < m_childNode.GetSize(); ++i)
1825 delete m_childNode[i]; 1745 delete m_childNode[i];
1826 m_childNode.RemoveAll(); 1746 m_childNode.RemoveAll();
1827 } 1747 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698