From cd04860b16d26acd5805ca3e0051e198c83fdb63 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 20 Aug 2022 13:13:39 +0200 Subject: [PATCH] Page rotation is now a part of pdf-tools --- cmds.cc | 22 +--------------------- pdf-tools.cc | 28 +++++++++++++++++++++++++++- pdf-tools.h | 1 + 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/cmds.cc b/cmds.cc index 7fad302..719058a 100644 --- a/cmds.cc +++ b/cmds.cc @@ -483,27 +483,7 @@ public: } page *process_page(page *p) override { - pdf_matrix m; - switch (deg) - { - case 0: - break; - case 90: - m.rotate_deg(-90); - m.shift(0, p->width); - break; - case 180: - m.rotate_deg(180); - m.shift(p->width, p->height); - break; - case 270: - m.rotate_deg(90); - m.shift(p->height, 0); - break; - default: - abort(); - } - return new xform_page(p, m); + return new xform_page(p, pdf_rotation_matrix(deg, p->width, p->height)); } }; diff --git a/pdf-tools.cc b/pdf-tools.cc index 0871637..0d74ca3 100644 --- a/pdf-tools.cc +++ b/pdf-tools.cc @@ -1,7 +1,7 @@ /* * Auxiliary functions for processing PDF files * - * (c) 2018 Martin Mares + * (c) 2018--2022 Martin Mares */ #include @@ -247,3 +247,29 @@ string pdf_coord(double x, uint digits) buf[--n] = 0; return buf; } + +/*** Rotation matrix construction ***/ + +pdf_matrix pdf_rotation_matrix(int deg, double width, double height) +{ + pdf_matrix m; + switch (deg) { + case 0: + break; + case 90: + m.rotate_deg(-90); + m.shift(0, width); + break; + case 180: + m.rotate_deg(180); + m.shift(width, height); + break; + case 270: + m.rotate_deg(90); + m.shift(height, 0); + break; + default: + abort(); + } + return m; +} diff --git a/pdf-tools.h b/pdf-tools.h index 46430f4..ea7b920 100644 --- a/pdf-tools.h +++ b/pdf-tools.h @@ -143,5 +143,6 @@ private: QPDFObjectHandle unicode_string(std::string s); QPDFObjectHandle page_to_xobject(QPDF *out, QPDFObjectHandle page); string pdf_coord(double x, uint digits=1); +pdf_matrix pdf_rotation_matrix(int deg, double width, double height); #endif -- 2.39.5