From 738b1d2d93a77283bc40e3d03f378a2db8aec97f Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Tue, 8 Nov 2011 12:49:27 +0100 Subject: Fix styleName listing with the same QtFontStyle::Key value We should store fonts with different style names but the same QtFontStyle::Key value (italic, weight and stretch) separately, so that fonts like Osaka (Regular, Regular-Mono) can be listed correctly. dd0205e0fbacf340508686cc136d70eda7bf664d introduced this regression when moving styleName out of Key. Without a styleName specified, we will do binary search and insertion for styles by comparing QtFontStyle::Key. We should do the same but comparing styleName instead when it's available. Reviewed-by: Eskil --- src/gui/text/qfontdatabase.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 8d375b8..675c292 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -359,23 +359,26 @@ QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &st { 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; + bool hasStyleName = !styleName.isEmpty(); // search styleName first if available pos = count / 2; while (high > low) { - if (styles[pos]->key == key) - return styles[pos]; - if (styles[pos]->key < key) - low = pos + 1; - else - high = pos; + 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; } pos = low; @@ -383,7 +386,7 @@ QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &st 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 *)); -- cgit v0.12