diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2015-10-31 18:32:49 +1030 |
---|---|---|
committer | Adrian Johnson <ajohnson@redneon.com> | 2015-10-31 18:32:49 +1030 |
commit | 0e14049bc5b85f8ae2e1a56bc09480a499343e49 (patch) | |
tree | 35facb83f014ee05d2fa061ed5a0c535e10cb159 /utils/pdftocairo.cc | |
parent | 3167964d70647d7b04e3ef8f415d5935990ecc9a (diff) |
pdftocairo: fix fit to page transformation
Testing with the test case in bug 87161 revealed some bugs.
Diffstat (limited to 'utils/pdftocairo.cc')
-rw-r--r-- | utils/pdftocairo.cc | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index 18fade4e..bdc6460f 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -447,8 +447,13 @@ static void getOutputSize(double page_w, double page_h, double *width, double *h *width = page_w; *height = page_h; } else { - *width = paperWidth; - *height = paperHeight; + if (page_w > page_h) { + *width = paperHeight; + *height = paperWidth; + } else { + *width = paperWidth; + *height = paperHeight; + } } } else { getCropSize(page_w * (x_resolution / 72.0), @@ -470,27 +475,20 @@ static void getFitToPageTransform(double page_w, double page_h, else scale = y_scale; + if (scale > 1.0 && !expand) + scale = 1.0; + if (scale < 1.0 && noShrink) + scale = 1.0; + cairo_matrix_init_identity (m); - if (scale > 1.0) { - // page is smaller than paper - if (expand) { - // expand to fit - cairo_matrix_scale (m, scale, scale); - } else if (!noCenter) { - // centre page - cairo_matrix_translate (m, (paper_w - page_w)/2, (paper_h - page_h)/2); - } else { - if (!svg) { - // move to PostScript origin - cairo_matrix_translate (m, 0, (paper_h - page_h)); - } - } - } else if (scale < 1.0) - // page is larger than paper - if (!noShrink) { - // shrink to fit - cairo_matrix_scale (m, scale, scale); - } + if (!noCenter) { + // centre page + cairo_matrix_translate (m, (paper_w - page_w*scale)/2, (paper_h - page_h*scale)/2); + } else if (!svg) { + // move to PostScript origin + cairo_matrix_translate (m, 0, (paper_h - page_h*scale)); + } + cairo_matrix_scale (m, scale, scale); } static cairo_status_t writeStream(void *closure, const unsigned char *data, unsigned int length) |