diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2011-11-10 10:12:01 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2011-11-10 10:12:01 (GMT) |
commit | 359073d92be05d0a66a4310edc02c6b65d5b5d86 (patch) | |
tree | c60bb5e6daca3462acf248e26487b2e7291207b0 | |
parent | 865ccc15029d49e72a16a20cc72c268b0e9944c2 (diff) | |
parent | 68de09f538ae1103a3104e0fba1086ea93581b6e (diff) | |
download | Qt-359073d92be05d0a66a4310edc02c6b65d5b5d86.zip Qt-359073d92be05d0a66a4310edc02c6b65d5b5d86.tar.gz Qt-359073d92be05d0a66a4310edc02c6b65d5b5d86.tar.bz2 |
Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qt-fire-team
* 'master' of git://scm.dev.nokia.troll.no/qt/qt-fire-team:
Fix regression in styleName searching
Fix styleName listing with the same QtFontStyle::Key value
Fix localized font family access in OS X
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 32 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase_mac.cpp | 26 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase_x11.cpp | 1 | ||||
-rw-r--r-- | tests/auto/qfontdatabase/tst_qfontdatabase.cpp | 15 |
4 files changed, 49 insertions, 25 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 796c455..d5d8a12 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -91,6 +91,8 @@ QT_BEGIN_NAMESPACE bool qt_enable_test_font = false; +static QString styleStringHelper(int weight, QFont::Style style); + Q_AUTOTEST_EXPORT void qt_setQtEnableTestFont(bool value) { qt_enable_test_font = value; @@ -358,32 +360,20 @@ struct QtFontFoundry QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &styleName, bool create) { int pos = 0; - if (count) { - // if styleName for searching first if possible - if (!styleName.isEmpty()) { - for (; pos < count; pos++) { - if (styles[pos]->styleName == styleName) - return styles[pos]; - } - } - int low = 0; - int high = count; - pos = count / 2; - while (high > low) { + for (; pos < count; pos++) { + bool hasStyleName = !styleName.isEmpty(); // search styleName first if available + if (hasStyleName && !styles[pos]->styleName.isEmpty()) { + if (styles[pos]->styleName == styleName) + return styles[pos]; + } else { if (styles[pos]->key == key) return styles[pos]; - if (styles[pos]->key < key) - low = pos + 1; - else - high = pos; - pos = (high + low) / 2; } - pos = low; } if (!create) return 0; -// qDebug("adding key (weight=%d, style=%d, oblique=%d stretch=%d) at %d", key.weight, key.style, key.oblique, key.stretch, pos); + // qDebug("adding key (weight=%d, style=%d, stretch=%d) at %d", key.weight, key.style, key.stretch, pos); if (!(count % 8)) { QtFontStyle **newStyles = (QtFontStyle **) realloc(styles, (((count+8) >> 3) << 3) * sizeof(QtFontStyle *)); @@ -393,13 +383,11 @@ QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &st QtFontStyle *style = new QtFontStyle(key); style->styleName = styleName; - memmove(styles + pos + 1, styles + pos, (count-pos)*sizeof(QtFontStyle *)); styles[pos] = style; count++; return styles[pos]; } - struct QtFontFamily { enum WritingSystemStatus { @@ -1132,7 +1120,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 diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp index 922a97f..df25aa6 100644 --- a/src/gui/text/qfontdatabase_x11.cpp +++ b/src/gui/text/qfontdatabase_x11.cpp @@ -1361,6 +1361,7 @@ static void initializeDb() // let's fake one... equiv = foundry->style(key, QString(), true); + equiv->styleName = styleStringHelper(key.weight, QFont::Style(key.style)); equiv->smoothScalable = true; QtFontSize *equiv_size = equiv->pixelSize(SMOOTH_SCALABLE, true); diff --git a/tests/auto/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/qfontdatabase/tst_qfontdatabase.cpp index 735c7e4..15be776 100644 --- a/tests/auto/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/qfontdatabase/tst_qfontdatabase.cpp @@ -80,6 +80,10 @@ private slots: void addAppFont_data(); void addAppFont(); + +#ifdef Q_WS_MAC + void localizedFonts(); +#endif }; tst_QFontDatabase::tst_QFontDatabase() @@ -275,5 +279,16 @@ void tst_QFontDatabase::addAppFont() QVERIFY(db.families() == oldFamilies); } +#ifdef Q_WS_MAC +void tst_QFontDatabase::localizedFonts() +{ + QFontDatabase db; + + QVERIFY(db.hasFamily(QString::fromUtf8("ヒラギノ明朝 Pro"))); + QVERIFY(db.hasFamily(QString::fromUtf8("华文宋体"))); + QVERIFY(!db.hasFamily(QString::fromUtf8("NotValidFont"))); +} +#endif + QTEST_MAIN(tst_QFontDatabase) #include "tst_qfontdatabase.moc" |