X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=pdf-tools.h;h=46430f4bd426d9f9835b5db7b6ba1ec6127dfa14;hb=ecef4671aafd32e3a00a834cdafa2c5af4bbb33c;hp=a4004d3d8c2e03dccdf9beed4a42bc4202d15875;hpb=0067f5b7bd14a37261df30bfcd5ca71ed2c1a38a;p=paperjam.git diff --git a/pdf-tools.h b/pdf-tools.h index a4004d3..46430f4 100644 --- a/pdf-tools.h +++ b/pdf-tools.h @@ -14,24 +14,10 @@ /*** Basic macros and constants ***/ -#define UNUSED __attribute__((unused)) -#define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z))) -#define NONRET __attribute__((noreturn)) - #define A4_WIDTH 595 #define A4_HEIGHT 842 static const double mm = 72/25.4; -/*** Messages ***/ - -void debug(const char *msg, ...) FORMAT_CHECK(printf, 1, 2); -void warn(const char *msg, ...) FORMAT_CHECK(printf, 1, 2); -void die(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET; -void bad(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET; - -extern int debug_mode; -extern int debug_indent; - /*** Transformation matrices ***/ struct pdf_matrix { @@ -65,6 +51,13 @@ struct pdf_matrix { m[5] = f; } + void apply(double *px, double *py) + { + double x=*px, y=*py; + *px = m[0]*x + m[2]*y + m[4]; + *py = m[1]*x + m[3]*y + m[5]; + } + // A*B is a matrix which transforms first by A and then by B pdf_matrix operator *(pdf_matrix y) { @@ -130,16 +123,17 @@ struct BBox { x_min = 0, x_max = x; y_min = 0, y_max = y; } - BBox(QPDFObjectHandle box) { - if (!parse(box)) { - warn("Invalid bounding box, falling back to A4"); - x_min = 0, x_max = A4_WIDTH; - y_min = 0, y_max = A4_HEIGHT; - } - } + BBox(QPDFObjectHandle box); QPDFObjectHandle to_array(); + string to_rect(); double width() { return x_max - x_min; } double height() { return y_max - y_min; } + void transform(pdf_matrix &m); + BBox transformed(pdf_matrix &m); + void enlarge(double by); + BBox enlarged(double by); + void join(BBox &with); + void intersect(BBox &with); private: bool parse(QPDFObjectHandle h); }; @@ -148,6 +142,6 @@ private: QPDFObjectHandle unicode_string(std::string s); QPDFObjectHandle page_to_xobject(QPDF *out, QPDFObjectHandle page); +string pdf_coord(double x, uint digits=1); #endif -