| 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_parser.h" | |
| 11 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" | |
| 12 #include "core/fxcrt/fx_basic.h" | |
| 13 | |
| 14 class CPDF_Dictionary; | |
| 15 class CPDF_HintTables; | |
| 16 class CPDF_IndirectObjectHolder; | |
| 17 class CPDF_Parser; | |
| 18 | |
| 19 enum PDF_DATAAVAIL_STATUS { | |
| 20 PDF_DATAAVAIL_HEADER = 0, | |
| 21 PDF_DATAAVAIL_FIRSTPAGE, | |
| 22 PDF_DATAAVAIL_FIRSTPAGE_PREPARE, | |
| 23 PDF_DATAAVAIL_HINTTABLE, | |
| 24 PDF_DATAAVAIL_END, | |
| 25 PDF_DATAAVAIL_CROSSREF, | |
| 26 PDF_DATAAVAIL_CROSSREF_ITEM, | |
| 27 PDF_DATAAVAIL_CROSSREF_STREAM, | |
| 28 PDF_DATAAVAIL_TRAILER, | |
| 29 PDF_DATAAVAIL_LOADALLCROSSREF, | |
| 30 PDF_DATAAVAIL_ROOT, | |
| 31 PDF_DATAAVAIL_INFO, | |
| 32 PDF_DATAAVAIL_ACROFORM, | |
| 33 PDF_DATAAVAIL_ACROFORM_SUBOBJECT, | |
| 34 PDF_DATAAVAIL_PAGETREE, | |
| 35 PDF_DATAAVAIL_PAGE, | |
| 36 PDF_DATAAVAIL_PAGE_LATERLOAD, | |
| 37 PDF_DATAAVAIL_RESOURCES, | |
| 38 PDF_DATAAVAIL_DONE, | |
| 39 PDF_DATAAVAIL_ERROR, | |
| 40 PDF_DATAAVAIL_LOADALLFILE, | |
| 41 PDF_DATAAVAIL_TRAILER_APPEND | |
| 42 }; | |
| 43 | |
| 44 enum PDF_PAGENODE_TYPE { | |
| 45 PDF_PAGENODE_UNKNOWN = 0, | |
| 46 PDF_PAGENODE_PAGE, | |
| 47 PDF_PAGENODE_PAGES, | |
| 48 PDF_PAGENODE_ARRAY, | |
| 49 }; | |
| 50 | |
| 51 class CPDF_DataAvail final { | |
| 52 public: | |
| 53 // Must match PDF_DATA_* definitions in public/fpdf_dataavail.h, but cannot | |
| 54 // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts | |
| 55 // to make sure the two sets of values match. | |
| 56 enum DocAvailStatus { | |
| 57 DataError = -1, // PDF_DATA_ERROR | |
| 58 DataNotAvailable = 0, // PDF_DATA_NOTAVAIL | |
| 59 DataAvailable = 1, // PDF_DATA_AVAIL | |
| 60 }; | |
| 61 | |
| 62 // Must match PDF_*LINEAR* definitions in public/fpdf_dataavail.h, but cannot | |
| 63 // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts | |
| 64 // to make sure the two sets of values match. | |
| 65 enum DocLinearizationStatus { | |
| 66 LinearizationUnknown = -1, // PDF_LINEARIZATION_UNKNOWN | |
| 67 NotLinearized = 0, // PDF_NOT_LINEARIZED | |
| 68 Linearized = 1, // PDF_LINEARIZED | |
| 69 }; | |
| 70 | |
| 71 // Must match PDF_FORM_* definitions in public/fpdf_dataavail.h, but cannot | |
| 72 // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts | |
| 73 // to make sure the two sets of values match. | |
| 74 enum DocFormStatus { | |
| 75 FormError = -1, // PDF_FORM_ERROR | |
| 76 FormNotAvailable = 0, // PDF_FORM_NOTAVAIL | |
| 77 FormAvailable = 1, // PDF_FORM_AVAIL | |
| 78 FormNotExist = 2, // PDF_FORM_NOTEXIST | |
| 79 }; | |
| 80 | |
| 81 class FileAvail { | |
| 82 public: | |
| 83 virtual ~FileAvail(); | |
| 84 virtual FX_BOOL IsDataAvail(FX_FILESIZE offset, uint32_t size) = 0; | |
| 85 }; | |
| 86 | |
| 87 class DownloadHints { | |
| 88 public: | |
| 89 virtual ~DownloadHints(); | |
| 90 virtual void AddSegment(FX_FILESIZE offset, uint32_t size) = 0; | |
| 91 }; | |
| 92 | |
| 93 CPDF_DataAvail(FileAvail* pFileAvail, | |
| 94 IFX_FileRead* pFileRead, | |
| 95 FX_BOOL bSupportHintTable); | |
| 96 ~CPDF_DataAvail(); | |
| 97 | |
| 98 DocAvailStatus IsDocAvail(DownloadHints* pHints); | |
| 99 void SetDocument(CPDF_Document* pDoc); | |
| 100 DocAvailStatus IsPageAvail(uint32_t dwPage, DownloadHints* pHints); | |
| 101 DocFormStatus IsFormAvail(DownloadHints* pHints); | |
| 102 DocLinearizationStatus IsLinearizedPDF(); | |
| 103 FX_BOOL IsLinearized(); | |
| 104 void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, uint32_t* pSize); | |
| 105 IFX_FileRead* GetFileRead() const { return m_pFileRead; } | |
| 106 int GetPageCount() const; | |
| 107 CPDF_Dictionary* GetPage(int index); | |
| 108 | |
| 109 friend class CPDF_HintTables; | |
| 110 | |
| 111 protected: | |
| 112 class PageNode { | |
| 113 public: | |
| 114 PageNode(); | |
| 115 ~PageNode(); | |
| 116 | |
| 117 PDF_PAGENODE_TYPE m_type; | |
| 118 uint32_t m_dwPageNo; | |
| 119 CFX_ArrayTemplate<PageNode*> m_childNode; | |
| 120 }; | |
| 121 | |
| 122 static const int kMaxDataAvailRecursionDepth = 64; | |
| 123 static int s_CurrentDataAvailRecursionDepth; | |
| 124 static const int kMaxPageRecursionDepth = 1024; | |
| 125 | |
| 126 uint32_t GetObjectSize(uint32_t objnum, FX_FILESIZE& offset); | |
| 127 FX_BOOL IsObjectsAvail(CFX_ArrayTemplate<CPDF_Object*>& obj_array, | |
| 128 FX_BOOL bParsePage, | |
| 129 DownloadHints* pHints, | |
| 130 CFX_ArrayTemplate<CPDF_Object*>& ret_array); | |
| 131 FX_BOOL CheckDocStatus(DownloadHints* pHints); | |
| 132 FX_BOOL CheckHeader(DownloadHints* pHints); | |
| 133 FX_BOOL CheckFirstPage(DownloadHints* pHints); | |
| 134 FX_BOOL CheckHintTables(DownloadHints* pHints); | |
| 135 FX_BOOL CheckEnd(DownloadHints* pHints); | |
| 136 FX_BOOL CheckCrossRef(DownloadHints* pHints); | |
| 137 FX_BOOL CheckCrossRefItem(DownloadHints* pHints); | |
| 138 FX_BOOL CheckTrailer(DownloadHints* pHints); | |
| 139 FX_BOOL CheckRoot(DownloadHints* pHints); | |
| 140 FX_BOOL CheckInfo(DownloadHints* pHints); | |
| 141 FX_BOOL CheckPages(DownloadHints* pHints); | |
| 142 FX_BOOL CheckPage(DownloadHints* pHints); | |
| 143 FX_BOOL CheckResources(DownloadHints* pHints); | |
| 144 FX_BOOL CheckAnnots(DownloadHints* pHints); | |
| 145 FX_BOOL CheckAcroForm(DownloadHints* pHints); | |
| 146 FX_BOOL CheckAcroFormSubObject(DownloadHints* pHints); | |
| 147 FX_BOOL CheckTrailerAppend(DownloadHints* pHints); | |
| 148 FX_BOOL CheckPageStatus(DownloadHints* pHints); | |
| 149 FX_BOOL CheckAllCrossRefStream(DownloadHints* pHints); | |
| 150 | |
| 151 int32_t CheckCrossRefStream(DownloadHints* pHints, FX_FILESIZE& xref_offset); | |
| 152 FX_BOOL IsLinearizedFile(uint8_t* pData, uint32_t dwLen); | |
| 153 void SetStartOffset(FX_FILESIZE dwOffset); | |
| 154 FX_BOOL GetNextToken(CFX_ByteString& token); | |
| 155 FX_BOOL GetNextChar(uint8_t& ch); | |
| 156 CPDF_Object* ParseIndirectObjectAt( | |
| 157 FX_FILESIZE pos, | |
| 158 uint32_t objnum, | |
| 159 CPDF_IndirectObjectHolder* pObjList = nullptr); | |
| 160 CPDF_Object* GetObject(uint32_t objnum, | |
| 161 DownloadHints* pHints, | |
| 162 FX_BOOL* pExistInFile); | |
| 163 FX_BOOL GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages); | |
| 164 FX_BOOL PreparePageItem(); | |
| 165 FX_BOOL LoadPages(DownloadHints* pHints); | |
| 166 FX_BOOL LoadAllXref(DownloadHints* pHints); | |
| 167 FX_BOOL LoadAllFile(DownloadHints* pHints); | |
| 168 DocAvailStatus CheckLinearizedData(DownloadHints* pHints); | |
| 169 FX_BOOL CheckPageAnnots(uint32_t dwPage, DownloadHints* pHints); | |
| 170 | |
| 171 DocAvailStatus CheckLinearizedFirstPage(uint32_t dwPage, | |
| 172 DownloadHints* pHints); | |
| 173 FX_BOOL HaveResourceAncestor(CPDF_Dictionary* pDict); | |
| 174 FX_BOOL CheckPage(uint32_t dwPage, DownloadHints* pHints); | |
| 175 FX_BOOL LoadDocPages(DownloadHints* pHints); | |
| 176 FX_BOOL LoadDocPage(uint32_t dwPage, DownloadHints* pHints); | |
| 177 FX_BOOL CheckPageNode(PageNode& pageNodes, | |
| 178 int32_t iPage, | |
| 179 int32_t& iCount, | |
| 180 DownloadHints* pHints, | |
| 181 int level); | |
| 182 FX_BOOL CheckUnkownPageNode(uint32_t dwPageNo, | |
| 183 PageNode* pPageNode, | |
| 184 DownloadHints* pHints); | |
| 185 FX_BOOL CheckArrayPageNode(uint32_t dwPageNo, | |
| 186 PageNode* pPageNode, | |
| 187 DownloadHints* pHints); | |
| 188 FX_BOOL CheckPageCount(DownloadHints* pHints); | |
| 189 bool IsFirstCheck(uint32_t dwPage); | |
| 190 void ResetFirstCheck(uint32_t dwPage); | |
| 191 FX_BOOL IsDataAvail(FX_FILESIZE offset, uint32_t size, DownloadHints* pHints); | |
| 192 | |
| 193 FileAvail* const m_pFileAvail; | |
| 194 IFX_FileRead* const m_pFileRead; | |
| 195 CPDF_Parser m_parser; | |
| 196 CPDF_SyntaxParser m_syntaxParser; | |
| 197 CPDF_Object* m_pRoot; | |
| 198 uint32_t m_dwRootObjNum; | |
| 199 uint32_t m_dwInfoObjNum; | |
| 200 CPDF_Object* m_pLinearized; | |
| 201 CPDF_Object* m_pTrailer; | |
| 202 FX_BOOL m_bDocAvail; | |
| 203 FX_FILESIZE m_dwHeaderOffset; | |
| 204 FX_FILESIZE m_dwLastXRefOffset; | |
| 205 FX_FILESIZE m_dwXRefOffset; | |
| 206 FX_FILESIZE m_dwTrailerOffset; | |
| 207 FX_FILESIZE m_dwCurrentOffset; | |
| 208 PDF_DATAAVAIL_STATUS m_docStatus; | |
| 209 FX_FILESIZE m_dwFileLen; | |
| 210 CPDF_Document* m_pDocument; | |
| 211 std::set<uint32_t> m_ObjectSet; | |
| 212 CFX_ArrayTemplate<CPDF_Object*> m_objs_array; | |
| 213 FX_FILESIZE m_Pos; | |
| 214 FX_FILESIZE m_bufferOffset; | |
| 215 uint32_t m_bufferSize; | |
| 216 CFX_ByteString m_WordBuf; | |
| 217 uint8_t m_bufferData[512]; | |
| 218 CFX_ArrayTemplate<uint32_t> m_XRefStreamList; | |
| 219 CFX_ArrayTemplate<uint32_t> m_PageObjList; | |
| 220 uint32_t m_PagesObjNum; | |
| 221 FX_BOOL m_bLinearized; | |
| 222 uint32_t m_dwFirstPageNo; | |
| 223 FX_BOOL m_bLinearedDataOK; | |
| 224 FX_BOOL m_bMainXRefLoadTried; | |
| 225 FX_BOOL m_bMainXRefLoadedOK; | |
| 226 FX_BOOL m_bPagesTreeLoad; | |
| 227 FX_BOOL m_bPagesLoad; | |
| 228 CPDF_Parser* m_pCurrentParser; | |
| 229 FX_FILESIZE m_dwCurrentXRefSteam; | |
| 230 FX_BOOL m_bAnnotsLoad; | |
| 231 FX_BOOL m_bHaveAcroForm; | |
| 232 uint32_t m_dwAcroFormObjNum; | |
| 233 FX_BOOL m_bAcroFormLoad; | |
| 234 CPDF_Object* m_pAcroForm; | |
| 235 CFX_ArrayTemplate<CPDF_Object*> m_arrayAcroforms; | |
| 236 CPDF_Dictionary* m_pPageDict; | |
| 237 CPDF_Object* m_pPageResource; | |
| 238 FX_BOOL m_bNeedDownLoadResource; | |
| 239 FX_BOOL m_bPageLoadedOK; | |
| 240 FX_BOOL m_bLinearizedFormParamLoad; | |
| 241 CFX_ArrayTemplate<CPDF_Object*> m_PagesArray; | |
| 242 uint32_t m_dwEncryptObjNum; | |
| 243 FX_FILESIZE m_dwPrevXRefOffset; | |
| 244 FX_BOOL m_bTotalLoadPageTree; | |
| 245 FX_BOOL m_bCurPageDictLoadOK; | |
| 246 PageNode m_pageNodes; | |
| 247 std::set<uint32_t> m_pageMapCheckState; | |
| 248 std::set<uint32_t> m_pagesLoadState; | |
| 249 std::unique_ptr<CPDF_HintTables> m_pHintTables; | |
| 250 FX_BOOL m_bSupportHintTable; | |
| 251 }; | |
| 252 | |
| 253 #endif // CORE_FPDFAPI_FPDF_PARSER_CPDF_DATA_AVAIL_H_ | |
| OLD | NEW |