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