From 92989bb302b58ff11d0cd8d6f7755efc58f9734e Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Mon, 14 Feb 2022 22:03:12 -0300 Subject: [PATCH] imagetoraster, imagetopdf: Fixed "print-scaling=none" In the imageto...()s fixed the print-scaling=none (crop-to-fit) mode, which prints the image in its original size (based on PPI resolution stored in the image file or on 200 dpi resolution, which is the standard resolution for shipping labels). Also use crop-to-fit always when requested, do not fall back to fit-to-page when the image is significantly larger or smaller than the page. (manually backported from commit cb2737b5683adfbe5cc25bada323f43cc1ca2329) --- NEWS | 4 +++ filter/imagetopdf.c | 66 +++++++++++++++++++------------------- filter/imagetoraster.c | 73 +++++++++++++++++++++--------------------- 3 files changed, 73 insertions(+), 70 deletions(-) diff --git a/NEWS b/NEWS index c6f770cc4..1cf3bca68 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,10 @@ NEWS - OpenPrinting CUPS Filters v1.28.11 - 2022-01-15 CHANGES IN V1.28.12 + - imagetoraster, imagetopdf: Fixed the "print-scaling=none" + (crop-to-fit) mode, also use crop-to-fit always when + requested, do not fall back to fit-to-page when the image + size differs significantly from the page size (Issue #362). - libcupsfilters: Changed the default PPI resolution for images as input files from 128 to 200 (Pull request #446). - implicitclass: Do not check availability of "gs" and diff --git a/filter/imagetopdf.c b/filter/imagetopdf.c index cc72cea02..0ebf09807 100644 --- a/filter/imagetopdf.c +++ b/filter/imagetopdf.c @@ -22,6 +22,7 @@ #include "common.h" #include #include +#include #include #include @@ -1113,44 +1114,43 @@ main(int argc, /* I - Number of command-line arguments */ cupsImageClose(img); img = img2; } - else { + else + { float final_w=w,final_h=h; - if(final_w>pw) - { - final_w = pw; - } - if(final_h>ph) + if (w > pw * img->xppi / 72.0) + final_w = pw * img->xppi / 72.0; + if (h > ph * img->yppi / 72.0) + final_h = ph * img->yppi / 72.0; + float posw=(w-final_w)/2,posh=(h-final_h)/2; + posw = (1+XPosition)*posw; + posh = (1-YPosition)*posh; + cups_image_t *img2 = cupsImageCrop(img,posw,posh,final_w,final_h); + cupsImageClose(img); + img = img2; + if(flag==4) { - final_h = ph; + PageBottom += (PageTop - PageBottom - + final_w * 72.0 / img->xppi) / 2; + PageTop = PageBottom + + final_w * 72.0 / img->xppi; + PageLeft += (PageRight - PageLeft - + final_h * 72.0 / img->yppi) / 2; + PageRight = PageLeft + + final_h * 72.0 / img->yppi; } - if((fabs(final_w-w)>0.5*w)||(fabs(final_h-h)>0.5*h)) + else { - fprintf(stderr,"[DEBUG]: Ignoring crop-to-fit option!\n"); - cropfit=0; + PageBottom += (PageTop - PageBottom - + final_h * 72.0 / img->yppi) / 2; + PageTop = PageBottom + + final_h * 72.0 / img->yppi; + PageLeft += (PageRight - PageLeft - + final_w * 72.0 / img->xppi) / 2; + PageRight = PageLeft + + final_w * 72.0 / img->xppi; } - else{ - float posw=(w-final_w)/2,posh=(h-final_h)/2; - posw = (1+XPosition)*posw; - posh = (1-YPosition)*posh; - cups_image_t *img2 = cupsImageCrop(img,posw,posh,final_w,final_h); - cupsImageClose(img); - img = img2; - if(flag==4) - { - PageBottom+=(PageTop-PageBottom-final_w)/2; - PageTop = PageBottom+final_w; - PageLeft +=(PageRight-PageLeft-final_h)/2; - PageRight = PageLeft+final_h; - } - else{ - PageBottom+=(PageTop-PageBottom-final_h)/2; - PageTop = PageBottom+final_h; - PageLeft +=(PageRight-PageLeft-final_w)/2; - PageRight = PageLeft+final_w; - } - if(PageBottom<0) PageBottom = 0; - if(PageLeft<0) PageLeft = 0; - } + if(PageBottom<0) PageBottom = 0; + if(PageLeft<0) PageLeft = 0; } } diff --git a/filter/imagetoraster.c b/filter/imagetoraster.c index aa8422b72..a63ac1ce8 100644 --- a/filter/imagetoraster.c +++ b/filter/imagetoraster.c @@ -790,45 +790,44 @@ main(int argc, /* I - Number of command-line arguments */ cupsImageClose(img); img = img2; } - else { + else + { float final_w=w,final_h=h; - if(w>pw) - { - final_w = pw; - } - if(h>ph) + if (w > pw * img->xppi / 72.0) + final_w = pw * img->xppi / 72.0; + if (h > ph * img->yppi / 72.0) + final_h = ph * img->yppi / 72.0; + float posw=(w-final_w)/2,posh=(h-final_h)/2; + posw = (1+XPosition)*posw; + posh = (1-YPosition)*posh; + cups_image_t *img2 = cupsImageCrop(img,posw,posh,final_w,final_h); + cupsImageClose(img); + img = img2; + if(flag==4) { - final_h = ph; - } - if((fabs(final_w-w)>0.5*w)||(fabs(final_h-h)>0.5*h)) - { - fprintf(stderr,"[DEBUG]: Ignoring crop-to-fit option!\n"); - cropfit=0; - } - else{ - float posw=(w-final_w)/2,posh=(h-final_h)/2; - posw = (1+XPosition)*posw; - posh = (1-YPosition)*posh; - cups_image_t *img2 = cupsImageCrop(img,posw,posh,final_w,final_h); - cupsImageClose(img); - img = img2; - if(flag==4) - { - PageBottom+=(PageTop-PageBottom-final_w)/2; - PageTop = PageBottom+final_w; - PageLeft +=(PageRight-PageLeft-final_h)/2; - PageRight = PageLeft+final_h; - } - else{ - PageBottom+=(PageTop-PageBottom-final_h)/2; - PageTop = PageBottom+final_h; - PageLeft +=(PageRight-PageLeft-final_w)/2; - PageRight = PageLeft+final_w; - } - if(PageBottom<0) PageBottom = 0; - if(PageLeft<0) PageLeft = 0; - } - } + PageBottom += (PageTop - PageBottom - + final_w * 72.0 / img->xppi) / 2; + PageTop = PageBottom + + final_w * 72.0 / img->xppi; + PageLeft += (PageRight - PageLeft - + final_h * 72.0 / img->yppi) / 2; + PageRight = PageLeft + + final_h * 72.0 / img->yppi; + } + else + { + PageBottom += (PageTop - PageBottom - + final_h * 72.0 / img->yppi) / 2; + PageTop = PageBottom + + final_h * 72.0 / img->yppi; + PageLeft += (PageRight - PageLeft - + final_w * 72.0 / img->xppi) / 2; + PageRight = PageLeft + + final_w * 72.0 / img->xppi; + } + if(PageBottom<0) PageBottom = 0; + if(PageLeft<0) PageLeft = 0; + } } } if (argc == 6) -- 2.47.3