From 68de09f538ae1103a3104e0fba1086ea93581b6e Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Wed, 9 Nov 2011 16:06:55 +0100 Subject: Fix regression in styleName searching 1. Faked styles should have styleNames as well otherwise we couldn't find them. 2. With a QtFontFoundry mixed with style keys and style names, there is no way to sort them in a manner than binary search will work, we have to use linear search instead. --- src/gui/text/qfontdatabase.cpp | 33 +++++++++------------------------ src/gui/text/qfontdatabase_x11.cpp | 1 + 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 675c292..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,30 +360,15 @@ struct QtFontFoundry QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &styleName, bool create) { int pos = 0; - if (count) { - int low = 0; - int high = count; + for (; pos < count; pos++) { bool hasStyleName = !styleName.isEmpty(); // search styleName first if available - pos = count / 2; - while (high > low) { - if (hasStyleName) { - if (styles[pos]->styleName == styleName) - return styles[pos]; - if (styles[pos]->styleName < styleName) - low = pos + 1; - else - high = 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; + if (hasStyleName && !styles[pos]->styleName.isEmpty()) { + if (styles[pos]->styleName == styleName) + return styles[pos]; + } else { + if (styles[pos]->key == key) + return styles[pos]; } - pos = low; } if (!create) return 0; @@ -396,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 { 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); -- cgit v0.12