OLD | NEW |
| (Empty) |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #ifndef CORE_FPDFAPI_FPDF_PARSER_CPDF_DATA_AVAIL_H_ | |
8 #define CORE_FPDFAPI_FPDF_PARSER_CPDF_DATA_AVAIL_H_ | |
9 | |
10 #include "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" | |
11 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" | |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" | |
13 #include "core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h" | |
14 #include "core/fxcrt/include/fx_basic.h" | |
15 | |
16 class CPDF_Dictionary; | |
17 class CPDF_IndirectObjectHolder; | |
18 class CPDF_Parser; | |
19 | |
20 enum PDF_DATAAVAIL_STATUS { | |
21 PDF_DATAAVAIL_HEADER = 0, | |
22 PDF_DATAAVAIL_FIRSTPAGE, | |
23 PDF_DATAAVAIL_FIRSTPAGE_PREPARE, | |
24 PDF_DATAAVAIL_HINTTABLE, | |
25 PDF_DATAAVAIL_END, | |
26 PDF_DATAAVAIL_CROSSREF, | |
27 PDF_DATAAVAIL_CROSSREF_ITEM, | |
28 PDF_DATAAVAIL_CROSSREF_STREAM, | |
29 PDF_DATAAVAIL_TRAILER, | |
30 PDF_DATAAVAIL_LOADALLCROSSREF, | |
31 PDF_DATAAVAIL_ROOT, | |
32 PDF_DATAAVAIL_INFO, | |
33 PDF_DATAAVAIL_ACROFORM, | |
34 PDF_DATAAVAIL_ACROFORM_SUBOBJECT, | |
35 PDF_DATAAVAIL_PAGETREE, | |
36 PDF_DATAAVAIL_PAGE, | |
37 PDF_DATAAVAIL_PAGE_LATERLOAD, | |
38 PDF_DATAAVAIL_RESOURCES, | |
39 PDF_DATAAVAIL_DONE, | |
40 PDF_DATAAVAIL_ERROR, | |
41 PDF_DATAAVAIL_LOADALLFILE, | |
42 PDF_DATAAVAIL_TRAILER_APPEND | |
43 }; | |
44 | |
45 enum PDF_PAGENODE_TYPE { | |
46 PDF_PAGENODE_UNKNOWN = 0, | |
47 PDF_PAGENODE_PAGE, | |
48 PDF_PAGENODE_PAGES, | |
49 PDF_PAGENODE_ARRAY, | |
50 }; | |
51 | |
52 class CPDF_DataAvail final : public IPDF_DataAvail { | |
53 public: | |
54 CPDF_DataAvail(FileAvail* pFileAvail, | |
55 IFX_FileRead* pFileRead, | |
56 FX_BOOL bSupportHintTable); | |
57 ~CPDF_DataAvail() override; | |
58 | |
59 // IPDF_DataAvail | |
60 DocAvailStatus IsDocAvail(DownloadHints* pHints) override; | |
61 void SetDocument(CPDF_Document* pDoc) override; | |
62 DocAvailStatus IsPageAvail(int iPage, DownloadHints* pHints) override; | |
63 DocFormStatus IsFormAvail(DownloadHints* pHints) override; | |
64 DocLinearizationStatus IsLinearizedPDF() override; | |
65 FX_BOOL IsLinearized() override; | |
66 void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, uint32_t* pSize) override; | |
67 | |
68 int GetPageCount() const; | |
69 CPDF_Dictionary* GetPage(int index); | |
70 | |
71 friend class CPDF_HintTables; | |
72 | |
73 protected: | |
74 class PageNode { | |
75 public: | |
76 PageNode(); | |
77 ~PageNode(); | |
78 | |
79 PDF_PAGENODE_TYPE m_type; | |
80 uint32_t m_dwPageNo; | |
81 CFX_ArrayTemplate<PageNode*> m_childNode; | |
82 }; | |
83 | |
84 static const int kMaxDataAvailRecursionDepth = 64; | |
85 static int s_CurrentDataAvailRecursionDepth; | |
86 static const int kMaxPageRecursionDepth = 1024; | |
87 | |
88 uint32_t GetObjectSize(uint32_t objnum, FX_FILESIZE& offset); | |
89 FX_BOOL IsObjectsAvail(CFX_ArrayTemplate<CPDF_Object*>& obj_array, | |
90 FX_BOOL bParsePage, | |
91 IPDF_DataAvail::DownloadHints* pHints, | |
92 CFX_ArrayTemplate<CPDF_Object*>& ret_array); | |
93 FX_BOOL CheckDocStatus(IPDF_DataAvail::DownloadHints* pHints); | |
94 FX_BOOL CheckHeader(IPDF_DataAvail::DownloadHints* pHints); | |
95 FX_BOOL CheckFirstPage(IPDF_DataAvail::DownloadHints* pHints); | |
96 FX_BOOL CheckHintTables(IPDF_DataAvail::DownloadHints* pHints); | |
97 FX_BOOL CheckEnd(IPDF_DataAvail::DownloadHints* pHints); | |
98 FX_BOOL CheckCrossRef(IPDF_DataAvail::DownloadHints* pHints); | |
99 FX_BOOL CheckCrossRefItem(IPDF_DataAvail::DownloadHints* pHints); | |
100 FX_BOOL CheckTrailer(IPDF_DataAvail::DownloadHints* pHints); | |
101 FX_BOOL CheckRoot(IPDF_DataAvail::DownloadHints* pHints); | |
102 FX_BOOL CheckInfo(IPDF_DataAvail::DownloadHints* pHints); | |
103 FX_BOOL CheckPages(IPDF_DataAvail::DownloadHints* pHints); | |
104 FX_BOOL CheckPage(IPDF_DataAvail::DownloadHints* pHints); | |
105 FX_BOOL CheckResources(IPDF_DataAvail::DownloadHints* pHints); | |
106 FX_BOOL CheckAnnots(IPDF_DataAvail::DownloadHints* pHints); | |
107 FX_BOOL CheckAcroForm(IPDF_DataAvail::DownloadHints* pHints); | |
108 FX_BOOL CheckAcroFormSubObject(IPDF_DataAvail::DownloadHints* pHints); | |
109 FX_BOOL CheckTrailerAppend(IPDF_DataAvail::DownloadHints* pHints); | |
110 FX_BOOL CheckPageStatus(IPDF_DataAvail::DownloadHints* pHints); | |
111 FX_BOOL CheckAllCrossRefStream(IPDF_DataAvail::DownloadHints* pHints); | |
112 | |
113 int32_t CheckCrossRefStream(IPDF_DataAvail::DownloadHints* pHints, | |
114 FX_FILESIZE& xref_offset); | |
115 FX_BOOL IsLinearizedFile(uint8_t* pData, uint32_t dwLen); | |
116 void SetStartOffset(FX_FILESIZE dwOffset); | |
117 FX_BOOL GetNextToken(CFX_ByteString& token); | |
118 FX_BOOL GetNextChar(uint8_t& ch); | |
119 CPDF_Object* ParseIndirectObjectAt( | |
120 FX_FILESIZE pos, | |
121 uint32_t objnum, | |
122 CPDF_IndirectObjectHolder* pObjList = nullptr); | |
123 CPDF_Object* GetObject(uint32_t objnum, | |
124 IPDF_DataAvail::DownloadHints* pHints, | |
125 FX_BOOL* pExistInFile); | |
126 FX_BOOL GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages); | |
127 FX_BOOL PreparePageItem(); | |
128 FX_BOOL LoadPages(IPDF_DataAvail::DownloadHints* pHints); | |
129 FX_BOOL LoadAllXref(IPDF_DataAvail::DownloadHints* pHints); | |
130 FX_BOOL LoadAllFile(IPDF_DataAvail::DownloadHints* pHints); | |
131 DocAvailStatus CheckLinearizedData(IPDF_DataAvail::DownloadHints* pHints); | |
132 FX_BOOL CheckPageAnnots(int iPage, IPDF_DataAvail::DownloadHints* pHints); | |
133 | |
134 DocAvailStatus CheckLinearizedFirstPage( | |
135 int iPage, | |
136 IPDF_DataAvail::DownloadHints* pHints); | |
137 FX_BOOL HaveResourceAncestor(CPDF_Dictionary* pDict); | |
138 FX_BOOL CheckPage(int32_t iPage, IPDF_DataAvail::DownloadHints* pHints); | |
139 FX_BOOL LoadDocPages(IPDF_DataAvail::DownloadHints* pHints); | |
140 FX_BOOL LoadDocPage(int32_t iPage, IPDF_DataAvail::DownloadHints* pHints); | |
141 FX_BOOL CheckPageNode(PageNode& pageNodes, | |
142 int32_t iPage, | |
143 int32_t& iCount, | |
144 IPDF_DataAvail::DownloadHints* pHints, | |
145 int level); | |
146 FX_BOOL CheckUnkownPageNode(uint32_t dwPageNo, | |
147 PageNode* pPageNode, | |
148 IPDF_DataAvail::DownloadHints* pHints); | |
149 FX_BOOL CheckArrayPageNode(uint32_t dwPageNo, | |
150 PageNode* pPageNode, | |
151 IPDF_DataAvail::DownloadHints* pHints); | |
152 FX_BOOL CheckPageCount(IPDF_DataAvail::DownloadHints* pHints); | |
153 bool IsFirstCheck(int iPage); | |
154 void ResetFirstCheck(int iPage); | |
155 FX_BOOL IsDataAvail(FX_FILESIZE offset, | |
156 uint32_t size, | |
157 IPDF_DataAvail::DownloadHints* pHints); | |
158 | |
159 CPDF_Parser m_parser; | |
160 CPDF_SyntaxParser m_syntaxParser; | |
161 CPDF_Object* m_pRoot; | |
162 uint32_t m_dwRootObjNum; | |
163 uint32_t m_dwInfoObjNum; | |
164 CPDF_Object* m_pLinearized; | |
165 CPDF_Object* m_pTrailer; | |
166 FX_BOOL m_bDocAvail; | |
167 FX_FILESIZE m_dwHeaderOffset; | |
168 FX_FILESIZE m_dwLastXRefOffset; | |
169 FX_FILESIZE m_dwXRefOffset; | |
170 FX_FILESIZE m_dwTrailerOffset; | |
171 FX_FILESIZE m_dwCurrentOffset; | |
172 PDF_DATAAVAIL_STATUS m_docStatus; | |
173 FX_FILESIZE m_dwFileLen; | |
174 CPDF_Document* m_pDocument; | |
175 std::set<uint32_t> m_ObjectSet; | |
176 CFX_ArrayTemplate<CPDF_Object*> m_objs_array; | |
177 FX_FILESIZE m_Pos; | |
178 FX_FILESIZE m_bufferOffset; | |
179 uint32_t m_bufferSize; | |
180 CFX_ByteString m_WordBuf; | |
181 uint8_t m_bufferData[512]; | |
182 CFX_ArrayTemplate<uint32_t> m_XRefStreamList; | |
183 CFX_ArrayTemplate<uint32_t> m_PageObjList; | |
184 uint32_t m_PagesObjNum; | |
185 FX_BOOL m_bLinearized; | |
186 uint32_t m_dwFirstPageNo; | |
187 FX_BOOL m_bLinearedDataOK; | |
188 FX_BOOL m_bMainXRefLoadTried; | |
189 FX_BOOL m_bMainXRefLoadedOK; | |
190 FX_BOOL m_bPagesTreeLoad; | |
191 FX_BOOL m_bPagesLoad; | |
192 CPDF_Parser* m_pCurrentParser; | |
193 FX_FILESIZE m_dwCurrentXRefSteam; | |
194 FX_BOOL m_bAnnotsLoad; | |
195 FX_BOOL m_bHaveAcroForm; | |
196 uint32_t m_dwAcroFormObjNum; | |
197 FX_BOOL m_bAcroFormLoad; | |
198 CPDF_Object* m_pAcroForm; | |
199 CFX_ArrayTemplate<CPDF_Object*> m_arrayAcroforms; | |
200 CPDF_Dictionary* m_pPageDict; | |
201 CPDF_Object* m_pPageResource; | |
202 FX_BOOL m_bNeedDownLoadResource; | |
203 FX_BOOL m_bPageLoadedOK; | |
204 FX_BOOL m_bLinearizedFormParamLoad; | |
205 CFX_ArrayTemplate<CPDF_Object*> m_PagesArray; | |
206 uint32_t m_dwEncryptObjNum; | |
207 FX_FILESIZE m_dwPrevXRefOffset; | |
208 FX_BOOL m_bTotalLoadPageTree; | |
209 FX_BOOL m_bCurPageDictLoadOK; | |
210 PageNode m_pageNodes; | |
211 std::set<uint32_t> m_pageMapCheckState; | |
212 std::set<uint32_t> m_pagesLoadState; | |
213 std::unique_ptr<CPDF_HintTables> m_pHintTables; | |
214 FX_BOOL m_bSupportHintTable; | |
215 }; | |
216 | |
217 #endif // CORE_FPDFAPI_FPDF_PARSER_CPDF_DATA_AVAIL_H_ | |
OLD | NEW |