--- src/gui/dialogs/qfontdialog_mac.mm.orig +++ src/gui/dialogs/qfontdialog_mac.mm @@ -141,6 +141,7 @@ QFont newFont; if (cocoaFont) { int pSize = qRound([cocoaFont pointSize]); +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) CTFontDescriptorRef font = CTFontCopyFontDescriptor((CTFontRef)cocoaFont); // QCoreTextFontDatabase::populateFontDatabase() is using localized names QString family = QCFString::toQString((CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL)); @@ -151,6 +152,23 @@ newFont.setStrikeOut(resolveFont.strikeOut()); CFRelease(font); +#else + // This pre-Leopard version is buggy and was fixed in 717e36037cf246aa201c0aaf15a5dcbd7883f159 + // see QTBUG-27415 https://codereview.qt-project.org/#/c/42830/ + 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"); + } + + newFont = QFontDatabase().font(family, typeface, pSize); + newFont.setUnderline(resolveFont.underline()); + newFont.setStrikeOut(resolveFont.strikeOut()); +#endif } return newFont; }