From 5059ec0d35547c0b3328c3089221b7cb3c3ac45d Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 24 Dec 2018 19:29:30 -0500 Subject: Add Matrix class under QPDFObjectHandle --- libqpdf/QPDFMatrix.cc | 11 +++++++++ libqpdf/QPDFObjectHandle.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++ libqpdf/qpdf/QPDFMatrix.hh | 3 +++ 3 files changed, 69 insertions(+) (limited to 'libqpdf') 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::getArrayAsVector() { @@ -1930,12 +1966,31 @@ QPDFObjectHandle::newArray(Rectangle const& rect) return newArray(items); } +QPDFObjectHandle +QPDFObjectHandle::newArray(Matrix const& matrix) +{ + std::vector 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() { 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 #include #include @@ -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; -- cgit v1.2.3-54-g00ecf