aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@digia.com>2013-06-07 15:55:25 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-06-14 08:40:03 +0200
commit2493f9e6cea52c5d293f2170b71cc36af4b82351 (patch)
tree5df0fee71ea34e0311589235e876971e76dc5d81 /src
parent8b32e1cb76e24cdcf0b614c39ad702360fd479fb (diff)
Allow floating point pixel sizes for Context2D, don't set if invalid.
Currently, setting a floating point pixel size for context2d's font will result in the following error: QFont::setPixelSize: Pixel size <= 0 (0) This is because qt_font_from_string() uses toInt() to convert the number to an int, which fails because of the decimal fraction. The font size is then set regardless (to 0), which does not comply with the standard: "[...] If the new value is syntactically incorrect (including using property-independent style sheet syntax like 'inherit' or 'initial'), then it must be ignored, without assigning a new font value. [CSS]" [1] This patch makes qt_font_from_string() call toFloat() on the string and then casts the value to an int. I could not find any evidence that floating point pixel sizes are disallowed, and QFont only deals with integer sizes anyway. If the conversion to float fails, the font size is not set (it defaults to 10px, according to [2]). [1] http://www.w3.org/TR/2dcontext/#dom-context-2d-font [2] http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-context2d.html#font-prop Change-Id: I6204eaa9fb6048bb9c4452403c3a4cf2913a03a1 Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/context2d/qquickcontext2d.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp
index d359077426..35ea28b81f 100644
--- a/src/quick/items/context2d/qquickcontext2d.cpp
+++ b/src/quick/items/context2d/qquickcontext2d.cpp
@@ -205,8 +205,10 @@ QFont qt_font_from_string(const QString& fontString) {
else if (token.endsWith(QLatin1String("px"))) {
QString number = token;
number.remove(QLatin1String("px"));
- //font.setPointSizeF(number.trimmed().toFloat());
- font.setPixelSize(number.trimmed().toInt());
+ bool ok = false;
+ float pixelSize = number.trimmed().toFloat(&ok);
+ if (ok)
+ font.setPixelSize(int(pixelSize));
} else
font.setFamily(token);
}