summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@digia.com>2014-10-01 18:02:56 +0200
committerJoerg Bornemann <joerg.bornemann@digia.com>2014-10-07 14:00:28 +0200
commitf4c99c16bcf8638ccff7aabe4eff707150f11022 (patch)
treecafbba30da3421dd39826cca9b8e8f32143308f4
parenta4dbb28c4602421a3166e83ffc0011e49e1b37b2 (diff)
downloadqtsvg-f4c99c16bcf8638ccff7aabe4eff707150f11022.tar.gz
QSvgGenerator: make use of the <rect> element
[ChangeLog][][QSvgGenerator] Make use of the <rect> element for drawing rectangles instead of generating a number of path strokes. Task-number: QTBUG-1359 Change-Id: I54163a13f66089c7ff3d29953ba3e923e3983517 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Andy Shaw <andy.shaw@digia.com>
-rw-r--r--src/svg/qsvggenerator.cpp16
-rw-r--r--tests/auto/qsvggenerator/referenceSvgs/fileName_output.svg2
-rw-r--r--tests/auto/qsvggenerator/referenceSvgs/radial_gradient.svg4
3 files changed, 19 insertions, 3 deletions
diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp
index 6a12043..1cb342a 100644
--- a/src/svg/qsvggenerator.cpp
+++ b/src/svg/qsvggenerator.cpp
@@ -165,6 +165,7 @@ public:
void drawPath(const QPainterPath &path);
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
+ void drawRects(const QRectF *rects, int rectCount) Q_DECL_OVERRIDE;
void drawTextItem(const QPointF &pt, const QTextItem &item);
void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
Qt::ImageConversionFlags flags = Qt::AutoColor);
@@ -1038,6 +1039,21 @@ void QSvgPaintEngine::drawPolygon(const QPointF *points, int pointCount,
}
}
+void QSvgPaintEngine::drawRects(const QRectF *rects, int rectCount)
+{
+ Q_D(QSvgPaintEngine);
+
+ for (int i=0; i < rectCount; ++i) {
+ const QRectF &rect = rects[i];
+ *d->stream << "<rect";
+ if (state->pen().isCosmetic())
+ *d->stream << " vector-effect=\"non-scaling-stroke\"";
+ *d->stream << " x=\"" << rect.x() << "\" y=\"" << rect.y()
+ << "\" width=\"" << rect.width() << "\" height=\"" << rect.height()
+ << "\"/>" << endl;
+ }
+}
+
void QSvgPaintEngine::drawTextItem(const QPointF &pt, const QTextItem &textItem)
{
Q_D(QSvgPaintEngine);
diff --git a/tests/auto/qsvggenerator/referenceSvgs/fileName_output.svg b/tests/auto/qsvggenerator/referenceSvgs/fileName_output.svg
index 1e78e17..3519f6a 100644
--- a/tests/auto/qsvggenerator/referenceSvgs/fileName_output.svg
+++ b/tests/auto/qsvggenerator/referenceSvgs/fileName_output.svg
@@ -9,7 +9,7 @@
<g fill="#ff0000" fill-opacity="1" stroke="none" transform="matrix(1,0,0,1,0,0)"
font-family="Sans Serif" font-size="8.25" font-weight="400" font-style="normal"
>
-<path vector-effect="none" fill-rule="evenodd" d="M0,0 L100,0 L100,100 L0,100 L0,0"/>
+<rect x="0" y="0" width="100" height="100"/>
</g>
</g>
</svg>
diff --git a/tests/auto/qsvggenerator/referenceSvgs/radial_gradient.svg b/tests/auto/qsvggenerator/referenceSvgs/radial_gradient.svg
index 2c5c03e..a56674c 100644
--- a/tests/auto/qsvggenerator/referenceSvgs/radial_gradient.svg
+++ b/tests/auto/qsvggenerator/referenceSvgs/radial_gradient.svg
@@ -18,13 +18,13 @@
<g fill="url(#gradient1)" stroke="none" transform="matrix(1,0,0,1,0,0)"
font-family="Sans Serif" font-size="8.25" font-weight="400" font-style="normal"
>
-<path vector-effect="none" fill-rule="evenodd" d="M0,0 L100,0 L100,100 L0,100 L0,0"/>
+<rect x="0" y="0" width="100" height="100"/>
</g>
<g fill="url(#gradient2)" stroke="none" transform="matrix(1,0,0,1,0,0)"
font-family="Sans Serif" font-size="8.25" font-weight="400" font-style="normal"
>
-<path vector-effect="none" fill-rule="evenodd" d="M100,0 L200,0 L200,100 L100,100 L100,0"/>
+<rect x="100" y="0" width="100" height="100"/>
</g>
</g>
</svg>