int32_t CFGAS_FontMgr::CalcPenalty(CFX_FontDescriptor* pInstalled, uint16_t wCodePage, uint32_t dwFontStyles, const CFX_WideString& FontName, FX_WCHAR wcUnicode) { int32_t nPenalty = 30000; if (FontName.GetLength() != 0) { if (FontName != pInstalled->m_wsFaceName) { int32_t i; for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { if (pInstalled->m_wsFamilyNames[i] == FontName) break; } if (i == pInstalled->m_wsFamilyNames.GetSize()) nPenalty += 0xFFFF; else nPenalty -= 28000; } else { nPenalty -= 30000; } if (30000 == nPenalty && 0 == IsPartName(pInstalled->m_wsFaceName, FontName)) { int32_t i; for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { if (IsPartName(pInstalled->m_wsFamilyNames[i], FontName) != 0) break; } if (i == pInstalled->m_wsFamilyNames.GetSize()) nPenalty += 0xFFFF; else nPenalty -= 26000; } else { nPenalty -= 27000; } } uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; if (dwStyleMask & FX_FONTSTYLE_Bold) nPenalty += 4500; if (dwStyleMask & FX_FONTSTYLE_FixedPitch) nPenalty += 10000; if (dwStyleMask & FX_FONTSTYLE_Italic) nPenalty += 10000; if (dwStyleMask & FX_FONTSTYLE_Serif) nPenalty += 500; if (dwStyleMask & FX_FONTSTYLE_Symbolic) nPenalty += 0xFFFF; if (nPenalty >= 0xFFFF) return 0xFFFF; uint16_t wBit = (wCodePage == 0 || wCodePage == 0xFFFF) ? static_cast<uint16_t>(-1) : FX_GetCodePageBit(wCodePage); if (wBit != static_cast<uint16_t>(-1)) { ASSERT(wBit < 64); if ((pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32))) == 0) nPenalty += 0xFFFF; else nPenalty -= 60000; } wBit = (wcUnicode == 0 || wcUnicode == 0xFFFE) ? static_cast<uint16_t>(999) : FX_GetUnicodeBit(wcUnicode); if (wBit != static_cast<uint16_t>(999)) { ASSERT(wBit < 128); if ((pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32))) == 0) nPenalty += 0xFFFF; else nPenalty -= 60000; } return nPenalty; }
int32_t CFGAS_FontMgrImp::CalcPenalty(CFX_FontDescriptor* pInstalled, uint16_t wCodePage, uint32_t dwFontStyles, const CFX_WideString& FontName, FX_WCHAR wcUnicode) { int32_t nPenalty = 30000; if (0 != FontName.GetLength()) { if (FontName != pInstalled->m_wsFaceName) { int32_t i; for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { if (pInstalled->m_wsFamilyNames[i] == FontName) { break; } } if (i == pInstalled->m_wsFamilyNames.GetSize()) { nPenalty += 0xFFFF; } else { nPenalty -= 28000; } } else { nPenalty -= 30000; } if (30000 == nPenalty && 0 == IsPartName(pInstalled->m_wsFaceName, FontName)) { int32_t i; for (i = 0; i < pInstalled->m_wsFamilyNames.GetSize(); i++) { if (0 != IsPartName(pInstalled->m_wsFamilyNames[i], FontName)) { break; } } if (i == pInstalled->m_wsFamilyNames.GetSize()) { nPenalty += 0xFFFF; } else { nPenalty -= 26000; } } else { nPenalty -= 27000; } } uint32_t dwStyleMask = pInstalled->m_dwFontStyles ^ dwFontStyles; if (dwStyleMask & FX_FONTSTYLE_Bold) { nPenalty += 4500; } if (dwStyleMask & FX_FONTSTYLE_FixedPitch) { nPenalty += 10000; } if (dwStyleMask & FX_FONTSTYLE_Italic) { nPenalty += 10000; } if (dwStyleMask & FX_FONTSTYLE_Serif) { nPenalty += 500; } if (dwStyleMask & FX_FONTSTYLE_Symbolic) { nPenalty += 0xFFFF; } if (nPenalty >= 0xFFFF) { return 0xFFFF; } uint16_t wBit = ((0 == wCodePage || 0xFFFF == wCodePage) ? (uint16_t)-1 : FX_GetCodePageBit(wCodePage)); if (wBit != (uint16_t)-1) { ASSERT(wBit < 64); if (0 == (pInstalled->m_dwCsb[wBit / 32] & (1 << (wBit % 32)))) { nPenalty += 0xFFFF; } else { nPenalty -= 60000; } } wBit = ((0 == wcUnicode || 0xFFFE == wcUnicode) ? (uint16_t)999 : FX_GetUnicodeBit(wcUnicode)); if (wBit != (uint16_t)999) { ASSERT(wBit < 128); if (0 == (pInstalled->m_dwUsb[wBit / 32] & (1 << (wBit % 32)))) { nPenalty += 0xFFFF; } else { nPenalty -= 60000; } } return nPenalty; }