diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-07-03 15:07:25 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-07-05 15:32:35 +0200 |
commit | 96cc776650a1845f4b3894c2311bee4d51d60f20 (patch) | |
tree | e3adedbb6577e9e0509b203c721c038f01019efe /source/fitz/geometry.c | |
parent | 2f698870f3ec77050694a9731a2a7ecc1b2962dd (diff) | |
download | mupdf-96cc776650a1845f4b3894c2311bee4d51d60f20.tar.xz |
Add fz_transform_page helper function.
Create a matrix that transforms a page with resolution and rotation,
and grid fits the resulting bounding box.
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; |