summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontdatabase.cpp
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@digia.com>2014-10-22 17:14:29 +0200
committerKonstantin Ritt <ritt.ks@gmail.com>2014-12-12 06:59:46 +0100
commit517da68893be9e6d97c7993922c573de9560604d (patch)
tree9da6027604c97023fd6cacc3114c2f2fd43dd26f /src/gui/text/qfontdatabase.cpp
parent0478bc15bd3b4c616b4860e460600ba8877ee216 (diff)
Add QFont::Weight enum values
And try to make good use of them in order to match the QFont request more closely. Task-number: QTBUG-38482 Change-Id: I768dfa8828e370d77a1c17ecf4796d750b3edd9b Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Diffstat (limited to 'src/gui/text/qfontdatabase.cpp')
-rw-r--r--src/gui/text/qfontdatabase.cpp70
1 files changed, 37 insertions, 33 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 37d3756e52..dd11cd8382 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -90,22 +90,29 @@ static int getFontWeight(const QString &weightString)
// order of "expense".
//
// A simple string test is the cheapest, so let's do that first.
- if (s == QLatin1String("normal"))
+ // Test in decreasing order of commonness
+ if (s == QLatin1String("normal") || s == QLatin1String("regular"))
return QFont::Normal;
- if (s == QLatin1String("medium"))
- return qt_mediumFontWeight;
if (s == QLatin1String("bold"))
return QFont::Bold;
- if (s == QLatin1String("demibold") || s == QLatin1String("demi bold"))
+ if (s == QLatin1String("semibold") || s == QLatin1String("semi bold")
+ || s == QLatin1String("demibold") || s == QLatin1String("demi bold"))
return QFont::DemiBold;
+ if (s == QLatin1String("medium"))
+ return QFont::Medium;
if (s == QLatin1String("black"))
return QFont::Black;
if (s == QLatin1String("light"))
return QFont::Light;
if (s == QLatin1String("thin"))
- return qt_thinFontWeight;
- if (s == QLatin1String("extralight"))
- return qt_extralightFontWeight;
+ return QFont::Thin;
+ const QStringRef s2 = s.midRef(2);
+ if (s.startsWith(QLatin1String("ex")) || s.startsWith(QLatin1String("ul"))) {
+ if (s2 == QLatin1String("tralight") || s == QLatin1String("tra light"))
+ return QFont::ExtraLight;
+ if (s2 == QLatin1String("trabold") || s2 == QLatin1String("tra bold"))
+ return QFont::ExtraBold;
+ }
// Next up, let's see if contains() matches: slightly more expensive, but
// still fast enough.
@@ -123,49 +130,46 @@ static int getFontWeight(const QString &weightString)
// These are (very) slow compared to simple string ops, so we do these last.
// As using translated values for such things is not very common, this should
// not be too bad.
- QString translatedNormal = QCoreApplication::translate("QFontDatabase", "Normal").toLower();
- if (s == translatedNormal)
+ if (s.compare(QCoreApplication::translate("QFontDatabase", "Normal", "The Normal or Regular font weight"), Qt::CaseInsensitive) == 0)
return QFont::Normal;
- QString translatedBold = QCoreApplication::translate("QFontDatabase", "Bold").toLower();
+ const QString translatedBold = QCoreApplication::translate("QFontDatabase", "Bold").toLower();
if (s == translatedBold)
return QFont::Bold;
- QString translatedDemiBold = QCoreApplication::translate("QFontDatabase", "Demi Bold").toLower();
- if (s == translatedDemiBold)
+ if (s.compare(QCoreApplication::translate("QFontDatabase", "Demi Bold"), Qt::CaseInsensitive) == 0)
return QFont::DemiBold;
- QString translatedBlack = QCoreApplication::translate("QFontDatabase", "Black").toLower();
- if (s == translatedBlack)
+ if (s.compare(QCoreApplication::translate("QFontDatabase", "Medium", "The Medium font weight"), Qt::CaseInsensitive) == 0)
+ return QFont::Medium;
+ if (s.compare(QCoreApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
return QFont::Black;
+ const QString translatedLight = QCoreApplication::translate("QFontDatabase", "Light").toLower();
+ if (s == translatedLight)
+ return QFont::Light;
+ if (s.compare(QCoreApplication::translate("QFontDatabase", "Thin"), Qt::CaseInsensitive) == 0)
+ return QFont::Thin;
+ if (s.compare(QCoreApplication::translate("QFontDatabase", "Extra Light"), Qt::CaseInsensitive) == 0)
+ return QFont::ExtraLight;
+ if (s.compare(QCoreApplication::translate("QFontDatabase", "Extra Bold"), Qt::CaseInsensitive) == 0)
+ return QFont::ExtraBold;
// And now the contains() checks for the translated strings.
+ const QString translatedExtra = QCoreApplication::translate("QFontDatabase", "Extra").toLower();
if (s.contains(translatedBold)) {
QString translatedDemi = QCoreApplication::translate("QFontDatabase", "Demi").toLower();
- if (s == translatedDemi)
+ if (s .contains(translatedDemi))
return QFont::DemiBold;
+ if (s.contains(translatedExtra))
+ return QFont::ExtraBold;
return QFont::Bold;
}
- QString translatedLight = QCoreApplication::translate("QFontDatabase", "Light").toLower();
- if (s == translatedLight || s.contains(translatedLight))
+ if (s.contains(translatedLight)) {
+ if (s.contains(translatedExtra))
+ return QFont::ExtraLight;
return QFont::Light;
-
+ }
return QFont::Normal;
}
-// convert 0 ~ 1000 integer to QFont::Weight
-QFont::Weight weightFromInteger(int weight)
-{
- if (weight < 400)
- return QFont::Light;
- else if (weight < 600)
- return QFont::Normal;
- else if (weight < 700)
- return QFont::DemiBold;
- else if (weight < 800)
- return QFont::Bold;
- else
- return QFont::Black;
-}
-
struct QtFontEncoding
{
signed int encoding : 16;