| 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/cfgas_fontmgr.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" |
| 11 #include "core/fxge/cfx_fontmgr.h" | 11 #include "core/fxge/cfx_fontmgr.h" |
| 12 #include "core/fxge/cfx_gemodule.h" | 12 #include "core/fxge/cfx_gemodule.h" |
| 13 #include "core/fxge/ifx_systemfontinfo.h" | 13 #include "core/fxge/ifx_systemfontinfo.h" |
| 14 #include "third_party/base/ptr_util.h" |
| 14 #include "xfa/fgas/crt/fgas_codepage.h" | 15 #include "xfa/fgas/crt/fgas_codepage.h" |
| 15 #include "xfa/fgas/font/fgas_fontutils.h" | 16 #include "xfa/fgas/font/fgas_fontutils.h" |
| 16 #include "xfa/fgas/font/fgas_gefont.h" | 17 #include "xfa/fgas/font/fgas_gefont.h" |
| 17 | 18 |
| 18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 19 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 19 | 20 |
| 20 std::unique_ptr<IFGAS_FontMgr> IFGAS_FontMgr::Create( | 21 namespace { |
| 21 FX_LPEnumAllFonts pEnumerator) { | 22 |
| 22 return std::unique_ptr<IFGAS_FontMgr>(new CFGAS_StdFontMgrImp(pEnumerator)); | 23 int32_t GetSimilarityScore(FX_FONTDESCRIPTOR const* pFont, |
| 24 uint32_t dwFontStyles) { |
| 25 int32_t iValue = 0; |
| 26 if ((dwFontStyles & FX_FONTSTYLE_Symbolic) == |
| 27 (pFont->dwFontStyles & FX_FONTSTYLE_Symbolic)) { |
| 28 iValue += 64; |
| 29 } |
| 30 if ((dwFontStyles & FX_FONTSTYLE_FixedPitch) == |
| 31 (pFont->dwFontStyles & FX_FONTSTYLE_FixedPitch)) { |
| 32 iValue += 32; |
| 33 } |
| 34 if ((dwFontStyles & FX_FONTSTYLE_Serif) == |
| 35 (pFont->dwFontStyles & FX_FONTSTYLE_Serif)) { |
| 36 iValue += 16; |
| 37 } |
| 38 if ((dwFontStyles & FX_FONTSTYLE_Script) == |
| 39 (pFont->dwFontStyles & FX_FONTSTYLE_Script)) { |
| 40 iValue += 8; |
| 41 } |
| 42 return iValue; |
| 23 } | 43 } |
| 24 | 44 |
| 25 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) | 45 FX_FONTDESCRIPTOR const* MatchDefaultFont(FX_LPFONTMATCHPARAMS pParams, |
| 46 const CFX_FontDescriptors& fonts) { |
| 47 FX_FONTDESCRIPTOR const* pBestFont = nullptr; |
| 48 int32_t iBestSimilar = 0; |
| 49 bool bMatchStyle = (pParams->dwMatchFlags & FX_FONTMATCHPARA_MatchStyle) > 0; |
| 50 for (int32_t i = 0; i < fonts.GetSize(); ++i) { |
| 51 FX_FONTDESCRIPTOR const* pFont = fonts.GetPtrAt(i); |
| 52 if ((pFont->dwFontStyles & FX_FONTSTYLE_BoldItalic) == |
| 53 FX_FONTSTYLE_BoldItalic) { |
| 54 continue; |
| 55 } |
| 56 if (pParams->pwsFamily) { |
| 57 if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace)) |
| 58 continue; |
| 59 if (pFont->uCharSet == FX_CHARSET_Symbol) |
| 60 return pFont; |
| 61 } |
| 62 if (pFont->uCharSet == FX_CHARSET_Symbol) |
| 63 continue; |
| 64 if (pParams->wCodePage != 0xFFFF) { |
| 65 if (FX_GetCodePageFromCharset(pFont->uCharSet) != pParams->wCodePage) |
| 66 continue; |
| 67 } else { |
| 68 if (pParams->dwUSB < 128) { |
| 69 uint32_t dwByte = pParams->dwUSB / 32; |
| 70 uint32_t dwUSB = 1 << (pParams->dwUSB % 32); |
| 71 if ((pFont->FontSignature.fsUsb[dwByte] & dwUSB) == 0) |
| 72 continue; |
| 73 } |
| 74 } |
| 75 if (bMatchStyle) { |
| 76 if ((pFont->dwFontStyles & 0x0F) == (pParams->dwFontStyles & 0x0F)) |
| 77 return pFont; |
| 78 continue; |
| 79 } |
| 80 if (pParams->pwsFamily) { |
| 81 if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace) == 0) |
| 82 return pFont; |
| 83 } |
| 84 int32_t iSimilarValue = GetSimilarityScore(pFont, pParams->dwFontStyles); |
| 85 if (iBestSimilar < iSimilarValue) { |
| 86 iBestSimilar = iSimilarValue; |
| 87 pBestFont = pFont; |
| 88 } |
| 89 } |
| 90 return iBestSimilar < 1 ? nullptr : pBestFont; |
| 91 } |
| 92 |
| 93 } // namespace |
| 94 |
| 95 std::unique_ptr<CFGAS_FontMgr> CFGAS_FontMgr::Create( |
| 96 FX_LPEnumAllFonts pEnumerator) { |
| 97 return pdfium::MakeUnique<CFGAS_FontMgr>(pEnumerator); |
| 98 } |
| 99 |
| 100 CFGAS_FontMgr::CFGAS_FontMgr(FX_LPEnumAllFonts pEnumerator) |
| 26 : m_pEnumerator(pEnumerator), | 101 : m_pEnumerator(pEnumerator), |
| 27 m_FontFaces(100), | 102 m_FontFaces(100), |
| 28 m_CPFonts(8), | 103 m_CPFonts(8), |
| 29 m_FamilyFonts(16), | 104 m_FamilyFonts(16), |
| 30 m_UnicodeFonts(16), | 105 m_UnicodeFonts(16), |
| 31 m_BufferFonts(4), | 106 m_BufferFonts(4), |
| 32 m_StreamFonts(4), | 107 m_StreamFonts(4), |
| 33 m_DeriveFonts(4) { | 108 m_DeriveFonts(4) { |
| 34 if (m_pEnumerator) { | 109 if (m_pEnumerator) |
| 35 m_pEnumerator(m_FontFaces, nullptr, 0xFEFF); | 110 m_pEnumerator(m_FontFaces, nullptr, 0xFEFF); |
| 36 } | |
| 37 } | 111 } |
| 38 | 112 |
| 39 CFGAS_StdFontMgrImp::~CFGAS_StdFontMgrImp() { | 113 CFGAS_FontMgr::~CFGAS_FontMgr() { |
| 40 m_FontFaces.RemoveAll(false); | 114 m_FontFaces.RemoveAll(false); |
| 41 m_CPFonts.RemoveAll(); | 115 m_CPFonts.RemoveAll(); |
| 42 m_FamilyFonts.RemoveAll(); | 116 m_FamilyFonts.RemoveAll(); |
| 43 m_UnicodeFonts.RemoveAll(); | 117 m_UnicodeFonts.RemoveAll(); |
| 44 m_BufferFonts.RemoveAll(); | 118 m_BufferFonts.RemoveAll(); |
| 45 m_StreamFonts.RemoveAll(); | 119 m_StreamFonts.RemoveAll(); |
| 46 m_DeriveFonts.RemoveAll(); | 120 m_DeriveFonts.RemoveAll(); |
| 47 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) | 121 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) |
| 48 m_Fonts[i]->Release(); | 122 m_Fonts[i]->Release(); |
| 49 } | 123 } |
| 50 | 124 |
| 51 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage( | 125 CFGAS_GEFont* CFGAS_FontMgr::GetDefFontByCodePage( |
| 52 uint16_t wCodePage, | 126 uint16_t wCodePage, |
| 53 uint32_t dwFontStyles, | 127 uint32_t dwFontStyles, |
| 54 const FX_WCHAR* pszFontFamily) { | 128 const FX_WCHAR* pszFontFamily) { |
| 55 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 129 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
| 56 CFGAS_GEFont* pFont = nullptr; | 130 CFGAS_GEFont* pFont = nullptr; |
| 57 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 131 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) |
| 58 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; | 132 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; |
| 59 } | |
| 60 FX_FONTDESCRIPTOR const* pFD = | 133 FX_FONTDESCRIPTOR const* pFD = |
| 61 FindFont(pszFontFamily, dwFontStyles, true, wCodePage); | 134 FindFont(pszFontFamily, dwFontStyles, true, wCodePage); |
| 62 if (!pFD) | 135 if (!pFD) |
| 63 pFD = FindFont(nullptr, dwFontStyles, true, wCodePage); | 136 pFD = FindFont(nullptr, dwFontStyles, true, wCodePage); |
| 64 if (!pFD) | 137 if (!pFD) |
| 65 pFD = FindFont(nullptr, dwFontStyles, false, wCodePage); | 138 pFD = FindFont(nullptr, dwFontStyles, false, wCodePage); |
| 66 if (!pFD) | 139 if (!pFD) |
| 67 return nullptr; | 140 return nullptr; |
| 68 | 141 |
| 69 pFont = | 142 pFont = |
| 70 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 143 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
| 71 if (pFont) { | 144 if (pFont) { |
| 72 m_Fonts.Add(pFont); | 145 m_Fonts.Add(pFont); |
| 73 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 146 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 74 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); | 147 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); |
| 75 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 148 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 76 return LoadFont(pFont, dwFontStyles, wCodePage); | 149 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 77 } | 150 } |
| 78 return nullptr; | 151 return nullptr; |
| 79 } | 152 } |
| 80 | 153 |
| 81 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCharset( | 154 CFGAS_GEFont* CFGAS_FontMgr::GetDefFontByUnicode( |
| 82 uint8_t nCharset, | |
| 83 uint32_t dwFontStyles, | |
| 84 const FX_WCHAR* pszFontFamily) { | |
| 85 return GetDefFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, | |
| 86 pszFontFamily); | |
| 87 } | |
| 88 | |
| 89 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByUnicode( | |
| 90 FX_WCHAR wUnicode, | 155 FX_WCHAR wUnicode, |
| 91 uint32_t dwFontStyles, | 156 uint32_t dwFontStyles, |
| 92 const FX_WCHAR* pszFontFamily) { | 157 const FX_WCHAR* pszFontFamily) { |
| 93 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); | 158 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); |
| 94 if (pRet->wBitField == 999) | 159 if (pRet->wBitField == 999) |
| 95 return nullptr; | 160 return nullptr; |
| 96 | 161 |
| 97 uint32_t dwHash = | 162 uint32_t dwHash = |
| 98 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); | 163 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); |
| 99 CFGAS_GEFont* pFont = nullptr; | 164 CFGAS_GEFont* pFont = nullptr; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 118 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 183 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 119 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 184 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
| 120 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 185 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 121 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); | 186 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); |
| 122 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 187 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 123 return LoadFont(pFont, dwFontStyles, wCodePage); | 188 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 124 } | 189 } |
| 125 return nullptr; | 190 return nullptr; |
| 126 } | 191 } |
| 127 | 192 |
| 128 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByLanguage( | 193 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(const FX_WCHAR* pszFontFamily, |
| 129 uint16_t wLanguage, | 194 uint32_t dwFontStyles, |
| 130 uint32_t dwFontStyles, | 195 uint16_t wCodePage) { |
| 131 const FX_WCHAR* pszFontFamily) { | |
| 132 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), | |
| 133 dwFontStyles, pszFontFamily); | |
| 134 } | |
| 135 | |
| 136 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, | |
| 137 uint32_t dwFontStyles, | |
| 138 uint16_t wCodePage) { | |
| 139 uint32_t dwHash = | 196 uint32_t dwHash = |
| 140 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); | 197 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); |
| 141 CFGAS_GEFont* pFont = nullptr; | 198 CFGAS_GEFont* pFont = nullptr; |
| 142 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 199 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) |
| 143 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; | 200 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; |
| 144 } | |
| 145 FX_FONTDESCRIPTOR const* pFD = | 201 FX_FONTDESCRIPTOR const* pFD = |
| 146 FindFont(pszFontFamily, dwFontStyles, true, wCodePage); | 202 FindFont(pszFontFamily, dwFontStyles, true, wCodePage); |
| 147 if (!pFD) | 203 if (!pFD) |
| 148 pFD = FindFont(pszFontFamily, dwFontStyles, false, wCodePage); | 204 pFD = FindFont(pszFontFamily, dwFontStyles, false, wCodePage); |
| 149 if (!pFD) | 205 if (!pFD) |
| 150 return nullptr; | 206 return nullptr; |
| 151 | 207 |
| 152 if (wCodePage == 0xFFFF) { | 208 if (wCodePage == 0xFFFF) |
| 153 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); | 209 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); |
| 154 } | |
| 155 pFont = | 210 pFont = |
| 156 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 211 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
| 157 if (pFont) { | 212 if (pFont) { |
| 158 m_Fonts.Add(pFont); | 213 m_Fonts.Add(pFont); |
| 159 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 214 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 160 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 215 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
| 161 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 216 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 162 return LoadFont(pFont, dwFontStyles, wCodePage); | 217 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 163 } | 218 } |
| 164 return nullptr; | 219 return nullptr; |
| 165 } | 220 } |
| 166 | 221 |
| 167 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, | 222 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(const uint8_t* pBuffer, int32_t iLength) { |
| 168 int32_t iLength) { | |
| 169 ASSERT(pBuffer && iLength > 0); | 223 ASSERT(pBuffer && iLength > 0); |
| 170 CFGAS_GEFont* pFont = nullptr; | 224 CFGAS_GEFont* pFont = nullptr; |
| 171 if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) { | 225 if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) { |
| 172 if (pFont) { | 226 if (pFont) |
| 173 return pFont->Retain(); | 227 return pFont->Retain(); |
| 174 } | |
| 175 } | 228 } |
| 176 pFont = CFGAS_GEFont::LoadFont(pBuffer, iLength, this); | 229 pFont = CFGAS_GEFont::LoadFont(pBuffer, iLength, this); |
| 177 if (pFont) { | 230 if (pFont) { |
| 178 m_Fonts.Add(pFont); | 231 m_Fonts.Add(pFont); |
| 179 m_BufferFonts.SetAt((void*)pBuffer, pFont); | 232 m_BufferFonts.SetAt((void*)pBuffer, pFont); |
| 180 return pFont->Retain(); | 233 return pFont->Retain(); |
| 181 } | 234 } |
| 182 return nullptr; | 235 return nullptr; |
| 183 } | 236 } |
| 184 | 237 |
| 185 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, | 238 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(IFX_Stream* pFontStream, |
| 186 const FX_WCHAR* pszFontAlias, | 239 const FX_WCHAR* pszFontAlias, |
| 187 uint32_t dwFontStyles, | 240 uint32_t dwFontStyles, |
| 188 uint16_t wCodePage, | 241 uint16_t wCodePage, |
| 189 bool bSaveStream) { | 242 bool bSaveStream) { |
| 190 ASSERT(pFontStream && pFontStream->GetLength() > 0); | 243 ASSERT(pFontStream && pFontStream->GetLength() > 0); |
| 191 CFGAS_GEFont* pFont = nullptr; | 244 CFGAS_GEFont* pFont = nullptr; |
| 192 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { | 245 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { |
| 193 if (pFont) { | 246 if (pFont) { |
| 194 if (pszFontAlias) { | 247 if (pszFontAlias) { |
| 195 uint32_t dwHash = | 248 uint32_t dwHash = |
| 196 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); | 249 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); |
| 197 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 250 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 198 } | 251 } |
| 199 return LoadFont(pFont, dwFontStyles, wCodePage); | 252 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 200 } | 253 } |
| 201 } | 254 } |
| 202 pFont = CFGAS_GEFont::LoadFont(pFontStream, this, bSaveStream); | 255 pFont = CFGAS_GEFont::LoadFont(pFontStream, this, bSaveStream); |
| 203 if (pFont) { | 256 if (pFont) { |
| 204 m_Fonts.Add(pFont); | 257 m_Fonts.Add(pFont); |
| 205 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); | 258 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); |
| 206 if (pszFontAlias) { | 259 if (pszFontAlias) { |
| 207 uint32_t dwHash = | 260 uint32_t dwHash = |
| 208 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); | 261 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); |
| 209 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 262 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 210 } | 263 } |
| 211 return LoadFont(pFont, dwFontStyles, wCodePage); | 264 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 212 } | 265 } |
| 213 return nullptr; | 266 return nullptr; |
| 214 } | 267 } |
| 215 | 268 |
| 216 CFGAS_GEFont* CFGAS_StdFontMgrImp::LoadFont(CFGAS_GEFont* pSrcFont, | 269 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(CFGAS_GEFont* pSrcFont, |
| 217 uint32_t dwFontStyles, | 270 uint32_t dwFontStyles, |
| 218 uint16_t wCodePage) { | 271 uint16_t wCodePage) { |
| 219 ASSERT(pSrcFont); | 272 ASSERT(pSrcFont); |
| 220 if (pSrcFont->GetFontStyles() == dwFontStyles) { | 273 if (pSrcFont->GetFontStyles() == dwFontStyles) |
| 221 return pSrcFont->Retain(); | 274 return pSrcFont->Retain(); |
| 222 } | |
| 223 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, | 275 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, |
| 224 (void*)(uintptr_t)wCodePage}; | 276 (void*)(uintptr_t)wCodePage}; |
| 225 uint32_t dwHash = FX_HashCode_GetA( | 277 uint32_t dwHash = FX_HashCode_GetA( |
| 226 CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); | 278 CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); |
| 227 CFGAS_GEFont* pFont = nullptr; | 279 CFGAS_GEFont* pFont = nullptr; |
| 228 if (m_DeriveFonts.GetCount() > 0) { | 280 if (m_DeriveFonts.GetCount() > 0) { |
| 229 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); | 281 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); |
| 230 if (pFont) { | 282 if (pFont) |
| 231 return pFont->Retain(); | 283 return pFont->Retain(); |
| 232 } | |
| 233 } | 284 } |
| 234 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); | 285 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); |
| 235 if (pFont) { | 286 if (pFont) { |
| 236 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 287 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 237 int32_t index = m_Fonts.Find(pFont); | 288 int32_t index = m_Fonts.Find(pFont); |
| 238 if (index < 0) { | 289 if (index < 0) { |
| 239 m_Fonts.Add(pFont); | 290 m_Fonts.Add(pFont); |
| 240 pFont->Retain(); | 291 pFont->Retain(); |
| 241 } | 292 } |
| 242 return pFont; | 293 return pFont; |
| 243 } | 294 } |
| 244 return nullptr; | 295 return nullptr; |
| 245 } | 296 } |
| 246 | 297 |
| 247 void CFGAS_StdFontMgrImp::ClearFontCache() { | 298 void CFGAS_FontMgr::ClearFontCache() { |
| 248 for (int32_t i = 0; i < m_Fonts.GetSize(); i++) | 299 for (int32_t i = 0; i < m_Fonts.GetSize(); i++) |
| 249 m_Fonts[i]->Reset(); | 300 m_Fonts[i]->Reset(); |
| 250 } | 301 } |
| 251 | 302 |
| 252 void CFGAS_StdFontMgrImp::RemoveFont(CFX_MapPtrToPtr& fontMap, | 303 void CFGAS_FontMgr::RemoveFont(CFX_MapPtrToPtr& fontMap, CFGAS_GEFont* pFont) { |
| 253 CFGAS_GEFont* pFont) { | |
| 254 FX_POSITION pos = fontMap.GetStartPosition(); | 304 FX_POSITION pos = fontMap.GetStartPosition(); |
| 255 void* pKey; | 305 void* pKey; |
| 256 void* pFind; | 306 void* pFind; |
| 257 while (pos) { | 307 while (pos) { |
| 258 pFind = nullptr; | 308 pFind = nullptr; |
| 259 fontMap.GetNextAssoc(pos, pKey, pFind); | 309 fontMap.GetNextAssoc(pos, pKey, pFind); |
| 260 if (pFind != (void*)pFont) { | 310 if (pFind != (void*)pFont) |
| 261 continue; | 311 continue; |
| 262 } | |
| 263 fontMap.RemoveKey(pKey); | 312 fontMap.RemoveKey(pKey); |
| 264 break; | 313 break; |
| 265 } | 314 } |
| 266 } | 315 } |
| 267 | 316 |
| 268 void CFGAS_StdFontMgrImp::RemoveFont(CFGAS_GEFont* pFont) { | 317 void CFGAS_FontMgr::RemoveFont(CFGAS_GEFont* pFont) { |
| 269 RemoveFont(m_CPFonts, pFont); | 318 RemoveFont(m_CPFonts, pFont); |
| 270 RemoveFont(m_FamilyFonts, pFont); | 319 RemoveFont(m_FamilyFonts, pFont); |
| 271 RemoveFont(m_UnicodeFonts, pFont); | 320 RemoveFont(m_UnicodeFonts, pFont); |
| 272 RemoveFont(m_BufferFonts, pFont); | 321 RemoveFont(m_BufferFonts, pFont); |
| 273 RemoveFont(m_StreamFonts, pFont); | 322 RemoveFont(m_StreamFonts, pFont); |
| 274 RemoveFont(m_DeriveFonts, pFont); | 323 RemoveFont(m_DeriveFonts, pFont); |
| 275 int32_t iFind = m_Fonts.Find(pFont); | 324 int32_t iFind = m_Fonts.Find(pFont); |
| 276 if (iFind > -1) { | 325 if (iFind > -1) |
| 277 m_Fonts.RemoveAt(iFind, 1); | 326 m_Fonts.RemoveAt(iFind, 1); |
| 278 } | |
| 279 } | 327 } |
| 280 | 328 |
| 281 FX_FONTDESCRIPTOR const* CFGAS_StdFontMgrImp::FindFont( | 329 FX_FONTDESCRIPTOR const* CFGAS_FontMgr::FindFont(const FX_WCHAR* pszFontFamily, |
| 282 const FX_WCHAR* pszFontFamily, | 330 uint32_t dwFontStyles, |
| 283 uint32_t dwFontStyles, | 331 uint32_t dwMatchFlags, |
| 284 uint32_t dwMatchFlags, | 332 uint16_t wCodePage, |
| 285 uint16_t wCodePage, | 333 uint32_t dwUSB, |
| 286 uint32_t dwUSB, | 334 FX_WCHAR wUnicode) { |
| 287 FX_WCHAR wUnicode) { | |
| 288 FX_FONTMATCHPARAMS params; | 335 FX_FONTMATCHPARAMS params; |
| 289 FXSYS_memset(¶ms, 0, sizeof(params)); | 336 FXSYS_memset(¶ms, 0, sizeof(params)); |
| 290 params.dwUSB = dwUSB; | 337 params.dwUSB = dwUSB; |
| 291 params.wUnicode = wUnicode; | 338 params.wUnicode = wUnicode; |
| 292 params.wCodePage = wCodePage; | 339 params.wCodePage = wCodePage; |
| 293 params.pwsFamily = pszFontFamily; | 340 params.pwsFamily = pszFontFamily; |
| 294 params.dwFontStyles = dwFontStyles; | 341 params.dwFontStyles = dwFontStyles; |
| 295 params.dwMatchFlags = dwMatchFlags; | 342 params.dwMatchFlags = dwMatchFlags; |
| 296 FX_FONTDESCRIPTOR const* pDesc = FX_DefFontMatcher(¶ms, m_FontFaces); | 343 FX_FONTDESCRIPTOR const* pDesc = MatchDefaultFont(¶ms, m_FontFaces); |
| 297 if (pDesc) { | 344 if (pDesc) |
| 298 return pDesc; | 345 return pDesc; |
| 299 } | |
| 300 if (pszFontFamily && m_pEnumerator) { | 346 if (pszFontFamily && m_pEnumerator) { |
| 301 CFX_FontDescriptors namedFonts(100); | 347 CFX_FontDescriptors namedFonts(100); |
| 302 m_pEnumerator(namedFonts, pszFontFamily, wUnicode); | 348 m_pEnumerator(namedFonts, pszFontFamily, wUnicode); |
| 303 params.pwsFamily = nullptr; | 349 params.pwsFamily = nullptr; |
| 304 pDesc = FX_DefFontMatcher(¶ms, namedFonts); | 350 pDesc = MatchDefaultFont(¶ms, namedFonts); |
| 305 if (!pDesc) { | 351 if (!pDesc) |
| 306 return nullptr; | 352 return nullptr; |
| 307 } | |
| 308 for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) { | 353 for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) { |
| 309 FX_FONTDESCRIPTOR const* pMatch = m_FontFaces.GetPtrAt(i); | 354 FX_FONTDESCRIPTOR const* pMatch = m_FontFaces.GetPtrAt(i); |
| 310 if (*pMatch == *pDesc) { | 355 if (*pMatch == *pDesc) |
| 311 return pMatch; | 356 return pMatch; |
| 312 } | |
| 313 } | 357 } |
| 314 int index = m_FontFaces.Add(*pDesc); | 358 int index = m_FontFaces.Add(*pDesc); |
| 315 return m_FontFaces.GetPtrAt(index); | 359 return m_FontFaces.GetPtrAt(index); |
| 316 } | 360 } |
| 317 return nullptr; | 361 return nullptr; |
| 318 } | 362 } |
| 319 | 363 |
| 320 FX_FONTDESCRIPTOR const* FX_DefFontMatcher(FX_LPFONTMATCHPARAMS pParams, | |
| 321 const CFX_FontDescriptors& fonts) { | |
| 322 FX_FONTDESCRIPTOR const* pBestFont = nullptr; | |
| 323 int32_t iBestSimilar = 0; | |
| 324 bool bMatchStyle = (pParams->dwMatchFlags & FX_FONTMATCHPARA_MacthStyle) > 0; | |
| 325 int32_t iCount = fonts.GetSize(); | |
| 326 for (int32_t i = 0; i < iCount; ++i) { | |
| 327 FX_FONTDESCRIPTOR const* pFont = fonts.GetPtrAt(i); | |
| 328 if ((pFont->dwFontStyles & FX_FONTSTYLE_BoldItalic) == | |
| 329 FX_FONTSTYLE_BoldItalic) { | |
| 330 continue; | |
| 331 } | |
| 332 if (pParams->pwsFamily) { | |
| 333 if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace)) { | |
| 334 continue; | |
| 335 } | |
| 336 if (pFont->uCharSet == FX_CHARSET_Symbol) { | |
| 337 return pFont; | |
| 338 } | |
| 339 } | |
| 340 if (pFont->uCharSet == FX_CHARSET_Symbol) { | |
| 341 continue; | |
| 342 } | |
| 343 if (pParams->wCodePage != 0xFFFF) { | |
| 344 if (FX_GetCodePageFromCharset(pFont->uCharSet) != pParams->wCodePage) { | |
| 345 continue; | |
| 346 } | |
| 347 } else { | |
| 348 if (pParams->dwUSB < 128) { | |
| 349 uint32_t dwByte = pParams->dwUSB / 32; | |
| 350 uint32_t dwUSB = 1 << (pParams->dwUSB % 32); | |
| 351 if ((pFont->FontSignature.fsUsb[dwByte] & dwUSB) == 0) { | |
| 352 continue; | |
| 353 } | |
| 354 } | |
| 355 } | |
| 356 if (bMatchStyle) { | |
| 357 if ((pFont->dwFontStyles & 0x0F) == (pParams->dwFontStyles & 0x0F)) | |
| 358 return pFont; | |
| 359 continue; | |
| 360 } | |
| 361 if (pParams->pwsFamily) { | |
| 362 if (FXSYS_wcsicmp(pParams->pwsFamily, pFont->wsFontFace) == 0) { | |
| 363 return pFont; | |
| 364 } | |
| 365 } | |
| 366 int32_t iSimilarValue = FX_GetSimilarValue(pFont, pParams->dwFontStyles); | |
| 367 if (iBestSimilar < iSimilarValue) { | |
| 368 iBestSimilar = iSimilarValue; | |
| 369 pBestFont = pFont; | |
| 370 } | |
| 371 } | |
| 372 return iBestSimilar < 1 ? nullptr : pBestFont; | |
| 373 } | |
| 374 | |
| 375 int32_t FX_GetSimilarValue(FX_FONTDESCRIPTOR const* pFont, | |
| 376 uint32_t dwFontStyles) { | |
| 377 int32_t iValue = 0; | |
| 378 if ((dwFontStyles & FX_FONTSTYLE_Symbolic) == | |
| 379 (pFont->dwFontStyles & FX_FONTSTYLE_Symbolic)) { | |
| 380 iValue += 64; | |
| 381 } | |
| 382 if ((dwFontStyles & FX_FONTSTYLE_FixedPitch) == | |
| 383 (pFont->dwFontStyles & FX_FONTSTYLE_FixedPitch)) { | |
| 384 iValue += 32; | |
| 385 } | |
| 386 if ((dwFontStyles & FX_FONTSTYLE_Serif) == | |
| 387 (pFont->dwFontStyles & FX_FONTSTYLE_Serif)) { | |
| 388 iValue += 16; | |
| 389 } | |
| 390 if ((dwFontStyles & FX_FONTSTYLE_Script) == | |
| 391 (pFont->dwFontStyles & FX_FONTSTYLE_Script)) { | |
| 392 iValue += 8; | |
| 393 } | |
| 394 return iValue; | |
| 395 } | |
| 396 | |
| 397 FX_LPMatchFont FX_GetDefFontMatchor() { | |
| 398 return FX_DefFontMatcher; | |
| 399 } | |
| 400 | |
| 401 uint32_t FX_GetGdiFontStyles(const LOGFONTW& lf) { | 364 uint32_t FX_GetGdiFontStyles(const LOGFONTW& lf) { |
| 402 uint32_t dwStyles = 0; | 365 uint32_t dwStyles = 0; |
| 403 if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) { | 366 if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) |
| 404 dwStyles |= FX_FONTSTYLE_FixedPitch; | 367 dwStyles |= FX_FONTSTYLE_FixedPitch; |
| 405 } | |
| 406 uint8_t nFamilies = lf.lfPitchAndFamily & 0xF0; | 368 uint8_t nFamilies = lf.lfPitchAndFamily & 0xF0; |
| 407 if (nFamilies == FF_ROMAN) { | 369 if (nFamilies == FF_ROMAN) |
| 408 dwStyles |= FX_FONTSTYLE_Serif; | 370 dwStyles |= FX_FONTSTYLE_Serif; |
| 409 } | 371 if (nFamilies == FF_SCRIPT) |
| 410 if (nFamilies == FF_SCRIPT) { | |
| 411 dwStyles |= FX_FONTSTYLE_Script; | 372 dwStyles |= FX_FONTSTYLE_Script; |
| 412 } | 373 if (lf.lfCharSet == SYMBOL_CHARSET) |
| 413 if (lf.lfCharSet == SYMBOL_CHARSET) { | |
| 414 dwStyles |= FX_FONTSTYLE_Symbolic; | 374 dwStyles |= FX_FONTSTYLE_Symbolic; |
| 415 } | |
| 416 return dwStyles; | 375 return dwStyles; |
| 417 } | 376 } |
| 418 | 377 |
| 419 static int32_t CALLBACK FX_GdiFontEnumProc(ENUMLOGFONTEX* lpelfe, | 378 static int32_t CALLBACK FX_GdiFontEnumProc(ENUMLOGFONTEX* lpelfe, |
| 420 NEWTEXTMETRICEX* lpntme, | 379 NEWTEXTMETRICEX* lpntme, |
| 421 DWORD dwFontType, | 380 DWORD dwFontType, |
| 422 LPARAM lParam) { | 381 LPARAM lParam) { |
| 423 if (dwFontType != TRUETYPE_FONTTYPE) { | 382 if (dwFontType != TRUETYPE_FONTTYPE) |
| 424 return 1; | 383 return 1; |
| 425 } | |
| 426 const LOGFONTW& lf = ((LPENUMLOGFONTEXW)lpelfe)->elfLogFont; | 384 const LOGFONTW& lf = ((LPENUMLOGFONTEXW)lpelfe)->elfLogFont; |
| 427 if (lf.lfFaceName[0] == L'@') { | 385 if (lf.lfFaceName[0] == L'@') |
| 428 return 1; | 386 return 1; |
| 429 } | |
| 430 FX_FONTDESCRIPTOR* pFont = FX_Alloc(FX_FONTDESCRIPTOR, 1); | 387 FX_FONTDESCRIPTOR* pFont = FX_Alloc(FX_FONTDESCRIPTOR, 1); |
| 431 FXSYS_memset(pFont, 0, sizeof(FX_FONTDESCRIPTOR)); | 388 FXSYS_memset(pFont, 0, sizeof(FX_FONTDESCRIPTOR)); |
| 432 pFont->uCharSet = lf.lfCharSet; | 389 pFont->uCharSet = lf.lfCharSet; |
| 433 pFont->dwFontStyles = FX_GetGdiFontStyles(lf); | 390 pFont->dwFontStyles = FX_GetGdiFontStyles(lf); |
| 434 FXSYS_wcsncpy(pFont->wsFontFace, (const FX_WCHAR*)lf.lfFaceName, 31); | 391 FXSYS_wcsncpy(pFont->wsFontFace, (const FX_WCHAR*)lf.lfFaceName, 31); |
| 435 pFont->wsFontFace[31] = 0; | 392 pFont->wsFontFace[31] = 0; |
| 436 FXSYS_memcpy(&pFont->FontSignature, &lpntme->ntmFontSig, | 393 FXSYS_memcpy(&pFont->FontSignature, &lpntme->ntmFontSig, |
| 437 sizeof(lpntme->ntmFontSig)); | 394 sizeof(lpntme->ntmFontSig)); |
| 438 ((CFX_FontDescriptors*)lParam)->Add(*pFont); | 395 ((CFX_FontDescriptors*)lParam)->Add(*pFont); |
| 439 FX_Free(pFont); | 396 FX_Free(pFont); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 453 } | 410 } |
| 454 EnumFontFamiliesExW(hDC, (LPLOGFONTW)&lfFind, | 411 EnumFontFamiliesExW(hDC, (LPLOGFONTW)&lfFind, |
| 455 (FONTENUMPROCW)FX_GdiFontEnumProc, (LPARAM)&fonts, 0); | 412 (FONTENUMPROCW)FX_GdiFontEnumProc, (LPARAM)&fonts, 0); |
| 456 ::ReleaseDC(nullptr, hDC); | 413 ::ReleaseDC(nullptr, hDC); |
| 457 } | 414 } |
| 458 | 415 |
| 459 FX_LPEnumAllFonts FX_GetDefFontEnumerator() { | 416 FX_LPEnumAllFonts FX_GetDefFontEnumerator() { |
| 460 return FX_EnumGdiFonts; | 417 return FX_EnumGdiFonts; |
| 461 } | 418 } |
| 462 | 419 |
| 463 #else | 420 #else // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 421 |
| 422 namespace { |
| 423 |
| 464 const FX_CHAR* g_FontFolders[] = { | 424 const FX_CHAR* g_FontFolders[] = { |
| 465 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ | 425 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ |
| 466 "/usr/share/fonts", "/usr/share/X11/fonts/Type1", | 426 "/usr/share/fonts", "/usr/share/X11/fonts/Type1", |
| 467 "/usr/share/X11/fonts/TTF", "/usr/local/share/fonts", | 427 "/usr/share/X11/fonts/TTF", "/usr/local/share/fonts", |
| 468 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 428 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 469 "~/Library/Fonts", "/Library/Fonts", "/System/Library/Fonts", | 429 "~/Library/Fonts", "/Library/Fonts", "/System/Library/Fonts", |
| 470 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | 430 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ |
| 471 "/system/fonts", | 431 "/system/fonts", |
| 472 #endif | 432 #endif |
| 473 }; | 433 }; |
| 474 | 434 |
| 435 struct FX_BitCodePage { |
| 436 uint16_t wBit; |
| 437 uint16_t wCodePage; |
| 438 }; |
| 439 |
| 440 const FX_BitCodePage g_Bit2CodePage[] = { |
| 441 {0, 1252}, {1, 1250}, {2, 1251}, {3, 1253}, {4, 1254}, {5, 1255}, |
| 442 {6, 1256}, {7, 1257}, {8, 1258}, {9, 0}, {10, 0}, {11, 0}, |
| 443 {12, 0}, {13, 0}, {14, 0}, {15, 0}, {16, 874}, {17, 932}, |
| 444 {18, 936}, {19, 949}, {20, 950}, {21, 1361}, {22, 0}, {23, 0}, |
| 445 {24, 0}, {25, 0}, {26, 0}, {27, 0}, {28, 0}, {29, 0}, |
| 446 {30, 0}, {31, 0}, {32, 0}, {33, 0}, {34, 0}, {35, 0}, |
| 447 {36, 0}, {37, 0}, {38, 0}, {39, 0}, {40, 0}, {41, 0}, |
| 448 {42, 0}, {43, 0}, {44, 0}, {45, 0}, {46, 0}, {47, 0}, |
| 449 {48, 869}, {49, 866}, {50, 865}, {51, 864}, {52, 863}, {53, 862}, |
| 450 {54, 861}, {55, 860}, {56, 857}, {57, 855}, {58, 852}, {59, 775}, |
| 451 {60, 737}, {61, 708}, {62, 850}, {63, 437}, |
| 452 }; |
| 453 |
| 454 uint16_t FX_GetCodePageBit(uint16_t wCodePage) { |
| 455 for (size_t i = 0; i < FX_ArraySize(g_Bit2CodePage); ++i) { |
| 456 if (g_Bit2CodePage[i].wCodePage == wCodePage) |
| 457 return g_Bit2CodePage[i].wBit; |
| 458 } |
| 459 return (uint16_t)-1; |
| 460 } |
| 461 |
| 462 uint16_t FX_GetUnicodeBit(FX_WCHAR wcUnicode) { |
| 463 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wcUnicode); |
| 464 return x ? x->wBitField : 999; |
| 465 } |
| 466 |
| 467 inline uint8_t GetUInt8(const uint8_t* p) { |
| 468 return (uint8_t)(p[0]); |
| 469 } |
| 470 |
| 471 inline uint16_t GetUInt16(const uint8_t* p) { |
| 472 return (uint16_t)(p[0] << 8 | p[1]); |
| 473 } |
| 474 |
| 475 struct FX_BIT2CHARSET { |
| 476 uint16_t wBit; |
| 477 uint16_t wCharset; |
| 478 }; |
| 479 |
| 480 const FX_BIT2CHARSET g_FX_Bit2Charset1[16] = { |
| 481 {1 << 0, FX_CHARSET_ANSI}, |
| 482 {1 << 1, FX_CHARSET_MSWin_EasterEuropean}, |
| 483 {1 << 2, FX_CHARSET_MSWin_Cyrillic}, |
| 484 {1 << 3, FX_CHARSET_MSWin_Greek}, |
| 485 {1 << 4, FX_CHARSET_MSWin_Turkish}, |
| 486 {1 << 5, FX_CHARSET_MSWin_Hebrew}, |
| 487 {1 << 6, FX_CHARSET_MSWin_Arabic}, |
| 488 {1 << 7, FX_CHARSET_MSWin_Baltic}, |
| 489 {1 << 8, FX_CHARSET_MSWin_Vietnamese}, |
| 490 {1 << 9, FX_CHARSET_Default}, |
| 491 {1 << 10, FX_CHARSET_Default}, |
| 492 {1 << 11, FX_CHARSET_Default}, |
| 493 {1 << 12, FX_CHARSET_Default}, |
| 494 {1 << 13, FX_CHARSET_Default}, |
| 495 {1 << 14, FX_CHARSET_Default}, |
| 496 {1 << 15, FX_CHARSET_Default}, |
| 497 }; |
| 498 |
| 499 const FX_BIT2CHARSET g_FX_Bit2Charset2[16] = { |
| 500 {1 << 0, FX_CHARSET_Thai}, |
| 501 {1 << 1, FX_CHARSET_ShiftJIS}, |
| 502 {1 << 2, FX_CHARSET_ChineseSimplified}, |
| 503 {1 << 3, FX_CHARSET_Korean}, |
| 504 {1 << 4, FX_CHARSET_ChineseTriditional}, |
| 505 {1 << 5, FX_CHARSET_Johab}, |
| 506 {1 << 6, FX_CHARSET_Default}, |
| 507 {1 << 7, FX_CHARSET_Default}, |
| 508 {1 << 8, FX_CHARSET_Default}, |
| 509 {1 << 9, FX_CHARSET_Default}, |
| 510 {1 << 10, FX_CHARSET_Default}, |
| 511 {1 << 11, FX_CHARSET_Default}, |
| 512 {1 << 12, FX_CHARSET_Default}, |
| 513 {1 << 13, FX_CHARSET_Default}, |
| 514 {1 << 14, FX_CHARSET_OEM}, |
| 515 {1 << 15, FX_CHARSET_Symbol}, |
| 516 }; |
| 517 |
| 518 const FX_BIT2CHARSET g_FX_Bit2Charset3[16] = { |
| 519 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, |
| 520 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, |
| 521 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, |
| 522 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, |
| 523 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, |
| 524 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, |
| 525 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, |
| 526 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_Default}, |
| 527 }; |
| 528 |
| 529 const FX_BIT2CHARSET g_FX_Bit2Charset4[16] = { |
| 530 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, |
| 531 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, |
| 532 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, |
| 533 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, |
| 534 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, |
| 535 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, |
| 536 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, |
| 537 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US}, |
| 538 }; |
| 539 |
| 540 } // namespace |
| 541 |
| 475 CFX_FontDescriptor::CFX_FontDescriptor() | 542 CFX_FontDescriptor::CFX_FontDescriptor() |
| 476 : m_nFaceIndex(0), m_dwFontStyles(0), m_dwUsb(), m_dwCsb() {} | 543 : m_nFaceIndex(0), m_dwFontStyles(0), m_dwUsb(), m_dwCsb() {} |
| 477 | 544 |
| 478 CFX_FontDescriptor::~CFX_FontDescriptor() {} | 545 CFX_FontDescriptor::~CFX_FontDescriptor() {} |
| 479 | 546 |
| 480 CFX_FontSourceEnum_File::CFX_FontSourceEnum_File() { | 547 CFX_FontSourceEnum_File::CFX_FontSourceEnum_File() { |
| 481 for (size_t i = 0; i < FX_ArraySize(g_FontFolders); ++i) | 548 for (size_t i = 0; i < FX_ArraySize(g_FontFolders); ++i) |
| 482 m_FolderPaths.Add(g_FontFolders[i]); | 549 m_FolderPaths.Add(g_FontFolders[i]); |
| 483 } | 550 } |
| 484 | 551 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 bsName = | 599 bsName = |
| 533 m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath + | 600 m_FolderQueue.GetDataPtr(m_FolderQueue.GetSize() - 1)->bsParentPath + |
| 534 bsFolderSpearator + bsName; | 601 bsFolderSpearator + bsName; |
| 535 break; | 602 break; |
| 536 } | 603 } |
| 537 return bsName; | 604 return bsName; |
| 538 } | 605 } |
| 539 | 606 |
| 540 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() { | 607 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() { |
| 541 m_wsNext = GetNextFile().UTF8Decode(); | 608 m_wsNext = GetNextFile().UTF8Decode(); |
| 542 if (m_wsNext.GetLength() == 0) { | 609 if (m_wsNext.GetLength() == 0) |
| 543 return (FX_POSITION)0; | 610 return (FX_POSITION)0; |
| 544 } | |
| 545 return (FX_POSITION)-1; | 611 return (FX_POSITION)-1; |
| 546 } | 612 } |
| 547 | 613 |
| 548 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { | 614 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { |
| 549 IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC()); | 615 IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC()); |
| 550 m_wsNext = GetNextFile().UTF8Decode(); | 616 m_wsNext = GetNextFile().UTF8Decode(); |
| 551 pos = m_wsNext.GetLength() != 0 ? pAccess : nullptr; | 617 pos = m_wsNext.GetLength() != 0 ? pAccess : nullptr; |
| 552 return pAccess; | 618 return pAccess; |
| 553 } | 619 } |
| 554 | 620 |
| 555 std::unique_ptr<IFGAS_FontMgr> IFGAS_FontMgr::Create( | 621 std::unique_ptr<CFGAS_FontMgr> CFGAS_FontMgr::Create( |
| 556 CFX_FontSourceEnum_File* pFontEnum) { | 622 CFX_FontSourceEnum_File* pFontEnum) { |
| 557 if (!pFontEnum) | 623 if (!pFontEnum) |
| 558 return nullptr; | 624 return nullptr; |
| 559 | 625 |
| 560 std::unique_ptr<CFGAS_FontMgrImp> pFontMgr(new CFGAS_FontMgrImp(pFontEnum)); | 626 auto pFontMgr = pdfium::MakeUnique<CFGAS_FontMgr>(pFontEnum); |
| 561 if (!pFontMgr->EnumFonts()) | 627 if (!pFontMgr->EnumFonts()) |
| 562 return nullptr; | 628 return nullptr; |
| 563 return std::move(pFontMgr); | 629 return pFontMgr; |
| 564 } | 630 } |
| 565 | 631 |
| 566 CFGAS_FontMgrImp::CFGAS_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum) | 632 CFGAS_FontMgr::CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum) |
| 567 : m_pFontSource(pFontEnum) {} | 633 : m_pFontSource(pFontEnum) {} |
| 568 | 634 |
| 569 CFGAS_FontMgrImp::~CFGAS_FontMgrImp() { | 635 CFGAS_FontMgr::~CFGAS_FontMgr() { |
| 570 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) { | 636 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) |
| 571 delete m_InstalledFonts[i]; | 637 delete m_InstalledFonts[i]; |
| 572 } | |
| 573 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 638 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
| 574 while (pos) { | 639 while (pos) { |
| 575 uint32_t dwHash; | 640 uint32_t dwHash; |
| 576 CFX_FontDescriptorInfos* pDescs; | 641 CFX_FontDescriptorInfos* pDescs; |
| 577 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 642 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
| 578 delete pDescs; | 643 delete pDescs; |
| 579 } | 644 } |
| 580 pos = m_Hash2Fonts.GetStartPosition(); | 645 pos = m_Hash2Fonts.GetStartPosition(); |
| 581 while (pos) { | 646 while (pos) { |
| 582 uint32_t dwHash; | 647 uint32_t dwHash; |
| 583 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; | 648 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |
| 584 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 649 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
| 585 for (int32_t i = 0; i < pFonts->GetSize(); i++) | 650 for (int32_t i = 0; i < pFonts->GetSize(); i++) |
| 586 delete pFonts->GetAt(i); | 651 delete pFonts->GetAt(i); |
| 587 delete pFonts; | 652 delete pFonts; |
| 588 } | 653 } |
| 589 m_Hash2Fonts.RemoveAll(); | 654 m_Hash2Fonts.RemoveAll(); |
| 590 pos = m_IFXFont2FileRead.GetStartPosition(); | 655 pos = m_IFXFont2FileRead.GetStartPosition(); |
| 591 while (pos) { | 656 while (pos) { |
| 592 CFGAS_GEFont* pFont; | 657 CFGAS_GEFont* pFont; |
| 593 IFX_SeekableReadStream* pFileRead; | 658 IFX_SeekableReadStream* pFileRead; |
| 594 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 659 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
| 595 pFileRead->Release(); | 660 pFileRead->Release(); |
| 596 } | 661 } |
| 597 } | 662 } |
| 598 | 663 |
| 599 bool CFGAS_FontMgrImp::EnumFontsFromFontMapper() { | 664 bool CFGAS_FontMgr::EnumFontsFromFontMapper() { |
| 600 CFX_FontMapper* pFontMapper = | 665 CFX_FontMapper* pFontMapper = |
| 601 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); | 666 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); |
| 602 if (!pFontMapper) | 667 if (!pFontMapper) |
| 603 return false; | 668 return false; |
| 604 | 669 |
| 605 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 670 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
| 606 if (!pSystemFontInfo) | 671 if (!pSystemFontInfo) |
| 607 return false; | 672 return false; |
| 608 | 673 |
| 609 pSystemFontInfo->EnumFontList(pFontMapper); | 674 pSystemFontInfo->EnumFontList(pFontMapper); |
| 610 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { | 675 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { |
| 611 IFX_SeekableReadStream* pFontStream = | 676 IFX_SeekableReadStream* pFontStream = |
| 612 CreateFontStream(pFontMapper, pSystemFontInfo, i); | 677 CreateFontStream(pFontMapper, pSystemFontInfo, i); |
| 613 if (!pFontStream) | 678 if (!pFontStream) |
| 614 continue; | 679 continue; |
| 615 | 680 |
| 616 CFX_WideString wsFaceName = | 681 CFX_WideString wsFaceName = |
| 617 CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str()); | 682 CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str()); |
| 618 RegisterFaces(pFontStream, &wsFaceName); | 683 RegisterFaces(pFontStream, &wsFaceName); |
| 619 pFontStream->Release(); | 684 pFontStream->Release(); |
| 620 } | 685 } |
| 621 if (m_InstalledFonts.GetSize() == 0) | 686 if (m_InstalledFonts.GetSize() == 0) |
| 622 return false; | 687 return false; |
| 623 | 688 |
| 624 return true; | 689 return true; |
| 625 } | 690 } |
| 626 | 691 |
| 627 bool CFGAS_FontMgrImp::EnumFontsFromFiles() { | 692 bool CFGAS_FontMgr::EnumFontsFromFiles() { |
| 628 CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary(); | 693 CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary(); |
| 629 FX_POSITION pos = m_pFontSource->GetStartPosition(); | 694 FX_POSITION pos = m_pFontSource->GetStartPosition(); |
| 630 IFX_FileAccess* pFontSource = nullptr; | 695 IFX_FileAccess* pFontSource = nullptr; |
| 631 IFX_SeekableReadStream* pFontStream = nullptr; | 696 IFX_SeekableReadStream* pFontStream = nullptr; |
| 632 while (pos) { | 697 while (pos) { |
| 633 pFontSource = m_pFontSource->GetNext(pos); | 698 pFontSource = m_pFontSource->GetNext(pos); |
| 634 pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); | 699 pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); |
| 635 if (!pFontStream) { | 700 if (!pFontStream) { |
| 636 pFontSource->Release(); | 701 pFontSource->Release(); |
| 637 continue; | 702 continue; |
| 638 } | 703 } |
| 639 RegisterFaces(pFontStream, nullptr); | 704 RegisterFaces(pFontStream, nullptr); |
| 640 pFontStream->Release(); | 705 pFontStream->Release(); |
| 641 pFontSource->Release(); | 706 pFontSource->Release(); |
| 642 } | 707 } |
| 643 if (m_InstalledFonts.GetSize() == 0) | 708 if (m_InstalledFonts.GetSize() == 0) |
| 644 return false; | 709 return false; |
| 645 return true; | 710 return true; |
| 646 } | 711 } |
| 647 | 712 |
| 648 bool CFGAS_FontMgrImp::EnumFonts() { | 713 bool CFGAS_FontMgr::EnumFonts() { |
| 649 if (EnumFontsFromFontMapper()) | 714 if (EnumFontsFromFontMapper()) |
| 650 return true; | 715 return true; |
| 651 return EnumFontsFromFiles(); | 716 return EnumFontsFromFiles(); |
| 652 } | 717 } |
| 653 | 718 |
| 654 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage( | 719 CFGAS_GEFont* CFGAS_FontMgr::GetFontByCodePage(uint16_t wCodePage, |
| 655 uint16_t wCodePage, | 720 uint32_t dwFontStyles, |
| 656 uint32_t dwFontStyles, | 721 const FX_WCHAR* pszFontFamily) { |
| 657 const FX_WCHAR* pszFontFamily) { | |
| 658 return nullptr; | |
| 659 } | |
| 660 | |
| 661 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCharset( | |
| 662 uint8_t nCharset, | |
| 663 uint32_t dwFontStyles, | |
| 664 const FX_WCHAR* pszFontFamily) { | |
| 665 return nullptr; | |
| 666 } | |
| 667 | |
| 668 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByUnicode( | |
| 669 FX_WCHAR wUnicode, | |
| 670 uint32_t dwFontStyles, | |
| 671 const FX_WCHAR* pszFontFamily) { | |
| 672 return nullptr; | |
| 673 } | |
| 674 | |
| 675 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByLanguage( | |
| 676 uint16_t wLanguage, | |
| 677 uint32_t dwFontStyles, | |
| 678 const FX_WCHAR* pszFontFamily) { | |
| 679 return nullptr; | |
| 680 } | |
| 681 | |
| 682 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCodePage( | |
| 683 uint16_t wCodePage, | |
| 684 uint32_t dwFontStyles, | |
| 685 const FX_WCHAR* pszFontFamily) { | |
| 686 CFX_ByteString bsHash; | 722 CFX_ByteString bsHash; |
| 687 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 723 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
| 688 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 724 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
| 689 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | 725 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 690 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts = nullptr; | 726 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts = nullptr; |
| 691 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { | 727 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { |
| 692 if (!pFonts) | 728 if (!pFonts) |
| 693 return nullptr; | 729 return nullptr; |
| 694 | 730 |
| 695 if (pFonts->GetSize() != 0) | 731 if (pFonts->GetSize() != 0) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 713 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; | 749 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; |
| 714 CFGAS_GEFont* pFont = | 750 CFGAS_GEFont* pFont = |
| 715 LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); | 751 LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); |
| 716 if (pFont) | 752 if (pFont) |
| 717 pFont->SetLogicalFontStyle(dwFontStyles); | 753 pFont->SetLogicalFontStyle(dwFontStyles); |
| 718 | 754 |
| 719 pFonts->Add(pFont); | 755 pFonts->Add(pFont); |
| 720 return pFont; | 756 return pFont; |
| 721 } | 757 } |
| 722 | 758 |
| 723 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByCharset( | 759 CFGAS_GEFont* CFGAS_FontMgr::GetFontByUnicode(FX_WCHAR wUnicode, |
| 724 uint8_t nCharset, | 760 uint32_t dwFontStyles, |
| 725 uint32_t dwFontStyles, | 761 const FX_WCHAR* pszFontFamily) { |
| 726 const FX_WCHAR* pszFontFamily) { | |
| 727 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, | |
| 728 pszFontFamily); | |
| 729 } | |
| 730 | |
| 731 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByUnicode( | |
| 732 FX_WCHAR wUnicode, | |
| 733 uint32_t dwFontStyles, | |
| 734 const FX_WCHAR* pszFontFamily) { | |
| 735 CFGAS_GEFont* pFont = nullptr; | 762 CFGAS_GEFont* pFont = nullptr; |
| 736 if (m_FailedUnicodes2Nullptr.Lookup(wUnicode, pFont)) | 763 if (m_FailedUnicodes2Nullptr.Lookup(wUnicode, pFont)) |
| 737 return nullptr; | 764 return nullptr; |
| 738 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); | 765 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); |
| 739 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; | 766 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; |
| 740 uint16_t wBitField = x ? x->wBitField : 0x03E7; | 767 uint16_t wBitField = x ? x->wBitField : 0x03E7; |
| 741 CFX_ByteString bsHash; | 768 CFX_ByteString bsHash; |
| 742 if (wCodePage == 0xFFFF) | 769 if (wCodePage == 0xFFFF) |
| 743 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); | 770 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); |
| 744 else | 771 else |
| (...skipping 28 matching lines...) Expand all Loading... |
| 773 continue; | 800 continue; |
| 774 pFont->SetLogicalFontStyle(dwFontStyles); | 801 pFont->SetLogicalFontStyle(dwFontStyles); |
| 775 pFonts->Add(pFont); | 802 pFonts->Add(pFont); |
| 776 return pFont; | 803 return pFont; |
| 777 } | 804 } |
| 778 if (!pszFontFamily) | 805 if (!pszFontFamily) |
| 779 m_FailedUnicodes2Nullptr.SetAt(wUnicode, nullptr); | 806 m_FailedUnicodes2Nullptr.SetAt(wUnicode, nullptr); |
| 780 return nullptr; | 807 return nullptr; |
| 781 } | 808 } |
| 782 | 809 |
| 783 bool CFGAS_FontMgrImp::VerifyUnicode(CFX_FontDescriptor* pDesc, | 810 bool CFGAS_FontMgr::VerifyUnicode(CFX_FontDescriptor* pDesc, |
| 784 FX_WCHAR wcUnicode) { | 811 FX_WCHAR wcUnicode) { |
| 785 IFX_SeekableReadStream* pFileRead = | 812 IFX_SeekableReadStream* pFileRead = |
| 786 CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); | 813 CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); |
| 787 if (!pFileRead) | 814 if (!pFileRead) |
| 788 return false; | 815 return false; |
| 789 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); | 816 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); |
| 790 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); | 817 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); |
| 791 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); | 818 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); |
| 792 pFileRead->Release(); | 819 pFileRead->Release(); |
| 793 if (!pFace) | 820 if (!pFace) |
| 794 return false; | 821 return false; |
| 795 if (FXFT_Get_Face_External_Stream(pFace)) | 822 if (FXFT_Get_Face_External_Stream(pFace)) |
| 796 FXFT_Clear_Face_External_Stream(pFace); | 823 FXFT_Clear_Face_External_Stream(pFace); |
| 797 FXFT_Done_Face(pFace); | 824 FXFT_Done_Face(pFace); |
| 798 return !retCharmap && retIndex; | 825 return !retCharmap && retIndex; |
| 799 } | 826 } |
| 800 | 827 |
| 801 bool CFGAS_FontMgrImp::VerifyUnicode(CFGAS_GEFont* pFont, FX_WCHAR wcUnicode) { | 828 bool CFGAS_FontMgr::VerifyUnicode(CFGAS_GEFont* pFont, FX_WCHAR wcUnicode) { |
| 802 if (!pFont) | 829 if (!pFont) |
| 803 return false; | 830 return false; |
| 804 | 831 |
| 805 FXFT_Face pFace = pFont->GetDevFont()->GetFace(); | 832 FXFT_Face pFace = pFont->GetDevFont()->GetFace(); |
| 806 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); | 833 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); |
| 807 if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0) | 834 if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0) |
| 808 return false; | 835 return false; |
| 809 | 836 |
| 810 if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) { | 837 if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) { |
| 811 FXFT_Set_Charmap(pFace, charmap); | 838 FXFT_Set_Charmap(pFace, charmap); |
| 812 return false; | 839 return false; |
| 813 } | 840 } |
| 814 return true; | 841 return true; |
| 815 } | 842 } |
| 816 | 843 |
| 817 CFGAS_GEFont* CFGAS_FontMgrImp::GetFontByLanguage( | 844 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(const CFX_WideString& wsFaceName, |
| 818 uint16_t wLanguage, | 845 int32_t iFaceIndex, |
| 819 uint32_t dwFontStyles, | 846 int32_t* pFaceCount) { |
| 820 const FX_WCHAR* pszFontFamily) { | |
| 821 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, | |
| 822 pszFontFamily); | |
| 823 } | |
| 824 | |
| 825 CFGAS_GEFont* CFGAS_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName, | |
| 826 int32_t iFaceIndex, | |
| 827 int32_t* pFaceCount) { | |
| 828 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 847 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
| 829 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | 848 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
| 830 if (!pFontMapper) | 849 if (!pFontMapper) |
| 831 return nullptr; | 850 return nullptr; |
| 832 | 851 |
| 833 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 852 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
| 834 if (!pSystemFontInfo) | 853 if (!pSystemFontInfo) |
| 835 return nullptr; | 854 return nullptr; |
| 836 | 855 |
| 837 IFX_SeekableReadStream* pFontStream = | 856 IFX_SeekableReadStream* pFontStream = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 int res = pFile->ReadBlock(buffer, offset, count); | 891 int res = pFile->ReadBlock(buffer, offset, count); |
| 873 if (res) | 892 if (res) |
| 874 return count; | 893 return count; |
| 875 return 0; | 894 return 0; |
| 876 } | 895 } |
| 877 | 896 |
| 878 void _ftStreamClose(FXFT_Stream stream) {} | 897 void _ftStreamClose(FXFT_Stream stream) {} |
| 879 | 898 |
| 880 }; // extern "C" | 899 }; // extern "C" |
| 881 | 900 |
| 882 FXFT_Face CFGAS_FontMgrImp::LoadFace(IFX_SeekableReadStream* pFontStream, | 901 FXFT_Face CFGAS_FontMgr::LoadFace(IFX_SeekableReadStream* pFontStream, |
| 883 int32_t iFaceIndex) { | 902 int32_t iFaceIndex) { |
| 884 if (!pFontStream) | 903 if (!pFontStream) |
| 885 return nullptr; | 904 return nullptr; |
| 886 | 905 |
| 887 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 906 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
| 888 pFontMgr->InitFTLibrary(); | 907 pFontMgr->InitFTLibrary(); |
| 889 FXFT_Library library = pFontMgr->GetFTLibrary(); | 908 FXFT_Library library = pFontMgr->GetFTLibrary(); |
| 890 if (!library) | 909 if (!library) |
| 891 return nullptr; | 910 return nullptr; |
| 892 | 911 |
| 893 FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); | 912 FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 907 FXFT_Face pFace = nullptr; | 926 FXFT_Face pFace = nullptr; |
| 908 if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { | 927 if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { |
| 909 FX_Free(ftStream); | 928 FX_Free(ftStream); |
| 910 return nullptr; | 929 return nullptr; |
| 911 } | 930 } |
| 912 | 931 |
| 913 FXFT_Set_Pixel_Sizes(pFace, 0, 64); | 932 FXFT_Set_Pixel_Sizes(pFace, 0, 64); |
| 914 return pFace; | 933 return pFace; |
| 915 } | 934 } |
| 916 | 935 |
| 917 IFX_SeekableReadStream* CFGAS_FontMgrImp::CreateFontStream( | 936 IFX_SeekableReadStream* CFGAS_FontMgr::CreateFontStream( |
| 918 CFX_FontMapper* pFontMapper, | 937 CFX_FontMapper* pFontMapper, |
| 919 IFX_SystemFontInfo* pSystemFontInfo, | 938 IFX_SystemFontInfo* pSystemFontInfo, |
| 920 uint32_t index) { | 939 uint32_t index) { |
| 921 int iExact = 0; | 940 int iExact = 0; |
| 922 void* hFont = | 941 void* hFont = |
| 923 pSystemFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, | 942 pSystemFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, |
| 924 pFontMapper->GetFaceName(index).c_str(), iExact); | 943 pFontMapper->GetFaceName(index).c_str(), iExact); |
| 925 if (!hFont) | 944 if (!hFont) |
| 926 return nullptr; | 945 return nullptr; |
| 927 | 946 |
| 928 uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0); | 947 uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, nullptr, 0); |
| 929 if (dwFileSize == 0) | 948 if (dwFileSize == 0) |
| 930 return nullptr; | 949 return nullptr; |
| 931 | 950 |
| 932 uint8_t* pBuffer = FX_Alloc(uint8_t, dwFileSize + 1); | 951 uint8_t* pBuffer = FX_Alloc(uint8_t, dwFileSize + 1); |
| 933 dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, pBuffer, dwFileSize); | 952 dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, pBuffer, dwFileSize); |
| 934 | 953 |
| 935 return FX_CreateMemoryStream(pBuffer, dwFileSize, true); | 954 return FX_CreateMemoryStream(pBuffer, dwFileSize, true); |
| 936 } | 955 } |
| 937 | 956 |
| 938 IFX_SeekableReadStream* CFGAS_FontMgrImp::CreateFontStream( | 957 IFX_SeekableReadStream* CFGAS_FontMgr::CreateFontStream( |
| 939 const CFX_ByteString& bsFaceName) { | 958 const CFX_ByteString& bsFaceName) { |
| 940 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 959 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
| 941 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | 960 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
| 942 | 961 |
| 943 if (!pFontMapper) | 962 if (!pFontMapper) |
| 944 return nullptr; | 963 return nullptr; |
| 945 | 964 |
| 946 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 965 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
| 947 if (!pSystemFontInfo) | 966 if (!pSystemFontInfo) |
| 948 return nullptr; | 967 return nullptr; |
| 949 | 968 |
| 950 pSystemFontInfo->EnumFontList(pFontMapper); | 969 pSystemFontInfo->EnumFontList(pFontMapper); |
| 951 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { | 970 for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { |
| 952 if (pFontMapper->GetFaceName(i) == bsFaceName) | 971 if (pFontMapper->GetFaceName(i) == bsFaceName) |
| 953 return CreateFontStream(pFontMapper, pSystemFontInfo, i); | 972 return CreateFontStream(pFontMapper, pSystemFontInfo, i); |
| 954 } | 973 } |
| 955 return nullptr; | 974 return nullptr; |
| 956 } | 975 } |
| 957 | 976 |
| 958 int32_t CFGAS_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, | 977 int32_t CFGAS_FontMgr::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, |
| 959 uint16_t wCodePage, | 978 uint16_t wCodePage, |
| 960 uint32_t dwFontStyles, | 979 uint32_t dwFontStyles, |
| 961 const CFX_WideString& FontName, | 980 const CFX_WideString& FontName, |
| 962 FX_WCHAR wcUnicode) { | 981 FX_WCHAR wcUnicode) { |
| 963 MatchedFonts.RemoveAll(); | 982 MatchedFonts.RemoveAll(); |
| 964 CFX_WideString wsNormalizedFontName = FontName; | 983 CFX_WideString wsNormalizedFontName = FontName; |
| 965 | 984 |
| 966 CFX_FontDescriptor* pFont = nullptr; | 985 CFX_FontDescriptor* pFont = nullptr; |
| 967 int32_t nCount = m_InstalledFonts.GetSize(); | 986 int32_t nCount = m_InstalledFonts.GetSize(); |
| 968 for (int32_t i = 0; i < nCount; i++) { | 987 for (int32_t i = 0; i < nCount; i++) { |
| 969 pFont = m_InstalledFonts[i]; | 988 pFont = m_InstalledFonts[i]; |
| 970 int32_t nPenalty = CalcPenalty(pFont, wCodePage, dwFontStyles, | 989 int32_t nPenalty = CalcPenalty(pFont, wCodePage, dwFontStyles, |
| 971 wsNormalizedFontName, wcUnicode); | 990 wsNormalizedFontName, wcUnicode); |
| 972 if (nPenalty >= 0xffff) | 991 if (nPenalty >= 0xffff) |
| 973 continue; | 992 continue; |
| 974 | 993 |
| 975 FX_FontDescriptorInfo FontInfo; | 994 FX_FontDescriptorInfo FontInfo; |
| 976 FontInfo.pFont = pFont; | 995 FontInfo.pFont = pFont; |
| 977 FontInfo.nPenalty = nPenalty; | 996 FontInfo.nPenalty = nPenalty; |
| 978 MatchedFonts.Add(FontInfo); | 997 MatchedFonts.Add(FontInfo); |
| 979 if (MatchedFonts.GetSize() == 0xffff) | 998 if (MatchedFonts.GetSize() == 0xffff) |
| 980 break; | 999 break; |
| 981 } | 1000 } |
| 982 if (MatchedFonts.GetSize() == 0) | 1001 if (MatchedFonts.GetSize() == 0) |
| 983 return 0; | 1002 return 0; |
| 984 | 1003 |
| 985 CFX_SSortTemplate<FX_FontDescriptorInfo> ssort; | 1004 CFX_SSortTemplate<FX_FontDescriptorInfo> ssort; |
| 986 ssort.ShellSort(MatchedFonts.GetData(), MatchedFonts.GetSize()); | 1005 ssort.ShellSort(MatchedFonts.GetData(), MatchedFonts.GetSize()); |
| 987 return MatchedFonts.GetSize(); | 1006 return MatchedFonts.GetSize(); |
| 988 } | 1007 } |
| 989 | 1008 |
| 990 struct FX_BitCodePage { | 1009 int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled, |
| 991 uint16_t wBit; | 1010 uint16_t wCodePage, |
| 992 uint16_t wCodePage; | 1011 uint32_t dwFontStyles, |
| 993 }; | 1012 const CFX_WideString& FontName, |
| 994 static const FX_BitCodePage g_Bit2CodePage[] = { | 1013 FX_WCHAR wcUnicode) { |
| 995 {0, 1252}, {1, 1250}, {2, 1251}, {3, 1253}, {4, 1254}, {5, 1255}, | |
| 996 {6, 1256}, {7, 1257}, {8, 1258}, {9, 0}, {10, 0}, {11, 0}, | |
| 997 {12, 0}, {13, 0}, {14, 0}, {15, 0}, {16, 874}, {17, 932}, | |
| 998 {18, 936}, {19, 949}, {20, 950}, {21, 1361}, {22, 0}, {23, 0}, | |
| 999 {24, 0}, {25, 0}, {26, 0}, {27, 0}, {28, 0}, {29, 0}, | |
| 1000 {30, 0}, {31, 0}, {32, 0}, {33, 0}, {34, 0}, {35, 0}, | |
| 1001 {36, 0}, {37, 0}, {38, 0}, {39, 0}, {40, 0}, {41, 0}, | |
| 1002 {42, 0}, {43, 0}, {44, 0}, {45, 0}, {46, 0}, {47, 0}, | |
| 1003 {48, 869}, {49, 866}, {50, 865}, {51, 864}, {52, 863}, {53, 862}, | |
| 1004 {54, 861}, {55, 860}, {56, 857}, {57, 855}, {58, 852}, {59, 775}, | |
| 1005 {60, 737}, {61, 708}, {62, 850}, {63, 437}, | |
| 1006 }; | |
| 1007 | |
| 1008 uint16_t FX_GetCodePageBit(uint16_t wCodePage) { | |
| 1009 for (size_t i = 0; i < FX_ArraySize(g_Bit2CodePage); ++i) { | |
| 1010 if (g_Bit2CodePage[i].wCodePage == wCodePage) | |
| 1011 return g_Bit2CodePage[i].wBit; | |
| 1012 } | |
| 1013 return (uint16_t)-1; | |
| 1014 } | |
| 1015 | |
| 1016 uint16_t FX_GetUnicodeBit(FX_WCHAR wcUnicode) { | |
| 1017 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wcUnicode); | |
| 1018 return x ? x->wBitField : 999; | |
| 1019 } | |
| 1020 | |
| 1021 int32_t CFGAS_FontMgrImp::CalcPenalty(CFX_FontDescriptor* pInstalled, | |
| 1022 uint16_t wCodePage, | |
| 1023 uint32_t dwFontStyles, | |
| 1024 const CFX_WideString& FontName, | |
| 1025 FX_WCHAR wcUnicode) { | |
| 1026 int32_t nPenalty = 30000; | 1014 int32_t nPenalty = 30000; |
| 1027 if (0 != FontName.GetLength()) { | 1015 if (0 != FontName.GetLength()) { |
| 1028 if (FontName != pInstalled->m_wsFaceName) { | 1016 if (FontName != pInstalled->m_wsFaceName) { |
| 1029 int32_t i; | 1017 int32_t i; |
| 1030 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { | 1018 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { |
| 1031 if (pInstalled->m_wsFamilyNames[i] == FontName) { | 1019 if (pInstalled->m_wsFamilyNames[i] == FontName) |
| 1032 break; | 1020 break; |
| 1033 } | |
| 1034 } | 1021 } |
| 1035 if (i == pInstalled->m_wsFamilyNames.GetSize()) { | 1022 if (i == pInstalled->m_wsFamilyNames.GetSize()) |
| 1036 nPenalty += 0xFFFF; | 1023 nPenalty += 0xFFFF; |
| 1037 } else { | 1024 else |
| 1038 nPenalty -= 28000; | 1025 nPenalty -= 28000; |
| 1039 } | |
| 1040 } else { | 1026 } else { |
| 1041 nPenalty -= 30000; | 1027 nPenalty -= 30000; |
| 1042 } | 1028 } |
| 1043 if (30000 == nPenalty && | 1029 if (30000 == nPenalty && |
| 1044 0 == IsPartName(pInstalled->m_wsFaceName, FontName)) { | 1030 0 == IsPartName(pInstalled->m_wsFaceName, FontName)) { |
| 1045 int32_t i; | 1031 int32_t i; |
| 1046 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { | 1032 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { |
| 1047 if (0 != IsPartName(pInstalled->m_wsFamilyNames[i], FontName)) { | 1033 if (0 != IsPartName(pInstalled->m_wsFamilyNames[i], FontName)) |
| 1048 break; | 1034 break; |
| 1049 } | |
| 1050 } | 1035 } |
| 1051 if (i == pInstalled->m_wsFamilyNames.GetSize()) { | 1036 if (i == pInstalled->m_wsFamilyNames.GetSize()) |
| 1052 nPenalty += 0xFFFF; | 1037 nPenalty += 0xFFFF; |
| 1053 } else { | 1038 else |
| 1054 nPenalty -= 26000; | 1039 nPenalty -= 26000; |
| 1055 } | |
| 1056 } else { | 1040 } else { |
| 1057 nPenalty -= 27000; | 1041 nPenalty -= 27000; |
| 1058 } | 1042 } |
| 1059 } | 1043 } |
| 1060 uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; | 1044 uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; |
| 1061 if (dwStyleMask & FX_FONTSTYLE_Bold) { | 1045 if (dwStyleMask & FX_FONTSTYLE_Bold) |
| 1062 nPenalty += 4500; | 1046 nPenalty += 4500; |
| 1063 } | 1047 if (dwStyleMask & FX_FONTSTYLE_FixedPitch) |
| 1064 if (dwStyleMask & FX_FONTSTYLE_FixedPitch) { | |
| 1065 nPenalty += 10000; | 1048 nPenalty += 10000; |
| 1066 } | 1049 if (dwStyleMask & FX_FONTSTYLE_Italic) |
| 1067 if (dwStyleMask & FX_FONTSTYLE_Italic) { | |
| 1068 nPenalty += 10000; | 1050 nPenalty += 10000; |
| 1069 } | 1051 if (dwStyleMask & FX_FONTSTYLE_Serif) |
| 1070 if (dwStyleMask & FX_FONTSTYLE_Serif) { | |
| 1071 nPenalty += 500; | 1052 nPenalty += 500; |
| 1072 } | 1053 if (dwStyleMask & FX_FONTSTYLE_Symbolic) |
| 1073 if (dwStyleMask & FX_FONTSTYLE_Symbolic) { | |
| 1074 nPenalty += 0xFFFF; | 1054 nPenalty += 0xFFFF; |
| 1075 } | 1055 if (nPenalty >= 0xFFFF) |
| 1076 if (nPenalty >= 0xFFFF) { | |
| 1077 return 0xFFFF; | 1056 return 0xFFFF; |
| 1078 } | |
| 1079 uint16_t wBit = | 1057 uint16_t wBit = |
| 1080 ((0 == wCodePage || 0xFFFF == wCodePage) ? (uint16_t)-1 | 1058 ((0 == wCodePage || 0xFFFF == wCodePage) ? (uint16_t)-1 |
| 1081 : FX_GetCodePageBit(wCodePage)); | 1059 : FX_GetCodePageBit(wCodePage)); |
| 1082 if (wBit != (uint16_t)-1) { | 1060 if (wBit != (uint16_t)-1) { |
| 1083 ASSERT(wBit < 64); | 1061 ASSERT(wBit < 64); |
| 1084 if (0 == (pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32)))) { | 1062 if (0 == (pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32)))) |
| 1085 nPenalty += 0xFFFF; | 1063 nPenalty += 0xFFFF; |
| 1086 } else { | 1064 else |
| 1087 nPenalty -= 60000; | 1065 nPenalty -= 60000; |
| 1088 } | |
| 1089 } | 1066 } |
| 1090 wBit = | 1067 wBit = |
| 1091 ((0 == wcUnicode || 0xFFFE == wcUnicode) ? (uint16_t)999 | 1068 ((0 == wcUnicode || 0xFFFE == wcUnicode) ? (uint16_t)999 |
| 1092 : FX_GetUnicodeBit(wcUnicode)); | 1069 : FX_GetUnicodeBit(wcUnicode)); |
| 1093 if (wBit != (uint16_t)999) { | 1070 if (wBit != (uint16_t)999) { |
| 1094 ASSERT(wBit < 128); | 1071 ASSERT(wBit < 128); |
| 1095 if (0 == (pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32)))) { | 1072 if (0 == (pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32)))) |
| 1096 nPenalty += 0xFFFF; | 1073 nPenalty += 0xFFFF; |
| 1097 } else { | 1074 else |
| 1098 nPenalty -= 60000; | 1075 nPenalty -= 60000; |
| 1099 } | |
| 1100 } | 1076 } |
| 1101 return nPenalty; | 1077 return nPenalty; |
| 1102 } | 1078 } |
| 1103 | 1079 |
| 1104 void CFGAS_FontMgrImp::ClearFontCache() { | 1080 void CFGAS_FontMgr::ClearFontCache() { |
| 1105 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 1081 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |
| 1106 while (pos) { | 1082 while (pos) { |
| 1107 uint32_t dwHash; | 1083 uint32_t dwHash; |
| 1108 CFX_FontDescriptorInfos* pDescs; | 1084 CFX_FontDescriptorInfos* pDescs; |
| 1109 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 1085 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |
| 1110 delete pDescs; | 1086 delete pDescs; |
| 1111 } | 1087 } |
| 1112 pos = m_IFXFont2FileRead.GetStartPosition(); | 1088 pos = m_IFXFont2FileRead.GetStartPosition(); |
| 1113 while (pos) { | 1089 while (pos) { |
| 1114 CFGAS_GEFont* pFont; | 1090 CFGAS_GEFont* pFont; |
| 1115 IFX_SeekableReadStream* pFileRead; | 1091 IFX_SeekableReadStream* pFileRead; |
| 1116 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 1092 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |
| 1117 pFileRead->Release(); | 1093 pFileRead->Release(); |
| 1118 } | 1094 } |
| 1119 } | 1095 } |
| 1120 | 1096 |
| 1121 void CFGAS_FontMgrImp::RemoveFont(CFGAS_GEFont* pEFont) { | 1097 void CFGAS_FontMgr::RemoveFont(CFGAS_GEFont* pEFont) { |
| 1122 if (!pEFont) { | 1098 if (!pEFont) |
| 1123 return; | 1099 return; |
| 1124 } | 1100 |
| 1125 IFX_SeekableReadStream* pFileRead; | 1101 IFX_SeekableReadStream* pFileRead; |
| 1126 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { | 1102 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { |
| 1127 pFileRead->Release(); | 1103 pFileRead->Release(); |
| 1128 m_IFXFont2FileRead.RemoveKey(pEFont); | 1104 m_IFXFont2FileRead.RemoveKey(pEFont); |
| 1129 } | 1105 } |
| 1130 FX_POSITION pos; | 1106 FX_POSITION pos; |
| 1131 pos = m_Hash2Fonts.GetStartPosition(); | 1107 pos = m_Hash2Fonts.GetStartPosition(); |
| 1132 while (pos) { | 1108 while (pos) { |
| 1133 uint32_t dwHash; | 1109 uint32_t dwHash; |
| 1134 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; | 1110 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |
| 1135 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 1111 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |
| 1136 if (pFonts) { | 1112 if (pFonts) { |
| 1137 for (int32_t i = 0; i < pFonts->GetSize(); i++) { | 1113 for (int32_t i = 0; i < pFonts->GetSize(); i++) { |
| 1138 if (pFonts->GetAt(i) == pEFont) { | 1114 if (pFonts->GetAt(i) == pEFont) |
| 1139 pFonts->SetAt(i, nullptr); | 1115 pFonts->SetAt(i, nullptr); |
| 1140 } | |
| 1141 } | 1116 } |
| 1142 } else { | 1117 } else { |
| 1143 m_Hash2Fonts.RemoveKey(dwHash); | 1118 m_Hash2Fonts.RemoveKey(dwHash); |
| 1144 } | 1119 } |
| 1145 } | 1120 } |
| 1146 } | 1121 } |
| 1147 | 1122 |
| 1148 void CFGAS_FontMgrImp::RegisterFace(FXFT_Face pFace, | 1123 void CFGAS_FontMgr::RegisterFace(FXFT_Face pFace, |
| 1149 const CFX_WideString* pFaceName) { | 1124 const CFX_WideString* pFaceName) { |
| 1150 if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0) | 1125 if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0) |
| 1151 return; | 1126 return; |
| 1152 | 1127 |
| 1153 std::unique_ptr<CFX_FontDescriptor> pFont(new CFX_FontDescriptor); | 1128 std::unique_ptr<CFX_FontDescriptor> pFont(new CFX_FontDescriptor); |
| 1154 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; | 1129 pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; |
| 1155 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; | 1130 pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; |
| 1156 pFont->m_dwFontStyles |= GetFlags(pFace); | 1131 pFont->m_dwFontStyles |= GetFlags(pFace); |
| 1157 | 1132 |
| 1158 std::vector<uint16_t> charsets = GetCharsets(pFace); | 1133 std::vector<uint16_t> charsets = GetCharsets(pFace); |
| 1159 GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb); | 1134 GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1173 | 1148 |
| 1174 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); | 1149 pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); |
| 1175 pFont->m_wsFaceName = | 1150 pFont->m_wsFaceName = |
| 1176 pFaceName ? *pFaceName | 1151 pFaceName ? *pFaceName |
| 1177 : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); | 1152 : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); |
| 1178 pFont->m_nFaceIndex = pFace->face_index; | 1153 pFont->m_nFaceIndex = pFace->face_index; |
| 1179 | 1154 |
| 1180 m_InstalledFonts.Add(pFont.release()); | 1155 m_InstalledFonts.Add(pFont.release()); |
| 1181 } | 1156 } |
| 1182 | 1157 |
| 1183 void CFGAS_FontMgrImp::RegisterFaces(IFX_SeekableReadStream* pFontStream, | 1158 void CFGAS_FontMgr::RegisterFaces(IFX_SeekableReadStream* pFontStream, |
| 1184 const CFX_WideString* pFaceName) { | 1159 const CFX_WideString* pFaceName) { |
| 1185 int32_t index = 0; | 1160 int32_t index = 0; |
| 1186 int32_t num_faces = 0; | 1161 int32_t num_faces = 0; |
| 1187 do { | 1162 do { |
| 1188 FXFT_Face pFace = LoadFace(pFontStream, index++); | 1163 FXFT_Face pFace = LoadFace(pFontStream, index++); |
| 1189 if (!pFace) | 1164 if (!pFace) |
| 1190 continue; | 1165 continue; |
| 1191 // All faces keep number of faces. It can be retrieved from any one face. | 1166 // All faces keep number of faces. It can be retrieved from any one face. |
| 1192 if (num_faces == 0) | 1167 if (num_faces == 0) |
| 1193 num_faces = pFace->num_faces; | 1168 num_faces = pFace->num_faces; |
| 1194 RegisterFace(pFace, pFaceName); | 1169 RegisterFace(pFace, pFaceName); |
| 1195 if (FXFT_Get_Face_External_Stream(pFace)) | 1170 if (FXFT_Get_Face_External_Stream(pFace)) |
| 1196 FXFT_Clear_Face_External_Stream(pFace); | 1171 FXFT_Clear_Face_External_Stream(pFace); |
| 1197 FXFT_Done_Face(pFace); | 1172 FXFT_Done_Face(pFace); |
| 1198 } while (index < num_faces); | 1173 } while (index < num_faces); |
| 1199 } | 1174 } |
| 1200 | 1175 |
| 1201 uint32_t CFGAS_FontMgrImp::GetFlags(FXFT_Face pFace) { | 1176 uint32_t CFGAS_FontMgr::GetFlags(FXFT_Face pFace) { |
| 1202 uint32_t flag = 0; | 1177 uint32_t flag = 0; |
| 1203 if (FT_IS_FIXED_WIDTH(pFace)) { | 1178 if (FT_IS_FIXED_WIDTH(pFace)) |
| 1204 flag |= FX_FONTSTYLE_FixedPitch; | 1179 flag |= FX_FONTSTYLE_FixedPitch; |
| 1205 } | |
| 1206 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1180 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
| 1207 if (!pOS2) { | 1181 if (!pOS2) |
| 1208 return flag; | 1182 return flag; |
| 1209 } | 1183 if (pOS2->ulCodePageRange1 & (1 << 31)) |
| 1210 if (pOS2->ulCodePageRange1 & (1 << 31)) { | |
| 1211 flag |= FX_FONTSTYLE_Symbolic; | 1184 flag |= FX_FONTSTYLE_Symbolic; |
| 1212 } | |
| 1213 if (pOS2->panose[0] == 2) { | 1185 if (pOS2->panose[0] == 2) { |
| 1214 uint8_t uSerif = pOS2->panose[1]; | 1186 uint8_t uSerif = pOS2->panose[1]; |
| 1215 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) { | 1187 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) |
| 1216 flag |= FX_FONTSTYLE_Serif; | 1188 flag |= FX_FONTSTYLE_Serif; |
| 1217 } | |
| 1218 } | 1189 } |
| 1219 return flag; | 1190 return flag; |
| 1220 } | 1191 } |
| 1221 | 1192 |
| 1222 #define GetUInt8(p) ((uint8_t)((p)[0])) | 1193 void CFGAS_FontMgr::GetNames(const uint8_t* name_table, |
| 1223 #define GetUInt16(p) ((uint16_t)((p)[0] << 8 | (p)[1])) | 1194 CFX_WideStringArray& Names) { |
| 1224 #define GetUInt32(p) \ | |
| 1225 ((uint32_t)((p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3])) | |
| 1226 | |
| 1227 void CFGAS_FontMgrImp::GetNames(const uint8_t* name_table, | |
| 1228 CFX_WideStringArray& Names) { | |
| 1229 if (!name_table) { | 1195 if (!name_table) { |
| 1230 return; | 1196 return; |
| 1231 } | 1197 } |
| 1232 uint8_t* lpTable = (uint8_t*)name_table; | 1198 uint8_t* lpTable = (uint8_t*)name_table; |
| 1233 CFX_WideString wsFamily; | 1199 CFX_WideString wsFamily; |
| 1234 uint8_t* sp = lpTable + 2; | 1200 uint8_t* sp = lpTable + 2; |
| 1235 uint8_t* lpNameRecord = lpTable + 6; | 1201 uint8_t* lpNameRecord = lpTable + 6; |
| 1236 uint16_t nNameCount = GetUInt16(sp); | 1202 uint16_t nNameCount = GetUInt16(sp); |
| 1237 uint8_t* lpStr = lpTable + GetUInt16(sp + 2); | 1203 uint8_t* lpStr = lpTable + GetUInt16(sp + 2); |
| 1238 for (uint16_t j = 0; j < nNameCount; j++) { | 1204 for (uint16_t j = 0; j < nNameCount; j++) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1252 Names.Add(wsFamily); | 1218 Names.Add(wsFamily); |
| 1253 } else { | 1219 } else { |
| 1254 for (uint16_t k = 0; k < nNameLength; k++) { | 1220 for (uint16_t k = 0; k < nNameLength; k++) { |
| 1255 FX_WCHAR wcTemp = GetUInt8(lpStr + nNameOffset + k); | 1221 FX_WCHAR wcTemp = GetUInt8(lpStr + nNameOffset + k); |
| 1256 wsFamily += wcTemp; | 1222 wsFamily += wcTemp; |
| 1257 } | 1223 } |
| 1258 Names.Add(wsFamily); | 1224 Names.Add(wsFamily); |
| 1259 } | 1225 } |
| 1260 } | 1226 } |
| 1261 } | 1227 } |
| 1262 #undef GetUInt8 | |
| 1263 #undef GetUInt16 | |
| 1264 #undef GetUInt32 | |
| 1265 struct FX_BIT2CHARSET { | |
| 1266 uint16_t wBit; | |
| 1267 uint16_t wCharset; | |
| 1268 }; | |
| 1269 | 1228 |
| 1270 FX_BIT2CHARSET g_FX_Bit2Charset1[16] = { | 1229 // TODO(npm): Get rid of this #define |
| 1271 {1 << 0, FX_CHARSET_ANSI}, | |
| 1272 {1 << 1, FX_CHARSET_MSWin_EasterEuropean}, | |
| 1273 {1 << 2, FX_CHARSET_MSWin_Cyrillic}, | |
| 1274 {1 << 3, FX_CHARSET_MSWin_Greek}, | |
| 1275 {1 << 4, FX_CHARSET_MSWin_Turkish}, | |
| 1276 {1 << 5, FX_CHARSET_MSWin_Hebrew}, | |
| 1277 {1 << 6, FX_CHARSET_MSWin_Arabic}, | |
| 1278 {1 << 7, FX_CHARSET_MSWin_Baltic}, | |
| 1279 {1 << 8, FX_CHARSET_MSWin_Vietnamese}, | |
| 1280 {1 << 9, FX_CHARSET_Default}, | |
| 1281 {1 << 10, FX_CHARSET_Default}, | |
| 1282 {1 << 11, FX_CHARSET_Default}, | |
| 1283 {1 << 12, FX_CHARSET_Default}, | |
| 1284 {1 << 13, FX_CHARSET_Default}, | |
| 1285 {1 << 14, FX_CHARSET_Default}, | |
| 1286 {1 << 15, FX_CHARSET_Default}, | |
| 1287 }; | |
| 1288 | |
| 1289 FX_BIT2CHARSET g_FX_Bit2Charset2[16] = { | |
| 1290 {1 << 0, FX_CHARSET_Thai}, | |
| 1291 {1 << 1, FX_CHARSET_ShiftJIS}, | |
| 1292 {1 << 2, FX_CHARSET_ChineseSimplified}, | |
| 1293 {1 << 3, FX_CHARSET_Korean}, | |
| 1294 {1 << 4, FX_CHARSET_ChineseTriditional}, | |
| 1295 {1 << 5, FX_CHARSET_Johab}, | |
| 1296 {1 << 6, FX_CHARSET_Default}, | |
| 1297 {1 << 7, FX_CHARSET_Default}, | |
| 1298 {1 << 8, FX_CHARSET_Default}, | |
| 1299 {1 << 9, FX_CHARSET_Default}, | |
| 1300 {1 << 10, FX_CHARSET_Default}, | |
| 1301 {1 << 11, FX_CHARSET_Default}, | |
| 1302 {1 << 12, FX_CHARSET_Default}, | |
| 1303 {1 << 13, FX_CHARSET_Default}, | |
| 1304 {1 << 14, FX_CHARSET_OEM}, | |
| 1305 {1 << 15, FX_CHARSET_Symbol}, | |
| 1306 }; | |
| 1307 | |
| 1308 FX_BIT2CHARSET g_FX_Bit2Charset3[16] = { | |
| 1309 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, | |
| 1310 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, | |
| 1311 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, | |
| 1312 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, | |
| 1313 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, | |
| 1314 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, | |
| 1315 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, | |
| 1316 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_Default}, | |
| 1317 }; | |
| 1318 | |
| 1319 FX_BIT2CHARSET g_FX_Bit2Charset4[16] = { | |
| 1320 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, | |
| 1321 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, | |
| 1322 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, | |
| 1323 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, | |
| 1324 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, | |
| 1325 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, | |
| 1326 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, | |
| 1327 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US}, | |
| 1328 }; | |
| 1329 | |
| 1330 #define CODEPAGERANGE_IMPLEMENT(n) \ | 1230 #define CODEPAGERANGE_IMPLEMENT(n) \ |
| 1331 for (int32_t i = 0; i < 16; i++) { \ | 1231 for (int32_t i = 0; i < 16; i++) { \ |
| 1332 if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) \ | 1232 if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) \ |
| 1333 charsets.push_back(g_FX_Bit2Charset##n[i].wCharset); \ | 1233 charsets.push_back(g_FX_Bit2Charset##n[i].wCharset); \ |
| 1334 } | 1234 } |
| 1335 | 1235 |
| 1336 std::vector<uint16_t> CFGAS_FontMgrImp::GetCharsets(FXFT_Face pFace) const { | 1236 std::vector<uint16_t> CFGAS_FontMgr::GetCharsets(FXFT_Face pFace) const { |
| 1337 std::vector<uint16_t> charsets; | 1237 std::vector<uint16_t> charsets; |
| 1338 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1238 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
| 1339 if (pOS2) { | 1239 if (pOS2) { |
| 1340 uint16_t a1 = pOS2->ulCodePageRange1 & 0xffff; | 1240 uint16_t a1 = pOS2->ulCodePageRange1 & 0xffff; |
| 1341 CODEPAGERANGE_IMPLEMENT(1); | 1241 CODEPAGERANGE_IMPLEMENT(1); |
| 1342 uint16_t a2 = (pOS2->ulCodePageRange1 >> 16) & 0xffff; | 1242 uint16_t a2 = (pOS2->ulCodePageRange1 >> 16) & 0xffff; |
| 1343 CODEPAGERANGE_IMPLEMENT(2); | 1243 CODEPAGERANGE_IMPLEMENT(2); |
| 1344 uint16_t a3 = pOS2->ulCodePageRange2 & 0xffff; | 1244 uint16_t a3 = pOS2->ulCodePageRange2 & 0xffff; |
| 1345 CODEPAGERANGE_IMPLEMENT(3); | 1245 CODEPAGERANGE_IMPLEMENT(3); |
| 1346 uint16_t a4 = (pOS2->ulCodePageRange2 >> 16) & 0xffff; | 1246 uint16_t a4 = (pOS2->ulCodePageRange2 >> 16) & 0xffff; |
| 1347 CODEPAGERANGE_IMPLEMENT(4); | 1247 CODEPAGERANGE_IMPLEMENT(4); |
| 1348 } else { | 1248 } else { |
| 1349 charsets.push_back(FX_CHARSET_Default); | 1249 charsets.push_back(FX_CHARSET_Default); |
| 1350 } | 1250 } |
| 1351 return charsets; | 1251 return charsets; |
| 1352 } | 1252 } |
| 1353 | 1253 |
| 1354 #undef CODEPAGERANGE_IMPLEMENT | 1254 #undef CODEPAGERANGE_IMPLEMENT |
| 1355 void CFGAS_FontMgrImp::GetUSBCSB(FXFT_Face pFace, | 1255 |
| 1356 uint32_t* USB, | 1256 void CFGAS_FontMgr::GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB) { |
| 1357 uint32_t* CSB) { | |
| 1358 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1257 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
| 1359 if (pOS2) { | 1258 if (pOS2) { |
| 1360 USB[0] = pOS2->ulUnicodeRange1; | 1259 USB[0] = pOS2->ulUnicodeRange1; |
| 1361 USB[1] = pOS2->ulUnicodeRange2; | 1260 USB[1] = pOS2->ulUnicodeRange2; |
| 1362 USB[2] = pOS2->ulUnicodeRange3; | 1261 USB[2] = pOS2->ulUnicodeRange3; |
| 1363 USB[3] = pOS2->ulUnicodeRange4; | 1262 USB[3] = pOS2->ulUnicodeRange4; |
| 1364 CSB[0] = pOS2->ulCodePageRange1; | 1263 CSB[0] = pOS2->ulCodePageRange1; |
| 1365 CSB[1] = pOS2->ulCodePageRange2; | 1264 CSB[1] = pOS2->ulCodePageRange2; |
| 1366 } else { | 1265 } else { |
| 1367 USB[0] = 0; | 1266 USB[0] = 0; |
| 1368 USB[1] = 0; | 1267 USB[1] = 0; |
| 1369 USB[2] = 0; | 1268 USB[2] = 0; |
| 1370 USB[3] = 0; | 1269 USB[3] = 0; |
| 1371 CSB[0] = 0; | 1270 CSB[0] = 0; |
| 1372 CSB[1] = 0; | 1271 CSB[1] = 0; |
| 1373 } | 1272 } |
| 1374 } | 1273 } |
| 1375 | 1274 |
| 1376 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1275 int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1, |
| 1377 const CFX_WideString& Name2) { | 1276 const CFX_WideString& Name2) { |
| 1378 if (Name1.Find(Name2.c_str()) != -1) { | 1277 if (Name1.Find(Name2.c_str()) != -1) |
| 1379 return 1; | 1278 return 1; |
| 1380 } | |
| 1381 return 0; | 1279 return 0; |
| 1382 } | 1280 } |
| 1383 | 1281 |
| 1384 #endif | 1282 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| OLD | NEW |