1
#include "qpdf_pdftopdf.h"
5
PageRect getBoxAsRect(QPDFObjectHandle box) // {{{
9
ret.left=box.getArrayItem(0).getNumericValue();
10
ret.bottom=box.getArrayItem(1).getNumericValue();
11
ret.right=box.getArrayItem(2).getNumericValue();
12
ret.top=box.getArrayItem(3).getNumericValue();
14
ret.width=ret.right-ret.left;
15
ret.height=ret.top-ret.bottom;
21
Rotation getRotate(QPDFObjectHandle page) // {{{
23
if (!page.hasKey("/Rotate")) {
26
double rot=page.getKey("/Rotate").getNumericValue();
27
if (rot==90.0) { // CW
28
return ROT_270; // CCW
29
} else if (rot==180.0) {
31
} else if (rot==270.0) {
40
double getUserUnit(QPDFObjectHandle page) // {{{
42
if (!page.hasKey("/UserUnit")) {
45
return page.getKey("/UserUnit").getNumericValue();
49
QPDFObjectHandle makeRotate(Rotation rot) // {{{
53
return QPDFObjectHandle::newNull();
55
return QPDFObjectHandle::newInteger(270); // CW
57
return QPDFObjectHandle::newInteger(180);
59
return QPDFObjectHandle::newInteger(90);
61
throw std::invalid_argument("Bad rotation");
66
#include "qpdf_tools.h"
68
QPDFObjectHandle getRectAsBox(const PageRect &rect) // {{{
70
return makeBox(rect.left,rect.bottom,rect.right,rect.top);
74
#include <qpdf/QUtil.hh>
76
Matrix::Matrix() // {{{
82
Matrix::Matrix(QPDFObjectHandle ar) // {{{
84
if (ar.getArrayNItems()!=6) {
85
throw std::runtime_error("Not a ctm matrix");
87
for (int iA=0;iA<6;iA++) {
88
ctm[iA]=ar.getArrayItem(iA).getNumericValue();
93
Matrix &Matrix::rotate(Rotation rot) // {{{
99
std::swap(ctm[0],ctm[2]);
100
std::swap(ctm[1],ctm[3]);
109
std::swap(ctm[0],ctm[2]);
110
std::swap(ctm[1],ctm[3]);
122
Matrix &Matrix::rotate_move(Rotation rot,double width,double height) // {{{
132
translate(width,height);
142
Matrix &Matrix::rotate(double rad) // {{{
148
tmp.ctm[2]=-sin(rad);
155
Matrix &Matrix::translate(double tx,double ty) // {{{
157
ctm[4]+=ctm[0]*tx+ctm[2]*ty;
158
ctm[5]+=ctm[1]*tx+ctm[3]*ty;
163
Matrix &Matrix::scale(double sx,double sy) // {{{
173
Matrix &Matrix::operator*=(const Matrix &rhs) // {{{
176
std::copy(ctm,ctm+6,tmp);
178
ctm[0] = tmp[0]*rhs.ctm[0] + tmp[2]*rhs.ctm[1];
179
ctm[1] = tmp[1]*rhs.ctm[0] + tmp[3]*rhs.ctm[1];
181
ctm[2] = tmp[0]*rhs.ctm[2] + tmp[2]*rhs.ctm[3];
182
ctm[3] = tmp[1]*rhs.ctm[2] + tmp[3]*rhs.ctm[3];
184
ctm[4] = tmp[0]*rhs.ctm[4] + tmp[2]*rhs.ctm[5] + tmp[4];
185
ctm[5] = tmp[1]*rhs.ctm[4] + tmp[3]*rhs.ctm[5] + tmp[5];
191
QPDFObjectHandle Matrix::get() const // {{{
193
QPDFObjectHandle ret=QPDFObjectHandle::newArray();
194
ret.appendItem(QPDFObjectHandle::newReal(ctm[0]));
195
ret.appendItem(QPDFObjectHandle::newReal(ctm[1]));
196
ret.appendItem(QPDFObjectHandle::newReal(ctm[2]));
197
ret.appendItem(QPDFObjectHandle::newReal(ctm[3]));
198
ret.appendItem(QPDFObjectHandle::newReal(ctm[4]));
199
ret.appendItem(QPDFObjectHandle::newReal(ctm[5]));
204
std::string Matrix::get_string() const // {{{
207
ret.append(QUtil::double_to_string(ctm[0]));
209
ret.append(QUtil::double_to_string(ctm[1]));
211
ret.append(QUtil::double_to_string(ctm[2]));
213
ret.append(QUtil::double_to_string(ctm[3]));
215
ret.append(QUtil::double_to_string(ctm[4]));
217
ret.append(QUtil::double_to_string(ctm[5]));