2022-05-03 12:21:01 +00:00
|
|
|
#include <qpdf/assert_test.h>
|
|
|
|
|
2018-12-24 21:28:08 +00:00
|
|
|
#include <qpdf/QPDFMatrix.hh>
|
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
#include <iostream>
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
check(QPDFMatrix const& m, std::string const& exp)
|
2018-12-24 21:28:08 +00:00
|
|
|
{
|
|
|
|
std::string u = m.unparse();
|
2022-04-02 21:14:10 +00:00
|
|
|
if (u != exp) {
|
2018-12-24 21:28:08 +00:00
|
|
|
std::cout << "got " << u << ", wanted " << exp << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
check_xy(double x, double y, std::string const& exp)
|
2018-12-24 21:28:08 +00:00
|
|
|
{
|
2023-05-21 17:35:09 +00:00
|
|
|
std::string u = (QUtil::double_to_string(x, 2) + " " + QUtil::double_to_string(y, 2));
|
2022-04-02 21:14:10 +00:00
|
|
|
if (u != exp) {
|
2018-12-24 21:28:08 +00:00
|
|
|
std::cout << "got " << u << ", wanted " << exp << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
2023-05-21 17:35:09 +00:00
|
|
|
check_rect(QPDFObjectHandle::Rectangle const& r, double llx, double lly, double urx, double ury)
|
2019-01-26 21:48:41 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
std::string actual =
|
2023-05-21 17:35:09 +00:00
|
|
|
(QUtil::double_to_string(r.llx, 2) + " " + QUtil::double_to_string(r.lly, 2) + " " +
|
|
|
|
QUtil::double_to_string(r.urx, 2) + " " + QUtil::double_to_string(r.ury, 2));
|
2022-04-02 21:14:10 +00:00
|
|
|
std::string wanted =
|
2023-05-21 17:35:09 +00:00
|
|
|
(QUtil::double_to_string(llx, 2) + " " + QUtil::double_to_string(lly, 2) + " " +
|
|
|
|
QUtil::double_to_string(urx, 2) + " " + QUtil::double_to_string(ury, 2));
|
2022-04-02 21:14:10 +00:00
|
|
|
if (actual != wanted) {
|
2019-01-26 21:48:41 +00:00
|
|
|
std::cout << "got " << actual << ", wanted " << wanted << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
main()
|
2018-12-24 21:28:08 +00:00
|
|
|
{
|
|
|
|
QPDFMatrix m;
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "1 0 0 1 0 0");
|
2018-12-24 21:28:08 +00:00
|
|
|
m.translate(10, 20);
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "1 0 0 1 10 20");
|
2018-12-24 21:28:08 +00:00
|
|
|
m.scale(1.5, 2);
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "1.5 0 0 2 10 20");
|
2019-01-26 21:48:41 +00:00
|
|
|
double xp = 0;
|
|
|
|
double yp = 0;
|
|
|
|
m.transform(10, 100, xp, yp);
|
2021-02-12 08:44:12 +00:00
|
|
|
check_xy(xp, yp, "25 220");
|
2018-12-24 21:28:08 +00:00
|
|
|
m.translate(30, 40);
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "1.5 0 0 2 55 100");
|
2019-01-26 21:48:41 +00:00
|
|
|
m.transform(10, 100, xp, yp);
|
2021-02-12 08:44:12 +00:00
|
|
|
check_xy(xp, yp, "70 300");
|
2018-12-24 21:28:08 +00:00
|
|
|
m.concat(QPDFMatrix(1, 2, 3, 4, 5, 6));
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "1.5 4 4.5 8 62.5 112");
|
2018-12-24 21:28:08 +00:00
|
|
|
m.rotatex90(90);
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "4.5 8 -1.5 -4 62.5 112");
|
2018-12-24 21:28:08 +00:00
|
|
|
m.rotatex90(180);
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "-4.5 -8 1.5 4 62.5 112");
|
2018-12-24 21:28:08 +00:00
|
|
|
m.rotatex90(270);
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "-1.5 -4 -4.5 -8 62.5 112");
|
2018-12-24 21:28:08 +00:00
|
|
|
m.rotatex90(180);
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "1.5 4 4.5 8 62.5 112");
|
2018-12-24 21:28:08 +00:00
|
|
|
m.rotatex90(12345);
|
2021-02-12 08:44:12 +00:00
|
|
|
check(m, "1.5 4 4.5 8 62.5 112");
|
2018-12-24 21:28:08 +00:00
|
|
|
|
|
|
|
m.transform(240, 480, xp, yp);
|
2021-02-12 08:44:12 +00:00
|
|
|
check_xy(xp, yp, "2582.5 4912");
|
2018-12-24 21:28:08 +00:00
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
check(
|
2023-05-21 17:35:09 +00:00
|
|
|
QPDFMatrix(QPDFObjectHandle::parse("[3 1 4 1 5 9.26535]").getArrayAsMatrix()),
|
2022-04-02 21:14:10 +00:00
|
|
|
"3 1 4 1 5 9.26535");
|
2018-12-25 00:29:30 +00:00
|
|
|
|
2019-01-26 21:48:41 +00:00
|
|
|
m = QPDFMatrix();
|
|
|
|
m.rotatex90(90);
|
|
|
|
m.translate(200, -100);
|
2023-05-21 17:35:09 +00:00
|
|
|
check_rect(m.transformRectangle(QPDFObjectHandle::Rectangle(10, 20, 30, 50)), 50, 210, 80, 230);
|
2019-01-26 21:48:41 +00:00
|
|
|
|
2018-12-24 21:28:08 +00:00
|
|
|
std::cout << "matrix tests done" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|