From: Jiang Jiang Date: Mon, 16 May 2011 08:20:54 +0000 (+0200) Subject: Workaround a bug in Core Text to select Light fonts X-Git-Tag: qt-v5.0.0-alpha1~4263 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ffc19505914e774e067217f5d7149af032312bb7;p=profile%2Fivi%2Fqtbase.git Workaround a bug in Core Text to select Light fonts Currently in Core Text there is not proper way to select fonts with Light weight, for example: QFont font("Helvetica"); font.setWeight(QFont::Light); will give you Helvetica-Light, as with: QFont font("Helvetica"); font.setWeight(QFont::Normal); because of a bug in Core Text, applying 0 symbolic traits with CTFontCreateCopyWithSymbolicTraits will always return the Light variant of that font family. Thus, we should only do this unless symbolicTraits is not 0 or font.weight is not Normal (Light is not a symbolic trait, but CT doesn't support selecting Light weight numerically). Reviewed-by: Eskil (cherry picked from commit 4d5b8f66d82e9087d9d58a4e76e6b46ce7bb53cc) Change-Id: I37a970aba5019a13b9f3bc43b7fb594b74a1aa37 Reviewed-on: http://codereview.qt.nokia.com/124 Reviewed-by: Jiang Jiang --- diff --git a/src/gui/text/qfontengine_coretext.mm b/src/gui/text/qfontengine_coretext.mm index 24bd750..737edc3 100644 --- a/src/gui/text/qfontengine_coretext.mm +++ b/src/gui/text/qfontengine_coretext.mm @@ -100,7 +100,12 @@ QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const QCFString &name, const QCFType descriptor = CTFontDescriptorCreateWithNameAndSize(name, fontDef.pixelSize); QCFType baseFont = CTFontCreateWithFontDescriptor(descriptor, fontDef.pixelSize, &transform); - ctfont = CTFontCreateCopyWithSymbolicTraits(baseFont, fontDef.pixelSize, &transform, symbolicTraits, symbolicTraits); + ctfont = NULL; + // There is a side effect in Core Text: if we apply 0 as symbolic traits to a font in normal weight, + // we will get the light version of that font (while the way supposed to work doesn't: + // setting kCTFontWeightTrait to some value between -1.0 to 0.0 has no effect on font selection) + if (fontDef.weight != QFont::Normal || symbolicTraits) + ctfont = CTFontCreateCopyWithSymbolicTraits(baseFont, fontDef.pixelSize, &transform, symbolicTraits, symbolicTraits); // CTFontCreateCopyWithSymbolicTraits returns NULL if we ask for a trait that does // not exist for the given font. (for example italic)