diff options
author | Liang Qi <liang.qi@digia.com> | 2012-12-14 11:32:13 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-14 22:01:43 (GMT) |
commit | 717e36037cf246aa201c0aaf15a5dcbd7883f159 (patch) | |
tree | 20ea7ad038cd1424fc2e93ef94113c526d656eaa | |
parent | 94a5839d74d53832674cd6eca49c980bac27fc04 (diff) | |
download | Qt-717e36037cf246aa201c0aaf15a5dcbd7883f159.zip Qt-717e36037cf246aa201c0aaf15a5dcbd7883f159.tar.gz Qt-717e36037cf246aa201c0aaf15a5dcbd7883f159.tar.bz2 |
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: Ia10aaff50e1ffdb248c730fb46a8a66088ee64bb
(cherry picked from qtbase/3c09f6bc9aee0c97427fe8da6efdc73b4ac473aa)
Reviewed-by: Liang Qi <liang.qi@digia.com>
-rw-r--r-- | src/gui/dialogs/qfontdialog_mac.mm | 16 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 2 |
2 files changed, 7 insertions, 11 deletions
diff --git a/src/gui/dialogs/qfontdialog_mac.mm b/src/gui/dialogs/qfontdialog_mac.mm index 119c299..10d995c 100644 --- a/src/gui/dialogs/qfontdialog_mac.mm +++ b/src/gui/dialogs/qfontdialog_mac.mm @@ -141,20 +141,16 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) QFont newFont; if (cocoaFont) { int pSize = qRound([cocoaFont pointSize]); - QString family(qt_mac_NSStringToQString([cocoaFont familyName])); - QString typeface(qt_mac_NSStringToQString([cocoaFont fontName])); - - int hyphenPos = typeface.indexOf(QLatin1Char('-')); - if (hyphenPos != -1) { - typeface.remove(0, hyphenPos + 1); - } else { - typeface = QLatin1String("Normal"); - } + CTFontDescriptorRef font = CTFontCopyFontDescriptor((CTFontRef)cocoaFont); + // QCoreTextFontDatabase::populateFontDatabase() is using localized names + QString family = QCFString::toQString((CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL)); + QString style = QCFString::toQString((CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontStyleNameAttribute, NULL)); - newFont = QFontDatabase().font(family, typeface, pSize); + newFont = QFontDatabase().font(family, style, pSize); newFont.setUnderline(resolveFont.underline()); newFont.setStrikeOut(resolveFont.strikeOut()); + CFRelease(font); } return newFont; } diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 6d16701..10ef906 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -769,7 +769,7 @@ QtFontFamily *QFontDatabasePrivate::family(const QString &f, bool create) if (res < 0) 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)) { QtFontFamily **newFamilies = (QtFontFamily **) realloc(families, |