Skip to content

Commit

Permalink
feat: update XML/skia conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
kaixoo committed Jan 17, 2025
1 parent 88e6ea0 commit 6fda77e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/core/XML/xmlexporthelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "xmlexporthelpers.h"

#include <QMatrix4x4>

#include "Properties/property.h"
#include "Paint/simplebrushwrapper.h"
#include "Paint/brushescontext.h"
Expand Down Expand Up @@ -158,6 +160,39 @@ QString XmlExportHelpers::matrixToString(const QMatrix& m) {
arg(m.dx()).arg(m.dy());
}

QMatrix4x4 XmlExportHelpers::stringToMatrix4x4(const QString& str) {
const auto vals = str.split(' ', Qt::SkipEmptyParts);
if(vals.count() != 7) RuntimeThrow("Invalid matrix value '" + str + "'");
const qreal m11 = stringToDouble(vals[0]);
const qreal m12 = stringToDouble(vals[1]);
const qreal m13 = stringToDouble(vals[1]);
const qreal m14 = stringToDouble(vals[1]);
const qreal m21 = stringToDouble(vals[2]);
const qreal m22 = stringToDouble(vals[3]);
const qreal m23 = stringToDouble(vals[1]);
const qreal m24 = stringToDouble(vals[1]);
const qreal m31 = stringToDouble(vals[1]);
const qreal m32 = stringToDouble(vals[1]);
const qreal m33 = stringToDouble(vals[1]);
const qreal m34 = stringToDouble(vals[1]);
const qreal m41 = stringToDouble(vals[1]);
const qreal m42 = stringToDouble(vals[1]);
const qreal m43 = stringToDouble(vals[1]);
const qreal m44 = stringToDouble(vals[1]);
return QMatrix4x4(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44);
}
// TODO
/*QString XmlExportHelpers::matrix4x4ToString(const QMatrix4x4& m) {
return QString("%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14").arg(m.m11()).arg(m.m12())
.arg(m.m13()).arg(m.m14())
.arg(m.m21()).arg(m.m22())
.arg(m.m23()).arg(m.m24())
.arg(m.m31()).arg(m.m32())
.arg(m.m33()).arg(m.m34())
.arg(m.m41()).arg(m.42())
.arg(m.m43()).arg(m.m44());
}*/

void XevExportHelpers::setAbsAndRelFileSrc(const QString& absSrc,
QDomElement& ele,
const XevExporter& exp) {
Expand Down
6 changes: 6 additions & 0 deletions src/core/XML/xmlexporthelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QDomElement>
#include <QString>

class QMatrix4x4;
class SimpleBrushWrapper;
class XevExporter;
class XevImporter;
Expand Down Expand Up @@ -76,6 +77,11 @@ namespace XmlExportHelpers {
QMatrix stringToMatrix(const QString& str);
CORE_EXPORT
QString matrixToString(const QMatrix& m);

CORE_EXPORT
QMatrix4x4 stringToMatrix4x4(const QString& str);
/*CORE_EXPORT TODO
QString matrix4x4ToString(const QMatrix4x4& matrix);*/
};

namespace XevExportHelpers {
Expand Down
2 changes: 2 additions & 0 deletions src/core/skia/skiaincludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ QT_WARNING_DISABLE_GCC("-Wattributes")
#include "include/core/SkMaskFilter.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkFontMetrics.h"
#include "include/core/SkMatrix44.h"
#include "include/core/SkPoint3.h"

#include "include/pathops/SkPathOps.h"

Expand Down
27 changes: 27 additions & 0 deletions src/core/skia/skqtconversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <QRectF>
#include <QMatrix>
#include <QMatrix4x4>
#include <QColor>
#include <QFont>

Expand Down Expand Up @@ -77,11 +78,23 @@ extern QMatrix toQMatrix(const SkMatrix &matrix);
CORE_EXPORT
extern SkMatrix toSkMatrix(const QMatrix &matrix);

CORE_EXPORT
extern QMatrix4x4 toQMatrix4x4(const SkMatrix44 &matrix);

CORE_EXPORT
extern SkMatrix44 toSkMatrix44(const QMatrix4x4 &matrix);

extern inline QPointF toQPointF(const SkPoint &point) {
return QPointF(toQreal(point.x()),
toQreal(point.y()));
}

extern inline QVector3D toQVector3D(const SkPoint3 &point) {
return QVector3D(toQreal(point.x()),
toQreal(point.y()),
toQreal(point.z()));
}

extern inline SkPoint toSkPoint(const QPointF &point) {
return SkPoint::Make(toSkScalar(point.x()),
toSkScalar(point.y()));
Expand All @@ -91,6 +104,20 @@ extern inline SkPoint toSkPoint(const QPoint &point) {
return SkPoint::Make(point.x(), point.y());
}

extern inline SkPoint3 toSkPoint3(const QPointF &point) {
return SkPoint3::Make(toSkScalar(point.x()),
toSkScalar(point.y()),
0);
}

extern inline SkPoint3 toSkPoint3(const QPoint &point) {
return SkPoint3::Make(point.x(), point.y(), 0);
}

extern inline SkPoint3 toSkPoint3(const QVector3D &point) {
return SkPoint3::Make(point.x(), point.y(), point.z());
}

CORE_EXPORT
extern SkPaint::Cap QCapToSkCap(const Qt::PenCapStyle &cap);

Expand Down

0 comments on commit 6fda77e

Please sign in to comment.