]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: rastertopclm() fails if no default resolution given
authorTill Kamppeter <till.kamppeter@gmail.com>
Mon, 28 Mar 2022 18:00:59 +0000 (20:00 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Mon, 28 Mar 2022 18:00:59 +0000 (20:00 +0200)
Some PCLm printers, especially the ones which support only one
resolution in PCLm ("pclm-source-resolution-supported" IPP attribute)
do not have the "pclm-source-resolution-default" IPP attribute. This
broke rastertopclm().

This is fixed now for both direct use of the printer IPP attributes or
use via an auto-generated PPD file. The missing default resolution is
simply filles with the first item of
"pclm-source-resolution-supported" then. If this item is also missing,
we error out on this printer/PPD file.

cupsfilters/rastertopdf.cpp

index 7326e8ff41f770750372ffecf44a839525e7c735..230e76bd6237f9ee8ed91af02a947a73ffe4614f 100644 (file)
@@ -1500,22 +1500,36 @@ rastertopdf(int inputfd,    /* I - File descriptor input stream */
       pdf.pclm_raster_back_side = attr->value;
     }
 
-    attr_name = (char *)"cupsPclmSourceResolutionDefault";
+    attr_name = (char *)"cupsPclmSourceResolutionSupported";
     if ((attr = ppdFindAttr(data->ppd, attr_name, NULL)) != NULL)
     {
       if (log) log(ld, FILTER_LOGLEVEL_DEBUG,
                   "rastertopdf: PPD PCLm attribute \"%s\" with value \"%s\"",
                   attr_name, attr->value);
-      pdf.pclm_source_resolution_default = attr->value;
+      pdf.pclm_source_resolution_supported = split_strings(attr->value, ",");
     }
 
-    attr_name = (char *)"cupsPclmSourceResolutionSupported";
+    attr_name = (char *)"cupsPclmSourceResolutionDefault";
     if ((attr = ppdFindAttr(data->ppd, attr_name, NULL)) != NULL)
     {
       if (log) log(ld, FILTER_LOGLEVEL_DEBUG,
                   "rastertopdf: PPD PCLm attribute \"%s\" with value \"%s\"",
                   attr_name, attr->value);
-      pdf.pclm_source_resolution_supported = split_strings(attr->value, ",");
+      pdf.pclm_source_resolution_default = attr->value;
+    }
+    else if (pdf.pclm_source_resolution_supported.size() > 0)
+    {
+      pdf.pclm_source_resolution_default =
+       pdf.pclm_source_resolution_supported[0];
+      if (log) log(ld, FILTER_LOGLEVEL_DEBUG,
+                  "rastertopdf: PPD PCLm attribute \"%s\" missing, taking first item of \"cupsPclmSourceResolutionSupported\" as default resolution",
+                  attr_name);
+    }
+    else
+    {
+      if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                  "rastertopdf: PCLm output: PPD file does not contain printer resolution information for PCLm.");
+      return 1;
     }
 
     attr_name = (char *)"cupsPclmCompressionMethodPreferred";
@@ -1607,24 +1621,38 @@ rastertopdf(int inputfd,    /* I - File descriptor input stream */
       pdf.pclm_raster_back_side = ippGetString(ipp_attr, 0, NULL);
     }
 
-    attr_name = (char *)"pclm-source-resolution-default";
+    attr_name = (char *)"pclm-source-resolution-supported";
     if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name, IPP_TAG_ZERO)) != NULL)
     {
       ippAttributeString(ipp_attr, buf, sizeof(buf));
       if (log) log(ld, FILTER_LOGLEVEL_DEBUG,
                   "rastertopdf: Printer PCLm attribute \"%s\" with value \"%s\"",
                   attr_name, buf);
-      pdf.pclm_source_resolution_default = buf;
+      pdf.pclm_source_resolution_supported = split_strings(buf, ",");
     }
 
-    attr_name = (char *)"pclm-source-resolution-supported";
+    attr_name = (char *)"pclm-source-resolution-default";
     if ((ipp_attr = ippFindAttribute(printer_attrs, attr_name, IPP_TAG_ZERO)) != NULL)
     {
       ippAttributeString(ipp_attr, buf, sizeof(buf));
       if (log) log(ld, FILTER_LOGLEVEL_DEBUG,
                   "rastertopdf: Printer PCLm attribute \"%s\" with value \"%s\"",
                   attr_name, buf);
-      pdf.pclm_source_resolution_supported = split_strings(buf, ",");
+      pdf.pclm_source_resolution_default = buf;
+    }
+    else if (pdf.pclm_source_resolution_supported.size() > 0)
+    {
+      pdf.pclm_source_resolution_default =
+       pdf.pclm_source_resolution_supported[0];
+      if (log) log(ld, FILTER_LOGLEVEL_DEBUG,
+                  "rastertopdf: Printer PCLm attribute \"%s\" missing, taking first item of \"pclm-source-resolution-supported\" as default resolution",
+                  attr_name);
+    }
+    else
+    {
+      if (log) log(ld, FILTER_LOGLEVEL_ERROR,
+                  "rastertopdf: PCLm output: Printer IPP attributes do not contain printer resolution information for PCLm.");
+      return 1;
     }
 
     attr_name = (char *)"pclm-compression-method-preferred";