better pdfload page size rounding

We were doing simple round down for page size with @scale param. But
this makes it very sensitive to rounding errors, so do rint() instead.

vips-resize() does rint() on the output size as well for the same
reason.

See https://github.com/libvips/libvips/issues/1297#issuecomment-487682785
This commit is contained in:
John Cupitt 2019-04-30 16:08:26 +01:00
parent 7326a409c6
commit 29d29533d4
2 changed files with 14 additions and 6 deletions

View File

@ -297,8 +297,12 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load )
poppler_page_get_size( pdf->page, &width, &height );
pdf->pages[i].left = 0;
pdf->pages[i].top = top;
pdf->pages[i].width = width * pdf->scale;
pdf->pages[i].height = height * pdf->scale;
/* We do round to nearest, in the same way that vips_resize()
* does round to nearest. Without this, things like
* shrink-on-load will break.
*/
pdf->pages[i].width = VIPS_RINT( width * pdf->scale );
pdf->pages[i].height = VIPS_RINT( height * pdf->scale );
if( pdf->pages[i].width > pdf->image.width )
pdf->image.width = pdf->pages[i].width;

View File

@ -341,10 +341,14 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load )
return( -1 );
pdf->pages[i].left = 0;
pdf->pages[i].top = top;
pdf->pages[i].width =
FPDF_GetPageWidth( pdf->page ) * pdf->scale;
pdf->pages[i].height =
FPDF_GetPageHeight( pdf->page ) * pdf->scale;
/* We do round to nearest, in the same way that vips_resize()
* does round to nearest. Without this, things like
* shrink-on-load will break.
*/
pdf->pages[i].width = VIPS_RINT(
FPDF_GetPageWidth( pdf->page ) * pdf->scale );
pdf->pages[i].height = VIPS_RINT(
FPDF_GetPageHeight( pdf->page ) * pdf->scale );
if( pdf->pages[i].width > pdf->image.width )
pdf->image.width = pdf->pages[i].width;