From 901f1a788c6dcb5291539fe4edc271cf53d85a2a Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 21 Feb 2021 05:11:31 -0500 Subject: [PATCH] Enhance QPDFMatrix API --- ChangeLog | 8 ++++++++ include/qpdf/QPDFMatrix.hh | 1 - include/qpdf/QPDFObjectHandle.hh | 5 +++++ libqpdf/QPDFObjectHandle.cc | 24 ++++++++++++++++++++++-- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3b6629e..9621b3ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2021-02-21 Jay Berkenbilt + + * Allow QPDFObjectHandle::newArray and + QPDFObjectHandle::newFromMatrix take QPDFMatrix as well as + QPDFObjectHandle::Matrix + + * Make member variables a--f of QPDFMatrix public + 2021-02-20 Jay Berkenbilt * Allow --rotate=0 to clear rotation from a page. diff --git a/include/qpdf/QPDFMatrix.hh b/include/qpdf/QPDFMatrix.hh index 8a8bff60..9448fb99 100644 --- a/include/qpdf/QPDFMatrix.hh +++ b/include/qpdf/QPDFMatrix.hh @@ -90,7 +90,6 @@ class QPDFMatrix QPDFObjectHandle::Rectangle transformRectangle( QPDFObjectHandle::Rectangle r); - private: double a; double b; double c; diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index efcd653a..bb877622 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -47,6 +47,7 @@ class QPDF_Array; class QPDFTokenizer; class QPDFExc; class Pl_QPDFTokenizer; +class QPDFMatrix; class QPDFObjectHandle { @@ -522,6 +523,8 @@ class QPDFObjectHandle QPDF_DLL static QPDFObjectHandle newArray(Matrix const&); QPDF_DLL + static QPDFObjectHandle newArray(QPDFMatrix const&); + QPDF_DLL static QPDFObjectHandle newDictionary(); QPDF_DLL static QPDFObjectHandle newDictionary( @@ -535,6 +538,8 @@ class QPDFObjectHandle // form of newArray. QPDF_DLL static QPDFObjectHandle newFromMatrix(Matrix const&); + QPDF_DLL + static QPDFObjectHandle newFromMatrix(QPDFMatrix const&); // Create a new stream and associate it with the given qpdf // object. A subsequent call must be made to replaceStreamData() diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 6c37829d..ceb91630 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -2566,6 +2567,19 @@ QPDFObjectHandle::newArray(Matrix const& matrix) return newArray(items); } +QPDFObjectHandle +QPDFObjectHandle::newArray(QPDFMatrix 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) { @@ -2573,9 +2587,15 @@ QPDFObjectHandle::newFromRectangle(Rectangle const& rect) } QPDFObjectHandle -QPDFObjectHandle::newFromMatrix(Matrix const& rect) +QPDFObjectHandle::newFromMatrix(Matrix const& m) { - return newArray(rect); + return newArray(m); +} + +QPDFObjectHandle +QPDFObjectHandle::newFromMatrix(QPDFMatrix const& m) +{ + return newArray(m); } QPDFObjectHandle