Mac: fix bugs for font selection in QFontDialog

Use localized family name and style name when selecting font with
non-English locale

Task-number: QTBUG-27415
Change-Id: Ie81507ed011fc096e0f5edad146e97c392e86494
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
Liang Qi 2012-10-30 14:01:12 +01:00 committed by The Qt Project
parent 0ce317826f
commit 3c09f6bc9a
2 changed files with 7 additions and 11 deletions

View File

@ -595,7 +595,7 @@ QtFontFamily *QFontDatabasePrivate::family(const QString &f, bool create)
if (res < 0) if (res < 0)
pos++; pos++;
// qDebug("adding family %s at %d total=%d", f.latin1(), pos, count); // qDebug() << "adding family " << f.toLatin1() << " at " << pos << " total=" << count;
if (!(count % 8)) { if (!(count % 8)) {
QtFontFamily **newFamilies = (QtFontFamily **) QtFontFamily **newFamilies = (QtFontFamily **)
realloc(families, realloc(families,

View File

@ -92,20 +92,16 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont)
QFont newFont; QFont newFont;
if (cocoaFont) { if (cocoaFont) {
int pSize = qRound([cocoaFont pointSize]); int pSize = qRound([cocoaFont pointSize]);
QString family(QCFString::toQString([cocoaFont familyName])); CTFontDescriptorRef font = CTFontCopyFontDescriptor((CTFontRef)cocoaFont);
QString typeface(QCFString::toQString([cocoaFont fontName])); // QCoreTextFontDatabase::populateFontDatabase() is using localized names
QString family = QCFString::toQString((CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL));
QString style = QCFString::toQString((CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontStyleNameAttribute, NULL));
int hyphenPos = typeface.indexOf(QLatin1Char('-')); newFont = QFontDatabase().font(family, style, pSize);
if (hyphenPos != -1) {
typeface.remove(0, hyphenPos + 1);
} else {
typeface = QLatin1String("Normal");
}
newFont = QFontDatabase().font(family, typeface, pSize);
newFont.setUnderline(resolveFont.underline()); newFont.setUnderline(resolveFont.underline());
newFont.setStrikeOut(resolveFont.strikeOut()); newFont.setStrikeOut(resolveFont.strikeOut());
CFRelease(font);
} }
return newFont; return newFont;
} }