]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
imagetoraster, imagetopdf: Fixed "print-scaling=none"
authorTill Kamppeter <till.kamppeter@gmail.com>
Tue, 15 Feb 2022 01:03:12 +0000 (22:03 -0300)
committerTill Kamppeter <till.kamppeter@gmail.com>
Tue, 15 Feb 2022 01:03:12 +0000 (22:03 -0300)
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
filter/imagetopdf.c
filter/imagetoraster.c

diff --git a/NEWS b/NEWS
index c6f770cc43fba933b0382acae07aa176c1df6d25..1cf3bca68e2556758e051205cf79c20225f4e2e9 100644 (file)
--- 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
index cc72cea027587a658f9b3defdabdb5e0f1315dee..0ebf0980791df97b6b6d072d13fc903d71d4ca9c 100644 (file)
@@ -22,6 +22,7 @@
 #include "common.h"
 #include <cupsfilters/image.h>
 #include <cupsfilters/raster.h>
+#include <cupsfilters/image-private.h>
 #include <math.h>
 #include <ctype.h>
 
@@ -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;
     }
   }
 
index aa8422b725d37281d43fdb07ebf6fa12424a6379..a63ac1ce8c84cc048268c37da1bcf504ca5e33eb 100644 (file)
@@ -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)