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" |
11 #include "xfa/fgas/font/fgas_fontutils.h" | 11 #include "xfa/fgas/font/fgas_fontutils.h" |
12 | 12 |
13 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 13 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
14 IFX_FontMgr* IFX_FontMgr::Create(FX_LPEnumAllFonts pEnumerator, | 14 IFX_FontMgr* IFX_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { |
15 FX_LPMatchFont pMatcher, | 15 return new CFX_StdFontMgrImp(pEnumerator); |
16 void* pUserData) { | |
17 return new CFX_StdFontMgrImp(pEnumerator, pMatcher, pUserData); | |
18 } | 16 } |
19 CFX_StdFontMgrImp::CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator, | 17 CFX_StdFontMgrImp::CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) |
20 FX_LPMatchFont pMatcher, | 18 : m_pEnumerator(pEnumerator), |
21 void* pUserData) | |
22 : m_pMatcher(pMatcher), | |
23 m_pEnumerator(pEnumerator), | |
24 m_FontFaces(), | 19 m_FontFaces(), |
25 m_Fonts(), | 20 m_Fonts(), |
26 m_CPFonts(8), | 21 m_CPFonts(8), |
27 m_FamilyFonts(16), | 22 m_FamilyFonts(16), |
28 m_UnicodeFonts(16), | 23 m_UnicodeFonts(16), |
29 m_BufferFonts(4), | 24 m_BufferFonts(4), |
30 m_FileFonts(4), | 25 m_FileFonts(4), |
31 m_StreamFonts(4), | 26 m_StreamFonts(4), |
32 m_DeriveFonts(4), | 27 m_DeriveFonts(4) { |
33 m_pUserData(pUserData) { | |
34 if (m_pEnumerator != NULL) { | 28 if (m_pEnumerator != NULL) { |
35 m_pEnumerator(m_FontFaces, m_pUserData, NULL, 0xFEFF); | 29 m_pEnumerator(m_FontFaces, NULL, 0xFEFF); |
36 } | 30 } |
37 if (m_pMatcher == NULL) { | |
38 m_pMatcher = FX_DefFontMatcher; | |
39 } | |
40 FXSYS_assert(m_pMatcher != NULL); | |
41 } | 31 } |
| 32 |
42 CFX_StdFontMgrImp::~CFX_StdFontMgrImp() { | 33 CFX_StdFontMgrImp::~CFX_StdFontMgrImp() { |
43 m_FontFaces.RemoveAll(); | 34 m_FontFaces.RemoveAll(); |
44 m_CPFonts.RemoveAll(); | 35 m_CPFonts.RemoveAll(); |
45 m_FamilyFonts.RemoveAll(); | 36 m_FamilyFonts.RemoveAll(); |
46 m_UnicodeFonts.RemoveAll(); | 37 m_UnicodeFonts.RemoveAll(); |
47 m_BufferFonts.RemoveAll(); | 38 m_BufferFonts.RemoveAll(); |
48 m_FileFonts.RemoveAll(); | 39 m_FileFonts.RemoveAll(); |
49 m_StreamFonts.RemoveAll(); | 40 m_StreamFonts.RemoveAll(); |
50 m_DeriveFonts.RemoveAll(); | 41 m_DeriveFonts.RemoveAll(); |
51 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) { | 42 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) { |
52 IFX_Font* pFont = (IFX_Font*)m_Fonts[i]; | 43 IFX_Font* pFont = (IFX_Font*)m_Fonts[i]; |
53 if (pFont != NULL) { | 44 if (pFont != NULL) { |
54 pFont->Release(); | 45 pFont->Release(); |
55 } | 46 } |
56 } | 47 } |
57 m_Fonts.RemoveAll(); | 48 m_Fonts.RemoveAll(); |
58 } | 49 } |
59 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCodePage( | 50 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCodePage( |
60 uint16_t wCodePage, | 51 uint16_t wCodePage, |
61 uint32_t dwFontStyles, | 52 uint32_t dwFontStyles, |
62 const FX_WCHAR* pszFontFamily) { | 53 const FX_WCHAR* pszFontFamily) { |
63 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 54 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
64 IFX_Font* pFont = NULL; | 55 IFX_Font* pFont = NULL; |
65 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 56 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
66 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; | 57 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; |
67 } | 58 } |
68 FX_LPCFONTDESCRIPTOR pFD; | 59 FX_FONTDESCRIPTOR const* pFD; |
69 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { | 60 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { |
70 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) { | 61 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) { |
71 if ((pFD = FindFont(NULL, dwFontStyles, FALSE, wCodePage)) == NULL) | 62 if ((pFD = FindFont(NULL, dwFontStyles, FALSE, wCodePage)) == NULL) |
72 return NULL; | 63 return NULL; |
73 } | 64 } |
74 } | 65 } |
75 FXSYS_assert(pFD != NULL); | 66 FXSYS_assert(pFD != NULL); |
76 pFont = IFX_Font::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 67 pFont = IFX_Font::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
77 if (pFont != NULL) { | 68 if (pFont != NULL) { |
78 m_Fonts.Add(pFont); | 69 m_Fonts.Add(pFont); |
(...skipping 19 matching lines...) Expand all Loading... |
98 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); | 89 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); |
99 if (pRet->wBitField == 999) | 90 if (pRet->wBitField == 999) |
100 return nullptr; | 91 return nullptr; |
101 | 92 |
102 uint32_t dwHash = | 93 uint32_t dwHash = |
103 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); | 94 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); |
104 IFX_Font* pFont = nullptr; | 95 IFX_Font* pFont = nullptr; |
105 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) | 96 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) |
106 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; | 97 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; |
107 | 98 |
108 FX_LPCFONTDESCRIPTOR pFD = | 99 FX_FONTDESCRIPTOR const* pFD = |
109 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage, | 100 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage, |
110 pRet->wBitField, wUnicode); | 101 pRet->wBitField, wUnicode); |
111 if (!pFD && pszFontFamily) { | 102 if (!pFD && pszFontFamily) { |
112 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage, | 103 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage, |
113 pRet->wBitField, wUnicode); | 104 pRet->wBitField, wUnicode); |
114 } | 105 } |
115 if (!pFD) | 106 if (!pFD) |
116 return nullptr; | 107 return nullptr; |
117 | 108 |
118 uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); | 109 uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); |
(...skipping 20 matching lines...) Expand all Loading... |
139 } | 130 } |
140 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, | 131 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, |
141 uint32_t dwFontStyles, | 132 uint32_t dwFontStyles, |
142 uint16_t wCodePage) { | 133 uint16_t wCodePage) { |
143 uint32_t dwHash = | 134 uint32_t dwHash = |
144 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); | 135 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); |
145 IFX_Font* pFont = NULL; | 136 IFX_Font* pFont = NULL; |
146 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 137 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
147 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; | 138 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; |
148 } | 139 } |
149 FX_LPCFONTDESCRIPTOR pFD = NULL; | 140 FX_FONTDESCRIPTOR const* pFD = NULL; |
150 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { | 141 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { |
151 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) == | 142 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) == |
152 NULL) { | 143 NULL) { |
153 return NULL; | 144 return NULL; |
154 } | 145 } |
155 } | 146 } |
156 FXSYS_assert(pFD != NULL); | 147 FXSYS_assert(pFD != NULL); |
157 if (wCodePage == 0xFFFF) { | 148 if (wCodePage == 0xFFFF) { |
158 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); | 149 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); |
159 } | 150 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 RemoveFont(m_UnicodeFonts, pFont); | 280 RemoveFont(m_UnicodeFonts, pFont); |
290 RemoveFont(m_BufferFonts, pFont); | 281 RemoveFont(m_BufferFonts, pFont); |
291 RemoveFont(m_FileFonts, pFont); | 282 RemoveFont(m_FileFonts, pFont); |
292 RemoveFont(m_StreamFonts, pFont); | 283 RemoveFont(m_StreamFonts, pFont); |
293 RemoveFont(m_DeriveFonts, pFont); | 284 RemoveFont(m_DeriveFonts, pFont); |
294 int32_t iFind = m_Fonts.Find(pFont); | 285 int32_t iFind = m_Fonts.Find(pFont); |
295 if (iFind > -1) { | 286 if (iFind > -1) { |
296 m_Fonts.RemoveAt(iFind, 1); | 287 m_Fonts.RemoveAt(iFind, 1); |
297 } | 288 } |
298 } | 289 } |
299 FX_LPCFONTDESCRIPTOR CFX_StdFontMgrImp::FindFont(const FX_WCHAR* pszFontFamily, | 290 FX_FONTDESCRIPTOR const* CFX_StdFontMgrImp::FindFont( |
300 uint32_t dwFontStyles, | 291 const FX_WCHAR* pszFontFamily, |
301 uint32_t dwMatchFlags, | 292 uint32_t dwFontStyles, |
302 uint16_t wCodePage, | 293 uint32_t dwMatchFlags, |
303 uint32_t dwUSB, | 294 uint16_t wCodePage, |
304 FX_WCHAR wUnicode) { | 295 uint32_t dwUSB, |
305 if (m_pMatcher == NULL) { | 296 FX_WCHAR wUnicode) { |
306 return NULL; | |
307 } | |
308 FX_FONTMATCHPARAMS params; | 297 FX_FONTMATCHPARAMS params; |
309 FXSYS_memset(¶ms, 0, sizeof(params)); | 298 FXSYS_memset(¶ms, 0, sizeof(params)); |
310 params.dwUSB = dwUSB; | 299 params.dwUSB = dwUSB; |
311 params.wUnicode = wUnicode; | 300 params.wUnicode = wUnicode; |
312 params.wCodePage = wCodePage; | 301 params.wCodePage = wCodePage; |
313 params.pwsFamily = pszFontFamily; | 302 params.pwsFamily = pszFontFamily; |
314 params.dwFontStyles = dwFontStyles; | 303 params.dwFontStyles = dwFontStyles; |
315 params.dwMatchFlags = dwMatchFlags; | 304 params.dwMatchFlags = dwMatchFlags; |
316 FX_LPCFONTDESCRIPTOR pDesc = m_pMatcher(¶ms, m_FontFaces, m_pUserData); | 305 FX_FONTDESCRIPTOR const* pDesc = FX_DefFontMatcher(¶ms, m_FontFaces); |
317 if (pDesc) { | 306 if (pDesc) { |
318 return pDesc; | 307 return pDesc; |
319 } | 308 } |
320 if (pszFontFamily && m_pEnumerator) { | 309 if (pszFontFamily && m_pEnumerator) { |
321 CFX_FontDescriptors namedFonts; | 310 CFX_FontDescriptors namedFonts; |
322 m_pEnumerator(namedFonts, m_pUserData, pszFontFamily, wUnicode); | 311 m_pEnumerator(namedFonts, pszFontFamily, wUnicode); |
323 params.pwsFamily = NULL; | 312 params.pwsFamily = NULL; |
324 pDesc = m_pMatcher(¶ms, namedFonts, m_pUserData); | 313 pDesc = FX_DefFontMatcher(¶ms, namedFonts); |
325 if (pDesc == NULL) { | 314 if (pDesc == NULL) { |
326 return NULL; | 315 return NULL; |
327 } | 316 } |
328 for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) { | 317 for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) { |
329 FX_LPCFONTDESCRIPTOR pMatch = m_FontFaces.GetPtrAt(i); | 318 FX_FONTDESCRIPTOR const* pMatch = m_FontFaces.GetPtrAt(i); |
330 if (*pMatch == *pDesc) { | 319 if (*pMatch == *pDesc) { |
331 return pMatch; | 320 return pMatch; |
332 } | 321 } |
333 } | 322 } |
334 int index = m_FontFaces.Add(*pDesc); | 323 int index = m_FontFaces.Add(*pDesc); |
335 return m_FontFaces.GetPtrAt(index); | 324 return m_FontFaces.GetPtrAt(index); |
336 } | 325 } |
337 return NULL; | 326 return NULL; |
338 } | 327 } |
339 FX_LPCFONTDESCRIPTOR FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, | 328 FX_FONTDESCRIPTOR const* FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, |
340 const CFX_FontDescriptors& fonts, | 329 const CFX_FontDescriptors& fonts) { |
341 void* pUserData) { | 330 FX_FONTDESCRIPTOR const* pBestFont = NULL; |
342 FX_LPCFONTDESCRIPTOR pBestFont = NULL; | |
343 int32_t iBestSimilar = 0; | 331 int32_t iBestSimilar = 0; |
344 FX_BOOL bMatchStyle = | 332 FX_BOOL bMatchStyle = |
345 (pParams->dwMatchFlags & FX_FONTMATCHPARA_MacthStyle) > 0; | 333 (pParams->dwMatchFlags & FX_FONTMATCHPARA_MacthStyle) > 0; |
346 int32_t iCount = fonts.GetSize(); | 334 int32_t iCount = fonts.GetSize(); |
347 for (int32_t i = 0; i < iCount; ++i) { | 335 for (int32_t i = 0; i < iCount; ++i) { |
348 FX_LPCFONTDESCRIPTOR pFont = fonts.GetPtrAt(i); | 336 FX_FONTDESCRIPTOR const* pFont = fonts.GetPtrAt(i); |
349 if ((pFont->dwFontStyles & FX_FONTSTYLE_BoldItalic) == | 337 if ((pFont->dwFontStyles & FX_FONTSTYLE_BoldItalic) == |
350 FX_FONTSTYLE_BoldItalic) { | 338 FX_FONTSTYLE_BoldItalic) { |
351 continue; | 339 continue; |
352 } | 340 } |
353 if (pParams->pwsFamily) { | 341 if (pParams->pwsFamily) { |
354 if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace)) { | 342 if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace)) { |
355 continue; | 343 continue; |
356 } | 344 } |
357 if (pFont->uCharSet == FX_CHARSET_Symbol) { | 345 if (pFont->uCharSet == FX_CHARSET_Symbol) { |
358 return pFont; | 346 return pFont; |
(...skipping 28 matching lines...) Expand all Loading... |
387 } | 375 } |
388 } | 376 } |
389 int32_t iSimilarValue = FX_GetSimilarValue(pFont, pParams->dwFontStyles); | 377 int32_t iSimilarValue = FX_GetSimilarValue(pFont, pParams->dwFontStyles); |
390 if (iBestSimilar < iSimilarValue) { | 378 if (iBestSimilar < iSimilarValue) { |
391 iBestSimilar = iSimilarValue; | 379 iBestSimilar = iSimilarValue; |
392 pBestFont = pFont; | 380 pBestFont = pFont; |
393 } | 381 } |
394 } | 382 } |
395 return iBestSimilar < 1 ? NULL : pBestFont; | 383 return iBestSimilar < 1 ? NULL : pBestFont; |
396 } | 384 } |
397 int32_t FX_GetSimilarValue(FX_LPCFONTDESCRIPTOR pFont, uint32_t dwFontStyles) { | 385 int32_t FX_GetSimilarValue(FX_FONTDESCRIPTOR const* pFont, |
| 386 uint32_t dwFontStyles) { |
398 int32_t iValue = 0; | 387 int32_t iValue = 0; |
399 if ((dwFontStyles & FX_FONTSTYLE_Symbolic) == | 388 if ((dwFontStyles & FX_FONTSTYLE_Symbolic) == |
400 (pFont->dwFontStyles & FX_FONTSTYLE_Symbolic)) { | 389 (pFont->dwFontStyles & FX_FONTSTYLE_Symbolic)) { |
401 iValue += 64; | 390 iValue += 64; |
402 } | 391 } |
403 if ((dwFontStyles & FX_FONTSTYLE_FixedPitch) == | 392 if ((dwFontStyles & FX_FONTSTYLE_FixedPitch) == |
404 (pFont->dwFontStyles & FX_FONTSTYLE_FixedPitch)) { | 393 (pFont->dwFontStyles & FX_FONTSTYLE_FixedPitch)) { |
405 iValue += 32; | 394 iValue += 32; |
406 } | 395 } |
407 if ((dwFontStyles & FX_FONTSTYLE_Serif) == | 396 if ((dwFontStyles & FX_FONTSTYLE_Serif) == |
(...skipping 30 matching lines...) Expand all Loading... |
438 NEWTEXTMETRICEX* lpntme, | 427 NEWTEXTMETRICEX* lpntme, |
439 DWORD dwFontType, | 428 DWORD dwFontType, |
440 LPARAM lParam) { | 429 LPARAM lParam) { |
441 if (dwFontType != TRUETYPE_FONTTYPE) { | 430 if (dwFontType != TRUETYPE_FONTTYPE) { |
442 return 1; | 431 return 1; |
443 } | 432 } |
444 const LOGFONTW& lf = ((LPENUMLOGFONTEXW)lpelfe)->elfLogFont; | 433 const LOGFONTW& lf = ((LPENUMLOGFONTEXW)lpelfe)->elfLogFont; |
445 if (lf.lfFaceName[0] == L'@') { | 434 if (lf.lfFaceName[0] == L'@') { |
446 return 1; | 435 return 1; |
447 } | 436 } |
448 FX_LPFONTDESCRIPTOR pFont = FX_Alloc(FX_FONTDESCRIPTOR, 1); | 437 FX_FONTDESCRIPTOR* pFont = FX_Alloc(FX_FONTDESCRIPTOR, 1); |
449 FXSYS_memset(pFont, 0, sizeof(FX_FONTDESCRIPTOR)); | 438 FXSYS_memset(pFont, 0, sizeof(FX_FONTDESCRIPTOR)); |
450 pFont->uCharSet = lf.lfCharSet; | 439 pFont->uCharSet = lf.lfCharSet; |
451 pFont->dwFontStyles = FX_GetGdiFontStyles(lf); | 440 pFont->dwFontStyles = FX_GetGdiFontStyles(lf); |
452 FXSYS_wcsncpy(pFont->wsFontFace, (const FX_WCHAR*)lf.lfFaceName, 31); | 441 FXSYS_wcsncpy(pFont->wsFontFace, (const FX_WCHAR*)lf.lfFaceName, 31); |
453 pFont->wsFontFace[31] = 0; | 442 pFont->wsFontFace[31] = 0; |
454 FXSYS_memcpy(&pFont->FontSignature, &lpntme->ntmFontSig, | 443 FXSYS_memcpy(&pFont->FontSignature, &lpntme->ntmFontSig, |
455 sizeof(lpntme->ntmFontSig)); | 444 sizeof(lpntme->ntmFontSig)); |
456 ((CFX_FontDescriptors*)lParam)->Add(*pFont); | 445 ((CFX_FontDescriptors*)lParam)->Add(*pFont); |
457 FX_Free(pFont); | 446 FX_Free(pFont); |
458 return 1; | 447 return 1; |
459 } | 448 } |
460 static void FX_EnumGdiFonts(CFX_FontDescriptors& fonts, | 449 static void FX_EnumGdiFonts(CFX_FontDescriptors& fonts, |
461 void* pUserData, | |
462 const FX_WCHAR* pwsFaceName, | 450 const FX_WCHAR* pwsFaceName, |
463 FX_WCHAR wUnicode) { | 451 FX_WCHAR wUnicode) { |
464 HDC hDC = ::GetDC(NULL); | 452 HDC hDC = ::GetDC(NULL); |
465 LOGFONTW lfFind; | 453 LOGFONTW lfFind; |
466 FXSYS_memset(&lfFind, 0, sizeof(lfFind)); | 454 FXSYS_memset(&lfFind, 0, sizeof(lfFind)); |
467 lfFind.lfCharSet = DEFAULT_CHARSET; | 455 lfFind.lfCharSet = DEFAULT_CHARSET; |
468 if (pwsFaceName) { | 456 if (pwsFaceName) { |
469 FXSYS_wcsncpy((FX_WCHAR*)lfFind.lfFaceName, pwsFaceName, 31); | 457 FXSYS_wcsncpy((FX_WCHAR*)lfFind.lfFaceName, pwsFaceName, 31); |
470 lfFind.lfFaceName[31] = 0; | 458 lfFind.lfFaceName[31] = 0; |
471 } | 459 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 pCurHandle = hpp.pFileHandle; | 533 pCurHandle = hpp.pFileHandle; |
546 continue; | 534 continue; |
547 } | 535 } |
548 bsName = | 536 bsName = |
549 m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath + | 537 m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath + |
550 bsFolderSpearator + bsName; | 538 bsFolderSpearator + bsName; |
551 break; | 539 break; |
552 } | 540 } |
553 return bsName; | 541 return bsName; |
554 } | 542 } |
555 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition(void* pUserData) { | 543 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() { |
556 m_wsNext = GetNextFile().UTF8Decode(); | 544 m_wsNext = GetNextFile().UTF8Decode(); |
557 if (0 == m_wsNext.GetLength()) { | 545 if (0 == m_wsNext.GetLength()) { |
558 return (FX_POSITION)0; | 546 return (FX_POSITION)0; |
559 } | 547 } |
560 return (FX_POSITION)-1; | 548 return (FX_POSITION)-1; |
561 } | 549 } |
562 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos, | 550 |
563 void* pUserData) { | 551 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { |
564 IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC()); | 552 IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC()); |
565 m_wsNext = GetNextFile().UTF8Decode(); | 553 m_wsNext = GetNextFile().UTF8Decode(); |
566 pos = 0 != m_wsNext.GetLength() ? pAccess : NULL; | 554 pos = 0 != m_wsNext.GetLength() ? pAccess : NULL; |
567 return (IFX_FileAccess*)pAccess; | 555 return (IFX_FileAccess*)pAccess; |
568 } | 556 } |
569 IFX_FontSourceEnum* FX_CreateDefaultFontSourceEnum() { | 557 IFX_FontSourceEnum* FX_CreateDefaultFontSourceEnum() { |
570 return (IFX_FontSourceEnum*)new CFX_FontSourceEnum_File; | 558 return (IFX_FontSourceEnum*)new CFX_FontSourceEnum_File; |
571 } | 559 } |
572 IFX_FontMgr* IFX_FontMgr::Create(IFX_FontSourceEnum* pFontEnum, | 560 IFX_FontMgr* IFX_FontMgr::Create(IFX_FontSourceEnum* pFontEnum) { |
573 IFX_FontMgrDelegate* pDelegate, | |
574 void* pUserData) { | |
575 if (NULL == pFontEnum) { | 561 if (NULL == pFontEnum) { |
576 return NULL; | 562 return NULL; |
577 } | 563 } |
578 CFX_FontMgrImp* pFontMgr = | 564 CFX_FontMgrImp* pFontMgr = new CFX_FontMgrImp(pFontEnum); |
579 new CFX_FontMgrImp(pFontEnum, pDelegate, pUserData); | |
580 if (pFontMgr->EnumFonts()) { | 565 if (pFontMgr->EnumFonts()) { |
581 return pFontMgr; | 566 return pFontMgr; |
582 } | 567 } |
583 delete pFontMgr; | 568 delete pFontMgr; |
584 return NULL; | 569 return NULL; |
585 } | 570 } |
586 CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum, | 571 CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum) |
587 IFX_FontMgrDelegate* pDelegate, | 572 : m_pFontSource(pFontEnum) {} |
588 void* pUserData) | |
589 : m_pFontSource(pFontEnum), | |
590 m_pDelegate(pDelegate), | |
591 m_pUserData(pUserData) {} | |
592 | 573 |
593 FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() { | 574 FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() { |
594 CFX_FontMapper* pFontMapper = | 575 CFX_FontMapper* pFontMapper = |
595 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); | 576 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); |
596 if (!pFontMapper) | 577 if (!pFontMapper) |
597 return FALSE; | 578 return FALSE; |
598 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 579 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
599 if (!pSystemFontInfo) | 580 if (!pSystemFontInfo) |
600 return FALSE; | 581 return FALSE; |
601 pSystemFontInfo->EnumFontList(pFontMapper); | 582 pSystemFontInfo->EnumFontList(pFontMapper); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 IFX_Font* pFont; | 665 IFX_Font* pFont; |
685 IFX_FileRead* pFileRead; | 666 IFX_FileRead* pFileRead; |
686 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 667 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
687 pFileRead->Release(); | 668 pFileRead->Release(); |
688 } | 669 } |
689 delete this; | 670 delete this; |
690 } | 671 } |
691 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage, | 672 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage, |
692 uint32_t dwFontStyles, | 673 uint32_t dwFontStyles, |
693 const FX_WCHAR* pszFontFamily) { | 674 const FX_WCHAR* pszFontFamily) { |
694 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByCodePage( | 675 return nullptr; |
695 this, wCodePage, dwFontStyles, | |
696 pszFontFamily); | |
697 } | 676 } |
698 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset, | 677 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset, |
699 uint32_t dwFontStyles, | 678 uint32_t dwFontStyles, |
700 const FX_WCHAR* pszFontFamily) { | 679 const FX_WCHAR* pszFontFamily) { |
701 return NULL == m_pDelegate ? NULL | 680 return nullptr; |
702 : m_pDelegate->GetDefFontByCharset( | |
703 this, nCharset, dwFontStyles, pszFontFamily); | |
704 } | 681 } |
705 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode, | 682 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode, |
706 uint32_t dwFontStyles, | 683 uint32_t dwFontStyles, |
707 const FX_WCHAR* pszFontFamily) { | 684 const FX_WCHAR* pszFontFamily) { |
708 return NULL == m_pDelegate ? NULL | 685 return nullptr; |
709 : m_pDelegate->GetDefFontByUnicode( | |
710 this, wUnicode, dwFontStyles, pszFontFamily); | |
711 } | 686 } |
712 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage, | 687 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage, |
713 uint32_t dwFontStyles, | 688 uint32_t dwFontStyles, |
714 const FX_WCHAR* pszFontFamily) { | 689 const FX_WCHAR* pszFontFamily) { |
715 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByLanguage( | 690 return nullptr; |
716 this, wLanguage, dwFontStyles, | |
717 pszFontFamily); | |
718 } | 691 } |
719 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, | 692 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, |
720 uint32_t dwFontStyles, | 693 uint32_t dwFontStyles, |
721 const FX_WCHAR* pszFontFamily) { | 694 const FX_WCHAR* pszFontFamily) { |
722 CFX_ByteString bsHash; | 695 CFX_ByteString bsHash; |
723 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 696 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
724 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 697 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
725 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); | 698 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); |
726 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL; | 699 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL; |
727 IFX_Font* pFont = NULL; | 700 IFX_Font* pFont = NULL; |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 } | 1480 } |
1508 } | 1481 } |
1509 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1482 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, |
1510 const CFX_WideString& Name2) { | 1483 const CFX_WideString& Name2) { |
1511 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { | 1484 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { |
1512 return 1; | 1485 return 1; |
1513 } | 1486 } |
1514 return 0; | 1487 return 0; |
1515 } | 1488 } |
1516 #endif | 1489 #endif |
OLD | NEW |