summaryrefslogtreecommitdiffstats
path: root/src/svg/qsvggraphics.cpp
diff options
context:
space:
mode:
authorAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-11-03 09:36:52 (GMT)
committerAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-11-06 16:45:51 (GMT)
commit676780d515cedca85829ae962e4f501c5e5b6581 (patch)
treeb2994f82bf34031ae4b23ed9eb3a078e3c2a1e39 /src/svg/qsvggraphics.cpp
parent03b19519768b504e5c7f5fd3923a14591e58b365 (diff)
downloadQt-676780d515cedca85829ae962e4f501c5e5b6581.zip
Qt-676780d515cedca85829ae962e4f501c5e5b6581.tar.gz
Qt-676780d515cedca85829ae962e4f501c5e5b6581.tar.bz2
Using qreal more consistently in code (prevent misuse of double)
We want to force use of qreal where possible. This can lead to better performance on platforms where qreal -> float (i.e. ARM). To achieve this we: 1. changed from 'double' to 'qreal', where justified 2. using qreal() to intialize constants, where justified 3. adding helper functions that are overloaded for qreal like qAtan2(), qAcos(), qFabs() ... 4. defining QT_USE_MATH_H_FLOATS for Symbian platform In addtion we used opportunity to improve code with some small things 5. converting divisions to multiplications (i.e. '/ 2.0' -> '* qreal(0.5)') 6. defining new constants (i.e. 'Q_PI / 180.0' -> 'Q_PI180') 7. declaring variables as 'const', where justified Reviewed-by: Andreas Aardal Hanssen Reviewed-by: Gunnar Sletta Reviewed-by: Jan-Arve Reviewed-by: Kim Motoyoshi Kalland Reviewed-by: Alessandro Portale Reviewed-by: Janne Koskinen
Diffstat (limited to 'src/svg/qsvggraphics.cpp')
-rw-r--r--src/svg/qsvggraphics.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/svg/qsvggraphics.cpp b/src/svg/qsvggraphics.cpp
index 6552b69..cc3c170 100644
--- a/src/svg/qsvggraphics.cpp
+++ b/src/svg/qsvggraphics.cpp
@@ -332,11 +332,12 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states)
// Force the font to have a size of 100 pixels to avoid truncation problems
// when the font is very small.
- qreal scale = 100.0 / p->font().pointSizeF();
+ const qreal scale = qreal(100.0) / p->font().pointSizeF();
+ const qreal inv_scale = p->font().pointSizeF() / qreal(100.0); // like '1/scale' but with less rounding errors
Qt::Alignment alignment = states.textAnchor;
QTransform oldTransform = p->worldTransform();
- p->scale(1 / scale, 1 / scale);
+ p->scale(inv_scale, inv_scale);
qreal y = 0;
bool initial = true;
@@ -346,7 +347,7 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states)
if (m_type == TEXTAREA) {
if (alignment == Qt::AlignHCenter)
- px += scaledSize.width() / 2;
+ px += scaledSize.width() * qreal(0.5);
else if (alignment == Qt::AlignRight)
px += scaledSize.width();
}
@@ -459,7 +460,7 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states)
qreal x = 0;
if (alignment == Qt::AlignHCenter)
- x -= 0.5 * line.naturalTextWidth();
+ x -= qreal(0.5) * line.naturalTextWidth();
else if (alignment == Qt::AlignRight)
x -= line.naturalTextWidth();
@@ -479,7 +480,7 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states)
break;
}
- y += 1.1 * line.height();
+ y += qreal(1.1) * line.height();
}
tl.draw(p, QPointF(px, py), QVector<QTextLayout::FormatRange>(), bounds);