diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2013-06-07 15:55:25 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-14 08:40:03 +0200 |
commit | 2493f9e6cea52c5d293f2170b71cc36af4b82351 (patch) | |
tree | 5df0fee71ea34e0311589235e876971e76dc5d81 /tests/auto/quick/qquickcanvasitem | |
parent | 8b32e1cb76e24cdcf0b614c39ad702360fd479fb (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 'tests/auto/quick/qquickcanvasitem')
-rw-r--r-- | tests/auto/quick/qquickcanvasitem/data/tst_context.qml | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_context.qml b/tests/auto/quick/qquickcanvasitem/data/tst_context.qml index b72e755ed9..7350ed6c81 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_context.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_context.qml @@ -70,4 +70,18 @@ Canvas { compare(canvas.contextInPaint, canvas.getContext("2d")); } } + + TestCase { + name: "ContextFontValidation" + when: canvas.available + + function test_pixelSize() { + wait(100); + compare(contextSpy.count, 1); + + var ctx = canvas.getContext("2d"); + ctx.font = "80.1px sans-serif"; + compare(ctx.font, "sans-serif,-1,80,5,50,0,0,0,0,0"); + } + } } |