PDA

View Full Version : QSvgRenderer::boundsOnElement broken for text nodes



treaves
12th July 2013, 18:10
When calling boundsOnElement() on a text node QRectF(0,0 0x0) is always returned. I've searched around a bit, and can find one reference on a Yahoo group to this as well. I've tried a couple of different versions of Qt, but, am currently using 4.8.5 on a Mac.

When calling this method for non-text nodes, it works correctly.

Has anyone found a workaround for this?

ChrisW67
13th July 2013, 09:24
Can you provide an example SVG document and the code that fails?

treaves
15th July 2013, 15:24
Your question implies there is an example that works.

Here is a simple SVG and the code. The output is:
Element exists: true
Matrix: QMatrix(11=1 12=0 21=0 22=1 dx=0 dy=0)
Local bounds: QRectF(0,0 0x0)
Context bounds: QRectF(0,0 0x0)
Element exists: true
Matrix: QMatrix(11=1 12=0 21=0 22=1 dx=0 dy=0)
Local bounds: QRectF(955.358,2445.36 7.28346x204.283)
Context bounds: QRectF(955.358,2445.36 7.28346x204.283)
Elapsed time: 2 milliseconds.


QString fileName = "test.svg";
QSvgRenderer * renderer = new QSvgRenderer(fileName, this);

QString testID = "id1";
qDebug() << "Element exists: " << renderer->elementExists(testID);
QMatrix matrixOfElement = renderer->matrixForElement(testID);
qDebug() << "Matrix: " << matrixOfElement;
QRectF localBounds = renderer->boundsOnElement(testID);
qDebug() << "Local bounds:" << localBounds;
QRectF bounds = matrixOfElement.mapRect(localBounds);
qDebug() << "Context bounds:" << bounds;

testID = "id2";
qDebug() << "Element exists: " << renderer->elementExists(testID);
matrixOfElement = renderer->matrixForElement(testID);
qDebug() << "Matrix: " << matrixOfElement;
localBounds = renderer->boundsOnElement(testID);
qDebug() << "Local bounds:" << localBounds;
bounds = matrixOfElement.mapRect(localBounds);
qDebug() << "Context bounds:" << bounds;

9290

Thanks for any assistance.

lni
7th December 2013, 12:00
Anyone has answer on this?

I am using Qt 4.8.1, and having exactly same problem, QSvgRenderer::boundsOnElement always return (0,0,0,0) for text node.

Thanks

ChrisW67
7th December 2013, 22:18
https://bugreports.qt-project.org/browse/QTBUG-32405
Fails here with Qt 4.8.5 and 5.1.1 on Linux. I cannot see an obvious cause.