QSvgRenderer draw text incorrect after QDomDocument.
-
I try to draw SVG image over QPrintPreviewWidget.
If I simply loads SVG image via QSvgRenderer - all works fine.
But if I at first load this file to the QDomDocument, for edit, and then convert it to QByteArray - text on image goes wrong.
Can I fix it or it's a bug?@void PrintPreviewWidget::doPaint(QPrinter *printer)
{
QString str("../test/test.svg");QFile file(str); QString src; if (file.open(QIODevice::ReadOnly | QIODevice::Text)) src = file.readAll(); QDomDocument doc; doc.setContent(src); // document editing // didn't work QSvgRenderer renderer(doc.toByteArray()); // works good
// QSvgRenderer renderer(str);
QPainter painter(printer); QRectF rect(0, 0, printer->width(), printer->height()); renderer.render(&painter, rect); painter.end();
}@
!http://storage3.static.itmages.ru/i/12/1124/h_1353705790_9196847_73481a1a77.png(1)!
!http://storage4.static.itmages.ru/i/12/1124/h_1353705823_2938344_62c09f5615.png(2)!"Code example":http://rghost.ru/41768863
Qt 4.8.3, Gentoo Linux, KDE
-
Well to use moe resources of SVG I have used the WebKit, QWebKit!
Using the Webkit suck things like JavaScript on SVG would be possible to use and link the JS with C++ code!
I think that QWebKit have a better support to SVG Files! -
Fixed by:
@doc.toString(0).replace(">\n<tspan", "><tspan")@QDomDocument by default write each tag on new line, but by "SVG spec":http://www.w3.org/TR/SVGTiny12/text.html#TSpanElement <tspan> on new line equated to space.