| 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_INCLUDE_FPDFAPI_FPDF_PARSER_H_ |  | 
|    8 #define CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ |  | 
|    9  |  | 
|   10 #include <map> |  | 
|   11 #include <memory> |  | 
|   12 #include <set> |  | 
|   13  |  | 
|   14 #include "core/include/fpdfapi/fpdf_objects.h" |  | 
|   15 #include "core/include/fxcrt/fx_basic.h" |  | 
|   16  |  | 
|   17 class CFX_Font; |  | 
|   18 class CFX_Matrix; |  | 
|   19 class CPDF_ColorSpace; |  | 
|   20 class IPDF_CryptoHandler; |  | 
|   21 class CPDF_Document; |  | 
|   22 class CPDF_DocPageData; |  | 
|   23 class CPDF_DocRenderData; |  | 
|   24 class CPDF_Font; |  | 
|   25 class CPDF_FontEncoding; |  | 
|   26 class CPDF_IccProfile; |  | 
|   27 class CPDF_Image; |  | 
|   28 class CPDF_Object; |  | 
|   29 class CPDF_Parser; |  | 
|   30 class CPDF_Pattern; |  | 
|   31 class CPDF_StandardSecurityHandler; |  | 
|   32 class CPDF_SyntaxParser; |  | 
|   33 class IPDF_SecurityHandler; |  | 
|   34  |  | 
|   35 #define FPDFPERM_PRINT 0x0004 |  | 
|   36 #define FPDFPERM_MODIFY 0x0008 |  | 
|   37 #define FPDFPERM_EXTRACT 0x0010 |  | 
|   38 #define FPDFPERM_ANNOT_FORM 0x0020 |  | 
|   39 #define FPDFPERM_FILL_FORM 0x0100 |  | 
|   40 #define FPDFPERM_EXTRACT_ACCESS 0x0200 |  | 
|   41 #define FPDFPERM_ASSEMBLE 0x0400 |  | 
|   42 #define FPDFPERM_PRINT_HIGH 0x0800 |  | 
|   43 #define FPDF_PAGE_MAX_NUM 0xFFFFF |  | 
|   44  |  | 
|   45 // Indexed by 8-bit char code, contains unicode code points. |  | 
|   46 extern const FX_WORD PDFDocEncoding[256]; |  | 
|   47  |  | 
|   48  |  | 
|   49 CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& orig); |  | 
|   50 CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig); |  | 
|   51 CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig); |  | 
|   52 CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, |  | 
|   53                                 FX_BOOL bHex = FALSE); |  | 
|   54 CFX_WideString PDF_DecodeText(const uint8_t* pData, FX_DWORD size); |  | 
|   55 CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr); |  | 
|   56 CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len = -1); |  | 
|   57 CFX_ByteString PDF_EncodeText(const CFX_WideString& str); |  | 
|   58  |  | 
|   59 class CFDF_Document : public CPDF_IndirectObjectHolder { |  | 
|   60  public: |  | 
|   61   static CFDF_Document* CreateNewDoc(); |  | 
|   62   static CFDF_Document* ParseFile(IFX_FileRead* pFile, |  | 
|   63                                   FX_BOOL bOwnFile = FALSE); |  | 
|   64   static CFDF_Document* ParseMemory(const uint8_t* pData, FX_DWORD size); |  | 
|   65   ~CFDF_Document(); |  | 
|   66  |  | 
|   67   FX_BOOL WriteBuf(CFX_ByteTextBuf& buf) const; |  | 
|   68   CPDF_Dictionary* GetRoot() const { return m_pRootDict; } |  | 
|   69  |  | 
|   70  protected: |  | 
|   71   CFDF_Document(); |  | 
|   72   void ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile); |  | 
|   73  |  | 
|   74   CPDF_Dictionary* m_pRootDict; |  | 
|   75   IFX_FileRead* m_pFile; |  | 
|   76   FX_BOOL m_bOwnFile; |  | 
|   77 }; |  | 
|   78  |  | 
|   79 void FlateEncode(const uint8_t* src_buf, |  | 
|   80                  FX_DWORD src_size, |  | 
|   81                  uint8_t*& dest_buf, |  | 
|   82                  FX_DWORD& dest_size); |  | 
|   83 void FlateEncode(const uint8_t* src_buf, |  | 
|   84                  FX_DWORD src_size, |  | 
|   85                  int predictor, |  | 
|   86                  int Colors, |  | 
|   87                  int BitsPerComponent, |  | 
|   88                  int Columns, |  | 
|   89                  uint8_t*& dest_buf, |  | 
|   90                  FX_DWORD& dest_size); |  | 
|   91 FX_DWORD FlateDecode(const uint8_t* src_buf, |  | 
|   92                      FX_DWORD src_size, |  | 
|   93                      uint8_t*& dest_buf, |  | 
|   94                      FX_DWORD& dest_size); |  | 
|   95 FX_DWORD RunLengthDecode(const uint8_t* src_buf, |  | 
|   96                          FX_DWORD src_size, |  | 
|   97                          uint8_t*& dest_buf, |  | 
|   98                          FX_DWORD& dest_size); |  | 
|   99 bool IsSignatureDict(const CPDF_Dictionary* pDict); |  | 
|  100  |  | 
|  101 class IFX_FileAvail { |  | 
|  102  public: |  | 
|  103   virtual ~IFX_FileAvail() {} |  | 
|  104   virtual FX_BOOL IsDataAvail(FX_FILESIZE offset, FX_DWORD size) = 0; |  | 
|  105 }; |  | 
|  106 class IFX_DownloadHints { |  | 
|  107  public: |  | 
|  108   virtual ~IFX_DownloadHints() {} |  | 
|  109   virtual void AddSegment(FX_FILESIZE offset, FX_DWORD size) = 0; |  | 
|  110 }; |  | 
|  111  |  | 
|  112 class IPDF_DataAvail { |  | 
|  113  public: |  | 
|  114   // Must match PDF_DATA_* definitions in public/fpdf_dataavail.h, but cannot |  | 
|  115   // #include that header. fpdfsdk/src/fpdf_dataavail.cpp has static_asserts |  | 
|  116   // to make sure the two sets of values match. |  | 
|  117   enum DocAvailStatus { |  | 
|  118     DataError = -1,        // PDF_DATA_ERROR |  | 
|  119     DataNotAvailable = 0,  // PDF_DATA_NOTAVAIL |  | 
|  120     DataAvailable = 1,     // PDF_DATA_AVAIL |  | 
|  121   }; |  | 
|  122  |  | 
|  123   // Must match PDF_*LINEAR* definitions in public/fpdf_dataavail.h, but cannot |  | 
|  124   // #include that header. fpdfsdk/src/fpdf_dataavail.cpp has static_asserts |  | 
|  125   // to make sure the two sets of values match. |  | 
|  126   enum DocLinearizationStatus { |  | 
|  127     LinearizationUnknown = -1,  // PDF_LINEARIZATION_UNKNOWN |  | 
|  128     NotLinearized = 0,          // PDF_NOT_LINEARIZED |  | 
|  129     Linearized = 1,             // PDF_LINEARIZED |  | 
|  130   }; |  | 
|  131  |  | 
|  132   // Must match PDF_FORM_* definitions in public/fpdf_dataavail.h, but cannot |  | 
|  133   // #include that header. fpdfsdk/src/fpdf_dataavail.cpp has static_asserts |  | 
|  134   // to make sure the two sets of values match. |  | 
|  135   enum DocFormStatus { |  | 
|  136     FormError = -1,        // PDF_FORM_ERROR |  | 
|  137     FormNotAvailable = 0,  // PDF_FORM_NOTAVAIL |  | 
|  138     FormAvailable = 1,     // PDF_FORM_AVAIL |  | 
|  139     FormNotExist = 2,      // PDF_FORM_NOTEXIST |  | 
|  140   }; |  | 
|  141  |  | 
|  142   static IPDF_DataAvail* Create(IFX_FileAvail* pFileAvail, |  | 
|  143                                 IFX_FileRead* pFileRead); |  | 
|  144   virtual ~IPDF_DataAvail() {} |  | 
|  145  |  | 
|  146   IFX_FileAvail* GetFileAvail() const { return m_pFileAvail; } |  | 
|  147   IFX_FileRead* GetFileRead() const { return m_pFileRead; } |  | 
|  148  |  | 
|  149   virtual DocAvailStatus IsDocAvail(IFX_DownloadHints* pHints) = 0; |  | 
|  150   virtual void SetDocument(CPDF_Document* pDoc) = 0; |  | 
|  151   virtual DocAvailStatus IsPageAvail(int iPage, IFX_DownloadHints* pHints) = 0; |  | 
|  152   virtual FX_BOOL IsLinearized() = 0; |  | 
|  153   virtual DocFormStatus IsFormAvail(IFX_DownloadHints* pHints) = 0; |  | 
|  154   virtual DocLinearizationStatus IsLinearizedPDF() = 0; |  | 
|  155   virtual void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, |  | 
|  156                                          FX_DWORD* pSize) = 0; |  | 
|  157  |  | 
|  158  protected: |  | 
|  159   IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); |  | 
|  160  |  | 
|  161   IFX_FileAvail* m_pFileAvail; |  | 
|  162   IFX_FileRead* m_pFileRead; |  | 
|  163 }; |  | 
|  164  |  | 
|  165 enum PDF_PAGENODE_TYPE { |  | 
|  166   PDF_PAGENODE_UNKNOWN = 0, |  | 
|  167   PDF_PAGENODE_PAGE, |  | 
|  168   PDF_PAGENODE_PAGES, |  | 
|  169   PDF_PAGENODE_ARRAY, |  | 
|  170 }; |  | 
|  171  |  | 
|  172 class CPDF_PageNode { |  | 
|  173  public: |  | 
|  174   CPDF_PageNode(); |  | 
|  175   ~CPDF_PageNode(); |  | 
|  176  |  | 
|  177   PDF_PAGENODE_TYPE m_type; |  | 
|  178   FX_DWORD m_dwPageNo; |  | 
|  179   CFX_ArrayTemplate<CPDF_PageNode*> m_childNode; |  | 
|  180 }; |  | 
|  181  |  | 
|  182 enum PDF_DATAAVAIL_STATUS { |  | 
|  183   PDF_DATAAVAIL_HEADER = 0, |  | 
|  184   PDF_DATAAVAIL_FIRSTPAGE, |  | 
|  185   PDF_DATAAVAIL_FIRSTPAGE_PREPARE, |  | 
|  186   PDF_DATAAVAIL_HINTTABLE, |  | 
|  187   PDF_DATAAVAIL_END, |  | 
|  188   PDF_DATAAVAIL_CROSSREF, |  | 
|  189   PDF_DATAAVAIL_CROSSREF_ITEM, |  | 
|  190   PDF_DATAAVAIL_CROSSREF_STREAM, |  | 
|  191   PDF_DATAAVAIL_TRAILER, |  | 
|  192   PDF_DATAAVAIL_LOADALLCROSSREF, |  | 
|  193   PDF_DATAAVAIL_ROOT, |  | 
|  194   PDF_DATAAVAIL_INFO, |  | 
|  195   PDF_DATAAVAIL_ACROFORM, |  | 
|  196   PDF_DATAAVAIL_ACROFORM_SUBOBJECT, |  | 
|  197   PDF_DATAAVAIL_PAGETREE, |  | 
|  198   PDF_DATAAVAIL_PAGE, |  | 
|  199   PDF_DATAAVAIL_PAGE_LATERLOAD, |  | 
|  200   PDF_DATAAVAIL_RESOURCES, |  | 
|  201   PDF_DATAAVAIL_DONE, |  | 
|  202   PDF_DATAAVAIL_ERROR, |  | 
|  203   PDF_DATAAVAIL_LOADALLFILE, |  | 
|  204   PDF_DATAAVAIL_TRAILER_APPEND |  | 
|  205 }; |  | 
|  206  |  | 
|  207 // Public for testing. |  | 
|  208 FX_DWORD A85Decode(const uint8_t* src_buf, |  | 
|  209                    FX_DWORD src_size, |  | 
|  210                    uint8_t*& dest_buf, |  | 
|  211                    FX_DWORD& dest_size); |  | 
|  212 // Public for testing. |  | 
|  213 FX_DWORD HexDecode(const uint8_t* src_buf, |  | 
|  214                    FX_DWORD src_size, |  | 
|  215                    uint8_t*& dest_buf, |  | 
|  216                    FX_DWORD& dest_size); |  | 
|  217 // Public for testing. |  | 
|  218 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, |  | 
|  219                                   const uint8_t* src_buf, |  | 
|  220                                   FX_DWORD src_size, |  | 
|  221                                   CPDF_Dictionary* pParams, |  | 
|  222                                   FX_DWORD estimated_size, |  | 
|  223                                   uint8_t*& dest_buf, |  | 
|  224                                   FX_DWORD& dest_size); |  | 
|  225 FX_BOOL PDF_DataDecode(const uint8_t* src_buf, |  | 
|  226                        FX_DWORD src_size, |  | 
|  227                        const CPDF_Dictionary* pDict, |  | 
|  228                        uint8_t*& dest_buf, |  | 
|  229                        FX_DWORD& dest_size, |  | 
|  230                        CFX_ByteString& ImageEncoding, |  | 
|  231                        CPDF_Dictionary*& pImageParms, |  | 
|  232                        FX_DWORD estimated_size, |  | 
|  233                        FX_BOOL bImageAcc); |  | 
|  234  |  | 
|  235 #endif  // CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ |  | 
| OLD | NEW |