diff options
author | thestig <thestig@chromium.org> | 2016-07-01 16:52:49 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-01 16:52:49 -0700 |
commit | cfb31d67a40310ed64d942ba346cf0cd3a01cadf (patch) | |
tree | 05a94e21f8cd828df6e04268a9bf7bd165ae07a8 /core/fxge/apple | |
parent | 1d13fb7be58a0909f532e4f4da572e69ecbb2c8e (diff) | |
download | pdfium-cfb31d67a40310ed64d942ba346cf0cd3a01cadf.tar.xz |
Mac: Improve font substitution.chromium/2790chromium/2789chromium/2788chromium/2787
Take the requested font weight and italicization into account when
searching for fonts. For example, for a font with the face "Arial" and a
weight of 700, search to see if "Arial Bold" is available.
BUG=530
Review-Url: https://codereview.chromium.org/2119983002
Diffstat (limited to 'core/fxge/apple')
-rw-r--r-- | core/fxge/apple/fx_mac_imp.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/core/fxge/apple/fx_mac_imp.cpp b/core/fxge/apple/fx_mac_imp.cpp index 4ddc7db8ad..8940896901 100644 --- a/core/fxge/apple/fx_mac_imp.cpp +++ b/core/fxge/apple/fx_mac_imp.cpp @@ -67,10 +67,27 @@ void* CFX_MacFontInfo::MapFont(int weight, face = g_Base14Substs[i].m_pSubstName; iExact = TRUE; return GetFont(face.c_str()); - break; } } + // The request may not ask for the bold and/or italic version of a font by + // name. So try to construct the appropriate name. This is not 100% foolproof + // as there are fonts that have "Oblique" or "BoldOblique" or "Heavy" in their + // names instead. But this at least works for common fonts like Arial and + // Times New Roman. A more sophisticated approach would be to find all the + // fonts in |m_FontList| with |face| in the name, and examine the fonts to + // see which best matches the requested characteristics. + if (face.Find("Bold") == -1 && face.Find("Italic") == -1) { + CFX_ByteString new_face = face; + if (weight > 400) + new_face += " Bold"; + if (bItalic) + new_face += " Italic"; + auto it = m_FontList.find(new_face); + if (it != m_FontList.end()) + return it->second; + } + auto it = m_FontList.find(face); if (it != m_FontList.end()) return it->second; |