OLD | NEW |
---|---|
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/fxge/include/fx_ge.h" | 10 #include "core/fxge/include/fx_ge.h" |
11 #include "xfa/fgas/crt/fgas_codepage.h" | 11 #include "xfa/fgas/crt/fgas_codepage.h" |
12 #include "xfa/fgas/font/fgas_fontutils.h" | 12 #include "xfa/fgas/font/fgas_fontutils.h" |
13 #include "xfa/fgas/font/fgas_gefont.h" | 13 #include "xfa/fgas/font/fgas_gefont.h" |
14 | 14 |
15 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 15 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
16 | |
16 IFGAS_FontMgr* IFGAS_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { | 17 IFGAS_FontMgr* IFGAS_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { |
17 return new CFGAS_StdFontMgrImp(pEnumerator); | 18 return new CFGAS_StdFontMgrImp(pEnumerator); |
18 } | 19 } |
20 | |
19 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) | 21 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) |
20 : m_pEnumerator(pEnumerator), | 22 : m_pEnumerator(pEnumerator), |
21 m_FontFaces(), | 23 m_FontFaces(), |
22 m_CPFonts(8), | 24 m_CPFonts(8), |
23 m_FamilyFonts(16), | 25 m_FamilyFonts(16), |
24 m_UnicodeFonts(16), | 26 m_UnicodeFonts(16), |
25 m_BufferFonts(4), | 27 m_BufferFonts(4), |
26 m_StreamFonts(4), | 28 m_StreamFonts(4), |
27 m_DeriveFonts(4) { | 29 m_DeriveFonts(4) { |
28 if (m_pEnumerator) { | 30 if (m_pEnumerator) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 69 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
68 if (pFont) { | 70 if (pFont) { |
69 m_Fonts.Add(pFont); | 71 m_Fonts.Add(pFont); |
70 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 72 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
71 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); | 73 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); |
72 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 74 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
73 return LoadFont(pFont, dwFontStyles, wCodePage); | 75 return LoadFont(pFont, dwFontStyles, wCodePage); |
74 } | 76 } |
75 return NULL; | 77 return NULL; |
76 } | 78 } |
79 | |
77 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCharset( | 80 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCharset( |
78 uint8_t nCharset, | 81 uint8_t nCharset, |
79 uint32_t dwFontStyles, | 82 uint32_t dwFontStyles, |
80 const FX_WCHAR* pszFontFamily) { | 83 const FX_WCHAR* pszFontFamily) { |
81 return GetDefFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, | 84 return GetDefFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, |
82 pszFontFamily); | 85 pszFontFamily); |
83 } | 86 } |
84 | 87 |
85 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByUnicode( | 88 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByUnicode( |
86 FX_WCHAR wUnicode, | 89 FX_WCHAR wUnicode, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 return nullptr; | 124 return nullptr; |
122 } | 125 } |
123 | 126 |
124 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByLanguage( | 127 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByLanguage( |
125 uint16_t wLanguage, | 128 uint16_t wLanguage, |
126 uint32_t dwFontStyles, | 129 uint32_t dwFontStyles, |
127 const FX_WCHAR* pszFontFamily) { | 130 const FX_WCHAR* pszFontFamily) { |
128 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), | 131 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), |
129 dwFontStyles, pszFontFamily); | 132 dwFontStyles, pszFontFamily); |
130 } | 133 } |
134 | |
131 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, | 135 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, |
132 uint32_t dwFontStyles, | 136 uint32_t dwFontStyles, |
133 uint16_t wCodePage) { | 137 uint16_t wCodePage) { |
134 uint32_t dwHash = | 138 uint32_t dwHash = |
135 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); | 139 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); |
136 CFGAS_GEFont* pFont = NULL; | 140 CFGAS_GEFont* pFont = NULL; |
137 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 141 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
138 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; | 142 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; |
139 } | 143 } |
140 FX_FONTDESCRIPTOR const* pFD = NULL; | 144 FX_FONTDESCRIPTOR const* pFD = NULL; |
(...skipping 11 matching lines...) Expand all Loading... | |
152 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 156 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
153 if (pFont) { | 157 if (pFont) { |
154 m_Fonts.Add(pFont); | 158 m_Fonts.Add(pFont); |
155 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 159 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
156 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 160 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
157 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 161 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
158 return LoadFont(pFont, dwFontStyles, wCodePage); | 162 return LoadFont(pFont, dwFontStyles, wCodePage); |
159 } | 163 } |
160 return NULL; | 164 return NULL; |
161 } | 165 } |
166 | |
162 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, | 167 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, |
163 int32_t iLength) { | 168 int32_t iLength) { |
164 ASSERT(pBuffer && iLength > 0); | 169 ASSERT(pBuffer && iLength > 0); |
165 CFGAS_GEFont* pFont = NULL; | 170 CFGAS_GEFont* pFont = NULL; |
166 if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) { | 171 if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) { |
167 if (pFont) { | 172 if (pFont) { |
168 return pFont->Retain(); | 173 return pFont->Retain(); |
169 } | 174 } |
170 } | 175 } |
171 pFont = CFGAS_GEFont::LoadFont(pBuffer, iLength, this); | 176 pFont = CFGAS_GEFont::LoadFont(pBuffer, iLength, this); |
(...skipping 28 matching lines...) Expand all Loading... | |
200 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); | 205 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); |
201 if (pszFontAlias) { | 206 if (pszFontAlias) { |
202 uint32_t dwHash = | 207 uint32_t dwHash = |
203 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); | 208 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); |
204 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 209 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
205 } | 210 } |
206 return LoadFont(pFont, dwFontStyles, wCodePage); | 211 return LoadFont(pFont, dwFontStyles, wCodePage); |
207 } | 212 } |
208 return NULL; | 213 return NULL; |
209 } | 214 } |
215 | |
210 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(CFGAS_GEFont* pSrcFont, | 216 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(CFGAS_GEFont* pSrcFont, |
211 uint32_t dwFontStyles, | 217 uint32_t dwFontStyles, |
212 uint16_t wCodePage) { | 218 uint16_t wCodePage) { |
213 ASSERT(pSrcFont); | 219 ASSERT(pSrcFont); |
214 if (pSrcFont->GetFontStyles() == dwFontStyles) { | 220 if (pSrcFont->GetFontStyles() == dwFontStyles) { |
215 return pSrcFont->Retain(); | 221 return pSrcFont->Retain(); |
216 } | 222 } |
217 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, | 223 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, |
218 (void*)(uintptr_t)wCodePage}; | 224 (void*)(uintptr_t)wCodePage}; |
219 uint32_t dwHash = FX_HashCode_GetA( | 225 uint32_t dwHash = FX_HashCode_GetA( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 while (pos) { | 257 while (pos) { |
252 pFind = NULL; | 258 pFind = NULL; |
253 fontMap.GetNextAssoc(pos, pKey, pFind); | 259 fontMap.GetNextAssoc(pos, pKey, pFind); |
254 if (pFind != (void*)pFont) { | 260 if (pFind != (void*)pFont) { |
255 continue; | 261 continue; |
256 } | 262 } |
257 fontMap.RemoveKey(pKey); | 263 fontMap.RemoveKey(pKey); |
258 break; | 264 break; |
259 } | 265 } |
260 } | 266 } |
267 | |
261 void CFGAS_StdFontMgrImp::RemoveFont(CFGAS_GEFont* pFont) { | 268 void CFGAS_StdFontMgrImp::RemoveFont(CFGAS_GEFont* pFont) { |
262 RemoveFont(m_CPFonts, pFont); | 269 RemoveFont(m_CPFonts, pFont); |
263 RemoveFont(m_FamilyFonts, pFont); | 270 RemoveFont(m_FamilyFonts, pFont); |
264 RemoveFont(m_UnicodeFonts, pFont); | 271 RemoveFont(m_UnicodeFonts, pFont); |
265 RemoveFont(m_BufferFonts, pFont); | 272 RemoveFont(m_BufferFonts, pFont); |
266 RemoveFont(m_StreamFonts, pFont); | 273 RemoveFont(m_StreamFonts, pFont); |
267 RemoveFont(m_DeriveFonts, pFont); | 274 RemoveFont(m_DeriveFonts, pFont); |
268 int32_t iFind = m_Fonts.Find(pFont); | 275 int32_t iFind = m_Fonts.Find(pFont); |
269 if (iFind > -1) { | 276 if (iFind > -1) { |
270 m_Fonts.RemoveAt(iFind, 1); | 277 m_Fonts.RemoveAt(iFind, 1); |
271 } | 278 } |
272 } | 279 } |
280 | |
273 FX_FONTDESCRIPTOR const* CFGAS_StdFontMgrImp::FindFont( | 281 FX_FONTDESCRIPTOR const* CFGAS_StdFontMgrImp::FindFont( |
274 const FX_WCHAR* pszFontFamily, | 282 const FX_WCHAR* pszFontFamily, |
275 uint32_t dwFontStyles, | 283 uint32_t dwFontStyles, |
276 uint32_t dwMatchFlags, | 284 uint32_t dwMatchFlags, |
277 uint16_t wCodePage, | 285 uint16_t wCodePage, |
278 uint32_t dwUSB, | 286 uint32_t dwUSB, |
279 FX_WCHAR wUnicode) { | 287 FX_WCHAR wUnicode) { |
280 FX_FONTMATCHPARAMS params; | 288 FX_FONTMATCHPARAMS params; |
281 FXSYS_memset(¶ms, 0, sizeof(params)); | 289 FXSYS_memset(¶ms, 0, sizeof(params)); |
282 params.dwUSB = dwUSB; | 290 params.dwUSB = dwUSB; |
(...skipping 18 matching lines...) Expand all Loading... | |
301 FX_FONTDESCRIPTOR const* pMatch = m_FontFaces.GetPtrAt(i); | 309 FX_FONTDESCRIPTOR const* pMatch = m_FontFaces.GetPtrAt(i); |
302 if (*pMatch == *pDesc) { | 310 if (*pMatch == *pDesc) { |
303 return pMatch; | 311 return pMatch; |
304 } | 312 } |
305 } | 313 } |
306 int index = m_FontFaces.Add(*pDesc); | 314 int index = m_FontFaces.Add(*pDesc); |
307 return m_FontFaces.GetPtrAt(index); | 315 return m_FontFaces.GetPtrAt(index); |
308 } | 316 } |
309 return NULL; | 317 return NULL; |
310 } | 318 } |
319 | |
311 FX_FONTDESCRIPTOR const* FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, | 320 FX_FONTDESCRIPTOR const* FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, |
312 const CFX_FontDescriptors& fonts) { | 321 const CFX_FontDescriptors& fonts) { |
313 FX_FONTDESCRIPTOR const* pBestFont = NULL; | 322 FX_FONTDESCRIPTOR const* pBestFont = NULL; |
314 int32_t iBestSimilar = 0; | 323 int32_t iBestSimilar = 0; |
315 FX_BOOL bMatchStyle = | 324 FX_BOOL bMatchStyle = |
316 (pParams->dwMatchFlags & FX_FONTMATCHPARA_MacthStyle) > 0; | 325 (pParams->dwMatchFlags & FX_FONTMATCHPARA_MacthStyle) > 0; |
317 int32_t iCount = fonts.GetSize(); | 326 int32_t iCount = fonts.GetSize(); |
318 for (int32_t i = 0; i < iCount; ++i) { | 327 for (int32_t i = 0; i < iCount; ++i) { |
319 FX_FONTDESCRIPTOR const* pFont = fonts.GetPtrAt(i); | 328 FX_FONTDESCRIPTOR const* pFont = fonts.GetPtrAt(i); |
320 if ((pFont->dwFontStyles & FX_FONTSTYLE_BoldItalic) == | 329 if ((pFont->dwFontStyles & FX_FONTSTYLE_BoldItalic) == |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 } | 365 } |
357 } | 366 } |
358 int32_t iSimilarValue = FX_GetSimilarValue(pFont, pParams->dwFontStyles); | 367 int32_t iSimilarValue = FX_GetSimilarValue(pFont, pParams->dwFontStyles); |
359 if (iBestSimilar < iSimilarValue) { | 368 if (iBestSimilar < iSimilarValue) { |
360 iBestSimilar = iSimilarValue; | 369 iBestSimilar = iSimilarValue; |
361 pBestFont = pFont; | 370 pBestFont = pFont; |
362 } | 371 } |
363 } | 372 } |
364 return iBestSimilar < 1 ? NULL : pBestFont; | 373 return iBestSimilar < 1 ? NULL : pBestFont; |
365 } | 374 } |
375 | |
366 int32_t FX_GetSimilarValue(FX_FONTDESCRIPTOR const* pFont, | 376 int32_t FX_GetSimilarValue(FX_FONTDESCRIPTOR const* pFont, |
367 uint32_t dwFontStyles) { | 377 uint32_t dwFontStyles) { |
368 int32_t iValue = 0; | 378 int32_t iValue = 0; |
369 if ((dwFontStyles & FX_FONTSTYLE_Symbolic) == | 379 if ((dwFontStyles & FX_FONTSTYLE_Symbolic) == |
370 (pFont->dwFontStyles & FX_FONTSTYLE_Symbolic)) { | 380 (pFont->dwFontStyles & FX_FONTSTYLE_Symbolic)) { |
371 iValue += 64; | 381 iValue += 64; |
372 } | 382 } |
373 if ((dwFontStyles & FX_FONTSTYLE_FixedPitch) == | 383 if ((dwFontStyles & FX_FONTSTYLE_FixedPitch) == |
374 (pFont->dwFontStyles & FX_FONTSTYLE_FixedPitch)) { | 384 (pFont->dwFontStyles & FX_FONTSTYLE_FixedPitch)) { |
375 iValue += 32; | 385 iValue += 32; |
376 } | 386 } |
377 if ((dwFontStyles & FX_FONTSTYLE_Serif) == | 387 if ((dwFontStyles & FX_FONTSTYLE_Serif) == |
378 (pFont->dwFontStyles & FX_FONTSTYLE_Serif)) { | 388 (pFont->dwFontStyles & FX_FONTSTYLE_Serif)) { |
379 iValue += 16; | 389 iValue += 16; |
380 } | 390 } |
381 if ((dwFontStyles & FX_FONTSTYLE_Script) == | 391 if ((dwFontStyles & FX_FONTSTYLE_Script) == |
382 (pFont->dwFontStyles & FX_FONTSTYLE_Script)) { | 392 (pFont->dwFontStyles & FX_FONTSTYLE_Script)) { |
383 iValue += 8; | 393 iValue += 8; |
384 } | 394 } |
385 return iValue; | 395 return iValue; |
386 } | 396 } |
397 | |
387 FX_LPMatchFont FX_GetDefFontMatchor() { | 398 FX_LPMatchFont FX_GetDefFontMatchor() { |
388 return FX_DefFontMatcher; | 399 return FX_DefFontMatcher; |
389 } | 400 } |
401 | |
390 uint32_t FX_GetGdiFontStyles(const LOGFONTW& lf) { | 402 uint32_t FX_GetGdiFontStyles(const LOGFONTW& lf) { |
391 uint32_t dwStyles = 0; | 403 uint32_t dwStyles = 0; |
392 if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) { | 404 if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) { |
393 dwStyles |= FX_FONTSTYLE_FixedPitch; | 405 dwStyles |= FX_FONTSTYLE_FixedPitch; |
394 } | 406 } |
395 uint8_t nFamilies = lf.lfPitchAndFamily & 0xF0; | 407 uint8_t nFamilies = lf.lfPitchAndFamily & 0xF0; |
396 if (nFamilies == FF_ROMAN) { | 408 if (nFamilies == FF_ROMAN) { |
397 dwStyles |= FX_FONTSTYLE_Serif; | 409 dwStyles |= FX_FONTSTYLE_Serif; |
398 } | 410 } |
399 if (nFamilies == FF_SCRIPT) { | 411 if (nFamilies == FF_SCRIPT) { |
400 dwStyles |= FX_FONTSTYLE_Script; | 412 dwStyles |= FX_FONTSTYLE_Script; |
401 } | 413 } |
402 if (lf.lfCharSet == SYMBOL_CHARSET) { | 414 if (lf.lfCharSet == SYMBOL_CHARSET) { |
403 dwStyles |= FX_FONTSTYLE_Symbolic; | 415 dwStyles |= FX_FONTSTYLE_Symbolic; |
404 } | 416 } |
405 return dwStyles; | 417 return dwStyles; |
406 } | 418 } |
419 | |
407 static int32_t CALLBACK FX_GdiFontEnumProc(ENUMLOGFONTEX* lpelfe, | 420 static int32_t CALLBACK FX_GdiFontEnumProc(ENUMLOGFONTEX* lpelfe, |
408 NEWTEXTMETRICEX* lpntme, | 421 NEWTEXTMETRICEX* lpntme, |
409 DWORD dwFontType, | 422 DWORD dwFontType, |
410 LPARAM lParam) { | 423 LPARAM lParam) { |
411 if (dwFontType != TRUETYPE_FONTTYPE) { | 424 if (dwFontType != TRUETYPE_FONTTYPE) { |
412 return 1; | 425 return 1; |
413 } | 426 } |
414 const LOGFONTW& lf = ((LPENUMLOGFONTEXW)lpelfe)->elfLogFont; | 427 const LOGFONTW& lf = ((LPENUMLOGFONTEXW)lpelfe)->elfLogFont; |
415 if (lf.lfFaceName[0] == L'@') { | 428 if (lf.lfFaceName[0] == L'@') { |
416 return 1; | 429 return 1; |
417 } | 430 } |
418 FX_FONTDESCRIPTOR* pFont = FX_Alloc(FX_FONTDESCRIPTOR, 1); | 431 FX_FONTDESCRIPTOR* pFont = FX_Alloc(FX_FONTDESCRIPTOR, 1); |
419 FXSYS_memset(pFont, 0, sizeof(FX_FONTDESCRIPTOR)); | 432 FXSYS_memset(pFont, 0, sizeof(FX_FONTDESCRIPTOR)); |
420 pFont->uCharSet = lf.lfCharSet; | 433 pFont->uCharSet = lf.lfCharSet; |
421 pFont->dwFontStyles = FX_GetGdiFontStyles(lf); | 434 pFont->dwFontStyles = FX_GetGdiFontStyles(lf); |
422 FXSYS_wcsncpy(pFont->wsFontFace, (const FX_WCHAR*)lf.lfFaceName, 31); | 435 FXSYS_wcsncpy(pFont->wsFontFace, (const FX_WCHAR*)lf.lfFaceName, 31); |
423 pFont->wsFontFace[31] = 0; | 436 pFont->wsFontFace[31] = 0; |
424 FXSYS_memcpy(&pFont->FontSignature, &lpntme->ntmFontSig, | 437 FXSYS_memcpy(&pFont->FontSignature, &lpntme->ntmFontSig, |
425 sizeof(lpntme->ntmFontSig)); | 438 sizeof(lpntme->ntmFontSig)); |
426 ((CFX_FontDescriptors*)lParam)->Add(*pFont); | 439 ((CFX_FontDescriptors*)lParam)->Add(*pFont); |
427 FX_Free(pFont); | 440 FX_Free(pFont); |
428 return 1; | 441 return 1; |
429 } | 442 } |
443 | |
430 static void FX_EnumGdiFonts(CFX_FontDescriptors& fonts, | 444 static void FX_EnumGdiFonts(CFX_FontDescriptors& fonts, |
431 const FX_WCHAR* pwsFaceName, | 445 const FX_WCHAR* pwsFaceName, |
432 FX_WCHAR wUnicode) { | 446 FX_WCHAR wUnicode) { |
433 HDC hDC = ::GetDC(NULL); | 447 HDC hDC = ::GetDC(NULL); |
434 LOGFONTW lfFind; | 448 LOGFONTW lfFind; |
435 FXSYS_memset(&lfFind, 0, sizeof(lfFind)); | 449 FXSYS_memset(&lfFind, 0, sizeof(lfFind)); |
436 lfFind.lfCharSet = DEFAULT_CHARSET; | 450 lfFind.lfCharSet = DEFAULT_CHARSET; |
437 if (pwsFaceName) { | 451 if (pwsFaceName) { |
438 FXSYS_wcsncpy(lfFind.lfFaceName, pwsFaceName, 31); | 452 FXSYS_wcsncpy(lfFind.lfFaceName, pwsFaceName, 31); |
439 lfFind.lfFaceName[31] = 0; | 453 lfFind.lfFaceName[31] = 0; |
440 } | 454 } |
441 EnumFontFamiliesExW(hDC, (LPLOGFONTW)&lfFind, | 455 EnumFontFamiliesExW(hDC, (LPLOGFONTW)&lfFind, |
442 (FONTENUMPROCW)FX_GdiFontEnumProc, (LPARAM)&fonts, 0); | 456 (FONTENUMPROCW)FX_GdiFontEnumProc, (LPARAM)&fonts, 0); |
443 ::ReleaseDC(NULL, hDC); | 457 ::ReleaseDC(NULL, hDC); |
444 } | 458 } |
459 | |
445 FX_LPEnumAllFonts FX_GetDefFontEnumerator() { | 460 FX_LPEnumAllFonts FX_GetDefFontEnumerator() { |
446 return FX_EnumGdiFonts; | 461 return FX_EnumGdiFonts; |
447 } | 462 } |
463 | |
448 #else | 464 #else |
449 const FX_CHAR* g_FontFolders[] = { | 465 const FX_CHAR* g_FontFolders[] = { |
450 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ | 466 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ |
451 "/usr/share/fonts", "/usr/share/X11/fonts/Type1", | 467 "/usr/share/fonts", "/usr/share/X11/fonts/Type1", |
452 "/usr/share/X11/fonts/TTF", "/usr/local/share/fonts", | 468 "/usr/share/X11/fonts/TTF", "/usr/local/share/fonts", |
453 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 469 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
454 "~/Library/Fonts", "/Library/Fonts", "/System/Library/Fonts", | 470 "~/Library/Fonts", "/Library/Fonts", "/System/Library/Fonts", |
455 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | 471 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ |
456 "/system/fonts", | 472 "/system/fonts", |
457 #endif | 473 #endif |
458 }; | 474 }; |
459 | 475 |
476 CFX_FontDescriptor::CFX_FontDescriptor() | |
477 : m_nFaceIndex(0), m_dwFontStyles(0), m_dwUsb(), m_dwCsb() {} | |
Lei Zhang
2016/06/20 17:45:02
Does this actually initialize |m_dwUsb| and |m_dwC
Wei Li
2016/06/20 18:04:10
Yes, this will zero initialize the vars, same as =
| |
478 | |
479 CFX_FontDescriptor::~CFX_FontDescriptor() {} | |
480 | |
460 CFX_FontSourceEnum_File::CFX_FontSourceEnum_File() { | 481 CFX_FontSourceEnum_File::CFX_FontSourceEnum_File() { |
461 for (size_t i = 0; i < FX_ArraySize(g_FontFolders); ++i) | 482 for (size_t i = 0; i < FX_ArraySize(g_FontFolders); ++i) |
462 m_FolderPaths.Add(g_FontFolders[i]); | 483 m_FolderPaths.Add(g_FontFolders[i]); |
463 } | 484 } |
464 | 485 |
486 CFX_FontSourceEnum_File::~CFX_FontSourceEnum_File() {} | |
487 | |
465 CFX_ByteString CFX_FontSourceEnum_File::GetNextFile() { | 488 CFX_ByteString CFX_FontSourceEnum_File::GetNextFile() { |
466 Restart: | 489 Restart: |
467 void* pCurHandle = | 490 void* pCurHandle = |
468 m_FolderQueue.GetSize() == 0 | 491 m_FolderQueue.GetSize() == 0 |
469 ? NULL | 492 ? NULL |
470 : m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->pFileHandle; | 493 : m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->pFileHandle; |
471 if (NULL == pCurHandle) { | 494 if (NULL == pCurHandle) { |
472 if (m_FolderPaths.GetSize() < 1) { | 495 if (m_FolderPaths.GetSize() < 1) { |
473 return ""; | 496 return ""; |
474 } | 497 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 pCurHandle = hpp.pFileHandle; | 538 pCurHandle = hpp.pFileHandle; |
516 continue; | 539 continue; |
517 } | 540 } |
518 bsName = | 541 bsName = |
519 m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath + | 542 m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath + |
520 bsFolderSpearator + bsName; | 543 bsFolderSpearator + bsName; |
521 break; | 544 break; |
522 } | 545 } |
523 return bsName; | 546 return bsName; |
524 } | 547 } |
548 | |
525 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() { | 549 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() { |
526 m_wsNext = GetNextFile().UTF8Decode(); | 550 m_wsNext = GetNextFile().UTF8Decode(); |
527 if (0 == m_wsNext.GetLength()) { | 551 if (0 == m_wsNext.GetLength()) { |
528 return (FX_POSITION)0; | 552 return (FX_POSITION)0; |
529 } | 553 } |
530 return (FX_POSITION)-1; | 554 return (FX_POSITION)-1; |
531 } | 555 } |
532 | 556 |
533 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { | 557 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { |
534 IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC()); | 558 IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 continue; | 617 continue; |
594 } | 618 } |
595 RegisterFaces(pFontStream, nullptr); | 619 RegisterFaces(pFontStream, nullptr); |
596 pFontStream->Release(); | 620 pFontStream->Release(); |
597 pFontSource->Release(); | 621 pFontSource->Release(); |
598 } | 622 } |
599 if (m_InstalledFonts.GetSize() == 0) | 623 if (m_InstalledFonts.GetSize() == 0) |
600 return FALSE; | 624 return FALSE; |
601 return TRUE; | 625 return TRUE; |
602 } | 626 } |
627 | |
603 FX_BOOL CFGAS_FontMgrImp::EnumFonts() { | 628 FX_BOOL CFGAS_FontMgrImp::EnumFonts() { |
604 if (EnumFontsFromFontMapper()) | 629 if (EnumFontsFromFontMapper()) |
605 return TRUE; | 630 return TRUE; |
606 return EnumFontsFromFiles(); | 631 return EnumFontsFromFiles(); |
607 } | 632 } |
633 | |
608 void CFGAS_FontMgrImp::Release() { | 634 void CFGAS_FontMgrImp::Release() { |
609 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) { | 635 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) { |
610 delete m_InstalledFonts[i]; | 636 delete m_InstalledFonts[i]; |
611 } | 637 } |
612 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 638 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
613 while (pos) { | 639 while (pos) { |
614 uint32_t dwHash; | 640 uint32_t dwHash; |
615 CFX_FontDescriptorInfos* pDescs; | 641 CFX_FontDescriptorInfos* pDescs; |
616 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 642 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
617 delete pDescs; | 643 delete pDescs; |
618 } | 644 } |
619 pos = m_Hash2Fonts.GetStartPosition(); | 645 pos = m_Hash2Fonts.GetStartPosition(); |
620 while (pos) { | 646 while (pos) { |
621 uint32_t dwHash; | 647 uint32_t dwHash; |
622 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; | 648 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |
623 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 649 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
624 delete pFonts; | 650 delete pFonts; |
625 } | 651 } |
626 m_Hash2Fonts.RemoveAll(); | 652 m_Hash2Fonts.RemoveAll(); |
627 pos = m_IFXFont2FileRead.GetStartPosition(); | 653 pos = m_IFXFont2FileRead.GetStartPosition(); |
628 while (pos) { | 654 while (pos) { |
629 CFGAS_GEFont* pFont; | 655 CFGAS_GEFont* pFont; |
630 IFX_FileRead* pFileRead; | 656 IFX_FileRead* pFileRead; |
631 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 657 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
632 pFileRead->Release(); | 658 pFileRead->Release(); |
633 } | 659 } |
634 delete this; | 660 delete this; |
635 } | 661 } |
662 | |
636 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage( | 663 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage( |
637 uint16_t wCodePage, | 664 uint16_t wCodePage, |
638 uint32_t dwFontStyles, | 665 uint32_t dwFontStyles, |
639 const FX_WCHAR* pszFontFamily) { | 666 const FX_WCHAR* pszFontFamily) { |
640 return nullptr; | 667 return nullptr; |
641 } | 668 } |
669 | |
642 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCharset( | 670 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCharset( |
643 uint8_t nCharset, | 671 uint8_t nCharset, |
644 uint32_t dwFontStyles, | 672 uint32_t dwFontStyles, |
645 const FX_WCHAR* pszFontFamily) { | 673 const FX_WCHAR* pszFontFamily) { |
646 return nullptr; | 674 return nullptr; |
647 } | 675 } |
676 | |
648 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByUnicode( | 677 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByUnicode( |
649 FX_WCHAR wUnicode, | 678 FX_WCHAR wUnicode, |
650 uint32_t dwFontStyles, | 679 uint32_t dwFontStyles, |
651 const FX_WCHAR* pszFontFamily) { | 680 const FX_WCHAR* pszFontFamily) { |
652 return nullptr; | 681 return nullptr; |
653 } | 682 } |
683 | |
654 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByLanguage( | 684 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByLanguage( |
655 uint16_t wLanguage, | 685 uint16_t wLanguage, |
656 uint32_t dwFontStyles, | 686 uint32_t dwFontStyles, |
657 const FX_WCHAR* pszFontFamily) { | 687 const FX_WCHAR* pszFontFamily) { |
658 return nullptr; | 688 return nullptr; |
659 } | 689 } |
660 | 690 |
661 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCodePage( | 691 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCodePage( |
662 uint16_t wCodePage, | 692 uint16_t wCodePage, |
663 uint32_t dwFontStyles, | 693 uint32_t dwFontStyles, |
(...skipping 27 matching lines...) Expand all Loading... | |
691 | 721 |
692 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; | 722 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; |
693 CFGAS_GEFont* pFont = | 723 CFGAS_GEFont* pFont = |
694 LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); | 724 LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); |
695 if (pFont) | 725 if (pFont) |
696 pFont->SetLogicalFontStyle(dwFontStyles); | 726 pFont->SetLogicalFontStyle(dwFontStyles); |
697 | 727 |
698 pFonts->Add(pFont); | 728 pFonts->Add(pFont); |
699 return pFont; | 729 return pFont; |
700 } | 730 } |
731 | |
701 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCharset( | 732 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCharset( |
702 uint8_t nCharset, | 733 uint8_t nCharset, |
703 uint32_t dwFontStyles, | 734 uint32_t dwFontStyles, |
704 const FX_WCHAR* pszFontFamily) { | 735 const FX_WCHAR* pszFontFamily) { |
705 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, | 736 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, |
706 pszFontFamily); | 737 pszFontFamily); |
707 } | 738 } |
739 | |
708 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByUnicode( | 740 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByUnicode( |
709 FX_WCHAR wUnicode, | 741 FX_WCHAR wUnicode, |
710 uint32_t dwFontStyles, | 742 uint32_t dwFontStyles, |
711 const FX_WCHAR* pszFontFamily) { | 743 const FX_WCHAR* pszFontFamily) { |
712 CFGAS_GEFont* pFont = nullptr; | 744 CFGAS_GEFont* pFont = nullptr; |
713 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont)) | 745 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont)) |
714 return nullptr; | 746 return nullptr; |
715 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); | 747 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); |
716 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; | 748 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; |
717 uint16_t wBitField = x ? x->wBitField : 0x03E7; | 749 uint16_t wBitField = x ? x->wBitField : 0x03E7; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 if (!pFont) | 781 if (!pFont) |
750 continue; | 782 continue; |
751 pFont->SetLogicalFontStyle(dwFontStyles); | 783 pFont->SetLogicalFontStyle(dwFontStyles); |
752 pFonts->Add(pFont); | 784 pFonts->Add(pFont); |
753 return pFont; | 785 return pFont; |
754 } | 786 } |
755 if (!pszFontFamily) | 787 if (!pszFontFamily) |
756 m_FailedUnicodes2NULL.SetAt(wUnicode, nullptr); | 788 m_FailedUnicodes2NULL.SetAt(wUnicode, nullptr); |
757 return nullptr; | 789 return nullptr; |
758 } | 790 } |
791 | |
759 FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(CFX_FontDescriptor* pDesc, | 792 FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(CFX_FontDescriptor* pDesc, |
760 FX_WCHAR wcUnicode) { | 793 FX_WCHAR wcUnicode) { |
761 IFX_FileRead* pFileRead = CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); | 794 IFX_FileRead* pFileRead = CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); |
762 if (!pFileRead) | 795 if (!pFileRead) |
763 return FALSE; | 796 return FALSE; |
764 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); | 797 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); |
765 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); | 798 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); |
766 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); | 799 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); |
767 pFileRead->Release(); | 800 pFileRead->Release(); |
768 if (!pFace) | 801 if (!pFace) |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
926 if (!pSystemFontInfo) | 959 if (!pSystemFontInfo) |
927 return nullptr; | 960 return nullptr; |
928 | 961 |
929 pSystemFontInfo->EnumFontList(pFontMapper); | 962 pSystemFontInfo->EnumFontList(pFontMapper); |
930 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { | 963 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { |
931 if (pFontMapper->GetFaceName(i) == bsFaceName) | 964 if (pFontMapper->GetFaceName(i) == bsFaceName) |
932 return CreateFontStream(pFontMapper, pSystemFontInfo, i); | 965 return CreateFontStream(pFontMapper, pSystemFontInfo, i); |
933 } | 966 } |
934 return nullptr; | 967 return nullptr; |
935 } | 968 } |
969 | |
936 int32_t CFGAS_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, | 970 int32_t CFGAS_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, |
937 uint16_t wCodePage, | 971 uint16_t wCodePage, |
938 uint32_t dwFontStyles, | 972 uint32_t dwFontStyles, |
939 const CFX_WideString& FontName, | 973 const CFX_WideString& FontName, |
940 FX_WCHAR wcUnicode) { | 974 FX_WCHAR wcUnicode) { |
941 MatchedFonts.RemoveAll(); | 975 MatchedFonts.RemoveAll(); |
942 CFX_WideString wsNormalizedFontName = FontName; | 976 CFX_WideString wsNormalizedFontName = FontName; |
943 | 977 |
944 CFX_FontDescriptor* pFont = nullptr; | 978 CFX_FontDescriptor* pFont = nullptr; |
945 int32_t nCount = m_InstalledFonts.GetSize(); | 979 int32_t nCount = m_InstalledFonts.GetSize(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1071 if (wBit != (uint16_t)999) { | 1105 if (wBit != (uint16_t)999) { |
1072 ASSERT(wBit < 128); | 1106 ASSERT(wBit < 128); |
1073 if (0 == (pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32)))) { | 1107 if (0 == (pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32)))) { |
1074 nPenalty += 0xFFFF; | 1108 nPenalty += 0xFFFF; |
1075 } else { | 1109 } else { |
1076 nPenalty -= 60000; | 1110 nPenalty -= 60000; |
1077 } | 1111 } |
1078 } | 1112 } |
1079 return nPenalty; | 1113 return nPenalty; |
1080 } | 1114 } |
1115 | |
1081 void CFGAS_FontMgrImp::ClearFontCache() { | 1116 void CFGAS_FontMgrImp::ClearFontCache() { |
1082 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 1117 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
1083 while (pos) { | 1118 while (pos) { |
1084 uint32_t dwHash; | 1119 uint32_t dwHash; |
1085 CFX_FontDescriptorInfos* pDescs; | 1120 CFX_FontDescriptorInfos* pDescs; |
1086 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 1121 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
1087 delete pDescs; | 1122 delete pDescs; |
1088 } | 1123 } |
1089 pos = m_IFXFont2FileRead.GetStartPosition(); | 1124 pos = m_IFXFont2FileRead.GetStartPosition(); |
1090 while (pos) { | 1125 while (pos) { |
1091 CFGAS_GEFont* pFont; | 1126 CFGAS_GEFont* pFont; |
1092 IFX_FileRead* pFileRead; | 1127 IFX_FileRead* pFileRead; |
1093 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 1128 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
1094 pFileRead->Release(); | 1129 pFileRead->Release(); |
1095 } | 1130 } |
1096 } | 1131 } |
1132 | |
1097 void CFGAS_FontMgrImp::RemoveFont(CFGAS_GEFont* pEFont) { | 1133 void CFGAS_FontMgrImp::RemoveFont(CFGAS_GEFont* pEFont) { |
1098 if (NULL == pEFont) { | 1134 if (NULL == pEFont) { |
1099 return; | 1135 return; |
1100 } | 1136 } |
1101 IFX_FileRead* pFileRead; | 1137 IFX_FileRead* pFileRead; |
1102 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { | 1138 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { |
1103 pFileRead->Release(); | 1139 pFileRead->Release(); |
1104 m_IFXFont2FileRead.RemoveKey(pEFont); | 1140 m_IFXFont2FileRead.RemoveKey(pEFont); |
1105 } | 1141 } |
1106 FX_POSITION pos; | 1142 FX_POSITION pos; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1173 continue; | 1209 continue; |
1174 // All faces keep number of faces. It can be retrieved from any one face. | 1210 // All faces keep number of faces. It can be retrieved from any one face. |
1175 if (num_faces == 0) | 1211 if (num_faces == 0) |
1176 num_faces = pFace->num_faces; | 1212 num_faces = pFace->num_faces; |
1177 RegisterFace(pFace, m_InstalledFonts, pFaceName); | 1213 RegisterFace(pFace, m_InstalledFonts, pFaceName); |
1178 if (FXFT_Get_Face_External_Stream(pFace)) | 1214 if (FXFT_Get_Face_External_Stream(pFace)) |
1179 FXFT_Clear_Face_External_Stream(pFace); | 1215 FXFT_Clear_Face_External_Stream(pFace); |
1180 FXFT_Done_Face(pFace); | 1216 FXFT_Done_Face(pFace); |
1181 } while (index < num_faces); | 1217 } while (index < num_faces); |
1182 } | 1218 } |
1219 | |
1183 uint32_t CFGAS_FontMgrImp::GetFlags(FXFT_Face pFace) { | 1220 uint32_t CFGAS_FontMgrImp::GetFlags(FXFT_Face pFace) { |
1184 uint32_t flag = 0; | 1221 uint32_t flag = 0; |
1185 if (FT_IS_FIXED_WIDTH(pFace)) { | 1222 if (FT_IS_FIXED_WIDTH(pFace)) { |
1186 flag |= FX_FONTSTYLE_FixedPitch; | 1223 flag |= FX_FONTSTYLE_FixedPitch; |
1187 } | 1224 } |
1188 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1225 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
1189 if (!pOS2) { | 1226 if (!pOS2) { |
1190 return flag; | 1227 return flag; |
1191 } | 1228 } |
1192 if (pOS2->ulCodePageRange1 & (1 << 31)) { | 1229 if (pOS2->ulCodePageRange1 & (1 << 31)) { |
1193 flag |= FX_FONTSTYLE_Symbolic; | 1230 flag |= FX_FONTSTYLE_Symbolic; |
1194 } | 1231 } |
1195 if (pOS2->panose[0] == 2) { | 1232 if (pOS2->panose[0] == 2) { |
1196 uint8_t uSerif = pOS2->panose[1]; | 1233 uint8_t uSerif = pOS2->panose[1]; |
1197 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) { | 1234 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) { |
1198 flag |= FX_FONTSTYLE_Serif; | 1235 flag |= FX_FONTSTYLE_Serif; |
1199 } | 1236 } |
1200 } | 1237 } |
1201 return flag; | 1238 return flag; |
1202 } | 1239 } |
1240 | |
1203 #define GetUInt8(p) ((uint8_t)((p)[0])) | 1241 #define GetUInt8(p) ((uint8_t)((p)[0])) |
1204 #define GetUInt16(p) ((uint16_t)((p)[0] << 8 | (p)[1])) | 1242 #define GetUInt16(p) ((uint16_t)((p)[0] << 8 | (p)[1])) |
1205 #define GetUInt32(p) \ | 1243 #define GetUInt32(p) \ |
1206 ((uint32_t)((p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3])) | 1244 ((uint32_t)((p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3])) |
1245 | |
1207 void CFGAS_FontMgrImp::GetNames(const uint8_t* name_table, | 1246 void CFGAS_FontMgrImp::GetNames(const uint8_t* name_table, |
1208 CFX_WideStringArray& Names) { | 1247 CFX_WideStringArray& Names) { |
1209 if (NULL == name_table) { | 1248 if (NULL == name_table) { |
1210 return; | 1249 return; |
1211 } | 1250 } |
1212 uint8_t* lpTable = (uint8_t*)name_table; | 1251 uint8_t* lpTable = (uint8_t*)name_table; |
1213 CFX_WideString wsFamily; | 1252 CFX_WideString wsFamily; |
1214 uint8_t* sp = lpTable + 2; | 1253 uint8_t* sp = lpTable + 2; |
1215 uint8_t* lpNameRecord = lpTable + 6; | 1254 uint8_t* lpNameRecord = lpTable + 6; |
1216 uint16_t nNameCount = GetUInt16(sp); | 1255 uint16_t nNameCount = GetUInt16(sp); |
(...skipping 22 matching lines...) Expand all Loading... | |
1239 } | 1278 } |
1240 } | 1279 } |
1241 } | 1280 } |
1242 #undef GetUInt8 | 1281 #undef GetUInt8 |
1243 #undef GetUInt16 | 1282 #undef GetUInt16 |
1244 #undef GetUInt32 | 1283 #undef GetUInt32 |
1245 struct FX_BIT2CHARSET { | 1284 struct FX_BIT2CHARSET { |
1246 uint16_t wBit; | 1285 uint16_t wBit; |
1247 uint16_t wCharset; | 1286 uint16_t wCharset; |
1248 }; | 1287 }; |
1288 | |
1249 FX_BIT2CHARSET g_FX_Bit2Charset1[16] = { | 1289 FX_BIT2CHARSET g_FX_Bit2Charset1[16] = { |
1250 {1 << 0, FX_CHARSET_ANSI}, | 1290 {1 << 0, FX_CHARSET_ANSI}, |
1251 {1 << 1, FX_CHARSET_MSWin_EasterEuropean}, | 1291 {1 << 1, FX_CHARSET_MSWin_EasterEuropean}, |
1252 {1 << 2, FX_CHARSET_MSWin_Cyrillic}, | 1292 {1 << 2, FX_CHARSET_MSWin_Cyrillic}, |
1253 {1 << 3, FX_CHARSET_MSWin_Greek}, | 1293 {1 << 3, FX_CHARSET_MSWin_Greek}, |
1254 {1 << 4, FX_CHARSET_MSWin_Turkish}, | 1294 {1 << 4, FX_CHARSET_MSWin_Turkish}, |
1255 {1 << 5, FX_CHARSET_MSWin_Hebrew}, | 1295 {1 << 5, FX_CHARSET_MSWin_Hebrew}, |
1256 {1 << 6, FX_CHARSET_MSWin_Arabic}, | 1296 {1 << 6, FX_CHARSET_MSWin_Arabic}, |
1257 {1 << 7, FX_CHARSET_MSWin_Baltic}, | 1297 {1 << 7, FX_CHARSET_MSWin_Baltic}, |
1258 {1 << 8, FX_CHARSET_MSWin_Vietnamese}, | 1298 {1 << 8, FX_CHARSET_MSWin_Vietnamese}, |
1259 {1 << 9, FX_CHARSET_Default}, | 1299 {1 << 9, FX_CHARSET_Default}, |
1260 {1 << 10, FX_CHARSET_Default}, | 1300 {1 << 10, FX_CHARSET_Default}, |
1261 {1 << 11, FX_CHARSET_Default}, | 1301 {1 << 11, FX_CHARSET_Default}, |
1262 {1 << 12, FX_CHARSET_Default}, | 1302 {1 << 12, FX_CHARSET_Default}, |
1263 {1 << 13, FX_CHARSET_Default}, | 1303 {1 << 13, FX_CHARSET_Default}, |
1264 {1 << 14, FX_CHARSET_Default}, | 1304 {1 << 14, FX_CHARSET_Default}, |
1265 {1 << 15, FX_CHARSET_Default}, | 1305 {1 << 15, FX_CHARSET_Default}, |
1266 }; | 1306 }; |
1307 | |
1267 FX_BIT2CHARSET g_FX_Bit2Charset2[16] = { | 1308 FX_BIT2CHARSET g_FX_Bit2Charset2[16] = { |
1268 {1 << 0, FX_CHARSET_Thai}, | 1309 {1 << 0, FX_CHARSET_Thai}, |
1269 {1 << 1, FX_CHARSET_ShiftJIS}, | 1310 {1 << 1, FX_CHARSET_ShiftJIS}, |
1270 {1 << 2, FX_CHARSET_ChineseSimplified}, | 1311 {1 << 2, FX_CHARSET_ChineseSimplified}, |
1271 {1 << 3, FX_CHARSET_Korean}, | 1312 {1 << 3, FX_CHARSET_Korean}, |
1272 {1 << 4, FX_CHARSET_ChineseTriditional}, | 1313 {1 << 4, FX_CHARSET_ChineseTriditional}, |
1273 {1 << 5, FX_CHARSET_Johab}, | 1314 {1 << 5, FX_CHARSET_Johab}, |
1274 {1 << 6, FX_CHARSET_Default}, | 1315 {1 << 6, FX_CHARSET_Default}, |
1275 {1 << 7, FX_CHARSET_Default}, | 1316 {1 << 7, FX_CHARSET_Default}, |
1276 {1 << 8, FX_CHARSET_Default}, | 1317 {1 << 8, FX_CHARSET_Default}, |
1277 {1 << 9, FX_CHARSET_Default}, | 1318 {1 << 9, FX_CHARSET_Default}, |
1278 {1 << 10, FX_CHARSET_Default}, | 1319 {1 << 10, FX_CHARSET_Default}, |
1279 {1 << 11, FX_CHARSET_Default}, | 1320 {1 << 11, FX_CHARSET_Default}, |
1280 {1 << 12, FX_CHARSET_Default}, | 1321 {1 << 12, FX_CHARSET_Default}, |
1281 {1 << 13, FX_CHARSET_Default}, | 1322 {1 << 13, FX_CHARSET_Default}, |
1282 {1 << 14, FX_CHARSET_OEM}, | 1323 {1 << 14, FX_CHARSET_OEM}, |
1283 {1 << 15, FX_CHARSET_Symbol}, | 1324 {1 << 15, FX_CHARSET_Symbol}, |
1284 }; | 1325 }; |
1326 | |
1285 FX_BIT2CHARSET g_FX_Bit2Charset3[16] = { | 1327 FX_BIT2CHARSET g_FX_Bit2Charset3[16] = { |
1286 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, | 1328 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, |
1287 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, | 1329 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, |
1288 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, | 1330 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, |
1289 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, | 1331 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, |
1290 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, | 1332 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, |
1291 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, | 1333 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, |
1292 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, | 1334 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, |
1293 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_Default}, | 1335 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_Default}, |
1294 }; | 1336 }; |
1337 | |
1295 FX_BIT2CHARSET g_FX_Bit2Charset4[16] = { | 1338 FX_BIT2CHARSET g_FX_Bit2Charset4[16] = { |
1296 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, | 1339 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, |
1297 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, | 1340 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, |
1298 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, | 1341 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, |
1299 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, | 1342 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, |
1300 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, | 1343 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, |
1301 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, | 1344 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, |
1302 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, | 1345 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, |
1303 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US}, | 1346 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US}, |
1304 }; | 1347 }; |
1348 | |
1305 #define CODEPAGERANGE_IMPLEMENT(n) \ | 1349 #define CODEPAGERANGE_IMPLEMENT(n) \ |
1306 for (int32_t i = 0; i < 16; i++) { \ | 1350 for (int32_t i = 0; i < 16; i++) { \ |
1307 if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) { \ | 1351 if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) { \ |
1308 Charsets.Add(g_FX_Bit2Charset##n[i].wCharset); \ | 1352 Charsets.Add(g_FX_Bit2Charset##n[i].wCharset); \ |
1309 } \ | 1353 } \ |
1310 } | 1354 } |
1355 | |
1311 void CFGAS_FontMgrImp::GetCharsets(FXFT_Face pFace, | 1356 void CFGAS_FontMgrImp::GetCharsets(FXFT_Face pFace, |
1312 CFX_ArrayTemplate<uint16_t>& Charsets) { | 1357 CFX_ArrayTemplate<uint16_t>& Charsets) { |
1313 Charsets.RemoveAll(); | 1358 Charsets.RemoveAll(); |
1314 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1359 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
1315 if (NULL != pOS2) { | 1360 if (NULL != pOS2) { |
1316 uint16_t a1, a2, a3, a4; | 1361 uint16_t a1, a2, a3, a4; |
1317 a1 = pOS2->ulCodePageRange1 & 0x0000ffff; | 1362 a1 = pOS2->ulCodePageRange1 & 0x0000ffff; |
1318 CODEPAGERANGE_IMPLEMENT(1); | 1363 CODEPAGERANGE_IMPLEMENT(1); |
1319 a2 = (pOS2->ulCodePageRange1 >> 16) & 0x0000ffff; | 1364 a2 = (pOS2->ulCodePageRange1 >> 16) & 0x0000ffff; |
1320 CODEPAGERANGE_IMPLEMENT(2); | 1365 CODEPAGERANGE_IMPLEMENT(2); |
1321 a3 = pOS2->ulCodePageRange2 & 0x0000ffff; | 1366 a3 = pOS2->ulCodePageRange2 & 0x0000ffff; |
1322 CODEPAGERANGE_IMPLEMENT(3); | 1367 CODEPAGERANGE_IMPLEMENT(3); |
1323 a4 = (pOS2->ulCodePageRange2 >> 16) & 0x0000ffff; | 1368 a4 = (pOS2->ulCodePageRange2 >> 16) & 0x0000ffff; |
1324 CODEPAGERANGE_IMPLEMENT(4); | 1369 CODEPAGERANGE_IMPLEMENT(4); |
1325 } else { | 1370 } else { |
1326 Charsets.Add(FX_CHARSET_Default); | 1371 Charsets.Add(FX_CHARSET_Default); |
1327 } | 1372 } |
1328 } | 1373 } |
1374 | |
1329 #undef CODEPAGERANGE_IMPLEMENT | 1375 #undef CODEPAGERANGE_IMPLEMENT |
1330 void CFGAS_FontMgrImp::GetUSBCSB(FXFT_Face pFace, | 1376 void CFGAS_FontMgrImp::GetUSBCSB(FXFT_Face pFace, |
1331 uint32_t* USB, | 1377 uint32_t* USB, |
1332 uint32_t* CSB) { | 1378 uint32_t* CSB) { |
1333 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1379 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
1334 if (NULL != pOS2) { | 1380 if (NULL != pOS2) { |
1335 USB[0] = pOS2->ulUnicodeRange1; | 1381 USB[0] = pOS2->ulUnicodeRange1; |
1336 USB[1] = pOS2->ulUnicodeRange2; | 1382 USB[1] = pOS2->ulUnicodeRange2; |
1337 USB[2] = pOS2->ulUnicodeRange3; | 1383 USB[2] = pOS2->ulUnicodeRange3; |
1338 USB[3] = pOS2->ulUnicodeRange4; | 1384 USB[3] = pOS2->ulUnicodeRange4; |
1339 CSB[0] = pOS2->ulCodePageRange1; | 1385 CSB[0] = pOS2->ulCodePageRange1; |
1340 CSB[1] = pOS2->ulCodePageRange2; | 1386 CSB[1] = pOS2->ulCodePageRange2; |
1341 } else { | 1387 } else { |
1342 USB[0] = 0; | 1388 USB[0] = 0; |
1343 USB[1] = 0; | 1389 USB[1] = 0; |
1344 USB[2] = 0; | 1390 USB[2] = 0; |
1345 USB[3] = 0; | 1391 USB[3] = 0; |
1346 CSB[0] = 0; | 1392 CSB[0] = 0; |
1347 CSB[1] = 0; | 1393 CSB[1] = 0; |
1348 } | 1394 } |
1349 } | 1395 } |
1396 | |
1350 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1397 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, |
1351 const CFX_WideString& Name2) { | 1398 const CFX_WideString& Name2) { |
1352 if (Name1.Find(Name2.c_str()) != -1) { | 1399 if (Name1.Find(Name2.c_str()) != -1) { |
1353 return 1; | 1400 return 1; |
1354 } | 1401 } |
1355 return 0; | 1402 return 0; |
1356 } | 1403 } |
1404 | |
1357 #endif | 1405 #endif |
OLD | NEW |