summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontdatabase.cpp
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2011-11-08 11:49:27 (GMT)
committerJiang Jiang <jiang.jiang@nokia.com>2011-11-08 14:32:10 (GMT)
commit738b1d2d93a77283bc40e3d03f378a2db8aec97f (patch)
tree5e77ad46c13a235b63a994ed2226b105fe3c0433 /src/gui/text/qfontdatabase.cpp
parent1496976a05b8804135608c7dde9bca5620950c33 (diff)
downloadQt-738b1d2d93a77283bc40e3d03f378a2db8aec97f.zip
Qt-738b1d2d93a77283bc40e3d03f378a2db8aec97f.tar.gz
Qt-738b1d2d93a77283bc40e3d03f378a2db8aec97f.tar.bz2
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
Diffstat (limited to 'src/gui/text/qfontdatabase.cpp')
-rw-r--r--src/gui/text/qfontdatabase.cpp31
1 files 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 *));