1 // Copyright 2017 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_FONT_CPDF_FONTGLOBALS_H_ 8 #define CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_ 9 10 #include <map> 11 #include <memory> 12 #include <utility> 13 14 #include "core/fpdfapi/cmaps/cmap_int.h" 15 #include "core/fpdfapi/font/cfx_stockfontarray.h" 16 #include "core/fpdfapi/font/cpdf_cmapmanager.h" 17 18 class CPDF_FontGlobals { 19 public: 20 CPDF_FontGlobals(); 21 ~CPDF_FontGlobals(); 22 23 void Clear(CPDF_Document* pDoc); 24 CPDF_Font* Find(CPDF_Document* pDoc, uint32_t index); 25 26 // Takes ownership of |pFont|, returns unowned pointer to it. 27 CPDF_Font* Set(CPDF_Document* key, 28 uint32_t index, 29 std::unique_ptr<CPDF_Font> pFont); 30 SetEmbeddedCharset(size_t idx,const FXCMAP_CMap * map,uint32_t count)31 void SetEmbeddedCharset(size_t idx, const FXCMAP_CMap* map, uint32_t count) { 32 m_EmbeddedCharsets[idx].m_pMapList = map; 33 m_EmbeddedCharsets[idx].m_Count = count; 34 } GetEmbeddedCharset(size_t idx)35 std::pair<uint32_t, const FXCMAP_CMap*> GetEmbeddedCharset(size_t idx) const { 36 return {m_EmbeddedCharsets[idx].m_Count, 37 m_EmbeddedCharsets[idx].m_pMapList.Get()}; 38 } SetEmbeddedToUnicode(size_t idx,const uint16_t * map,uint32_t count)39 void SetEmbeddedToUnicode(size_t idx, const uint16_t* map, uint32_t count) { 40 m_EmbeddedToUnicodes[idx].m_pMap = map; 41 m_EmbeddedToUnicodes[idx].m_Count = count; 42 } GetEmbeddedToUnicode(size_t idx)43 std::pair<uint32_t, const uint16_t*> GetEmbeddedToUnicode(size_t idx) { 44 return {m_EmbeddedToUnicodes[idx].m_Count, 45 m_EmbeddedToUnicodes[idx].m_pMap}; 46 } 47 GetCMapManager()48 CPDF_CMapManager* GetCMapManager() { return &m_CMapManager; } 49 50 private: 51 CPDF_CMapManager m_CMapManager; 52 struct { 53 UnownedPtr<const FXCMAP_CMap> m_pMapList; 54 uint32_t m_Count; 55 } m_EmbeddedCharsets[CIDSET_NUM_SETS]; 56 struct { 57 const uint16_t* m_pMap; 58 uint32_t m_Count; 59 } m_EmbeddedToUnicodes[CIDSET_NUM_SETS]; 60 61 std::map<CPDF_Document*, std::unique_ptr<CFX_StockFontArray>> m_StockMap; 62 }; 63 64 #endif // CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_ 65