summaryrefslogtreecommitdiffstats
path: root/src/tools/uic/cpp
diff options
context:
space:
mode:
authorJonas Karlsson <jonas.karlsson@qt.io>2020-08-05 10:47:33 +0200
committerJonas Karlsson <jonas.karlsson@qt.io>2020-08-28 07:26:54 +0200
commit3558704ed5c3d2c6dc6d024dfa454997469ca75f (patch)
tree84fe1b1d8314a389b480b7e720574573c3bd2083 /src/tools/uic/cpp
parenteb98bed4e76bb0fa6bad8474f2f370334cb70f6c (diff)
Use OpenType font weights
Task-number: QTBUG-42248 Change-Id: Icdb301b27d6699c2b842c4563fbef9df73c23cbc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/tools/uic/cpp')
-rw-r--r--src/tools/uic/cpp/cppwriteinitialization.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp
index 29c054bc22..2a3c9bdd70 100644
--- a/src/tools/uic/cpp/cppwriteinitialization.cpp
+++ b/src/tools/uic/cpp/cppwriteinitialization.cpp
@@ -1623,8 +1623,57 @@ QString WriteInitialization::writeFontProperties(const DomFont *f)
<< language::boolValue(f->elementUnderline()) << ')' << language::eol;
}
if (f->hasElementWeight() && f->elementWeight() > 0) {
- m_output << m_indent << fontName << ".setWeight("
- << f->elementWeight() << ")" << language::eol;
+ int weight = f->elementWeight();
+ if (!f->hasAttributeScale()) {
+ // Convert from old Qt scale to OpenType scale.
+ // (not a linear conversion, so we adapt the known values and approximate the others).
+ // Note that we cannot use qt_legacyToOpenTypeWeight from qfont_p.h here due to
+ // dependency issues.
+
+ switch (f->elementWeight()) {
+ case 0:
+ weight = 100;
+ break;
+ case 12:
+ weight = 200;
+ break;
+ case 25:
+ weight = 300;
+ break;
+ case 50:
+ weight = 400;
+ break;
+ case 57:
+ weight = 500;
+ break;
+ case 63:
+ weight = 600;
+ break;
+ case 75:
+ weight = 700;
+ break;
+ case 81:
+ weight = 800;
+ break;
+ case 87:
+ weight = 900;
+ break;
+ default:
+ weight *= 8;
+ weight += 100;
+ break;
+ }
+ }
+
+ switch (language::language()) {
+ case Language::Cpp:
+ m_output << m_indent << fontName << ".setWeight(QFont::Weight(" << weight << "))"
+ << language::eol;
+ break;
+ case Language::Python:
+ m_output << m_indent << fontName << ".setWeight(" << weight << ")" << language::eol;
+ break;
+ }
}
if (f->hasElementStrikeOut()) {
m_output << m_indent << fontName << ".setStrikeOut("