diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-05-06 07:57:45 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-05-27 11:08:35 +0200 |
commit | 096c6223683e35dddd930fd06ee0dc0f5eefcf22 (patch) | |
tree | 99404364bd459545b58b38943d4e40803f49ec98 /src | |
parent | 54eac7e5ac9a32eef0434a7e8d94640b4e3ae16e (diff) |
macOS: Fix synthesized bold
When a user requested bold and there was no available font for
this (which is quite common with CJK fonts and in fact is the case
for the official Japanese font on the system), we should synthesize
the boldness.
This was done by checking if the requested font weight boldness
matched the one in the font's traits, and if not, we flag the
font boldness to be synthesized.
But when initializing the font, we would first override the requested
weight with the selected font's weight, *before* performing the check
above. So even if there was a mismatch, we would not catch this and
as a result, e.g. the system Japanese font would never be bold.
[ChangeLog][macOS] Fixed an issue where boldness would not be
correctly synthesized for families with no bold variant.
Fixes: QTBUG-85634
Change-Id: I36da59d7689455e29cca283cb0724a0841095918
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 76d3cda88469137050f6aab4bbb8578061fe25f2)
Diffstat (limited to 'src')
-rw-r--r-- | src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm index b6cefb96a8..5b74280ffc 100644 --- a/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm +++ b/src/platformsupport/fontdatabases/mac/qfontengine_coretext.mm @@ -255,13 +255,15 @@ void QCoreTextFontEngine::init() }; QCFType<CFDictionaryRef> allTraits = CTFontCopyTraits(ctfont); - fontDef.weight = QCoreTextFontEngine::qtWeightFromCFWeight(getTraitValue(allTraits, kCTFontWeightTrait)); int slant = static_cast<int>(getTraitValue(allTraits, kCTFontSlantTrait) * 500 + 500); if (slant > 500 && !(traits & kCTFontItalicTrait)) fontDef.style = QFont::StyleOblique; if (fontDef.weight >= QFont::Bold && !(traits & kCTFontBoldTrait) && !qEnvironmentVariableIsSet("QT_NO_SYNTHESIZED_BOLD")) synthesisFlags |= SynthesizedBold; + else + fontDef.weight = QCoreTextFontEngine::qtWeightFromCFWeight(getTraitValue(allTraits, kCTFontWeightTrait)); + // XXX: we probably don't need to synthesis italic for oblique font if (fontDef.style != QFont::StyleNormal && !(traits & kCTFontItalicTrait) && !qEnvironmentVariableIsSet("QT_NO_SYNTHESIZED_ITALIC")) synthesisFlags |= SynthesizedItalic; |