]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix print-color-mode-default support so that it can be configured and defaults
authorMichael R Sweet <michael.r.sweet@gmail.com>
Wed, 12 Jan 2022 13:44:01 +0000 (08:44 -0500)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Wed, 12 Jan 2022 13:44:01 +0000 (08:44 -0500)
to the printer's value (Issue #277)

CHANGES.md
cups/ppd-cache.c
scheduler/printers.c

index ccee6c8f541198efbf149949c31979a047dccd2a..6bc64396dd57b8f3adf8644142481f256cd417f8 100644 (file)
@@ -4,6 +4,8 @@ CHANGES - OpenPrinting CUPS 2.4.0 - 2021-11-29
 Changes in CUPS v2.4.1 (TBA)
 ----------------------------
 
+- The default color mode now is now configurable and defaults to the printer's
+  reported default mode (Issue #277)
 - Configuration script now checks linking for -Wl,-pie flags (Issue #303)
 - Fixed memory leaks - in testi18n (Issue #313), in `cups_enum_dests()`
   (Issue #317), in `_cupsEncodeOption()` and `http_tls_upgrade()` (Issue #322)
index 786c66b9c76be06e686bdf4ea92a7b56bdafbbcc..886181319f192a4417aadd0067493b140104a7dd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * PPD cache implementation for CUPS.
  *
- * Copyright © 2021 by OpenPrinting.
+ * Copyright © 2021-2022 by OpenPrinting.
  * Copyright © 2010-2021 by Apple Inc.
  *
  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
@@ -4065,6 +4065,9 @@ _ppdCreateFromIPP2(
   * ColorModel...
   */
 
+  if ((defattr = ippFindAttribute(supported, "print-color-mode-default", IPP_TAG_KEYWORD)) == NULL)
+    defattr = ippFindAttribute(supported, "output-mode-default", IPP_TAG_KEYWORD);
+
   if ((attr = ippFindAttribute(supported, "urf-supported", IPP_TAG_KEYWORD)) == NULL)
     if ((attr = ippFindAttribute(supported, "pwg-raster-document-type-supported", IPP_TAG_KEYWORD)) == NULL)
       if ((attr = ippFindAttribute(supported, "print-color-mode-supported", IPP_TAG_KEYWORD)) == NULL)
@@ -4075,6 +4078,16 @@ _ppdCreateFromIPP2(
     int wrote_color = 0;
     const char *default_color = NULL;  /* Default */
 
+    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 ++)
@@ -4099,7 +4112,7 @@ _ppdCreateFromIPP2(
 
        PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW, 8)
 
-       if (!default_color || !strcmp(default_color, "FastGray"))
+       if (!default_color || (!defattr && !strcmp(default_color, "FastGray")))
          default_color = "Gray";
       }
       else if (!strcasecmp(keyword, "sgray_16") || !strcmp(keyword, "W8-16"))
@@ -4110,7 +4123,7 @@ _ppdCreateFromIPP2(
        {
          PRINTF_COLOROPTION("Gray", _("Grayscale"), CUPS_CSPACE_SW, 8)
 
-         if (!default_color || !strcmp(default_color, "FastGray"))
+         if (!default_color || (!defattr && !strcmp(default_color, "FastGray")))
            default_color = "Gray";
        }
 
@@ -4122,7 +4135,8 @@ _ppdCreateFromIPP2(
 
        PRINTF_COLOROPTION("RGB", _("Color"), CUPS_CSPACE_SRGB, 8)
 
-       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...
index 6cc5f79b47453d6ef9921dd7849321fb74e90c3c..fffb4e7b832e8b7db7e6ac2733e7a611ccac51c2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Printer routines for the CUPS scheduler.
  *
- * Copyright © 2020-2021 by OpenPrinting
+ * Copyright © 2020-2022 by OpenPrinting
  * Copyright © 2007-2019 by Apple Inc.
  * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
  *
@@ -3395,6 +3395,7 @@ add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
     cupsArrayAdd(CommonDefaults, _cupsStrAlloc("notify-events-default"));
     cupsArrayAdd(CommonDefaults, _cupsStrAlloc("number-up-default"));
     cupsArrayAdd(CommonDefaults, _cupsStrAlloc("orientation-requested-default"));
+    cupsArrayAdd(CommonDefaults, _cupsStrAlloc("print-color-mode-default"));
     cupsArrayAdd(CommonDefaults, _cupsStrAlloc("print-quality-default"));
   }
 
@@ -3406,9 +3407,7 @@ add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
        i > 0;
        i --, option ++)
   {
-    if (strcmp(option->name, "ipp-options") &&
-       strcmp(option->name, "job-sheets") &&
-        strcmp(option->name, "lease-duration"))
+    if (strcmp(option->name, "ipp-options") && strcmp(option->name, "job-sheets") && strcmp(option->name, "lease-duration"))
     {
       snprintf(name, sizeof(name), "%s-default", option->name);
       num_options = cupsAddOption(name, option->value, num_options, &options);
@@ -3430,44 +3429,37 @@ add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
   */
 
   if (!cupsGetOption("copies", p->num_options, p->options))
-    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default",
-                  1);
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "copies-default", 1);
 
   if (!cupsGetOption("document-format", p->num_options, p->options))
-    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
-                "document-format-default", NULL, "application/octet-stream");
+    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, "document-format-default", NULL, "application/octet-stream");
 
   if (!cupsGetOption("job-cancel-after", p->num_options, p->options))
-    ippAddInteger(p->attrs, IPP_TAG_PRINTER, MaxJobTime > 0 ? IPP_TAG_INTEGER : IPP_TAG_NOVALUE,
-                 "job-cancel-after-default", MaxJobTime);
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, MaxJobTime > 0 ? IPP_TAG_INTEGER : IPP_TAG_NOVALUE, "job-cancel-after-default", MaxJobTime);
 
   if (!cupsGetOption("job-hold-until", p->num_options, p->options))
-    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-                 "job-hold-until-default", NULL, "no-hold");
+    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "job-hold-until-default", NULL, "no-hold");
 
   if (!cupsGetOption("job-priority", p->num_options, p->options))
-    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                  "job-priority-default", 50);
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "job-priority-default", 50);
 
   if (!cupsGetOption("number-up", p->num_options, p->options))
-    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                  "number-up-default", 1);
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "number-up-default", 1);
 
   if (!cupsGetOption("notify-lease-duration", p->num_options, p->options))
-    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
-                 "notify-lease-duration-default", DefaultLeaseDuration);
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "notify-lease-duration-default", DefaultLeaseDuration);
 
   if (!cupsGetOption("notify-events", p->num_options, p->options))
-    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-                "notify-events-default", NULL, "job-completed");
+    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "notify-events-default", NULL, "job-completed");
 
   if (!cupsGetOption("orientation-requested", p->num_options, p->options))
-    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
-                 "orientation-requested-default", NULL, NULL);
+    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NOVALUE, "orientation-requested-default", NULL, NULL);
+
+  if (!cupsGetOption("print-color-mode", p->num_options, p->options))
+    ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "print-color-mode-default", NULL, (p->type & CUPS_PRINTER_COLOR) ? "color" : "monochrome");
 
   if (!cupsGetOption("print-quality", p->num_options, p->options))
-    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
-                  "print-quality-default", IPP_QUALITY_NORMAL);
+    ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, "print-quality-default", IPP_QUALITY_NORMAL);
 }
 
 
@@ -4497,20 +4489,25 @@ load_ppd(cupsd_printer_t *p)            /* I - Printer */
        "color"
       };
 
-      ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-                    "print-color-mode-supported", 2, NULL, color_modes);
-      ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-                   "print-color-mode-default", NULL, "color");
+      ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "print-color-mode-supported", 2, NULL, color_modes);
       ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "pwg-raster-document-type-supported", 3, NULL, pwg_raster_document_types);
 
       urf[num_urf ++] = "SRGB24";
+
+      if (!cupsGetOption("printer-color-mode", p->num_options, p->options))
+      {
+        // If the default color mode isn't set, use the default from the PPD
+        // file...
+        ppd_option_t *color_model = ppdFindOption(ppd, "ColorModel");
+                                       // ColorModel PPD option
+
+        if (color_model && strcmp(color_model->defchoice, "RGB"))
+          p->num_options = cupsAddOption("print-color-mode", "monochrome", p->num_options, &p->options);
+      }
     }
     else
     {
-      ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-                   "print-color-mode-supported", NULL, "monochrome");
-      ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
-                   "print-color-mode-default", NULL, "monochrome");
+      ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "print-color-mode-supported", NULL, "monochrome");
       ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "pwg-raster-document-type-supported", 2, NULL, pwg_raster_document_types);
     }