Add PDFCharIsLineEnding helper
[pdfium.git] / core / include / fpdfapi / fpdf_parser.h
index 9d41539..32509eb 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#ifndef _FPDF_PARSER_\r
-#define _FPDF_PARSER_\r
-#ifndef _FX_BASIC_H_\r
-#include "../fxcrt/fx_ext.h"\r
-#endif\r
-#ifndef _FPDF_OBJECTS_\r
-#include "fpdf_objects.h"\r
-#endif\r
-class CPDF_Document;\r
-class IPDF_DocParser;\r
-class CPDF_Parser;\r
-class CPDF_SecurityHandler;\r
-class CPDF_StandardSecurityHandler;\r
-class CPDF_CryptoHandler;\r
-class CPDF_Object;\r
-class IFX_FileRead;\r
-class CFDF_Document;\r
-class CFDF_Parser;\r
-class CFX_Font;\r
-class CFX_AffineMatrix;\r
-class CFX_FloatRect;\r
-class CPDF_Point;\r
-class CPDF_DocPageData;\r
-class CPDF_DocRenderData;\r
-class CPDF_ModuleMgr;\r
-class CFX_DIBSource;\r
-class CPDF_Font;\r
-class CPDF_Image;\r
-class CPDF_ColorSpace;\r
-class CPDF_Pattern;\r
-class CPDF_FontEncoding;\r
-class CPDF_IccProfile;\r
-class CFX_PrivateData;\r
-#define FPDFPERM_PRINT                 0x0004\r
-#define FPDFPERM_MODIFY                        0x0008\r
-#define FPDFPERM_EXTRACT               0x0010\r
-#define FPDFPERM_ANNOT_FORM            0x0020\r
-#define FPDFPERM_FILL_FORM             0x0100\r
-#define FPDFPERM_EXTRACT_ACCESS        0x0200\r
-#define FPDFPERM_ASSEMBLE              0x0400\r
-#define FPDFPERM_PRINT_HIGH            0x0800\r
-#define FPDF_PAGE_MAX_NUM              0xFFFFF\r
-class IPDF_EnumPageHandler\r
-{\r
-public:\r
-\r
-    virtual FX_BOOL EnumPage(CPDF_Dictionary* pPageDict) = 0;\r
-};\r
-class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjects\r
-{\r
-public:\r
-\r
-    CPDF_Document(IPDF_DocParser* pParser);\r
-\r
-    CPDF_Document();\r
-\r
-    ~CPDF_Document();\r
-\r
-    IPDF_DocParser*                    GetParser() const\r
-    {\r
-        return m_pParser;\r
-    }\r
-\r
-    CPDF_Dictionary*           GetRoot() const\r
-    {\r
-        return m_pRootDict;\r
-    }\r
-\r
-    CPDF_Dictionary*           GetInfo() const\r
-    {\r
-        return m_pInfoDict;\r
-    }\r
-\r
-    void                                       GetID(CFX_ByteString& id1, CFX_ByteString& id2) const\r
-    {\r
-        id1 = m_ID1;\r
-        id2 = m_ID2;\r
-    }\r
-\r
-    int                                                GetPageCount() const;\r
-\r
-    CPDF_Dictionary*           GetPage(int iPage);\r
-\r
-    int                                                GetPageIndex(FX_DWORD objnum);\r
-\r
-    void                                       EnumPages(IPDF_EnumPageHandler* pHandler);\r
-\r
-    FX_DWORD                           GetUserPermissions(FX_BOOL bCheckRevision = FALSE) const;\r
-\r
-    FX_BOOL                                    IsOwner() const;\r
-\r
-\r
-\r
-    CPDF_DocPageData*          GetPageData()\r
-    {\r
-        return GetValidatePageData();\r
-    }\r
-\r
-    void                                       ClearPageData();\r
-\r
-    void                                       RemoveColorSpaceFromPageData(CPDF_Object* pObject);\r
-\r
-\r
-    CPDF_DocRenderData*                GetRenderData()\r
-    {\r
-        return GetValidateRenderData();\r
-    }\r
-\r
-    void                                       ClearRenderData();\r
-\r
-    void                                       ClearRenderFont();\r
-\r
-\r
-    FX_BOOL                                    IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const;\r
-\r
-\r
-\r
-\r
-    CPDF_Font*                         LoadFont(CPDF_Dictionary* pFontDict);\r
-\r
-    CPDF_Font*                         FindFont(CPDF_Dictionary* pFontDict);\r
-\r
-    CPDF_ColorSpace*           LoadColorSpace(CPDF_Object* pCSObj, CPDF_Dictionary* pResources = NULL);\r
-\r
-    CPDF_Pattern*                      LoadPattern(CPDF_Object* pObj, FX_BOOL bShading, const CFX_AffineMatrix* matrix = NULL);\r
-\r
-    CPDF_Image*                                LoadImageF(CPDF_Object* pObj);\r
-\r
-    CPDF_StreamAcc*                    LoadFontFile(CPDF_Stream* pStream);\r
-\r
-    CPDF_IccProfile*           LoadIccProfile(CPDF_Stream* pStream, int nComponents);\r
-\r
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_\r
-\r
-    CPDF_Font*                         AddWindowsFont(LOGFONTA* pLogFont, FX_BOOL bVert, FX_BOOL bTranslateName = FALSE);\r
-    CPDF_Font*                         AddWindowsFont(LOGFONTW* pLogFont, FX_BOOL bVert, FX_BOOL bTranslateName = FALSE);\r
-#endif\r
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_\r
-    CPDF_Font*              AddMacFont(CTFontRef pFont, FX_BOOL bVert, FX_BOOL bTranslateName = FALSE);\r
-#endif\r
-\r
-    CPDF_Font*                         AddStandardFont(const FX_CHAR* font, CPDF_FontEncoding* pEncoding);\r
-\r
-\r
-    CPDF_Font*                         AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert);\r
-\r
-    void                                       CreateNewDoc();\r
-\r
-    CPDF_Dictionary*           CreateNewPage(int iPage);\r
-\r
-    void                                       DeletePage(int iPage);\r
-\r
-    void                                       LoadDoc();\r
-    void                                       LoadAsynDoc(CPDF_Dictionary *pLinearized);\r
-    void                                       LoadPages();\r
-protected:\r
-\r
-    CPDF_Dictionary*           m_pRootDict;\r
-\r
-    CPDF_Dictionary*           m_pInfoDict;\r
-\r
-    CFX_ByteString                     m_ID1;\r
-\r
-    CFX_ByteString                     m_ID2;\r
-\r
-\r
-    FX_BOOL                                    m_bLinearized;\r
-\r
-    FX_DWORD                           m_dwFirstPageNo;\r
-\r
-    FX_DWORD                           m_dwFirstPageObjNum;\r
-\r
-    CFX_DWordArray                     m_PageList;\r
-\r
-    int                                                _GetPageCount() const;\r
-    CPDF_Dictionary*           _FindPDFPage(CPDF_Dictionary* pPages, int iPage, int nPagesToGo, int level);\r
-    int                                                _FindPageIndex(CPDF_Dictionary* pNode, FX_DWORD& skip_count, FX_DWORD objnum, int& index, int level = 0);\r
-    FX_BOOL                                    IsContentUsedElsewhere(FX_DWORD objnum, CPDF_Dictionary* pPageDict);\r
-    FX_BOOL                                    CheckOCGVisible(CPDF_Dictionary* pOCG, FX_BOOL bPrinting);\r
-    CPDF_DocPageData*          GetValidatePageData();\r
-    CPDF_DocRenderData*                GetValidateRenderData();\r
-    friend class                       CPDF_Creator;\r
-    friend class                       CPDF_Parser;\r
-    friend class                       CPDF_DataAvail;\r
-    friend class                       CPDF_OCContext;\r
-\r
-\r
-\r
-    CPDF_DocPageData*          m_pDocPage;\r
-\r
-    CPDF_DocRenderData*                m_pDocRender;\r
-\r
-};\r
-\r
-#define PDFWORD_EOF                    0\r
-#define PDFWORD_NUMBER         1\r
-#define PDFWORD_TEXT           2\r
-#define PDFWORD_DELIMITER      3\r
-#define PDFWORD_NAME           4\r
-class CPDF_SimpleParser : public CFX_Object\r
-{\r
-public:\r
-\r
-    CPDF_SimpleParser(FX_LPCBYTE pData, FX_DWORD dwSize);\r
-\r
-    CPDF_SimpleParser(FX_BSTR str);\r
-\r
-    CFX_ByteStringC            GetWord();\r
-\r
-    FX_BOOL                            SearchToken(FX_BSTR token);\r
-\r
-    FX_BOOL                            SkipWord(FX_BSTR token);\r
-\r
-    FX_BOOL                            FindTagPair(FX_BSTR start_token, FX_BSTR end_token,\r
-                                    FX_DWORD& start_pos, FX_DWORD& end_pos);\r
-\r
-    FX_BOOL                            FindTagParam(FX_BSTR token, int nParams);\r
-\r
-    FX_DWORD                   GetPos()\r
-    {\r
-        return m_dwCurPos;\r
-    }\r
-\r
-    void                               SetPos(FX_DWORD pos)\r
-    {\r
-        ASSERT(pos <= m_dwSize);\r
-        m_dwCurPos = pos;\r
-    }\r
-private:\r
-\r
-    void                               ParseWord(FX_LPCBYTE& pStart, FX_DWORD& dwSize, int& type);\r
-\r
-    FX_LPCBYTE                 m_pData;\r
-\r
-    FX_DWORD                   m_dwSize;\r
-\r
-    FX_DWORD                   m_dwCurPos;\r
-};\r
-class CPDF_SyntaxParser : public CFX_Object\r
-{\r
-public:\r
-\r
-    CPDF_SyntaxParser();\r
-\r
-    ~CPDF_SyntaxParser();\r
-\r
-    void                               InitParser(IFX_FileRead* pFileAccess, FX_DWORD HeaderOffset);\r
-\r
-    FX_FILESIZE                        SavePos()\r
-    {\r
-        return m_Pos;\r
-    }\r
-\r
-    void                               RestorePos(FX_FILESIZE pos)\r
-    {\r
-        m_Pos = pos;\r
-    }\r
-\r
-    CPDF_Object*               GetObject(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, FX_DWORD gennum, int level, struct PARSE_CONTEXT* pContext = NULL, FX_BOOL bDecrypt = TRUE);\r
-\r
-\r
-    CPDF_Object*               GetObjectByStrict(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, FX_DWORD gennum, int level, struct PARSE_CONTEXT* pContext = NULL);\r
-\r
-    int                                        GetDirectNum();\r
-\r
-    CFX_ByteString             GetString(FX_DWORD objnum, FX_DWORD gennum);\r
-\r
-    CFX_ByteString             GetName();\r
-\r
-    CFX_ByteString             GetKeyword();\r
-\r
-    void                               GetBinary(FX_BYTE* buffer, FX_DWORD size);\r
-\r
-    void                               ToNextLine();\r
-\r
-    void                               ToNextWord();\r
-\r
-    FX_BOOL                            SearchWord(FX_BSTR word, FX_BOOL bWholeWord, FX_BOOL bForward, FX_FILESIZE limit);\r
-\r
-    int                                        SearchMultiWord(FX_BSTR words, FX_BOOL bWholeWord, FX_FILESIZE limit);\r
-\r
-    FX_FILESIZE                        FindTag(FX_BSTR tag, FX_FILESIZE limit);\r
-\r
-    void                               SetEncrypt(CPDF_CryptoHandler* pCryptoHandler)\r
-    {\r
-        m_pCryptoHandler = pCryptoHandler;\r
-    }\r
-\r
-    FX_BOOL                            IsEncrypted()\r
-    {\r
-        return m_pCryptoHandler != NULL;\r
-    }\r
-\r
-    FX_BOOL                            GetCharAt(FX_FILESIZE pos, FX_BYTE& ch);\r
-\r
-    FX_BOOL                            ReadBlock(FX_BYTE* pBuf, FX_DWORD size);\r
-\r
-    CFX_ByteString             GetNextWord(FX_BOOL& bIsNumber);\r
-protected:\r
-\r
-    virtual FX_BOOL                            GetNextChar(FX_BYTE& ch);\r
-\r
-    FX_BOOL                            GetCharAtBackward(FX_FILESIZE pos, FX_BYTE& ch);\r
-\r
-    void                               GetNextWord();\r
-\r
-    FX_BOOL                            IsWholeWord(FX_FILESIZE startpos, FX_FILESIZE limit, FX_LPCBYTE tag, FX_DWORD taglen);\r
-\r
-    CFX_ByteString             ReadString();\r
-\r
-    CFX_ByteString             ReadHexString();\r
-\r
-    CPDF_Stream*               ReadStream(CPDF_Dictionary* pDict, PARSE_CONTEXT* pContext, FX_DWORD objnum, FX_DWORD gennum);\r
-\r
-    FX_FILESIZE                        m_Pos;\r
-\r
-    FX_BOOL                            m_bFileStream;\r
-\r
-    int                                        m_MetadataObjnum;\r
-\r
-    IFX_FileRead*              m_pFileAccess;\r
-\r
-    FX_DWORD                   m_HeaderOffset;\r
-\r
-    FX_FILESIZE                        m_FileLen;\r
-\r
-    FX_BYTE*                   m_pFileBuf;\r
-\r
-    FX_DWORD                   m_BufSize;\r
-\r
-    FX_FILESIZE                        m_BufOffset;\r
-\r
-    CPDF_CryptoHandler*        m_pCryptoHandler;\r
-\r
-    FX_BYTE                            m_WordBuffer[257];\r
-\r
-    FX_DWORD                   m_WordSize;\r
-\r
-    FX_BOOL                            m_bIsNumber;\r
-\r
-    FX_FILESIZE                        m_dwWordPos;\r
-    friend class               CPDF_Parser;\r
-    friend class               CPDF_DataAvail;\r
-};\r
-\r
-#define PDFPARSE_TYPEONLY      1\r
-#define PDFPARSE_NOSTREAM      2\r
-struct PARSE_CONTEXT {\r
-\r
-    FX_BOOL            m_Flags;\r
-\r
-    FX_FILESIZE        m_DictStart;\r
-\r
-    FX_FILESIZE        m_DictEnd;\r
-\r
-    FX_FILESIZE        m_DataStart;\r
-\r
-    FX_FILESIZE        m_DataEnd;\r
-};\r
-class IPDF_DocParser : public CFX_Object\r
-{\r
-public:\r
-\r
-    virtual FX_DWORD   GetRootObjNum() = 0;\r
-\r
-    virtual FX_DWORD   GetInfoObjNum() = 0;\r
-\r
-    virtual CPDF_Object*       ParseIndirectObject(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, PARSE_CONTEXT* pContext = NULL) = 0;\r
-\r
-    virtual FX_DWORD   GetLastObjNum() = 0;\r
-\r
-    virtual CPDF_Array*        GetIDArray() = 0;\r
-\r
-    virtual CPDF_Dictionary*   GetEncryptDict() = 0;\r
-\r
-    FX_BOOL                            IsEncrypted()\r
-    {\r
-        return GetEncryptDict() != NULL;\r
-    }\r
-\r
-    virtual FX_DWORD   GetPermissions(FX_BOOL bCheckRevision = FALSE) = 0;\r
-\r
-    virtual FX_BOOL            IsOwner() = 0;\r
-\r
-    virtual FX_BOOL            IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) = 0;\r
-};\r
-\r
-#define PDFPARSE_ERROR_SUCCESS         0\r
-#define PDFPARSE_ERROR_FILE                    1\r
-#define PDFPARSE_ERROR_FORMAT          2\r
-#define PDFPARSE_ERROR_PASSWORD                3\r
-#define PDFPARSE_ERROR_HANDLER         4\r
-#define PDFPARSE_ERROR_CERT                    5\r
-class CPDF_Parser : public IPDF_DocParser\r
-{\r
-public:\r
-\r
-    CPDF_Parser();\r
-\r
-    ~CPDF_Parser();\r
-\r
-    FX_DWORD                   StartParse(FX_LPCSTR filename, FX_BOOL bReParse = FALSE);\r
-\r
-    FX_DWORD                   StartParse(FX_LPCWSTR filename, FX_BOOL bReParse = FALSE);\r
-\r
-    FX_DWORD                   StartParse(IFX_FileRead* pFile, FX_BOOL bReParse = FALSE, FX_BOOL bOwnFileRead = TRUE);\r
-\r
-    void                               CloseParser(FX_BOOL bReParse = FALSE);\r
-\r
-    virtual FX_DWORD   GetPermissions(FX_BOOL bCheckRevision = FALSE);\r
-\r
-    virtual FX_BOOL            IsOwner();\r
-\r
-    void                               SetPassword(const FX_CHAR* password)\r
-    {\r
-        m_Password = password;\r
-    }\r
-\r
-    CFX_ByteString             GetPassword()\r
-    {\r
-        return m_Password;\r
-    }\r
-\r
-    CPDF_SecurityHandler* GetSecurityHandler()\r
-    {\r
-        return m_pSecurityHandler;\r
-    }\r
-\r
-    CPDF_CryptoHandler*        GetCryptoHandler()\r
-    {\r
-        return m_Syntax.m_pCryptoHandler;\r
-    }\r
-\r
-    void                               SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, FX_BOOL bForced = FALSE);\r
-\r
-    CFX_ByteString             GetRecipient()\r
-    {\r
-        return m_bsRecipient;\r
-    }\r
-\r
-    CPDF_Dictionary*   GetTrailer()\r
-    {\r
-        return m_pTrailer;\r
-    }\r
-\r
-    FX_FILESIZE                        GetLastXRefOffset()\r
-    {\r
-        return m_LastXRefOffset;\r
-    }\r
-\r
-    CPDF_Document*             GetDocument()\r
-    {\r
-        return m_pDocument;\r
-    }\r
-    CFX_ArrayTemplate<CPDF_Dictionary *> * GetOtherTrailers()\r
-    {\r
-        return &m_Trailers;\r
-    }\r
-\r
-    virtual FX_DWORD   GetRootObjNum();\r
-    virtual FX_DWORD   GetInfoObjNum();\r
-    virtual CPDF_Array*        GetIDArray();\r
-    virtual CPDF_Dictionary*   GetEncryptDict()\r
-    {\r
-        return m_pEncryptDict;\r
-    }\r
-    virtual CPDF_Object*               ParseIndirectObject(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, PARSE_CONTEXT* pContext = NULL);\r
-    virtual FX_DWORD   GetLastObjNum();\r
-    virtual FX_BOOL            IsFormStream(FX_DWORD objnum, FX_BOOL& bForm);\r
-\r
-    FX_FILESIZE                        GetObjectOffset(FX_DWORD objnum);\r
-\r
-    FX_FILESIZE                        GetObjectSize(FX_DWORD objnum);\r
-\r
-    int                                        GetObjectVersion(FX_DWORD objnum)\r
-    {\r
-        return m_ObjVersion[objnum];\r
-    }\r
-\r
-    void                               GetIndirectBinary(FX_DWORD objnum, FX_BYTE*& pBuffer, FX_DWORD& size);\r
-\r
-    FX_BOOL                            GetFileStreamOption()\r
-    {\r
-        return m_Syntax.m_bFileStream;\r
-    }\r
-\r
-    void                               SetFileStreamOption(FX_BOOL b)\r
-    {\r
-        m_Syntax.m_bFileStream = b;\r
-    }\r
-\r
-    IFX_FileRead*              GetFileAccess() const\r
-    {\r
-        return m_Syntax.m_pFileAccess;\r
-    }\r
-\r
-    int                                        GetFileVersion() const\r
-    {\r
-        return m_FileVersion;\r
-    }\r
-\r
-    FX_BOOL                            IsXRefStream() const\r
-    {\r
-        return m_bXRefStream;\r
-    }\r
-    CPDF_Object*               ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, FX_FILESIZE pos, FX_DWORD objnum,\r
-            struct PARSE_CONTEXT* pContext);\r
-\r
-    CPDF_Object*               ParseIndirectObjectAtByStrict(CPDF_IndirectObjects* pObjList, FX_FILESIZE pos, FX_DWORD objnum,\r
-            struct PARSE_CONTEXT* pContext, FX_FILESIZE *pResultPos);\r
-\r
-    FX_DWORD                   StartAsynParse(IFX_FileRead* pFile, FX_BOOL bReParse = FALSE, FX_BOOL bOwnFileRead = TRUE);\r
-\r
-    FX_DWORD                   GetFirstPageNo()\r
-    {\r
-        return m_dwFirstPageNo;\r
-    }\r
-protected:\r
-\r
-    CPDF_Document*             m_pDocument;\r
-\r
-    CPDF_SyntaxParser  m_Syntax;\r
-    FX_BOOL                            m_bOwnFileRead;\r
-    CPDF_Object*               ParseDirect(CPDF_Object* pObj);\r
-\r
-    FX_BOOL                            LoadAllCrossRefV4(FX_FILESIZE pos);\r
-\r
-    FX_BOOL                            LoadAllCrossRefV5(FX_FILESIZE pos);\r
-\r
-    FX_BOOL                            LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, FX_BOOL bSkip, FX_BOOL bFirst);\r
-\r
-    FX_BOOL                            LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL bMainXRef);\r
-\r
-    CPDF_Dictionary*   LoadTrailerV4();\r
-\r
-    FX_BOOL                            RebuildCrossRef();\r
-\r
-    FX_DWORD                   SetEncryptHandler();\r
-\r
-    void                               ReleaseEncryptHandler();\r
-\r
-    FX_BOOL                            LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);\r
-\r
-    FX_BOOL                            LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);\r
-\r
-    FX_BOOL                            LoadLinearizedAllCrossRefV5(FX_FILESIZE pos);\r
-\r
-    FX_DWORD                   LoadLinearizedMainXRefTable();\r
-\r
-    CFX_MapPtrToPtr            m_ObjectStreamMap;\r
-\r
-    CPDF_StreamAcc*            GetObjectStream(FX_DWORD number);\r
-\r
-    FX_BOOL                            IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset);\r
-\r
-\r
-\r
-    int                                        m_FileVersion;\r
-\r
-    CPDF_Dictionary*   m_pTrailer;\r
-\r
-    CPDF_Dictionary*   m_pEncryptDict;\r
-    void SetEncryptDictionary(CPDF_Dictionary* pDict);\r
-\r
-    FX_FILESIZE                        m_LastXRefOffset;\r
-\r
-    FX_BOOL                            m_bXRefStream;\r
-\r
-\r
-    CPDF_SecurityHandler*      m_pSecurityHandler;\r
-\r
-    FX_BOOL                                    m_bForceUseSecurityHandler;\r
-\r
-    CFX_ByteString                     m_bsRecipient;\r
-\r
-    CFX_ByteString             m_FilePath;\r
-\r
-    CFX_ByteString             m_Password;\r
-\r
-    CFX_FileSizeArray  m_CrossRef;\r
-\r
-    CFX_ByteArray              m_V5Type;\r
-\r
-    CFX_FileSizeArray  m_SortedOffset;\r
-\r
-    CFX_WordArray              m_ObjVersion;\r
-    CFX_ArrayTemplate<CPDF_Dictionary *>       m_Trailers;\r
-\r
-    FX_BOOL                            m_bVersionUpdated;\r
-\r
-    CPDF_Object*               m_pLinearized;\r
-\r
-    FX_DWORD                   m_dwFirstPageNo;\r
-\r
-    FX_DWORD                   m_dwXrefStartObjNum;\r
-    friend class               CPDF_Creator;\r
-    friend class               CPDF_DataAvail;\r
-};\r
-#define FXCIPHER_NONE  0\r
-#define FXCIPHER_RC4   1\r
-#define FXCIPHER_AES   2\r
-#define FXCIPHER_AES2   3\r
-class CPDF_SecurityHandler : public CFX_Object\r
-{\r
-public:\r
-\r
-    virtual ~CPDF_SecurityHandler() {}\r
-\r
-    virtual FX_BOOL            OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict) = 0;\r
-\r
-    virtual FX_DWORD   GetPermissions() = 0;\r
-\r
-    virtual FX_BOOL            IsOwner() = 0;\r
-\r
-    virtual FX_BOOL            GetCryptInfo(int& cipher, FX_LPCBYTE& buffer, int& keylen) = 0;\r
-\r
-    virtual FX_BOOL            IsMetadataEncrypted()\r
-    {\r
-        return TRUE;\r
-    }\r
-\r
-    virtual CPDF_CryptoHandler*        CreateCryptoHandler() = 0;\r
-\r
-    virtual CPDF_StandardSecurityHandler* GetStandardHandler()\r
-    {\r
-        return NULL;\r
-    }\r
-};\r
-#define PDF_ENCRYPT_CONTENT                            0\r
-class CPDF_StandardSecurityHandler : public CPDF_SecurityHandler\r
-{\r
-public:\r
-    CPDF_StandardSecurityHandler();\r
-\r
-    virtual ~CPDF_StandardSecurityHandler();\r
-    virtual FX_BOOL            OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict);\r
-    virtual FX_DWORD   GetPermissions();\r
-    virtual FX_BOOL            IsOwner()\r
-    {\r
-        return m_bOwner;\r
-    }\r
-    virtual FX_BOOL            GetCryptInfo(int& cipher, FX_LPCBYTE& buffer, int& keylen);\r
-    virtual FX_BOOL            IsMetadataEncrypted();\r
-    virtual CPDF_CryptoHandler*        CreateCryptoHandler();\r
-    virtual CPDF_StandardSecurityHandler* GetStandardHandler()\r
-    {\r
-        return this;\r
-    }\r
-\r
-    void                               OnCreate(CPDF_Dictionary* pEncryptDict, CPDF_Array* pIdArray,\r
-                                 FX_LPCBYTE user_pass, FX_DWORD user_size,\r
-                                 FX_LPCBYTE owner_pass, FX_DWORD owner_size, FX_DWORD type = PDF_ENCRYPT_CONTENT);\r
-\r
-    void                               OnCreate(CPDF_Dictionary* pEncryptDict, CPDF_Array* pIdArray,\r
-                                 FX_LPCBYTE user_pass, FX_DWORD user_size, FX_DWORD type = PDF_ENCRYPT_CONTENT);\r
-\r
-    CFX_ByteString             GetUserPassword(FX_LPCBYTE owner_pass, FX_DWORD pass_size);\r
-    CFX_ByteString             GetUserPassword(FX_LPCBYTE owner_pass, FX_DWORD pass_size, FX_INT32 key_len);\r
-    int                                        GetVersion()\r
-    {\r
-        return m_Version;\r
-    }\r
-    int                                        GetRevision()\r
-    {\r
-        return m_Revision;\r
-    }\r
-\r
-    int                                        CheckPassword(FX_LPCBYTE password, FX_DWORD pass_size, FX_BOOL bOwner, FX_LPBYTE key);\r
-    int                                        CheckPassword(FX_LPCBYTE password, FX_DWORD pass_size, FX_BOOL bOwner, FX_LPBYTE key, int key_len);\r
-private:\r
-\r
-    int                                        m_Version;\r
-\r
-    int                                        m_Revision;\r
-\r
-    CPDF_Parser*               m_pParser;\r
-\r
-    CPDF_Dictionary*   m_pEncryptDict;\r
-\r
-    FX_BOOL                            LoadDict(CPDF_Dictionary* pEncryptDict);\r
-    FX_BOOL                            LoadDict(CPDF_Dictionary* pEncryptDict, FX_DWORD type, int& cipher, int& key_len);\r
-\r
-    FX_BOOL                            CheckUserPassword(FX_LPCBYTE password, FX_DWORD pass_size,\r
-                                          FX_BOOL bIgnoreEncryptMeta, FX_LPBYTE key, FX_INT32 key_len);\r
-\r
-    FX_BOOL                            CheckOwnerPassword(FX_LPCBYTE password, FX_DWORD pass_size, FX_LPBYTE key, FX_INT32 key_len);\r
-    FX_BOOL                            AES256_CheckPassword(FX_LPCBYTE password, FX_DWORD size, FX_BOOL bOwner, FX_LPBYTE key);\r
-    void                               AES256_SetPassword(CPDF_Dictionary* pEncryptDict, FX_LPCBYTE password, FX_DWORD size, FX_BOOL bOwner, FX_LPCBYTE key);\r
-    void                               AES256_SetPerms(CPDF_Dictionary* pEncryptDict, FX_DWORD permission, FX_BOOL bEncryptMetadata, FX_LPCBYTE key);\r
-    void                               OnCreate(CPDF_Dictionary* pEncryptDict, CPDF_Array* pIdArray,\r
-                                 FX_LPCBYTE user_pass, FX_DWORD user_size,\r
-                                 FX_LPCBYTE owner_pass, FX_DWORD owner_size, FX_BOOL bDefault, FX_DWORD type);\r
-    FX_BOOL                            CheckSecurity(FX_INT32 key_len);\r
-\r
-    FX_BOOL                            m_bOwner;\r
-\r
-    FX_DWORD                   m_Permissions;\r
-\r
-    int                                        m_Cipher;\r
-\r
-    FX_BYTE                            m_EncryptKey[32];\r
-\r
-    int                                        m_KeyLen;\r
-};\r
-class CPDF_CryptoHandler : public CFX_Object\r
-{\r
-public:\r
-\r
-    virtual ~CPDF_CryptoHandler() {}\r
-\r
-    virtual FX_BOOL            Init(CPDF_Dictionary* pEncryptDict, CPDF_SecurityHandler* pSecurityHandler) = 0;\r
-\r
-    virtual FX_DWORD   DecryptGetSize(FX_DWORD src_size) = 0;\r
-\r
-    virtual FX_LPVOID  DecryptStart(FX_DWORD objnum, FX_DWORD gennum) = 0;\r
-\r
-    virtual FX_BOOL            DecryptStream(FX_LPVOID context, FX_LPCBYTE src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf) = 0;\r
-\r
-    virtual FX_BOOL            DecryptFinish(FX_LPVOID context, CFX_BinaryBuf& dest_buf) = 0;\r
-\r
-\r
-    virtual FX_DWORD   EncryptGetSize(FX_DWORD objnum, FX_DWORD version, FX_LPCBYTE src_buf, FX_DWORD src_size) = 0;\r
-\r
-    virtual FX_BOOL            EncryptContent(FX_DWORD objnum, FX_DWORD version, FX_LPCBYTE src_buf, FX_DWORD src_size,\r
-                                       FX_LPBYTE dest_buf, FX_DWORD& dest_size) = 0;\r
-\r
-    void                               Decrypt(FX_DWORD objnum, FX_DWORD version, CFX_ByteString& str);\r
-};\r
-class CPDF_StandardCryptoHandler : public CPDF_CryptoHandler\r
-{\r
-public:\r
-\r
-    CPDF_StandardCryptoHandler();\r
-\r
-    virtual ~CPDF_StandardCryptoHandler();\r
-\r
-    FX_BOOL                            Init(int cipher, FX_LPCBYTE key, int keylen);\r
-    virtual FX_BOOL            Init(CPDF_Dictionary* pEncryptDict, CPDF_SecurityHandler* pSecurityHandler);\r
-    virtual FX_DWORD   DecryptGetSize(FX_DWORD src_size);\r
-    virtual FX_LPVOID  DecryptStart(FX_DWORD objnum, FX_DWORD gennum);\r
-    virtual FX_BOOL            DecryptStream(FX_LPVOID context, FX_LPCBYTE src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf);\r
-    virtual FX_BOOL            DecryptFinish(FX_LPVOID context, CFX_BinaryBuf& dest_buf);\r
-    virtual FX_DWORD   EncryptGetSize(FX_DWORD objnum, FX_DWORD version, FX_LPCBYTE src_buf, FX_DWORD src_size);\r
-    virtual FX_BOOL            EncryptContent(FX_DWORD objnum, FX_DWORD version, FX_LPCBYTE src_buf, FX_DWORD src_size,\r
-                                       FX_LPBYTE dest_buf, FX_DWORD& dest_size);\r
-protected:\r
-\r
-    virtual void               CryptBlock(FX_BOOL bEncrypt, FX_DWORD objnum, FX_DWORD gennum, FX_LPCBYTE src_buf, FX_DWORD src_size,\r
-                                   FX_LPBYTE dest_buf, FX_DWORD& dest_size);\r
-    virtual FX_LPVOID  CryptStart(FX_DWORD objnum, FX_DWORD gennum, FX_BOOL bEncrypt);\r
-    virtual FX_BOOL            CryptStream(FX_LPVOID context, FX_LPCBYTE src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf, FX_BOOL bEncrypt);\r
-    virtual FX_BOOL            CryptFinish(FX_LPVOID context, CFX_BinaryBuf& dest_buf, FX_BOOL bEncrypt);\r
-\r
-    FX_BYTE                            m_EncryptKey[32];\r
-\r
-    int                                        m_KeyLen;\r
-\r
-    int                                        m_Cipher;\r
-\r
-    FX_LPBYTE                  m_pAESContext;\r
-};\r
-class CPDF_Point : public CFX_Object\r
-{\r
-public:\r
-\r
-    CPDF_Point(FX_FLOAT xx, FX_FLOAT yy)\r
-    {\r
-        x = xx;\r
-        y = yy;\r
-    }\r
-\r
-    FX_FLOAT                   x;\r
-\r
-    FX_FLOAT                   y;\r
-};\r
-\r
-#define CPDF_Rect              CFX_FloatRect\r
-#define CPDF_Matrix            CFX_AffineMatrix\r
-CFX_ByteString PDF_NameDecode(FX_BSTR orig);\r
-CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig);\r
-CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig);\r
-CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex = FALSE);\r
-CFX_WideString PDF_DecodeText(const CFX_ByteString& str, CFX_CharMap* pCharMap = NULL);\r
-CFX_WideString PDF_DecodeText(FX_LPCBYTE pData, FX_DWORD size, CFX_CharMap* pCharMap = NULL);\r
-CFX_ByteString PDF_EncodeText(FX_LPCWSTR pString, int len = -1, CFX_CharMap* pCharMap = NULL);\r
-FX_FLOAT PDF_ClipFloat(FX_FLOAT f);\r
-class CFDF_Document : public CPDF_IndirectObjects\r
-{\r
-public:\r
-\r
-    static CFDF_Document*      CreateNewDoc();\r
-\r
-    static CFDF_Document*      ParseFile(FX_LPCSTR file_path);\r
-\r
-    static CFDF_Document*      ParseFile(FX_LPCWSTR file_path);\r
-\r
-    static CFDF_Document*      ParseFile(IFX_FileRead *pFile, FX_BOOL bOwnFile = FALSE);\r
-\r
-    static CFDF_Document*      ParseMemory(FX_LPCBYTE pData, FX_DWORD size);\r
-\r
-    ~CFDF_Document();\r
-\r
-    FX_BOOL                                    WriteFile(FX_LPCSTR file_path) const;\r
-\r
-    FX_BOOL                                    WriteFile(FX_LPCWSTR file_path) const;\r
-\r
-    FX_BOOL                                    WriteFile(IFX_FileWrite *pFile) const;\r
-\r
-    FX_BOOL                                    WriteBuf(CFX_ByteTextBuf& buf) const;\r
-\r
-    CPDF_Dictionary*           GetRoot() const\r
-    {\r
-        return m_pRootDict;\r
-    }\r
-\r
-    CFX_WideString                     GetWin32Path() const;\r
-protected:\r
-\r
-    CFDF_Document();\r
-    void       ParseStream(IFX_FileRead *pFile, FX_BOOL bOwnFile);\r
-    CPDF_Dictionary*           m_pRootDict;\r
-    IFX_FileRead*                      m_pFile;\r
-    FX_BOOL                                    m_bOwnFile;\r
-};\r
-\r
-CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec);\r
-void                   FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec, const CFX_WideString& fullpath);\r
-\r
-void FlateEncode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size);\r
-FX_DWORD FlateDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size);\r
-FX_DWORD RunLengthDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size);\r
-class CPDF_NumberTree : public CFX_Object\r
-{\r
-public:\r
-\r
-    CPDF_NumberTree(CPDF_Dictionary* pRoot)\r
-    {\r
-        m_pRoot = pRoot;\r
-    }\r
-\r
-    CPDF_Object*               LookupValue(int num);\r
-protected:\r
-\r
-    CPDF_Dictionary*   m_pRoot;\r
-};\r
-\r
-class IFX_FileAvail\r
-{\r
-public:\r
-\r
-    virtual FX_BOOL                    IsDataAvail( FX_FILESIZE offset, FX_DWORD size) = 0;\r
-};\r
-class IFX_DownloadHints\r
-{\r
-public:\r
-\r
-    virtual void                       AddSegment(FX_FILESIZE offset, FX_DWORD size) = 0;\r
-};\r
-#define PDF_IS_LINEARIZED                      1\r
-#define PDF_NOT_LINEARIZED                     0\r
-#define PDF_UNKNOW_LINEARIZED          -1\r
-#define PDFFORM_NOTAVAIL               0\r
-#define PDFFORM_AVAIL                  1\r
-#define PDFFORM_NOTEXIST               2\r
-class IPDF_DataAvail\r
-{\r
-public:\r
-\r
-    virtual FX_BOOL                    IsDocAvail(IFX_DownloadHints* pHints) = 0;\r
-\r
-\r
-    virtual void                       SetDocument(CPDF_Document* pDoc) = 0;\r
-\r
-\r
-    virtual FX_BOOL                    IsPageAvail(int iPage, IFX_DownloadHints* pHints) = 0;\r
-\r
-    virtual FX_BOOL                    IsLinearized() = 0;\r
-\r
-    virtual FX_INT32           IsFormAvail(IFX_DownloadHints *pHints) = 0;\r
-\r
-    virtual FX_INT32           IsLinearizedPDF() = 0;\r
-\r
-    virtual void                               GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSize) = 0;\r
-};\r
-class CPDF_SortObjNumArray : public CFX_Object\r
-{\r
-public:\r
-\r
-    void AddObjNum(FX_DWORD dwObjNum);\r
-\r
-    FX_BOOL Find(FX_DWORD dwObjNum);\r
-\r
-    void RemoveAll()\r
-    {\r
-        m_number_array.RemoveAll();\r
-    }\r
-protected:\r
-\r
-    FX_BOOL BinarySearch(FX_DWORD value, int &iNext);\r
-protected:\r
-\r
-    CFX_DWordArray                     m_number_array;\r
-};\r
-enum PDF_PAGENODE_TYPE {\r
-    PDF_PAGENODE_UNKOWN = 0,\r
-    PDF_PAGENODE_PAGE,\r
-    PDF_PAGENODE_PAGES,\r
-    PDF_PAGENODE_ARRAY,\r
-};\r
-class CPDF_PageNode : public CFX_Object\r
-{\r
-public:\r
-    CPDF_PageNode() : m_type(PDF_PAGENODE_UNKOWN) {}\r
-    ~CPDF_PageNode();\r
-    PDF_PAGENODE_TYPE  m_type;\r
-    FX_DWORD                   m_dwPageNo;\r
-    CFX_PtrArray               m_childNode;\r
-};\r
-enum PDF_DATAAVAIL_STATUS {\r
-    PDF_DATAAVAIL_HEADER = 0,\r
-    PDF_DATAAVAIL_FIRSTPAGE,\r
-    PDF_DATAAVAIL_FIRSTPAGE_PREPARE,\r
-    PDF_DATAAVAIL_END,\r
-    PDF_DATAAVAIL_CROSSREF,\r
-    PDF_DATAAVAIL_CROSSREF_ITEM,\r
-    PDF_DATAAVAIL_CROSSREF_STREAM,\r
-    PDF_DATAAVAIL_TRAILER,\r
-    PDF_DATAAVAIL_LOADALLCRSOSSREF,\r
-    PDF_DATAAVAIL_ROOT,\r
-    PDF_DATAAVAIL_INFO,\r
-    PDF_DATAAVAIL_ACROFORM,\r
-    PDF_DATAAVAIL_ACROFORM_SUBOBJECT,\r
-    PDF_DATAAVAIL_PAGETREE,\r
-    PDF_DATAAVAIL_PAGE,\r
-    PDF_DATAAVAIL_PAGE_LATERLOAD,\r
-    PDF_DATAAVAIL_RESOURCES,\r
-    PDF_DATAAVAIL_DONE,\r
-    PDF_DATAAVAIL_ERROR,\r
-    PDF_DATAAVAIL_LOADALLFILE,\r
-    PDF_DATAAVAIL_TRAILER_APPEND\r
-};\r
-class CPDF_DataAvail : public CFX_Object, public IPDF_DataAvail\r
-{\r
-public:\r
-\r
-    CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead);\r
-    ~CPDF_DataAvail();\r
-\r
-    virtual FX_BOOL                            IsDocAvail(IFX_DownloadHints* pHints);\r
-\r
-\r
-    virtual void                               SetDocument(CPDF_Document* pDoc);\r
-\r
-\r
-    virtual FX_BOOL                            IsPageAvail(int iPage, IFX_DownloadHints* pHints);\r
-\r
-    virtual FX_INT32                   IsFormAvail(IFX_DownloadHints *pHints);\r
-\r
-    virtual FX_INT32                   IsLinearizedPDF();\r
-\r
-    virtual FX_BOOL                            IsLinearized()\r
-    {\r
-        return m_bLinearized;\r
-    }\r
-\r
-    virtual void                               GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSize);\r
-    IFX_FileRead*                              GetFileRead() const\r
-    {\r
-        return m_pFileRead;\r
-    }\r
-    IFX_FileAvail*                             GetFileAvail() const\r
-    {\r
-        return m_pFileAvail;\r
-    }\r
-protected:\r
-    FX_DWORD                                   GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset);\r
-    FX_BOOL                                            IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePage, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array);\r
-    FX_BOOL                                            CheckDocStatus(IFX_DownloadHints *pHints);\r
-    FX_BOOL                                            CheckHeader(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckFirstPage(IFX_DownloadHints *pHints);\r
-    FX_BOOL                                            CheckEnd(IFX_DownloadHints *pHints);\r
-    FX_BOOL                                            CheckCrossRef(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckCrossRefItem(IFX_DownloadHints *pHints);\r
-    FX_BOOL                                            CheckTrailer(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckRoot(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckInfo(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckPages(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckPage(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckResources(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckAnnots(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckAcroForm(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckAcroFormSubObject(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckTrailerAppend(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckPageStatus(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckAllCrossRefStream(IFX_DownloadHints *pHints);\r
-\r
-    FX_DWORD                                   CheckCrossRefStream(IFX_DownloadHints *pHints, FX_FILESIZE &xref_offset);\r
-    FX_BOOL                                            IsLinearizedFile(FX_LPBYTE pData, FX_DWORD dwLen);\r
-    void                                               SetStartOffset(FX_FILESIZE dwOffset);\r
-    FX_BOOL                                            GetNextToken(CFX_ByteString &token);\r
-    FX_BOOL                                            GetNextChar(FX_BYTE &ch);\r
-    CPDF_Object        *                               ParseIndirectObjectAt(FX_FILESIZE pos, FX_DWORD objnum);\r
-    CPDF_Object        *                               GetObject(FX_DWORD objnum, IFX_DownloadHints* pHints, FX_BOOL *pExistInFile);\r
-    FX_BOOL                                            GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages);\r
-    FX_BOOL                                            PreparePageItem();\r
-    FX_BOOL                                            LoadPages(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            LoadAllXref(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            LoadAllFile(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckLinearizedData(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckFileResources(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckPageAnnots(int iPage, IFX_DownloadHints* pHints);\r
-\r
-    FX_BOOL                                            CheckLinearizedFirstPage(int iPage, IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            HaveResourceAncestor(CPDF_Dictionary *pDict);\r
-    FX_BOOL                                            CheckPage(FX_INT32 iPage, IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            LoadDocPages(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            LoadDocPage(FX_INT32 iPage, IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckPageNode(CPDF_PageNode &pageNodes, FX_INT32 iPage, FX_INT32 &iCount, IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPageNode, IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            CheckArrayPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPageNode, IFX_DownloadHints* pHints);\r
-    FX_BOOL                     CheckPageCount(IFX_DownloadHints* pHints);\r
-    FX_BOOL                                            IsFirstCheck(int iPage);\r
-    void                                               ResetFirstCheck(int iPage);\r
-\r
-    CPDF_Parser                                m_parser;\r
-\r
-    CPDF_SyntaxParser          m_syntaxParser;\r
-\r
-    CPDF_Object                                *m_pRoot;\r
-\r
-    FX_DWORD                           m_dwRootObjNum;\r
-\r
-    FX_DWORD                           m_dwInfoObjNum;\r
-\r
-    CPDF_Object                                *m_pLinearized;\r
-\r
-    CPDF_Object                                *m_pTrailer;\r
-\r
-    FX_BOOL                                    m_bDocAvail;\r
-\r
-    FX_FILESIZE                                m_dwHeaderOffset;\r
-\r
-    FX_FILESIZE                                m_dwLastXRefOffset;\r
-\r
-    FX_FILESIZE                                m_dwXRefOffset;\r
-\r
-    FX_FILESIZE                                m_dwTrailerOffset;\r
-\r
-    FX_FILESIZE                                m_dwCurrentOffset;\r
-\r
-    PDF_DATAAVAIL_STATUS       m_docStatus;\r
-\r
-    IFX_FileAvail*                     m_pFileAvail;\r
-\r
-    IFX_FileRead*                      m_pFileRead;\r
-\r
-    FX_FILESIZE                                m_dwFileLen;\r
-\r
-    CPDF_Document*                     m_pDocument;\r
-\r
-    CPDF_SortObjNumArray       m_objnum_array;\r
-\r
-    CFX_PtrArray                       m_objs_array;\r
-\r
-    FX_FILESIZE                                m_Pos;\r
-\r
-    FX_FILESIZE                                m_bufferOffset;\r
-\r
-    FX_DWORD                           m_bufferSize;\r
-\r
-    CFX_ByteString                     m_WordBuf;\r
-\r
-    FX_BYTE                                    m_WordBuffer[257];\r
-\r
-    FX_DWORD                           m_WordSize;\r
-\r
-    FX_BYTE                                    m_bufferData[512];\r
-\r
-    CFX_FileSizeArray          m_CrossOffset;\r
-\r
-    CFX_DWordArray                     m_XRefStreamList;\r
-\r
-    CFX_DWordArray                     m_PageObjList;\r
-\r
-    FX_DWORD                           m_PagesObjNum;\r
-\r
-    FX_BOOL                                    m_bLinearized;\r
-\r
-    FX_DWORD                           m_dwFirstPageNo;\r
-\r
-    FX_BOOL                                    m_bLinearedDataOK;\r
-\r
-    FX_BOOL                                    m_bMainXRefLoad;\r
-\r
-    FX_BOOL                                    m_bMainXRefLoadedOK;\r
-\r
-    FX_BOOL                                    m_bPagesTreeLoad;\r
-\r
-    FX_BOOL                                    m_bPagesLoad;\r
-\r
-    CPDF_Parser *                      m_pCurrentParser;\r
-\r
-    FX_FILESIZE                                m_dwCurrentXRefSteam;\r
-\r
-    FX_BOOL                                    m_bAnnotsLoad;\r
-\r
-    FX_BOOL                                    m_bHaveAcroForm;\r
-\r
-    FX_DWORD                           m_dwAcroFormObjNum;\r
-\r
-    FX_BOOL                                    m_bAcroFormLoad;\r
-\r
-    CPDF_Object        *                       m_pAcroForm;\r
-\r
-    CFX_PtrArray                       m_arrayAcroforms;\r
-\r
-    CPDF_Dictionary *          m_pPageDict;\r
-\r
-    CPDF_Object *                      m_pPageResource;\r
-\r
-    FX_BOOL                                    m_bNeedDownLoadResource;\r
-\r
-    FX_BOOL                                    m_bPageLoadedOK;\r
-\r
-    FX_BOOL                                    m_bLinearizedFormParamLoad;\r
-\r
-    CFX_PtrArray                       m_PagesArray;\r
-\r
-    FX_DWORD                           m_dwEncryptObjNum;\r
-\r
-    FX_FILESIZE                                m_dwPrevXRefOffset;\r
-\r
-    FX_BOOL                                    m_bTotalLoadPageTree;\r
-\r
-    FX_BOOL                                    m_bCurPageDictLoadOK;\r
-\r
-    CPDF_PageNode                      m_pageNodes;\r
-\r
-    CFX_CMapDWordToDWord *     m_pageMapCheckState;\r
-\r
-    CFX_CMapDWordToDWord *     m_pagesLoadState;\r
-};\r
-#endif\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
+#define CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
+
+#include "../../../third_party/base/nonstd_unique_ptr.h"
+#include "../fxcrt/fx_system.h"
+#include "fpdf_objects.h"
+
+class CPDF_Document;
+class CPDF_Parser;
+class CPDF_SecurityHandler;
+class CPDF_StandardSecurityHandler;
+class CPDF_CryptoHandler;
+class CPDF_Object;
+class IFX_FileRead;
+class CFDF_Document;
+class CFDF_Parser;
+class CFX_Font;
+class CFX_AffineMatrix;
+class CFX_FloatRect;
+class CPDF_Point;
+class CPDF_DocPageData;
+class CPDF_DocRenderData;
+class CPDF_ModuleMgr;
+class CFX_DIBSource;
+class CPDF_Font;
+class CPDF_Image;
+class CPDF_ColorSpace;
+class CPDF_Pattern;
+class CPDF_FontEncoding;
+class CPDF_IccProfile;
+class CFX_PrivateData;
+#define FPDFPERM_PRINT 0x0004
+#define FPDFPERM_MODIFY 0x0008
+#define FPDFPERM_EXTRACT 0x0010
+#define FPDFPERM_ANNOT_FORM 0x0020
+#define FPDFPERM_FILL_FORM 0x0100
+#define FPDFPERM_EXTRACT_ACCESS 0x0200
+#define FPDFPERM_ASSEMBLE 0x0400
+#define FPDFPERM_PRINT_HIGH 0x0800
+#define FPDF_PAGE_MAX_NUM 0xFFFFF
+
+// Use the accessors below instead of directly accessing PDF_CharType.
+extern const char PDF_CharType[256];
+
+inline bool PDFCharIsWhitespace(uint8_t c) {
+  return PDF_CharType[c] == 'W';
+}
+inline bool PDFCharIsNumeric(uint8_t c) {
+  return PDF_CharType[c] == 'N';
+}
+inline bool PDFCharIsDelimiter(uint8_t c) {
+  return PDF_CharType[c] == 'D';
+}
+inline bool PDFCharIsOther(uint8_t c) {
+  return PDF_CharType[c] == 'R';
+}
+
+inline bool PDFCharIsLineEnding(uint8_t c) {
+  return c == '\r' || c == '\n';
+}
+
+// Indexed by 8-bit char code, contains unicode code points.
+extern const FX_WORD PDFDocEncoding[256];
+
+class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjects {
+ public:
+  CPDF_Document();
+  explicit CPDF_Document(CPDF_Parser* pParser);
+
+  ~CPDF_Document();
+
+  CPDF_Parser* GetParser() const { return m_pParser; }
+
+  CPDF_Dictionary* GetRoot() const { return m_pRootDict; }
+
+  CPDF_Dictionary* GetInfo() const { return m_pInfoDict; }
+
+  void GetID(CFX_ByteString& id1, CFX_ByteString& id2) const {
+    id1 = m_ID1;
+    id2 = m_ID2;
+  }
+
+  int GetPageCount() const;
+
+  CPDF_Dictionary* GetPage(int iPage);
+
+  int GetPageIndex(FX_DWORD objnum);
+
+  FX_DWORD GetUserPermissions(FX_BOOL bCheckRevision = FALSE) const;
+
+  FX_BOOL IsOwner() const;
+
+  CPDF_DocPageData* GetPageData() { return GetValidatePageData(); }
+
+  void ClearPageData();
+
+  void RemoveColorSpaceFromPageData(CPDF_Object* pObject);
+
+  CPDF_DocRenderData* GetRenderData() { return GetValidateRenderData(); }
+
+  void ClearRenderData();
+
+  void ClearRenderFont();
+
+  FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const;
+
+  // |pFontDict| must not be null.
+  CPDF_Font* LoadFont(CPDF_Dictionary* pFontDict);
+
+  CPDF_ColorSpace* LoadColorSpace(CPDF_Object* pCSObj,
+                                  CPDF_Dictionary* pResources = NULL);
+
+  CPDF_Pattern* LoadPattern(CPDF_Object* pObj,
+                            FX_BOOL bShading,
+                            const CFX_AffineMatrix* matrix = NULL);
+
+  CPDF_Image* LoadImageF(CPDF_Object* pObj);
+
+  CPDF_StreamAcc* LoadFontFile(CPDF_Stream* pStream);
+
+  CPDF_IccProfile* LoadIccProfile(CPDF_Stream* pStream);
+
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+
+  CPDF_Font* AddWindowsFont(LOGFONTA* pLogFont,
+                            FX_BOOL bVert,
+                            FX_BOOL bTranslateName = FALSE);
+  CPDF_Font* AddWindowsFont(LOGFONTW* pLogFont,
+                            FX_BOOL bVert,
+                            FX_BOOL bTranslateName = FALSE);
+#endif
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+  CPDF_Font* AddMacFont(CTFontRef pFont,
+                        FX_BOOL bVert,
+                        FX_BOOL bTranslateName = FALSE);
+#endif
+
+  CPDF_Font* AddStandardFont(const FX_CHAR* font, CPDF_FontEncoding* pEncoding);
+
+  CPDF_Font* AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert);
+
+  void CreateNewDoc();
+
+  CPDF_Dictionary* CreateNewPage(int iPage);
+
+  void DeletePage(int iPage);
+
+  void LoadDoc();
+  void LoadAsynDoc(CPDF_Dictionary* pLinearized);
+  void LoadPages();
+
+ protected:
+  CPDF_Dictionary* m_pRootDict;
+
+  CPDF_Dictionary* m_pInfoDict;
+
+  CFX_ByteString m_ID1;
+
+  CFX_ByteString m_ID2;
+
+  FX_BOOL m_bLinearized;
+
+  FX_DWORD m_dwFirstPageNo;
+
+  FX_DWORD m_dwFirstPageObjNum;
+
+  CFX_DWordArray m_PageList;
+
+  int _GetPageCount() const;
+  CPDF_Dictionary* _FindPDFPage(CPDF_Dictionary* pPages,
+                                int iPage,
+                                int nPagesToGo,
+                                int level);
+  int _FindPageIndex(CPDF_Dictionary* pNode,
+                     FX_DWORD& skip_count,
+                     FX_DWORD objnum,
+                     int& index,
+                     int level = 0);
+  FX_BOOL IsContentUsedElsewhere(FX_DWORD objnum, CPDF_Dictionary* pPageDict);
+  FX_BOOL CheckOCGVisible(CPDF_Dictionary* pOCG, FX_BOOL bPrinting);
+  CPDF_DocPageData* GetValidatePageData();
+  CPDF_DocRenderData* GetValidateRenderData();
+  friend class CPDF_Creator;
+  friend class CPDF_Parser;
+  friend class CPDF_DataAvail;
+  friend class CPDF_OCContext;
+
+  CPDF_DocPageData* m_pDocPage;
+
+  CPDF_DocRenderData* m_pDocRender;
+};
+
+#define PDFWORD_EOF 0
+#define PDFWORD_NUMBER 1
+#define PDFWORD_TEXT 2
+#define PDFWORD_DELIMITER 3
+#define PDFWORD_NAME 4
+class CPDF_SimpleParser {
+ public:
+  CPDF_SimpleParser(const uint8_t* pData, FX_DWORD dwSize);
+
+  CPDF_SimpleParser(const CFX_ByteStringC& str);
+
+  CFX_ByteStringC GetWord();
+
+  FX_BOOL SearchToken(const CFX_ByteStringC& token);
+
+  FX_BOOL SkipWord(const CFX_ByteStringC& token);
+
+  FX_BOOL FindTagPair(const CFX_ByteStringC& start_token,
+                      const CFX_ByteStringC& end_token,
+                      FX_DWORD& start_pos,
+                      FX_DWORD& end_pos);
+
+  FX_BOOL FindTagParam(const CFX_ByteStringC& token, int nParams);
+
+  FX_DWORD GetPos() { return m_dwCurPos; }
+
+  void SetPos(FX_DWORD pos) {
+    ASSERT(pos <= m_dwSize);
+    m_dwCurPos = pos;
+  }
+
+ private:
+  void ParseWord(const uint8_t*& pStart, FX_DWORD& dwSize, int& type);
+
+  const uint8_t* m_pData;
+
+  FX_DWORD m_dwSize;
+
+  FX_DWORD m_dwCurPos;
+};
+class CPDF_SyntaxParser {
+ public:
+  CPDF_SyntaxParser();
+  virtual ~CPDF_SyntaxParser();
+
+  void InitParser(IFX_FileRead* pFileAccess, FX_DWORD HeaderOffset);
+
+  FX_FILESIZE SavePos() { return m_Pos; }
+
+  void RestorePos(FX_FILESIZE pos) { m_Pos = pos; }
+
+  CPDF_Object* GetObject(CPDF_IndirectObjects* pObjList,
+                         FX_DWORD objnum,
+                         FX_DWORD gennum,
+                         struct PARSE_CONTEXT* pContext = NULL,
+                         FX_BOOL bDecrypt = TRUE);
+
+  CPDF_Object* GetObjectByStrict(CPDF_IndirectObjects* pObjList,
+                                 FX_DWORD objnum,
+                                 FX_DWORD gennum,
+                                 struct PARSE_CONTEXT* pContext = NULL);
+
+  int GetDirectNum();
+
+  CFX_ByteString GetString(FX_DWORD objnum, FX_DWORD gennum);
+
+  CFX_ByteString GetName();
+
+  CFX_ByteString GetKeyword();
+
+  void GetBinary(uint8_t* buffer, FX_DWORD size);
+
+  void ToNextLine();
+
+  void ToNextWord();
+
+  FX_BOOL SearchWord(const CFX_ByteStringC& word,
+                     FX_BOOL bWholeWord,
+                     FX_BOOL bForward,
+                     FX_FILESIZE limit);
+
+  int SearchMultiWord(const CFX_ByteStringC& words,
+                      FX_BOOL bWholeWord,
+                      FX_FILESIZE limit);
+
+  FX_FILESIZE FindTag(const CFX_ByteStringC& tag, FX_FILESIZE limit);
+
+  void SetEncrypt(CPDF_CryptoHandler* pCryptoHandler) {
+    m_pCryptoHandler.reset(pCryptoHandler);
+  }
+
+  FX_BOOL IsEncrypted() { return m_pCryptoHandler != NULL; }
+
+  FX_BOOL GetCharAt(FX_FILESIZE pos, uint8_t& ch);
+
+  FX_BOOL ReadBlock(uint8_t* pBuf, FX_DWORD size);
+
+  CFX_ByteString GetNextWord(FX_BOOL& bIsNumber);
+
+ protected:
+  static const int kParserMaxRecursionDepth = 64;
+  static int s_CurrentRecursionDepth;
+
+  virtual FX_BOOL GetNextChar(uint8_t& ch);
+
+  FX_BOOL GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch);
+
+  void GetNextWord();
+
+  FX_BOOL IsWholeWord(FX_FILESIZE startpos,
+                      FX_FILESIZE limit,
+                      const uint8_t* tag,
+                      FX_DWORD taglen,
+                      FX_BOOL checkKeyword);
+
+  CFX_ByteString ReadString();
+
+  CFX_ByteString ReadHexString();
+
+  unsigned int ReadEOLMarkers(FX_FILESIZE pos);
+
+  CPDF_Stream* ReadStream(CPDF_Dictionary* pDict,
+                          PARSE_CONTEXT* pContext,
+                          FX_DWORD objnum,
+                          FX_DWORD gennum);
+
+  FX_FILESIZE m_Pos;
+
+  FX_BOOL m_bFileStream;
+
+  int m_MetadataObjnum;
+
+  IFX_FileRead* m_pFileAccess;
+
+  FX_DWORD m_HeaderOffset;
+
+  FX_FILESIZE m_FileLen;
+
+  uint8_t* m_pFileBuf;
+
+  FX_DWORD m_BufSize;
+
+  FX_FILESIZE m_BufOffset;
+
+  nonstd::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler;
+
+  uint8_t m_WordBuffer[257];
+
+  FX_DWORD m_WordSize;
+
+  FX_BOOL m_bIsNumber;
+
+  FX_FILESIZE m_dwWordPos;
+  friend class CPDF_Parser;
+  friend class CPDF_DataAvail;
+};
+
+#define PDFPARSE_TYPEONLY 1
+#define PDFPARSE_NOSTREAM 2
+struct PARSE_CONTEXT {
+  uint32_t m_Flags;
+  FX_FILESIZE m_DictStart;
+  FX_FILESIZE m_DictEnd;
+  FX_FILESIZE m_DataStart;
+  FX_FILESIZE m_DataEnd;
+};
+
+#define PDFPARSE_ERROR_SUCCESS 0
+#define PDFPARSE_ERROR_FILE 1
+#define PDFPARSE_ERROR_FORMAT 2
+#define PDFPARSE_ERROR_PASSWORD 3
+#define PDFPARSE_ERROR_HANDLER 4
+#define PDFPARSE_ERROR_CERT 5
+
+class CPDF_Parser {
+ public:
+  CPDF_Parser();
+  ~CPDF_Parser();
+
+  FX_DWORD StartParse(IFX_FileRead* pFile,
+                      FX_BOOL bReParse = FALSE,
+                      FX_BOOL bOwnFileRead = TRUE);
+
+  void CloseParser(FX_BOOL bReParse = FALSE);
+
+  FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE);
+
+  FX_BOOL IsOwner();
+
+  void SetPassword(const FX_CHAR* password) { m_Password = password; }
+
+  CFX_ByteString GetPassword() { return m_Password; }
+
+  CPDF_SecurityHandler* GetSecurityHandler() {
+    return m_pSecurityHandler.get();
+  }
+
+  CPDF_CryptoHandler* GetCryptoHandler() {
+    return m_Syntax.m_pCryptoHandler.get();
+  }
+
+  void SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler,
+                          FX_BOOL bForced = FALSE);
+
+  CFX_ByteString GetRecipient() { return m_bsRecipient; }
+
+  CPDF_Dictionary* GetTrailer() { return m_pTrailer; }
+
+  FX_FILESIZE GetLastXRefOffset() { return m_LastXRefOffset; }
+
+  CPDF_Document* GetDocument() { return m_pDocument; }
+
+  CFX_ArrayTemplate<CPDF_Dictionary*>* GetOtherTrailers() {
+    return &m_Trailers;
+  }
+
+  FX_DWORD GetRootObjNum();
+  FX_DWORD GetInfoObjNum();
+  CPDF_Array* GetIDArray();
+
+  CPDF_Dictionary* GetEncryptDict() { return m_pEncryptDict; }
+
+  FX_BOOL IsEncrypted() { return GetEncryptDict() != NULL; }
+
+  CPDF_Object* ParseIndirectObject(CPDF_IndirectObjects* pObjList,
+                                   FX_DWORD objnum,
+                                   PARSE_CONTEXT* pContext = NULL);
+  FX_DWORD GetLastObjNum();
+  FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm);
+
+  FX_FILESIZE GetObjectOffset(FX_DWORD objnum);
+
+  FX_FILESIZE GetObjectSize(FX_DWORD objnum);
+
+  int GetObjectVersion(FX_DWORD objnum) { return m_ObjVersion[objnum]; }
+
+  void GetIndirectBinary(FX_DWORD objnum, uint8_t*& pBuffer, FX_DWORD& size);
+
+  FX_BOOL GetFileStreamOption() { return m_Syntax.m_bFileStream; }
+
+  void SetFileStreamOption(FX_BOOL b) { m_Syntax.m_bFileStream = b; }
+
+  IFX_FileRead* GetFileAccess() const { return m_Syntax.m_pFileAccess; }
+
+  int GetFileVersion() const { return m_FileVersion; }
+
+  FX_BOOL IsXRefStream() const { return m_bXRefStream; }
+  CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList,
+                                     FX_FILESIZE pos,
+                                     FX_DWORD objnum,
+                                     struct PARSE_CONTEXT* pContext);
+
+  CPDF_Object* ParseIndirectObjectAtByStrict(CPDF_IndirectObjects* pObjList,
+                                             FX_FILESIZE pos,
+                                             FX_DWORD objnum,
+                                             struct PARSE_CONTEXT* pContext,
+                                             FX_FILESIZE* pResultPos);
+
+  FX_DWORD StartAsynParse(IFX_FileRead* pFile,
+                          FX_BOOL bReParse = FALSE,
+                          FX_BOOL bOwnFileRead = TRUE);
+
+  FX_DWORD GetFirstPageNo() { return m_dwFirstPageNo; }
+
+ protected:
+  CPDF_Document* m_pDocument;
+
+  CPDF_SyntaxParser m_Syntax;
+  FX_BOOL m_bOwnFileRead;
+  CPDF_Object* ParseDirect(CPDF_Object* pObj);
+
+  FX_BOOL LoadAllCrossRefV4(FX_FILESIZE pos);
+
+  FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos);
+
+  bool LoadCrossRefV4(FX_FILESIZE pos,
+                      FX_FILESIZE streampos,
+                      FX_BOOL bSkip,
+                      FX_BOOL bFirst);
+
+  FX_BOOL LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL bMainXRef);
+
+  CPDF_Dictionary* LoadTrailerV4();
+
+  FX_BOOL RebuildCrossRef();
+
+  FX_DWORD SetEncryptHandler();
+
+  void ReleaseEncryptHandler();
+
+  FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);
+
+  FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);
+
+  FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos);
+
+  FX_DWORD LoadLinearizedMainXRefTable();
+
+  CFX_MapPtrToPtr m_ObjectStreamMap;
+
+  CPDF_StreamAcc* GetObjectStream(FX_DWORD number);
+
+  FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset);
+
+  bool FindPosInOffsets(FX_FILESIZE pos) const;
+
+  int m_FileVersion;
+
+  CPDF_Dictionary* m_pTrailer;
+
+  CPDF_Dictionary* m_pEncryptDict;
+  void SetEncryptDictionary(CPDF_Dictionary* pDict);
+
+  FX_FILESIZE m_LastXRefOffset;
+
+  FX_BOOL m_bXRefStream;
+
+  nonstd::unique_ptr<CPDF_SecurityHandler> m_pSecurityHandler;
+
+  FX_BOOL m_bForceUseSecurityHandler;
+
+  CFX_ByteString m_bsRecipient;
+
+  CFX_ByteString m_FilePath;
+
+  CFX_ByteString m_Password;
+
+  CFX_FileSizeArray m_CrossRef;
+
+  CFX_ByteArray m_V5Type;
+
+  CFX_FileSizeArray m_SortedOffset;
+
+  CFX_WordArray m_ObjVersion;
+  CFX_ArrayTemplate<CPDF_Dictionary*> m_Trailers;
+
+  FX_BOOL m_bVersionUpdated;
+
+  CPDF_Object* m_pLinearized;
+
+  FX_DWORD m_dwFirstPageNo;
+
+  FX_DWORD m_dwXrefStartObjNum;
+  friend class CPDF_Creator;
+  friend class CPDF_DataAvail;
+};
+#define FXCIPHER_NONE 0
+#define FXCIPHER_RC4 1
+#define FXCIPHER_AES 2
+#define FXCIPHER_AES2 3
+class CPDF_SecurityHandler {
+ public:
+  virtual ~CPDF_SecurityHandler() {}
+
+  virtual FX_BOOL OnInit(CPDF_Parser* pParser,
+                         CPDF_Dictionary* pEncryptDict) = 0;
+
+  virtual FX_DWORD GetPermissions() = 0;
+
+  virtual FX_BOOL IsOwner() = 0;
+
+  virtual FX_BOOL GetCryptInfo(int& cipher,
+                               const uint8_t*& buffer,
+                               int& keylen) = 0;
+
+  virtual FX_BOOL IsMetadataEncrypted() { return TRUE; }
+
+  virtual CPDF_CryptoHandler* CreateCryptoHandler() = 0;
+
+  virtual CPDF_StandardSecurityHandler* GetStandardHandler() { return NULL; }
+};
+#define PDF_ENCRYPT_CONTENT 0
+class CPDF_StandardSecurityHandler : public CPDF_SecurityHandler {
+ public:
+  CPDF_StandardSecurityHandler();
+  ~CPDF_StandardSecurityHandler() override;
+
+  // CPDF_SecurityHandler
+  FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict) override;
+  FX_DWORD GetPermissions() override;
+  FX_BOOL IsOwner() override { return m_bOwner; }
+  FX_BOOL GetCryptInfo(int& cipher,
+                       const uint8_t*& buffer,
+                       int& keylen) override;
+  FX_BOOL IsMetadataEncrypted() override;
+  CPDF_CryptoHandler* CreateCryptoHandler() override;
+  CPDF_StandardSecurityHandler* GetStandardHandler() override { return this; }
+
+  void OnCreate(CPDF_Dictionary* pEncryptDict,
+                CPDF_Array* pIdArray,
+                const uint8_t* user_pass,
+                FX_DWORD user_size,
+                const uint8_t* owner_pass,
+                FX_DWORD owner_size,
+                FX_DWORD type = PDF_ENCRYPT_CONTENT);
+
+  void OnCreate(CPDF_Dictionary* pEncryptDict,
+                CPDF_Array* pIdArray,
+                const uint8_t* user_pass,
+                FX_DWORD user_size,
+                FX_DWORD type = PDF_ENCRYPT_CONTENT);
+
+  CFX_ByteString GetUserPassword(const uint8_t* owner_pass, FX_DWORD pass_size);
+  CFX_ByteString GetUserPassword(const uint8_t* owner_pass,
+                                 FX_DWORD pass_size,
+                                 int32_t key_len);
+  int GetVersion() { return m_Version; }
+  int GetRevision() { return m_Revision; }
+
+  int CheckPassword(const uint8_t* password,
+                    FX_DWORD pass_size,
+                    FX_BOOL bOwner,
+                    uint8_t* key);
+  int CheckPassword(const uint8_t* password,
+                    FX_DWORD pass_size,
+                    FX_BOOL bOwner,
+                    uint8_t* key,
+                    int key_len);
+
+ private:
+  int m_Version;
+
+  int m_Revision;
+
+  CPDF_Parser* m_pParser;
+
+  CPDF_Dictionary* m_pEncryptDict;
+
+  FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict);
+  FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict,
+                   FX_DWORD type,
+                   int& cipher,
+                   int& key_len);
+
+  FX_BOOL CheckUserPassword(const uint8_t* password,
+                            FX_DWORD pass_size,
+                            FX_BOOL bIgnoreEncryptMeta,
+                            uint8_t* key,
+                            int32_t key_len);
+
+  FX_BOOL CheckOwnerPassword(const uint8_t* password,
+                             FX_DWORD pass_size,
+                             uint8_t* key,
+                             int32_t key_len);
+  FX_BOOL AES256_CheckPassword(const uint8_t* password,
+                               FX_DWORD size,
+                               FX_BOOL bOwner,
+                               uint8_t* key);
+  void AES256_SetPassword(CPDF_Dictionary* pEncryptDict,
+                          const uint8_t* password,
+                          FX_DWORD size,
+                          FX_BOOL bOwner,
+                          const uint8_t* key);
+  void AES256_SetPerms(CPDF_Dictionary* pEncryptDict,
+                       FX_DWORD permission,
+                       FX_BOOL bEncryptMetadata,
+                       const uint8_t* key);
+  void OnCreate(CPDF_Dictionary* pEncryptDict,
+                CPDF_Array* pIdArray,
+                const uint8_t* user_pass,
+                FX_DWORD user_size,
+                const uint8_t* owner_pass,
+                FX_DWORD owner_size,
+                FX_BOOL bDefault,
+                FX_DWORD type);
+  FX_BOOL CheckSecurity(int32_t key_len);
+
+  FX_BOOL m_bOwner;
+
+  FX_DWORD m_Permissions;
+
+  int m_Cipher;
+
+  uint8_t m_EncryptKey[32];
+
+  int m_KeyLen;
+};
+class CPDF_CryptoHandler {
+ public:
+  virtual ~CPDF_CryptoHandler() {}
+
+  virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict,
+                       CPDF_SecurityHandler* pSecurityHandler) = 0;
+
+  virtual FX_DWORD DecryptGetSize(FX_DWORD src_size) = 0;
+
+  virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) = 0;
+
+  virtual FX_BOOL DecryptStream(void* context,
+                                const uint8_t* src_buf,
+                                FX_DWORD src_size,
+                                CFX_BinaryBuf& dest_buf) = 0;
+
+  virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest_buf) = 0;
+
+  virtual FX_DWORD EncryptGetSize(FX_DWORD objnum,
+                                  FX_DWORD version,
+                                  const uint8_t* src_buf,
+                                  FX_DWORD src_size) = 0;
+
+  virtual FX_BOOL EncryptContent(FX_DWORD objnum,
+                                 FX_DWORD version,
+                                 const uint8_t* src_buf,
+                                 FX_DWORD src_size,
+                                 uint8_t* dest_buf,
+                                 FX_DWORD& dest_size) = 0;
+
+  void Decrypt(FX_DWORD objnum, FX_DWORD version, CFX_ByteString& str);
+};
+class CPDF_StandardCryptoHandler : public CPDF_CryptoHandler {
+ public:
+  CPDF_StandardCryptoHandler();
+  ~CPDF_StandardCryptoHandler() override;
+
+  // CPDF_CryptoHandler
+  FX_BOOL Init(CPDF_Dictionary* pEncryptDict,
+               CPDF_SecurityHandler* pSecurityHandler) override;
+  FX_DWORD DecryptGetSize(FX_DWORD src_size) override;
+  void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) override;
+  FX_BOOL DecryptStream(void* context,
+                        const uint8_t* src_buf,
+                        FX_DWORD src_size,
+                        CFX_BinaryBuf& dest_buf) override;
+  FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest_buf) override;
+  FX_DWORD EncryptGetSize(FX_DWORD objnum,
+                          FX_DWORD version,
+                          const uint8_t* src_buf,
+                          FX_DWORD src_size) override;
+  FX_BOOL EncryptContent(FX_DWORD objnum,
+                         FX_DWORD version,
+                         const uint8_t* src_buf,
+                         FX_DWORD src_size,
+                         uint8_t* dest_buf,
+                         FX_DWORD& dest_size) override;
+
+  FX_BOOL Init(int cipher, const uint8_t* key, int keylen);
+
+ protected:
+  virtual void CryptBlock(FX_BOOL bEncrypt,
+                          FX_DWORD objnum,
+                          FX_DWORD gennum,
+                          const uint8_t* src_buf,
+                          FX_DWORD src_size,
+                          uint8_t* dest_buf,
+                          FX_DWORD& dest_size);
+  virtual void* CryptStart(FX_DWORD objnum, FX_DWORD gennum, FX_BOOL bEncrypt);
+  virtual FX_BOOL CryptStream(void* context,
+                              const uint8_t* src_buf,
+                              FX_DWORD src_size,
+                              CFX_BinaryBuf& dest_buf,
+                              FX_BOOL bEncrypt);
+  virtual FX_BOOL CryptFinish(void* context,
+                              CFX_BinaryBuf& dest_buf,
+                              FX_BOOL bEncrypt);
+
+  uint8_t m_EncryptKey[32];
+
+  int m_KeyLen;
+
+  int m_Cipher;
+
+  uint8_t* m_pAESContext;
+};
+class CPDF_Point {
+ public:
+  CPDF_Point(FX_FLOAT xx, FX_FLOAT yy) {
+    x = xx;
+    y = yy;
+  }
+
+  FX_FLOAT x;
+
+  FX_FLOAT y;
+};
+
+#define CPDF_Rect CFX_FloatRect
+#define CPDF_Matrix CFX_AffineMatrix
+CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& orig);
+CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig);
+CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig);
+CFX_ByteString PDF_EncodeString(const CFX_ByteString& src,
+                                FX_BOOL bHex = FALSE);
+CFX_WideString PDF_DecodeText(const uint8_t* pData,
+                              FX_DWORD size,
+                              CFX_CharMap* pCharMap = NULL);
+inline CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr,
+                                     CFX_CharMap* pCharMap = NULL) {
+  return PDF_DecodeText((const uint8_t*)bstr.c_str(), bstr.GetLength(),
+                        pCharMap);
+}
+CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString,
+                              int len = -1,
+                              CFX_CharMap* pCharMap = NULL);
+inline CFX_ByteString PDF_EncodeText(const CFX_WideString& str,
+                                     CFX_CharMap* pCharMap = NULL) {
+  return PDF_EncodeText(str.c_str(), str.GetLength(), pCharMap);
+}
+FX_FLOAT PDF_ClipFloat(FX_FLOAT f);
+class CFDF_Document : public CPDF_IndirectObjects {
+ public:
+  static CFDF_Document* CreateNewDoc();
+  static CFDF_Document* ParseFile(IFX_FileRead* pFile,
+                                  FX_BOOL bOwnFile = FALSE);
+  static CFDF_Document* ParseMemory(const uint8_t* pData, FX_DWORD size);
+
+  ~CFDF_Document();
+
+  FX_BOOL WriteBuf(CFX_ByteTextBuf& buf) const;
+
+  CPDF_Dictionary* GetRoot() const { return m_pRootDict; }
+
+  CFX_WideString GetWin32Path() const;
+
+ protected:
+  CFDF_Document();
+  void ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile);
+  CPDF_Dictionary* m_pRootDict;
+  IFX_FileRead* m_pFile;
+  FX_BOOL m_bOwnFile;
+};
+
+CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec);
+void FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec,
+                                const CFX_WideString& fullpath);
+
+void FlateEncode(const uint8_t* src_buf,
+                 FX_DWORD src_size,
+                 uint8_t*& dest_buf,
+                 FX_DWORD& dest_size);
+void FlateEncode(const uint8_t* src_buf,
+                 FX_DWORD src_size,
+                 int predictor,
+                 int Colors,
+                 int BitsPerComponent,
+                 int Columns,
+                 uint8_t*& dest_buf,
+                 FX_DWORD& dest_size);
+FX_DWORD FlateDecode(const uint8_t* src_buf,
+                     FX_DWORD src_size,
+                     uint8_t*& dest_buf,
+                     FX_DWORD& dest_size);
+FX_DWORD RunLengthDecode(const uint8_t* src_buf,
+                         FX_DWORD src_size,
+                         uint8_t*& dest_buf,
+                         FX_DWORD& dest_size);
+FX_BOOL IsSignatureDict(const CPDF_Dictionary* pDict);
+
+class CPDF_NumberTree {
+ public:
+  CPDF_NumberTree(CPDF_Dictionary* pRoot) { m_pRoot = pRoot; }
+
+  CPDF_Object* LookupValue(int num);
+
+ protected:
+  CPDF_Dictionary* m_pRoot;
+};
+
+class IFX_FileAvail {
+ public:
+  virtual ~IFX_FileAvail() {}
+  virtual FX_BOOL IsDataAvail(FX_FILESIZE offset, FX_DWORD size) = 0;
+};
+class IFX_DownloadHints {
+ public:
+  virtual ~IFX_DownloadHints() {}
+  virtual void AddSegment(FX_FILESIZE offset, FX_DWORD size) = 0;
+};
+#define PDF_IS_LINEARIZED 1
+#define PDF_NOT_LINEARIZED 0
+#define PDF_UNKNOW_LINEARIZED -1
+#define PDFFORM_NOTAVAIL 0
+#define PDFFORM_AVAIL 1
+#define PDFFORM_NOTEXIST 2
+class IPDF_DataAvail {
+ public:
+  static IPDF_DataAvail* Create(IFX_FileAvail* pFileAvail,
+                                IFX_FileRead* pFileRead);
+  virtual ~IPDF_DataAvail() {}
+
+  IFX_FileAvail* GetFileAvail() const { return m_pFileAvail; }
+  IFX_FileRead* GetFileRead() const { return m_pFileRead; }
+
+  virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) = 0;
+  virtual void SetDocument(CPDF_Document* pDoc) = 0;
+  virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) = 0;
+  virtual FX_BOOL IsLinearized() = 0;
+  virtual int32_t IsFormAvail(IFX_DownloadHints* pHints) = 0;
+  virtual int32_t IsLinearizedPDF() = 0;
+  virtual void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos,
+                                         FX_DWORD* pSize) = 0;
+
+ protected:
+  IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead);
+
+  IFX_FileAvail* m_pFileAvail;
+  IFX_FileRead* m_pFileRead;
+};
+class CPDF_SortObjNumArray {
+ public:
+  void AddObjNum(FX_DWORD dwObjNum);
+
+  FX_BOOL Find(FX_DWORD dwObjNum);
+
+  void RemoveAll() { m_number_array.RemoveAll(); }
+
+ protected:
+  FX_BOOL BinarySearch(FX_DWORD value, int& iNext);
+
+ protected:
+  CFX_DWordArray m_number_array;
+};
+enum PDF_PAGENODE_TYPE {
+  PDF_PAGENODE_UNKOWN = 0,
+  PDF_PAGENODE_PAGE,
+  PDF_PAGENODE_PAGES,
+  PDF_PAGENODE_ARRAY,
+};
+class CPDF_PageNode {
+ public:
+  CPDF_PageNode() : m_type(PDF_PAGENODE_UNKOWN) {}
+  ~CPDF_PageNode();
+  PDF_PAGENODE_TYPE m_type;
+  FX_DWORD m_dwPageNo;
+  CFX_PtrArray m_childNode;
+};
+enum PDF_DATAAVAIL_STATUS {
+  PDF_DATAAVAIL_HEADER = 0,
+  PDF_DATAAVAIL_FIRSTPAGE,
+  PDF_DATAAVAIL_FIRSTPAGE_PREPARE,
+  PDF_DATAAVAIL_END,
+  PDF_DATAAVAIL_CROSSREF,
+  PDF_DATAAVAIL_CROSSREF_ITEM,
+  PDF_DATAAVAIL_CROSSREF_STREAM,
+  PDF_DATAAVAIL_TRAILER,
+  PDF_DATAAVAIL_LOADALLCRSOSSREF,
+  PDF_DATAAVAIL_ROOT,
+  PDF_DATAAVAIL_INFO,
+  PDF_DATAAVAIL_ACROFORM,
+  PDF_DATAAVAIL_ACROFORM_SUBOBJECT,
+  PDF_DATAAVAIL_PAGETREE,
+  PDF_DATAAVAIL_PAGE,
+  PDF_DATAAVAIL_PAGE_LATERLOAD,
+  PDF_DATAAVAIL_RESOURCES,
+  PDF_DATAAVAIL_DONE,
+  PDF_DATAAVAIL_ERROR,
+  PDF_DATAAVAIL_LOADALLFILE,
+  PDF_DATAAVAIL_TRAILER_APPEND
+};
+
+FX_BOOL PDF_DataDecode(const uint8_t* src_buf,
+                       FX_DWORD src_size,
+                       const CPDF_Dictionary* pDict,
+                       uint8_t*& dest_buf,
+                       FX_DWORD& dest_size,
+                       CFX_ByteString& ImageEncoding,
+                       CPDF_Dictionary*& pImageParms,
+                       FX_DWORD estimated_size,
+                       FX_BOOL bImageAcc);
+
+#endif  // CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_