]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: In pwgtoraster() determine input format by ImagingBoundingBox
authorTill Kamppeter <till.kamppeter@gmail.com>
Fri, 25 Mar 2022 10:38:11 +0000 (11:38 +0100)
committerTill Kamppeter <till.kamppeter@gmail.com>
Fri, 25 Mar 2022 10:38:11 +0000 (11:38 +0100)
pwgtoraster() converts PWG or Apple Raster input to CUPS Raster output.

Before, it identified whether the input format is a supported one by
the "PwgRaster" in the MediaClass field of the CUPS Raster header data
structure, which is the case if the input file header contains this
"magic string" or if libcups creates a CUPS Raster Header for an Apple
Raster file it reads. Unfortunately, there are sources of PWG Raster
files omitting to put "PwgRaster" into the MediaClass field (like
MuPDF used in the mupdftoraster() filter function) and so
pwgtoraster() rejects the otherwise correct input as unsupported CUPS
Raster. So we need a new form of identifying PWG Raster.

In contrary to the CUPS Raster format the two supported formats have
no margin definition and contain a bitmap for the whole page including
the unprintable margins. Therefore the supported formats have se the
ImagingBoundingBox field to all-zero, which is illegal in CUPS Raster
as it spans a zero-size printing area. We now make use of this to
identify the input format and simply accept files with all-zero
ImagingBoundingBox and reject others, safely telling apart CUPS Raster
from PWG/Apple Raster.

Now mupdftoraster() and so MuPDF can be used with CUPS Raster drivers.

cupsfilters/pwgtoraster.c

index 48bcad1408f8731018b4e6fe27602eb590923aee..3e1a76659a91d449763acac2b88ea815d60abf0a 100644 (file)
@@ -1144,11 +1144,18 @@ static bool outPage(pwgtoraster_doc_t *doc,
     return (false);
   }
 
-  if (strcasecmp(doc->inheader.MediaClass, "PwgRaster") != 0)
+  if (doc->inheader.ImagingBoundingBox[0] ||
+      doc->inheader.ImagingBoundingBox[1] ||
+      doc->inheader.ImagingBoundingBox[2] ||
+      doc->inheader.ImagingBoundingBox[3])
   {
-    // Not PWG Raster
+    // Only CUPS Raster (not supported as input format by this filter
+    // function) defines margins and so an ImagingBoundingBox, for PWG
+    // Raster and Apple Raster (the input formats supported by this
+    // filter function) these values are all zero. With at least one not
+    // zero we consider the input not supported.
     log(ld, FILTER_LOGLEVEL_ERROR,
-       "pwgtoraster: Input page %d is not PWG Raster", pageNo);
+       "pwgtoraster: Input page %d is not PWG or Apple Raster", pageNo);
     return (false);
   }