test: fix tst_QFont::defaultFamily on Mac OS X 10.8

Task-number: QTBUG-32834
Change-Id: Iac771eb0a544ae58d203717c39a13d2d21e3c3ed
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
Liang Qi 2013-09-18 14:31:43 +02:00 committed by The Qt Project
parent 14a1d06113
commit 9d56e9eae6
2 changed files with 27 additions and 35 deletions

View File

@ -372,43 +372,43 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo
static QHash<QString, QStringList> fallbackLists;
if (!family.isEmpty()) {
#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_8, __IPHONE_6_0)
// CTFontCopyDefaultCascadeListForLanguages is available in the SDK
// CTFontCopyDefaultCascadeListForLanguages is available in the SDK
#if QT_MAC_DEPLOYMENT_TARGET_BELOW(__MAC_10_8, __IPHONE_6_0)
// But we have to feature check at runtime
if (&CTFontCopyDefaultCascadeListForLanguages)
// But we have to feature check at runtime
if (&CTFontCopyDefaultCascadeListForLanguages)
#endif
{
if (fallbackLists.contains(family))
return fallbackLists.value(family);
{
if (fallbackLists.contains(family))
return fallbackLists.value(family);
if (!familyNameToPsName.contains(family))
const_cast<QCoreTextFontDatabase*>(this)->populateFontDatabase();
if (!familyNameToPsName.contains(family))
const_cast<QCoreTextFontDatabase*>(this)->populateFontDatabase();
QCFType<CTFontRef> font = CTFontCreateWithName(QCFString(familyNameToPsName[family]), 12.0, NULL);
if (font) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults stringArrayForKey: @"AppleLanguages"];
QCFType<CTFontRef> font = CTFontCreateWithName(QCFString(familyNameToPsName[family]), 12.0, NULL);
if (font) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults stringArrayForKey: @"AppleLanguages"];
QCFType<CFArrayRef> cascadeList = (CFArrayRef) CTFontCopyDefaultCascadeListForLanguages(font, (CFArrayRef) languages);
if (cascadeList) {
QStringList fallbackList;
const int numCascades = CFArrayGetCount(cascadeList);
for (int i = 0; i < numCascades; ++i) {
CTFontDescriptorRef fontFallback = (CTFontDescriptorRef) CFArrayGetValueAtIndex(cascadeList, i);
QCFString fallbackFamilyName = (CFStringRef) CTFontDescriptorCopyLocalizedAttribute(fontFallback, kCTFontFamilyNameAttribute, NULL);
fallbackList.append(QCFString::toQString(fallbackFamilyName));
QCFType<CFArrayRef> cascadeList = (CFArrayRef) CTFontCopyDefaultCascadeListForLanguages(font, (CFArrayRef) languages);
if (cascadeList) {
QStringList fallbackList;
const int numCascades = CFArrayGetCount(cascadeList);
for (int i = 0; i < numCascades; ++i) {
CTFontDescriptorRef fontFallback = (CTFontDescriptorRef) CFArrayGetValueAtIndex(cascadeList, i);
QCFString fallbackFamilyName = (CFStringRef) CTFontDescriptorCopyLocalizedAttribute(fontFallback, kCTFontFamilyNameAttribute, NULL);
fallbackList.append(QCFString::toQString(fallbackFamilyName));
}
fallbackLists[family] = fallbackList;
}
fallbackLists[family] = fallbackList;
}
}
if (fallbackLists.contains(family))
return fallbackLists.value(family);
}
#else
Q_UNUSED(family);
if (fallbackLists.contains(family))
return fallbackLists.value(family);
}
#endif
}
// We were not able to find a fallback for the specific family,
// so we fall back to the stylehint.

View File

@ -686,14 +686,6 @@ void tst_QFont::defaultFamily()
}
}
#if defined(Q_OS_MAC)
if (QSysInfo::MacintoshVersion == QSysInfo::MV_10_8) {
QEXPECT_FAIL("serif", "See QTBUG-32834", Continue);
QEXPECT_FAIL("monospace", "See QTBUG-32834", Continue);
QEXPECT_FAIL("cursive", "See QTBUG-32834", Continue);
QEXPECT_FAIL("fantasy", "See QTBUG-32834", Continue);
}
#endif
QVERIFY2(isAcceptable, msgNotAcceptableFont(familyForHint, acceptableFamilies));
}