aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFMatrix.cc11
-rw-r--r--libqpdf/QPDFObjectHandle.cc55
-rw-r--r--libqpdf/qpdf/QPDFMatrix.hh3
3 files changed, 69 insertions, 0 deletions
diff --git a/libqpdf/QPDFMatrix.cc b/libqpdf/QPDFMatrix.cc
index 28a338f0..3d410435 100644
--- a/libqpdf/QPDFMatrix.cc
+++ b/libqpdf/QPDFMatrix.cc
@@ -22,6 +22,17 @@ QPDFMatrix::QPDFMatrix(double a, double b, double c,
{
}
+QPDFMatrix::QPDFMatrix(QPDFObjectHandle::Matrix const& m) :
+ a(m.a),
+ b(m.b),
+ c(m.c),
+ d(m.d),
+ e(m.e),
+ f(m.f)
+{
+}
+
+
std::string
QPDFMatrix::unparse() const
{
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index d0373d63..51df113c 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -575,6 +575,26 @@ QPDFObjectHandle::isRectangle()
return true;
}
+bool
+QPDFObjectHandle::isMatrix()
+{
+ if (! isArray())
+ {
+ return false;
+ }
+ if (getArrayNItems() != 6)
+ {
+ return false;
+ }
+ for (size_t i = 0; i < 6; ++i)
+ {
+ if (! getArrayItem(i).isNumber())
+ {
+ return false;
+ }
+ }
+ return true;
+}
QPDFObjectHandle::Rectangle
QPDFObjectHandle::getArrayAsRectangle()
@@ -590,6 +610,22 @@ QPDFObjectHandle::getArrayAsRectangle()
return result;
}
+QPDFObjectHandle::Matrix
+QPDFObjectHandle::getArrayAsMatrix()
+{
+ Matrix result;
+ if (isMatrix())
+ {
+ result = Matrix(getArrayItem(0).getNumericValue(),
+ getArrayItem(1).getNumericValue(),
+ getArrayItem(2).getNumericValue(),
+ getArrayItem(3).getNumericValue(),
+ getArrayItem(4).getNumericValue(),
+ getArrayItem(5).getNumericValue());
+ }
+ return result;
+}
+
std::vector<QPDFObjectHandle>
QPDFObjectHandle::getArrayAsVector()
{
@@ -1931,12 +1967,31 @@ QPDFObjectHandle::newArray(Rectangle const& rect)
}
QPDFObjectHandle
+QPDFObjectHandle::newArray(Matrix const& matrix)
+{
+ std::vector<QPDFObjectHandle> items;
+ items.push_back(newReal(matrix.a));
+ items.push_back(newReal(matrix.b));
+ items.push_back(newReal(matrix.c));
+ items.push_back(newReal(matrix.d));
+ items.push_back(newReal(matrix.e));
+ items.push_back(newReal(matrix.f));
+ return newArray(items);
+}
+
+QPDFObjectHandle
QPDFObjectHandle::newFromRectangle(Rectangle const& rect)
{
return newArray(rect);
}
QPDFObjectHandle
+QPDFObjectHandle::newFromMatrix(Matrix const& rect)
+{
+ return newArray(rect);
+}
+
+QPDFObjectHandle
QPDFObjectHandle::newDictionary()
{
return newDictionary(std::map<std::string, QPDFObjectHandle>());
diff --git a/libqpdf/qpdf/QPDFMatrix.hh b/libqpdf/qpdf/QPDFMatrix.hh
index dcf8b195..81bc51f1 100644
--- a/libqpdf/qpdf/QPDFMatrix.hh
+++ b/libqpdf/qpdf/QPDFMatrix.hh
@@ -1,6 +1,7 @@
#ifndef QPDFMATRIX_HH
#define QPDFMATRIX_HH
+#include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/DLL.h>
#include <string>
@@ -12,6 +13,8 @@ class QPDFMatrix
QPDF_DLL
QPDFMatrix(double a, double b, double c,
double d, double e, double f);
+ QPDF_DLL
+ QPDFMatrix(QPDFObjectHandle::Matrix const&);
QPDF_DLL
std::string unparse() const;