1 // Copyright 2016 The PDFium Authors 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_PAGE_CPDF_DOCPAGEDATA_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_DOCPAGEDATA_H_ 9 10 #include <map> 11 #include <memory> 12 #include <set> 13 14 #include "core/fpdfapi/font/cpdf_font.h" 15 #include "core/fpdfapi/page/cpdf_colorspace.h" 16 #include "core/fpdfapi/parser/cpdf_document.h" 17 #include "core/fxcrt/bytestring.h" 18 #include "core/fxcrt/fx_codepage_forward.h" 19 #include "core/fxcrt/fx_coordinates.h" 20 #include "core/fxcrt/observed_ptr.h" 21 #include "core/fxcrt/retain_ptr.h" 22 23 class CFX_Font; 24 class CPDF_Dictionary; 25 class CPDF_FontEncoding; 26 class CPDF_IccProfile; 27 class CPDF_Image; 28 class CPDF_Object; 29 class CPDF_Pattern; 30 class CPDF_Stream; 31 class CPDF_StreamAcc; 32 33 class CPDF_DocPageData final : public CPDF_Document::PageDataIface, 34 public CPDF_Font::FormFactoryIface { 35 public: 36 static CPDF_DocPageData* FromDocument(const CPDF_Document* pDoc); 37 38 CPDF_DocPageData(); 39 ~CPDF_DocPageData() override; 40 41 // CPDF_Document::PageDataIface: 42 void ClearStockFont() override; 43 RetainPtr<CPDF_StreamAcc> GetFontFileStreamAcc( 44 RetainPtr<const CPDF_Stream> pFontStream) override; 45 void MaybePurgeFontFileStreamAcc( 46 RetainPtr<CPDF_StreamAcc>&& pStreamAcc) override; 47 void MaybePurgeImage(uint32_t dwStreamObjNum) override; 48 49 // CPDF_Font::FormFactoryIFace: 50 std::unique_ptr<CPDF_Font::FormIface> CreateForm( 51 CPDF_Document* pDocument, 52 RetainPtr<CPDF_Dictionary> pPageResources, 53 RetainPtr<CPDF_Stream> pFormStream) override; 54 IsForceClear()55 bool IsForceClear() const { return m_bForceClear; } 56 57 RetainPtr<CPDF_Font> AddFont(std::unique_ptr<CFX_Font> pFont, 58 FX_Charset charset); 59 RetainPtr<CPDF_Font> GetFont(RetainPtr<CPDF_Dictionary> pFontDict); 60 RetainPtr<CPDF_Font> AddStandardFont(const ByteString& fontName, 61 const CPDF_FontEncoding* pEncoding); 62 RetainPtr<CPDF_Font> GetStandardFont(const ByteString& fontName, 63 const CPDF_FontEncoding* pEncoding); 64 #if BUILDFLAG(IS_WIN) 65 RetainPtr<CPDF_Font> AddWindowsFont(LOGFONTA* pLogFont); 66 #endif 67 68 // Loads a colorspace. 69 RetainPtr<CPDF_ColorSpace> GetColorSpace(const CPDF_Object* pCSObj, 70 const CPDF_Dictionary* pResources); 71 72 // Loads a colorspace in a context that might be while loading another 73 // colorspace. |pVisited| is passed recursively to avoid circular calls 74 // involving CPDF_ColorSpace::Load(). 75 RetainPtr<CPDF_ColorSpace> GetColorSpaceGuarded( 76 const CPDF_Object* pCSObj, 77 const CPDF_Dictionary* pResources, 78 std::set<const CPDF_Object*>* pVisited); 79 80 RetainPtr<CPDF_Pattern> GetPattern(RetainPtr<CPDF_Object> pPatternObj, 81 const CFX_Matrix& matrix); 82 RetainPtr<CPDF_ShadingPattern> GetShading(RetainPtr<CPDF_Object> pPatternObj, 83 const CFX_Matrix& matrix); 84 85 RetainPtr<CPDF_Image> GetImage(uint32_t dwStreamObjNum); 86 87 RetainPtr<CPDF_IccProfile> GetIccProfile( 88 RetainPtr<const CPDF_Stream> pProfileStream); 89 90 private: 91 // Loads a colorspace in a context that might be while loading another 92 // colorspace, or even in a recursive call from this method itself. |pVisited| 93 // is passed recursively to avoid circular calls involving 94 // CPDF_ColorSpace::Load() and |pVisitedInternal| is also passed recursively 95 // to avoid circular calls with this method calling itself. 96 RetainPtr<CPDF_ColorSpace> GetColorSpaceInternal( 97 const CPDF_Object* pCSObj, 98 const CPDF_Dictionary* pResources, 99 std::set<const CPDF_Object*>* pVisited, 100 std::set<const CPDF_Object*>* pVisitedInternal); 101 102 size_t CalculateEncodingDict(FX_Charset charset, CPDF_Dictionary* pBaseDict); 103 RetainPtr<CPDF_Dictionary> ProcessbCJK( 104 RetainPtr<CPDF_Dictionary> pBaseDict, 105 FX_Charset charset, 106 ByteString basefont, 107 std::function<void(wchar_t, wchar_t, CPDF_Array*)> Insert); 108 109 bool m_bForceClear = false; 110 111 // Specific destruction order may be required between maps. 112 std::map<ByteString, RetainPtr<const CPDF_Stream>> m_HashProfileMap; 113 std::map<RetainPtr<const CPDF_Array>, ObservedPtr<CPDF_ColorSpace>> 114 m_ColorSpaceMap; 115 std::map<RetainPtr<const CPDF_Stream>, RetainPtr<CPDF_StreamAcc>> 116 m_FontFileMap; 117 std::map<RetainPtr<const CPDF_Stream>, ObservedPtr<CPDF_IccProfile>> 118 m_IccProfileMap; 119 std::map<RetainPtr<const CPDF_Object>, ObservedPtr<CPDF_Pattern>> 120 m_PatternMap; 121 std::map<uint32_t, RetainPtr<CPDF_Image>> m_ImageMap; 122 std::map<RetainPtr<const CPDF_Dictionary>, ObservedPtr<CPDF_Font>> m_FontMap; 123 }; 124 125 #endif // CORE_FPDFAPI_PAGE_CPDF_DOCPAGEDATA_H_ 126