OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 XFA_SRC_FGAS_FONT_FGAS_STDFONTMGR_H_ | |
8 #define XFA_SRC_FGAS_FONT_FGAS_STDFONTMGR_H_ | |
9 | |
10 #include "core/include/fxcrt/fx_ext.h" | |
11 #include "core/include/fxge/fx_freetype.h" | |
12 #include "core/include/fxge/fx_ge.h" | |
13 #include "third_party/freetype/include/freetype/fttypes.h" | |
14 #include "xfa/src/fgas/font/fgas_font.h" | |
15 | |
16 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | |
17 int32_t FX_GetSimilarValue(FX_LPCFONTDESCRIPTOR pFont, FX_DWORD dwFontStyles); | |
18 FX_LPCFONTDESCRIPTOR FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, | |
19 const CFX_FontDescriptors& fonts, | |
20 void* pUserData); | |
21 | |
22 class CFX_StdFontMgrImp : public IFX_FontMgr { | |
23 public: | |
24 CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator, | |
25 FX_LPMatchFont pMatcher, | |
26 void* pUserData); | |
27 ~CFX_StdFontMgrImp(); | |
28 virtual void Release() { delete this; } | |
29 virtual IFX_Font* GetDefFontByCodePage(FX_WORD wCodePage, | |
30 FX_DWORD dwFontStyles, | |
31 const FX_WCHAR* pszFontFamily = NULL); | |
32 virtual IFX_Font* GetDefFontByCharset(uint8_t nCharset, | |
33 FX_DWORD dwFontStyles, | |
34 const FX_WCHAR* pszFontFamily = NULL); | |
35 virtual IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode, | |
36 FX_DWORD dwFontStyles, | |
37 const FX_WCHAR* pszFontFamily = NULL); | |
38 virtual IFX_Font* GetDefFontByLanguage(FX_WORD wLanguage, | |
39 FX_DWORD dwFontStyles, | |
40 const FX_WCHAR* pszFontFamily = NULL); | |
41 virtual IFX_Font* LoadFont(const FX_WCHAR* pszFontFamily, | |
42 FX_DWORD dwFontStyles, | |
43 FX_WORD wCodePage = 0xFFFF); | |
44 virtual IFX_Font* LoadFont(const uint8_t* pBuffer, int32_t iLength); | |
45 virtual IFX_Font* LoadFont(const FX_WCHAR* pszFileName); | |
46 virtual IFX_Font* LoadFont(IFX_Stream* pFontStream, | |
47 const FX_WCHAR* pszFontAlias = NULL, | |
48 FX_DWORD dwFontStyles = 0, | |
49 FX_WORD wCodePage = 0, | |
50 FX_BOOL bSaveStream = FALSE); | |
51 virtual IFX_Font* LoadFont(IFX_Font* pSrcFont, | |
52 FX_DWORD dwFontStyles, | |
53 FX_WORD wCodePage = 0xFFFF); | |
54 virtual void ClearFontCache(); | |
55 virtual void RemoveFont(IFX_Font* pFont); | |
56 | |
57 protected: | |
58 FX_LPMatchFont m_pMatcher; | |
59 FX_LPEnumAllFonts m_pEnumerator; | |
60 CFX_FontDescriptors m_FontFaces; | |
61 CFX_PtrArray m_Fonts; | |
62 CFX_MapPtrToPtr m_CPFonts; | |
63 CFX_MapPtrToPtr m_FamilyFonts; | |
64 CFX_MapPtrToPtr m_UnicodeFonts; | |
65 CFX_MapPtrToPtr m_BufferFonts; | |
66 CFX_MapPtrToPtr m_FileFonts; | |
67 CFX_MapPtrToPtr m_StreamFonts; | |
68 CFX_MapPtrToPtr m_DeriveFonts; | |
69 void* m_pUserData; | |
70 void RemoveFont(CFX_MapPtrToPtr& fontMap, IFX_Font* pFont); | |
71 FX_LPCFONTDESCRIPTOR FindFont(const FX_WCHAR* pszFontFamily, | |
72 FX_DWORD dwFontStyles, | |
73 FX_DWORD dwMatchFlags, | |
74 FX_WORD wCodePage, | |
75 FX_DWORD dwUSB = 999, | |
76 FX_WCHAR wUnicode = 0); | |
77 IFX_Font* GetFont(FX_LPCFONTDESCRIPTOR pFD, FX_DWORD dwFontStyles); | |
78 }; | |
79 FX_DWORD FX_GetGdiFontStyles(const LOGFONTW& lf); | |
80 | |
81 #else | |
82 | |
83 class CFX_FontDescriptor { | |
84 public: | |
85 CFX_FontDescriptor() | |
86 : m_pFileAccess(NULL), m_nFaceIndex(0), m_dwFontStyles(0) { | |
87 m_dwUsb[0] = m_dwUsb[1] = m_dwUsb[2] = m_dwUsb[3] = 0; | |
88 m_dwCsb[0] = m_dwCsb[1] = 0; | |
89 } | |
90 ~CFX_FontDescriptor() { | |
91 if (NULL != m_pFileAccess) { | |
92 m_pFileAccess->Release(); | |
93 } | |
94 } | |
95 IFX_FileAccess* m_pFileAccess; | |
96 int32_t m_nFaceIndex; | |
97 CFX_WideString m_wsFaceName; | |
98 CFX_WideStringArray m_wsFamilyNames; | |
99 FX_DWORD m_dwFontStyles; | |
100 FX_DWORD m_dwUsb[4]; | |
101 FX_DWORD m_dwCsb[2]; | |
102 }; | |
103 typedef CFX_ArrayTemplate<CFX_FontDescriptor*> CFX_FontDescriptors; | |
104 | |
105 struct FX_FontDescriptorInfo { | |
106 public: | |
107 CFX_FontDescriptor* pFont; | |
108 int32_t nPenalty; | |
109 | |
110 bool operator>(const FX_FontDescriptorInfo& other) const { | |
111 return nPenalty > other.nPenalty; | |
112 } | |
113 bool operator<(const FX_FontDescriptorInfo& other) const { | |
114 return nPenalty < other.nPenalty; | |
115 } | |
116 bool operator==(const FX_FontDescriptorInfo& other) const { | |
117 return nPenalty == other.nPenalty; | |
118 } | |
119 }; | |
120 typedef CFX_ArrayTemplate<FX_FontDescriptorInfo> CFX_FontDescriptorInfos; | |
121 | |
122 struct FX_HandleParentPath { | |
123 FX_HandleParentPath() {} | |
124 FX_HandleParentPath(const FX_HandleParentPath& x) { | |
125 pFileHandle = x.pFileHandle; | |
126 bsParentPath = x.bsParentPath; | |
127 } | |
128 void* pFileHandle; | |
129 CFX_ByteString bsParentPath; | |
130 }; | |
131 | |
132 class CFX_FontSourceEnum_File : public IFX_FontSourceEnum { | |
133 public: | |
134 CFX_FontSourceEnum_File(); | |
135 virtual void Release() { delete this; } | |
136 virtual FX_POSITION GetStartPosition(void* pUserData = NULL); | |
137 virtual IFX_FileAccess* GetNext(FX_POSITION& pos, void* pUserData = NULL); | |
138 | |
139 private: | |
140 CFX_ByteString GetNextFile(); | |
141 CFX_WideString m_wsNext; | |
142 CFX_ObjectArray<FX_HandleParentPath> m_FolderQueue; | |
143 CFX_ByteStringArray m_FolderPaths; | |
144 }; | |
145 typedef CFX_MapPtrTemplate<FX_DWORD, IFX_FileAccess*> CFX_HashFileMap; | |
146 typedef CFX_MapPtrTemplate<FX_DWORD, IFX_Font*> CFX_HashFontMap; | |
147 typedef CFX_MapPtrTemplate<FX_DWORD, CFX_FontDescriptorInfos*> | |
148 CFX_HashFontDescsMap; | |
149 typedef CFX_MapPtrTemplate<FX_DWORD, CFX_ArrayTemplate<IFX_Font*>*> | |
150 CFX_HashFontsMap; | |
151 typedef CFX_MapPtrTemplate<FX_WCHAR, IFX_Font*> CFX_UnicodeFontMap; | |
152 typedef CFX_MapPtrTemplate<IFX_FileAccess*, CFX_ArrayTemplate<IFX_Font*>*> | |
153 CFX_FileFontMap; | |
154 typedef CFX_MapPtrTemplate<IFX_Font*, IFX_FileRead*> CFX_FonStreamtMap; | |
155 | |
156 class CFX_FontMgrImp : public IFX_FontMgr { | |
157 public: | |
158 CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum, | |
159 IFX_FontMgrDelegate* pDelegate = NULL, | |
160 void* pUserData = NULL); | |
161 virtual void Release(); | |
162 virtual IFX_Font* GetDefFontByCodePage(FX_WORD wCodePage, | |
163 FX_DWORD dwFontStyles, | |
164 const FX_WCHAR* pszFontFamily = NULL); | |
165 virtual IFX_Font* GetDefFontByCharset(uint8_t nCharset, | |
166 FX_DWORD dwFontStyles, | |
167 const FX_WCHAR* pszFontFamily = NULL); | |
168 virtual IFX_Font* GetDefFontByUnicode(FX_WCHAR wUnicode, | |
169 FX_DWORD dwFontStyles, | |
170 const FX_WCHAR* pszFontFamily = NULL); | |
171 virtual IFX_Font* GetDefFontByLanguage(FX_WORD wLanguage, | |
172 FX_DWORD dwFontStyles, | |
173 const FX_WCHAR* pszFontFamily = NULL); | |
174 virtual IFX_Font* GetFontByCodePage(FX_WORD wCodePage, | |
175 FX_DWORD dwFontStyles, | |
176 const FX_WCHAR* pszFontFamily = NULL); | |
177 virtual IFX_Font* GetFontByCharset(uint8_t nCharset, | |
178 FX_DWORD dwFontStyles, | |
179 const FX_WCHAR* pszFontFamily = NULL); | |
180 virtual IFX_Font* GetFontByUnicode(FX_WCHAR wUnicode, | |
181 FX_DWORD dwFontStyles, | |
182 const FX_WCHAR* pszFontFamily = NULL); | |
183 virtual IFX_Font* GetFontByLanguage(FX_WORD wLanguage, | |
184 FX_DWORD dwFontStyles, | |
185 const FX_WCHAR* pszFontFamily = NULL); | |
186 virtual IFX_Font* LoadFont(const uint8_t* pBuffer, | |
187 int32_t iLength, | |
188 int32_t iFaceIndex, | |
189 int32_t* pFaceCount); | |
190 virtual IFX_Font* LoadFont(const FX_WCHAR* pszFileName, | |
191 int32_t iFaceIndex, | |
192 int32_t* pFaceCount); | |
193 virtual IFX_Font* LoadFont(IFX_Stream* pFontStream, | |
194 int32_t iFaceIndex, | |
195 int32_t* pFaceCount, | |
196 FX_BOOL bSaveStream = FALSE); | |
197 virtual IFX_Font* LoadFont(const CFX_WideString& wsFaceName, | |
198 int32_t iFaceIndex, | |
199 int32_t* pFaceCount); | |
200 virtual void ClearFontCache(); | |
201 virtual void RemoveFont(IFX_Font* pFont); | |
202 FX_BOOL EnumFonts(); | |
203 FX_BOOL EnumFontsFromFontMapper(); | |
204 FX_BOOL EnumFontsFromFiles(); | |
205 | |
206 protected: | |
207 void RegisterFace(FXFT_Face pFace, | |
208 CFX_FontDescriptors& Fonts, | |
209 const CFX_WideString* pFaceName, | |
210 IFX_FileAccess* pFontAccess); | |
211 void RegisterFaces(IFX_FileRead* pFontStream, | |
212 const CFX_WideString* pFaceName); | |
213 void GetNames(const uint8_t* name_table, CFX_WideStringArray& Names); | |
214 void GetCharsets(FXFT_Face pFace, CFX_WordArray& Charsets); | |
215 void GetUSBCSB(FXFT_Face pFace, FX_DWORD* USB, FX_DWORD* CSB); | |
216 FX_DWORD GetFlags(FXFT_Face pFace); | |
217 CFX_FontDescriptors m_InstalledFonts; | |
218 FX_BOOL VerifyUnicode(CFX_FontDescriptor* pDesc, FX_WCHAR wcUnicode); | |
219 FX_BOOL VerifyUnicode(IFX_Font* pFont, FX_WCHAR wcUnicode); | |
220 int32_t IsPartName(const CFX_WideString& Name1, const CFX_WideString& Name2); | |
221 int32_t MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, | |
222 FX_WORD wCodePage, | |
223 FX_DWORD dwFontStyles, | |
224 const CFX_WideString& FontName, | |
225 FX_WCHAR wcUnicode = 0xFFFE); | |
226 int32_t CalcPenalty(CFX_FontDescriptor* pInstalled, | |
227 FX_WORD wCodePage, | |
228 FX_DWORD dwFontStyles, | |
229 const CFX_WideString& FontName, | |
230 FX_WCHAR wcUnicode = 0xFFFE); | |
231 IFX_Font* LoadFont(IFX_FileAccess* pFontAccess, | |
232 int32_t iFaceIndex, | |
233 int32_t* pFaceCount, | |
234 FX_BOOL bWantCache = FALSE); | |
235 FXFT_Face LoadFace(IFX_FileRead* pFontStream, int32_t iFaceIndex); | |
236 IFX_FileRead* CreateFontStream(CFX_FontMapper* pFontMapper, | |
237 IFX_SystemFontInfo* pSystemFontInfo, | |
238 FX_DWORD index); | |
239 IFX_FileRead* CreateFontStream(const CFX_ByteString& bsFaceName); | |
240 CFX_HashFontDescsMap m_Hash2CandidateList; | |
241 CFX_HashFontsMap m_Hash2Fonts; | |
242 CFX_HashFileMap m_Hash2FileAccess; | |
243 CFX_HashFontMap m_FileAccess2IFXFont; | |
244 CFX_FonStreamtMap m_IFXFont2FileRead; | |
245 CFX_UnicodeFontMap m_FailedUnicodes2NULL; | |
246 IFX_FontSourceEnum* m_pFontSource; | |
247 IFX_FontMgrDelegate* m_pDelegate; | |
248 void* m_pUserData; | |
249 }; | |
250 #endif | |
251 | |
252 #endif // XFA_SRC_FGAS_FONT_FGAS_STDFONTMGR_H_ | |
OLD | NEW |