Get CoreText style name when resolving Qt font

Since we use CoreText API to populate the font DB, we
should also make sure we use consistent data when doing
queries.

This partially reverts and ameds b619c35d85.

Change-Id: I6a3470fbee719ae1ea3085c252a4870040b9af1a
Task-number: QTBUG-41487
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
bb10
Gabriel de Dietrich 2015-03-11 17:37:03 +01:00
parent c9aaa3e2cd
commit f85b6c2461
1 changed files with 4 additions and 11 deletions

View File

@ -84,20 +84,13 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont)
QFont newFont;
if (cocoaFont) {
int pSize = qRound([cocoaFont pointSize]);
QString family(QCFString::toQString([cocoaFont familyName]));
QString typeface(QCFString::toQString([cocoaFont fontName]));
QCFType<CTFontDescriptorRef> font(CTFontCopyFontDescriptor((CTFontRef)cocoaFont));
QString family(QCFString((CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute)));
QString style(QCFString(((CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontStyleNameAttribute))));
int hyphenPos = typeface.indexOf(QLatin1Char('-'));
if (hyphenPos != -1) {
typeface.remove(0, hyphenPos + 1);
} else {
typeface = QLatin1String("Normal");
}
newFont = QFontDatabase().font(family, typeface, pSize);
newFont = QFontDatabase().font(family, style, pSize);
newFont.setUnderline(resolveFont.underline());
newFont.setStrikeOut(resolveFont.strikeOut());
}
return newFont;
}