CoreText: Localize getTraitValue helper function
It's only used in a single function (twice), so let's keep it closer to the call site. Change-Id: I7f8ceadc380171237eef3fa6b03ccd6bc89e99af Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>bb10
parent
bd989d1652
commit
b22c4e593b
|
|
@ -155,17 +155,6 @@ static void loadAdvancesForGlyphs(CTFontRef ctfont,
|
|||
}
|
||||
}
|
||||
|
||||
static float getTraitValue(CFDictionaryRef allTraits, CFStringRef trait)
|
||||
{
|
||||
if (CFDictionaryContainsKey(allTraits, trait)) {
|
||||
CFNumberRef traitNum = (CFNumberRef) CFDictionaryGetValue(allTraits, trait);
|
||||
float v = 0;
|
||||
CFNumberGetValue(traitNum, kCFNumberFloatType, &v);
|
||||
return v;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QCoreTextFontEngine::antialiasingThreshold = 0;
|
||||
QFontEngine::GlyphFormat QCoreTextFontEngine::defaultGlyphFormat = QFontEngine::Format_A32;
|
||||
|
||||
|
|
@ -277,6 +266,16 @@ void QCoreTextFontEngine::init()
|
|||
if (traits & kCTFontItalicTrait)
|
||||
fontDef.style = QFont::StyleItalic;
|
||||
|
||||
static const auto getTraitValue = [](CFDictionaryRef allTraits, CFStringRef trait) -> float {
|
||||
if (CFDictionaryContainsKey(allTraits, trait)) {
|
||||
CFNumberRef traitNum = (CFNumberRef) CFDictionaryGetValue(allTraits, trait);
|
||||
float v = 0;
|
||||
CFNumberGetValue(traitNum, kCFNumberFloatType, &v);
|
||||
return v;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
CFDictionaryRef allTraits = CTFontCopyTraits(ctfont);
|
||||
fontDef.weight = QCoreTextFontEngine::qtWeightFromCFWeight(getTraitValue(allTraits, kCTFontWeightTrait));
|
||||
int slant = static_cast<int>(getTraitValue(allTraits, kCTFontSlantTrait) * 500 + 500);
|
||||
|
|
|
|||
Loading…
Reference in New Issue