| 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" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 pFont = IFX_Font::LoadFont(pBuffer, iLength, this); | 169 pFont = IFX_Font::LoadFont(pBuffer, iLength, this); |
| 170 if (pFont != NULL) { | 170 if (pFont != NULL) { |
| 171 m_Fonts.Add(pFont); | 171 m_Fonts.Add(pFont); |
| 172 m_BufferFonts.SetAt((void*)pBuffer, pFont); | 172 m_BufferFonts.SetAt((void*)pBuffer, pFont); |
| 173 return pFont->Retain(); | 173 return pFont->Retain(); |
| 174 } | 174 } |
| 175 return NULL; | 175 return NULL; |
| 176 } | 176 } |
| 177 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { | 177 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { |
| 178 FXSYS_assert(pszFileName != NULL); | 178 FXSYS_assert(pszFileName != NULL); |
| 179 uint32_t dwHash = FX_HashCode_String_GetW(pszFileName, -1); | 179 uint32_t dwHash = FX_HashCode_GetW(pszFileName, false); |
| 180 IFX_Font* pFont = NULL; | 180 IFX_Font* pFont = NULL; |
| 181 if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 181 if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
| 182 if (pFont != NULL) { | 182 if (pFont != NULL) { |
| 183 return pFont->Retain(); | 183 return pFont->Retain(); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 pFont = IFX_Font::LoadFont(pszFileName, NULL); | 186 pFont = IFX_Font::LoadFont(pszFileName, NULL); |
| 187 if (pFont != NULL) { | 187 if (pFont != NULL) { |
| 188 m_Fonts.Add(pFont); | 188 m_Fonts.Add(pFont); |
| 189 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 189 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 223 } |
| 224 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont, | 224 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont, |
| 225 uint32_t dwFontStyles, | 225 uint32_t dwFontStyles, |
| 226 uint16_t wCodePage) { | 226 uint16_t wCodePage) { |
| 227 FXSYS_assert(pSrcFont != NULL); | 227 FXSYS_assert(pSrcFont != NULL); |
| 228 if (pSrcFont->GetFontStyles() == dwFontStyles) { | 228 if (pSrcFont->GetFontStyles() == dwFontStyles) { |
| 229 return pSrcFont->Retain(); | 229 return pSrcFont->Retain(); |
| 230 } | 230 } |
| 231 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, | 231 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, |
| 232 (void*)(uintptr_t)wCodePage}; | 232 (void*)(uintptr_t)wCodePage}; |
| 233 uint32_t dwHash = | 233 uint32_t dwHash = FX_HashCode_GetA( |
| 234 FX_HashCode_String_GetA((const FX_CHAR*)buffer, 3 * sizeof(void*)); | 234 CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); |
| 235 IFX_Font* pFont = NULL; | 235 IFX_Font* pFont = NULL; |
| 236 if (m_DeriveFonts.GetCount() > 0) { | 236 if (m_DeriveFonts.GetCount() > 0) { |
| 237 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); | 237 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); |
| 238 if (pFont != NULL) { | 238 if (pFont != NULL) { |
| 239 return pFont->Retain(); | 239 return pFont->Retain(); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); | 242 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); |
| 243 if (pFont != NULL) { | 243 if (pFont != NULL) { |
| 244 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 244 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 const FX_WCHAR* pszFontFamily) { | 695 const FX_WCHAR* pszFontFamily) { |
| 696 return nullptr; | 696 return nullptr; |
| 697 } | 697 } |
| 698 | 698 |
| 699 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, | 699 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, |
| 700 uint32_t dwFontStyles, | 700 uint32_t dwFontStyles, |
| 701 const FX_WCHAR* pszFontFamily) { | 701 const FX_WCHAR* pszFontFamily) { |
| 702 CFX_ByteString bsHash; | 702 CFX_ByteString bsHash; |
| 703 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 703 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
| 704 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 704 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
| 705 uint32_t dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength()); | 705 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 706 | |
| 707 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; | 706 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; |
| 708 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { | 707 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { |
| 709 if (!pFonts) | 708 if (!pFonts) |
| 710 return nullptr; | 709 return nullptr; |
| 711 | 710 |
| 712 if (pFonts->GetSize() != 0) | 711 if (pFonts->GetSize() != 0) |
| 713 return pFonts->GetAt(0)->Retain(); | 712 return pFonts->GetAt(0)->Retain(); |
| 714 } | 713 } |
| 715 | 714 |
| 716 if (!pFonts) | 715 if (!pFonts) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 return nullptr; | 751 return nullptr; |
| 753 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); | 752 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); |
| 754 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; | 753 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; |
| 755 uint16_t wBitField = x ? x->wBitField : 0x03E7; | 754 uint16_t wBitField = x ? x->wBitField : 0x03E7; |
| 756 CFX_ByteString bsHash; | 755 CFX_ByteString bsHash; |
| 757 if (wCodePage == 0xFFFF) | 756 if (wCodePage == 0xFFFF) |
| 758 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); | 757 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); |
| 759 else | 758 else |
| 760 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 759 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
| 761 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 760 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
| 762 uint32_t dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength()); | 761 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 763 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; | 762 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; |
| 764 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { | 763 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { |
| 765 if (!pFonts) | 764 if (!pFonts) |
| 766 return nullptr; | 765 return nullptr; |
| 767 for (int32_t i = 0; i < pFonts->GetSize(); ++i) { | 766 for (int32_t i = 0; i < pFonts->GetSize(); ++i) { |
| 768 if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) | 767 if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) |
| 769 return pFonts->GetAt(i)->Retain(); | 768 return pFonts->GetAt(i)->Retain(); |
| 770 } | 769 } |
| 771 } | 770 } |
| 772 if (!pFonts) | 771 if (!pFonts) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, | 839 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, |
| 841 pszFontFamily); | 840 pszFontFamily); |
| 842 } | 841 } |
| 843 | 842 |
| 844 IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer, | 843 IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer, |
| 845 int32_t iLength, | 844 int32_t iLength, |
| 846 int32_t iFaceIndex, | 845 int32_t iFaceIndex, |
| 847 int32_t* pFaceCount) { | 846 int32_t* pFaceCount) { |
| 848 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; | 847 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; |
| 849 uint32_t dwHash = | 848 uint32_t dwHash = |
| 850 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 2 * sizeof(void*)); | 849 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); |
| 851 IFX_FileAccess* pFontAccess = nullptr; | 850 IFX_FileAccess* pFontAccess = nullptr; |
| 852 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); | 851 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); |
| 853 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) | 852 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) |
| 854 : nullptr; | 853 : nullptr; |
| 855 } | 854 } |
| 856 | 855 |
| 857 IFX_Font* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, | 856 IFX_Font* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, |
| 858 int32_t iFaceIndex, | 857 int32_t iFaceIndex, |
| 859 int32_t* pFaceCount) { | 858 int32_t* pFaceCount) { |
| 860 CFX_ByteString bsHash; | 859 CFX_ByteString bsHash; |
| 861 bsHash += CFX_WideString(pszFileName).UTF8Encode(); | 860 bsHash += CFX_WideString(pszFileName).UTF8Encode(); |
| 862 | 861 |
| 863 uint32_t dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength()); | 862 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 864 IFX_FileAccess* pFontAccess = nullptr; | 863 IFX_FileAccess* pFontAccess = nullptr; |
| 865 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { | 864 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { |
| 866 pFontAccess = FX_CreateDefaultFileAccess(pszFileName); | 865 pFontAccess = FX_CreateDefaultFileAccess(pszFileName); |
| 867 m_Hash2FileAccess.SetAt(dwHash, pFontAccess); | 866 m_Hash2FileAccess.SetAt(dwHash, pFontAccess); |
| 868 } | 867 } |
| 869 | 868 |
| 870 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) | 869 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) |
| 871 : nullptr; | 870 : nullptr; |
| 872 } | 871 } |
| 873 | 872 |
| 874 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream, | 873 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream, |
| 875 int32_t iFaceIndex, | 874 int32_t iFaceIndex, |
| 876 int32_t* pFaceCount, | 875 int32_t* pFaceCount, |
| 877 FX_BOOL bSaveStream) { | 876 FX_BOOL bSaveStream) { |
| 878 void* Hash[1] = {(void*)(uintptr_t)pFontStream}; | 877 void* Hash[1] = {(void*)(uintptr_t)pFontStream}; |
| 879 uint32_t dwHash = | 878 uint32_t dwHash = |
| 880 FX_HashCode_String_GetA((const FX_CHAR*)Hash, 1 * sizeof(void*)); | 879 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); |
| 881 IFX_FileAccess* pFontAccess = nullptr; | 880 IFX_FileAccess* pFontAccess = nullptr; |
| 882 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); | 881 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); |
| 883 | 882 |
| 884 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) | 883 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) |
| 885 : nullptr; | 884 : nullptr; |
| 886 } | 885 } |
| 887 | 886 |
| 888 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, | 887 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, |
| 889 int32_t iFaceIndex, | 888 int32_t iFaceIndex, |
| 890 int32_t* pFaceCount, | 889 int32_t* pFaceCount, |
| 891 FX_BOOL bWantCache) { | 890 FX_BOOL bWantCache) { |
| 892 uint32_t dwHash = 0; | 891 uint32_t dwHash = 0; |
| 893 IFX_Font* pFont = nullptr; | 892 IFX_Font* pFont = nullptr; |
| 894 if (bWantCache) { | 893 if (bWantCache) { |
| 895 CFX_ByteString bsHash; | 894 CFX_ByteString bsHash; |
| 896 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); | 895 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); |
| 897 dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength()); | 896 dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 898 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { | 897 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { |
| 899 if (pFont) { | 898 if (pFont) { |
| 900 if (pFaceCount) | 899 if (pFaceCount) |
| 901 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; | 900 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; |
| 902 return pFont->Retain(); | 901 return pFont->Retain(); |
| 903 } | 902 } |
| 904 } | 903 } |
| 905 } | 904 } |
| 906 | 905 |
| 907 CFX_Font* pInternalFont = new CFX_Font; | 906 CFX_Font* pInternalFont = new CFX_Font; |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 } | 1502 } |
| 1504 } | 1503 } |
| 1505 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1504 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, |
| 1506 const CFX_WideString& Name2) { | 1505 const CFX_WideString& Name2) { |
| 1507 if (Name1.Find(Name2.c_str()) != -1) { | 1506 if (Name1.Find(Name2.c_str()) != -1) { |
| 1508 return 1; | 1507 return 1; |
| 1509 } | 1508 } |
| 1510 return 0; | 1509 return 0; |
| 1511 } | 1510 } |
| 1512 #endif | 1511 #endif |
| OLD | NEW |