| 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_DOCUMENT_H_ | |
| 8 #define CORE_FPDFAPI_FPDF_PARSER_CPDF_DOCUMENT_H_ | |
| 9 | |
| 10 #include <functional> | |
| 11 #include <memory> | |
| 12 | |
| 13 #include "core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.h" | |
| 14 #include "core/fpdfapi/fpdf_parser/cpdf_object.h" | |
| 15 #include "core/fpdfdoc/cpdf_linklist.h" | |
| 16 #include "core/fxcrt/cfx_string_pool_template.h" | |
| 17 #include "core/fxcrt/cfx_weak_ptr.h" | |
| 18 #include "core/fxcrt/fx_basic.h" | |
| 19 | |
| 20 class CFX_Font; | |
| 21 class CFX_Matrix; | |
| 22 class CPDF_ColorSpace; | |
| 23 class CPDF_DocPageData; | |
| 24 class CPDF_DocRenderData; | |
| 25 class CPDF_Font; | |
| 26 class CPDF_FontEncoding; | |
| 27 class CPDF_IccProfile; | |
| 28 class CPDF_Image; | |
| 29 class CPDF_Parser; | |
| 30 class CPDF_Pattern; | |
| 31 class CPDF_StreamAcc; | |
| 32 class JBig2_DocumentContext; | |
| 33 | |
| 34 #define FPDFPERM_PRINT 0x0004 | |
| 35 #define FPDFPERM_MODIFY 0x0008 | |
| 36 #define FPDFPERM_EXTRACT 0x0010 | |
| 37 #define FPDFPERM_ANNOT_FORM 0x0020 | |
| 38 #define FPDFPERM_FILL_FORM 0x0100 | |
| 39 #define FPDFPERM_EXTRACT_ACCESS 0x0200 | |
| 40 #define FPDFPERM_ASSEMBLE 0x0400 | |
| 41 #define FPDFPERM_PRINT_HIGH 0x0800 | |
| 42 #define FPDF_PAGE_MAX_NUM 0xFFFFF | |
| 43 | |
| 44 class CPDF_Document : public CPDF_IndirectObjectHolder { | |
| 45 public: | |
| 46 explicit CPDF_Document(std::unique_ptr<CPDF_Parser> pParser); | |
| 47 ~CPDF_Document() override; | |
| 48 | |
| 49 CPDF_Parser* GetParser() const { return m_pParser.get(); } | |
| 50 CPDF_Dictionary* GetRoot() const { return m_pRootDict; } | |
| 51 CPDF_Dictionary* GetInfo() const { return m_pInfoDict; } | |
| 52 CFX_WeakPtr<CFX_ByteStringPool> GetByteStringPool() const { | |
| 53 return m_pByteStringPool; | |
| 54 } | |
| 55 | |
| 56 void DeletePage(int iPage); | |
| 57 int GetPageCount() const; | |
| 58 | |
| 59 bool IsPageLoaded(int iPage) const; | |
| 60 CPDF_Dictionary* GetPage(int iPage); | |
| 61 int GetPageIndex(uint32_t objnum); | |
| 62 uint32_t GetUserPermissions() const; | |
| 63 CPDF_DocPageData* GetPageData() const { return m_pDocPage; } | |
| 64 | |
| 65 void SetPageObjNum(int iPage, uint32_t objNum); | |
| 66 | |
| 67 std::unique_ptr<JBig2_DocumentContext>* CodecContext() { | |
| 68 return &m_pCodecContext; | |
| 69 } | |
| 70 std::unique_ptr<CPDF_LinkList>* LinksContext() { return &m_pLinksContext; } | |
| 71 | |
| 72 CPDF_DocRenderData* GetRenderData() const { return m_pDocRender.get(); } | |
| 73 | |
| 74 // |pFontDict| must not be null. | |
| 75 CPDF_Font* LoadFont(CPDF_Dictionary* pFontDict); | |
| 76 CPDF_ColorSpace* LoadColorSpace(CPDF_Object* pCSObj, | |
| 77 CPDF_Dictionary* pResources = nullptr); | |
| 78 | |
| 79 CPDF_Pattern* LoadPattern(CPDF_Object* pObj, | |
| 80 FX_BOOL bShading, | |
| 81 const CFX_Matrix& matrix); | |
| 82 | |
| 83 CPDF_Image* LoadImageF(CPDF_Object* pObj); | |
| 84 CPDF_StreamAcc* LoadFontFile(CPDF_Stream* pStream); | |
| 85 CPDF_IccProfile* LoadIccProfile(CPDF_Stream* pStream); | |
| 86 | |
| 87 void LoadDoc(); | |
| 88 void LoadLinearizedDoc(CPDF_Dictionary* pLinearizationParams); | |
| 89 void LoadPages(); | |
| 90 | |
| 91 void CreateNewDoc(); | |
| 92 CPDF_Dictionary* CreateNewPage(int iPage); | |
| 93 | |
| 94 CPDF_Font* AddStandardFont(const FX_CHAR* font, CPDF_FontEncoding* pEncoding); | |
| 95 CPDF_Font* AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert); | |
| 96 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | |
| 97 CPDF_Font* AddWindowsFont(LOGFONTA* pLogFont, | |
| 98 FX_BOOL bVert, | |
| 99 FX_BOOL bTranslateName = FALSE); | |
| 100 CPDF_Font* AddWindowsFont(LOGFONTW* pLogFont, | |
| 101 FX_BOOL bVert, | |
| 102 FX_BOOL bTranslateName = FALSE); | |
| 103 #endif | |
| 104 | |
| 105 private: | |
| 106 friend class CPDF_TestDocument; | |
| 107 | |
| 108 // Retrieve page count information by getting count value from the tree nodes | |
| 109 int RetrievePageCount() const; | |
| 110 CPDF_Dictionary* FindPDFPage(CPDF_Dictionary* pPages, | |
| 111 int iPage, | |
| 112 int nPagesToGo, | |
| 113 int level); | |
| 114 int FindPageIndex(CPDF_Dictionary* pNode, | |
| 115 uint32_t& skip_count, | |
| 116 uint32_t objnum, | |
| 117 int& index, | |
| 118 int level = 0); | |
| 119 CPDF_Object* ParseIndirectObject(uint32_t objnum) override; | |
| 120 void LoadDocInternal(); | |
| 121 size_t CalculateEncodingDict(int charset, CPDF_Dictionary* pBaseDict); | |
| 122 CPDF_Dictionary* GetPagesDict() const; | |
| 123 CPDF_Dictionary* ProcessbCJK( | |
| 124 CPDF_Dictionary* pBaseDict, | |
| 125 int charset, | |
| 126 FX_BOOL bVert, | |
| 127 CFX_ByteString basefont, | |
| 128 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert); | |
| 129 | |
| 130 std::unique_ptr<CPDF_Parser> m_pParser; | |
| 131 CPDF_Dictionary* m_pRootDict; | |
| 132 CPDF_Dictionary* m_pInfoDict; | |
| 133 bool m_bLinearized; | |
| 134 int m_iFirstPageNo; | |
| 135 uint32_t m_dwFirstPageObjNum; | |
| 136 // TODO(thestig): Figure out why this cannot be a std::unique_ptr. | |
| 137 CPDF_DocPageData* m_pDocPage; | |
| 138 std::unique_ptr<CPDF_DocRenderData> m_pDocRender; | |
| 139 std::unique_ptr<JBig2_DocumentContext> m_pCodecContext; | |
| 140 std::unique_ptr<CPDF_LinkList> m_pLinksContext; | |
| 141 CFX_ArrayTemplate<uint32_t> m_PageList; | |
| 142 CFX_WeakPtr<CFX_ByteStringPool> m_pByteStringPool; | |
| 143 }; | |
| 144 | |
| 145 #endif // CORE_FPDFAPI_FPDF_PARSER_CPDF_DOCUMENT_H_ | |
| OLD | NEW |