1 // Copyright 2017 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_FONT_CPDF_FONTGLOBALS_H_ 8 #define CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_ 9 10 #include <functional> 11 #include <map> 12 #include <memory> 13 14 #include "core/fpdfapi/cmaps/fpdf_cmaps.h" 15 #include "core/fpdfapi/font/cpdf_cidfont.h" 16 #include "core/fxcrt/retain_ptr.h" 17 #include "core/fxge/cfx_fontmapper.h" 18 #include "third_party/base/span.h" 19 20 class CFX_StockFontArray; 21 class CPDF_Font; 22 23 class CPDF_FontGlobals { 24 public: 25 // Per-process singleton which must be managed by callers. 26 static void Create(); 27 static void Destroy(); 28 static CPDF_FontGlobals* GetInstance(); 29 30 // Caller must load the maps before using font globals. 31 void LoadEmbeddedMaps(); 32 33 void Clear(CPDF_Document* pDoc); 34 RetainPtr<CPDF_Font> Find(CPDF_Document* pDoc, 35 CFX_FontMapper::StandardFont index); 36 void Set(CPDF_Document* pDoc, 37 CFX_FontMapper::StandardFont index, 38 RetainPtr<CPDF_Font> pFont); 39 SetEmbeddedCharset(CIDSet idx,pdfium::span<const fxcmap::CMap> map)40 void SetEmbeddedCharset(CIDSet idx, pdfium::span<const fxcmap::CMap> map) { 41 m_EmbeddedCharsets[idx] = map; 42 } GetEmbeddedCharset(CIDSet idx)43 pdfium::span<const fxcmap::CMap> GetEmbeddedCharset(CIDSet idx) const { 44 return m_EmbeddedCharsets[idx]; 45 } SetEmbeddedToUnicode(CIDSet idx,pdfium::span<const uint16_t> map)46 void SetEmbeddedToUnicode(CIDSet idx, pdfium::span<const uint16_t> map) { 47 m_EmbeddedToUnicodes[idx] = map; 48 } GetEmbeddedToUnicode(CIDSet idx)49 pdfium::span<const uint16_t> GetEmbeddedToUnicode(CIDSet idx) { 50 return m_EmbeddedToUnicodes[idx]; 51 } 52 53 RetainPtr<const CPDF_CMap> GetPredefinedCMap(const ByteString& name); 54 CPDF_CID2UnicodeMap* GetCID2UnicodeMap(CIDSet charset); 55 56 private: 57 CPDF_FontGlobals(); 58 ~CPDF_FontGlobals(); 59 60 void LoadEmbeddedGB1CMaps(); 61 void LoadEmbeddedCNS1CMaps(); 62 void LoadEmbeddedJapan1CMaps(); 63 void LoadEmbeddedKorea1CMaps(); 64 65 std::map<ByteString, RetainPtr<const CPDF_CMap>> m_CMaps; 66 std::unique_ptr<CPDF_CID2UnicodeMap> m_CID2UnicodeMaps[CIDSET_NUM_SETS]; 67 pdfium::span<const fxcmap::CMap> m_EmbeddedCharsets[CIDSET_NUM_SETS]; 68 pdfium::span<const uint16_t> m_EmbeddedToUnicodes[CIDSET_NUM_SETS]; 69 std::map<UnownedPtr<CPDF_Document>, 70 std::unique_ptr<CFX_StockFontArray>, 71 std::less<>> 72 m_StockMap; 73 }; 74 75 #endif // CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_ 76