From 8d15fffc4d57c55949f799e52f2f52d3b0b66321 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 21 Jul 2010 13:44:25 +0200 Subject: Ensure that font sizes that are > 0 and < 1 are still respected What was happening was that when a font size of 0.5 was used then it would end up being set to be point size 0. This now respects the setting used. Autotest is included in this patch for this case. Reviewed-by: Kim --- src/svg/qsvgstyle_p.h | 2 +- tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/svg/qsvgstyle_p.h b/src/svg/qsvgstyle_p.h index af3b4e5..dfea12c 100644 --- a/src/svg/qsvgstyle_p.h +++ b/src/svg/qsvgstyle_p.h @@ -338,7 +338,7 @@ public: { // Store the _pixel_ size in the font. Since QFont::setPixelSize() only takes an int, call // QFont::SetPointSize() instead. Set proper font size just before rendering. - m_qfont.setPointSize(size); + m_qfont.setPointSizeF(size); m_sizeSet = 1; } diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp index 106fd8c..519f4f5 100644 --- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp +++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp @@ -85,6 +85,7 @@ private slots: void testFillInheritance(); void testStopOffsetOpacity(); void testUseElement(); + void smallFont(); #ifndef QT_NO_COMPRESS void testGzLoading(); @@ -1342,5 +1343,30 @@ void tst_QSvgRenderer::testUseElement() } } +void tst_QSvgRenderer::smallFont() +{ + static const char *svgs[] = { "Hello world", + "Hello world" + }; + const int COUNT = sizeof(svgs) / sizeof(svgs[0]); + QImage images[COUNT]; + QPainter p; + + for (int i = 0; i < COUNT; ++i) { + QByteArray data(svgs[i]); + if (i == 0) { + QTest::ignoreMessage(QtWarningMsg, "QFont::setPointSizeF: Point size <= 0 (0.000000), must be greater than 0"); + QTest::ignoreMessage(QtWarningMsg, "QFont::setPointSize: Point size <= 0 (0), must be greater than 0"); + } + QSvgRenderer renderer(data); + images[i] = QImage(50, 50, QImage::Format_ARGB32_Premultiplied); + images[i].fill(-1); + p.begin(&images[i]); + renderer.render(&p); + p.end(); + } + QVERIFY(images[0] != images[1]); +} + QTEST_MAIN(tst_QSvgRenderer) #include "tst_qsvgrenderer.moc" -- cgit v0.12