diff options
Diffstat (limited to 'src/svg')
-rw-r--r-- | src/svg/qsvggenerator.cpp | 9 | ||||
-rw-r--r-- | src/svg/qsvggraphics.cpp | 11 | ||||
-rw-r--r-- | src/svg/qsvghandler.cpp | 73 | ||||
-rw-r--r-- | src/svg/qsvgtinydocument.cpp | 13 |
4 files changed, 50 insertions, 56 deletions
diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp index 248bf55..2f80a92 100644 --- a/src/svg/qsvggenerator.cpp +++ b/src/svg/qsvggenerator.cpp @@ -796,9 +796,9 @@ int QSvgGenerator::metric(QPaintDevice::PaintDeviceMetric metric) const case QPaintDevice::PdmDpiY: return d->engine->resolution(); case QPaintDevice::PdmHeightMM: - return qRound(d->engine->size().height() * (d->engine->resolution() / qreal(25.4))); + return qRound(d->engine->size().height() * 25.4 / d->engine->resolution()); case QPaintDevice::PdmWidthMM: - return qRound(d->engine->size().width() * (d->engine->resolution() / qreal(25.4))); + return qRound(d->engine->size().width() * 25.4 / d->engine->resolution()); case QPaintDevice::PdmNumColors: return 0xffffffff; case QPaintDevice::PdmPhysicalDpiX: @@ -842,9 +842,8 @@ bool QSvgPaintEngine::begin(QPaintDevice *) *d->stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << endl << "<svg"; if (d->size.isValid()) { - const qreal mm_factor = d->resolution / qreal(25.4); - const qreal wmm = d->size.width() * mm_factor; - const qreal hmm = d->size.height() * mm_factor; + qreal wmm = d->size.width() * 25.4 / d->resolution; + qreal hmm = d->size.height() * 25.4 / d->resolution; *d->stream << " width=\"" << wmm << "mm\" height=\"" << hmm << "mm\"" << endl; } diff --git a/src/svg/qsvggraphics.cpp b/src/svg/qsvggraphics.cpp index cc3c170..6552b69 100644 --- a/src/svg/qsvggraphics.cpp +++ b/src/svg/qsvggraphics.cpp @@ -332,12 +332,11 @@ 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. - 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 + qreal scale = 100.0 / p->font().pointSizeF(); Qt::Alignment alignment = states.textAnchor; QTransform oldTransform = p->worldTransform(); - p->scale(inv_scale, inv_scale); + p->scale(1 / scale, 1 / scale); qreal y = 0; bool initial = true; @@ -347,7 +346,7 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states) if (m_type == TEXTAREA) { if (alignment == Qt::AlignHCenter) - px += scaledSize.width() * qreal(0.5); + px += scaledSize.width() / 2; else if (alignment == Qt::AlignRight) px += scaledSize.width(); } @@ -460,7 +459,7 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states) qreal x = 0; if (alignment == Qt::AlignHCenter) - x -= qreal(0.5) * line.naturalTextWidth(); + x -= 0.5 * line.naturalTextWidth(); else if (alignment == Qt::AlignRight) x -= line.naturalTextWidth(); @@ -480,7 +479,7 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states) break; } - y += qreal(1.1) * line.height(); + y += 1.1 * line.height(); } tl.draw(p, QPointF(px, py), QVector<QTextLayout::FormatRange>(), bounds); diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index a340c05..3ed918e 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -66,7 +66,6 @@ #include "qnumeric.h" #include "qvarlengtharray.h" #include "private/qmath_p.h" -#include "private/qnumeric_p.h" #include "float.h" @@ -909,7 +908,7 @@ static inline qreal convertToNumber(const QString &str, QSvgHandler *handler, bo QSvgHandler::LengthType type; qreal num = parseLength(str, type, handler, ok); if (type == QSvgHandler::LT_PERCENT) { - num = num * qreal(0.01); + num = num/100.0; } return num; } @@ -944,13 +943,13 @@ static qreal convertToPixels(qreal len, bool , QSvgHandler::LengthType type) case QSvgHandler::LT_PC: break; case QSvgHandler::LT_PT: - return len * qreal(1.25); + return len * 1.25; break; case QSvgHandler::LT_MM: - return len * qreal(3.543307); + return len * 3.543307; break; case QSvgHandler::LT_CM: - return len * qreal(35.43307); + return len * 35.43307; break; case QSvgHandler::LT_IN: return len * 90; @@ -1373,16 +1372,16 @@ static void pathArcSegment(QPainterPath &path, qreal t; qreal thHalf; - sinTh = qSin(xAxisRotation * Q_PI180); - cosTh = qCos(xAxisRotation * Q_PI180); + sinTh = qSin(xAxisRotation * (Q_PI / 180.0)); + cosTh = qCos(xAxisRotation * (Q_PI / 180.0)); a00 = cosTh * rx; a01 = -sinTh * ry; a10 = sinTh * rx; a11 = cosTh * ry; - thHalf = qreal(0.5) * (th1 - th0); - t = (qreal(8.0) / qreal(3.0)) * qSin(thHalf * qreal(0.5)) * qSin(thHalf * qreal(0.5)) / qSin(thHalf); + thHalf = 0.5 * (th1 - th0); + t = (8.0 / 3.0) * qSin(thHalf * 0.5) * qSin(thHalf * 0.5) / qSin(thHalf); x1 = xc + qCos(th0) - t * qSin(th0); y1 = yc + qSin(th0) + t * qCos(th0); x3 = xc + qCos(th1); @@ -1442,11 +1441,11 @@ static void pathArc(QPainterPath &path, rx = qAbs(rx); ry = qAbs(ry); - sin_th = qSin(x_axis_rotation * Q_PI180); - cos_th = qCos(x_axis_rotation * Q_PI180); + sin_th = qSin(x_axis_rotation * (Q_PI / 180.0)); + cos_th = qCos(x_axis_rotation * (Q_PI / 180.0)); - dx = (curx - x) * qreal(0.5); - dy = (cury - y) * qreal(0.5); + dx = (curx - x) / 2.0; + dy = (cury - y) / 2.0; dx1 = cos_th * dx + sin_th * dy; dy1 = -sin_th * dx + cos_th * dy; Pr1 = rx * rx; @@ -1460,12 +1459,10 @@ static void pathArc(QPainterPath &path, ry = ry * qSqrt(check); } - const qreal inv_rx = 1 / rx; - const qreal inv_ry = 1 / ry; - a00 = cos_th * inv_rx; - a01 = sin_th * inv_rx; - a10 = -sin_th * inv_ry; - a11 = cos_th * inv_ry; + a00 = cos_th / rx; + a01 = sin_th / rx; + a10 = -sin_th / ry; + a11 = cos_th / ry; x0 = a00 * curx + a01 * cury; y0 = a10 * curx + a11 * cury; x1 = a00 * x + a01 * y; @@ -1476,12 +1473,12 @@ static void pathArc(QPainterPath &path, The arc fits a unit-radius circle in this space. */ d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0); - sfactor_sq = qreal(1.0) / d - qreal(0.25); + sfactor_sq = 1.0 / d - 0.25; if (sfactor_sq < 0) sfactor_sq = 0; sfactor = qSqrt(sfactor_sq); if (sweep_flag == large_arc_flag) sfactor = -sfactor; - xc = qreal(0.5) * (x0 + x1) - sfactor * (y1 - y0); - yc = qreal(0.5) * (y0 + y1) + sfactor * (x1 - x0); + xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0); + yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0); /* (xc, yc) is center of the circle. */ th0 = atan2(y0 - yc, x0 - xc); @@ -1489,18 +1486,16 @@ static void pathArc(QPainterPath &path, th_arc = th1 - th0; if (th_arc < 0 && sweep_flag) - th_arc += Q_2PI; + th_arc += 2 * Q_PI; else if (th_arc > 0 && !sweep_flag) - th_arc -= Q_2PI; + th_arc -= 2 * Q_PI; - n_segs = qCeil(qAbs(th_arc / (Q_PI2 + qreal(0.001)))); + n_segs = qCeil(qAbs(th_arc / (Q_PI * 0.5 + 0.001))); - const qreal th_arc_div_n_segs = th_arc / n_segs; for (i = 0; i < n_segs; i++) { - const qreal i_mul_th_arc_div_n_segs = i * th_arc_div_n_segs; pathArcSegment(path, xc, yc, - th0 + i_mul_th_arc_div_n_segs, - th0 + i_mul_th_arc_div_n_segs + th_arc_div_n_segs, + th0 + i * th_arc / n_segs, + th0 + (i + 1) * th_arc / n_segs, rx, ry, x_axis_rotation); } } @@ -2974,10 +2969,10 @@ static QSvgNode *createRectNode(QSvgNode *parent, //9.2 The 'rect' element clearly specifies it // but the case might in fact be handled because // we draw rounded rectangles differently - if (nrx > bounds.width()*qreal(0.5)) - nrx = bounds.width()*qreal(0.5); - if (nry > bounds.height()*qreal(0.5)) - nry = bounds.height()*qreal(0.5); + if (nrx > bounds.width()/2) + nrx = bounds.width()/2; + if (nry > bounds.height()/2) + nry = bounds.height()/2; if (nrx && !nry) nry = nrx; @@ -2987,8 +2982,8 @@ static QSvgNode *createRectNode(QSvgNode *parent, //we draw rounded rect from 0...99 //svg from 0...bounds.width()/2 so we're adjusting the //coordinates - nrx *= (200/bounds.width()); - nry *= (200/bounds.height()); + nrx *= (100/(bounds.width()/2)); + nry *= (100/(bounds.height()/2)); QSvgNode *rect = new QSvgRect(parent, bounds, int(nrx), @@ -3078,7 +3073,7 @@ static bool parseStopNode(QSvgStyleProperty *parent, bool ok = true; qreal offset = convertToNumber(offsetStr, handler, &ok); if (!ok) - offset = qreal(0.0); + offset = 0.0; QString black = QString::fromLatin1("#000000"); if (colorStr.isEmpty()) { colorStr = QStringRef(&black); @@ -3098,9 +3093,9 @@ static bool parseStopNode(QSvgStyleProperty *parent, } // If offset is greater than one, it must be clamped to one. - if (offset > qreal(1.0)) { - if ((stops.size() == 1) || (stops.at(stops.size() - 2).first < qreal(1.0) - FLT_EPSILON)) { - stops.back().first = qreal(1.0) - FLT_EPSILON; + if (offset > 1.0) { + if ((stops.size() == 1) || (stops.at(stops.size() - 2).first < 1.0 - FLT_EPSILON)) { + stops.back().first = 1.0 - FLT_EPSILON; grad->setStops(stops); } offset = 1.0; diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp index 21e9e9f..e2cefeb 100644 --- a/src/svg/qsvgtinydocument.cpp +++ b/src/svg/qsvgtinydocument.cpp @@ -466,19 +466,20 @@ QMatrix QSvgTinyDocument::matrixForElement(const QString &id) const int QSvgTinyDocument::currentFrame() const { - const qreal runningPercentage = qMin(qreal(m_time.elapsed()) / qreal(m_animationDuration), qreal(1.)); + double runningPercentage = qMin(m_time.elapsed()/double(m_animationDuration), 1.); - const int totalFrames = m_fps * m_animationDuration; + int totalFrames = m_fps * m_animationDuration; return int(runningPercentage * totalFrames); } void QSvgTinyDocument::setCurrentFrame(int frame) { - const int totalFrames = m_fps * m_animationDuration; - const qreal framePercentage = frame / totalFrames; - const qreal timeForFrame = m_animationDuration * framePercentage * 1000; //in ms - const int timeToAdd = int(timeForFrame - m_time.elapsed()); + int totalFrames = m_fps * m_animationDuration; + double framePercentage = frame/double(totalFrames); + double timeForFrame = m_animationDuration * framePercentage; //in S + timeForFrame *= 1000; //in ms + int timeToAdd = int(timeForFrame - m_time.elapsed()); m_time = m_time.addMSecs(timeToAdd); } |