public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Zdenek Dohnal <zdohnal@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/libcupsfilters] f45: re-introduce option autoprint to fix scaling issues (fedora#2582037)
Date: Thu, 26 Nov 2026 13:39:45 GMT	[thread overview]
Message-ID: <179570038548.1.10644363835946862097.rpms-libcupsfilters-af67c5a9415a@fedoraproject.org> (raw)

A new commit has been pushed.

Repo   : rpms/libcupsfilters
Branch : f45
Commit : af67c5a9415a5a403ddd51666574c1257fa1f6bd
Author : Zdenek Dohnal <zdohnal@redhat.com>
Date   : 2026-11-25T18:58:21+01:00
Stats  : +220/-0 in 2 file(s)
URL    : https://src.fedoraproject.org/rpms/libcupsfilters/c/af67c5a9415a5a403ddd51666574c1257fa1f6bd?branch=f45

Log:
re-introduce option autoprint to fix scaling issues (fedora#2582037)

---
diff --git a/0001-pdftopdf-restore-print-scaling-auto-auto-fit-autopri.patch b/0001-pdftopdf-restore-print-scaling-auto-auto-fit-autopri.patch
new file mode 100644
index 0000000..3d0b9e3
--- /dev/null
+++ b/0001-pdftopdf-restore-print-scaling-auto-auto-fit-autopri.patch
@@ -0,0 +1,217 @@
+From 09f9b62e5488e93970333dd1d214438db0aac51b Mon Sep 17 00:00:00 2001
+From: Zdenek Dohnal <zdohnal@redhat.com>
+Date: Wed, 25 Nov 2026 18:03:05 +0100
+Subject: [PATCH] pdftopdf: restore print-scaling=auto/auto-fit autoprint
+ behavior of 2.1.x
+
+The PDFio-based rewrite of pdftopdf treated print-scaling=auto and
+print-scaling=auto-fit the same as print-scaling=fit, scaling every
+page into the printer's printable area whenever a page size got
+requested. Together with print-scaling=auto being the default
+(1973c4a9) this shrunk every job by the ratio of printable area to
+media size (around 95% on a printer with 4.8mm hardware margins),
+breaking exact-size printing like labels.
+
+Restore the decision logic of the QPDF-based pdftopdf of
+libcupsfilters 2.1.x: when the pages of the document fit on the
+output media (2% tolerance, either orientation) and the client did
+not request exact attribute fidelity, keep the pages at 100%,
+centered on the sheet, cropped by the printer's hardware margins.
+Only scale to fit (or fill, when the printer has no margins
+defined) when the document is actually too large for the media or
+ipp-attribute-fidelity is set. Like in 2.1.x, only the pages which
+actually get printed (after applying the page ranges) count for the
+too-large decision.
+
+Fixes #304
+Fixes #339
+
+Co-Authored-By: Claude Code <noreply@anthropic.com>
+---
+ Makefile.am                                   |   4 +
+ cupsfilters/pdftopdf-private.h                |   3 +
+ cupsfilters/pdftopdf.c                        | 120 +++++++++++++++++-
+ .../test-pdftopdf-print-scaling-auto-mixed.c  |  65 ++++++++++
+ .../test-pdftopdf-print-scaling-auto.c        | 115 +++++++++++++++++
+ .../test-pdftopdf-print-scaling-auto.sh       | 120 ++++++++++++++++++
+ 6 files changed, 424 insertions(+), 3 deletions(-)
+ create mode 100644 cupsfilters/test-pdftopdf-print-scaling-auto-mixed.c
+ create mode 100644 cupsfilters/test-pdftopdf-print-scaling-auto.c
+ create mode 100755 cupsfilters/test-pdftopdf-print-scaling-auto.sh
+
+diff --git a/cupsfilters/pdftopdf-private.h b/cupsfilters/pdftopdf-private.h
+index 030d34a2..439c0b5d 100644
+--- a/cupsfilters/pdftopdf-private.h
++++ b/cupsfilters/pdftopdf-private.h
+@@ -100,6 +100,9 @@ typedef struct xform_prepare_s          // Preparation data
+   bool 		has_form;    		// does PDF have Acroform(is flattening required?)
+   bool 		has_annotations;   	// does PDF have annotations in Acroform(is flattenning required?)
+   bool 		needAppearances;	// does PDF need appearances?
++  bool          auto_cropfit;         // print-scaling=auto/auto-fit resolved to
++                                      // no scaling: center pages on the media
++                                      // and crop, do not fast-copy
+   char          **annotation_contents; // Annotation contents to write to page streams
+   size_t        num_annotations;       // Number of annotations to write
+ } xform_prepare_t;
+diff --git a/cupsfilters/pdftopdf.c b/cupsfilters/pdftopdf.c
+index 1a924514..8ef77e1f 100644
+--- a/cupsfilters/pdftopdf.c
++++ b/cupsfilters/pdftopdf.c
+@@ -355,6 +355,39 @@ page_get_rect(pdfio_obj_t  *page,       // I - Page object
+   return (false);
+ }
+ 
++//
++// 'page_larger_than_media()' - Is a page too large for the output media?
++//
++// This uses 2% of tolerance and checks both orientations, like the
++// QPDF-based pdftopdf filter of libcupsfilters 2.1.x did for the
++// "print-scaling=auto"/"auto-fit" decision...
++//
++
++static bool				// O - `true` if the page is too large
++page_larger_than_media(
++    pdfio_file_t *pdf,			// I - PDF file
++    size_t       pg,			// I - Page number, 0-based
++    pdfio_rect_t *media)		// I - Output media box
++{
++  pdfio_obj_t	*page;			// Page object
++  pdfio_rect_t	rect;			// Page rectangle
++  double	w, h;			// Page dimensions, 2% tolerance
++
++
++  if ((page = pdfioFileGetPage(pdf, pg)) == NULL)
++    return (false);
++
++  if (!page_get_rect(page, "CropBox", &rect) &&
++      !page_get_rect(page, "MediaBox", &rect))
++    return (false);
++
++  w = (rect.x2 - rect.x1) * 100.0 / 102.0;
++  h = (rect.y2 - rect.y1) * 100.0 / 102.0;
++
++  return ((w > (media->x2 - media->x1) || h > (media->y2 - media->y1)) &&
++	  (h > (media->x2 - media->x1) || w > (media->y2 - media->y1)));
++}
++
+ 
+ //
+ // 'page_get_rotate()' - Look up the inheritable /Rotate attribute for a page,
+@@ -2865,6 +2898,9 @@ prepare_documents(
+   int			page;		// Current page number
+   bool			duplex = !strncmp(options->sides, "two-sided-", 10);
+ 					// Doing two-sided printing?
++  bool			document_large = false;
++					// Any input page larger than the media?
++  const char		*val;		// Option value
+   pdfio_file_t *flattened_pdf;
+   char          flattened_pdf_file[1024];
+   int		outfd;			// Output temporary file
+@@ -3092,6 +3128,32 @@ prepare_documents(
+       page ++;
+     }
+ 
++    // Check whether any of the pages that actually get printed is too
++    // large for the output media, for the print-scaling=auto/auto-fit
++    // decision after the document loop, like the QPDF-based pdftopdf of
++    // libcupsfilters 2.1.x did. Only the pages selected by the page
++    // ranges count, and the check is not needed when the scaling mode
++    // is fixed anyway...
++    if (options->print_scaling == CF_FILTER_SCALING_AUTO ||
++	options->print_scaling == CF_FILTER_SCALING_AUTO_FIT)
++    {
++      size_t	num_pages = (size_t)pdfioFileGetNumPages(d->pdf);
++					// Number of pages in document
++      for (size_t pg = 0; pg < num_pages; pg ++)
++      {
++	int	docpage;		// Page number for the page range check
++
++	if (options->multiple_document_handling < CF_FILTER_HANDLING_SINGLE_DOCUMENT)
++	  docpage = (int)pg + 1;
++	else
++	  docpage = d->first_page + (int)pg;
++
++	if (cfFilterOptionsIsPageInRange(options, docpage) &&
++	    page_larger_than_media(d->pdf, pg, &p.media))
++	  document_large = true;
++      }
++    }
++
+     if ((d->last_page & 1) && duplex && options->multiple_document_handling != CF_FILTER_HANDLING_SINGLE_DOCUMENT)
+     {
+       d->last_page ++;
+@@ -3104,6 +3166,57 @@ prepare_documents(
+     p.num_inpages += d->num_pages;
+   }
+ 
++  // Resolve "print-scaling=auto" and "print-scaling=auto-fit" like the
++  // QPDF-based pdftopdf filter of libcupsfilters 2.1.x did: when the
++  // pages of the document fit on the output media (with 2% tolerance,
++  // in either orientation) and the client did not request exact
++  // attribute fidelity, keep them at their original size, only centered
++  // on the sheet, and let the printer's hardware margins crop what
++  // sticks out. Only scale the pages when the document is too large
++  // for the media, or to fill the page when the printer's printable
++  // area is the whole page...
++  if (options->print_scaling == CF_FILTER_SCALING_AUTO ||
++      options->print_scaling == CF_FILTER_SCALING_AUTO_FIT)
++  {
++    bool	margin_defined =		// Printable area smaller than media?
++		  (p.crop.x1 > 0.0 || p.crop.y1 > 0.0 ||
++		   p.crop.x2 < p.media.x2 || p.crop.y2 < p.media.y2);
++    bool	fidelity =		// Exact attribute fidelity requested?
++		  ((val = cupsGetOption("ipp-attribute-fidelity",
++					num_job_options, job_options)) != NULL &&
++		   is_true(val));
++
++    if (fidelity || document_large)
++    {
++      if (options->print_scaling == CF_FILTER_SCALING_AUTO && !margin_defined)
++	options->print_scaling = CF_FILTER_SCALING_FILL;
++      else
++	options->print_scaling = CF_FILTER_SCALING_FIT;
++
++      if (p.logfunc)
++	p.logfunc(p.logdata, CF_LOGLEVEL_DEBUG,
++		  "cfFilterPDFToPDF: %s, scaling pages to %s the %s.",
++		  fidelity ?
++		      "Exact attribute fidelity requested" :
++		      "Pages too large for output page size",
++		  options->print_scaling == CF_FILTER_SCALING_FILL ? "fill" : "fit",
++		  options->print_scaling == CF_FILTER_SCALING_FILL ? "page" : "printable area");
++    }
++    else
++    {
++      // Do not scale, only center the pages on the sheet and let the
++      // printer's hardware margins crop (cropfit). This must not take
++      // the fast-copy path below, as there the pages would keep their
++      // own size instead of getting centered on the output media...
++      options->print_scaling = CF_FILTER_SCALING_NONE;
++      p.auto_cropfit = true;
++
++      if (p.logfunc)
++	p.logfunc(p.logdata, CF_LOGLEVEL_DEBUG,
++		  "cfFilterPDFToPDF: Pages fit output page size, no scaling, centering, crop if needed.");
++    }
++  }
++
+   // When doing N-up or booklet printing, the default is to scale to fit unless
+   // fill is explicitly chosen...
+   if (p.num_layout > 1 && options->print_scaling != CF_FILTER_SCALING_FILL)
+@@ -3163,9 +3276,10 @@ prepare_documents(
+       outdir  = 1;
+     }
+ 
+-    if (p.num_layout == 1 && 
+-        options->print_scaling == CF_FILTER_SCALING_NONE && 
+-	strcasecmp(outformat, "image/pwg-raster") && 
++    if (p.num_layout == 1 &&
++        options->print_scaling == CF_FILTER_SCALING_NONE &&
++	!p.auto_cropfit &&
++	strcasecmp(outformat, "image/pwg-raster") &&
+ 	strcasecmp(outformat, "image/urf") && 
+ 	!strcmp(options->page_border, "none") && 
+ 	!options->mirror && 
+-- 
+2.56.1
+

diff --git a/libcupsfilters.spec b/libcupsfilters.spec
index 7ac4a7d..4b7f99e 100644
--- a/libcupsfilters.spec
+++ b/libcupsfilters.spec
@@ -18,6 +18,8 @@ License: Apache-2.0 WITH LLVM-exception
 URL: https://github.com/OpenPrinting/libcupsfilters
 Source0: %{URL}/archive/%{commit}/%{name}-%{shortcommit}.tar.gz
 
+Patch001: 0001-pdftopdf-restore-print-scaling-auto-auto-fit-autopri.patch
+
 
 # for generating configure and Makefile scripts in autogen.h
 BuildRequires: autoconf
@@ -204,6 +206,7 @@ rm -f %{buildroot}%{_pkgdocdir}/{LICENSE,COPYING,NOTICE}
 %changelog
 * Wed Nov 25 2026 Zdenek Dohnal <zdohnal@redhat.com> - 1:2.2.1^20261123.3f08cf9-1
 - rebase to the newer snapshot
+- re-introduce option autoprint to fix scaling issues (fedora#2582037)
 
 * Wed Nov 18 2026 Zdenek Dohnal <zdohnal@redhat.com> - 1:2.2.1^20261118.3bf1892-1
 - migrate to latest upstream git snapshot (fedora#2579625, fedora#2573692, fedora#2573573, fedora#2573434, fedora#2568640)

                 reply	other threads:[~2026-11-26 13:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179570038548.1.10644363835946862097.rpms-libcupsfilters-af67c5a9415a@fedoraproject.org \
    --to=zdohnal@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox