Chromium Code Reviews| Index: core/src/fxge/ge/fx_ge_fontmap.cpp |
| diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp |
| index 90b3c52546fe03e2fc9d01085300e7d6289daae4..e61b338bb4c16e0841e7f88a86859246d87eaff7 100644 |
| --- a/core/src/fxge/ge/fx_ge_fontmap.cpp |
| +++ b/core/src/fxge/ge/fx_ge_fontmap.cpp |
| @@ -1407,6 +1407,107 @@ void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, |
| } |
| m_FontList[facename] = pInfo; |
| } |
| +static const struct { |
| + const FX_CHAR* m_pName; |
| + const FX_CHAR* m_pSubstName; |
| + FX_BOOL m_bBold; |
| + FX_BOOL m_bItalic; |
| +} Base14Substs[] = { |
| + {"Courier", "Courier New", FALSE, FALSE}, |
| + {"Courier-Bold", "Courier New", TRUE, FALSE}, |
| + {"Courier-BoldOblique", "Courier New", TRUE, TRUE}, |
| + {"Courier-Oblique", "Courier New", FALSE, TRUE}, |
| + {"Helvetica", "Arial", FALSE, FALSE}, |
| + {"Helvetica-Bold", "Arial", TRUE, FALSE}, |
| + {"Helvetica-BoldOblique", "Arial", TRUE, TRUE}, |
| + {"Helvetica-Oblique", "Arial", FALSE, TRUE}, |
| + {"Times-Roman", "Times New Roman", FALSE, FALSE}, |
| + {"Times-Bold", "Times New Roman", TRUE, FALSE}, |
| + {"Times-BoldItalic", "Times New Roman", TRUE, TRUE}, |
| + {"Times-Italic", "Times New Roman", FALSE, TRUE}, |
| +}; |
| +void* CFX_FolderFontInfo::GetSubstFont(const CFX_ByteString& face) { |
| + for (size_t iBaseFont = 0; iBaseFont < FX_ArraySize(Base14Substs); |
| + iBaseFont++) { |
| + if (face == Base14Substs[iBaseFont].m_pName) { |
| + return GetFont(Base14Substs[iBaseFont].m_pSubstName); |
| + } |
| + } |
| + return NULL; |
|
Tom Sepez
2015/10/01 15:55:56
nit: prefer nullptr to NULL. We've been changing
|
| +} |
| +static FX_DWORD _GetCharset(int charset) { |
| + switch (charset) { |
| + case FXFONT_SHIFTJIS_CHARSET: |
| + return CHARSET_FLAG_SHIFTJIS; |
| + case FXFONT_GB2312_CHARSET: |
| + return CHARSET_FLAG_GB; |
| + case FXFONT_CHINESEBIG5_CHARSET: |
| + return CHARSET_FLAG_BIG5; |
| + case FXFONT_HANGEUL_CHARSET: |
| + return CHARSET_FLAG_KOREAN; |
| + case FXFONT_SYMBOL_CHARSET: |
| + return CHARSET_FLAG_SYMBOL; |
| + case FXFONT_ANSI_CHARSET: |
| + return CHARSET_FLAG_ANSI; |
| + default: |
| + break; |
| + } |
| + return 0; |
| +} |
| +static int32_t _GetSimilarValue(int weight, |
| + FX_BOOL bItalic, |
| + int pitch_family, |
| + FX_DWORD style) { |
| + int32_t iSimilarValue = 0; |
| + if ((style & FXFONT_BOLD) == (weight > 400)) { |
| + iSimilarValue += 16; |
| + } |
| + if ((style & FXFONT_ITALIC) == bItalic) { |
| + iSimilarValue += 16; |
| + } |
| + if ((style & FXFONT_SERIF) == (pitch_family & FXFONT_FF_ROMAN)) { |
| + iSimilarValue += 16; |
| + } |
| + if ((style & FXFONT_SCRIPT) == (pitch_family & FXFONT_FF_SCRIPT)) { |
| + iSimilarValue += 8; |
| + } |
| + if ((style & FXFONT_FIXED_PITCH) == (pitch_family & FXFONT_FF_FIXEDPITCH)) { |
| + iSimilarValue += 8; |
| + } |
| + return iSimilarValue; |
| +} |
| +void* CFX_FolderFontInfo::FindFont(int weight, |
| + FX_BOOL bItalic, |
| + int charset, |
| + int pitch_family, |
| + const FX_CHAR* family, |
| + FX_BOOL bMatchName) { |
| + CFX_FontFaceInfo* pFind = NULL; |
| + if (charset == FXFONT_ANSI_CHARSET && (pitch_family & FXFONT_FF_FIXEDPITCH)) { |
| + return GetFont("Courier New"); |
| + } |
| + FX_DWORD charset_flag = _GetCharset(charset); |
| + int32_t iBestSimilar = 0; |
| + for (const auto& it : m_FontList) { |
| + const CFX_ByteString& bsName = it.first; |
| + CFX_FontFaceInfo* pFont = it.second; |
| + if (!(pFont->m_Charsets & charset_flag) && |
| + charset != FXFONT_DEFAULT_CHARSET) { |
| + continue; |
| + } |
| + int32_t index = bsName.Find(family); |
| + if (bMatchName && index < 0) { |
| + continue; |
| + } |
| + int32_t iSimilarValue = |
| + _GetSimilarValue(weight, bItalic, pitch_family, pFont->m_Styles); |
| + if (iSimilarValue > iBestSimilar) { |
| + iBestSimilar = iSimilarValue; |
| + pFind = pFont; |
| + } |
| + } |
| + return pFind; |
| +} |
| void* CFX_FolderFontInfo::MapFont(int weight, |
| FX_BOOL bItalic, |
| int charset, |