Skip to content

Commit

Permalink
macOS: Fix synthesized bold
Browse files Browse the repository at this point in the history
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
Pick-to: 5.15 6.1
Change-Id: I36da59d7689455e29cca283cb0724a0841095918
Reviewed-by: Konstantin Ritt <[email protected]>
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
eskilblomfeldt committed May 6, 2021
1 parent a1e405c commit 76d3cda
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/gui/text/coretext/qfontengine_coretext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,15 @@ CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef)
};

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));

if (fontDef.style != QFont::StyleNormal && !(traits & kCTFontItalicTrait) && !qEnvironmentVariableIsSet("QT_NO_SYNTHESIZED_ITALIC"))
synthesisFlags |= SynthesizedItalic;

Expand Down

0 comments on commit 76d3cda

Please sign in to comment.