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/fx_stream.h" | 9 #include "core/fxcrt/fx_stream.h" |
10 #include "core/fxge/cfx_fontmapper.h" | 10 #include "core/fxge/cfx_fontmapper.h" |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; | 584 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |
585 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 585 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
586 for (int32_t i = 0; i < pFonts->GetSize(); i++) | 586 for (int32_t i = 0; i < pFonts->GetSize(); i++) |
587 delete pFonts->GetAt(i); | 587 delete pFonts->GetAt(i); |
588 delete pFonts; | 588 delete pFonts; |
589 } | 589 } |
590 m_Hash2Fonts.RemoveAll(); | 590 m_Hash2Fonts.RemoveAll(); |
591 pos = m_IFXFont2FileRead.GetStartPosition(); | 591 pos = m_IFXFont2FileRead.GetStartPosition(); |
592 while (pos) { | 592 while (pos) { |
593 CFGAS_GEFont* pFont; | 593 CFGAS_GEFont* pFont; |
594 IFX_FileRead* pFileRead; | 594 IFX_SeekableReadStream* pFileRead; |
595 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 595 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
596 pFileRead->Release(); | 596 pFileRead->Release(); |
597 } | 597 } |
598 } | 598 } |
599 | 599 |
600 FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFontMapper() { | 600 FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFontMapper() { |
601 CFX_FontMapper* pFontMapper = | 601 CFX_FontMapper* pFontMapper = |
602 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); | 602 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); |
603 if (!pFontMapper) | 603 if (!pFontMapper) |
604 return FALSE; | 604 return FALSE; |
605 | 605 |
606 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 606 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
607 if (!pSystemFontInfo) | 607 if (!pSystemFontInfo) |
608 return FALSE; | 608 return FALSE; |
609 | 609 |
610 pSystemFontInfo->EnumFontList(pFontMapper); | 610 pSystemFontInfo->EnumFontList(pFontMapper); |
611 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { | 611 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { |
612 IFX_FileRead* pFontStream = | 612 IFX_SeekableReadStream* pFontStream = |
613 CreateFontStream(pFontMapper, pSystemFontInfo, i); | 613 CreateFontStream(pFontMapper, pSystemFontInfo, i); |
614 if (!pFontStream) | 614 if (!pFontStream) |
615 continue; | 615 continue; |
616 | 616 |
617 CFX_WideString wsFaceName = | 617 CFX_WideString wsFaceName = |
618 CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str()); | 618 CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str()); |
619 RegisterFaces(pFontStream, &wsFaceName); | 619 RegisterFaces(pFontStream, &wsFaceName); |
620 pFontStream->Release(); | 620 pFontStream->Release(); |
621 } | 621 } |
622 if (m_InstalledFonts.GetSize() == 0) | 622 if (m_InstalledFonts.GetSize() == 0) |
623 return FALSE; | 623 return FALSE; |
624 | 624 |
625 return TRUE; | 625 return TRUE; |
626 } | 626 } |
627 | 627 |
628 FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFiles() { | 628 FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFiles() { |
629 CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary(); | 629 CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary(); |
630 FX_POSITION pos = m_pFontSource->GetStartPosition(); | 630 FX_POSITION pos = m_pFontSource->GetStartPosition(); |
631 IFX_FileAccess* pFontSource = nullptr; | 631 IFX_FileAccess* pFontSource = nullptr; |
632 IFX_FileRead* pFontStream = nullptr; | 632 IFX_SeekableReadStream* pFontStream = nullptr; |
633 while (pos) { | 633 while (pos) { |
634 pFontSource = m_pFontSource->GetNext(pos); | 634 pFontSource = m_pFontSource->GetNext(pos); |
635 pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); | 635 pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); |
636 if (!pFontStream) { | 636 if (!pFontStream) { |
637 pFontSource->Release(); | 637 pFontSource->Release(); |
638 continue; | 638 continue; |
639 } | 639 } |
640 RegisterFaces(pFontStream, nullptr); | 640 RegisterFaces(pFontStream, nullptr); |
641 pFontStream->Release(); | 641 pFontStream->Release(); |
642 pFontSource->Release(); | 642 pFontSource->Release(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 pFonts->Add(pFont); | 776 pFonts->Add(pFont); |
777 return pFont; | 777 return pFont; |
778 } | 778 } |
779 if (!pszFontFamily) | 779 if (!pszFontFamily) |
780 m_FailedUnicodes2Nullptr.SetAt(wUnicode, nullptr); | 780 m_FailedUnicodes2Nullptr.SetAt(wUnicode, nullptr); |
781 return nullptr; | 781 return nullptr; |
782 } | 782 } |
783 | 783 |
784 FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(CFX_FontDescriptor* pDesc, | 784 FX_BOOL CFGAS_FontMgrImp::VerifyUnicode(CFX_FontDescriptor* pDesc, |
785 FX_WCHAR wcUnicode) { | 785 FX_WCHAR wcUnicode) { |
786 IFX_FileRead* pFileRead = CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); | 786 IFX_SeekableReadStream* pFileRead = |
| 787 CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); |
787 if (!pFileRead) | 788 if (!pFileRead) |
788 return FALSE; | 789 return FALSE; |
789 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); | 790 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); |
790 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); | 791 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); |
791 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); | 792 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); |
792 pFileRead->Release(); | 793 pFileRead->Release(); |
793 if (!pFace) | 794 if (!pFace) |
794 return FALSE; | 795 return FALSE; |
795 if (FXFT_Get_Face_External_Stream(pFace)) | 796 if (FXFT_Get_Face_External_Stream(pFace)) |
796 FXFT_Clear_Face_External_Stream(pFace); | 797 FXFT_Clear_Face_External_Stream(pFace); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 int32_t* pFaceCount) { | 829 int32_t* pFaceCount) { |
829 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 830 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
830 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | 831 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
831 if (!pFontMapper) | 832 if (!pFontMapper) |
832 return nullptr; | 833 return nullptr; |
833 | 834 |
834 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 835 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
835 if (!pSystemFontInfo) | 836 if (!pSystemFontInfo) |
836 return nullptr; | 837 return nullptr; |
837 | 838 |
838 IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode()); | 839 IFX_SeekableReadStream* pFontStream = |
| 840 CreateFontStream(wsFaceName.UTF8Encode()); |
839 if (!pFontStream) | 841 if (!pFontStream) |
840 return nullptr; | 842 return nullptr; |
841 | 843 |
842 std::unique_ptr<CFX_Font> pInternalFont(new CFX_Font()); | 844 std::unique_ptr<CFX_Font> pInternalFont(new CFX_Font()); |
843 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { | 845 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { |
844 pFontStream->Release(); | 846 pFontStream->Release(); |
845 return nullptr; | 847 return nullptr; |
846 } | 848 } |
847 | 849 |
848 CFGAS_GEFont* pFont = CFGAS_GEFont::LoadFont(std::move(pInternalFont), this); | 850 CFGAS_GEFont* pFont = CFGAS_GEFont::LoadFont(std::move(pInternalFont), this); |
(...skipping 11 matching lines...) Expand all Loading... |
860 | 862 |
861 extern "C" { | 863 extern "C" { |
862 | 864 |
863 unsigned long _ftStreamRead(FXFT_Stream stream, | 865 unsigned long _ftStreamRead(FXFT_Stream stream, |
864 unsigned long offset, | 866 unsigned long offset, |
865 unsigned char* buffer, | 867 unsigned char* buffer, |
866 unsigned long count) { | 868 unsigned long count) { |
867 if (count == 0) | 869 if (count == 0) |
868 return 0; | 870 return 0; |
869 | 871 |
870 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer; | 872 IFX_SeekableReadStream* pFile = |
| 873 (IFX_SeekableReadStream*)stream->descriptor.pointer; |
871 int res = pFile->ReadBlock(buffer, offset, count); | 874 int res = pFile->ReadBlock(buffer, offset, count); |
872 if (res) | 875 if (res) |
873 return count; | 876 return count; |
874 return 0; | 877 return 0; |
875 } | 878 } |
876 | 879 |
877 void _ftStreamClose(FXFT_Stream stream) {} | 880 void _ftStreamClose(FXFT_Stream stream) {} |
878 | 881 |
879 }; // extern "C" | 882 }; // extern "C" |
880 | 883 |
881 FXFT_Face CFGAS_FontMgrImp::LoadFace(IFX_FileRead* pFontStream, | 884 FXFT_Face CFGAS_FontMgrImp::LoadFace(IFX_SeekableReadStream* pFontStream, |
882 int32_t iFaceIndex) { | 885 int32_t iFaceIndex) { |
883 if (!pFontStream) | 886 if (!pFontStream) |
884 return nullptr; | 887 return nullptr; |
885 | 888 |
886 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 889 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
887 pFontMgr->InitFTLibrary(); | 890 pFontMgr->InitFTLibrary(); |
888 FXFT_Library library = pFontMgr->GetFTLibrary(); | 891 FXFT_Library library = pFontMgr->GetFTLibrary(); |
889 if (!library) | 892 if (!library) |
890 return nullptr; | 893 return nullptr; |
891 | 894 |
(...skipping 14 matching lines...) Expand all Loading... |
906 FXFT_Face pFace = nullptr; | 909 FXFT_Face pFace = nullptr; |
907 if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { | 910 if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { |
908 FX_Free(ftStream); | 911 FX_Free(ftStream); |
909 return nullptr; | 912 return nullptr; |
910 } | 913 } |
911 | 914 |
912 FXFT_Set_Pixel_Sizes(pFace, 0, 64); | 915 FXFT_Set_Pixel_Sizes(pFace, 0, 64); |
913 return pFace; | 916 return pFace; |
914 } | 917 } |
915 | 918 |
916 IFX_FileRead* CFGAS_FontMgrImp::CreateFontStream( | 919 IFX_SeekableReadStream* CFGAS_FontMgrImp::CreateFontStream( |
917 CFX_FontMapper* pFontMapper, | 920 CFX_FontMapper* pFontMapper, |
918 IFX_SystemFontInfo* pSystemFontInfo, | 921 IFX_SystemFontInfo* pSystemFontInfo, |
919 uint32_t index) { | 922 uint32_t index) { |
920 int iExact = 0; | 923 int iExact = 0; |
921 void* hFont = | 924 void* hFont = |
922 pSystemFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, | 925 pSystemFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, |
923 pFontMapper->GetFaceName(index).c_str(), iExact); | 926 pFontMapper->GetFaceName(index).c_str(), iExact); |
924 if (!hFont) | 927 if (!hFont) |
925 return nullptr; | 928 return nullptr; |
926 | 929 |
927 uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0); | 930 uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0); |
928 if (dwFileSize == 0) | 931 if (dwFileSize == 0) |
929 return nullptr; | 932 return nullptr; |
930 | 933 |
931 uint8_t* pBuffer = FX_Alloc(uint8_t, dwFileSize + 1); | 934 uint8_t* pBuffer = FX_Alloc(uint8_t, dwFileSize + 1); |
932 dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, pBuffer, dwFileSize); | 935 dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, pBuffer, dwFileSize); |
933 | 936 |
934 return FX_CreateMemoryStream(pBuffer, dwFileSize, TRUE); | 937 return FX_CreateMemoryStream(pBuffer, dwFileSize, TRUE); |
935 } | 938 } |
936 | 939 |
937 IFX_FileRead* CFGAS_FontMgrImp::CreateFontStream( | 940 IFX_SeekableReadStream* CFGAS_FontMgrImp::CreateFontStream( |
938 const CFX_ByteString& bsFaceName) { | 941 const CFX_ByteString& bsFaceName) { |
939 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 942 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
940 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | 943 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
941 | 944 |
942 if (!pFontMapper) | 945 if (!pFontMapper) |
943 return nullptr; | 946 return nullptr; |
944 | 947 |
945 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 948 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
946 if (!pSystemFontInfo) | 949 if (!pSystemFontInfo) |
947 return nullptr; | 950 return nullptr; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 1107 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
1105 while (pos) { | 1108 while (pos) { |
1106 uint32_t dwHash; | 1109 uint32_t dwHash; |
1107 CFX_FontDescriptorInfos* pDescs; | 1110 CFX_FontDescriptorInfos* pDescs; |
1108 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 1111 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
1109 delete pDescs; | 1112 delete pDescs; |
1110 } | 1113 } |
1111 pos = m_IFXFont2FileRead.GetStartPosition(); | 1114 pos = m_IFXFont2FileRead.GetStartPosition(); |
1112 while (pos) { | 1115 while (pos) { |
1113 CFGAS_GEFont* pFont; | 1116 CFGAS_GEFont* pFont; |
1114 IFX_FileRead* pFileRead; | 1117 IFX_SeekableReadStream* pFileRead; |
1115 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 1118 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
1116 pFileRead->Release(); | 1119 pFileRead->Release(); |
1117 } | 1120 } |
1118 } | 1121 } |
1119 | 1122 |
1120 void CFGAS_FontMgrImp::RemoveFont(CFGAS_GEFont* pEFont) { | 1123 void CFGAS_FontMgrImp::RemoveFont(CFGAS_GEFont* pEFont) { |
1121 if (!pEFont) { | 1124 if (!pEFont) { |
1122 return; | 1125 return; |
1123 } | 1126 } |
1124 IFX_FileRead* pFileRead; | 1127 IFX_SeekableReadStream* pFileRead; |
1125 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { | 1128 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { |
1126 pFileRead->Release(); | 1129 pFileRead->Release(); |
1127 m_IFXFont2FileRead.RemoveKey(pEFont); | 1130 m_IFXFont2FileRead.RemoveKey(pEFont); |
1128 } | 1131 } |
1129 FX_POSITION pos; | 1132 FX_POSITION pos; |
1130 pos = m_Hash2Fonts.GetStartPosition(); | 1133 pos = m_Hash2Fonts.GetStartPosition(); |
1131 while (pos) { | 1134 while (pos) { |
1132 uint32_t dwHash; | 1135 uint32_t dwHash; |
1133 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; | 1136 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |
1134 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 1137 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 | 1175 |
1173 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); | 1176 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); |
1174 pFont->m_wsFaceName = | 1177 pFont->m_wsFaceName = |
1175 pFaceName ? *pFaceName | 1178 pFaceName ? *pFaceName |
1176 : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); | 1179 : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); |
1177 pFont->m_nFaceIndex = pFace->face_index; | 1180 pFont->m_nFaceIndex = pFace->face_index; |
1178 | 1181 |
1179 m_InstalledFonts.Add(pFont.release()); | 1182 m_InstalledFonts.Add(pFont.release()); |
1180 } | 1183 } |
1181 | 1184 |
1182 void CFGAS_FontMgrImp::RegisterFaces(IFX_FileRead* pFontStream, | 1185 void CFGAS_FontMgrImp::RegisterFaces(IFX_SeekableReadStream* pFontStream, |
1183 const CFX_WideString* pFaceName) { | 1186 const CFX_WideString* pFaceName) { |
1184 int32_t index = 0; | 1187 int32_t index = 0; |
1185 int32_t num_faces = 0; | 1188 int32_t num_faces = 0; |
1186 do { | 1189 do { |
1187 FXFT_Face pFace = LoadFace(pFontStream, index++); | 1190 FXFT_Face pFace = LoadFace(pFontStream, index++); |
1188 if (!pFace) | 1191 if (!pFace) |
1189 continue; | 1192 continue; |
1190 // All faces keep number of faces. It can be retrieved from any one face. | 1193 // All faces keep number of faces. It can be retrieved from any one face. |
1191 if (num_faces == 0) | 1194 if (num_faces == 0) |
1192 num_faces = pFace->num_faces; | 1195 num_faces = pFace->num_faces; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 | 1377 |
1375 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1378 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, |
1376 const CFX_WideString& Name2) { | 1379 const CFX_WideString& Name2) { |
1377 if (Name1.Find(Name2.c_str()) != -1) { | 1380 if (Name1.Find(Name2.c_str()) != -1) { |
1378 return 1; | 1381 return 1; |
1379 } | 1382 } |
1380 return 0; | 1383 return 0; |
1381 } | 1384 } |
1382 | 1385 |
1383 #endif | 1386 #endif |
OLD | NEW |