]> 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>
Sun, 16 Jan 2022 00:09:09 +0000 (21:09 -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.

(cherry picked from commit 99d1cc62b74959f8465301ccc5bd29092cf987cc)

cupsfilters/ppdgenerator.c

index 05f1da83369efae3564557b730e5ca36e03695fd..b205f073fbbf6e54d16a7d0bde8a086a51a9997c 100644 (file)
@@ -2764,6 +2764,10 @@ ppdCreateFromIPP2(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, "urf-supported", IPP_TAG_KEYWORD)) ==
       NULL)
@@ -2782,6 +2786,17 @@ ppdCreateFromIPP2(char         *buffer,          /* I - Filename buffer */
       have_bi_level = 0,
       have_mono = 0;
 
+    if ((keyword = ippGetString(defattr, 0, NULL)) != NULL)
+    {
+      if (!strcmp(keyword, "bi-level"))
+        default_color = "FastGray";
+      else if (!strcmp(keyword, "monochrome") ||
+              !strcmp(keyword, "auto-monochrome"))
+        default_color = "Gray";
+      else
+        default_color = "RGB";
+    }
+
     cupsFilePrintf(fp, "*%% ColorModel from %s\n", ippGetName(attr));
 
     for (i = 0, count = ippGetCount(attr); i < count; i ++) {
@@ -2829,7 +2844,7 @@ ppdCreateFromIPP2(char         *buffer,          /* I - Filename buffer */
                       (human_readable2 ? human_readable2 :
                        _cupsLangString(lang, _("Grayscale"))));
 
-        if (!default_color || !strcmp(default_color, "FastGray"))
+        if (!default_color || (!defattr && !strcmp(default_color, "FastGray")))
          default_color = "Gray";
       } else if (!strcasecmp(keyword, "sgray_16") ||
                 !strncmp(keyword, "W8-16", 5) ||
@@ -2845,7 +2860,7 @@ ppdCreateFromIPP2(char         *buffer,          /* I - Filename buffer */
         cupsFilePrintf(fp, "*ColorModel Gray16/%s: \"<</cupsColorSpace 18/cupsBitsPerColor 16/cupsColorOrder 0/cupsCompression 0>>setpagedevice\"\n",
                       _cupsLangString(lang, _("Deep Gray (High Definition Grayscale)")));
 
-        if (!default_color || !strcmp(default_color, "FastGray"))
+       if (!default_color || (!defattr && !strcmp(default_color, "FastGray")))
          default_color = "Gray16";
       } else if (!strcasecmp(keyword, "srgb_8") ||
                 !strncmp(keyword, "SRGB24", 6) ||
@@ -2865,7 +2880,8 @@ ppdCreateFromIPP2(char         *buffer,          /* I - Filename buffer */
                       (human_readable2 ? human_readable2 :
                        _cupsLangString(lang, _("Color"))));
 
-       default_color = "RGB";
+       if (!defattr)
+         default_color = "RGB";
       } else if ((!strcasecmp(keyword, "srgb_16") ||
                  !strncmp(keyword, "SRGB48", 6)) &&
                 !ippContainsString(attr, "srgb_8")) {
@@ -2884,7 +2900,8 @@ ppdCreateFromIPP2(char         *buffer,          /* I - Filename buffer */
                       (human_readable2 ? human_readable2 :
                        _cupsLangString(lang, _("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... */
@@ -3016,7 +3033,7 @@ ppdCreateFromIPP2(char         *buffer,          /* I - Filename buffer */
     if (default_pagesize != NULL) {
       /* Here we are dealing with a cluster, if the default cluster color
          is not supplied we set it Gray*/
-      if (default_cluster_color != NULL) {
+      if (default_cluster_color != NULL && (!default_color || !defattr)) {
        default_color = default_cluster_color;
       } else
        default_color = "Gray";