Chromium Code Reviews| 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/cfgas_fontmgr.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" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 m_CPFonts.RemoveAll(); | 115 m_CPFonts.RemoveAll(); |
| 116 m_FamilyFonts.RemoveAll(); | 116 m_FamilyFonts.RemoveAll(); |
| 117 m_UnicodeFonts.RemoveAll(); | 117 m_UnicodeFonts.RemoveAll(); |
| 118 m_BufferFonts.RemoveAll(); | 118 m_BufferFonts.RemoveAll(); |
| 119 m_StreamFonts.RemoveAll(); | 119 m_StreamFonts.RemoveAll(); |
| 120 m_DeriveFonts.RemoveAll(); | 120 m_DeriveFonts.RemoveAll(); |
| 121 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) | 121 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) |
| 122 m_Fonts[i]->Release(); | 122 m_Fonts[i]->Release(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 CFGAS_GEFont* CFGAS_FontMgr::GetDefFontByCodePage( | 125 CFGAS_GEFont* CFGAS_FontMgr::GetFontByCodePage(uint16_t wCodePage, |
| 126 uint16_t wCodePage, | 126 uint32_t dwFontStyles, |
| 127 uint32_t dwFontStyles, | 127 const FX_WCHAR* pszFontFamily) { |
| 128 const FX_WCHAR* pszFontFamily) { | |
| 129 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 128 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
| 130 CFGAS_GEFont* pFont = nullptr; | 129 CFGAS_GEFont* pFont = nullptr; |
| 131 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) | 130 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) |
| 132 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; | 131 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; |
| 133 FX_FONTDESCRIPTOR const* pFD = | 132 FX_FONTDESCRIPTOR const* pFD = |
| 134 FindFont(pszFontFamily, dwFontStyles, true, wCodePage); | 133 FindFont(pszFontFamily, dwFontStyles, true, wCodePage); |
| 135 if (!pFD) | 134 if (!pFD) |
| 136 pFD = FindFont(nullptr, dwFontStyles, true, wCodePage); | 135 pFD = FindFont(nullptr, dwFontStyles, true, wCodePage); |
| 137 if (!pFD) | 136 if (!pFD) |
| 138 pFD = FindFont(nullptr, dwFontStyles, false, wCodePage); | 137 pFD = FindFont(nullptr, dwFontStyles, false, wCodePage); |
| 139 if (!pFD) | 138 if (!pFD) |
| 140 return nullptr; | 139 return nullptr; |
| 141 | 140 |
| 142 pFont = | 141 pFont = |
| 143 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 142 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
| 144 if (pFont) { | 143 if (!pFont) |
| 145 m_Fonts.Add(pFont); | 144 return nullptr; |
| 146 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 145 |
| 147 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); | 146 m_Fonts.Add(pFont); |
| 148 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 147 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 149 return LoadFont(pFont, dwFontStyles, wCodePage); | 148 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); |
| 150 } | 149 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 151 return nullptr; | 150 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 152 } | 151 } |
| 153 | 152 |
| 154 CFGAS_GEFont* CFGAS_FontMgr::GetDefFontByUnicode( | 153 CFGAS_GEFont* CFGAS_FontMgr::GetFontByUnicode(FX_WCHAR wUnicode, |
| 155 FX_WCHAR wUnicode, | 154 uint32_t dwFontStyles, |
| 156 uint32_t dwFontStyles, | 155 const FX_WCHAR* pszFontFamily) { |
| 157 const FX_WCHAR* pszFontFamily) { | |
| 158 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); | 156 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); |
| 159 if (pRet->wBitField == 999) | 157 if (pRet->wBitField == 999) |
| 160 return nullptr; | 158 return nullptr; |
| 161 | 159 |
| 162 uint32_t dwHash = | 160 uint32_t dwHash = |
| 163 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); | 161 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); |
| 164 CFGAS_GEFont* pFont = nullptr; | 162 CFGAS_GEFont* pFont = nullptr; |
| 165 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) | 163 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) |
| 166 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; | 164 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; |
| 167 | 165 |
| 168 FX_FONTDESCRIPTOR const* pFD = | 166 FX_FONTDESCRIPTOR const* pFD = |
| 169 FindFont(pszFontFamily, dwFontStyles, false, pRet->wCodePage, | 167 FindFont(pszFontFamily, dwFontStyles, false, pRet->wCodePage, |
| 170 pRet->wBitField, wUnicode); | 168 pRet->wBitField, wUnicode); |
| 171 if (!pFD && pszFontFamily) { | 169 if (!pFD && pszFontFamily) { |
| 172 pFD = FindFont(nullptr, dwFontStyles, false, pRet->wCodePage, | 170 pFD = FindFont(nullptr, dwFontStyles, false, pRet->wCodePage, |
| 173 pRet->wBitField, wUnicode); | 171 pRet->wBitField, wUnicode); |
| 174 } | 172 } |
| 175 if (!pFD) | 173 if (!pFD) |
| 176 return nullptr; | 174 return nullptr; |
| 177 | 175 |
| 178 uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); | 176 uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); |
| 179 const FX_WCHAR* pFontFace = pFD->wsFontFace; | 177 const FX_WCHAR* pFontFace = pFD->wsFontFace; |
| 180 pFont = CFGAS_GEFont::LoadFont(pFontFace, dwFontStyles, wCodePage, this); | 178 pFont = CFGAS_GEFont::LoadFont(pFontFace, dwFontStyles, wCodePage, this); |
| 181 if (pFont) { | 179 if (!pFont) |
| 182 m_Fonts.Add(pFont); | 180 return nullptr; |
| 183 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 181 |
| 184 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 182 m_Fonts.Add(pFont); |
| 185 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 183 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 186 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); | 184 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
| 187 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 185 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 188 return LoadFont(pFont, dwFontStyles, wCodePage); | 186 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); |
| 189 } | 187 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 190 return nullptr; | 188 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 191 } | 189 } |
| 192 | 190 |
| 193 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(const FX_WCHAR* pszFontFamily, | 191 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(const FX_WCHAR* pszFontFamily, |
| 194 uint32_t dwFontStyles, | 192 uint32_t dwFontStyles, |
| 195 uint16_t wCodePage) { | 193 uint16_t wCodePage) { |
| 196 uint32_t dwHash = | 194 uint32_t dwHash = |
| 197 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); | 195 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); |
| 198 CFGAS_GEFont* pFont = nullptr; | 196 CFGAS_GEFont* pFont = nullptr; |
| 199 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) | 197 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) |
| 200 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; | 198 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; |
| 201 FX_FONTDESCRIPTOR const* pFD = | 199 FX_FONTDESCRIPTOR const* pFD = |
| 202 FindFont(pszFontFamily, dwFontStyles, true, wCodePage); | 200 FindFont(pszFontFamily, dwFontStyles, true, wCodePage); |
| 203 if (!pFD) | 201 if (!pFD) |
| 204 pFD = FindFont(pszFontFamily, dwFontStyles, false, wCodePage); | 202 pFD = FindFont(pszFontFamily, dwFontStyles, false, wCodePage); |
| 205 if (!pFD) | 203 if (!pFD) |
| 206 return nullptr; | 204 return nullptr; |
| 207 | 205 |
| 208 if (wCodePage == 0xFFFF) | 206 if (wCodePage == 0xFFFF) |
| 209 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); | 207 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); |
| 210 pFont = | 208 pFont = |
| 211 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); | 209 CFGAS_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); |
| 212 if (pFont) { | 210 if (!pFont) |
| 213 m_Fonts.Add(pFont); | 211 return nullptr; |
| 214 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | |
| 215 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | |
| 216 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | |
| 217 return LoadFont(pFont, dwFontStyles, wCodePage); | |
| 218 } | |
| 219 return nullptr; | |
| 220 } | |
| 221 | 212 |
| 222 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(const uint8_t* pBuffer, int32_t iLength) { | 213 m_Fonts.Add(pFont); |
| 223 ASSERT(pBuffer && iLength > 0); | 214 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 224 CFGAS_GEFont* pFont = nullptr; | 215 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); |
| 225 if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) { | 216 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 226 if (pFont) | 217 return LoadFont(pFont, dwFontStyles, wCodePage); |
| 227 return pFont->Retain(); | |
| 228 } | |
| 229 pFont = CFGAS_GEFont::LoadFont(pBuffer, iLength, this); | |
| 230 if (pFont) { | |
| 231 m_Fonts.Add(pFont); | |
| 232 m_BufferFonts.SetAt((void*)pBuffer, pFont); | |
| 233 return pFont->Retain(); | |
| 234 } | |
| 235 return nullptr; | |
| 236 } | |
| 237 | |
| 238 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(IFX_Stream* pFontStream, | |
| 239 const FX_WCHAR* pszFontAlias, | |
| 240 uint32_t dwFontStyles, | |
| 241 uint16_t wCodePage, | |
| 242 bool bSaveStream) { | |
| 243 ASSERT(pFontStream && pFontStream->GetLength() > 0); | |
| 244 CFGAS_GEFont* pFont = nullptr; | |
| 245 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { | |
| 246 if (pFont) { | |
| 247 if (pszFontAlias) { | |
| 248 uint32_t dwHash = | |
| 249 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); | |
| 250 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | |
| 251 } | |
| 252 return LoadFont(pFont, dwFontStyles, wCodePage); | |
| 253 } | |
| 254 } | |
| 255 pFont = CFGAS_GEFont::LoadFont(pFontStream, this, bSaveStream); | |
| 256 if (pFont) { | |
| 257 m_Fonts.Add(pFont); | |
| 258 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); | |
| 259 if (pszFontAlias) { | |
| 260 uint32_t dwHash = | |
| 261 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); | |
| 262 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | |
| 263 } | |
| 264 return LoadFont(pFont, dwFontStyles, wCodePage); | |
| 265 } | |
| 266 return nullptr; | |
| 267 } | 218 } |
| 268 | 219 |
| 269 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(CFGAS_GEFont* pSrcFont, | 220 CFGAS_GEFont* CFGAS_FontMgr::LoadFont(CFGAS_GEFont* pSrcFont, |
| 270 uint32_t dwFontStyles, | 221 uint32_t dwFontStyles, |
| 271 uint16_t wCodePage) { | 222 uint16_t wCodePage) { |
| 272 ASSERT(pSrcFont); | 223 ASSERT(pSrcFont); |
| 273 if (pSrcFont->GetFontStyles() == dwFontStyles) | 224 if (pSrcFont->GetFontStyles() == dwFontStyles) |
| 274 return pSrcFont->Retain(); | 225 return pSrcFont->Retain(); |
| 275 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, | 226 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, |
| 276 (void*)(uintptr_t)wCodePage}; | 227 (void*)(uintptr_t)wCodePage}; |
| 277 uint32_t dwHash = FX_HashCode_GetA( | 228 uint32_t dwHash = FX_HashCode_GetA( |
| 278 CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); | 229 CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); |
| 279 CFGAS_GEFont* pFont = nullptr; | 230 CFGAS_GEFont* pFont = nullptr; |
| 280 if (m_DeriveFonts.GetCount() > 0) { | 231 if (m_DeriveFonts.GetCount() > 0) { |
| 281 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); | 232 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); |
| 282 if (pFont) | 233 if (pFont) |
| 283 return pFont->Retain(); | 234 return pFont->Retain(); |
| 284 } | 235 } |
| 285 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); | 236 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); |
| 286 if (pFont) { | 237 if (!pFont) |
| 287 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | 238 return nullptr; |
| 288 int32_t index = m_Fonts.Find(pFont); | 239 |
| 289 if (index < 0) { | 240 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 290 m_Fonts.Add(pFont); | 241 int32_t index = m_Fonts.Find(pFont); |
| 291 pFont->Retain(); | 242 if (index < 0) { |
| 292 } | 243 m_Fonts.Add(pFont); |
| 293 return pFont; | 244 pFont->Retain(); |
| 294 } | 245 } |
| 295 return nullptr; | 246 return pFont; |
| 296 } | |
| 297 | |
| 298 void CFGAS_FontMgr::ClearFontCache() { | |
| 299 for (int32_t i = 0; i < m_Fonts.GetSize(); i++) | |
| 300 m_Fonts[i]->Reset(); | |
| 301 } | 247 } |
| 302 | 248 |
| 303 void CFGAS_FontMgr::RemoveFont(CFX_MapPtrToPtr& fontMap, CFGAS_GEFont* pFont) { | 249 void CFGAS_FontMgr::RemoveFont(CFX_MapPtrToPtr& fontMap, CFGAS_GEFont* pFont) { |
| 304 FX_POSITION pos = fontMap.GetStartPosition(); | 250 FX_POSITION pos = fontMap.GetStartPosition(); |
| 305 void* pKey; | 251 void* pKey; |
| 306 void* pFind; | 252 void* pFind; |
| 307 while (pos) { | 253 while (pos) { |
| 308 pFind = nullptr; | 254 pFind = nullptr; |
| 309 fontMap.GetNextAssoc(pos, pKey, pFind); | 255 fontMap.GetNextAssoc(pos, pKey, pFind); |
| 310 if (pFind != (void*)pFont) | 256 if (pFind != (void*)pFont) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 336 FXSYS_memset(¶ms, 0, sizeof(params)); | 282 FXSYS_memset(¶ms, 0, sizeof(params)); |
| 337 params.dwUSB = dwUSB; | 283 params.dwUSB = dwUSB; |
| 338 params.wUnicode = wUnicode; | 284 params.wUnicode = wUnicode; |
| 339 params.wCodePage = wCodePage; | 285 params.wCodePage = wCodePage; |
| 340 params.pwsFamily = pszFontFamily; | 286 params.pwsFamily = pszFontFamily; |
| 341 params.dwFontStyles = dwFontStyles; | 287 params.dwFontStyles = dwFontStyles; |
| 342 params.dwMatchFlags = dwMatchFlags; | 288 params.dwMatchFlags = dwMatchFlags; |
| 343 FX_FONTDESCRIPTOR const* pDesc = MatchDefaultFont(¶ms, m_FontFaces); | 289 FX_FONTDESCRIPTOR const* pDesc = MatchDefaultFont(¶ms, m_FontFaces); |
| 344 if (pDesc) | 290 if (pDesc) |
| 345 return pDesc; | 291 return pDesc; |
| 346 if (pszFontFamily && m_pEnumerator) { | 292 if (!pszFontFamily || !m_pEnumerator) |
| 347 CFX_FontDescriptors namedFonts(100); | 293 return nullptr; |
| 348 m_pEnumerator(namedFonts, pszFontFamily, wUnicode); | 294 |
| 349 params.pwsFamily = nullptr; | 295 CFX_FontDescriptors namedFonts(100); |
| 350 pDesc = MatchDefaultFont(¶ms, namedFonts); | 296 m_pEnumerator(namedFonts, pszFontFamily, wUnicode); |
| 351 if (!pDesc) | 297 params.pwsFamily = nullptr; |
| 352 return nullptr; | 298 pDesc = MatchDefaultFont(¶ms, namedFonts); |
| 353 for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) { | 299 if (!pDesc) |
| 354 FX_FONTDESCRIPTOR const* pMatch = m_FontFaces.GetPtrAt(i); | 300 return nullptr; |
| 355 if (*pMatch == *pDesc) | 301 for (int32_t i = m_FontFaces.GetSize() - 1; i >= 0; i--) { |
| 356 return pMatch; | 302 FX_FONTDESCRIPTOR const* pMatch = m_FontFaces.GetPtrAt(i); |
| 357 } | 303 if (*pMatch == *pDesc) |
| 358 int index = m_FontFaces.Add(*pDesc); | 304 return pMatch; |
| 359 return m_FontFaces.GetPtrAt(index); | |
| 360 } | 305 } |
| 361 return nullptr; | 306 int index = m_FontFaces.Add(*pDesc); |
| 307 return m_FontFaces.GetPtrAt(index); | |
| 362 } | 308 } |
| 363 | 309 |
| 364 uint32_t FX_GetGdiFontStyles(const LOGFONTW& lf) { | 310 uint32_t FX_GetGdiFontStyles(const LOGFONTW& lf) { |
| 365 uint32_t dwStyles = 0; | 311 uint32_t dwStyles = 0; |
| 366 if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) | 312 if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) |
| 367 dwStyles |= FX_FONTSTYLE_FixedPitch; | 313 dwStyles |= FX_FONTSTYLE_FixedPitch; |
| 368 uint8_t nFamilies = lf.lfPitchAndFamily & 0xF0; | 314 uint8_t nFamilies = lf.lfPitchAndFamily & 0xF0; |
| 369 if (nFamilies == FF_ROMAN) | 315 if (nFamilies == FF_ROMAN) |
| 370 dwStyles |= FX_FONTSTYLE_Serif; | 316 dwStyles |= FX_FONTSTYLE_Serif; |
| 371 if (nFamilies == FF_SCRIPT) | 317 if (nFamilies == FF_SCRIPT) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 {48, 869}, {49, 866}, {50, 865}, {51, 864}, {52, 863}, {53, 862}, | 395 {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}, | 396 {54, 861}, {55, 860}, {56, 857}, {57, 855}, {58, 852}, {59, 775}, |
| 451 {60, 737}, {61, 708}, {62, 850}, {63, 437}, | 397 {60, 737}, {61, 708}, {62, 850}, {63, 437}, |
| 452 }; | 398 }; |
| 453 | 399 |
| 454 uint16_t FX_GetCodePageBit(uint16_t wCodePage) { | 400 uint16_t FX_GetCodePageBit(uint16_t wCodePage) { |
| 455 for (size_t i = 0; i < FX_ArraySize(g_Bit2CodePage); ++i) { | 401 for (size_t i = 0; i < FX_ArraySize(g_Bit2CodePage); ++i) { |
| 456 if (g_Bit2CodePage[i].wCodePage == wCodePage) | 402 if (g_Bit2CodePage[i].wCodePage == wCodePage) |
| 457 return g_Bit2CodePage[i].wBit; | 403 return g_Bit2CodePage[i].wBit; |
| 458 } | 404 } |
| 459 return (uint16_t)-1; | 405 return static_cast<uint16_t>(-1); |
| 460 } | 406 } |
| 461 | 407 |
| 462 uint16_t FX_GetUnicodeBit(FX_WCHAR wcUnicode) { | 408 uint16_t FX_GetUnicodeBit(FX_WCHAR wcUnicode) { |
| 463 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wcUnicode); | 409 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wcUnicode); |
| 464 return x ? x->wBitField : 999; | 410 return x ? x->wBitField : 999; |
| 465 } | 411 } |
| 466 | 412 |
| 467 inline uint8_t GetUInt8(const uint8_t* p) { | 413 inline uint8_t GetUInt8(const uint8_t* p) { |
| 468 return (uint8_t)(p[0]); | 414 return p[0]; |
| 469 } | 415 } |
| 470 | 416 |
| 471 inline uint16_t GetUInt16(const uint8_t* p) { | 417 inline uint16_t GetUInt16(const uint8_t* p) { |
| 472 return (uint16_t)(p[0] << 8 | p[1]); | 418 return static_cast<uint16_t>(p[0] << 8 | p[1]); |
| 473 } | 419 } |
| 474 | 420 |
| 475 struct FX_BIT2CHARSET { | 421 struct FX_BIT2CHARSET { |
| 476 uint16_t wBit; | 422 uint16_t wBit; |
| 477 uint16_t wCharset; | 423 uint16_t wCharset; |
| 478 }; | 424 }; |
| 479 | 425 |
| 480 const FX_BIT2CHARSET g_FX_Bit2Charset1[16] = { | 426 const FX_BIT2CHARSET g_FX_Bit2Charset[4][16] = { |
| 481 {1 << 0, FX_CHARSET_ANSI}, | 427 {{1 << 0, FX_CHARSET_ANSI}, |
| 482 {1 << 1, FX_CHARSET_MSWin_EasterEuropean}, | 428 {1 << 1, FX_CHARSET_MSWin_EasterEuropean}, |
| 483 {1 << 2, FX_CHARSET_MSWin_Cyrillic}, | 429 {1 << 2, FX_CHARSET_MSWin_Cyrillic}, |
| 484 {1 << 3, FX_CHARSET_MSWin_Greek}, | 430 {1 << 3, FX_CHARSET_MSWin_Greek}, |
| 485 {1 << 4, FX_CHARSET_MSWin_Turkish}, | 431 {1 << 4, FX_CHARSET_MSWin_Turkish}, |
| 486 {1 << 5, FX_CHARSET_MSWin_Hebrew}, | 432 {1 << 5, FX_CHARSET_MSWin_Hebrew}, |
| 487 {1 << 6, FX_CHARSET_MSWin_Arabic}, | 433 {1 << 6, FX_CHARSET_MSWin_Arabic}, |
| 488 {1 << 7, FX_CHARSET_MSWin_Baltic}, | 434 {1 << 7, FX_CHARSET_MSWin_Baltic}, |
| 489 {1 << 8, FX_CHARSET_MSWin_Vietnamese}, | 435 {1 << 8, FX_CHARSET_MSWin_Vietnamese}, |
| 490 {1 << 9, FX_CHARSET_Default}, | 436 {1 << 9, FX_CHARSET_Default}, |
| 491 {1 << 10, FX_CHARSET_Default}, | 437 {1 << 10, FX_CHARSET_Default}, |
| 492 {1 << 11, FX_CHARSET_Default}, | 438 {1 << 11, FX_CHARSET_Default}, |
| 493 {1 << 12, FX_CHARSET_Default}, | 439 {1 << 12, FX_CHARSET_Default}, |
| 494 {1 << 13, FX_CHARSET_Default}, | 440 {1 << 13, FX_CHARSET_Default}, |
| 495 {1 << 14, FX_CHARSET_Default}, | 441 {1 << 14, FX_CHARSET_Default}, |
| 496 {1 << 15, FX_CHARSET_Default}, | 442 {1 << 15, FX_CHARSET_Default}}, |
| 497 }; | 443 {{1 << 0, FX_CHARSET_Thai}, |
| 498 | 444 {1 << 1, FX_CHARSET_ShiftJIS}, |
| 499 const FX_BIT2CHARSET g_FX_Bit2Charset2[16] = { | 445 {1 << 2, FX_CHARSET_ChineseSimplified}, |
| 500 {1 << 0, FX_CHARSET_Thai}, | 446 {1 << 3, FX_CHARSET_Korean}, |
| 501 {1 << 1, FX_CHARSET_ShiftJIS}, | 447 {1 << 4, FX_CHARSET_ChineseTriditional}, |
| 502 {1 << 2, FX_CHARSET_ChineseSimplified}, | 448 {1 << 5, FX_CHARSET_Johab}, |
| 503 {1 << 3, FX_CHARSET_Korean}, | 449 {1 << 6, FX_CHARSET_Default}, |
| 504 {1 << 4, FX_CHARSET_ChineseTriditional}, | 450 {1 << 7, FX_CHARSET_Default}, |
| 505 {1 << 5, FX_CHARSET_Johab}, | 451 {1 << 8, FX_CHARSET_Default}, |
| 506 {1 << 6, FX_CHARSET_Default}, | 452 {1 << 9, FX_CHARSET_Default}, |
| 507 {1 << 7, FX_CHARSET_Default}, | 453 {1 << 10, FX_CHARSET_Default}, |
| 508 {1 << 8, FX_CHARSET_Default}, | 454 {1 << 11, FX_CHARSET_Default}, |
| 509 {1 << 9, FX_CHARSET_Default}, | 455 {1 << 12, FX_CHARSET_Default}, |
| 510 {1 << 10, FX_CHARSET_Default}, | 456 {1 << 13, FX_CHARSET_Default}, |
| 511 {1 << 11, FX_CHARSET_Default}, | 457 {1 << 14, FX_CHARSET_OEM}, |
| 512 {1 << 12, FX_CHARSET_Default}, | 458 {1 << 15, FX_CHARSET_Symbol}}, |
| 513 {1 << 13, FX_CHARSET_Default}, | 459 {{1 << 0, FX_CHARSET_Default}, |
| 514 {1 << 14, FX_CHARSET_OEM}, | 460 {1 << 1, FX_CHARSET_Default}, |
| 515 {1 << 15, FX_CHARSET_Symbol}, | 461 {1 << 2, FX_CHARSET_Default}, |
| 516 }; | 462 {1 << 3, FX_CHARSET_Default}, |
| 517 | 463 {1 << 4, FX_CHARSET_Default}, |
| 518 const FX_BIT2CHARSET g_FX_Bit2Charset3[16] = { | 464 {1 << 5, FX_CHARSET_Default}, |
| 519 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, | 465 {1 << 6, FX_CHARSET_Default}, |
| 520 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, | 466 {1 << 7, FX_CHARSET_Default}, |
| 521 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, | 467 {1 << 8, FX_CHARSET_Default}, |
| 522 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, | 468 {1 << 9, FX_CHARSET_Default}, |
| 523 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, | 469 {1 << 10, FX_CHARSET_Default}, |
| 524 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, | 470 {1 << 11, FX_CHARSET_Default}, |
| 525 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, | 471 {1 << 12, FX_CHARSET_Default}, |
| 526 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_Default}, | 472 {1 << 13, FX_CHARSET_Default}, |
| 527 }; | 473 {1 << 14, FX_CHARSET_Default}, |
| 528 | 474 {1 << 15, FX_CHARSET_Default}}, |
| 529 const FX_BIT2CHARSET g_FX_Bit2Charset4[16] = { | 475 {{1 << 0, FX_CHARSET_Default}, |
| 530 {1 << 0, FX_CHARSET_Default}, {1 << 1, FX_CHARSET_Default}, | 476 {1 << 1, FX_CHARSET_Default}, |
| 531 {1 << 2, FX_CHARSET_Default}, {1 << 3, FX_CHARSET_Default}, | 477 {1 << 2, FX_CHARSET_Default}, |
| 532 {1 << 4, FX_CHARSET_Default}, {1 << 5, FX_CHARSET_Default}, | 478 {1 << 3, FX_CHARSET_Default}, |
| 533 {1 << 6, FX_CHARSET_Default}, {1 << 7, FX_CHARSET_Default}, | 479 {1 << 4, FX_CHARSET_Default}, |
| 534 {1 << 8, FX_CHARSET_Default}, {1 << 9, FX_CHARSET_Default}, | 480 {1 << 5, FX_CHARSET_Default}, |
| 535 {1 << 10, FX_CHARSET_Default}, {1 << 11, FX_CHARSET_Default}, | 481 {1 << 6, FX_CHARSET_Default}, |
| 536 {1 << 12, FX_CHARSET_Default}, {1 << 13, FX_CHARSET_Default}, | 482 {1 << 7, FX_CHARSET_Default}, |
| 537 {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US}, | 483 {1 << 8, FX_CHARSET_Default}, |
| 538 }; | 484 {1 << 9, FX_CHARSET_Default}, |
| 485 {1 << 10, FX_CHARSET_Default}, | |
| 486 {1 << 11, FX_CHARSET_Default}, | |
| 487 {1 << 12, FX_CHARSET_Default}, | |
| 488 {1 << 13, FX_CHARSET_Default}, | |
| 489 {1 << 14, FX_CHARSET_Default}, | |
| 490 {1 << 15, FX_CHARSET_US}}}; | |
| 539 | 491 |
| 540 } // namespace | 492 } // namespace |
| 541 | 493 |
| 542 CFX_FontDescriptor::CFX_FontDescriptor() | 494 CFX_FontDescriptor::CFX_FontDescriptor() |
| 543 : m_nFaceIndex(0), m_dwFontStyles(0), m_dwUsb(), m_dwCsb() {} | 495 : m_nFaceIndex(0), m_dwFontStyles(0), m_dwUsb(), m_dwCsb() {} |
| 544 | 496 |
| 545 CFX_FontDescriptor::~CFX_FontDescriptor() {} | 497 CFX_FontDescriptor::~CFX_FontDescriptor() {} |
| 546 | 498 |
| 547 CFX_FontSourceEnum_File::CFX_FontSourceEnum_File() { | 499 CFX_FontSourceEnum_File::CFX_FontSourceEnum_File() { |
| 548 for (size_t i = 0; i < FX_ArraySize(g_FontFolders); ++i) | 500 for (size_t i = 0; i < FX_ArraySize(g_FontFolders); ++i) |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 if (wCodePage == 0xFFFF) | 721 if (wCodePage == 0xFFFF) |
| 770 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); | 722 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); |
| 771 else | 723 else |
| 772 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 724 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
| 773 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 725 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
| 774 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | 726 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 775 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts = nullptr; | 727 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts = nullptr; |
| 776 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { | 728 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { |
| 777 if (!pFonts) | 729 if (!pFonts) |
| 778 return nullptr; | 730 return nullptr; |
| 731 | |
| 779 for (int32_t i = 0; i < pFonts->GetSize(); ++i) { | 732 for (int32_t i = 0; i < pFonts->GetSize(); ++i) { |
| 780 if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) | 733 if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) |
| 781 return pFonts->GetAt(i)->Retain(); | 734 return pFonts->GetAt(i)->Retain(); |
| 782 } | 735 } |
| 783 } | 736 } |
| 784 if (!pFonts) | 737 if (!pFonts) |
| 785 pFonts = new CFX_ArrayTemplate<CFGAS_GEFont*>; | 738 pFonts = new CFX_ArrayTemplate<CFGAS_GEFont*>; |
| 786 m_Hash2Fonts.SetAt(dwHash, pFonts); | 739 m_Hash2Fonts.SetAt(dwHash, pFonts); |
| 787 CFX_FontDescriptorInfos* sortedFonts = nullptr; | 740 CFX_FontDescriptorInfos* sortedFonts = nullptr; |
| 788 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { | 741 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 806 m_FailedUnicodes2Nullptr.SetAt(wUnicode, nullptr); | 759 m_FailedUnicodes2Nullptr.SetAt(wUnicode, nullptr); |
| 807 return nullptr; | 760 return nullptr; |
| 808 } | 761 } |
| 809 | 762 |
| 810 bool CFGAS_FontMgr::VerifyUnicode(CFX_FontDescriptor* pDesc, | 763 bool CFGAS_FontMgr::VerifyUnicode(CFX_FontDescriptor* pDesc, |
| 811 FX_WCHAR wcUnicode) { | 764 FX_WCHAR wcUnicode) { |
| 812 IFX_SeekableReadStream* pFileRead = | 765 IFX_SeekableReadStream* pFileRead = |
| 813 CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); | 766 CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); |
| 814 if (!pFileRead) | 767 if (!pFileRead) |
| 815 return false; | 768 return false; |
| 769 | |
| 816 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); | 770 FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); |
| 817 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); | 771 FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); |
| 818 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); | 772 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); |
| 819 pFileRead->Release(); | 773 pFileRead->Release(); |
| 820 if (!pFace) | 774 if (!pFace) |
| 821 return false; | 775 return false; |
| 776 | |
| 822 if (FXFT_Get_Face_External_Stream(pFace)) | 777 if (FXFT_Get_Face_External_Stream(pFace)) |
| 823 FXFT_Clear_Face_External_Stream(pFace); | 778 FXFT_Clear_Face_External_Stream(pFace); |
| 824 FXFT_Done_Face(pFace); | 779 FXFT_Done_Face(pFace); |
| 825 return !retCharmap && retIndex; | 780 return !retCharmap && retIndex; |
| 826 } | 781 } |
| 827 | 782 |
| 828 bool CFGAS_FontMgr::VerifyUnicode(CFGAS_GEFont* pFont, FX_WCHAR wcUnicode) { | 783 bool CFGAS_FontMgr::VerifyUnicode(CFGAS_GEFont* pFont, FX_WCHAR wcUnicode) { |
| 829 if (!pFont) | 784 if (!pFont) |
| 830 return false; | 785 return false; |
| 831 | 786 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 pFontMgr->InitFTLibrary(); | 862 pFontMgr->InitFTLibrary(); |
| 908 FXFT_Library library = pFontMgr->GetFTLibrary(); | 863 FXFT_Library library = pFontMgr->GetFTLibrary(); |
| 909 if (!library) | 864 if (!library) |
| 910 return nullptr; | 865 return nullptr; |
| 911 | 866 |
| 912 FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); | 867 FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); |
| 913 FXSYS_memset(ftStream, 0, sizeof(FXFT_StreamRec)); | 868 FXSYS_memset(ftStream, 0, sizeof(FXFT_StreamRec)); |
| 914 ftStream->base = nullptr; | 869 ftStream->base = nullptr; |
| 915 ftStream->descriptor.pointer = pFontStream; | 870 ftStream->descriptor.pointer = pFontStream; |
| 916 ftStream->pos = 0; | 871 ftStream->pos = 0; |
| 917 ftStream->size = (unsigned long)pFontStream->GetSize(); | 872 ftStream->size = static_cast<unsigned long>(pFontStream->GetSize()); |
| 918 ftStream->read = _ftStreamRead; | 873 ftStream->read = _ftStreamRead; |
| 919 ftStream->close = _ftStreamClose; | 874 ftStream->close = _ftStreamClose; |
| 920 | 875 |
| 921 FXFT_Open_Args ftArgs; | 876 FXFT_Open_Args ftArgs; |
| 922 FXSYS_memset(&ftArgs, 0, sizeof(FXFT_Open_Args)); | 877 FXSYS_memset(&ftArgs, 0, sizeof(FXFT_Open_Args)); |
| 923 ftArgs.flags |= FT_OPEN_STREAM; | 878 ftArgs.flags |= FT_OPEN_STREAM; |
| 924 ftArgs.stream = ftStream; | 879 ftArgs.stream = ftStream; |
| 925 | 880 |
| 926 FXFT_Face pFace = nullptr; | 881 FXFT_Face pFace = nullptr; |
| 927 if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { | 882 if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 ssort.ShellSort(MatchedFonts.GetData(), MatchedFonts.GetSize()); | 960 ssort.ShellSort(MatchedFonts.GetData(), MatchedFonts.GetSize()); |
| 1006 return MatchedFonts.GetSize(); | 961 return MatchedFonts.GetSize(); |
| 1007 } | 962 } |
| 1008 | 963 |
| 1009 int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled, | 964 int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled, |
| 1010 uint16_t wCodePage, | 965 uint16_t wCodePage, |
| 1011 uint32_t dwFontStyles, | 966 uint32_t dwFontStyles, |
| 1012 const CFX_WideString& FontName, | 967 const CFX_WideString& FontName, |
| 1013 FX_WCHAR wcUnicode) { | 968 FX_WCHAR wcUnicode) { |
| 1014 int32_t nPenalty = 30000; | 969 int32_t nPenalty = 30000; |
| 1015 if (0 != FontName.GetLength()) { | 970 if (FontName.GetLength() != 0) { |
| 1016 if (FontName != pInstalled->m_wsFaceName) { | 971 if (FontName != pInstalled->m_wsFaceName) { |
| 1017 int32_t i; | 972 int32_t i; |
| 1018 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { | 973 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { |
| 1019 if (pInstalled->m_wsFamilyNames[i] == FontName) | 974 if (pInstalled->m_wsFamilyNames[i] == FontName) |
| 1020 break; | 975 break; |
| 1021 } | 976 } |
| 1022 if (i == pInstalled->m_wsFamilyNames.GetSize()) | 977 if (i == pInstalled->m_wsFamilyNames.GetSize()) |
| 1023 nPenalty += 0xFFFF; | 978 nPenalty += 0xFFFF; |
| 1024 else | 979 else |
| 1025 nPenalty -= 28000; | 980 nPenalty -= 28000; |
| 1026 } else { | 981 } else { |
| 1027 nPenalty -= 30000; | 982 nPenalty -= 30000; |
| 1028 } | 983 } |
| 1029 if (30000 == nPenalty && | 984 if (30000 == nPenalty && |
| 1030 0 == IsPartName(pInstalled->m_wsFaceName, FontName)) { | 985 0 == IsPartName(pInstalled->m_wsFaceName, FontName)) { |
| 1031 int32_t i; | 986 int32_t i; |
| 1032 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { | 987 for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { |
| 1033 if (0 != IsPartName(pInstalled->m_wsFamilyNames[i], FontName)) | 988 if (IsPartName(pInstalled->m_wsFamilyNames[i], FontName) != 0) |
| 1034 break; | 989 break; |
| 1035 } | 990 } |
| 1036 if (i == pInstalled->m_wsFamilyNames.GetSize()) | 991 if (i == pInstalled->m_wsFamilyNames.GetSize()) |
| 1037 nPenalty += 0xFFFF; | 992 nPenalty += 0xFFFF; |
| 1038 else | 993 else |
| 1039 nPenalty -= 26000; | 994 nPenalty -= 26000; |
| 1040 } else { | 995 } else { |
| 1041 nPenalty -= 27000; | 996 nPenalty -= 27000; |
| 1042 } | 997 } |
| 1043 } | 998 } |
| 1044 uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; | 999 uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; |
| 1045 if (dwStyleMask & FX_FONTSTYLE_Bold) | 1000 if (dwStyleMask & FX_FONTSTYLE_Bold) |
| 1046 nPenalty += 4500; | 1001 nPenalty += 4500; |
| 1047 if (dwStyleMask & FX_FONTSTYLE_FixedPitch) | 1002 if (dwStyleMask & FX_FONTSTYLE_FixedPitch) |
| 1048 nPenalty += 10000; | 1003 nPenalty += 10000; |
| 1049 if (dwStyleMask & FX_FONTSTYLE_Italic) | 1004 if (dwStyleMask & FX_FONTSTYLE_Italic) |
| 1050 nPenalty += 10000; | 1005 nPenalty += 10000; |
| 1051 if (dwStyleMask & FX_FONTSTYLE_Serif) | 1006 if (dwStyleMask & FX_FONTSTYLE_Serif) |
| 1052 nPenalty += 500; | 1007 nPenalty += 500; |
| 1053 if (dwStyleMask & FX_FONTSTYLE_Symbolic) | 1008 if (dwStyleMask & FX_FONTSTYLE_Symbolic) |
| 1054 nPenalty += 0xFFFF; | 1009 nPenalty += 0xFFFF; |
| 1055 if (nPenalty >= 0xFFFF) | 1010 if (nPenalty >= 0xFFFF) |
| 1056 return 0xFFFF; | 1011 return 0xFFFF; |
| 1057 uint16_t wBit = | 1012 |
| 1058 ((0 == wCodePage || 0xFFFF == wCodePage) ? (uint16_t)-1 | 1013 uint16_t wBit = (wCodePage == 0 || wCodePage == 0xFFFF) |
| 1059 : FX_GetCodePageBit(wCodePage)); | 1014 ? static_cast<uint16_t>(-1) |
| 1060 if (wBit != (uint16_t)-1) { | 1015 : FX_GetCodePageBit(wCodePage); |
| 1016 if (wBit != static_cast<uint16_t>(-1)) { | |
| 1061 ASSERT(wBit < 64); | 1017 ASSERT(wBit < 64); |
| 1062 if (0 == (pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32)))) | 1018 if ((pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32))) == 0) |
| 1063 nPenalty += 0xFFFF; | 1019 nPenalty += 0xFFFF; |
| 1064 else | 1020 else |
| 1065 nPenalty -= 60000; | 1021 nPenalty -= 60000; |
| 1066 } | 1022 } |
| 1067 wBit = | 1023 wBit = (wcUnicode == 0 || wcUnicode == 0xFFFE) ? static_cast<uint16_t>(999) |
| 1068 ((0 == wcUnicode || 0xFFFE == wcUnicode) ? (uint16_t)999 | 1024 : FX_GetUnicodeBit(wcUnicode); |
| 1069 : FX_GetUnicodeBit(wcUnicode)); | 1025 if (wBit != static_cast<uint16_t>(999)) { |
| 1070 if (wBit != (uint16_t)999) { | |
| 1071 ASSERT(wBit < 128); | 1026 ASSERT(wBit < 128); |
| 1072 if (0 == (pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32)))) | 1027 if ((pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32))) == 0) |
| 1073 nPenalty += 0xFFFF; | 1028 nPenalty += 0xFFFF; |
| 1074 else | 1029 else |
| 1075 nPenalty -= 60000; | 1030 nPenalty -= 60000; |
| 1076 } | 1031 } |
| 1077 return nPenalty; | 1032 return nPenalty; |
| 1078 } | 1033 } |
| 1079 | 1034 |
| 1080 void CFGAS_FontMgr::ClearFontCache() { | |
| 1081 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | |
| 1082 while (pos) { | |
| 1083 uint32_t dwHash; | |
| 1084 CFX_FontDescriptorInfos* pDescs; | |
| 1085 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | |
| 1086 delete pDescs; | |
| 1087 } | |
| 1088 pos = m_IFXFont2FileRead.GetStartPosition(); | |
| 1089 while (pos) { | |
| 1090 CFGAS_GEFont* pFont; | |
| 1091 IFX_SeekableReadStream* pFileRead; | |
| 1092 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | |
| 1093 pFileRead->Release(); | |
| 1094 } | |
| 1095 } | |
| 1096 | |
| 1097 void CFGAS_FontMgr::RemoveFont(CFGAS_GEFont* pEFont) { | 1035 void CFGAS_FontMgr::RemoveFont(CFGAS_GEFont* pEFont) { |
| 1098 if (!pEFont) | 1036 if (!pEFont) |
| 1099 return; | 1037 return; |
| 1100 | 1038 |
| 1101 IFX_SeekableReadStream* pFileRead; | 1039 IFX_SeekableReadStream* pFileRead; |
| 1102 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { | 1040 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { |
| 1103 pFileRead->Release(); | 1041 pFileRead->Release(); |
| 1104 m_IFXFont2FileRead.RemoveKey(pEFont); | 1042 m_IFXFont2FileRead.RemoveKey(pEFont); |
| 1105 } | 1043 } |
| 1106 FX_POSITION pos; | 1044 FX_POSITION pos; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1173 } while (index < num_faces); | 1111 } while (index < num_faces); |
| 1174 } | 1112 } |
| 1175 | 1113 |
| 1176 uint32_t CFGAS_FontMgr::GetFlags(FXFT_Face pFace) { | 1114 uint32_t CFGAS_FontMgr::GetFlags(FXFT_Face pFace) { |
| 1177 uint32_t flag = 0; | 1115 uint32_t flag = 0; |
| 1178 if (FT_IS_FIXED_WIDTH(pFace)) | 1116 if (FT_IS_FIXED_WIDTH(pFace)) |
| 1179 flag |= FX_FONTSTYLE_FixedPitch; | 1117 flag |= FX_FONTSTYLE_FixedPitch; |
| 1180 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1118 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
| 1181 if (!pOS2) | 1119 if (!pOS2) |
| 1182 return flag; | 1120 return flag; |
| 1121 | |
| 1183 if (pOS2->ulCodePageRange1 & (1 << 31)) | 1122 if (pOS2->ulCodePageRange1 & (1 << 31)) |
| 1184 flag |= FX_FONTSTYLE_Symbolic; | 1123 flag |= FX_FONTSTYLE_Symbolic; |
| 1185 if (pOS2->panose[0] == 2) { | 1124 if (pOS2->panose[0] == 2) { |
| 1186 uint8_t uSerif = pOS2->panose[1]; | 1125 uint8_t uSerif = pOS2->panose[1]; |
| 1187 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) | 1126 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) |
| 1188 flag |= FX_FONTSTYLE_Serif; | 1127 flag |= FX_FONTSTYLE_Serif; |
| 1189 } | 1128 } |
| 1190 return flag; | 1129 return flag; |
| 1191 } | 1130 } |
| 1192 | 1131 |
| 1193 void CFGAS_FontMgr::GetNames(const uint8_t* name_table, | 1132 void CFGAS_FontMgr::GetNames(const uint8_t* name_table, |
| 1194 CFX_WideStringArray& Names) { | 1133 CFX_WideStringArray& Names) { |
| 1195 if (!name_table) { | 1134 if (!name_table) |
| 1196 return; | 1135 return; |
| 1197 } | 1136 |
| 1198 uint8_t* lpTable = (uint8_t*)name_table; | 1137 uint8_t* lpTable = (uint8_t*)name_table; |
| 1199 CFX_WideString wsFamily; | 1138 CFX_WideString wsFamily; |
| 1200 uint8_t* sp = lpTable + 2; | 1139 uint8_t* sp = lpTable + 2; |
| 1201 uint8_t* lpNameRecord = lpTable + 6; | 1140 uint8_t* lpNameRecord = lpTable + 6; |
| 1202 uint16_t nNameCount = GetUInt16(sp); | 1141 uint16_t nNameCount = GetUInt16(sp); |
| 1203 uint8_t* lpStr = lpTable + GetUInt16(sp + 2); | 1142 uint8_t* lpStr = lpTable + GetUInt16(sp + 2); |
| 1204 for (uint16_t j = 0; j < nNameCount; j++) { | 1143 for (uint16_t j = 0; j < nNameCount; j++) { |
| 1205 uint16_t nNameID = GetUInt16(lpNameRecord + j * 12 + 6); | 1144 uint16_t nNameID = GetUInt16(lpNameRecord + j * 12 + 6); |
| 1206 if (nNameID != 1) { | 1145 if (nNameID != 1) |
| 1207 continue; | 1146 continue; |
| 1208 } | 1147 |
| 1209 uint16_t nPlatformID = GetUInt16(lpNameRecord + j * 12 + 0); | 1148 uint16_t nPlatformID = GetUInt16(lpNameRecord + j * 12 + 0); |
| 1210 uint16_t nNameLength = GetUInt16(lpNameRecord + j * 12 + 8); | 1149 uint16_t nNameLength = GetUInt16(lpNameRecord + j * 12 + 8); |
| 1211 uint16_t nNameOffset = GetUInt16(lpNameRecord + j * 12 + 10); | 1150 uint16_t nNameOffset = GetUInt16(lpNameRecord + j * 12 + 10); |
| 1212 wsFamily.clear(); | 1151 wsFamily.clear(); |
| 1213 if (nPlatformID != 1) { | 1152 if (nPlatformID != 1) { |
| 1214 for (uint16_t k = 0; k < nNameLength / 2; k++) { | 1153 for (uint16_t k = 0; k < nNameLength / 2; k++) { |
| 1215 FX_WCHAR wcTemp = GetUInt16(lpStr + nNameOffset + k * 2); | 1154 FX_WCHAR wcTemp = GetUInt16(lpStr + nNameOffset + k * 2); |
| 1216 wsFamily += wcTemp; | 1155 wsFamily += wcTemp; |
| 1217 } | 1156 } |
| 1218 Names.Add(wsFamily); | 1157 Names.Add(wsFamily); |
| 1219 } else { | 1158 continue; |
| 1220 for (uint16_t k = 0; k < nNameLength; k++) { | |
| 1221 FX_WCHAR wcTemp = GetUInt8(lpStr + nNameOffset + k); | |
| 1222 wsFamily += wcTemp; | |
| 1223 } | |
| 1224 Names.Add(wsFamily); | |
| 1225 } | 1159 } |
| 1160 for (uint16_t k = 0; k < nNameLength; k++) { | |
| 1161 FX_WCHAR wcTemp = GetUInt8(lpStr + nNameOffset + k); | |
| 1162 wsFamily += wcTemp; | |
| 1163 } | |
| 1164 Names.Add(wsFamily); | |
| 1226 } | 1165 } |
| 1227 } | 1166 } |
| 1228 | 1167 |
| 1229 // TODO(npm): Get rid of this #define | |
| 1230 #define CODEPAGERANGE_IMPLEMENT(n) \ | |
| 1231 for (int32_t i = 0; i < 16; i++) { \ | |
| 1232 if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) \ | |
| 1233 charsets.push_back(g_FX_Bit2Charset##n[i].wCharset); \ | |
| 1234 } | |
| 1235 | |
| 1236 std::vector<uint16_t> CFGAS_FontMgr::GetCharsets(FXFT_Face pFace) const { | 1168 std::vector<uint16_t> CFGAS_FontMgr::GetCharsets(FXFT_Face pFace) const { |
| 1237 std::vector<uint16_t> charsets; | 1169 std::vector<uint16_t> charsets; |
| 1238 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1170 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
| 1239 if (pOS2) { | 1171 if (!pOS2) { |
| 1240 uint16_t a1 = pOS2->ulCodePageRange1 & 0xffff; | |
| 1241 CODEPAGERANGE_IMPLEMENT(1); | |
| 1242 uint16_t a2 = (pOS2->ulCodePageRange1 >> 16) & 0xffff; | |
| 1243 CODEPAGERANGE_IMPLEMENT(2); | |
| 1244 uint16_t a3 = pOS2->ulCodePageRange2 & 0xffff; | |
| 1245 CODEPAGERANGE_IMPLEMENT(3); | |
| 1246 uint16_t a4 = (pOS2->ulCodePageRange2 >> 16) & 0xffff; | |
| 1247 CODEPAGERANGE_IMPLEMENT(4); | |
| 1248 } else { | |
| 1249 charsets.push_back(FX_CHARSET_Default); | 1172 charsets.push_back(FX_CHARSET_Default); |
| 1173 return charsets; | |
| 1174 } | |
| 1175 uint16_t a[4]; | |
|
Tom Sepez
2016/11/18 19:46:23
nit: I'd unroll the loop at 1180 to maybe avoid ha
Tom Sepez
2016/11/18 19:55:43
nit: maybe brace-initialization of this array.
npm
2016/11/18 20:49:44
I like loops
npm
2016/11/18 20:49:44
Done.
| |
| 1176 a[0] = pOS2->ulCodePageRange1 & 0xffff; | |
| 1177 a[1] = (pOS2->ulCodePageRange1 >> 16) & 0xffff; | |
| 1178 a[2] = pOS2->ulCodePageRange2 & 0xffff; | |
| 1179 a[3] = (pOS2->ulCodePageRange2 >> 16) & 0xffff; | |
| 1180 for (int n = 0; n < 4; n++) { | |
| 1181 for (int32_t i = 0; i < 16; i++) { | |
| 1182 if ((a[n] & g_FX_Bit2Charset[n][i].wBit) != 0) | |
| 1183 charsets.push_back(g_FX_Bit2Charset[n][i].wCharset); | |
| 1184 } | |
| 1250 } | 1185 } |
| 1251 return charsets; | 1186 return charsets; |
| 1252 } | 1187 } |
| 1253 | 1188 |
| 1254 #undef CODEPAGERANGE_IMPLEMENT | |
| 1255 | |
| 1256 void CFGAS_FontMgr::GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB) { | 1189 void CFGAS_FontMgr::GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB) { |
| 1257 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); | 1190 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); |
| 1258 if (pOS2) { | 1191 if (pOS2) { |
|
Tom Sepez
2016/11/18 19:46:23
nit: can we make this !pOS2 and flip the blocks ar
npm
2016/11/18 20:49:44
Done.
| |
| 1259 USB[0] = pOS2->ulUnicodeRange1; | 1192 USB[0] = pOS2->ulUnicodeRange1; |
| 1260 USB[1] = pOS2->ulUnicodeRange2; | 1193 USB[1] = pOS2->ulUnicodeRange2; |
| 1261 USB[2] = pOS2->ulUnicodeRange3; | 1194 USB[2] = pOS2->ulUnicodeRange3; |
| 1262 USB[3] = pOS2->ulUnicodeRange4; | 1195 USB[3] = pOS2->ulUnicodeRange4; |
| 1263 CSB[0] = pOS2->ulCodePageRange1; | 1196 CSB[0] = pOS2->ulCodePageRange1; |
| 1264 CSB[1] = pOS2->ulCodePageRange2; | 1197 CSB[1] = pOS2->ulCodePageRange2; |
| 1265 } else { | 1198 return; |
| 1266 USB[0] = 0; | |
| 1267 USB[1] = 0; | |
| 1268 USB[2] = 0; | |
| 1269 USB[3] = 0; | |
| 1270 CSB[0] = 0; | |
| 1271 CSB[1] = 0; | |
| 1272 } | 1199 } |
| 1200 USB[0] = 0; | |
| 1201 USB[1] = 0; | |
| 1202 USB[2] = 0; | |
| 1203 USB[3] = 0; | |
| 1204 CSB[0] = 0; | |
| 1205 CSB[1] = 0; | |
| 1273 } | 1206 } |
| 1274 | 1207 |
| 1275 int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1, | 1208 int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1, |
| 1276 const CFX_WideString& Name2) { | 1209 const CFX_WideString& Name2) { |
| 1277 if (Name1.Find(Name2.c_str()) != -1) | 1210 if (Name1.Find(Name2.c_str()) != -1) |
| 1278 return 1; | 1211 return 1; |
| 1279 return 0; | 1212 return 0; |
| 1280 } | 1213 } |
| 1281 | 1214 |
| 1282 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1215 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| OLD | NEW |