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