summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-07-16 12:58:41 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-07-20 13:20:23 +0200
commita1a6e3d21b1a4fb799dfd245fed6bb6564178894 (patch)
tree502b1296f6e5973c074cd2241040892133896a09 /src/gui
parent3ee587f8fa4086b0cc9ba85f08c26ee646344177 (diff)
Support pt units for sizes, as documented
Declaration::lengthValue only supported 'px' sizes, but one can transform any 'pt' value into 'px' by multiplying with 1.33. Notes: this ignores display DPI, and instead follows the W3C definition of 'pt' and 'px' as absolute lengths [1]. [1] https://www.w3.org/TR/css3-values/#absolute-lengths 1pt = 1/72th of 1 inch 1px = 1/96th of 1 inch so the conversion is px = pt * (72/96). Add unit test that verifies this using QPushButton's icon-sizes property, also with changed font in preparation of adding support for 'em' and 'ex' units in a follow up commit. Task-number: QTBUG-8096 Pick-to: 6.2 Done-with: Cristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> Change-Id: I58782e7ad0e2ff9d89ed695f8a23b1e584cfed64 Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/text/qcssparser.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index 4cc310c7e7..62e14e92bb 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -1599,11 +1599,21 @@ QSize Declaration::sizeValue() const
return qvariant_cast<QSize>(d->parsed);
int x[2] = { 0, 0 };
- if (d->values.count() > 0)
- intValueHelper(d->values.at(0), &x[0], "px");
- if (d->values.count() > 1)
- intValueHelper(d->values.at(1), &x[1], "px");
- else
+ const int count = d->values.count();
+ for (int i = 0; i < count; ++i) {
+ const auto &value = d->values.at(i);
+ const QString valueString = value.variant.toString();
+ if (valueString.endsWith(u"pt", Qt::CaseInsensitive)) {
+ intValueHelper(value, &x[i], "pt");
+ // according to https://www.w3.org/TR/css3-values/#absolute-lengths
+ // 1pt = 1/72th of 1 inch, and 1px = 1/96th of 1 inch
+ x[i] *= 72.0/96.0;
+ } else {
+ // by default we use 'px'
+ intValueHelper(value, &x[i], "px");
+ }
+ }
+ if (count == 1)
x[1] = x[0];
QSize size(x[0], x[1]);
d->parsed = QVariant::fromValue<QSize>(size);