• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_FXGE_CFX_FONTMAPPER_H_
8 #define CORE_FXGE_CFX_FONTMAPPER_H_
9 
10 #include <memory>
11 #include <utility>
12 #include <vector>
13 
14 #include "core/fxge/fx_font.h"
15 
16 class CFX_FontMgr;
17 class CFX_SubstFont;
18 class IFX_SystemFontInfo;
19 
20 class CFX_FontMapper {
21  public:
22   explicit CFX_FontMapper(CFX_FontMgr* mgr);
23   ~CFX_FontMapper();
24 
25   void SetSystemFontInfo(std::unique_ptr<IFX_SystemFontInfo> pFontInfo);
GetSystemFontInfo()26   IFX_SystemFontInfo* GetSystemFontInfo() { return m_pFontInfo.get(); }
27   void AddInstalledFont(const ByteString& name, int charset);
28   void LoadInstalledFonts();
29 
30   FXFT_Face FindSubstFont(const ByteString& face_name,
31                           bool bTrueType,
32                           uint32_t flags,
33                           int weight,
34                           int italic_angle,
35                           int CharsetCP,
36                           CFX_SubstFont* pSubstFont);
37 #ifdef PDF_ENABLE_XFA
38   FXFT_Face FindSubstFontByUnicode(uint32_t dwUnicode,
39                                    uint32_t flags,
40                                    int weight,
41                                    int italic_angle);
42 #endif  // PDF_ENABLE_XFA
43   bool IsBuiltinFace(const FXFT_Face face) const;
44   int GetFaceSize() const;
GetFaceName(int index)45   ByteString GetFaceName(int index) const { return m_FaceArray[index].name; }
46 
47   std::vector<ByteString> m_InstalledTTFonts;
48   std::vector<std::pair<ByteString, ByteString>> m_LocalizedTTFonts;
49 
50  private:
51   static const size_t MM_FACE_COUNT = 2;
52   static const size_t FOXIT_FACE_COUNT = 14;
53 
54   ByteString GetPSNameFromTT(void* hFont);
55   ByteString MatchInstalledFonts(const ByteString& norm_name);
56   FXFT_Face UseInternalSubst(CFX_SubstFont* pSubstFont,
57                              int iBaseFont,
58                              int italic_angle,
59                              int weight,
60                              int picthfamily);
61   FXFT_Face GetCachedTTCFace(void* hFont,
62                              const uint32_t tableTTCF,
63                              uint32_t ttc_size,
64                              uint32_t font_size);
65   FXFT_Face GetCachedFace(void* hFont,
66                           ByteString SubstName,
67                           int weight,
68                           bool bItalic,
69                           uint32_t font_size);
70 
71   struct FaceData {
72     ByteString name;
73     uint32_t charset;
74   };
75 
76   bool m_bListLoaded;
77   FXFT_Face m_MMFaces[MM_FACE_COUNT];
78   ByteString m_LastFamily;
79   std::vector<FaceData> m_FaceArray;
80   std::unique_ptr<IFX_SystemFontInfo> m_pFontInfo;
81   FXFT_Face m_FoxitFaces[FOXIT_FACE_COUNT];
82   UnownedPtr<CFX_FontMgr> const m_pFontMgr;
83 };
84 
85 #endif  // CORE_FXGE_CFX_FONTMAPPER_H_
86