Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.2.9, 6.5.2, 6.6.0 Beta2
-
Windows 10 22H2, MSVC 2022 x64
-
d257737a5 (dev), 6ee6fafa1 (6.6), 6242980de (6.5), 1370f271e (tqtc/lts-6.2)
Description
Code
#include <QGuiApplication> #include <QSvgRenderer> #include <QDebug> int main(int argc, char *argv[]) { QGuiApplication a(argc, argv); const QByteArrayList elements{ R"x(<text id="x" transform="matrix(0 -1 1 0 16 27.5)" font-family="Arial" font-size="10px">X</text>)x", R"y(<text id="y" transform="matrix(0 -1 1 0 27.5 27.5)" font-family="Arial" font-size="10px">Y</text>)y" }; for (int i = 0; i < 3; ++i) { QByteArray data = R"header(<svg xmlns="http://www.w3.org/2000/svg"><g id="all">)header"; if (i % 2 == 0) data += elements[0]; if (i > 0) data += elements[1]; data += "</g></svg>"; qDebug() << "=== Test" << i << "==="; qDebug() << data; QSvgRenderer renderer(data); QRectF unionRect; if (renderer.elementExists("x")) { auto xRect = renderer.boundsOnElement("x"); qDebug() << " X:" << xRect; unionRect = unionRect.united(xRect); } if (renderer.elementExists("y")) { auto yRect = renderer.boundsOnElement("y"); qDebug() << " Y:" << yRect; unionRect = unionRect.united(yRect); } qDebug() << "All, method 1:" << unionRect; qDebug() << "All, method 2:" << renderer.boundsOnElement("all"); qDebug("\n"); } }
Expected outcomes
At the end of every test case, we should see that renderer.boundsOnElement("all") == unionRect
Actual outcomes
- When there is only 1 text element (Test 0 and Test 1), the result is as expected
- When there is more than 1 text element (Test 2), renderer.boundsOnElement("all") is much larger than unionRect
=== Test 0 === "<svg xmlns=\"http://www.w3.org/2000/svg\"><g id=\"all\"><text id=\"x\" transform=\"matrix(0 -1 1 0 16 27.5)\" font-family=\"Arial\" font-size=\"10px\">X</text></g></svg>" X: QRectF(6.94688,20.8313 11.1719x6.66875) All, method 1: QRectF(6.94688,20.8313 11.1719x6.66875) All, method 2: QRectF(6.94688,20.8313 11.1719x6.66875) === Test 1 === "<svg xmlns=\"http://www.w3.org/2000/svg\"><g id=\"all\"><text id=\"y\" transform=\"matrix(0 -1 1 0 27.5 27.5)\" font-family=\"Arial\" font-size=\"10px\">Y</text></g></svg>" Y: QRectF(18.4469,20.8313 11.1719x6.66875) All, method 1: QRectF(18.4469,20.8313 11.1719x6.66875) All, method 2: QRectF(18.4469,20.8313 11.1719x6.66875) === Test 2 === "<svg xmlns=\"http://www.w3.org/2000/svg\"><g id=\"all\"><text id=\"x\" transform=\"matrix(0 -1 1 0 16 27.5)\" font-family=\"Arial\" font-size=\"10px\">X</text><text id=\"y\" transform=\"matrix(0 -1 1 0 27.5 27.5)\" font-family=\"Arial\" font-size=\"10px\">Y</text></g></svg>" X: QRectF(6.94688,20.8313 11.1719x6.66875) Y: QRectF(18.4469,20.8313 11.1719x6.66875) All, method 1: QRectF(6.94688,20.8313 22.6719x6.66875) All, method 2: QRectF(6.94688,-2.11875 36.5531x29.6187)
Notes
- The issue doesn't seem to occur if there is no transform attribute on the text elements
- The issue is not applicable to Qt 5.15 as boundsOnElement() only returns null rectangles in this test code
Attachments
For Gerrit Dashboard: QTBUG-115648 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
494207,3 | Fix bounds calculation for structures with text element children | dev | qt/qtsvg | Status: MERGED | +2 | 0 |
497596,2 | Fix bounds calculation for structures with text element children | 6.6 | qt/qtsvg | Status: MERGED | +2 | 0 |
497597,2 | Fix bounds calculation for structures with text element children | 6.5 | qt/qtsvg | Status: MERGED | +2 | 0 |
497701,2 | Fix bounds calculation for structures with text element children | tqtc/lts-6.2 | qt/tqtc-qtsvg | Status: MERGED | +2 | 0 |