Skip to content

Commit

Permalink
saving/loading text box: include transform matrix (ignored by Xournal++)
Browse files Browse the repository at this point in the history
  • Loading branch information
stiglers-eponym committed Sep 5, 2022
1 parent a4926f1 commit 84f31cd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/drawing/pathcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ void PathContainer::writeXml(QXmlStreamWriter &writer) const
writer.writeAttribute("color", color_to_rgba(item->defaultTextColor()).toLower());
writer.writeAttribute("x", QString::number(item->x()));
writer.writeAttribute("y", QString::number(item->y()));
const QTransform transform = item->transform();
if (!transform.isIdentity())
writer.writeAttribute("transform",
QString("matrix(%1,%2,%3,%4,%5,%6)")
.arg(transform.m11())
.arg(transform.m12())
.arg(transform.m21())
.arg(transform.m22())
.arg(transform.dx())
.arg(transform.dy()));
writer.writeCharacters(item->toPlainText());
writer.writeEndElement();
break;
Expand Down Expand Up @@ -638,6 +648,19 @@ TextGraphicsItem *loadTextItem(QXmlStreamReader &reader)
font.setPointSizeF(reader.attributes().value("size").toDouble());
item->setFont(font);
item->setDefaultTextColor(rgba_to_color(reader.attributes().value("color").toString()));
QString transform_string = reader.attributes().value("transform").toString();
if (transform_string.length() >= 19 && transform_string.startsWith("matrix(") && transform_string.endsWith(")"))
{
// TODO: this is inefficient
transform_string.remove("matrix(");
transform_string.remove(")");
const QStringList list = transform_string.trimmed().replace(" ", ",").split(",");
if (list.length() == 6)
item->setTransform(QTransform(
list[0].toDouble(), list[1].toDouble(),
list[2].toDouble(), list[3].toDouble(),
list[4].toDouble(), list[5].toDouble()));
}
const QString text = reader.readElementText();
if (text.isEmpty())
{
Expand Down

0 comments on commit 84f31cd

Please sign in to comment.