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