mirror of
https://github.com/qpdf/qpdf.git
synced 2025-04-02 14:41:50 +00:00
Add Matrix class under QPDFObjectHandle
This commit is contained in:
parent
daeb5a85b6
commit
5059ec0d35
@ -1,3 +1,9 @@
|
|||||||
|
2018-12-31 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* Add QPDFObjectHandle::Matrix, similar to
|
||||||
|
QPDFObjectHandle::Rectangle, as a convenience class for
|
||||||
|
six-element arrays that are used as matrices.
|
||||||
|
|
||||||
2018-12-23 Jay Berkenbilt <ejb@ql.org>
|
2018-12-23 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* When specifying @arg on the command line, if the file "arg" does
|
* When specifying @arg on the command line, if the file "arg" does
|
||||||
|
@ -198,6 +198,38 @@ class QPDFObjectHandle
|
|||||||
double ury;
|
double ury;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Convenience object for transformation matrices
|
||||||
|
class Matrix
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Matrix() :
|
||||||
|
a(0.0),
|
||||||
|
b(0.0),
|
||||||
|
c(0.0),
|
||||||
|
d(0.0),
|
||||||
|
e(0.0),
|
||||||
|
f(0.0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Matrix(double a, double b, double c,
|
||||||
|
double d, double e, double f) :
|
||||||
|
a(a),
|
||||||
|
b(b),
|
||||||
|
c(c),
|
||||||
|
d(d),
|
||||||
|
e(e),
|
||||||
|
f(f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double a;
|
||||||
|
double b;
|
||||||
|
double c;
|
||||||
|
double d;
|
||||||
|
double e;
|
||||||
|
double f;
|
||||||
|
};
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
QPDFObjectHandle();
|
QPDFObjectHandle();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
@ -368,6 +400,8 @@ class QPDFObjectHandle
|
|||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
static QPDFObjectHandle newArray(Rectangle const&);
|
static QPDFObjectHandle newArray(Rectangle const&);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
|
static QPDFObjectHandle newArray(Matrix const&);
|
||||||
|
QPDF_DLL
|
||||||
static QPDFObjectHandle newDictionary();
|
static QPDFObjectHandle newDictionary();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
static QPDFObjectHandle newDictionary(
|
static QPDFObjectHandle newDictionary(
|
||||||
@ -377,6 +411,10 @@ class QPDFObjectHandle
|
|||||||
// form of newArray.
|
// form of newArray.
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
static QPDFObjectHandle newFromRectangle(Rectangle const&);
|
static QPDFObjectHandle newFromRectangle(Rectangle const&);
|
||||||
|
// Create an array from a matrix. Equivalent to the matrix
|
||||||
|
// form of newArray.
|
||||||
|
QPDF_DLL
|
||||||
|
static QPDFObjectHandle newFromMatrix(Matrix const&);
|
||||||
|
|
||||||
// Create a new stream and associate it with the given qpdf
|
// Create a new stream and associate it with the given qpdf
|
||||||
// object. A subsequent call must be made to replaceStreamData()
|
// object. A subsequent call must be made to replaceStreamData()
|
||||||
@ -500,6 +538,12 @@ class QPDFObjectHandle
|
|||||||
// rectangle. Otherwise, return the rectangle [0, 0, 0, 0]
|
// rectangle. Otherwise, return the rectangle [0, 0, 0, 0]
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
Rectangle getArrayAsRectangle();
|
Rectangle getArrayAsRectangle();
|
||||||
|
QPDF_DLL
|
||||||
|
bool isMatrix();
|
||||||
|
// If the array an array of six numeric values, return as a
|
||||||
|
// matrix. Otherwise, return the matrix [1, 0, 0, 1, 0, 0]
|
||||||
|
QPDF_DLL
|
||||||
|
Matrix getArrayAsMatrix();
|
||||||
|
|
||||||
// Methods for dictionary objects
|
// Methods for dictionary objects
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
|
@ -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
|
std::string
|
||||||
QPDFMatrix::unparse() const
|
QPDFMatrix::unparse() const
|
||||||
{
|
{
|
||||||
|
@ -575,6 +575,26 @@ QPDFObjectHandle::isRectangle()
|
|||||||
return true;
|
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::Rectangle
|
||||||
QPDFObjectHandle::getArrayAsRectangle()
|
QPDFObjectHandle::getArrayAsRectangle()
|
||||||
@ -590,6 +610,22 @@ QPDFObjectHandle::getArrayAsRectangle()
|
|||||||
return result;
|
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>
|
std::vector<QPDFObjectHandle>
|
||||||
QPDFObjectHandle::getArrayAsVector()
|
QPDFObjectHandle::getArrayAsVector()
|
||||||
{
|
{
|
||||||
@ -1930,12 +1966,31 @@ QPDFObjectHandle::newArray(Rectangle const& rect)
|
|||||||
return newArray(items);
|
return newArray(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
QPDFObjectHandle::newFromRectangle(Rectangle const& rect)
|
QPDFObjectHandle::newFromRectangle(Rectangle const& rect)
|
||||||
{
|
{
|
||||||
return newArray(rect);
|
return newArray(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPDFObjectHandle
|
||||||
|
QPDFObjectHandle::newFromMatrix(Matrix const& rect)
|
||||||
|
{
|
||||||
|
return newArray(rect);
|
||||||
|
}
|
||||||
|
|
||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
QPDFObjectHandle::newDictionary()
|
QPDFObjectHandle::newDictionary()
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef QPDFMATRIX_HH
|
#ifndef QPDFMATRIX_HH
|
||||||
#define QPDFMATRIX_HH
|
#define QPDFMATRIX_HH
|
||||||
|
|
||||||
|
#include <qpdf/QPDFObjectHandle.hh>
|
||||||
#include <qpdf/DLL.h>
|
#include <qpdf/DLL.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -12,6 +13,8 @@ class QPDFMatrix
|
|||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
QPDFMatrix(double a, double b, double c,
|
QPDFMatrix(double a, double b, double c,
|
||||||
double d, double e, double f);
|
double d, double e, double f);
|
||||||
|
QPDF_DLL
|
||||||
|
QPDFMatrix(QPDFObjectHandle::Matrix const&);
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
std::string unparse() const;
|
std::string unparse() const;
|
||||||
|
@ -50,6 +50,11 @@ int main()
|
|||||||
m.transform(240, 480, xp, yp);
|
m.transform(240, 480, xp, yp);
|
||||||
check_xy(xp, yp, "2582.50 4912.00");
|
check_xy(xp, yp, "2582.50 4912.00");
|
||||||
|
|
||||||
|
check(QPDFMatrix(
|
||||||
|
QPDFObjectHandle::parse(
|
||||||
|
"[3 1 4 1 5 9.26535]").getArrayAsMatrix()),
|
||||||
|
"3.00000 1.00000 4.00000 1.00000 5.00000 9.26535");
|
||||||
|
|
||||||
std::cout << "matrix tests done" << std::endl;
|
std::cout << "matrix tests done" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user