Load a free text's non-finite position or rotation as 0

"nan", "inf" and "-inf" parse as numbers, and IndependentTextItem::
fromXml() used them as they came for x, y and rotation. A project with
such a value kept it: --resave wrote x="nan" back, and the SVG export
drew the text at matrix(1,0,0,1,nan,95), which is not valid SVG.
Conductors and element texts already load a non-finite position as 0.

Load a non-finite x, y or rotation of a free text as 0, the same way.

No file-format change: finite values load and save as before.

Tests: tst_freetextnonfinite runs the binary's --resave and --export-svg
on a fixture with x="nan", y="inf", x="-inf", rotation="nan" and a
finite text (61.7, 61.3, 37 degrees, kept as they are). The four
non-finite cases and the export check fail on master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Beat Hangartner <beat@hangartners.ch>
This commit is contained in:
Beat Hangartner
2026-10-09 13:35:53 +02:00
parent 5f6e74918e
commit 9136c605f4
4 changed files with 192 additions and 2 deletions
@@ -85,9 +85,14 @@ IndependentTextItem::~IndependentTextItem()
void IndependentTextItem::fromXml(const QDomElement &e) {
const QUuid uuid(e.attribute(QStringLiteral("uuid")));
if (!uuid.isNull() && uuid != m_uuid) setUuid(uuid);
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
//"nan" and "inf" parse as numbers; a non-finite position or
//rotation is kept at 0, as for conductors and element texts
const qreal x = e.attribute("x").toDouble();
const qreal y = e.attribute("y").toDouble();
setPos(qIsFinite(x) ? x : 0, qIsFinite(y) ? y : 0);
setHtml(e.attribute("text"));
setRotation(e.attribute("rotation").toDouble());
const qreal rotation = e.attribute("rotation").toDouble();
setRotation(qIsFinite(rotation) ? rotation : 0);
if (e.hasAttribute("font"))
{
QFont font;