diff options
author | Jiang Jiang <jiang.jiang@nokia.com> | 2011-11-07 15:24:21 (GMT) |
---|---|---|
committer | Jiang Jiang <jiang.jiang@nokia.com> | 2011-11-08 14:32:09 (GMT) |
commit | 1496976a05b8804135608c7dde9bca5620950c33 (patch) | |
tree | 6073045538cbb1af8331a4b1da1a0e95cfefbab7 /src/gui/text | |
parent | 96e484c95629afd1f550449296f82c0561e64d26 (diff) | |
download | Qt-1496976a05b8804135608c7dde9bca5620950c33.zip Qt-1496976a05b8804135608c7dde9bca5620950c33.tar.gz Qt-1496976a05b8804135608c7dde9bca5620950c33.tar.bz2 |
Fix localized font family access in OS X
Font family names listed in QFontDatabase::families() should be
localized names rather than their default (English) names, to be
consistent with behaviors in other Mac apps and previous Qt/Mac
based on ATS.
It should also be possible to verify if a font exists with any
family name, regardless it's localized or not. Say we have font
"Hiragino Mincho Pro", which has a Japanese name called "ヒラギ
ノ明朝 Pro", then
db.hasFamily(QString::fromUtf8("ヒラギノ明朝 Pro"))
should return true.
Task-number: QTBUG-22372
Reviewed-by: Morten Sorvig
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 2 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase_mac.cpp | 26 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 796c455..8d375b8 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -1132,7 +1132,7 @@ QT_BEGIN_INCLUDE_NAMESPACE #endif QT_END_INCLUDE_NAMESPACE -#if !defined(Q_WS_X11) +#if !defined(Q_WS_X11) && !defined(Q_WS_MAC) QString QFontDatabase::resolveFontFamilyAlias(const QString &family) { return family; diff --git a/src/gui/text/qfontdatabase_mac.cpp b/src/gui/text/qfontdatabase_mac.cpp index 9a8e8af..81500c7 100644 --- a/src/gui/text/qfontdatabase_mac.cpp +++ b/src/gui/text/qfontdatabase_mac.cpp @@ -104,9 +104,8 @@ if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { const int numFonts = CFArrayGetCount(fonts); for(int i = 0; i < numFonts; ++i) { CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fonts, i); - - QCFString family_name = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute); - QCFString style_name = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontStyleNameAttribute); + QCFString family_name = (CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL); + QCFString style_name = (CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontStyleNameAttribute, NULL); QtFontFamily *family = db->family(family_name, true); for(int ws = 1; ws < QFontDatabase::WritingSystemsCount; ++ws) family->writingSystems[ws] = QtFontFamily::Supported; @@ -489,4 +488,25 @@ bool QFontDatabase::supportsThreadedFontRendering() return true; } +QString QFontDatabase::resolveFontFamilyAlias(const QString &family) +{ + QCFString expectedFamily = QCFString(family); + + QCFType<CFMutableDictionaryRef> attributes = CFDictionaryCreateMutable(NULL, 0, + &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, expectedFamily); + QCFType<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithAttributes(attributes); + + QCFType<CFMutableSetRef> mandatoryAttributes = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); + CFSetAddValue(mandatoryAttributes, kCTFontFamilyNameAttribute); + + QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(descriptor, 0.0, NULL); + QCFType<CTFontDescriptorRef> matched = CTFontDescriptorCreateMatchingFontDescriptor(descriptor, mandatoryAttributes); + if (!matched) + return family; + + QCFString familyName = (CFStringRef) CTFontDescriptorCopyLocalizedAttribute(matched, kCTFontFamilyNameAttribute, NULL); + return familyName; +} + QT_END_NAMESPACE |