| 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_FGAS_STDFONTMGR_H_ | 7 #ifndef XFA_FGAS_FONT_CFGAS_FONTMGR_H_ |
| 8 #define XFA_FGAS_FONT_FGAS_STDFONTMGR_H_ | 8 #define XFA_FGAS_FONT_CFGAS_FONTMGR_H_ |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "core/fxcrt/fx_ext.h" | 12 #include "core/fxcrt/fx_ext.h" |
| 13 #include "core/fxge/cfx_fontmapper.h" | 13 #include "core/fxge/cfx_fontmapper.h" |
| 14 #include "core/fxge/fx_freetype.h" | 14 #include "core/fxge/fx_freetype.h" |
| 15 #include "core/fxge/ifx_systemfontinfo.h" | 15 #include "core/fxge/ifx_systemfontinfo.h" |
| 16 #include "third_party/freetype/include/freetype/fttypes.h" | 16 #include "third_party/freetype/include/freetype/fttypes.h" |
| 17 #include "xfa/fgas/font/fgas_font.h" | 17 #include "xfa/fgas/crt/fgas_stream.h" |
| 18 #include "xfa/fgas/font/cfgas_fontmgr.h" |
| 18 | 19 |
| 19 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 20 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 20 int32_t FX_GetSimilarValue(FX_FONTDESCRIPTOR const* pFont, | 21 #include "xfa/fgas/crt/fgas_memory.h" |
| 21 uint32_t dwFontStyles); | 22 #include "xfa/fgas/crt/fgas_utils.h" |
| 22 FX_FONTDESCRIPTOR const* FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, | 23 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 23 const CFX_FontDescriptors& fonts); | |
| 24 | 24 |
| 25 class CFGAS_StdFontMgrImp : public IFGAS_FontMgr { | 25 #define FX_FONTSTYLE_Normal 0x00 |
| 26 #define FX_FONTSTYLE_FixedPitch 0x01 |
| 27 #define FX_FONTSTYLE_Serif 0x02 |
| 28 #define FX_FONTSTYLE_Symbolic 0x04 |
| 29 #define FX_FONTSTYLE_Script 0x08 |
| 30 #define FX_FONTSTYLE_Italic 0x40 |
| 31 #define FX_FONTSTYLE_Bold 0x40000 |
| 32 #define FX_FONTSTYLE_BoldItalic (FX_FONTSTYLE_Bold | FX_FONTSTYLE_Italic) |
| 33 #define FX_FONTSTYLE_ExactMatch 0x80000000 |
| 34 |
| 35 class CFX_FontSourceEnum_File; |
| 36 class CFGAS_GEFont; |
| 37 class CXFA_PDFFontMgr; |
| 38 class CFGAS_FontMgr; |
| 39 |
| 40 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 41 #define FX_FONTMATCHPARA_MatchStyle 0x01 |
| 42 |
| 43 struct FX_FONTMATCHPARAMS { |
| 44 const FX_WCHAR* pwsFamily; |
| 45 uint32_t dwFontStyles; |
| 46 uint32_t dwUSB; |
| 47 uint32_t dwMatchFlags; |
| 48 FX_WCHAR wUnicode; |
| 49 uint16_t wCodePage; |
| 50 }; |
| 51 |
| 52 typedef FX_FONTMATCHPARAMS* FX_LPFONTMATCHPARAMS; |
| 53 |
| 54 struct FX_FONTSIGNATURE { |
| 55 uint32_t fsUsb[4]; |
| 56 uint32_t fsCsb[2]; |
| 57 }; |
| 58 |
| 59 inline bool operator==(const FX_FONTSIGNATURE& left, |
| 60 const FX_FONTSIGNATURE& right) { |
| 61 return left.fsUsb[0] == right.fsUsb[0] && left.fsUsb[1] == right.fsUsb[1] && |
| 62 left.fsUsb[2] == right.fsUsb[2] && left.fsUsb[3] == right.fsUsb[3] && |
| 63 left.fsCsb[0] == right.fsCsb[0] && left.fsCsb[1] == right.fsCsb[1]; |
| 64 } |
| 65 |
| 66 struct FX_FONTDESCRIPTOR { |
| 67 FX_WCHAR wsFontFace[32]; |
| 68 uint32_t dwFontStyles; |
| 69 uint8_t uCharSet; |
| 70 FX_FONTSIGNATURE FontSignature; |
| 71 }; |
| 72 |
| 73 typedef CFX_MassArrayTemplate<FX_FONTDESCRIPTOR> CFX_FontDescriptors; |
| 74 |
| 75 inline bool operator==(const FX_FONTDESCRIPTOR& left, |
| 76 const FX_FONTDESCRIPTOR& right) { |
| 77 return left.uCharSet == right.uCharSet && |
| 78 left.dwFontStyles == right.dwFontStyles && |
| 79 left.FontSignature == right.FontSignature && |
| 80 FXSYS_wcscmp(left.wsFontFace, right.wsFontFace) == 0; |
| 81 } |
| 82 |
| 83 typedef void (*FX_LPEnumAllFonts)(CFX_FontDescriptors& fonts, |
| 84 const FX_WCHAR* pwsFaceName, |
| 85 FX_WCHAR wUnicode); |
| 86 |
| 87 FX_LPEnumAllFonts FX_GetDefFontEnumerator(); |
| 88 |
| 89 class CFGAS_FontMgr { |
| 26 public: | 90 public: |
| 27 explicit CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator); | 91 explicit CFGAS_FontMgr(FX_LPEnumAllFonts pEnumerator); |
| 28 ~CFGAS_StdFontMgrImp() override; | 92 ~CFGAS_FontMgr(); |
| 29 | 93 |
| 30 // IFGAS_FontMgr: | 94 static std::unique_ptr<CFGAS_FontMgr> Create(FX_LPEnumAllFonts pEnumerator); |
| 31 CFGAS_GEFont* GetDefFontByCodePage( | 95 |
| 32 uint16_t wCodePage, | 96 CFGAS_GEFont* GetDefFontByCodePage(uint16_t wCodePage, |
| 33 uint32_t dwFontStyles, | 97 uint32_t dwFontStyles, |
| 34 const FX_WCHAR* pszFontFamily = nullptr) override; | 98 const FX_WCHAR* pszFontFamily = nullptr); |
| 35 CFGAS_GEFont* GetDefFontByCharset( | 99 CFGAS_GEFont* GetDefFontByUnicode(FX_WCHAR wUnicode, |
| 36 uint8_t nCharset, | 100 uint32_t dwFontStyles, |
| 37 uint32_t dwFontStyles, | 101 const FX_WCHAR* pszFontFamily = nullptr); |
| 38 const FX_WCHAR* pszFontFamily = nullptr) override; | |
| 39 CFGAS_GEFont* GetDefFontByUnicode( | |
| 40 FX_WCHAR wUnicode, | |
| 41 uint32_t dwFontStyles, | |
| 42 const FX_WCHAR* pszFontFamily = nullptr) override; | |
| 43 CFGAS_GEFont* GetDefFontByLanguage( | |
| 44 uint16_t wLanguage, | |
| 45 uint32_t dwFontStyles, | |
| 46 const FX_WCHAR* pszFontFamily = nullptr) override; | |
| 47 CFGAS_GEFont* LoadFont(const FX_WCHAR* pszFontFamily, | 102 CFGAS_GEFont* LoadFont(const FX_WCHAR* pszFontFamily, |
| 48 uint32_t dwFontStyles, | 103 uint32_t dwFontStyles, |
| 49 uint16_t wCodePage = 0xFFFF) override; | 104 uint16_t wCodePage = 0xFFFF); |
| 50 CFGAS_GEFont* LoadFont(const uint8_t* pBuffer, int32_t iLength) override; | 105 CFGAS_GEFont* LoadFont(const uint8_t* pBuffer, int32_t iLength); |
| 51 CFGAS_GEFont* LoadFont(IFX_Stream* pFontStream, | 106 CFGAS_GEFont* LoadFont(IFX_Stream* pFontStream, |
| 52 const FX_WCHAR* pszFontAlias = nullptr, | 107 const FX_WCHAR* pszFontAlias = nullptr, |
| 53 uint32_t dwFontStyles = 0, | 108 uint32_t dwFontStyles = 0, |
| 54 uint16_t wCodePage = 0, | 109 uint16_t wCodePage = 0, |
| 55 bool bSaveStream = false) override; | 110 bool bSaveStream = false); |
| 56 CFGAS_GEFont* LoadFont(CFGAS_GEFont* pSrcFont, | 111 CFGAS_GEFont* LoadFont(CFGAS_GEFont* pSrcFont, |
| 57 uint32_t dwFontStyles, | 112 uint32_t dwFontStyles, |
| 58 uint16_t wCodePage = 0xFFFF) override; | 113 uint16_t wCodePage = 0xFFFF); |
| 59 | 114 |
| 60 void ClearFontCache() override; | 115 // TODO(npm): This method is not being used, but probably should be in |
| 61 void RemoveFont(CFGAS_GEFont* pFont) override; | 116 // destructor |
| 117 void ClearFontCache(); |
| 118 void RemoveFont(CFGAS_GEFont* pFont); |
| 62 | 119 |
| 63 protected: | 120 private: |
| 64 void RemoveFont(CFX_MapPtrToPtr& fontMap, CFGAS_GEFont* pFont); | 121 void RemoveFont(CFX_MapPtrToPtr& fontMap, CFGAS_GEFont* pFont); |
| 65 FX_FONTDESCRIPTOR const* FindFont(const FX_WCHAR* pszFontFamily, | 122 FX_FONTDESCRIPTOR const* FindFont(const FX_WCHAR* pszFontFamily, |
| 66 uint32_t dwFontStyles, | 123 uint32_t dwFontStyles, |
| 67 uint32_t dwMatchFlags, | 124 uint32_t dwMatchFlags, |
| 68 uint16_t wCodePage, | 125 uint16_t wCodePage, |
| 69 uint32_t dwUSB = 999, | 126 uint32_t dwUSB = 999, |
| 70 FX_WCHAR wUnicode = 0); | 127 FX_WCHAR wUnicode = 0); |
| 71 | 128 |
| 72 FX_LPEnumAllFonts m_pEnumerator; | 129 FX_LPEnumAllFonts m_pEnumerator; |
| 73 CFX_FontDescriptors m_FontFaces; | 130 CFX_FontDescriptors m_FontFaces; |
| 74 CFX_ArrayTemplate<CFGAS_GEFont*> m_Fonts; | 131 CFX_ArrayTemplate<CFGAS_GEFont*> m_Fonts; |
| 75 CFX_MapPtrToPtr m_CPFonts; | 132 CFX_MapPtrToPtr m_CPFonts; |
| 76 CFX_MapPtrToPtr m_FamilyFonts; | 133 CFX_MapPtrToPtr m_FamilyFonts; |
| 77 CFX_MapPtrToPtr m_UnicodeFonts; | 134 CFX_MapPtrToPtr m_UnicodeFonts; |
| 78 CFX_MapPtrToPtr m_BufferFonts; | 135 CFX_MapPtrToPtr m_BufferFonts; |
| 79 CFX_MapPtrToPtr m_StreamFonts; | 136 CFX_MapPtrToPtr m_StreamFonts; |
| 80 CFX_MapPtrToPtr m_DeriveFonts; | 137 CFX_MapPtrToPtr m_DeriveFonts; |
| 81 }; | 138 }; |
| 82 uint32_t FX_GetGdiFontStyles(const LOGFONTW& lf); | |
| 83 | 139 |
| 84 #else | 140 #else // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 85 | |
| 86 class CFX_FontDescriptor { | 141 class CFX_FontDescriptor { |
| 87 public: | 142 public: |
| 88 CFX_FontDescriptor(); | 143 CFX_FontDescriptor(); |
| 89 ~CFX_FontDescriptor(); | 144 ~CFX_FontDescriptor(); |
| 90 | 145 |
| 91 int32_t m_nFaceIndex; | 146 int32_t m_nFaceIndex; |
| 92 CFX_WideString m_wsFaceName; | 147 CFX_WideString m_wsFaceName; |
| 93 CFX_WideStringArray m_wsFamilyNames; | 148 CFX_WideStringArray m_wsFamilyNames; |
| 94 uint32_t m_dwFontStyles; | 149 uint32_t m_dwFontStyles; |
| 95 uint32_t m_dwUsb[4]; | 150 uint32_t m_dwUsb[4]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 IFX_FileAccess* GetNext(FX_POSITION& pos); | 190 IFX_FileAccess* GetNext(FX_POSITION& pos); |
| 136 | 191 |
| 137 private: | 192 private: |
| 138 CFX_ByteString GetNextFile(); | 193 CFX_ByteString GetNextFile(); |
| 139 | 194 |
| 140 CFX_WideString m_wsNext; | 195 CFX_WideString m_wsNext; |
| 141 CFX_ObjectArray<FX_HandleParentPath> m_FolderQueue; | 196 CFX_ObjectArray<FX_HandleParentPath> m_FolderQueue; |
| 142 CFX_ByteStringArray m_FolderPaths; | 197 CFX_ByteStringArray m_FolderPaths; |
| 143 }; | 198 }; |
| 144 | 199 |
| 145 class CFGAS_FontMgrImp : public IFGAS_FontMgr { | 200 class CFGAS_FontMgr { |
| 146 public: | 201 public: |
| 147 explicit CFGAS_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum); | 202 explicit CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum); |
| 148 ~CFGAS_FontMgrImp() override; | 203 ~CFGAS_FontMgr(); |
| 204 static std::unique_ptr<CFGAS_FontMgr> Create( |
| 205 CFX_FontSourceEnum_File* pFontEnum); |
| 149 | 206 |
| 150 // IFGAS_FontMgr: | |
| 151 CFGAS_GEFont* GetDefFontByCodePage(uint16_t wCodePage, | |
| 152 uint32_t dwFontStyles, | |
| 153 const FX_WCHAR* pszFontFamily) override; | |
| 154 CFGAS_GEFont* GetDefFontByCharset(uint8_t nCharset, | |
| 155 uint32_t dwFontStyles, | |
| 156 const FX_WCHAR* pszFontFamily) override; | |
| 157 CFGAS_GEFont* GetDefFontByUnicode(FX_WCHAR wUnicode, | |
| 158 uint32_t dwFontStyles, | |
| 159 const FX_WCHAR* pszFontFamily) override; | |
| 160 CFGAS_GEFont* GetDefFontByLanguage(uint16_t wLanguage, | |
| 161 uint32_t dwFontStyles, | |
| 162 const FX_WCHAR* pszFontFamily) override; | |
| 163 CFGAS_GEFont* GetFontByCodePage(uint16_t wCodePage, | 207 CFGAS_GEFont* GetFontByCodePage(uint16_t wCodePage, |
| 164 uint32_t dwFontStyles, | 208 uint32_t dwFontStyles, |
| 165 const FX_WCHAR* pszFontFamily) override; | 209 const FX_WCHAR* pszFontFamily); |
| 166 CFGAS_GEFont* GetFontByCharset(uint8_t nCharset, | |
| 167 uint32_t dwFontStyles, | |
| 168 const FX_WCHAR* pszFontFamily) override; | |
| 169 CFGAS_GEFont* GetFontByUnicode(FX_WCHAR wUnicode, | 210 CFGAS_GEFont* GetFontByUnicode(FX_WCHAR wUnicode, |
| 170 uint32_t dwFontStyles, | 211 uint32_t dwFontStyles, |
| 171 const FX_WCHAR* pszFontFamily) override; | 212 const FX_WCHAR* pszFontFamily); |
| 172 CFGAS_GEFont* GetFontByLanguage(uint16_t wLanguage, | 213 void ClearFontCache(); |
| 173 uint32_t dwFontStyles, | 214 void RemoveFont(CFGAS_GEFont* pFont); |
| 174 const FX_WCHAR* pszFontFamily) override; | |
| 175 void ClearFontCache() override; | |
| 176 void RemoveFont(CFGAS_GEFont* pFont) override; | |
| 177 | 215 |
| 178 CFGAS_GEFont* LoadFont(const CFX_WideString& wsFaceName, | 216 CFGAS_GEFont* LoadFont(const CFX_WideString& wsFaceName, |
| 179 int32_t iFaceIndex, | 217 int32_t iFaceIndex, |
| 180 int32_t* pFaceCount); | 218 int32_t* pFaceCount); |
| 219 inline CFGAS_GEFont* LoadFont(const FX_WCHAR* pszFontFamily, |
| 220 uint32_t dwFontStyles, |
| 221 uint16_t wCodePage) { |
| 222 return GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); |
| 223 } |
| 181 bool EnumFonts(); | 224 bool EnumFonts(); |
| 182 bool EnumFontsFromFontMapper(); | 225 bool EnumFontsFromFontMapper(); |
| 183 bool EnumFontsFromFiles(); | 226 bool EnumFontsFromFiles(); |
| 184 | 227 |
| 185 protected: | 228 private: |
| 186 void RegisterFace(FXFT_Face pFace, | 229 void RegisterFace(FXFT_Face pFace, const CFX_WideString* pFaceName); |
| 187 const CFX_WideString* pFaceName); | |
| 188 void RegisterFaces(IFX_SeekableReadStream* pFontStream, | 230 void RegisterFaces(IFX_SeekableReadStream* pFontStream, |
| 189 const CFX_WideString* pFaceName); | 231 const CFX_WideString* pFaceName); |
| 190 void GetNames(const uint8_t* name_table, CFX_WideStringArray& Names); | 232 void GetNames(const uint8_t* name_table, CFX_WideStringArray& Names); |
| 191 std::vector<uint16_t> GetCharsets(FXFT_Face pFace) const; | 233 std::vector<uint16_t> GetCharsets(FXFT_Face pFace) const; |
| 192 void GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB); | 234 void GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB); |
| 193 uint32_t GetFlags(FXFT_Face pFace); | 235 uint32_t GetFlags(FXFT_Face pFace); |
| 194 bool VerifyUnicode(CFX_FontDescriptor* pDesc, FX_WCHAR wcUnicode); | 236 bool VerifyUnicode(CFX_FontDescriptor* pDesc, FX_WCHAR wcUnicode); |
| 195 bool VerifyUnicode(CFGAS_GEFont* pFont, FX_WCHAR wcUnicode); | 237 bool VerifyUnicode(CFGAS_GEFont* pFont, FX_WCHAR wcUnicode); |
| 196 int32_t IsPartName(const CFX_WideString& Name1, const CFX_WideString& Name2); | 238 int32_t IsPartName(const CFX_WideString& Name1, const CFX_WideString& Name2); |
| 197 int32_t MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, | 239 int32_t MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 212 | 254 |
| 213 CFX_FontDescriptors m_InstalledFonts; | 255 CFX_FontDescriptors m_InstalledFonts; |
| 214 CFX_MapPtrTemplate<uint32_t, CFX_FontDescriptorInfos*> m_Hash2CandidateList; | 256 CFX_MapPtrTemplate<uint32_t, CFX_FontDescriptorInfos*> m_Hash2CandidateList; |
| 215 CFX_MapPtrTemplate<uint32_t, CFX_ArrayTemplate<CFGAS_GEFont*>*> m_Hash2Fonts; | 257 CFX_MapPtrTemplate<uint32_t, CFX_ArrayTemplate<CFGAS_GEFont*>*> m_Hash2Fonts; |
| 216 CFX_MapPtrTemplate<CFGAS_GEFont*, IFX_SeekableReadStream*> m_IFXFont2FileRead; | 258 CFX_MapPtrTemplate<CFGAS_GEFont*, IFX_SeekableReadStream*> m_IFXFont2FileRead; |
| 217 CFX_MapPtrTemplate<FX_WCHAR, CFGAS_GEFont*> m_FailedUnicodes2Nullptr; | 259 CFX_MapPtrTemplate<FX_WCHAR, CFGAS_GEFont*> m_FailedUnicodes2Nullptr; |
| 218 CFX_FontSourceEnum_File* const m_pFontSource; | 260 CFX_FontSourceEnum_File* const m_pFontSource; |
| 219 }; | 261 }; |
| 220 #endif | 262 #endif |
| 221 | 263 |
| 222 #endif // XFA_FGAS_FONT_FGAS_STDFONTMGR_H_ | 264 #endif // XFA_FGAS_FONT_CFGAS_FONTMGR_H_ |
| OLD | NEW |