Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef XFA_FGAS_FONT_CFGAS_FONTMGR_H_ | 7 #ifndef XFA_FGAS_FONT_CFGAS_FONTMGR_H_ |
| 8 #define XFA_FGAS_FONT_CFGAS_FONTMGR_H_ | 8 #define XFA_FGAS_FONT_CFGAS_FONTMGR_H_ |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 15 #include "core/fxcrt/cfx_retain_ptr.h" | |
| 14 #include "core/fxcrt/fx_ext.h" | 16 #include "core/fxcrt/fx_ext.h" |
| 15 #include "core/fxge/cfx_fontmapper.h" | 17 #include "core/fxge/cfx_fontmapper.h" |
| 16 #include "core/fxge/fx_freetype.h" | 18 #include "core/fxge/fx_freetype.h" |
| 17 #include "core/fxge/ifx_systemfontinfo.h" | 19 #include "core/fxge/ifx_systemfontinfo.h" |
| 18 #include "third_party/freetype/include/freetype/fttypes.h" | 20 #include "third_party/freetype/include/freetype/fttypes.h" |
| 19 #include "xfa/fgas/crt/fgas_stream.h" | 21 #include "xfa/fgas/crt/fgas_stream.h" |
| 20 #include "xfa/fgas/font/cfgas_fontmgr.h" | |
| 21 | 22 |
| 22 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 23 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 23 #include "xfa/fgas/crt/fgas_memory.h" | 24 #include "xfa/fgas/crt/fgas_memory.h" |
| 24 #include "xfa/fgas/crt/fgas_utils.h" | 25 #include "xfa/fgas/crt/fgas_utils.h" |
| 25 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 26 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 26 | 27 |
| 27 #define FX_FONTSTYLE_Normal 0x00 | 28 #define FX_FONTSTYLE_Normal 0x00 |
| 28 #define FX_FONTSTYLE_FixedPitch 0x01 | 29 #define FX_FONTSTYLE_FixedPitch 0x01 |
| 29 #define FX_FONTSTYLE_Serif 0x02 | 30 #define FX_FONTSTYLE_Serif 0x02 |
| 30 #define FX_FONTSTYLE_Symbolic 0x04 | 31 #define FX_FONTSTYLE_Symbolic 0x04 |
| 31 #define FX_FONTSTYLE_Script 0x08 | 32 #define FX_FONTSTYLE_Script 0x08 |
| 32 #define FX_FONTSTYLE_Italic 0x40 | 33 #define FX_FONTSTYLE_Italic 0x40 |
| 33 #define FX_FONTSTYLE_Bold 0x40000 | 34 #define FX_FONTSTYLE_Bold 0x40000 |
| 34 #define FX_FONTSTYLE_BoldItalic (FX_FONTSTYLE_Bold | FX_FONTSTYLE_Italic) | 35 #define FX_FONTSTYLE_BoldItalic (FX_FONTSTYLE_Bold | FX_FONTSTYLE_Italic) |
| 35 #define FX_FONTSTYLE_ExactMatch 0x80000000 | 36 #define FX_FONTSTYLE_ExactMatch 0x80000000 |
| 36 | 37 |
| 37 class CFX_FontSourceEnum_File; | 38 class CFX_FontSourceEnum_File; |
| 38 class CFGAS_GEFont; | |
| 39 class CXFA_PDFFontMgr; | 39 class CXFA_PDFFontMgr; |
| 40 class CFGAS_FontMgr; | 40 class CFGAS_FontMgr; |
| 41 class CFGAS_GEFont; | |
| 41 | 42 |
| 42 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 43 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 43 #define FX_FONTMATCHPARA_MatchStyle 0x01 | 44 #define FX_FONTMATCHPARA_MatchStyle 0x01 |
| 44 | 45 |
| 45 struct FX_FONTMATCHPARAMS { | 46 struct FX_FONTMATCHPARAMS { |
| 46 const FX_WCHAR* pwsFamily; | 47 const FX_WCHAR* pwsFamily; |
| 47 uint32_t dwFontStyles; | 48 uint32_t dwFontStyles; |
| 48 uint32_t dwUSB; | 49 uint32_t dwUSB; |
| 49 uint32_t dwMatchFlags; | 50 uint32_t dwMatchFlags; |
| 50 FX_WCHAR wUnicode; | 51 FX_WCHAR wUnicode; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 } | 84 } |
| 84 | 85 |
| 85 typedef void (*FX_LPEnumAllFonts)(CFX_FontDescriptors& fonts, | 86 typedef void (*FX_LPEnumAllFonts)(CFX_FontDescriptors& fonts, |
| 86 const FX_WCHAR* pwsFaceName, | 87 const FX_WCHAR* pwsFaceName, |
| 87 FX_WCHAR wUnicode); | 88 FX_WCHAR wUnicode); |
| 88 | 89 |
| 89 FX_LPEnumAllFonts FX_GetDefFontEnumerator(); | 90 FX_LPEnumAllFonts FX_GetDefFontEnumerator(); |
| 90 | 91 |
| 91 class CFGAS_FontMgr { | 92 class CFGAS_FontMgr { |
| 92 public: | 93 public: |
| 94 static std::unique_ptr<CFGAS_FontMgr> Create(FX_LPEnumAllFonts pEnumerator); | |
| 95 | |
| 93 explicit CFGAS_FontMgr(FX_LPEnumAllFonts pEnumerator); | 96 explicit CFGAS_FontMgr(FX_LPEnumAllFonts pEnumerator); |
| 94 ~CFGAS_FontMgr(); | 97 ~CFGAS_FontMgr(); |
| 95 | 98 |
| 96 static std::unique_ptr<CFGAS_FontMgr> Create(FX_LPEnumAllFonts pEnumerator); | 99 CFX_RetainPtr<CFGAS_GEFont> GetFontByCodePage(uint16_t wCodePage, |
| 97 | 100 uint32_t dwFontStyles, |
| 98 CFGAS_GEFont* GetFontByCodePage(uint16_t wCodePage, | 101 const FX_WCHAR* pszFontFamily); |
| 99 uint32_t dwFontStyles, | 102 CFX_RetainPtr<CFGAS_GEFont> GetFontByUnicode(FX_WCHAR wUnicode, |
| 100 const FX_WCHAR* pszFontFamily); | 103 uint32_t dwFontStyles, |
| 101 CFGAS_GEFont* GetFontByUnicode(FX_WCHAR wUnicode, | 104 const FX_WCHAR* pszFontFamily); |
| 102 uint32_t dwFontStyles, | 105 CFX_RetainPtr<CFGAS_GEFont> LoadFont(const FX_WCHAR* pszFontFamily, |
| 103 const FX_WCHAR* pszFontFamily); | 106 uint32_t dwFontStyles, |
| 104 CFGAS_GEFont* LoadFont(const FX_WCHAR* pszFontFamily, | 107 uint16_t wCodePage); |
| 105 uint32_t dwFontStyles, | 108 void RemoveFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont); |
| 106 uint16_t wCodePage); | |
| 107 void RemoveFont(CFGAS_GEFont* pFont); | |
| 108 | 109 |
| 109 private: | 110 private: |
| 110 CFGAS_GEFont* LoadFont(CFGAS_GEFont* pSrcFont, | 111 CFX_RetainPtr<CFGAS_GEFont> LoadFont( |
| 111 uint32_t dwFontStyles, | 112 const CFX_RetainPtr<CFGAS_GEFont>& pSrcFont, |
| 112 uint16_t wCodePage); | 113 uint32_t dwFontStyles, |
| 113 void RemoveFont(CFX_MapPtrToPtr& fontMap, CFGAS_GEFont* pFont); | 114 uint16_t wCodePage); |
| 114 FX_FONTDESCRIPTOR const* FindFont(const FX_WCHAR* pszFontFamily, | 115 void RemoveFont(std::map<uint32_t, CFX_RetainPtr<CFGAS_GEFont>>* pFontMap, |
| 116 const CFX_RetainPtr<CFGAS_GEFont>& pFont); | |
| 117 const FX_FONTDESCRIPTOR* FindFont(const FX_WCHAR* pszFontFamily, | |
| 115 uint32_t dwFontStyles, | 118 uint32_t dwFontStyles, |
| 116 uint32_t dwMatchFlags, | 119 uint32_t dwMatchFlags, |
| 117 uint16_t wCodePage, | 120 uint16_t wCodePage, |
| 118 uint32_t dwUSB = 999, | 121 uint32_t dwUSB = 999, |
| 119 FX_WCHAR wUnicode = 0); | 122 FX_WCHAR wUnicode = 0); |
| 120 | 123 |
| 121 FX_LPEnumAllFonts m_pEnumerator; | 124 FX_LPEnumAllFonts m_pEnumerator; |
| 122 CFX_FontDescriptors m_FontFaces; | 125 CFX_FontDescriptors m_FontFaces; |
| 123 CFX_ArrayTemplate<CFGAS_GEFont*> m_Fonts; | 126 std::vector<CFX_RetainPtr<CFGAS_GEFont>> m_Fonts; |
| 124 CFX_MapPtrToPtr m_CPFonts; | 127 std::map<uint32_t, CFX_RetainPtr<CFGAS_GEFont>> m_CPFonts; |
| 125 CFX_MapPtrToPtr m_FamilyFonts; | 128 std::map<uint32_t, CFX_RetainPtr<CFGAS_GEFont>> m_FamilyFonts; |
| 126 CFX_MapPtrToPtr m_UnicodeFonts; | 129 std::map<uint32_t, CFX_RetainPtr<CFGAS_GEFont>> m_UnicodeFonts; |
| 127 CFX_MapPtrToPtr m_BufferFonts; | 130 std::map<uint32_t, CFX_RetainPtr<CFGAS_GEFont>> m_BufferFonts; |
| 128 CFX_MapPtrToPtr m_StreamFonts; | 131 std::map<uint32_t, CFX_RetainPtr<CFGAS_GEFont>> m_StreamFonts; |
| 129 CFX_MapPtrToPtr m_DeriveFonts; | 132 std::map<uint32_t, CFX_RetainPtr<CFGAS_GEFont>> m_DeriveFonts; |
| 130 }; | 133 }; |
| 131 | 134 |
| 132 #else // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 135 #else // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 133 class CFX_FontDescriptor { | 136 class CFX_FontDescriptor { |
| 134 public: | 137 public: |
| 135 CFX_FontDescriptor(); | 138 CFX_FontDescriptor(); |
| 136 ~CFX_FontDescriptor(); | 139 ~CFX_FontDescriptor(); |
| 137 | 140 |
| 138 int32_t m_nFaceIndex; | 141 int32_t m_nFaceIndex; |
| 139 CFX_WideString m_wsFaceName; | 142 CFX_WideString m_wsFaceName; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 private: | 187 private: |
| 185 CFX_ByteString GetNextFile(); | 188 CFX_ByteString GetNextFile(); |
| 186 | 189 |
| 187 CFX_WideString m_wsNext; | 190 CFX_WideString m_wsNext; |
| 188 std::vector<FX_HandleParentPath> m_FolderQueue; | 191 std::vector<FX_HandleParentPath> m_FolderQueue; |
| 189 std::vector<CFX_ByteString> m_FolderPaths; | 192 std::vector<CFX_ByteString> m_FolderPaths; |
| 190 }; | 193 }; |
| 191 | 194 |
| 192 class CFGAS_FontMgr { | 195 class CFGAS_FontMgr { |
| 193 public: | 196 public: |
| 194 explicit CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum); | |
| 195 ~CFGAS_FontMgr(); | |
| 196 static std::unique_ptr<CFGAS_FontMgr> Create( | 197 static std::unique_ptr<CFGAS_FontMgr> Create( |
| 197 CFX_FontSourceEnum_File* pFontEnum); | 198 CFX_FontSourceEnum_File* pFontEnum); |
| 198 | 199 |
| 199 CFGAS_GEFont* GetFontByCodePage(uint16_t wCodePage, | 200 explicit CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum); |
| 200 uint32_t dwFontStyles, | 201 ~CFGAS_FontMgr(); |
| 201 const FX_WCHAR* pszFontFamily); | |
| 202 CFGAS_GEFont* GetFontByUnicode(FX_WCHAR wUnicode, | |
| 203 uint32_t dwFontStyles, | |
| 204 const FX_WCHAR* pszFontFamily); | |
| 205 void RemoveFont(CFGAS_GEFont* pFont); | |
| 206 | 202 |
| 207 inline CFGAS_GEFont* LoadFont(const FX_WCHAR* pszFontFamily, | 203 CFX_RetainPtr<CFGAS_GEFont> GetFontByCodePage(uint16_t wCodePage, |
| 208 uint32_t dwFontStyles, | 204 uint32_t dwFontStyles, |
| 209 uint16_t wCodePage) { | 205 const FX_WCHAR* pszFontFamily); |
| 210 return GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); | 206 CFX_RetainPtr<CFGAS_GEFont> GetFontByUnicode(FX_WCHAR wUnicode, |
| 211 } | 207 uint32_t dwFontStyles, |
| 208 const FX_WCHAR* pszFontFamily); | |
| 209 CFX_RetainPtr<CFGAS_GEFont> LoadFont(const FX_WCHAR* pszFontFamily, | |
| 210 uint32_t dwFontStyles, | |
| 211 uint16_t wCodePage); | |
| 212 void RemoveFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont); | |
|
dsinclair
2017/01/05 17:01:20
This signature is a bit confusing. Will the retain
Tom Sepez
2017/01/05 17:35:49
RemoveFont removes the font from the Manager. Sin
| |
| 212 | 213 |
| 213 private: | 214 private: |
| 214 bool EnumFonts(); | 215 bool EnumFonts(); |
| 215 bool EnumFontsFromFontMapper(); | 216 bool EnumFontsFromFontMapper(); |
| 216 bool EnumFontsFromFiles(); | 217 bool EnumFontsFromFiles(); |
| 217 void RegisterFace(FXFT_Face pFace, const CFX_WideString* pFaceName); | 218 void RegisterFace(FXFT_Face pFace, const CFX_WideString* pFaceName); |
| 218 void RegisterFaces(const CFX_RetainPtr<IFX_SeekableReadStream>& pFontStream, | 219 void RegisterFaces(const CFX_RetainPtr<IFX_SeekableReadStream>& pFontStream, |
| 219 const CFX_WideString* pFaceName); | 220 const CFX_WideString* pFaceName); |
| 220 void GetNames(const uint8_t* name_table, std::vector<CFX_WideString>& Names); | 221 void GetNames(const uint8_t* name_table, std::vector<CFX_WideString>& Names); |
| 221 std::vector<uint16_t> GetCharsets(FXFT_Face pFace) const; | 222 std::vector<uint16_t> GetCharsets(FXFT_Face pFace) const; |
| 222 void GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB); | 223 void GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB); |
| 223 uint32_t GetFlags(FXFT_Face pFace); | 224 uint32_t GetFlags(FXFT_Face pFace); |
| 224 bool VerifyUnicode(CFX_FontDescriptor* pDesc, FX_WCHAR wcUnicode); | 225 bool VerifyUnicode(CFX_FontDescriptor* pDesc, FX_WCHAR wcUnicode); |
| 225 bool VerifyUnicode(CFGAS_GEFont* pFont, FX_WCHAR wcUnicode); | 226 bool VerifyUnicode(const CFX_RetainPtr<CFGAS_GEFont>& pFont, |
| 227 FX_WCHAR wcUnicode); | |
| 226 int32_t IsPartName(const CFX_WideString& Name1, const CFX_WideString& Name2); | 228 int32_t IsPartName(const CFX_WideString& Name1, const CFX_WideString& Name2); |
| 227 int32_t MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, | 229 int32_t MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, |
| 228 uint16_t wCodePage, | 230 uint16_t wCodePage, |
| 229 uint32_t dwFontStyles, | 231 uint32_t dwFontStyles, |
| 230 const CFX_WideString& FontName, | 232 const CFX_WideString& FontName, |
| 231 FX_WCHAR wcUnicode = 0xFFFE); | 233 FX_WCHAR wcUnicode = 0xFFFE); |
| 232 int32_t CalcPenalty(CFX_FontDescriptor* pInstalled, | 234 int32_t CalcPenalty(CFX_FontDescriptor* pInstalled, |
| 233 uint16_t wCodePage, | 235 uint16_t wCodePage, |
| 234 uint32_t dwFontStyles, | 236 uint32_t dwFontStyles, |
| 235 const CFX_WideString& FontName, | 237 const CFX_WideString& FontName, |
| 236 FX_WCHAR wcUnicode = 0xFFFE); | 238 FX_WCHAR wcUnicode = 0xFFFE); |
| 237 CFGAS_GEFont* LoadFont(const CFX_WideString& wsFaceName, | 239 CFX_RetainPtr<CFGAS_GEFont> LoadFont(const CFX_WideString& wsFaceName, |
| 238 int32_t iFaceIndex, | 240 int32_t iFaceIndex, |
| 239 int32_t* pFaceCount); | 241 int32_t* pFaceCount); |
| 240 FXFT_Face LoadFace(const CFX_RetainPtr<IFX_SeekableReadStream>& pFontStream, | 242 FXFT_Face LoadFace(const CFX_RetainPtr<IFX_SeekableReadStream>& pFontStream, |
| 241 int32_t iFaceIndex); | 243 int32_t iFaceIndex); |
| 242 CFX_RetainPtr<IFX_SeekableReadStream> CreateFontStream( | 244 CFX_RetainPtr<IFX_SeekableReadStream> CreateFontStream( |
| 243 CFX_FontMapper* pFontMapper, | 245 CFX_FontMapper* pFontMapper, |
| 244 IFX_SystemFontInfo* pSystemFontInfo, | 246 IFX_SystemFontInfo* pSystemFontInfo, |
| 245 uint32_t index); | 247 uint32_t index); |
| 246 CFX_RetainPtr<IFX_SeekableReadStream> CreateFontStream( | 248 CFX_RetainPtr<IFX_SeekableReadStream> CreateFontStream( |
| 247 const CFX_ByteString& bsFaceName); | 249 const CFX_ByteString& bsFaceName); |
| 248 | 250 |
| 249 CFX_FontDescriptors m_InstalledFonts; | 251 CFX_FontDescriptors m_InstalledFonts; |
| 250 CFX_MapPtrTemplate<uint32_t, CFX_FontDescriptorInfos*> m_Hash2CandidateList; | 252 CFX_MapPtrTemplate<uint32_t, CFX_FontDescriptorInfos*> m_Hash2CandidateList; |
| 251 CFX_MapPtrTemplate<uint32_t, CFX_ArrayTemplate<CFGAS_GEFont*>*> m_Hash2Fonts; | 253 std::map<uint32_t, std::vector<CFX_RetainPtr<CFGAS_GEFont>>> m_Hash2Fonts; |
| 252 std::map<CFGAS_GEFont*, CFX_RetainPtr<IFX_SeekableReadStream> > | 254 std::map<CFX_RetainPtr<CFGAS_GEFont>, CFX_RetainPtr<IFX_SeekableReadStream>> |
| 253 m_IFXFont2FileRead; | 255 m_IFXFont2FileRead; |
| 254 CFX_MapPtrTemplate<FX_WCHAR, CFGAS_GEFont*> m_FailedUnicodes2Nullptr; | 256 std::set<FX_WCHAR> m_FailedUnicodesSet; |
| 255 CFX_FontSourceEnum_File* const m_pFontSource; | 257 CFX_FontSourceEnum_File* const m_pFontSource; |
| 256 }; | 258 }; |
| 257 #endif | 259 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 258 | 260 |
| 259 #endif // XFA_FGAS_FONT_CFGAS_FONTMGR_H_ | 261 #endif // XFA_FGAS_FONT_CFGAS_FONTMGR_H_ |
| OLD | NEW |