]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Let PPD generator take default ColorModel from printer
authorTill Kamppeter <till.kamppeter@gmail.com>
Sat, 15 Jan 2022 18:40:43 +0000 (15:40 -0300)
committerTill Kamppeter <till.kamppeter@gmail.com>
Sat, 15 Jan 2022 18:40:43 +0000 (15:40 -0300)
Instead of selecting the "best" available color mode as default for
the PPD file generated from the response to the get-printer-attributes
IPP request we use the printer default according to the IPP attributes
(print-color-mode-default).

This way on can simply change the default on a network printer's web
interface or on a remote CUPS printer and clients using cups-browsed
or the "driverless" utility respect the change.

This solves https://github.com/OpenPrinting/cups/issues/277, together
with the changes done on CUPS for this issue.

cupsfilters/ppdgenerator.c

index c5175555609fe90c1f74b93c11b6ed07c9e6f1d7..c808b508f934558e206abfc1acb067cc9c303a4a 100644 (file)
@@ -2526,6 +2526,10 @@ cfCreatePPDFromIPP2(char         *buffer,          /* I - Filename buffer */
  /*
   * ColorModel...
   */
+  if ((defattr = ippFindAttribute(response, "print-color-mode-default",
+                                 IPP_TAG_KEYWORD)) == NULL)
+    defattr = ippFindAttribute(response, "output-mode-default",
+                              IPP_TAG_KEYWORD);
 
   if ((attr = ippFindAttribute(response, "print-color-mode-supported",
                               IPP_TAG_KEYWORD)) == NULL)
@@ -2538,6 +2542,22 @@ cfCreatePPDFromIPP2(char         *buffer,          /* I - Filename buffer */
     const char *default_color = NULL;  /* Default */
     int first_choice = 1;
 
+    if ((keyword = ippGetString(defattr, 0, NULL)) != NULL)
+    {
+      if (!strcmp(keyword, "bi-level"))
+        default_color = "FastGray";
+      else if (!strcmp(keyword, "process-bi-level"))
+        default_color = "ProcessFastGray";
+      else if (!strcmp(keyword, "auto-monochrome"))
+        default_color = "AutoGray";
+      else if (!strcmp(keyword, "monochrome"))
+        default_color = "Gray";
+      else if (!strcmp(keyword, "process-monochrome"))
+        default_color = "ProcessGray";
+      else
+        default_color = "RGB";
+    }
+
     cupsFilePrintf(fp, "*%% ColorModel from %s\n", ippGetName(attr));
 
     for (i = 0, count = ippGetCount(attr); i < count; i ++) {
@@ -2599,7 +2619,7 @@ cfCreatePPDFromIPP2(char         *buffer,          /* I - Filename buffer */
         cupsFilePrintf(fp, "*ColorModel Gray/%s: \"\"\n",
                       (human_readable2 ? human_readable2 : "Monochrome"));
 
-        if (!default_color || !strcmp(default_color, "FastGray"))
+        if (!default_color || (!defattr && !strcmp(default_color, "FastGray")))
          default_color = "Gray";
       } else if (!strcmp(keyword, "process-monochrome")) {
         if (first_choice) {
@@ -2630,7 +2650,8 @@ cfCreatePPDFromIPP2(char         *buffer,          /* I - Filename buffer */
         cupsFilePrintf(fp, "*ColorModel RGB/%s: \"\"\n",
                       (human_readable2 ? human_readable2 : "Color"));
 
-       default_color = "RGB";
+        if (!default_color)
+         default_color = "RGB";
 
        /* Apparently some printers only advertise color support, so make sure
            we also do grayscale for these printers... */