diff options
Diffstat (limited to 'source/fitz/geometry.c')
-rw-r--r-- | source/fitz/geometry.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/fitz/geometry.c b/source/fitz/geometry.c index e31a9435..96a46102 100644 --- a/source/fitz/geometry.c +++ b/source/fitz/geometry.c @@ -211,6 +211,29 @@ fz_pre_translate(fz_matrix m, float tx, float ty) } fz_matrix +fz_transform_page(fz_rect mediabox, float resolution, float rotate) +{ + float user_w, user_h, pixel_w, pixel_h; + fz_rect pixel_box; + fz_matrix matrix; + + /* Adjust scaling factors to cover whole pixels */ + user_w = mediabox.x1 - mediabox.x0; + user_h = mediabox.y1 - mediabox.y0; + pixel_w = floorf(user_w * resolution / 72 + 0.5f); + pixel_h = floorf(user_h * resolution / 72 + 0.5f); + + matrix = fz_pre_rotate(fz_scale(pixel_w / user_w, pixel_h / user_h), rotate); + + /* Adjust the page origin to sit at 0,0 after rotation */ + pixel_box = fz_transform_rect(mediabox, matrix); + matrix.e -= pixel_box.x0; + matrix.f -= pixel_box.y0; + + return matrix; +} + +fz_matrix fz_invert_matrix(fz_matrix src) { float a = src.a; |