aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFMatrix.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-12-24 22:28:08 +0100
committerJay Berkenbilt <ejb@ql.org>2019-01-01 00:23:47 +0100
commitdaeb5a85b6ded478aaac942c439ef5fd6bb8874f (patch)
treef83657f24a50c652ff833b4a93a6d2f55139282d /libqpdf/QPDFMatrix.cc
parent3440ea7d3ca0bfb5d6fb4d7392b61017cb36bf0a (diff)
downloadqpdf-daeb5a85b6ded478aaac942c439ef5fd6bb8874f.tar.zst
Transformation matrix
Diffstat (limited to 'libqpdf/QPDFMatrix.cc')
-rw-r--r--libqpdf/QPDFMatrix.cc90
1 files changed, 90 insertions, 0 deletions
diff --git a/libqpdf/QPDFMatrix.cc b/libqpdf/QPDFMatrix.cc
new file mode 100644
index 00000000..28a338f0
--- /dev/null
+++ b/libqpdf/QPDFMatrix.cc
@@ -0,0 +1,90 @@
+#include <qpdf/QPDFMatrix.hh>
+#include <qpdf/QUtil.hh>
+
+QPDFMatrix::QPDFMatrix() :
+ a(1.0),
+ b(0.0),
+ c(0.0),
+ d(1.0),
+ e(0.0),
+ f(0.0)
+{
+}
+
+QPDFMatrix::QPDFMatrix(double a, double b, double c,
+ double d, double e, double f) :
+ a(a),
+ b(b),
+ c(c),
+ d(d),
+ e(e),
+ f(f)
+{
+}
+
+std::string
+QPDFMatrix::unparse() const
+{
+ return (QUtil::double_to_string(a, 5) + " " +
+ QUtil::double_to_string(b, 5) + " " +
+ QUtil::double_to_string(c, 5) + " " +
+ QUtil::double_to_string(d, 5) + " " +
+ QUtil::double_to_string(e, 5) + " " +
+ QUtil::double_to_string(f, 5));
+}
+
+void
+QPDFMatrix::concat(QPDFMatrix const& other)
+{
+ double ap = (this->a * other.a) + (this->c * other.b);
+ double bp = (this->b * other.a) + (this->d * other.b);
+ double cp = (this->a * other.c) + (this->c * other.d);
+ double dp = (this->b * other.c) + (this->d * other.d);
+ double ep = (this->a * other.e) + (this->c * other.f) + this->e;
+ double fp = (this->b * other.e) + (this->d * other.f) + this->f;
+ this-> a = ap;
+ this-> b = bp;
+ this-> c = cp;
+ this-> d = dp;
+ this-> e = ep;
+ this-> f = fp;
+}
+
+void
+QPDFMatrix::scale(double sx, double sy)
+{
+ concat(QPDFMatrix(sx, 0, 0, sy, 0, 0));
+}
+
+void
+QPDFMatrix::translate(double tx, double ty)
+{
+ concat(QPDFMatrix(1, 0, 0, 1, tx, ty));
+}
+
+void
+QPDFMatrix::rotatex90(int angle)
+{
+ switch (angle)
+ {
+ case 90:
+ concat(QPDFMatrix(0, 1, -1, 0, 0, 0));
+ break;
+ case 180:
+ concat(QPDFMatrix(-1, 0, 0, -1, 0, 0));
+ break;
+ case 270:
+ concat(QPDFMatrix(0, -1, 1, 0, 0, 0));
+ break;
+ default:
+ // ignore
+ break;
+ }
+}
+
+void
+QPDFMatrix::transform(double x, double y, double& xp, double& yp)
+{
+ xp = (this->a * x) + (this->c * y) + this->e;
+ yp = (this->b * x) + (this->d * y) + this->f;
+}