Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: xfa/fgas/font/fgas_stdfontmgr.cpp

Issue 1874433002: Record all fonts, not just one per charset. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxge/include/fx_font.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fgas/font/fgas_stdfontmgr.h" 7 #include "xfa/fgas/font/fgas_stdfontmgr.h"
8 8
9 #include "core/fxcrt/include/fx_stream.h" 9 #include "core/fxcrt/include/fx_stream.h"
10 #include "xfa/fgas/crt/fgas_codepage.h" 10 #include "xfa/fgas/crt/fgas_codepage.h"
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 void* pUserData) 588 void* pUserData)
589 : m_pFontSource(pFontEnum), 589 : m_pFontSource(pFontEnum),
590 m_pDelegate(pDelegate), 590 m_pDelegate(pDelegate),
591 m_pUserData(pUserData) {} 591 m_pUserData(pUserData) {}
592 592
593 FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() { 593 FX_BOOL CFX_FontMgrImp::EnumFontsFromFontMapper() {
594 CFX_FontMapper* pFontMapper = 594 CFX_FontMapper* pFontMapper =
595 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); 595 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper();
596 if (!pFontMapper) 596 if (!pFontMapper)
597 return FALSE; 597 return FALSE;
598
598 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); 599 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
599 if (!pSystemFontInfo) 600 if (!pSystemFontInfo)
600 return FALSE; 601 return FALSE;
602
601 pSystemFontInfo->EnumFontList(pFontMapper); 603 pSystemFontInfo->EnumFontList(pFontMapper);
602 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { 604 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) {
603 IFX_FileRead* pFontStream = 605 IFX_FileRead* pFontStream =
604 CreateFontStream(pFontMapper, pSystemFontInfo, i); 606 CreateFontStream(pFontMapper, pSystemFontInfo, i);
605 if (!pFontStream) 607 if (!pFontStream)
606 continue; 608 continue;
609
607 CFX_WideString wsFaceName = 610 CFX_WideString wsFaceName =
608 CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str()); 611 CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str());
609 RegisterFaces(pFontStream, &wsFaceName); 612 RegisterFaces(pFontStream, &wsFaceName);
610 pFontStream->Release(); 613 pFontStream->Release();
611 } 614 }
612 if (m_InstalledFonts.GetSize() == 0) 615 if (m_InstalledFonts.GetSize() == 0)
613 return FALSE; 616 return FALSE;
617
614 return TRUE; 618 return TRUE;
615 } 619 }
620
616 FX_BOOL CFX_FontMgrImp::EnumFontsFromFiles() { 621 FX_BOOL CFX_FontMgrImp::EnumFontsFromFiles() {
617 CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary(); 622 CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary();
618 FX_POSITION pos = m_pFontSource->GetStartPosition(); 623 FX_POSITION pos = m_pFontSource->GetStartPosition();
619 IFX_FileAccess* pFontSource = nullptr; 624 IFX_FileAccess* pFontSource = nullptr;
620 IFX_FileRead* pFontStream = nullptr; 625 IFX_FileRead* pFontStream = nullptr;
621 while (pos) { 626 while (pos) {
622 pFontSource = m_pFontSource->GetNext(pos); 627 pFontSource = m_pFontSource->GetNext(pos);
623 pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); 628 pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly);
624 if (!pFontStream) { 629 if (!pFontStream) {
625 pFontSource->Release(); 630 pFontSource->Release();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 : m_pDelegate->GetDefFontByUnicode( 714 : m_pDelegate->GetDefFontByUnicode(
710 this, wUnicode, dwFontStyles, pszFontFamily); 715 this, wUnicode, dwFontStyles, pszFontFamily);
711 } 716 }
712 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage, 717 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage,
713 uint32_t dwFontStyles, 718 uint32_t dwFontStyles,
714 const FX_WCHAR* pszFontFamily) { 719 const FX_WCHAR* pszFontFamily) {
715 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByLanguage( 720 return NULL == m_pDelegate ? NULL : m_pDelegate->GetDefFontByLanguage(
716 this, wLanguage, dwFontStyles, 721 this, wLanguage, dwFontStyles,
717 pszFontFamily); 722 pszFontFamily);
718 } 723 }
724
719 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, 725 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage,
720 uint32_t dwFontStyles, 726 uint32_t dwFontStyles,
721 const FX_WCHAR* pszFontFamily) { 727 const FX_WCHAR* pszFontFamily) {
722 CFX_ByteString bsHash; 728 CFX_ByteString bsHash;
723 bsHash.Format("%d, %d", wCodePage, dwFontStyles); 729 bsHash.Format("%d, %d", wCodePage, dwFontStyles);
724 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); 730 bsHash += CFX_WideString(pszFontFamily).UTF8Encode();
725 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); 731 uint32_t dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength());
726 CFX_ArrayTemplate<IFX_Font*>* pFonts = NULL; 732
727 IFX_Font* pFont = NULL; 733 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr;
728 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { 734 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) {
729 if (NULL == pFonts) { 735 if (!pFonts)
730 return NULL; 736 return nullptr;
731 } 737
732 if (0 != pFonts->GetSize()) { 738 if (pFonts->GetSize() != 0)
733 return pFonts->GetAt(0)->Retain(); 739 return pFonts->GetAt(0)->Retain();
734 }
735 } 740 }
741
736 if (!pFonts) 742 if (!pFonts)
737 pFonts = new CFX_ArrayTemplate<IFX_Font*>; 743 pFonts = new CFX_ArrayTemplate<IFX_Font*>;
744
738 m_Hash2Fonts.SetAt(dwHash, pFonts); 745 m_Hash2Fonts.SetAt(dwHash, pFonts);
739 CFX_FontDescriptorInfos* sortedFonts = NULL; 746 CFX_FontDescriptorInfos* sortedFonts = nullptr;
740 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { 747 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) {
741 sortedFonts = new CFX_FontDescriptorInfos; 748 sortedFonts = new CFX_FontDescriptorInfos;
742 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, 749 MatchFonts(*sortedFonts, wCodePage, dwFontStyles,
743 CFX_WideString(pszFontFamily), 0); 750 CFX_WideString(pszFontFamily), 0);
744 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); 751 m_Hash2CandidateList.SetAt(dwHash, sortedFonts);
745 } 752 }
746 if (sortedFonts->GetSize() == 0) { 753 if (sortedFonts->GetSize() == 0)
747 return NULL; 754 return nullptr;
748 } 755
749 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; 756 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont;
750 if (pDesc->m_pFileAccess) 757 IFX_Font* pFont =
751 pFont = LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr); 758 pDesc->m_pFileAccess
752 else 759 ? LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr)
753 pFont = LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); 760 : LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr);
754 if (NULL != pFont) { 761 if (pFont)
755 pFont->SetLogicalFontStyle(dwFontStyles); 762 pFont->SetLogicalFontStyle(dwFontStyles);
756 } 763
757 pFonts->Add(pFont); 764 pFonts->Add(pFont);
758 return pFont; 765 return pFont;
759 } 766 }
760 IFX_Font* CFX_FontMgrImp::GetFontByCharset(uint8_t nCharset, 767 IFX_Font* CFX_FontMgrImp::GetFontByCharset(uint8_t nCharset,
761 uint32_t dwFontStyles, 768 uint32_t dwFontStyles,
762 const FX_WCHAR* pszFontFamily) { 769 const FX_WCHAR* pszFontFamily) {
763 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, 770 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles,
764 pszFontFamily); 771 pszFontFamily);
765 } 772 }
766 IFX_Font* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode, 773 IFX_Font* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); 836 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE);
830 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); 837 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode);
831 pFileRead->Release(); 838 pFileRead->Release();
832 if (!pFace) 839 if (!pFace)
833 return FALSE; 840 return FALSE;
834 if (FXFT_Get_Face_External_Stream(pFace)) 841 if (FXFT_Get_Face_External_Stream(pFace))
835 FXFT_Clear_Face_External_Stream(pFace); 842 FXFT_Clear_Face_External_Stream(pFace);
836 FXFT_Done_Face(pFace); 843 FXFT_Done_Face(pFace);
837 return !retCharmap && retIndex; 844 return !retCharmap && retIndex;
838 } 845 }
846
839 FX_BOOL CFX_FontMgrImp::VerifyUnicode(IFX_Font* pFont, FX_WCHAR wcUnicode) { 847 FX_BOOL CFX_FontMgrImp::VerifyUnicode(IFX_Font* pFont, FX_WCHAR wcUnicode) {
840 if (NULL == pFont) { 848 if (!pFont)
841 return FALSE; 849 return FALSE;
842 } 850
843 FXFT_Face pFace = ((CFX_Font*)pFont->GetDevFont())->GetFace(); 851 FXFT_Face pFace = ((CFX_Font*)pFont->GetDevFont())->GetFace();
844 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); 852 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace);
845 if (0 != FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE)) { 853 if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0)
846 return FALSE; 854 return FALSE;
847 } 855
848 if (0 == FXFT_Get_Char_Index(pFace, wcUnicode)) { 856 if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) {
849 FXFT_Set_Charmap(pFace, charmap); 857 FXFT_Set_Charmap(pFace, charmap);
850 return FALSE; 858 return FALSE;
851 } 859 }
852 return TRUE; 860 return TRUE;
853 } 861 }
862
854 IFX_Font* CFX_FontMgrImp::GetFontByLanguage(uint16_t wLanguage, 863 IFX_Font* CFX_FontMgrImp::GetFontByLanguage(uint16_t wLanguage,
855 uint32_t dwFontStyles, 864 uint32_t dwFontStyles,
856 const FX_WCHAR* pszFontFamily) { 865 const FX_WCHAR* pszFontFamily) {
857 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, 866 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles,
858 pszFontFamily); 867 pszFontFamily);
859 } 868 }
869
860 IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer, 870 IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer,
861 int32_t iLength, 871 int32_t iLength,
862 int32_t iFaceIndex, 872 int32_t iFaceIndex,
863 int32_t* pFaceCount) { 873 int32_t* pFaceCount) {
864 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; 874 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength};
865 uint32_t dwHash = 875 uint32_t dwHash =
866 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 2 * sizeof(void*)); 876 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 2 * sizeof(void*));
867 IFX_FileAccess* pFontAccess = NULL; 877 IFX_FileAccess* pFontAccess = nullptr;
868 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { 878 m_Hash2FileAccess.Lookup(dwHash, pFontAccess);
869 } 879 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE)
870 if (NULL != pFontAccess) { 880 : nullptr;
871 return LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE);
872 } else {
873 return NULL;
874 }
875 } 881 }
882
876 IFX_Font* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, 883 IFX_Font* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName,
877 int32_t iFaceIndex, 884 int32_t iFaceIndex,
878 int32_t* pFaceCount) { 885 int32_t* pFaceCount) {
879 CFX_ByteString bsHash; 886 CFX_ByteString bsHash;
880 bsHash += CFX_WideString(pszFileName).UTF8Encode(); 887 bsHash += CFX_WideString(pszFileName).UTF8Encode();
888
881 uint32_t dwHash = 889 uint32_t dwHash =
882 FX_HashCode_String_GetA((const FX_CHAR*)bsHash, bsHash.GetLength()); 890 FX_HashCode_String_GetA((const FX_CHAR*)bsHash, bsHash.GetLength());
883 IFX_FileAccess* pFontAccess = NULL; 891 IFX_FileAccess* pFontAccess = nullptr;
884 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { 892 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) {
885 pFontAccess = FX_CreateDefaultFileAccess(pszFileName); 893 pFontAccess = FX_CreateDefaultFileAccess(pszFileName);
886 m_Hash2FileAccess.SetAt(dwHash, pFontAccess); 894 m_Hash2FileAccess.SetAt(dwHash, pFontAccess);
887 } 895 }
888 if (NULL != pFontAccess) { 896
889 return LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE); 897 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE)
890 } else { 898 : nullptr;
891 return NULL;
892 }
893 } 899 }
900
894 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream, 901 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream,
895 int32_t iFaceIndex, 902 int32_t iFaceIndex,
896 int32_t* pFaceCount, 903 int32_t* pFaceCount,
897 FX_BOOL bSaveStream) { 904 FX_BOOL bSaveStream) {
898 void* Hash[1] = {(void*)(uintptr_t)pFontStream}; 905 void* Hash[1] = {(void*)(uintptr_t)pFontStream};
899 uint32_t dwHash = 906 uint32_t dwHash =
900 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 1 * sizeof(void*)); 907 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 1 * sizeof(void*));
901 IFX_FileAccess* pFontAccess = NULL; 908 IFX_FileAccess* pFontAccess = nullptr;
902 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { 909 m_Hash2FileAccess.Lookup(dwHash, pFontAccess);
903 } 910
904 if (NULL != pFontAccess) { 911 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE)
905 return LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE); 912 : nullptr;
906 } else {
907 return NULL;
908 }
909 } 913 }
914
910 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, 915 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess,
911 int32_t iFaceIndex, 916 int32_t iFaceIndex,
912 int32_t* pFaceCount, 917 int32_t* pFaceCount,
913 FX_BOOL bWantCache) { 918 FX_BOOL bWantCache) {
914 uint32_t dwHash = 0; 919 uint32_t dwHash = 0;
915 IFX_Font* pFont = NULL; 920 IFX_Font* pFont = nullptr;
916 if (bWantCache) { 921 if (bWantCache) {
917 CFX_ByteString bsHash; 922 CFX_ByteString bsHash;
918 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); 923 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex);
919 dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength()); 924 dwHash = FX_HashCode_String_GetA(bsHash, bsHash.GetLength());
920 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { 925 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) {
921 if (NULL != pFont) { 926 if (pFont) {
922 if (NULL != pFaceCount) { 927 if (pFaceCount)
923 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; 928 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces;
924 }
925 return pFont->Retain(); 929 return pFont->Retain();
926 } 930 }
927 } 931 }
928 } 932 }
933
929 CFX_Font* pInternalFont = new CFX_Font; 934 CFX_Font* pInternalFont = new CFX_Font;
930 IFX_FileRead* pFontStream = 935 IFX_FileRead* pFontStream =
931 pFontAccess->CreateFileStream(FX_FILEMODE_ReadOnly); 936 pFontAccess->CreateFileStream(FX_FILEMODE_ReadOnly);
932 if (NULL == pFontStream) { 937 if (!pFontStream) {
933 delete pInternalFont; 938 delete pInternalFont;
934 return NULL; 939 return nullptr;
935 } 940 }
936 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { 941 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) {
937 delete pInternalFont; 942 delete pInternalFont;
938 pFontStream->Release(); 943 pFontStream->Release();
939 return NULL; 944 return nullptr;
940 } 945 }
941 pFont = IFX_Font::LoadFont(pInternalFont, this, TRUE); 946 pFont = IFX_Font::LoadFont(pInternalFont, this, TRUE);
942 if (NULL == pFont) { 947 if (!pFont) {
943 delete pInternalFont; 948 delete pInternalFont;
944 pFontStream->Release(); 949 pFontStream->Release();
945 return NULL; 950 return nullptr;
946 } 951 }
947 if (bWantCache) { 952 if (bWantCache)
948 m_FileAccess2IFXFont.SetAt(dwHash, pFont); 953 m_FileAccess2IFXFont.SetAt(dwHash, pFont);
949 } 954
950 m_IFXFont2FileRead.SetAt(pFont, pFontStream); 955 m_IFXFont2FileRead.SetAt(pFont, pFontStream);
951 if (NULL != pFaceCount) { 956 if (pFaceCount)
952 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; 957 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces;
953 } 958
954 return pFont; 959 return pFont;
955 } 960 }
961
956 IFX_Font* CFX_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName, 962 IFX_Font* CFX_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName,
957 int32_t iFaceIndex, 963 int32_t iFaceIndex,
958 int32_t* pFaceCount) { 964 int32_t* pFaceCount) {
959 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); 965 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
960 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); 966 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper();
961 if (!pFontMapper) 967 if (!pFontMapper)
962 return nullptr; 968 return nullptr;
969
963 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); 970 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
964 if (!pSystemFontInfo) 971 if (!pSystemFontInfo)
965 return nullptr; 972 return nullptr;
973
966 IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode()); 974 IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode());
967 if (!pFontStream) 975 if (!pFontStream)
968 return nullptr; 976 return nullptr;
977
969 if (!LoadFace(pFontStream, 0)) { 978 if (!LoadFace(pFontStream, 0)) {
970 pFontStream->Release(); 979 pFontStream->Release();
971 return nullptr; 980 return nullptr;
972 } 981 }
982
973 CFX_Font* pInternalFont = new CFX_Font(); 983 CFX_Font* pInternalFont = new CFX_Font();
974 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { 984 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) {
975 pFontStream->Release(); 985 pFontStream->Release();
976 return nullptr; 986 return nullptr;
977 } 987 }
988
978 IFX_Font* pFont = IFX_Font::LoadFont(pInternalFont, this, FALSE); 989 IFX_Font* pFont = IFX_Font::LoadFont(pInternalFont, this, FALSE);
979 if (!pFont) { 990 if (!pFont) {
980 pFontStream->Release(); 991 pFontStream->Release();
981 return nullptr; 992 return nullptr;
982 } 993 }
994
983 m_IFXFont2FileRead.SetAt(pFont, pFontStream); 995 m_IFXFont2FileRead.SetAt(pFont, pFontStream);
984 if (pFaceCount) 996 if (pFaceCount)
985 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; 997 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces;
998
986 return pFont; 999 return pFont;
987 } 1000 }
1001
988 extern "C" { 1002 extern "C" {
1003
989 unsigned long _ftStreamRead(FXFT_Stream stream, 1004 unsigned long _ftStreamRead(FXFT_Stream stream,
990 unsigned long offset, 1005 unsigned long offset,
991 unsigned char* buffer, 1006 unsigned char* buffer,
992 unsigned long count) { 1007 unsigned long count) {
993 if (count == 0) { 1008 if (count == 0)
994 return 0; 1009 return 0;
995 } 1010
996 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer; 1011 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer;
997 int res = pFile->ReadBlock(buffer, offset, count); 1012 int res = pFile->ReadBlock(buffer, offset, count);
998 if (res) { 1013 if (res)
999 return count; 1014 return count;
1000 }
1001 return 0; 1015 return 0;
1002 } 1016 }
1017
1003 void _ftStreamClose(FXFT_Stream stream) {} 1018 void _ftStreamClose(FXFT_Stream stream) {}
1004 }; 1019
1020 }; // extern "C"
1005 1021
1006 FXFT_Face CFX_FontMgrImp::LoadFace(IFX_FileRead* pFontStream, 1022 FXFT_Face CFX_FontMgrImp::LoadFace(IFX_FileRead* pFontStream,
1007 int32_t iFaceIndex) { 1023 int32_t iFaceIndex) {
1008 if (!pFontStream) 1024 if (!pFontStream)
1009 return nullptr; 1025 return nullptr;
1010 1026
1011 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); 1027 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
1012 pFontMgr->InitFTLibrary(); 1028 pFontMgr->InitFTLibrary();
1013 FXFT_Library library = pFontMgr->GetFTLibrary(); 1029 FXFT_Library library = pFontMgr->GetFTLibrary();
1014 if (!library) 1030 if (!library)
1015 return nullptr; 1031 return nullptr;
1016 1032
1017 FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); 1033 FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1);
1018 FXSYS_memset(ftStream, 0, sizeof(FXFT_StreamRec)); 1034 FXSYS_memset(ftStream, 0, sizeof(FXFT_StreamRec));
1019 ftStream->base = NULL; 1035 ftStream->base = nullptr;
1020 ftStream->descriptor.pointer = pFontStream; 1036 ftStream->descriptor.pointer = pFontStream;
1021 ftStream->pos = 0; 1037 ftStream->pos = 0;
1022 ftStream->size = (unsigned long)pFontStream->GetSize(); 1038 ftStream->size = (unsigned long)pFontStream->GetSize();
1023 ftStream->read = _ftStreamRead; 1039 ftStream->read = _ftStreamRead;
1024 ftStream->close = _ftStreamClose; 1040 ftStream->close = _ftStreamClose;
1025 1041
1026 FXFT_Open_Args ftArgs; 1042 FXFT_Open_Args ftArgs;
1027 FXSYS_memset(&ftArgs, 0, sizeof(FXFT_Open_Args)); 1043 FXSYS_memset(&ftArgs, 0, sizeof(FXFT_Open_Args));
1028 ftArgs.flags |= FT_OPEN_STREAM; 1044 ftArgs.flags |= FT_OPEN_STREAM;
1029 ftArgs.stream = ftStream; 1045 ftArgs.stream = ftStream;
1030 1046
1031 FXFT_Face pFace = NULL; 1047 FXFT_Face pFace = nullptr;
1032 if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { 1048 if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) {
1033 FX_Free(ftStream); 1049 FX_Free(ftStream);
1034 return nullptr; 1050 return nullptr;
1035 } 1051 }
1036 1052
1037 FXFT_Set_Pixel_Sizes(pFace, 0, 64); 1053 FXFT_Set_Pixel_Sizes(pFace, 0, 64);
1038 return pFace; 1054 return pFace;
1039 } 1055 }
1040 1056
1041 IFX_FileRead* CFX_FontMgrImp::CreateFontStream( 1057 IFX_FileRead* CFX_FontMgrImp::CreateFontStream(
1042 CFX_FontMapper* pFontMapper, 1058 CFX_FontMapper* pFontMapper,
1043 IFX_SystemFontInfo* pSystemFontInfo, 1059 IFX_SystemFontInfo* pSystemFontInfo,
1044 uint32_t index) { 1060 uint32_t index) {
1045 int iExact = 0; 1061 int iExact = 0;
1046 void* hFont = pSystemFontInfo->MapFont( 1062 void* hFont = pSystemFontInfo->MapFont(
1047 0, 0, FXFONT_DEFAULT_CHARSET, 0, pFontMapper->GetFaceName(index), iExact); 1063 0, 0, FXFONT_DEFAULT_CHARSET, 0, pFontMapper->GetFaceName(index), iExact);
1048 if (!hFont) 1064 if (!hFont)
1049 return nullptr; 1065 return nullptr;
1066
1050 uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0); 1067 uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0);
1051 if (dwFileSize == 0) 1068 if (dwFileSize == 0)
1052 return nullptr; 1069 return nullptr;
1070
1053 uint8_t* pBuffer = FX_Alloc(uint8_t, dwFileSize + 1); 1071 uint8_t* pBuffer = FX_Alloc(uint8_t, dwFileSize + 1);
1054 dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, pBuffer, dwFileSize); 1072 dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, pBuffer, dwFileSize);
1073
1055 return FX_CreateMemoryStream(pBuffer, dwFileSize, TRUE); 1074 return FX_CreateMemoryStream(pBuffer, dwFileSize, TRUE);
1056 } 1075 }
1057 1076
1058 IFX_FileRead* CFX_FontMgrImp::CreateFontStream( 1077 IFX_FileRead* CFX_FontMgrImp::CreateFontStream(
1059 const CFX_ByteString& bsFaceName) { 1078 const CFX_ByteString& bsFaceName) {
1060 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); 1079 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
1061 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); 1080 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper();
1081
1062 if (!pFontMapper) 1082 if (!pFontMapper)
1063 return nullptr; 1083 return nullptr;
1084
1064 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); 1085 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
1065 if (!pSystemFontInfo) 1086 if (!pSystemFontInfo)
1066 return nullptr; 1087 return nullptr;
1088
1067 pSystemFontInfo->EnumFontList(pFontMapper); 1089 pSystemFontInfo->EnumFontList(pFontMapper);
1068 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { 1090 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) {
1069 if (pFontMapper->GetFaceName(i) == bsFaceName) 1091 if (pFontMapper->GetFaceName(i) == bsFaceName)
1070 return CreateFontStream(pFontMapper, pSystemFontInfo, i); 1092 return CreateFontStream(pFontMapper, pSystemFontInfo, i);
1071 } 1093 }
1072 return nullptr; 1094 return nullptr;
1073 } 1095 }
1074 int32_t CFX_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, 1096 int32_t CFX_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts,
1075 uint16_t wCodePage, 1097 uint16_t wCodePage,
1076 uint32_t dwFontStyles, 1098 uint32_t dwFontStyles,
1077 const CFX_WideString& FontName, 1099 const CFX_WideString& FontName,
1078 FX_WCHAR wcUnicode) { 1100 FX_WCHAR wcUnicode) {
1079 MatchedFonts.RemoveAll(); 1101 MatchedFonts.RemoveAll();
1080 CFX_WideString wsNormalizedFontName = FontName; 1102 CFX_WideString wsNormalizedFontName = FontName;
1081 static const int32_t nMax = 0xffff; 1103
1082 CFX_FontDescriptor* pFont = NULL; 1104 CFX_FontDescriptor* pFont = nullptr;
1083 int32_t nCount = m_InstalledFonts.GetSize(); 1105 int32_t nCount = m_InstalledFonts.GetSize();
1084 for (int32_t i = 0; i < nCount; i++) { 1106 for (int32_t i = 0; i < nCount; i++) {
1085 pFont = m_InstalledFonts[i]; 1107 pFont = m_InstalledFonts[i];
1086 int32_t nPenalty = CalcPenalty(pFont, wCodePage, dwFontStyles, 1108 int32_t nPenalty = CalcPenalty(pFont, wCodePage, dwFontStyles,
1087 wsNormalizedFontName, wcUnicode); 1109 wsNormalizedFontName, wcUnicode);
1088 if (nPenalty >= 0xFFFF) { 1110 if (nPenalty >= 0xffff)
1089 continue; 1111 continue;
1090 } 1112
1091 FX_FontDescriptorInfo FontInfo; 1113 FX_FontDescriptorInfo FontInfo;
1092 FontInfo.pFont = pFont; 1114 FontInfo.pFont = pFont;
1093 FontInfo.nPenalty = nPenalty; 1115 FontInfo.nPenalty = nPenalty;
1094 MatchedFonts.Add(FontInfo); 1116 MatchedFonts.Add(FontInfo);
1095 if (MatchedFonts.GetSize() == nMax) { 1117 if (MatchedFonts.GetSize() == 0xffff)
1096 break; 1118 break;
1097 }
1098 } 1119 }
1099 if (MatchedFonts.GetSize() == 0) { 1120 if (MatchedFonts.GetSize() == 0)
1100 return 0; 1121 return 0;
1101 } 1122
1102 CFX_SSortTemplate<FX_FontDescriptorInfo> ssort; 1123 CFX_SSortTemplate<FX_FontDescriptorInfo> ssort;
1103 ssort.ShellSort(MatchedFonts.GetData(), MatchedFonts.GetSize()); 1124 ssort.ShellSort(MatchedFonts.GetData(), MatchedFonts.GetSize());
1104 return MatchedFonts.GetSize(); 1125 return MatchedFonts.GetSize();
1105 } 1126 }
1127
1106 struct FX_BitCodePage { 1128 struct FX_BitCodePage {
1107 uint16_t wBit; 1129 uint16_t wBit;
1108 uint16_t wCodePage; 1130 uint16_t wCodePage;
1109 }; 1131 };
1110 static const FX_BitCodePage g_Bit2CodePage[] = { 1132 static const FX_BitCodePage g_Bit2CodePage[] = {
1111 {0, 1252}, {1, 1250}, {2, 1251}, {3, 1253}, {4, 1254}, {5, 1255}, 1133 {0, 1252}, {1, 1250}, {2, 1251}, {3, 1253}, {4, 1254}, {5, 1255},
1112 {6, 1256}, {7, 1257}, {8, 1258}, {9, 0}, {10, 0}, {11, 0}, 1134 {6, 1256}, {7, 1257}, {8, 1258}, {9, 0}, {10, 0}, {11, 0},
1113 {12, 0}, {13, 0}, {14, 0}, {15, 0}, {16, 874}, {17, 932}, 1135 {12, 0}, {13, 0}, {14, 0}, {15, 0}, {16, 874}, {17, 932},
1114 {18, 936}, {19, 949}, {20, 950}, {21, 1361}, {22, 0}, {23, 0}, 1136 {18, 936}, {19, 949}, {20, 950}, {21, 1361}, {22, 0}, {23, 0},
1115 {24, 0}, {25, 0}, {26, 0}, {27, 0}, {28, 0}, {29, 0}, 1137 {24, 0}, {25, 0}, {26, 0}, {27, 0}, {28, 0}, {29, 0},
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 for (int32_t i = 0; i < pFonts->GetSize(); i++) { 1294 for (int32_t i = 0; i < pFonts->GetSize(); i++) {
1273 if (pFonts->GetAt(i) == pEFont) { 1295 if (pFonts->GetAt(i) == pEFont) {
1274 pFonts->SetAt(i, NULL); 1296 pFonts->SetAt(i, NULL);
1275 } 1297 }
1276 } 1298 }
1277 } else { 1299 } else {
1278 m_Hash2Fonts.RemoveKey(dwHash); 1300 m_Hash2Fonts.RemoveKey(dwHash);
1279 } 1301 }
1280 } 1302 }
1281 } 1303 }
1304
1282 void CFX_FontMgrImp::RegisterFace(FXFT_Face pFace, 1305 void CFX_FontMgrImp::RegisterFace(FXFT_Face pFace,
1283 CFX_FontDescriptors& Fonts, 1306 CFX_FontDescriptors& Fonts,
1284 const CFX_WideString* pFaceName, 1307 const CFX_WideString* pFaceName,
1285 IFX_FileAccess* pFontAccess) { 1308 IFX_FileAccess* pFontAccess) {
1286 if (0 == (pFace->face_flags & FT_FACE_FLAG_SCALABLE)) { 1309 if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0)
1287 return; 1310 return;
1288 } 1311
1289 CFX_FontDescriptor* pFont = new CFX_FontDescriptor; 1312 CFX_FontDescriptor* pFont = new CFX_FontDescriptor;
1290 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; 1313 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0;
1291 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; 1314 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0;
1292 pFont->m_dwFontStyles |= GetFlags(pFace); 1315 pFont->m_dwFontStyles |= GetFlags(pFace);
1316
1293 CFX_ArrayTemplate<uint16_t> Charsets; 1317 CFX_ArrayTemplate<uint16_t> Charsets;
1294 GetCharsets(pFace, Charsets); 1318 GetCharsets(pFace, Charsets);
1295 GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb); 1319 GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb);
1320
1321 FT_ULong dwTag;
1322 uint8_t* pTable = nullptr;
1323 FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e');
1324
1296 unsigned long nLength = 0; 1325 unsigned long nLength = 0;
1297 FT_ULong dwTag; 1326 unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, nullptr, &nLength);
1298 uint8_t* pTable = NULL; 1327 if (error == 0 && nLength != 0) {
1299 FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e');
1300 unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, NULL, &nLength);
1301 if (0 == error && 0 != nLength) {
1302 pTable = FX_Alloc(uint8_t, nLength); 1328 pTable = FX_Alloc(uint8_t, nLength);
1303 error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, pTable, NULL); 1329 error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, pTable, nullptr);
1304 if (0 != error) { 1330 if (0 != error) {
1305 FX_Free(pTable); 1331 FX_Free(pTable);
1306 pTable = NULL; 1332 pTable = nullptr;
1307 } 1333 }
1308 } 1334 }
1309 GetNames(pTable, pFont->m_wsFamilyNames); 1335 GetNames(pTable, pFont->m_wsFamilyNames);
1310 if (NULL != pTable) { 1336 if (pTable)
1311 FX_Free(pTable); 1337 FX_Free(pTable);
1312 } 1338
1313 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); 1339 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode());
1314 if (pFaceName) { 1340 pFont->m_wsFaceName =
1315 pFont->m_wsFaceName = *pFaceName; 1341 pFaceName ? *pFaceName
1316 } else { 1342 : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace));
1317 pFont->m_wsFaceName =
1318 CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace));
1319 }
1320 pFont->m_nFaceIndex = pFace->face_index; 1343 pFont->m_nFaceIndex = pFace->face_index;
1321 if (pFontAccess) 1344 pFont->m_pFileAccess = pFontAccess ? pFontAccess->Retain() : nullptr;
1322 pFont->m_pFileAccess = pFontAccess->Retain(); 1345
1323 else
1324 pFont->m_pFileAccess = nullptr;
1325 Fonts.Add(pFont); 1346 Fonts.Add(pFont);
1326 } 1347 }
1348
1327 void CFX_FontMgrImp::RegisterFaces(IFX_FileRead* pFontStream, 1349 void CFX_FontMgrImp::RegisterFaces(IFX_FileRead* pFontStream,
1328 const CFX_WideString* pFaceName) { 1350 const CFX_WideString* pFaceName) {
1329 int32_t index = 0; 1351 int32_t index = 0;
1330 int32_t num_faces = 0; 1352 int32_t num_faces = 0;
1331 do { 1353 do {
1332 FXFT_Face pFace = LoadFace(pFontStream, index++); 1354 FXFT_Face pFace = LoadFace(pFontStream, index++);
1333 if (!pFace) 1355 if (!pFace)
1334 continue; 1356 continue;
1335 // All faces keep number of faces. It can be retrieved from any one face. 1357 // All faces keep number of faces. It can be retrieved from any one face.
1336 if (!num_faces) 1358 if (num_faces == 0)
1337 num_faces = pFace->num_faces; 1359 num_faces = pFace->num_faces;
1338 RegisterFace(pFace, m_InstalledFonts, pFaceName, nullptr); 1360 RegisterFace(pFace, m_InstalledFonts, pFaceName, nullptr);
1339 if (FXFT_Get_Face_External_Stream(pFace)) 1361 if (FXFT_Get_Face_External_Stream(pFace))
1340 FXFT_Clear_Face_External_Stream(pFace); 1362 FXFT_Clear_Face_External_Stream(pFace);
1341 FXFT_Done_Face(pFace); 1363 FXFT_Done_Face(pFace);
1342 } while (index < num_faces); 1364 } while (index < num_faces);
1343 } 1365 }
1344 uint32_t CFX_FontMgrImp::GetFlags(FXFT_Face pFace) { 1366 uint32_t CFX_FontMgrImp::GetFlags(FXFT_Face pFace) {
1345 uint32_t flag = 0; 1367 uint32_t flag = 0;
1346 if (FT_IS_FIXED_WIDTH(pFace)) { 1368 if (FT_IS_FIXED_WIDTH(pFace)) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 } 1529 }
1508 } 1530 }
1509 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, 1531 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1,
1510 const CFX_WideString& Name2) { 1532 const CFX_WideString& Name2) {
1511 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { 1533 if (Name1.Find((const FX_WCHAR*)Name2) != -1) {
1512 return 1; 1534 return 1;
1513 } 1535 }
1514 return 0; 1536 return 0;
1515 } 1537 }
1516 #endif 1538 #endif
OLDNEW
« no previous file with comments | « core/fxge/include/fx_font.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698