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_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/fx_coordinates.h" 18 #include "core/fxcrt/fx_string.h" 19 #include "core/fxcrt/observed_ptr.h" 20 #include "core/fxcrt/retain_ptr.h" 21 #include "core/fxcrt/unowned_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 : 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 const CPDF_Stream* pFontStream) override; 45 void MaybePurgeFontFileStreamAcc(const CPDF_Stream* pFontStream) override; 46 47 // CPDF_Font::FormFactoryIFace: 48 std::unique_ptr<CPDF_Font::FormIface> CreateForm( 49 CPDF_Document* pDocument, 50 CPDF_Dictionary* pPageResources, 51 CPDF_Stream* pFormStream) override; 52 IsForceClear()53 bool IsForceClear() const { return m_bForceClear; } 54 55 RetainPtr<CPDF_Font> AddFont(std::unique_ptr<CFX_Font> pFont, int charset); 56 RetainPtr<CPDF_Font> GetFont(CPDF_Dictionary* pFontDict); 57 RetainPtr<CPDF_Font> AddStandardFont(const ByteString& fontName, 58 const CPDF_FontEncoding* pEncoding); 59 RetainPtr<CPDF_Font> GetStandardFont(const ByteString& fontName, 60 const CPDF_FontEncoding* pEncoding); 61 #if defined(OS_WIN) 62 RetainPtr<CPDF_Font> AddWindowsFont(LOGFONTA* pLogFont); 63 #endif 64 65 // Loads a colorspace. 66 RetainPtr<CPDF_ColorSpace> GetColorSpace(const CPDF_Object* pCSObj, 67 const CPDF_Dictionary* pResources); 68 69 // Loads a colorspace in a context that might be while loading another 70 // colorspace. |pVisited| is passed recursively to avoid circular calls 71 // involving CPDF_ColorSpace::Load(). 72 RetainPtr<CPDF_ColorSpace> GetColorSpaceGuarded( 73 const CPDF_Object* pCSObj, 74 const CPDF_Dictionary* pResources, 75 std::set<const CPDF_Object*>* pVisited); 76 77 RetainPtr<CPDF_Pattern> GetPattern(CPDF_Object* pPatternObj, 78 bool bShading, 79 const CFX_Matrix& matrix); 80 81 RetainPtr<CPDF_Image> GetImage(uint32_t dwStreamObjNum); 82 void MaybePurgeImage(uint32_t dwStreamObjNum); 83 84 RetainPtr<CPDF_IccProfile> GetIccProfile(const CPDF_Stream* pProfileStream); 85 86 private: 87 // Loads a colorspace in a context that might be while loading another 88 // colorspace, or even in a recursive call from this method itself. |pVisited| 89 // is passed recursively to avoid circular calls involving 90 // CPDF_ColorSpace::Load() and |pVisitedInternal| is also passed recursively 91 // to avoid circular calls with this method calling itself. 92 RetainPtr<CPDF_ColorSpace> GetColorSpaceInternal( 93 const CPDF_Object* pCSObj, 94 const CPDF_Dictionary* pResources, 95 std::set<const CPDF_Object*>* pVisited, 96 std::set<const CPDF_Object*>* pVisitedInternal); 97 98 size_t CalculateEncodingDict(int charset, CPDF_Dictionary* pBaseDict); 99 CPDF_Dictionary* ProcessbCJK( 100 CPDF_Dictionary* pBaseDict, 101 int charset, 102 ByteString basefont, 103 std::function<void(wchar_t, wchar_t, CPDF_Array*)> Insert); 104 void Clear(bool bForceRelease); 105 106 bool m_bForceClear = false; 107 108 // Specific destruction order may be required between maps. 109 std::map<ByteString, RetainPtr<const CPDF_Stream>> m_HashProfileMap; 110 std::map<const CPDF_Object*, ObservedPtr<CPDF_ColorSpace>> m_ColorSpaceMap; 111 std::map<const CPDF_Stream*, RetainPtr<CPDF_StreamAcc>> m_FontFileMap; 112 std::map<const CPDF_Stream*, ObservedPtr<CPDF_IccProfile>> m_IccProfileMap; 113 std::map<const CPDF_Object*, ObservedPtr<CPDF_Pattern>> m_PatternMap; 114 std::map<uint32_t, RetainPtr<CPDF_Image>> m_ImageMap; 115 std::map<const CPDF_Dictionary*, ObservedPtr<CPDF_Font>> m_FontMap; 116 }; 117 118 #endif // CORE_FPDFAPI_PAGE_CPDF_DOCPAGEDATA_H_ 119