• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 #include "core/fpdfapi/cmaps/fpdf_cmaps.h"
14 #include "core/fpdfapi/font/cpdf_cmapmanager.h"
15 #include "core/fxcrt/retain_ptr.h"
16 #include "core/fxge/cfx_fontmapper.h"
17 #include "third_party/base/span.h"
18 
19 class CFX_StockFontArray;
20 
21 class CPDF_FontGlobals {
22  public:
23   // Per-process singleton which must be managed by callers.
24   static void Create();
25   static void Destroy();
26   static CPDF_FontGlobals* GetInstance();
27 
28   // Caller must load the maps before using font globals.
29   void LoadEmbeddedMaps();
30 
31   void Clear(CPDF_Document* pDoc);
32   RetainPtr<CPDF_Font> Find(CPDF_Document* pDoc,
33                             CFX_FontMapper::StandardFont index);
34   void Set(CPDF_Document* pDoc,
35            CFX_FontMapper::StandardFont index,
36            const RetainPtr<CPDF_Font>& pFont);
37 
SetEmbeddedCharset(size_t idx,pdfium::span<const FXCMAP_CMap> map)38   void SetEmbeddedCharset(size_t idx, pdfium::span<const FXCMAP_CMap> map) {
39     m_EmbeddedCharsets[idx] = map;
40   }
GetEmbeddedCharset(size_t idx)41   pdfium::span<const FXCMAP_CMap> GetEmbeddedCharset(size_t idx) const {
42     return m_EmbeddedCharsets[idx];
43   }
SetEmbeddedToUnicode(size_t idx,pdfium::span<const uint16_t> map)44   void SetEmbeddedToUnicode(size_t idx, pdfium::span<const uint16_t> map) {
45     m_EmbeddedToUnicodes[idx] = map;
46   }
GetEmbeddedToUnicode(size_t idx)47   pdfium::span<const uint16_t> GetEmbeddedToUnicode(size_t idx) {
48     return m_EmbeddedToUnicodes[idx];
49   }
50 
GetCMapManager()51   CPDF_CMapManager* GetCMapManager() { return &m_CMapManager; }
52 
53  private:
54   CPDF_FontGlobals();
55   ~CPDF_FontGlobals();
56 
57   void LoadEmbeddedGB1CMaps();
58   void LoadEmbeddedCNS1CMaps();
59   void LoadEmbeddedJapan1CMaps();
60   void LoadEmbeddedKorea1CMaps();
61 
62   CPDF_CMapManager m_CMapManager;
63   pdfium::span<const FXCMAP_CMap> m_EmbeddedCharsets[CIDSET_NUM_SETS];
64   pdfium::span<const uint16_t> m_EmbeddedToUnicodes[CIDSET_NUM_SETS];
65   std::map<CPDF_Document*, std::unique_ptr<CFX_StockFontArray>> m_StockMap;
66 };
67 
68 #endif  // CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_
69