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, m_pUserData, 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--) { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_LPCFONTDESCRIPTOR CFX_StdFontMgrImp::FindFont(const FX_WCHAR* pszFontFamily, |
300 uint32_t dwFontStyles, | 291 uint32_t dwFontStyles, |
301 uint32_t dwMatchFlags, | 292 uint32_t dwMatchFlags, |
302 uint16_t wCodePage, | 293 uint16_t wCodePage, |
303 uint32_t dwUSB, | 294 uint32_t dwUSB, |
304 FX_WCHAR wUnicode) { | 295 FX_WCHAR wUnicode) { |
305 if (m_pMatcher == NULL) { | |
306 return NULL; | |
307 } | |
308 FX_FONTMATCHPARAMS params; | 296 FX_FONTMATCHPARAMS params; |
309 FXSYS_memset(¶ms, 0, sizeof(params)); | 297 FXSYS_memset(¶ms, 0, sizeof(params)); |
310 params.dwUSB = dwUSB; | 298 params.dwUSB = dwUSB; |
311 params.wUnicode = wUnicode; | 299 params.wUnicode = wUnicode; |
312 params.wCodePage = wCodePage; | 300 params.wCodePage = wCodePage; |
313 params.pwsFamily = pszFontFamily; | 301 params.pwsFamily = pszFontFamily; |
314 params.dwFontStyles = dwFontStyles; | 302 params.dwFontStyles = dwFontStyles; |
315 params.dwMatchFlags = dwMatchFlags; | 303 params.dwMatchFlags = dwMatchFlags; |
316 FX_LPCFONTDESCRIPTOR pDesc = m_pMatcher(¶ms, m_FontFaces, m_pUserData); | 304 FX_LPCFONTDESCRIPTOR pDesc = |
| 305 FX_DefFontMatcher(¶ms, m_FontFaces, m_pUserData); |
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, m_pUserData, pszFontFamily, wUnicode); |
323 params.pwsFamily = NULL; | 312 params.pwsFamily = NULL; |
324 pDesc = m_pMatcher(¶ms, namedFonts, m_pUserData); | 313 pDesc = FX_DefFontMatcher(¶ms, namedFonts, m_pUserData); |
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_LPCFONTDESCRIPTOR 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); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 void* pUserData) { | 552 void* pUserData) { |
564 IFX_FileAccess* pAccess = | 553 IFX_FileAccess* pAccess = |
565 FX_CreateDefaultFileAccess(m_wsNext.AsWideStringC()); | 554 FX_CreateDefaultFileAccess(m_wsNext.AsWideStringC()); |
566 m_wsNext = GetNextFile().UTF8Decode(); | 555 m_wsNext = GetNextFile().UTF8Decode(); |
567 pos = 0 != m_wsNext.GetLength() ? pAccess : NULL; | 556 pos = 0 != m_wsNext.GetLength() ? pAccess : NULL; |
568 return (IFX_FileAccess*)pAccess; | 557 return (IFX_FileAccess*)pAccess; |
569 } | 558 } |
570 IFX_FontSourceEnum* FX_CreateDefaultFontSourceEnum() { | 559 IFX_FontSourceEnum* FX_CreateDefaultFontSourceEnum() { |
571 return (IFX_FontSourceEnum*)new CFX_FontSourceEnum_File; | 560 return (IFX_FontSourceEnum*)new CFX_FontSourceEnum_File; |
572 } | 561 } |
573 IFX_FontMgr* IFX_FontMgr::Create(IFX_FontSourceEnum* pFontEnum, | 562 IFX_FontMgr* IFX_FontMgr::Create(IFX_FontSourceEnum* pFontEnum) { |
574 IFX_FontMgrDelegate* pDelegate, | |
575 void* pUserData) { | |
576 if (NULL == pFontEnum) { | 563 if (NULL == pFontEnum) { |
577 return NULL; | 564 return NULL; |
578 } | 565 } |
579 CFX_FontMgrImp* pFontMgr = | 566 CFX_FontMgrImp* pFontMgr = new CFX_FontMgrImp(pFontEnum); |
580 new CFX_FontMgrImp(pFontEnum, pDelegate, pUserData); | |
581 if (pFontMgr->EnumFonts()) { | 567 if (pFontMgr->EnumFonts()) { |
582 return pFontMgr; | 568 return pFontMgr; |
583 } | 569 } |
584 delete pFontMgr; | 570 delete pFontMgr; |
585 return NULL; | 571 return NULL; |
586 } | 572 } |
587 CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum, | 573 CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum) |
588 IFX_FontMgrDelegate* pDelegate, | 574 : m_pFontSource(pFontEnum) {} |
589 void* pUserData) | |
590 : m_pFontSource(pFontEnum), | |
591 m_pDelegate(pDelegate), | |
592 m_pUserData(pUserData) {} | |
593 | 575 |
594 FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() { | 576 FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() { |
595 CFX_FontMapper* pFontMapper = | 577 CFX_FontMapper* pFontMapper = |
596 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); | 578 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); |
597 if (!pFontMapper) | 579 if (!pFontMapper) |
598 return FALSE; | 580 return FALSE; |
599 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 581 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
600 if (!pSystemFontInfo) | 582 if (!pSystemFontInfo) |
601 return FALSE; | 583 return FALSE; |
602 pSystemFontInfo->EnumFontList(pFontMapper); | 584 pSystemFontInfo->EnumFontList(pFontMapper); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 IFX_Font* pFont; | 667 IFX_Font* pFont; |
686 IFX_FileRead* pFileRead; | 668 IFX_FileRead* pFileRead; |
687 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 669 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
688 pFileRead->Release(); | 670 pFileRead->Release(); |
689 } | 671 } |
690 delete this; | 672 delete this; |
691 } | 673 } |
692 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage, | 674 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage, |
693 uint32_t dwFontStyles, | 675 uint32_t dwFontStyles, |
694 const FX_WCHAR* pszFontFamily) { | 676 const FX_WCHAR* pszFontFamily) { |
695 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByCodePage( | 677 return nullptr; |
696 this, wCodePage, dwFontStyles, | |
697 pszFontFamily); | |
698 } | 678 } |
699 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset, | 679 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset, |
700 uint32_t dwFontStyles, | 680 uint32_t dwFontStyles, |
701 const FX_WCHAR* pszFontFamily) { | 681 const FX_WCHAR* pszFontFamily) { |
702 return NULL == m_pDelegate ? NULL | 682 return nullptr; |
703 : m_pDelegate->GetDefFontByCharset( | |
704 this, nCharset, dwFontStyles, pszFontFamily); | |
705 } | 683 } |
706 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode, | 684 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode, |
707 uint32_t dwFontStyles, | 685 uint32_t dwFontStyles, |
708 const FX_WCHAR* pszFontFamily) { | 686 const FX_WCHAR* pszFontFamily) { |
709 return NULL == m_pDelegate ? NULL | 687 return nullptr; |
710 : m_pDelegate->GetDefFontByUnicode( | |
711 this, wUnicode, dwFontStyles, pszFontFamily); | |
712 } | 688 } |
713 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage, | 689 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage, |
714 uint32_t dwFontStyles, | 690 uint32_t dwFontStyles, |
715 const FX_WCHAR* pszFontFamily) { | 691 const FX_WCHAR* pszFontFamily) { |
716 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByLanguage( | 692 return nullptr; |
717 this, wLanguage, dwFontStyles, | |
718 pszFontFamily); | |
719 } | 693 } |
720 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, | 694 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, |
721 uint32_t dwFontStyles, | 695 uint32_t dwFontStyles, |
722 const FX_WCHAR* pszFontFamily) { | 696 const FX_WCHAR* pszFontFamily) { |
723 CFX_ByteString bsHash; | 697 CFX_ByteString bsHash; |
724 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 698 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
725 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 699 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
726 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); | 700 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); |
727 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL; | 701 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL; |
728 IFX_Font* pFont = NULL; | 702 IFX_Font* pFont = NULL; |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 } | 1482 } |
1509 } | 1483 } |
1510 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1484 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, |
1511 const CFX_WideString& Name2) { | 1485 const CFX_WideString& Name2) { |
1512 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { | 1486 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { |
1513 return 1; | 1487 return 1; |
1514 } | 1488 } |
1515 return 0; | 1489 return 0; |
1516 } | 1490 } |
1517 #endif | 1491 #endif |
OLD | NEW |