]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
backend/ipp.c: Adjust color job options 461/head
authorZdenek Dohnal <zdohnal@redhat.com>
Mon, 22 May 2023 15:52:43 +0000 (17:52 +0200)
committerZdenek Dohnal <zdohnal@redhat.com>
Thu, 25 May 2023 12:27:25 +0000 (14:27 +0200)
In case the client doesn't do it, we have to consolidate color options
in the job to prevent opposite options being set at the same time.

backend/ipp.c

index c8172792fe141d50e79400ef5e62de4180bd7b59..be1f2c048143fa697075f7abd62178585671f978 100644 (file)
@@ -146,6 +146,7 @@ static char         mandatory_attrs[1024] = "";
  * Local functions...
  */
 
+static void            adjust_options(int num_options, cups_option_t *options);
 static void            cancel_job(http_t *http, const char *uri, int id,
                                   const char *resource, const char *user,
                                   int version);
@@ -2286,6 +2287,59 @@ main(int  argc,                          /* I - Number of command-line args */
 }
 
 
+/*
+ * 'adjust_options()' - Adjust options which have the same meaning.
+ *
+ * In case the backend gets PPD option and IPP attribute of the same meaning
+ * among options array, adjust their values to reflect the same choices,
+ * if the values differ (preferring PPD option values).
+ *
+ * Support for each PPD x IPP option pair is added adhoc, based on demand.
+ */
+
+static void
+adjust_options(int num_options,                        /* I - Number of options */
+              cups_option_t *options)          /* I - Array of job options */
+{
+  const char *ppd_option_value = NULL;         /* PPD option value */
+  const char *ipp_attr_value = NULL;           /* IPP attribute value */
+
+
+  fprintf(stderr, "DEBUG: adjust_options()\n");
+
+  if (options == NULL || num_options < 2)
+  {
+    fprintf(stderr, "DEBUG: adjust_options(): Invalid values.\n");
+    return;
+  }
+
+ /*
+  * PPD option ColorModel and IPP attribute print-color-mode
+  */
+
+  ppd_option_value = cupsGetOption("ColorModel", num_options, options);
+  ipp_attr_value = cupsGetOption("print-color-mode", num_options, options);
+
+  if (!ppd_option_value || !ipp_attr_value)
+    return;
+
+  if (strcmp(ipp_attr_value, "monochrome") && (!strcmp(ppd_option_value, "Gray")
+                                              || !strcmp(ppd_option_value, "FastGray")
+                                              || !strcmp(ppd_option_value, "DeviceGray")))
+  {
+    fprintf(stderr, "DEBUG: adjust_options(): Adjusting print-color-mode to monochrome.\n");
+    num_options = cupsAddOption("print-color-mode", "monochrome", num_options, &options);
+  }
+  else if (strcmp(ipp_attr_value, "color") && (!strcmp(ppd_option_value, "CMY")
+                                              || !strcmp(ppd_option_value, "CMYK")
+                                              || !strcmp(ppd_option_value, "RGB")))
+  {
+    fprintf(stderr, "DEBUG: adjust_options(): Adjusting print-color-mode to color.\n");
+    num_options = cupsAddOption("print-color-mode", "color", num_options, &options);
+  }
+}
+
+
 /*
  * 'cancel_job()' - Cancel a print job.
  */
@@ -2897,6 +2951,7 @@ new_request(
       */
 
       fputs("DEBUG: Adding all operation/job attributes.\n", stderr);
+      adjust_options(num_options, options);
       cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
       cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB);
     }