| 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 IFGAS_FontMgr* IFGAS_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { | 16 IFGAS_FontMgr* IFGAS_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { |
| 17 return new CFGAS_StdFontMgrImp(pEnumerator); | 17 return new CFGAS_StdFontMgrImp(pEnumerator); |
| 18 } | 18 } |
| 19 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) | 19 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) |
| 20 : m_pEnumerator(pEnumerator), | 20 : m_pEnumerator(pEnumerator), |
| 21 m_FontFaces(), | 21 m_FontFaces(), |
| 22 m_CPFonts(8), | 22 m_CPFonts(8), |
| 23 m_FamilyFonts(16), | 23 m_FamilyFonts(16), |
| 24 m_UnicodeFonts(16), | 24 m_UnicodeFonts(16), |
| 25 m_BufferFonts(4), | 25 m_BufferFonts(4), |
| 26 m_FileFonts(4), | |
| 27 m_StreamFonts(4), | 26 m_StreamFonts(4), |
| 28 m_DeriveFonts(4) { | 27 m_DeriveFonts(4) { |
| 29 if (m_pEnumerator) { | 28 if (m_pEnumerator) { |
| 30 m_pEnumerator(m_FontFaces, NULL, 0xFEFF); | 29 m_pEnumerator(m_FontFaces, NULL, 0xFEFF); |
| 31 } | 30 } |
| 32 } | 31 } |
| 33 | 32 |
| 34 CFGAS_StdFontMgrImp::~CFGAS_StdFontMgrImp() { | 33 CFGAS_StdFontMgrImp::~CFGAS_StdFontMgrImp() { |
| 35 m_FontFaces.RemoveAll(); | 34 m_FontFaces.RemoveAll(); |
| 36 m_CPFonts.RemoveAll(); | 35 m_CPFonts.RemoveAll(); |
| 37 m_FamilyFonts.RemoveAll(); | 36 m_FamilyFonts.RemoveAll(); |
| 38 m_UnicodeFonts.RemoveAll(); | 37 m_UnicodeFonts.RemoveAll(); |
| 39 m_BufferFonts.RemoveAll(); | 38 m_BufferFonts.RemoveAll(); |
| 40 m_FileFonts.RemoveAll(); | |
| 41 m_StreamFonts.RemoveAll(); | 39 m_StreamFonts.RemoveAll(); |
| 42 m_DeriveFonts.RemoveAll(); | 40 m_DeriveFonts.RemoveAll(); |
| 43 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) | 41 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) |
| 44 m_Fonts[i]->Release(); | 42 m_Fonts[i]->Release(); |
| 45 } | 43 } |
| 46 | 44 |
| 47 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage( | 45 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage( |
| 48 uint16_t wCodePage, | 46 uint16_t wCodePage, |
| 49 uint32_t dwFontStyles, | 47 uint32_t dwFontStyles, |
| 50 const FX_WCHAR* pszFontFamily) { | 48 const FX_WCHAR* pszFontFamily) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 165 } |
| 168 } | 166 } |
| 169 pFont = CFGAS_GEFont::LoadFont(pBuffer, iLength, this); | 167 pFont = CFGAS_GEFont::LoadFont(pBuffer, iLength, this); |
| 170 if (pFont) { | 168 if (pFont) { |
| 171 m_Fonts.Add(pFont); | 169 m_Fonts.Add(pFont); |
| 172 m_BufferFonts.SetAt((void*)pBuffer, pFont); | 170 m_BufferFonts.SetAt((void*)pBuffer, pFont); |
| 173 return pFont->Retain(); | 171 return pFont->Retain(); |
| 174 } | 172 } |
| 175 return NULL; | 173 return NULL; |
| 176 } | 174 } |
| 177 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { | 175 |
| 178 ASSERT(pszFileName); | |
| 179 uint32_t dwHash = FX_HashCode_GetW(pszFileName, false); | |
| 180 CFGAS_GEFont* pFont = NULL; | |
| 181 if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | |
| 182 if (pFont) { | |
| 183 return pFont->Retain(); | |
| 184 } | |
| 185 } | |
| 186 pFont = CFGAS_GEFont::LoadFont(pszFileName); | |
| 187 if (pFont) { | |
| 188 m_Fonts.Add(pFont); | |
| 189 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | |
| 190 return pFont->Retain(); | |
| 191 } | |
| 192 return NULL; | |
| 193 } | |
| 194 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, | 176 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, |
| 195 const FX_WCHAR* pszFontAlias, | 177 const FX_WCHAR* pszFontAlias, |
| 196 uint32_t dwFontStyles, | 178 uint32_t dwFontStyles, |
| 197 uint16_t wCodePage, | 179 uint16_t wCodePage, |
| 198 FX_BOOL bSaveStream) { | 180 FX_BOOL bSaveStream) { |
| 199 ASSERT(pFontStream && pFontStream->GetLength() > 0); | 181 ASSERT(pFontStream && pFontStream->GetLength() > 0); |
| 200 CFGAS_GEFont* pFont = NULL; | 182 CFGAS_GEFont* pFont = NULL; |
| 201 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { | 183 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { |
| 202 if (pFont) { | 184 if (pFont) { |
| 203 if (pszFontAlias) { | 185 if (pszFontAlias) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 252 } |
| 271 fontMap.RemoveKey(pKey); | 253 fontMap.RemoveKey(pKey); |
| 272 break; | 254 break; |
| 273 } | 255 } |
| 274 } | 256 } |
| 275 void CFGAS_StdFontMgrImp::RemoveFont(CFGAS_GEFont* pFont) { | 257 void CFGAS_StdFontMgrImp::RemoveFont(CFGAS_GEFont* pFont) { |
| 276 RemoveFont(m_CPFonts, pFont); | 258 RemoveFont(m_CPFonts, pFont); |
| 277 RemoveFont(m_FamilyFonts, pFont); | 259 RemoveFont(m_FamilyFonts, pFont); |
| 278 RemoveFont(m_UnicodeFonts, pFont); | 260 RemoveFont(m_UnicodeFonts, pFont); |
| 279 RemoveFont(m_BufferFonts, pFont); | 261 RemoveFont(m_BufferFonts, pFont); |
| 280 RemoveFont(m_FileFonts, pFont); | |
| 281 RemoveFont(m_StreamFonts, pFont); | 262 RemoveFont(m_StreamFonts, pFont); |
| 282 RemoveFont(m_DeriveFonts, pFont); | 263 RemoveFont(m_DeriveFonts, pFont); |
| 283 int32_t iFind = m_Fonts.Find(pFont); | 264 int32_t iFind = m_Fonts.Find(pFont); |
| 284 if (iFind > -1) { | 265 if (iFind > -1) { |
| 285 m_Fonts.RemoveAt(iFind, 1); | 266 m_Fonts.RemoveAt(iFind, 1); |
| 286 } | 267 } |
| 287 } | 268 } |
| 288 FX_FONTDESCRIPTOR const* CFGAS_StdFontMgrImp::FindFont( | 269 FX_FONTDESCRIPTOR const* CFGAS_StdFontMgrImp::FindFont( |
| 289 const FX_WCHAR* pszFontFamily, | 270 const FX_WCHAR* pszFontFamily, |
| 290 uint32_t dwFontStyles, | 271 uint32_t dwFontStyles, |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 delete pDescs; | 613 delete pDescs; |
| 633 } | 614 } |
| 634 pos = m_Hash2Fonts.GetStartPosition(); | 615 pos = m_Hash2Fonts.GetStartPosition(); |
| 635 while (pos) { | 616 while (pos) { |
| 636 uint32_t dwHash; | 617 uint32_t dwHash; |
| 637 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; | 618 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |
| 638 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 619 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
| 639 delete pFonts; | 620 delete pFonts; |
| 640 } | 621 } |
| 641 m_Hash2Fonts.RemoveAll(); | 622 m_Hash2Fonts.RemoveAll(); |
| 642 pos = m_Hash2FileAccess.GetStartPosition(); | |
| 643 while (pos) { | |
| 644 uint32_t dwHash; | |
| 645 IFX_FileAccess* pFileAccess; | |
| 646 m_Hash2FileAccess.GetNextAssoc(pos, dwHash, pFileAccess); | |
| 647 if (NULL != pFileAccess) { | |
| 648 pFileAccess->Release(); | |
| 649 } | |
| 650 } | |
| 651 pos = m_FileAccess2IFXFont.GetStartPosition(); | |
| 652 while (pos) { | |
| 653 uint32_t dwHash; | |
| 654 CFGAS_GEFont* pFont; | |
| 655 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); | |
| 656 if (NULL != pFont) { | |
| 657 pFont->Release(); | |
| 658 } | |
| 659 } | |
| 660 pos = m_IFXFont2FileRead.GetStartPosition(); | 623 pos = m_IFXFont2FileRead.GetStartPosition(); |
| 661 while (pos) { | 624 while (pos) { |
| 662 CFGAS_GEFont* pFont; | 625 CFGAS_GEFont* pFont; |
| 663 IFX_FileRead* pFileRead; | 626 IFX_FileRead* pFileRead; |
| 664 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 627 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
| 665 pFileRead->Release(); | 628 pFileRead->Release(); |
| 666 } | 629 } |
| 667 delete this; | 630 delete this; |
| 668 } | 631 } |
| 669 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage( | 632 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 sortedFonts = new CFX_FontDescriptorInfos; | 680 sortedFonts = new CFX_FontDescriptorInfos; |
| 718 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, | 681 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, |
| 719 CFX_WideString(pszFontFamily), 0); | 682 CFX_WideString(pszFontFamily), 0); |
| 720 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); | 683 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); |
| 721 } | 684 } |
| 722 if (sortedFonts->GetSize() == 0) | 685 if (sortedFonts->GetSize() == 0) |
| 723 return nullptr; | 686 return nullptr; |
| 724 | 687 |
| 725 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; | 688 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; |
| 726 CFGAS_GEFont* pFont = | 689 CFGAS_GEFont* pFont = |
| 727 pDesc->m_pFileAccess | 690 LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); |
| 728 ? LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr) | |
| 729 : LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); | |
| 730 if (pFont) | 691 if (pFont) |
| 731 pFont->SetLogicalFontStyle(dwFontStyles); | 692 pFont->SetLogicalFontStyle(dwFontStyles); |
| 732 | 693 |
| 733 pFonts->Add(pFont); | 694 pFonts->Add(pFont); |
| 734 return pFont; | 695 return pFont; |
| 735 } | 696 } |
| 736 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCharset( | 697 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCharset( |
| 737 uint8_t nCharset, | 698 uint8_t nCharset, |
| 738 uint32_t dwFontStyles, | 699 uint32_t dwFontStyles, |
| 739 const FX_WCHAR* pszFontFamily) { | 700 const FX_WCHAR* pszFontFamily) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { | 734 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { |
| 774 sortedFonts = new CFX_FontDescriptorInfos; | 735 sortedFonts = new CFX_FontDescriptorInfos; |
| 775 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, | 736 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, |
| 776 CFX_WideString(pszFontFamily), wUnicode); | 737 CFX_WideString(pszFontFamily), wUnicode); |
| 777 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); | 738 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); |
| 778 } | 739 } |
| 779 for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) { | 740 for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) { |
| 780 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont; | 741 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont; |
| 781 if (!VerifyUnicode(pDesc, wUnicode)) | 742 if (!VerifyUnicode(pDesc, wUnicode)) |
| 782 continue; | 743 continue; |
| 783 if (pDesc->m_pFileAccess) | 744 pFont = LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); |
| 784 pFont = LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr); | |
| 785 else | |
| 786 pFont = LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); | |
| 787 if (!pFont) | 745 if (!pFont) |
| 788 continue; | 746 continue; |
| 789 pFont->SetLogicalFontStyle(dwFontStyles); | 747 pFont->SetLogicalFontStyle(dwFontStyles); |
| 790 pFonts->Add(pFont); | 748 pFonts->Add(pFont); |
| 791 return pFont; | 749 return pFont; |
| 792 } | 750 } |
| 793 if (!pszFontFamily) | 751 if (!pszFontFamily) |
| 794 m_FailedUnicodes2NULL.SetAt(wUnicode, nullptr); | 752 m_FailedUnicodes2NULL.SetAt(wUnicode, nullptr); |
| 795 return nullptr; | 753 return nullptr; |
| 796 } | 754 } |
| 797 FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(CFX_FontDescriptor* pDesc, | 755 FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(CFX_FontDescriptor* pDesc, |
| 798 FX_WCHAR wcUnicode) { | 756 FX_WCHAR wcUnicode) { |
| 799 IFX_FileRead* pFileRead = nullptr; | 757 IFX_FileRead* pFileRead = CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); |
| 800 if (pDesc->m_pFileAccess) | |
| 801 pFileRead = pDesc->m_pFileAccess->CreateFileStream(FX_FILEMODE_ReadOnly); | |
| 802 else | |
| 803 pFileRead = CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); | |
| 804 if (!pFileRead) | 758 if (!pFileRead) |
| 805 return FALSE; | 759 return FALSE; |
| 806 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); | 760 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); |
| 807 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); | 761 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); |
| 808 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); | 762 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); |
| 809 pFileRead->Release(); | 763 pFileRead->Release(); |
| 810 if (!pFace) | 764 if (!pFace) |
| 811 return FALSE; | 765 return FALSE; |
| 812 if (FXFT_Get_Face_External_Stream(pFace)) | 766 if (FXFT_Get_Face_External_Stream(pFace)) |
| 813 FXFT_Clear_Face_External_Stream(pFace); | 767 FXFT_Clear_Face_External_Stream(pFace); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 833 } | 787 } |
| 834 | 788 |
| 835 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByLanguage( | 789 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByLanguage( |
| 836 uint16_t wLanguage, | 790 uint16_t wLanguage, |
| 837 uint32_t dwFontStyles, | 791 uint32_t dwFontStyles, |
| 838 const FX_WCHAR* pszFontFamily) { | 792 const FX_WCHAR* pszFontFamily) { |
| 839 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, | 793 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, |
| 840 pszFontFamily); | 794 pszFontFamily); |
| 841 } | 795 } |
| 842 | 796 |
| 843 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const uint8_t* pBuffer, | |
| 844 int32_t iLength, | |
| 845 int32_t iFaceIndex, | |
| 846 int32_t* pFaceCount) { | |
| 847 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; | |
| 848 uint32_t dwHash = | |
| 849 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); | |
| 850 IFX_FileAccess* pFontAccess = nullptr; | |
| 851 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); | |
| 852 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) | |
| 853 : nullptr; | |
| 854 } | |
| 855 | |
| 856 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, | |
| 857 int32_t iFaceIndex, | |
| 858 int32_t* pFaceCount) { | |
| 859 CFX_ByteString bsHash; | |
| 860 bsHash += CFX_WideString(pszFileName).UTF8Encode(); | |
| 861 | |
| 862 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | |
| 863 IFX_FileAccess* pFontAccess = nullptr; | |
| 864 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { | |
| 865 pFontAccess = FX_CreateDefaultFileAccess(pszFileName); | |
| 866 m_Hash2FileAccess.SetAt(dwHash, pFontAccess); | |
| 867 } | |
| 868 | |
| 869 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) | |
| 870 : nullptr; | |
| 871 } | |
| 872 | |
| 873 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(IFX_Stream* pFontStream, | |
| 874 int32_t iFaceIndex, | |
| 875 int32_t* pFaceCount, | |
| 876 FX_BOOL bSaveStream) { | |
| 877 void* Hash[1] = {(void*)(uintptr_t)pFontStream}; | |
| 878 uint32_t dwHash = | |
| 879 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); | |
| 880 IFX_FileAccess* pFontAccess = nullptr; | |
| 881 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); | |
| 882 | |
| 883 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) | |
| 884 : nullptr; | |
| 885 } | |
| 886 | |
| 887 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, | |
| 888 int32_t iFaceIndex, | |
| 889 int32_t* pFaceCount, | |
| 890 FX_BOOL bWantCache) { | |
| 891 uint32_t dwHash = 0; | |
| 892 CFGAS_GEFont* pFont = nullptr; | |
| 893 if (bWantCache) { | |
| 894 CFX_ByteString bsHash; | |
| 895 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); | |
| 896 dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | |
| 897 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { | |
| 898 if (pFont) { | |
| 899 if (pFaceCount) | |
| 900 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; | |
| 901 return pFont->Retain(); | |
| 902 } | |
| 903 } | |
| 904 } | |
| 905 | |
| 906 CFX_Font* pInternalFont = new CFX_Font; | |
| 907 IFX_FileRead* pFontStream = | |
| 908 pFontAccess->CreateFileStream(FX_FILEMODE_ReadOnly); | |
| 909 if (!pFontStream) { | |
| 910 delete pInternalFont; | |
| 911 return nullptr; | |
| 912 } | |
| 913 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { | |
| 914 delete pInternalFont; | |
| 915 pFontStream->Release(); | |
| 916 return nullptr; | |
| 917 } | |
| 918 pFont = CFGAS_GEFont::LoadFont(pInternalFont, this, TRUE); | |
| 919 if (!pFont) { | |
| 920 delete pInternalFont; | |
| 921 pFontStream->Release(); | |
| 922 return nullptr; | |
| 923 } | |
| 924 if (bWantCache) | |
| 925 m_FileAccess2IFXFont.SetAt(dwHash, pFont); | |
| 926 | |
| 927 m_IFXFont2FileRead.SetAt(pFont, pFontStream); | |
| 928 if (pFaceCount) | |
| 929 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; | |
| 930 | |
| 931 return pFont; | |
| 932 } | |
| 933 | |
| 934 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName, | 797 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName, |
| 935 int32_t iFaceIndex, | 798 int32_t iFaceIndex, |
| 936 int32_t* pFaceCount) { | 799 int32_t* pFaceCount) { |
| 937 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 800 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
| 938 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | 801 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
| 939 if (!pFontMapper) | 802 if (!pFontMapper) |
| 940 return nullptr; | 803 return nullptr; |
| 941 | 804 |
| 942 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 805 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
| 943 if (!pSystemFontInfo) | 806 if (!pSystemFontInfo) |
| 944 return nullptr; | 807 return nullptr; |
| 945 | 808 |
| 946 IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode()); | 809 IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode()); |
| 947 if (!pFontStream) | 810 if (!pFontStream) |
| 948 return nullptr; | 811 return nullptr; |
| 949 | 812 |
| 950 if (!LoadFace(pFontStream, 0)) { | 813 if (!LoadFace(pFontStream, 0)) { |
| 951 pFontStream->Release(); | 814 pFontStream->Release(); |
| 952 return nullptr; | 815 return nullptr; |
| 953 } | 816 } |
| 954 | 817 |
| 955 CFX_Font* pInternalFont = new CFX_Font(); | 818 CFX_Font* pInternalFont = new CFX_Font(); |
| 956 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { | 819 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { |
| 957 pFontStream->Release(); | 820 pFontStream->Release(); |
| 958 return nullptr; | 821 return nullptr; |
| 959 } | 822 } |
| 960 | 823 |
| 961 CFGAS_GEFont* pFont = CFGAS_GEFont::LoadFont(pInternalFont, this, FALSE); | 824 CFGAS_GEFont* pFont = CFGAS_GEFont::LoadFont(pInternalFont, this); |
| 962 if (!pFont) { | 825 if (!pFont) { |
| 963 pFontStream->Release(); | 826 pFontStream->Release(); |
| 964 return nullptr; | 827 return nullptr; |
| 965 } | 828 } |
| 966 | 829 |
| 967 m_IFXFont2FileRead.SetAt(pFont, pFontStream); | 830 m_IFXFont2FileRead.SetAt(pFont, pFontStream); |
| 968 if (pFaceCount) | 831 if (pFaceCount) |
| 969 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; | 832 *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; |
| 970 | 833 |
| 971 return pFont; | 834 return pFont; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 return nPenalty; | 1075 return nPenalty; |
| 1213 } | 1076 } |
| 1214 void CFGAS_FontMgrImp::ClearFontCache() { | 1077 void CFGAS_FontMgrImp::ClearFontCache() { |
| 1215 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 1078 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
| 1216 while (pos) { | 1079 while (pos) { |
| 1217 uint32_t dwHash; | 1080 uint32_t dwHash; |
| 1218 CFX_FontDescriptorInfos* pDescs; | 1081 CFX_FontDescriptorInfos* pDescs; |
| 1219 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 1082 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
| 1220 delete pDescs; | 1083 delete pDescs; |
| 1221 } | 1084 } |
| 1222 pos = m_FileAccess2IFXFont.GetStartPosition(); | |
| 1223 while (pos) { | |
| 1224 uint32_t dwHash; | |
| 1225 CFGAS_GEFont* pFont; | |
| 1226 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); | |
| 1227 if (NULL != pFont) { | |
| 1228 pFont->Release(); | |
| 1229 } | |
| 1230 } | |
| 1231 pos = m_IFXFont2FileRead.GetStartPosition(); | 1085 pos = m_IFXFont2FileRead.GetStartPosition(); |
| 1232 while (pos) { | 1086 while (pos) { |
| 1233 CFGAS_GEFont* pFont; | 1087 CFGAS_GEFont* pFont; |
| 1234 IFX_FileRead* pFileRead; | 1088 IFX_FileRead* pFileRead; |
| 1235 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 1089 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
| 1236 pFileRead->Release(); | 1090 pFileRead->Release(); |
| 1237 } | 1091 } |
| 1238 } | 1092 } |
| 1239 void CFGAS_FontMgrImp::RemoveFont(CFGAS_GEFont* pEFont) { | 1093 void CFGAS_FontMgrImp::RemoveFont(CFGAS_GEFont* pEFont) { |
| 1240 if (NULL == pEFont) { | 1094 if (NULL == pEFont) { |
| 1241 return; | 1095 return; |
| 1242 } | 1096 } |
| 1243 IFX_FileRead* pFileRead; | 1097 IFX_FileRead* pFileRead; |
| 1244 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { | 1098 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { |
| 1245 pFileRead->Release(); | 1099 pFileRead->Release(); |
| 1246 m_IFXFont2FileRead.RemoveKey(pEFont); | 1100 m_IFXFont2FileRead.RemoveKey(pEFont); |
| 1247 } | 1101 } |
| 1248 FX_POSITION pos; | 1102 FX_POSITION pos; |
| 1249 pos = m_FileAccess2IFXFont.GetStartPosition(); | |
| 1250 while (pos) { | |
| 1251 uint32_t dwHash; | |
| 1252 CFGAS_GEFont* pCFont; | |
| 1253 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pCFont); | |
| 1254 if (pCFont == pEFont) { | |
| 1255 m_FileAccess2IFXFont.RemoveKey(dwHash); | |
| 1256 break; | |
| 1257 } | |
| 1258 } | |
| 1259 pos = m_Hash2Fonts.GetStartPosition(); | 1103 pos = m_Hash2Fonts.GetStartPosition(); |
| 1260 while (pos) { | 1104 while (pos) { |
| 1261 uint32_t dwHash; | 1105 uint32_t dwHash; |
| 1262 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; | 1106 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |
| 1263 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 1107 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
| 1264 if (NULL != pFonts) { | 1108 if (NULL != pFonts) { |
| 1265 for (int32_t i = 0; i < pFonts->GetSize(); i++) { | 1109 for (int32_t i = 0; i < pFonts->GetSize(); i++) { |
| 1266 if (pFonts->GetAt(i) == pEFont) { | 1110 if (pFonts->GetAt(i) == pEFont) { |
| 1267 pFonts->SetAt(i, NULL); | 1111 pFonts->SetAt(i, NULL); |
| 1268 } | 1112 } |
| 1269 } | 1113 } |
| 1270 } else { | 1114 } else { |
| 1271 m_Hash2Fonts.RemoveKey(dwHash); | 1115 m_Hash2Fonts.RemoveKey(dwHash); |
| 1272 } | 1116 } |
| 1273 } | 1117 } |
| 1274 } | 1118 } |
| 1275 | 1119 |
| 1276 void CFGAS_FontMgrImp::RegisterFace(FXFT_Face pFace, | 1120 void CFGAS_FontMgrImp::RegisterFace(FXFT_Face pFace, |
| 1277 CFX_FontDescriptors& Fonts, | 1121 CFX_FontDescriptors& Fonts, |
| 1278 const CFX_WideString* pFaceName, | 1122 const CFX_WideString* pFaceName) { |
| 1279 IFX_FileAccess* pFontAccess) { | |
| 1280 if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0) | 1123 if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0) |
| 1281 return; | 1124 return; |
| 1282 | 1125 |
| 1283 CFX_FontDescriptor* pFont = new CFX_FontDescriptor; | 1126 CFX_FontDescriptor* pFont = new CFX_FontDescriptor; |
| 1284 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; | 1127 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; |
| 1285 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; | 1128 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; |
| 1286 pFont->m_dwFontStyles |= GetFlags(pFace); | 1129 pFont->m_dwFontStyles |= GetFlags(pFace); |
| 1287 | 1130 |
| 1288 CFX_ArrayTemplate<uint16_t> Charsets; | 1131 CFX_ArrayTemplate<uint16_t> Charsets; |
| 1289 GetCharsets(pFace, Charsets); | 1132 GetCharsets(pFace, Charsets); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1305 } | 1148 } |
| 1306 GetNames(pTable, pFont->m_wsFamilyNames); | 1149 GetNames(pTable, pFont->m_wsFamilyNames); |
| 1307 if (pTable) | 1150 if (pTable) |
| 1308 FX_Free(pTable); | 1151 FX_Free(pTable); |
| 1309 | 1152 |
| 1310 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); | 1153 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); |
| 1311 pFont->m_wsFaceName = | 1154 pFont->m_wsFaceName = |
| 1312 pFaceName ? *pFaceName | 1155 pFaceName ? *pFaceName |
| 1313 : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); | 1156 : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); |
| 1314 pFont->m_nFaceIndex = pFace->face_index; | 1157 pFont->m_nFaceIndex = pFace->face_index; |
| 1315 pFont->m_pFileAccess = pFontAccess ? pFontAccess->Retain() : nullptr; | |
| 1316 | 1158 |
| 1317 Fonts.Add(pFont); | 1159 Fonts.Add(pFont); |
| 1318 } | 1160 } |
| 1319 | 1161 |
| 1320 void CFGAS_FontMgrImp::RegisterFaces(IFX_FileRead* pFontStream, | 1162 void CFGAS_FontMgrImp::RegisterFaces(IFX_FileRead* pFontStream, |
| 1321 const CFX_WideString* pFaceName) { | 1163 const CFX_WideString* pFaceName) { |
| 1322 int32_t index = 0; | 1164 int32_t index = 0; |
| 1323 int32_t num_faces = 0; | 1165 int32_t num_faces = 0; |
| 1324 do { | 1166 do { |
| 1325 FXFT_Face pFace = LoadFace(pFontStream, index++); | 1167 FXFT_Face pFace = LoadFace(pFontStream, index++); |
| 1326 if (!pFace) | 1168 if (!pFace) |
| 1327 continue; | 1169 continue; |
| 1328 // All faces keep number of faces. It can be retrieved from any one face. | 1170 // All faces keep number of faces. It can be retrieved from any one face. |
| 1329 if (num_faces == 0) | 1171 if (num_faces == 0) |
| 1330 num_faces = pFace->num_faces; | 1172 num_faces = pFace->num_faces; |
| 1331 RegisterFace(pFace, m_InstalledFonts, pFaceName, nullptr); | 1173 RegisterFace(pFace, m_InstalledFonts, pFaceName); |
| 1332 if (FXFT_Get_Face_External_Stream(pFace)) | 1174 if (FXFT_Get_Face_External_Stream(pFace)) |
| 1333 FXFT_Clear_Face_External_Stream(pFace); | 1175 FXFT_Clear_Face_External_Stream(pFace); |
| 1334 FXFT_Done_Face(pFace); | 1176 FXFT_Done_Face(pFace); |
| 1335 } while (index < num_faces); | 1177 } while (index < num_faces); |
| 1336 } | 1178 } |
| 1337 uint32_t CFGAS_FontMgrImp::GetFlags(FXFT_Face pFace) { | 1179 uint32_t CFGAS_FontMgrImp::GetFlags(FXFT_Face pFace) { |
| 1338 uint32_t flag = 0; | 1180 uint32_t flag = 0; |
| 1339 if (FT_IS_FIXED_WIDTH(pFace)) { | 1181 if (FT_IS_FIXED_WIDTH(pFace)) { |
| 1340 flag |= FX_FONTSTYLE_FixedPitch; | 1182 flag |= FX_FONTSTYLE_FixedPitch; |
| 1341 } | 1183 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 } | 1344 } |
| 1503 } | 1345 } |
| 1504 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1346 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, |
| 1505 const CFX_WideString& Name2) { | 1347 const CFX_WideString& Name2) { |
| 1506 if (Name1.Find(Name2.c_str()) != -1) { | 1348 if (Name1.Find(Name2.c_str()) != -1) { |
| 1507 return 1; | 1349 return 1; |
| 1508 } | 1350 } |
| 1509 return 0; | 1351 return 0; |
| 1510 } | 1352 } |
| 1511 #endif | 1353 #endif |
| OLD | NEW |