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 #include "xfa/fgas/font/fgas_stdfontmgr.h" | 7 #include "xfa/fgas/font/fgas_stdfontmgr.h" |
8 | 8 |
9 #include "core/fxcrt/include/fx_stream.h" | 9 #include "core/fxcrt/include/fx_stream.h" |
10 #include "xfa/fgas/crt/fgas_codepage.h" | 10 #include "xfa/fgas/crt/fgas_codepage.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) { | 51 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) { |
52 IFX_Font* pFont = (IFX_Font*)m_Fonts[i]; | 52 IFX_Font* pFont = (IFX_Font*)m_Fonts[i]; |
53 if (pFont != NULL) { | 53 if (pFont != NULL) { |
54 pFont->Release(); | 54 pFont->Release(); |
55 } | 55 } |
56 } | 56 } |
57 m_Fonts.RemoveAll(); | 57 m_Fonts.RemoveAll(); |
58 } | 58 } |
59 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCodePage( | 59 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCodePage( |
60 uint16_t wCodePage, | 60 uint16_t wCodePage, |
61 FX_DWORD dwFontStyles, | 61 uint32_t dwFontStyles, |
62 const FX_WCHAR* pszFontFamily) { | 62 const FX_WCHAR* pszFontFamily) { |
63 FX_DWORD dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 63 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
64 IFX_Font* pFont = NULL; | 64 IFX_Font* pFont = NULL; |
65 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 65 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
66 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; | 66 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; |
67 } | 67 } |
68 FX_LPCFONTDESCRIPTOR pFD; | 68 FX_LPCFONTDESCRIPTOR pFD; |
69 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { | 69 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { |
70 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) { | 70 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) { |
71 if ((pFD = FindFont(NULL, dwFontStyles, FALSE, wCodePage)) == NULL) | 71 if ((pFD = FindFont(NULL, dwFontStyles, FALSE, wCodePage)) == NULL) |
72 return NULL; | 72 return NULL; |
73 } | 73 } |
74 } | 74 } |
75 FXSYS_assert(pFD != NULL); | 75 FXSYS_assert(pFD != NULL); |
76 pFont = IFX_Font::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 76 pFont = IFX_Font::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
77 if (pFont != NULL) { | 77 if (pFont != NULL) { |
78 m_Fonts.Add(pFont); | 78 m_Fonts.Add(pFont); |
79 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 79 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
80 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); | 80 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); |
81 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 81 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
82 return LoadFont(pFont, dwFontStyles, wCodePage); | 82 return LoadFont(pFont, dwFontStyles, wCodePage); |
83 } | 83 } |
84 return NULL; | 84 return NULL; |
85 } | 85 } |
86 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCharset( | 86 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCharset( |
87 uint8_t nCharset, | 87 uint8_t nCharset, |
88 FX_DWORD dwFontStyles, | 88 uint32_t dwFontStyles, |
89 const FX_WCHAR* pszFontFamily) { | 89 const FX_WCHAR* pszFontFamily) { |
90 return GetDefFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, | 90 return GetDefFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, |
91 pszFontFamily); | 91 pszFontFamily); |
92 } | 92 } |
93 | 93 |
94 IFX_Font* CFX_StdFontMgrImp::GetDefFontByUnicode( | 94 IFX_Font* CFX_StdFontMgrImp::GetDefFontByUnicode( |
95 FX_WCHAR wUnicode, | 95 FX_WCHAR wUnicode, |
96 FX_DWORD dwFontStyles, | 96 uint32_t dwFontStyles, |
97 const FX_WCHAR* pszFontFamily) { | 97 const FX_WCHAR* pszFontFamily) { |
98 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); | 98 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); |
99 if (pRet->wBitField == 999) | 99 if (pRet->wBitField == 999) |
100 return nullptr; | 100 return nullptr; |
101 | 101 |
102 FX_DWORD dwHash = | 102 uint32_t dwHash = |
103 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); | 103 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); |
104 IFX_Font* pFont = nullptr; | 104 IFX_Font* pFont = nullptr; |
105 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) | 105 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) |
106 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; | 106 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; |
107 | 107 |
108 FX_LPCFONTDESCRIPTOR pFD = | 108 FX_LPCFONTDESCRIPTOR pFD = |
109 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage, | 109 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage, |
110 pRet->wBitField, wUnicode); | 110 pRet->wBitField, wUnicode); |
111 if (!pFD && pszFontFamily) { | 111 if (!pFD && pszFontFamily) { |
112 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage, | 112 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage, |
(...skipping 12 matching lines...) Expand all Loading... |
125 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 125 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
126 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); | 126 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); |
127 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 127 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
128 return LoadFont(pFont, dwFontStyles, wCodePage); | 128 return LoadFont(pFont, dwFontStyles, wCodePage); |
129 } | 129 } |
130 return nullptr; | 130 return nullptr; |
131 } | 131 } |
132 | 132 |
133 IFX_Font* CFX_StdFontMgrImp::GetDefFontByLanguage( | 133 IFX_Font* CFX_StdFontMgrImp::GetDefFontByLanguage( |
134 uint16_t wLanguage, | 134 uint16_t wLanguage, |
135 FX_DWORD dwFontStyles, | 135 uint32_t dwFontStyles, |
136 const FX_WCHAR* pszFontFamily) { | 136 const FX_WCHAR* pszFontFamily) { |
137 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), | 137 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), |
138 dwFontStyles, pszFontFamily); | 138 dwFontStyles, pszFontFamily); |
139 } | 139 } |
140 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, | 140 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, |
141 FX_DWORD dwFontStyles, | 141 uint32_t dwFontStyles, |
142 uint16_t wCodePage) { | 142 uint16_t wCodePage) { |
143 FX_DWORD dwHash = | 143 uint32_t dwHash = |
144 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); | 144 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); |
145 IFX_Font* pFont = NULL; | 145 IFX_Font* pFont = NULL; |
146 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 146 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
147 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; | 147 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; |
148 } | 148 } |
149 FX_LPCFONTDESCRIPTOR pFD = NULL; | 149 FX_LPCFONTDESCRIPTOR pFD = NULL; |
150 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { | 150 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { |
151 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) == | 151 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) == |
152 NULL) { | 152 NULL) { |
153 return NULL; | 153 return NULL; |
(...skipping 24 matching lines...) Expand all Loading... |
178 pFont = IFX_Font::LoadFont(pBuffer, iLength, this); | 178 pFont = IFX_Font::LoadFont(pBuffer, iLength, this); |
179 if (pFont != NULL) { | 179 if (pFont != NULL) { |
180 m_Fonts.Add(pFont); | 180 m_Fonts.Add(pFont); |
181 m_BufferFonts.SetAt((void*)pBuffer, pFont); | 181 m_BufferFonts.SetAt((void*)pBuffer, pFont); |
182 return pFont->Retain(); | 182 return pFont->Retain(); |
183 } | 183 } |
184 return NULL; | 184 return NULL; |
185 } | 185 } |
186 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { | 186 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { |
187 FXSYS_assert(pszFileName != NULL); | 187 FXSYS_assert(pszFileName != NULL); |
188 FX_DWORD dwHash = FX_HashCode_String_GetW(pszFileName, -1); | 188 uint32_t dwHash = FX_HashCode_String_GetW(pszFileName, -1); |
189 IFX_Font* pFont = NULL; | 189 IFX_Font* pFont = NULL; |
190 if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 190 if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
191 if (pFont != NULL) { | 191 if (pFont != NULL) { |
192 return pFont->Retain(); | 192 return pFont->Retain(); |
193 } | 193 } |
194 } | 194 } |
195 pFont = IFX_Font::LoadFont(pszFileName, NULL); | 195 pFont = IFX_Font::LoadFont(pszFileName, NULL); |
196 if (pFont != NULL) { | 196 if (pFont != NULL) { |
197 m_Fonts.Add(pFont); | 197 m_Fonts.Add(pFont); |
198 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 198 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
199 return pFont->Retain(); | 199 return pFont->Retain(); |
200 } | 200 } |
201 return NULL; | 201 return NULL; |
202 } | 202 } |
203 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, | 203 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, |
204 const FX_WCHAR* pszFontAlias, | 204 const FX_WCHAR* pszFontAlias, |
205 FX_DWORD dwFontStyles, | 205 uint32_t dwFontStyles, |
206 uint16_t wCodePage, | 206 uint16_t wCodePage, |
207 FX_BOOL bSaveStream) { | 207 FX_BOOL bSaveStream) { |
208 FXSYS_assert(pFontStream != NULL && pFontStream->GetLength() > 0); | 208 FXSYS_assert(pFontStream != NULL && pFontStream->GetLength() > 0); |
209 IFX_Font* pFont = NULL; | 209 IFX_Font* pFont = NULL; |
210 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { | 210 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { |
211 if (pFont != NULL) { | 211 if (pFont != NULL) { |
212 if (pszFontAlias != NULL) { | 212 if (pszFontAlias != NULL) { |
213 FX_DWORD dwHash = | 213 uint32_t dwHash = |
214 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); | 214 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); |
215 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 215 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
216 } | 216 } |
217 return LoadFont(pFont, dwFontStyles, wCodePage); | 217 return LoadFont(pFont, dwFontStyles, wCodePage); |
218 } | 218 } |
219 } | 219 } |
220 pFont = IFX_Font::LoadFont(pFontStream, this, bSaveStream); | 220 pFont = IFX_Font::LoadFont(pFontStream, this, bSaveStream); |
221 if (pFont != NULL) { | 221 if (pFont != NULL) { |
222 m_Fonts.Add(pFont); | 222 m_Fonts.Add(pFont); |
223 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); | 223 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); |
224 if (pszFontAlias != NULL) { | 224 if (pszFontAlias != NULL) { |
225 FX_DWORD dwHash = | 225 uint32_t dwHash = |
226 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); | 226 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); |
227 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 227 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
228 } | 228 } |
229 return LoadFont(pFont, dwFontStyles, wCodePage); | 229 return LoadFont(pFont, dwFontStyles, wCodePage); |
230 } | 230 } |
231 return NULL; | 231 return NULL; |
232 } | 232 } |
233 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont, | 233 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont, |
234 FX_DWORD dwFontStyles, | 234 uint32_t dwFontStyles, |
235 uint16_t wCodePage) { | 235 uint16_t wCodePage) { |
236 FXSYS_assert(pSrcFont != NULL); | 236 FXSYS_assert(pSrcFont != NULL); |
237 if (pSrcFont->GetFontStyles() == dwFontStyles) { | 237 if (pSrcFont->GetFontStyles() == dwFontStyles) { |
238 return pSrcFont->Retain(); | 238 return pSrcFont->Retain(); |
239 } | 239 } |
240 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, | 240 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, |
241 (void*)(uintptr_t)wCodePage}; | 241 (void*)(uintptr_t)wCodePage}; |
242 FX_DWORD dwHash = | 242 uint32_t dwHash = |
243 FX_HashCode_String_GetA((const FX_CHAR*)buffer, 3 * sizeof(void*)); | 243 FX_HashCode_String_GetA((const FX_CHAR*)buffer, 3 * sizeof(void*)); |
244 IFX_Font* pFont = NULL; | 244 IFX_Font* pFont = NULL; |
245 if (m_DeriveFonts.GetCount() > 0) { | 245 if (m_DeriveFonts.GetCount() > 0) { |
246 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); | 246 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); |
247 if (pFont != NULL) { | 247 if (pFont != NULL) { |
248 return pFont->Retain(); | 248 return pFont->Retain(); |
249 } | 249 } |
250 } | 250 } |
251 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); | 251 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); |
252 if (pFont != NULL) { | 252 if (pFont != NULL) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 RemoveFont(m_BufferFonts, pFont); | 290 RemoveFont(m_BufferFonts, pFont); |
291 RemoveFont(m_FileFonts, pFont); | 291 RemoveFont(m_FileFonts, pFont); |
292 RemoveFont(m_StreamFonts, pFont); | 292 RemoveFont(m_StreamFonts, pFont); |
293 RemoveFont(m_DeriveFonts, pFont); | 293 RemoveFont(m_DeriveFonts, pFont); |
294 int32_t iFind = m_Fonts.Find(pFont); | 294 int32_t iFind = m_Fonts.Find(pFont); |
295 if (iFind > -1) { | 295 if (iFind > -1) { |
296 m_Fonts.RemoveAt(iFind, 1); | 296 m_Fonts.RemoveAt(iFind, 1); |
297 } | 297 } |
298 } | 298 } |
299 FX_LPCFONTDESCRIPTOR CFX_StdFontMgrImp::FindFont(const FX_WCHAR* pszFontFamily, | 299 FX_LPCFONTDESCRIPTOR CFX_StdFontMgrImp::FindFont(const FX_WCHAR* pszFontFamily, |
300 FX_DWORD dwFontStyles, | 300 uint32_t dwFontStyles, |
301 FX_DWORD dwMatchFlags, | 301 uint32_t dwMatchFlags, |
302 uint16_t wCodePage, | 302 uint16_t wCodePage, |
303 FX_DWORD dwUSB, | 303 uint32_t dwUSB, |
304 FX_WCHAR wUnicode) { | 304 FX_WCHAR wUnicode) { |
305 if (m_pMatcher == NULL) { | 305 if (m_pMatcher == NULL) { |
306 return NULL; | 306 return NULL; |
307 } | 307 } |
308 FX_FONTMATCHPARAMS params; | 308 FX_FONTMATCHPARAMS params; |
309 FXSYS_memset(¶ms, 0, sizeof(params)); | 309 FXSYS_memset(¶ms, 0, sizeof(params)); |
310 params.dwUSB = dwUSB; | 310 params.dwUSB = dwUSB; |
311 params.wUnicode = wUnicode; | 311 params.wUnicode = wUnicode; |
312 params.wCodePage = wCodePage; | 312 params.wCodePage = wCodePage; |
313 params.pwsFamily = pszFontFamily; | 313 params.pwsFamily = pszFontFamily; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 } | 360 } |
361 if (pFont->uCharSet == FX_CHARSET_Symbol) { | 361 if (pFont->uCharSet == FX_CHARSET_Symbol) { |
362 continue; | 362 continue; |
363 } | 363 } |
364 if (pParams->wCodePage != 0xFFFF) { | 364 if (pParams->wCodePage != 0xFFFF) { |
365 if (FX_GetCodePageFromCharset(pFont->uCharSet) != pParams->wCodePage) { | 365 if (FX_GetCodePageFromCharset(pFont->uCharSet) != pParams->wCodePage) { |
366 continue; | 366 continue; |
367 } | 367 } |
368 } else { | 368 } else { |
369 if (pParams->dwUSB < 128) { | 369 if (pParams->dwUSB < 128) { |
370 FX_DWORD dwByte = pParams->dwUSB / 32; | 370 uint32_t dwByte = pParams->dwUSB / 32; |
371 FX_DWORD dwUSB = 1 << (pParams->dwUSB % 32); | 371 uint32_t dwUSB = 1 << (pParams->dwUSB % 32); |
372 if ((pFont->FontSignature.fsUsb[dwByte] & dwUSB) == 0) { | 372 if ((pFont->FontSignature.fsUsb[dwByte] & dwUSB) == 0) { |
373 continue; | 373 continue; |
374 } | 374 } |
375 } | 375 } |
376 } | 376 } |
377 if (bMatchStyle) { | 377 if (bMatchStyle) { |
378 if ((pFont->dwFontStyles & 0x0F) == (pParams->dwFontStyles & 0x0F)) { | 378 if ((pFont->dwFontStyles & 0x0F) == (pParams->dwFontStyles & 0x0F)) { |
379 return pFont; | 379 return pFont; |
380 } else { | 380 } else { |
381 continue; | 381 continue; |
382 } | 382 } |
383 } | 383 } |
384 if (pParams->pwsFamily != NULL) { | 384 if (pParams->pwsFamily != NULL) { |
385 if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace) == 0) { | 385 if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace) == 0) { |
386 return pFont; | 386 return pFont; |
387 } | 387 } |
388 } | 388 } |
389 int32_t iSimilarValue = FX_GetSimilarValue(pFont, pParams->dwFontStyles); | 389 int32_t iSimilarValue = FX_GetSimilarValue(pFont, pParams->dwFontStyles); |
390 if (iBestSimilar < iSimilarValue) { | 390 if (iBestSimilar < iSimilarValue) { |
391 iBestSimilar = iSimilarValue; | 391 iBestSimilar = iSimilarValue; |
392 pBestFont = pFont; | 392 pBestFont = pFont; |
393 } | 393 } |
394 } | 394 } |
395 return iBestSimilar < 1 ? NULL : pBestFont; | 395 return iBestSimilar < 1 ? NULL : pBestFont; |
396 } | 396 } |
397 int32_t FX_GetSimilarValue(FX_LPCFONTDESCRIPTOR pFont, FX_DWORD dwFontStyles) { | 397 int32_t FX_GetSimilarValue(FX_LPCFONTDESCRIPTOR pFont, uint32_t dwFontStyles) { |
398 int32_t iValue = 0; | 398 int32_t iValue = 0; |
399 if ((dwFontStyles & FX_FONTSTYLE_Symbolic) == | 399 if ((dwFontStyles & FX_FONTSTYLE_Symbolic) == |
400 (pFont->dwFontStyles & FX_FONTSTYLE_Symbolic)) { | 400 (pFont->dwFontStyles & FX_FONTSTYLE_Symbolic)) { |
401 iValue += 64; | 401 iValue += 64; |
402 } | 402 } |
403 if ((dwFontStyles & FX_FONTSTYLE_FixedPitch) == | 403 if ((dwFontStyles & FX_FONTSTYLE_FixedPitch) == |
404 (pFont->dwFontStyles & FX_FONTSTYLE_FixedPitch)) { | 404 (pFont->dwFontStyles & FX_FONTSTYLE_FixedPitch)) { |
405 iValue += 32; | 405 iValue += 32; |
406 } | 406 } |
407 if ((dwFontStyles & FX_FONTSTYLE_Serif) == | 407 if ((dwFontStyles & FX_FONTSTYLE_Serif) == |
408 (pFont->dwFontStyles & FX_FONTSTYLE_Serif)) { | 408 (pFont->dwFontStyles & FX_FONTSTYLE_Serif)) { |
409 iValue += 16; | 409 iValue += 16; |
410 } | 410 } |
411 if ((dwFontStyles & FX_FONTSTYLE_Script) == | 411 if ((dwFontStyles & FX_FONTSTYLE_Script) == |
412 (pFont->dwFontStyles & FX_FONTSTYLE_Script)) { | 412 (pFont->dwFontStyles & FX_FONTSTYLE_Script)) { |
413 iValue += 8; | 413 iValue += 8; |
414 } | 414 } |
415 return iValue; | 415 return iValue; |
416 } | 416 } |
417 FX_LPMatchFont FX_GetDefFontMatchor() { | 417 FX_LPMatchFont FX_GetDefFontMatchor() { |
418 return FX_DefFontMatcher; | 418 return FX_DefFontMatcher; |
419 } | 419 } |
420 FX_DWORD FX_GetGdiFontStyles(const LOGFONTW& lf) { | 420 uint32_t FX_GetGdiFontStyles(const LOGFONTW& lf) { |
421 FX_DWORD dwStyles = 0; | 421 uint32_t dwStyles = 0; |
422 if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) { | 422 if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) { |
423 dwStyles |= FX_FONTSTYLE_FixedPitch; | 423 dwStyles |= FX_FONTSTYLE_FixedPitch; |
424 } | 424 } |
425 uint8_t nFamilies = lf.lfPitchAndFamily & 0xF0; | 425 uint8_t nFamilies = lf.lfPitchAndFamily & 0xF0; |
426 if (nFamilies == FF_ROMAN) { | 426 if (nFamilies == FF_ROMAN) { |
427 dwStyles |= FX_FONTSTYLE_Serif; | 427 dwStyles |= FX_FONTSTYLE_Serif; |
428 } | 428 } |
429 if (nFamilies == FF_SCRIPT) { | 429 if (nFamilies == FF_SCRIPT) { |
430 dwStyles |= FX_FONTSTYLE_Script; | 430 dwStyles |= FX_FONTSTYLE_Script; |
431 } | 431 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 if (EnumFontsFromFontMapper()) | 637 if (EnumFontsFromFontMapper()) |
638 return TRUE; | 638 return TRUE; |
639 return EnumFontsFromFiles(); | 639 return EnumFontsFromFiles(); |
640 } | 640 } |
641 void CFX_FontMgrImp::Release() { | 641 void CFX_FontMgrImp::Release() { |
642 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) { | 642 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) { |
643 delete m_InstalledFonts[i]; | 643 delete m_InstalledFonts[i]; |
644 } | 644 } |
645 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 645 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
646 while (pos) { | 646 while (pos) { |
647 FX_DWORD dwHash; | 647 uint32_t dwHash; |
648 CFX_FontDescriptorInfos* pDescs; | 648 CFX_FontDescriptorInfos* pDescs; |
649 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 649 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
650 if (NULL != pDescs) { | 650 if (NULL != pDescs) { |
651 delete pDescs; | 651 delete pDescs; |
652 } | 652 } |
653 } | 653 } |
654 pos = m_Hash2Fonts.GetStartPosition(); | 654 pos = m_Hash2Fonts.GetStartPosition(); |
655 while (pos) { | 655 while (pos) { |
656 FX_DWORD dwHash; | 656 uint32_t dwHash; |
657 CFX_ArrayTemplate<IFX_Font*>* pFonts; | 657 CFX_ArrayTemplate<IFX_Font*>* pFonts; |
658 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 658 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
659 if (NULL != pFonts) { | 659 if (NULL != pFonts) { |
660 delete pFonts; | 660 delete pFonts; |
661 } | 661 } |
662 } | 662 } |
663 m_Hash2Fonts.RemoveAll(); | 663 m_Hash2Fonts.RemoveAll(); |
664 pos = m_Hash2FileAccess.GetStartPosition(); | 664 pos = m_Hash2FileAccess.GetStartPosition(); |
665 while (pos) { | 665 while (pos) { |
666 FX_DWORD dwHash; | 666 uint32_t dwHash; |
667 IFX_FileAccess* pFileAccess; | 667 IFX_FileAccess* pFileAccess; |
668 m_Hash2FileAccess.GetNextAssoc(pos, dwHash, pFileAccess); | 668 m_Hash2FileAccess.GetNextAssoc(pos, dwHash, pFileAccess); |
669 if (NULL != pFileAccess) { | 669 if (NULL != pFileAccess) { |
670 pFileAccess->Release(); | 670 pFileAccess->Release(); |
671 } | 671 } |
672 } | 672 } |
673 pos = m_FileAccess2IFXFont.GetStartPosition(); | 673 pos = m_FileAccess2IFXFont.GetStartPosition(); |
674 while (pos) { | 674 while (pos) { |
675 FX_DWORD dwHash; | 675 uint32_t dwHash; |
676 IFX_Font* pFont; | 676 IFX_Font* pFont; |
677 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); | 677 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); |
678 if (NULL != pFont) { | 678 if (NULL != pFont) { |
679 pFont->Release(); | 679 pFont->Release(); |
680 } | 680 } |
681 } | 681 } |
682 pos = m_IFXFont2FileRead.GetStartPosition(); | 682 pos = m_IFXFont2FileRead.GetStartPosition(); |
683 while (pos) { | 683 while (pos) { |
684 IFX_Font* pFont; | 684 IFX_Font* pFont; |
685 IFX_FileRead* pFileRead; | 685 IFX_FileRead* pFileRead; |
686 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 686 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
687 pFileRead->Release(); | 687 pFileRead->Release(); |
688 } | 688 } |
689 delete this; | 689 delete this; |
690 } | 690 } |
691 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage, | 691 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage, |
692 FX_DWORD dwFontStyles, | 692 uint32_t dwFontStyles, |
693 const FX_WCHAR* pszFontFamily) { | 693 const FX_WCHAR* pszFontFamily) { |
694 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByCodePage( | 694 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByCodePage( |
695 this, wCodePage, dwFontStyles, | 695 this, wCodePage, dwFontStyles, |
696 pszFontFamily); | 696 pszFontFamily); |
697 } | 697 } |
698 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset, | 698 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset, |
699 FX_DWORD dwFontStyles, | 699 uint32_t dwFontStyles, |
700 const FX_WCHAR* pszFontFamily) { | 700 const FX_WCHAR* pszFontFamily) { |
701 return NULL == m_pDelegate ? NULL | 701 return NULL == m_pDelegate ? NULL |
702 : m_pDelegate->GetDefFontByCharset( | 702 : m_pDelegate->GetDefFontByCharset( |
703 this, nCharset, dwFontStyles, pszFontFamily); | 703 this, nCharset, dwFontStyles, pszFontFamily); |
704 } | 704 } |
705 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode, | 705 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode, |
706 FX_DWORD dwFontStyles, | 706 uint32_t dwFontStyles, |
707 const FX_WCHAR* pszFontFamily) { | 707 const FX_WCHAR* pszFontFamily) { |
708 return NULL == m_pDelegate ? NULL | 708 return NULL == m_pDelegate ? NULL |
709 : m_pDelegate->GetDefFontByUnicode( | 709 : m_pDelegate->GetDefFontByUnicode( |
710 this, wUnicode, dwFontStyles, pszFontFamily); | 710 this, wUnicode, dwFontStyles, pszFontFamily); |
711 } | 711 } |
712 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage, | 712 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage, |
713 FX_DWORD dwFontStyles, | 713 uint32_t dwFontStyles, |
714 const FX_WCHAR* pszFontFamily) { | 714 const FX_WCHAR* pszFontFamily) { |
715 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByLanguage( | 715 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByLanguage( |
716 this, wLanguage, dwFontStyles, | 716 this, wLanguage, dwFontStyles, |
717 pszFontFamily); | 717 pszFontFamily); |
718 } | 718 } |
719 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, | 719 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, |
720 FX_DWORD dwFontStyles, | 720 uint32_t dwFontStyles, |
721 const FX_WCHAR* pszFontFamily) { | 721 const FX_WCHAR* pszFontFamily) { |
722 CFX_ByteString bsHash; | 722 CFX_ByteString bsHash; |
723 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 723 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
724 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 724 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
725 FX_DWORD dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); | 725 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); |
726 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL; | 726 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL; |
727 IFX_Font* pFont = NULL; | 727 IFX_Font* pFont = NULL; |
728 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { | 728 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { |
729 if (NULL == pFonts) { | 729 if (NULL == pFonts) { |
730 return NULL; | 730 return NULL; |
731 } | 731 } |
732 if (0 != pFonts->GetSize()) { | 732 if (0 != pFonts->GetSize()) { |
733 return pFonts->GetAt(0)->Retain(); | 733 return pFonts->GetAt(0)->Retain(); |
734 } | 734 } |
735 } | 735 } |
(...skipping 15 matching lines...) Expand all Loading... |
751 pFont = LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr); | 751 pFont = LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr); |
752 else | 752 else |
753 pFont = LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); | 753 pFont = LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); |
754 if (NULL != pFont) { | 754 if (NULL != pFont) { |
755 pFont->SetLogicalFontStyle(dwFontStyles); | 755 pFont->SetLogicalFontStyle(dwFontStyles); |
756 } | 756 } |
757 pFonts->Add(pFont); | 757 pFonts->Add(pFont); |
758 return pFont; | 758 return pFont; |
759 } | 759 } |
760 IFX_Font* CFX_FontMgrImp::GetFontByCharset(uint8_t nCharset, | 760 IFX_Font* CFX_FontMgrImp::GetFontByCharset(uint8_t nCharset, |
761 FX_DWORD dwFontStyles, | 761 uint32_t dwFontStyles, |
762 const FX_WCHAR* pszFontFamily) { | 762 const FX_WCHAR* pszFontFamily) { |
763 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, | 763 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, |
764 pszFontFamily); | 764 pszFontFamily); |
765 } | 765 } |
766 IFX_Font* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode, | 766 IFX_Font* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode, |
767 FX_DWORD dwFontStyles, | 767 uint32_t dwFontStyles, |
768 const FX_WCHAR* pszFontFamily) { | 768 const FX_WCHAR* pszFontFamily) { |
769 IFX_Font* pFont = nullptr; | 769 IFX_Font* pFont = nullptr; |
770 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont)) | 770 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont)) |
771 return nullptr; | 771 return nullptr; |
772 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); | 772 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); |
773 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; | 773 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; |
774 uint16_t wBitField = x ? x->wBitField : 0x03E7; | 774 uint16_t wBitField = x ? x->wBitField : 0x03E7; |
775 CFX_ByteString bsHash; | 775 CFX_ByteString bsHash; |
776 if (wCodePage == 0xFFFF) | 776 if (wCodePage == 0xFFFF) |
777 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); | 777 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); |
778 else | 778 else |
779 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 779 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
780 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 780 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
781 FX_DWORD dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); | 781 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); |
782 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; | 782 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; |
783 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { | 783 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { |
784 if (!pFonts) | 784 if (!pFonts) |
785 return nullptr; | 785 return nullptr; |
786 for (int32_t i = 0; i < pFonts->GetSize(); ++i) { | 786 for (int32_t i = 0; i < pFonts->GetSize(); ++i) { |
787 if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) | 787 if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) |
788 return pFonts->GetAt(i)->Retain(); | 788 return pFonts->GetAt(i)->Retain(); |
789 } | 789 } |
790 } | 790 } |
791 if (!pFonts) | 791 if (!pFonts) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 if (0 != FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE)) { | 845 if (0 != FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE)) { |
846 return FALSE; | 846 return FALSE; |
847 } | 847 } |
848 if (0 == FXFT_Get_Char_Index(pFace, wcUnicode)) { | 848 if (0 == FXFT_Get_Char_Index(pFace, wcUnicode)) { |
849 FXFT_Set_Charmap(pFace, charmap); | 849 FXFT_Set_Charmap(pFace, charmap); |
850 return FALSE; | 850 return FALSE; |
851 } | 851 } |
852 return TRUE; | 852 return TRUE; |
853 } | 853 } |
854 IFX_Font* CFX_FontMgrImp::GetFontByLanguage(uint16_t wLanguage, | 854 IFX_Font* CFX_FontMgrImp::GetFontByLanguage(uint16_t wLanguage, |
855 FX_DWORD dwFontStyles, | 855 uint32_t dwFontStyles, |
856 const FX_WCHAR* pszFontFamily) { | 856 const FX_WCHAR* pszFontFamily) { |
857 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, | 857 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, |
858 pszFontFamily); | 858 pszFontFamily); |
859 } | 859 } |
860 IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer, | 860 IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer, |
861 int32_t iLength, | 861 int32_t iLength, |
862 int32_t iFaceIndex, | 862 int32_t iFaceIndex, |
863 int32_t* pFaceCount) { | 863 int32_t* pFaceCount) { |
864 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; | 864 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; |
865 FX_DWORD dwHash = | 865 uint32_t dwHash = |
866 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 2 * sizeof(void*)); | 866 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 2 * sizeof(void*)); |
867 IFX_FileAccess* pFontAccess = NULL; | 867 IFX_FileAccess* pFontAccess = NULL; |
868 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { | 868 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { |
869 } | 869 } |
870 if (NULL != pFontAccess) { | 870 if (NULL != pFontAccess) { |
871 return LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE); | 871 return LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE); |
872 } else { | 872 } else { |
873 return NULL; | 873 return NULL; |
874 } | 874 } |
875 } | 875 } |
876 IFX_Font* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, | 876 IFX_Font* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, |
877 int32_t iFaceIndex, | 877 int32_t iFaceIndex, |
878 int32_t* pFaceCount) { | 878 int32_t* pFaceCount) { |
879 CFX_ByteString bsHash; | 879 CFX_ByteString bsHash; |
880 bsHash += CFX_WideString(pszFileName).UTF8Encode(); | 880 bsHash += CFX_WideString(pszFileName).UTF8Encode(); |
881 FX_DWORD dwHash = | 881 uint32_t dwHash = |
882 FX_HashCode_String_GetA((const FX_CHAR*)bsHash, bsHash.GetLength()); | 882 FX_HashCode_String_GetA((const FX_CHAR*)bsHash, bsHash.GetLength()); |
883 IFX_FileAccess* pFontAccess = NULL; | 883 IFX_FileAccess* pFontAccess = NULL; |
884 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { | 884 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { |
885 pFontAccess = FX_CreateDefaultFileAccess(pszFileName); | 885 pFontAccess = FX_CreateDefaultFileAccess(pszFileName); |
886 m_Hash2FileAccess.SetAt(dwHash, pFontAccess); | 886 m_Hash2FileAccess.SetAt(dwHash, pFontAccess); |
887 } | 887 } |
888 if (NULL != pFontAccess) { | 888 if (NULL != pFontAccess) { |
889 return LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE); | 889 return LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE); |
890 } else { | 890 } else { |
891 return NULL; | 891 return NULL; |
892 } | 892 } |
893 } | 893 } |
894 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream, | 894 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream, |
895 int32_t iFaceIndex, | 895 int32_t iFaceIndex, |
896 int32_t* pFaceCount, | 896 int32_t* pFaceCount, |
897 FX_BOOL bSaveStream) { | 897 FX_BOOL bSaveStream) { |
898 void* Hash[1] = {(void*)(uintptr_t)pFontStream}; | 898 void* Hash[1] = {(void*)(uintptr_t)pFontStream}; |
899 FX_DWORD dwHash = | 899 uint32_t dwHash = |
900 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 1 * sizeof(void*)); | 900 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 1 * sizeof(void*)); |
901 IFX_FileAccess* pFontAccess = NULL; | 901 IFX_FileAccess* pFontAccess = NULL; |
902 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { | 902 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { |
903 } | 903 } |
904 if (NULL != pFontAccess) { | 904 if (NULL != pFontAccess) { |
905 return LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE); | 905 return LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE); |
906 } else { | 906 } else { |
907 return NULL; | 907 return NULL; |
908 } | 908 } |
909 } | 909 } |
910 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, | 910 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, |
911 int32_t iFaceIndex, | 911 int32_t iFaceIndex, |
912 int32_t* pFaceCount, | 912 int32_t* pFaceCount, |
913 FX_BOOL bWantCache) { | 913 FX_BOOL bWantCache) { |
914 FX_DWORD dwHash = 0; | 914 uint32_t dwHash = 0; |
915 IFX_Font* pFont = NULL; | 915 IFX_Font* pFont = NULL; |
916 if (bWantCache) { | 916 if (bWantCache) { |
917 CFX_ByteString bsHash; | 917 CFX_ByteString bsHash; |
918 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); | 918 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); |
919 dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); | 919 dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); |
920 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { | 920 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { |
921 if (NULL != pFont) { | 921 if (NULL != pFont) { |
922 if (NULL != pFaceCount) { | 922 if (NULL != pFaceCount) { |
923 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; | 923 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; |
924 } | 924 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 return nullptr; | 1034 return nullptr; |
1035 } | 1035 } |
1036 | 1036 |
1037 FXFT_Set_Pixel_Sizes(pFace, 0, 64); | 1037 FXFT_Set_Pixel_Sizes(pFace, 0, 64); |
1038 return pFace; | 1038 return pFace; |
1039 } | 1039 } |
1040 | 1040 |
1041 IFX_FileRead* CFX_FontMgrImp::CreateFontStream( | 1041 IFX_FileRead* CFX_FontMgrImp::CreateFontStream( |
1042 CFX_FontMapper* pFontMapper, | 1042 CFX_FontMapper* pFontMapper, |
1043 IFX_SystemFontInfo* pSystemFontInfo, | 1043 IFX_SystemFontInfo* pSystemFontInfo, |
1044 FX_DWORD index) { | 1044 uint32_t index) { |
1045 int iExact = 0; | 1045 int iExact = 0; |
1046 void* hFont = pSystemFontInfo->MapFont( | 1046 void* hFont = pSystemFontInfo->MapFont( |
1047 0, 0, FXFONT_DEFAULT_CHARSET, 0, pFontMapper->GetFaceName(index), iExact); | 1047 0, 0, FXFONT_DEFAULT_CHARSET, 0, pFontMapper->GetFaceName(index), iExact); |
1048 if (!hFont) | 1048 if (!hFont) |
1049 return nullptr; | 1049 return nullptr; |
1050 FX_DWORD dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0); | 1050 uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0); |
1051 if (dwFileSize == 0) | 1051 if (dwFileSize == 0) |
1052 return nullptr; | 1052 return nullptr; |
1053 uint8_t* pBuffer = FX_Alloc(uint8_t, dwFileSize + 1); | 1053 uint8_t* pBuffer = FX_Alloc(uint8_t, dwFileSize + 1); |
1054 dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, pBuffer, dwFileSize); | 1054 dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, pBuffer, dwFileSize); |
1055 return FX_CreateMemoryStream(pBuffer, dwFileSize, TRUE); | 1055 return FX_CreateMemoryStream(pBuffer, dwFileSize, TRUE); |
1056 } | 1056 } |
1057 | 1057 |
1058 IFX_FileRead* CFX_FontMgrImp::CreateFontStream( | 1058 IFX_FileRead* CFX_FontMgrImp::CreateFontStream( |
1059 const CFX_ByteString& bsFaceName) { | 1059 const CFX_ByteString& bsFaceName) { |
1060 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 1060 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
1061 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | 1061 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
1062 if (!pFontMapper) | 1062 if (!pFontMapper) |
1063 return nullptr; | 1063 return nullptr; |
1064 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 1064 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
1065 if (!pSystemFontInfo) | 1065 if (!pSystemFontInfo) |
1066 return nullptr; | 1066 return nullptr; |
1067 pSystemFontInfo->EnumFontList(pFontMapper); | 1067 pSystemFontInfo->EnumFontList(pFontMapper); |
1068 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { | 1068 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { |
1069 if (pFontMapper->GetFaceName(i) == bsFaceName) | 1069 if (pFontMapper->GetFaceName(i) == bsFaceName) |
1070 return CreateFontStream(pFontMapper, pSystemFontInfo, i); | 1070 return CreateFontStream(pFontMapper, pSystemFontInfo, i); |
1071 } | 1071 } |
1072 return nullptr; | 1072 return nullptr; |
1073 } | 1073 } |
1074 int32_t CFX_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, | 1074 int32_t CFX_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, |
1075 uint16_t wCodePage, | 1075 uint16_t wCodePage, |
1076 FX_DWORD dwFontStyles, | 1076 uint32_t dwFontStyles, |
1077 const CFX_WideString& FontName, | 1077 const CFX_WideString& FontName, |
1078 FX_WCHAR wcUnicode) { | 1078 FX_WCHAR wcUnicode) { |
1079 MatchedFonts.RemoveAll(); | 1079 MatchedFonts.RemoveAll(); |
1080 CFX_WideString wsNormalizedFontName = FontName; | 1080 CFX_WideString wsNormalizedFontName = FontName; |
1081 static const int32_t nMax = 0xffff; | 1081 static const int32_t nMax = 0xffff; |
1082 CFX_FontDescriptor* pFont = NULL; | 1082 CFX_FontDescriptor* pFont = NULL; |
1083 int32_t nCount = m_InstalledFonts.GetSize(); | 1083 int32_t nCount = m_InstalledFonts.GetSize(); |
1084 for (int32_t i = 0; i < nCount; i++) { | 1084 for (int32_t i = 0; i < nCount; i++) { |
1085 pFont = m_InstalledFonts[i]; | 1085 pFont = m_InstalledFonts[i]; |
1086 int32_t nPenalty = CalcPenalty(pFont, wCodePage, dwFontStyles, | 1086 int32_t nPenalty = CalcPenalty(pFont, wCodePage, dwFontStyles, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 return (uint16_t)-1; | 1129 return (uint16_t)-1; |
1130 } | 1130 } |
1131 | 1131 |
1132 uint16_t FX_GetUnicodeBit(FX_WCHAR wcUnicode) { | 1132 uint16_t FX_GetUnicodeBit(FX_WCHAR wcUnicode) { |
1133 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wcUnicode); | 1133 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wcUnicode); |
1134 return x ? x->wBitField : 999; | 1134 return x ? x->wBitField : 999; |
1135 } | 1135 } |
1136 | 1136 |
1137 int32_t CFX_FontMgrImp::CalcPenalty(CFX_FontDescriptor* pInstalled, | 1137 int32_t CFX_FontMgrImp::CalcPenalty(CFX_FontDescriptor* pInstalled, |
1138 uint16_t wCodePage, | 1138 uint16_t wCodePage, |
1139 FX_DWORD dwFontStyles, | 1139 uint32_t dwFontStyles, |
1140 const CFX_WideString& FontName, | 1140 const CFX_WideString& FontName, |
1141 FX_WCHAR wcUnicode) { | 1141 FX_WCHAR wcUnicode) { |
1142 int32_t nPenalty = 30000; | 1142 int32_t nPenalty = 30000; |
1143 if (0 != FontName.GetLength()) { | 1143 if (0 != FontName.GetLength()) { |
1144 if (FontName != pInstalled->m_wsFaceName) { | 1144 if (FontName != pInstalled->m_wsFaceName) { |
1145 int32_t i; | 1145 int32_t i; |
1146 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { | 1146 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { |
1147 if (pInstalled->m_wsFamilyNames[i] == FontName) { | 1147 if (pInstalled->m_wsFamilyNames[i] == FontName) { |
1148 break; | 1148 break; |
1149 } | 1149 } |
(...skipping 16 matching lines...) Expand all Loading... |
1166 } | 1166 } |
1167 if (i == pInstalled->m_wsFamilyNames.GetSize()) { | 1167 if (i == pInstalled->m_wsFamilyNames.GetSize()) { |
1168 nPenalty += 0xFFFF; | 1168 nPenalty += 0xFFFF; |
1169 } else { | 1169 } else { |
1170 nPenalty -= 26000; | 1170 nPenalty -= 26000; |
1171 } | 1171 } |
1172 } else { | 1172 } else { |
1173 nPenalty -= 27000; | 1173 nPenalty -= 27000; |
1174 } | 1174 } |
1175 } | 1175 } |
1176 FX_DWORD dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; | 1176 uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; |
1177 if (dwStyleMask & FX_FONTSTYLE_Bold) { | 1177 if (dwStyleMask & FX_FONTSTYLE_Bold) { |
1178 nPenalty += 4500; | 1178 nPenalty += 4500; |
1179 } | 1179 } |
1180 if (dwStyleMask & FX_FONTSTYLE_FixedPitch) { | 1180 if (dwStyleMask & FX_FONTSTYLE_FixedPitch) { |
1181 nPenalty += 10000; | 1181 nPenalty += 10000; |
1182 } | 1182 } |
1183 if (dwStyleMask & FX_FONTSTYLE_Italic) { | 1183 if (dwStyleMask & FX_FONTSTYLE_Italic) { |
1184 nPenalty += 10000; | 1184 nPenalty += 10000; |
1185 } | 1185 } |
1186 if (dwStyleMask & FX_FONTSTYLE_Serif) { | 1186 if (dwStyleMask & FX_FONTSTYLE_Serif) { |
(...skipping 25 matching lines...) Expand all Loading... |
1212 nPenalty += 0xFFFF; | 1212 nPenalty += 0xFFFF; |
1213 } else { | 1213 } else { |
1214 nPenalty -= 60000; | 1214 nPenalty -= 60000; |
1215 } | 1215 } |
1216 } | 1216 } |
1217 return nPenalty; | 1217 return nPenalty; |
1218 } | 1218 } |
1219 void CFX_FontMgrImp::ClearFontCache() { | 1219 void CFX_FontMgrImp::ClearFontCache() { |
1220 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 1220 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
1221 while (pos) { | 1221 while (pos) { |
1222 FX_DWORD dwHash; | 1222 uint32_t dwHash; |
1223 CFX_FontDescriptorInfos* pDescs; | 1223 CFX_FontDescriptorInfos* pDescs; |
1224 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 1224 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
1225 if (NULL != pDescs) { | 1225 if (NULL != pDescs) { |
1226 delete pDescs; | 1226 delete pDescs; |
1227 } | 1227 } |
1228 } | 1228 } |
1229 pos = m_FileAccess2IFXFont.GetStartPosition(); | 1229 pos = m_FileAccess2IFXFont.GetStartPosition(); |
1230 while (pos) { | 1230 while (pos) { |
1231 FX_DWORD dwHash; | 1231 uint32_t dwHash; |
1232 IFX_Font* pFont; | 1232 IFX_Font* pFont; |
1233 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); | 1233 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); |
1234 if (NULL != pFont) { | 1234 if (NULL != pFont) { |
1235 pFont->Release(); | 1235 pFont->Release(); |
1236 } | 1236 } |
1237 } | 1237 } |
1238 pos = m_IFXFont2FileRead.GetStartPosition(); | 1238 pos = m_IFXFont2FileRead.GetStartPosition(); |
1239 while (pos) { | 1239 while (pos) { |
1240 IFX_Font* pFont; | 1240 IFX_Font* pFont; |
1241 IFX_FileRead* pFileRead; | 1241 IFX_FileRead* pFileRead; |
1242 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 1242 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
1243 pFileRead->Release(); | 1243 pFileRead->Release(); |
1244 } | 1244 } |
1245 } | 1245 } |
1246 void CFX_FontMgrImp::RemoveFont(IFX_Font* pEFont) { | 1246 void CFX_FontMgrImp::RemoveFont(IFX_Font* pEFont) { |
1247 if (NULL == pEFont) { | 1247 if (NULL == pEFont) { |
1248 return; | 1248 return; |
1249 } | 1249 } |
1250 IFX_FileRead* pFileRead; | 1250 IFX_FileRead* pFileRead; |
1251 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { | 1251 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { |
1252 pFileRead->Release(); | 1252 pFileRead->Release(); |
1253 m_IFXFont2FileRead.RemoveKey(pEFont); | 1253 m_IFXFont2FileRead.RemoveKey(pEFont); |
1254 } | 1254 } |
1255 FX_POSITION pos; | 1255 FX_POSITION pos; |
1256 pos = m_FileAccess2IFXFont.GetStartPosition(); | 1256 pos = m_FileAccess2IFXFont.GetStartPosition(); |
1257 while (pos) { | 1257 while (pos) { |
1258 FX_DWORD dwHash; | 1258 uint32_t dwHash; |
1259 IFX_Font* pCFont; | 1259 IFX_Font* pCFont; |
1260 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pCFont); | 1260 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pCFont); |
1261 if (pCFont == pEFont) { | 1261 if (pCFont == pEFont) { |
1262 m_FileAccess2IFXFont.RemoveKey(dwHash); | 1262 m_FileAccess2IFXFont.RemoveKey(dwHash); |
1263 break; | 1263 break; |
1264 } | 1264 } |
1265 } | 1265 } |
1266 pos = m_Hash2Fonts.GetStartPosition(); | 1266 pos = m_Hash2Fonts.GetStartPosition(); |
1267 while (pos) { | 1267 while (pos) { |
1268 FX_DWORD dwHash; | 1268 uint32_t dwHash; |
1269 CFX_ArrayTemplate<IFX_Font*>* pFonts; | 1269 CFX_ArrayTemplate<IFX_Font*>* pFonts; |
1270 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 1270 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
1271 if (NULL != pFonts) { | 1271 if (NULL != pFonts) { |
1272 for (int32_t i = 0; i < pFonts->GetSize(); i++) { | 1272 for (int32_t i = 0; i < pFonts->GetSize(); i++) { |
1273 if (pFonts->GetAt(i) == pEFont) { | 1273 if (pFonts->GetAt(i) == pEFont) { |
1274 pFonts->SetAt(i, NULL); | 1274 pFonts->SetAt(i, NULL); |
1275 } | 1275 } |
1276 } | 1276 } |
1277 } else { | 1277 } else { |
1278 m_Hash2Fonts.RemoveKey(dwHash); | 1278 m_Hash2Fonts.RemoveKey(dwHash); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 continue; | 1334 continue; |
1335 // All faces keep number of faces. It can be retrieved from any one face. | 1335 // All faces keep number of faces. It can be retrieved from any one face. |
1336 if (!num_faces) | 1336 if (!num_faces) |
1337 num_faces = pFace->num_faces; | 1337 num_faces = pFace->num_faces; |
1338 RegisterFace(pFace, m_InstalledFonts, pFaceName, nullptr); | 1338 RegisterFace(pFace, m_InstalledFonts, pFaceName, nullptr); |
1339 if (FXFT_Get_Face_External_Stream(pFace)) | 1339 if (FXFT_Get_Face_External_Stream(pFace)) |
1340 FXFT_Clear_Face_External_Stream(pFace); | 1340 FXFT_Clear_Face_External_Stream(pFace); |
1341 FXFT_Done_Face(pFace); | 1341 FXFT_Done_Face(pFace); |
1342 } while (index < num_faces); | 1342 } while (index < num_faces); |
1343 } | 1343 } |
1344 FX_DWORD CFX_FontMgrImp::GetFlags(FXFT_Face pFace) { | 1344 uint32_t CFX_FontMgrImp::GetFlags(FXFT_Face pFace) { |
1345 FX_DWORD flag = 0; | 1345 uint32_t flag = 0; |
1346 if (FT_IS_FIXED_WIDTH(pFace)) { | 1346 if (FT_IS_FIXED_WIDTH(pFace)) { |
1347 flag |= FX_FONTSTYLE_FixedPitch; | 1347 flag |= FX_FONTSTYLE_FixedPitch; |
1348 } | 1348 } |
1349 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1349 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
1350 if (!pOS2) { | 1350 if (!pOS2) { |
1351 return flag; | 1351 return flag; |
1352 } | 1352 } |
1353 if (pOS2->ulCodePageRange1 & (1 << 31)) { | 1353 if (pOS2->ulCodePageRange1 & (1 << 31)) { |
1354 flag |= FX_FONTSTYLE_Symbolic; | 1354 flag |= FX_FONTSTYLE_Symbolic; |
1355 } | 1355 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 CODEPAGERANGE_IMPLEMENT(2); | 1481 CODEPAGERANGE_IMPLEMENT(2); |
1482 a3 = pOS2->ulCodePageRange2 & 0x0000ffff; | 1482 a3 = pOS2->ulCodePageRange2 & 0x0000ffff; |
1483 CODEPAGERANGE_IMPLEMENT(3); | 1483 CODEPAGERANGE_IMPLEMENT(3); |
1484 a4 = (pOS2->ulCodePageRange2 >> 16) & 0x0000ffff; | 1484 a4 = (pOS2->ulCodePageRange2 >> 16) & 0x0000ffff; |
1485 CODEPAGERANGE_IMPLEMENT(4); | 1485 CODEPAGERANGE_IMPLEMENT(4); |
1486 } else { | 1486 } else { |
1487 Charsets.Add(FX_CHARSET_Default); | 1487 Charsets.Add(FX_CHARSET_Default); |
1488 } | 1488 } |
1489 } | 1489 } |
1490 #undef CODEPAGERANGE_IMPLEMENT | 1490 #undef CODEPAGERANGE_IMPLEMENT |
1491 void CFX_FontMgrImp::GetUSBCSB(FXFT_Face pFace, FX_DWORD* USB, FX_DWORD* CSB) { | 1491 void CFX_FontMgrImp::GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB) { |
1492 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1492 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
1493 if (NULL != pOS2) { | 1493 if (NULL != pOS2) { |
1494 USB[0] = pOS2->ulUnicodeRange1; | 1494 USB[0] = pOS2->ulUnicodeRange1; |
1495 USB[1] = pOS2->ulUnicodeRange2; | 1495 USB[1] = pOS2->ulUnicodeRange2; |
1496 USB[2] = pOS2->ulUnicodeRange3; | 1496 USB[2] = pOS2->ulUnicodeRange3; |
1497 USB[3] = pOS2->ulUnicodeRange4; | 1497 USB[3] = pOS2->ulUnicodeRange4; |
1498 CSB[0] = pOS2->ulCodePageRange1; | 1498 CSB[0] = pOS2->ulCodePageRange1; |
1499 CSB[1] = pOS2->ulCodePageRange2; | 1499 CSB[1] = pOS2->ulCodePageRange2; |
1500 } else { | 1500 } else { |
1501 USB[0] = 0; | 1501 USB[0] = 0; |
1502 USB[1] = 0; | 1502 USB[1] = 0; |
1503 USB[2] = 0; | 1503 USB[2] = 0; |
1504 USB[3] = 0; | 1504 USB[3] = 0; |
1505 CSB[0] = 0; | 1505 CSB[0] = 0; |
1506 CSB[1] = 0; | 1506 CSB[1] = 0; |
1507 } | 1507 } |
1508 } | 1508 } |
1509 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1509 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, |
1510 const CFX_WideString& Name2) { | 1510 const CFX_WideString& Name2) { |
1511 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { | 1511 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { |
1512 return 1; | 1512 return 1; |
1513 } | 1513 } |
1514 return 0; | 1514 return 0; |
1515 } | 1515 } |
1516 #endif | 1516 #endif |
OLD | NEW |