]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/mark.c
Merge changes from CUPS 1.5svn-r9041.
[thirdparty/cups.git] / cups / mark.c
index b2cef1f2d522ece1b1099ee64bf52e9352758889..a9b5124e34a7809d4ad4cb8caeac024856ab6814 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * "$Id: mark.c 8210 2009-01-09 02:30:26Z mike $"
  *
- *   Option marking routines for the Common UNIX Printing System (CUPS).
+ *   Option marking routines for CUPS.
  *
- *   Copyright 2007-2009 by Apple Inc.
+ *   Copyright 2007-2010 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  *   ppdFirstOption()      - Return the first option in the PPD file.
  *   ppdNextOption()       - Return the next option in the PPD file.
  *   _ppdParseOptions()    - Parse options from a PPD file.
- *   debug_marked()        - Output the marked array to stdout...
+ *   ppd_debug_marked()    - Output the marked array to stdout...
  *   ppd_defaults()        - Set the defaults for this group and all sub-groups.
  *   ppd_mark_choices()    - Mark one or more option choices from a string.
  *   ppd_mark_option()     - Quickly mark an option without checking for
  *                           conflicts.
- *   ppd_mark_size()       - Quickly mark a page size without checking for
- *                           conflicts.
  */
 
 /*
@@ -45,7 +43,7 @@
 #include "cups.h"
 #include "string.h"
 #include "debug.h"
-#include "pwgmedia.h"
+#include "pwg-private.h"
 
 
 /*
  */
 
 #ifdef DEBUG
-static void    debug_marked(ppd_file_t *ppd, const char *title);
+static void    ppd_debug_marked(ppd_file_t *ppd, const char *title);
 #else
-#  define      debug_marked(ppd,title)
+#  define      ppd_debug_marked(ppd,title)
 #endif /* DEBUG */
 static void    ppd_defaults(ppd_file_t *ppd, ppd_group_t *g);
 static void    ppd_mark_choices(ppd_file_t *ppd, const char *s);
 static void    ppd_mark_option(ppd_file_t *ppd, const char *option,
                                const char *choice);
-static void    ppd_mark_size(ppd_file_t *ppd, const char *size);
 
 
 /*
@@ -83,8 +80,8 @@ cupsMarkOptions(
                s[255];                 /* Temporary string */
   const char   *val,                   /* Pointer into value */
                *media,                 /* media option */
-               *media_col,             /* media-col option */
-               *page_size;             /* PageSize option */
+               *page_size,             /* PageSize option */
+               *ppd_keyword;           /* PPD keyword */
   cups_option_t        *optptr;                /* Current option */
   ppd_option_t *option;                /* PPD option */
   ppd_attr_t   *attr;                  /* PPD attribute */
@@ -122,71 +119,24 @@ cupsMarkOptions(
   if (!ppd || num_options <= 0 || !options)
     return (0);
 
-  debug_marked(ppd, "Before...");
+  ppd_debug_marked(ppd, "Before...");
 
  /*
-  * Do special handling for media, media-col, and PageSize...
+  * Do special handling for media and PageSize...
   */
 
   media     = cupsGetOption("media", num_options, options);
-  media_col = cupsGetOption("media-col", num_options, options);
   page_size = cupsGetOption("PageSize", num_options, options);
 
-  if (media_col && (!page_size || !page_size[0]))
+  if (media)
   {
    /*
-    * Pull out the corresponding media size from the media-col value...
+    * Load PWG mapping data as needed...
     */
 
-    int                        num_media_cols, /* Number of media-col values */
-                       num_media_sizes;/* Number of media-size values */
-    cups_option_t      *media_cols,    /* media-col values */
-                       *media_sizes;   /* media-size values */
-
-
-    num_media_cols = cupsParseOptions(media_col, 0, &media_cols);
-
-    if ((val = cupsGetOption("media-key", num_media_cols, media_cols)) != NULL)
-      media = val;
-    else if ((val = cupsGetOption("media-size", num_media_cols,
-                                  media_cols)) != NULL)
-    {
-     /*
-      * Lookup by dimensions...
-      */
-
-      double           width,          /* Width in points */
-                       length;         /* Length in points */
-      struct lconv     *loc;           /* Locale data */
-      _cups_pwg_media_t        *pwgmedia;      /* PWG media name */
-
-
-      num_media_sizes = cupsParseOptions(val, 0, &media_sizes);
-      loc             = localeconv();
-
-      if ((val = cupsGetOption("x-dimension", num_media_sizes,
-                               media_sizes)) != NULL)
-        width = _cupsStrScand(val, NULL, loc) * 2540.0 / 72.0;
-      else
-        width = 0.0;
-
-      if ((val = cupsGetOption("y-dimension", num_media_sizes,
-                               media_sizes)) != NULL)
-        length = _cupsStrScand(val, NULL, loc) * 2540.0 / 72.0;
-      else
-        length = 0.0;
-
-      if ((pwgmedia = _cupsPWGMediaBySize(width, length)) != NULL)
-        media = pwgmedia->pwg;
+    if (!ppd->pwg)
+      ppd->pwg = _pwgCreateWithPPD(ppd);
 
-      cupsFreeOptions(num_media_sizes, media_sizes);
-    }
-
-    cupsFreeOptions(num_media_cols, media_cols);
-  }
-
-  if (media)
-  {
    /*
     * Loop through the option string, separating it at commas and
     * marking each individual option as long as the corresponding
@@ -214,24 +164,18 @@ cupsMarkOptions(
       * Mark it...
       */
 
-      if (!page_size || !page_size[0])
-       ppd_mark_size(ppd, s);
-
-      if (cupsGetOption("InputSlot", num_options, options) == NULL)
-       ppd_mark_option(ppd, "InputSlot", s);
-
-      if (cupsGetOption("MediaType", num_options, options) == NULL)
-       ppd_mark_option(ppd, "MediaType", s);
+      if ((!page_size || !page_size[0]) &&
+         (ppd_keyword = _pwgGetPageSize((_pwg_t *)ppd->pwg, NULL, s,
+                                        NULL)) != NULL)
+       ppd_mark_option(ppd, "PageSize", ppd_keyword);
 
-      if (cupsGetOption("EFMediaType", num_options, options) == NULL)
-       ppd_mark_option(ppd, "EFMediaType", s);         /* EFI */
+      if (!cupsGetOption("InputSlot", num_options, options) &&
+         (ppd_keyword = _pwgGetInputSlot((_pwg_t *)ppd->pwg, NULL, s)) != NULL)
+       ppd_mark_option(ppd, "InputSlot", ppd_keyword);
 
-      if (cupsGetOption("EFMediaQualityMode", num_options, options) == NULL)
-       ppd_mark_option(ppd, "EFMediaQualityMode", s);  /* EFI */
-
-      if (!strcasecmp(s, "manual") &&
-         !cupsGetOption("ManualFeed", num_options, options))
-       ppd_mark_option(ppd, "ManualFeed", "True");
+      if (!cupsGetOption("MediaType", num_options, options) &&
+         (ppd_keyword = _pwgGetMediaType((_pwg_t *)ppd->pwg, NULL, s)) != NULL)
+       ppd_mark_option(ppd, "MediaType", ppd_keyword);
     }
   }
 
@@ -240,8 +184,7 @@ cupsMarkOptions(
   */
 
   for (i = num_options, optptr = options; i > 0; i --, optptr ++)
-    if (!strcasecmp(optptr->name, "media") ||
-        !strcasecmp(optptr->name, "media-col"))
+    if (!strcasecmp(optptr->name, "media"))
       continue;
     else if (!strcasecmp(optptr->name, "sides"))
     {
@@ -401,6 +344,60 @@ cupsMarkOptions(
         ppd_mark_choices(ppd, attr->value);
       }
     }
+    else if (!strcasecmp(optptr->name, "print-quality"))
+    {
+      ppd_option_t     *output_mode = ppdFindOption(ppd, "OutputMode");
+                                       /* OutputMode option */
+
+      if (!strcmp(optptr->value, "3"))
+      {
+       /*
+        * Draft quality...
+       */
+
+       if (ppdFindChoice(output_mode, "Draft"))
+         ppd_mark_option(ppd, "OutputMode", "Draft");
+       else if (ppdFindChoice(output_mode, "Fast"))
+         ppd_mark_option(ppd, "OutputMode", "Fast");
+
+        if ((attr = ppdFindAttr(ppd, "APPrinterPreset",
+                               "DraftGray_with_Paper_Auto-Detect")) != NULL)
+          ppd_mark_choices(ppd, attr->value);
+      }
+      else if (!strcmp(optptr->value, "4"))
+      {
+       /*
+        * Normal quality...
+       */
+
+       if (ppdFindChoice(output_mode, "Normal"))
+         ppd_mark_option(ppd, "OutputMode", "Normal");
+       else if (ppdFindChoice(output_mode, "Good"))
+         ppd_mark_option(ppd, "OutputMode", "Good");
+
+        if ((attr = ppdFindAttr(ppd, "APPrinterPreset",
+                               "Color_with_Paper_Auto-Detect")) != NULL)
+          ppd_mark_choices(ppd, attr->value);
+        else if ((attr = ppdFindAttr(ppd, "APPrinterPreset",
+                               "Gray_with_Paper_Auto-Detect")) != NULL)
+          ppd_mark_choices(ppd, attr->value);
+      }
+      else if (!strcmp(optptr->value, "5"))
+      {
+       /*
+        * High/best/photo quality...
+       */
+
+       if (ppdFindChoice(output_mode, "Best"))
+         ppd_mark_option(ppd, "OutputMode", "Best");
+       else if (ppdFindChoice(output_mode, "High"))
+         ppd_mark_option(ppd, "OutputMode", "High");
+
+        if ((attr = ppdFindAttr(ppd, "APPrinterPreset",
+                               "Photo_on_Photo_Paper")) != NULL)
+          ppd_mark_choices(ppd, attr->value);
+      }
+    }
     else if (!strcasecmp(optptr->name, "APPrinterPreset"))
     {
      /*
@@ -421,7 +418,7 @@ cupsMarkOptions(
     else
       ppd_mark_option(ppd, optptr->name, optptr->value);
 
-  debug_marked(ppd, "After...");
+  ppd_debug_marked(ppd, "After...");
 
   return (ppdConflicts(ppd) > 0);
 }
@@ -461,13 +458,24 @@ ppd_choice_t *                            /* O - Pointer to choice or @code NULL@ */
 ppdFindMarkedChoice(ppd_file_t *ppd,   /* I - PPD file */
                     const char *option)        /* I - Keyword/option name */
 {
-  ppd_choice_t key;                    /* Search key for choice */
+  ppd_choice_t key,                    /* Search key for choice */
+               *marked;                /* Marked choice */
 
 
+  DEBUG_printf(("2ppdFindMarkedChoice(ppd=%p, option=\"%s\")", ppd, option));
+
   if ((key.option = ppdFindOption(ppd, option)) == NULL)
+  {
+    DEBUG_puts("3ppdFindMarkedChoice: Option not found, returning NULL");
     return (NULL);
+  }
+
+  marked = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key);
 
-  return ((ppd_choice_t *)cupsArrayFind(ppd->marked, &key));
+  DEBUG_printf(("3ppdFindMarkedChoice: Returning %p(%s)...", marked,
+                marked ? marked->choice : "NULL"));
+
+  return (marked);
 }
 
 
@@ -591,7 +599,7 @@ ppdMarkOption(ppd_file_t *ppd,              /* I - PPD file record */
               const char *option,      /* I - Keyword */
               const char *choice)      /* I - Option name */
 {
-  DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")\n",
+  DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")",
                ppd, option, choice));
 
  /*
@@ -735,22 +743,22 @@ _ppdParseOptions(
 
 #ifdef DEBUG
 /*
- * 'debug_marked()' - Output the marked array to stdout...
+ * 'ppd_debug_marked()' - Output the marked array to stdout...
  */
 
 static void
-debug_marked(ppd_file_t *ppd,          /* I - PPD file data */
+ppd_debug_marked(ppd_file_t *ppd,              /* I - PPD file data */
              const char *title)                /* I - Title for list */
 {
   ppd_choice_t *c;                     /* Current choice */
 
 
-  DEBUG_printf(("cupsMarkOptions: %s\n", title));
+  DEBUG_printf(("2cupsMarkOptions: %s", title));
 
   for (c = (ppd_choice_t *)cupsArrayFirst(ppd->marked);
        c;
        c = (ppd_choice_t *)cupsArrayNext(ppd->marked))
-    DEBUG_printf(("cupsMarkOptions: %s=%s\n", c->option->keyword, c->choice));
+    DEBUG_printf(("2cupsMarkOptions: %s=%s", c->option->keyword, c->choice));
 }
 #endif /* DEBUG */
 
@@ -821,7 +829,7 @@ ppd_mark_option(ppd_file_t *ppd,    /* I - PPD file */
   struct lconv *loc;                   /* Locale data */
 
 
-  DEBUG_printf(("ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")\n",
+  DEBUG_printf(("7ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")",
                ppd, option, choice));
 
  /*
@@ -831,6 +839,8 @@ ppd_mark_option(ppd_file_t *ppd,    /* I - PPD file */
 
   if (!strcasecmp(option, "AP_D_InputSlot"))
   {
+    cupsArraySave(ppd->options);
+
     if ((o = ppdFindOption(ppd, "InputSlot")) != NULL)
     {
       key.option = o;
@@ -840,13 +850,21 @@ ppd_mark_option(ppd_file_t *ppd,  /* I - PPD file */
         cupsArrayRemove(ppd->marked, oldc);
       }
     }
+
+    cupsArrayRestore(ppd->options);
   }
 
  /*
   * Check for custom options...
   */
 
-  if ((o = ppdFindOption(ppd, option)) == NULL)
+  cupsArraySave(ppd->options);
+
+  o = ppdFindOption(ppd, option);
+
+  cupsArrayRestore(ppd->options);
+
+  if (!o)
     return;
 
   loc = localeconv();
@@ -901,15 +919,15 @@ ppd_mark_option(ppd_file_t *ppd,  /* I - PPD file */
               if (units)
              {
                if (!strcasecmp(units, "cm"))
-                 cparam->current.custom_points *= 72.0f / 2.54f;             
+                 cparam->current.custom_points *= 72.0f / 2.54f;
                else if (!strcasecmp(units, "mm"))
-                 cparam->current.custom_points *= 72.0f / 25.4f;             
+                 cparam->current.custom_points *= 72.0f / 25.4f;
                else if (!strcasecmp(units, "m"))
-                 cparam->current.custom_points *= 72.0f / 0.0254f;           
+                 cparam->current.custom_points *= 72.0f / 0.0254f;
                else if (!strcasecmp(units, "in"))
-                 cparam->current.custom_points *= 72.0f;             
+                 cparam->current.custom_points *= 72.0f;
                else if (!strcasecmp(units, "ft"))
-                 cparam->current.custom_points *= 12.0f * 72.0f;             
+                 cparam->current.custom_points *= 12.0f * 72.0f;
               }
              break;
 
@@ -1049,6 +1067,8 @@ ppd_mark_option(ppd_file_t *ppd,  /* I - PPD file */
       * appropriate...
       */
 
+      cupsArraySave(ppd->options);
+
       if (!strcasecmp(option, "PageSize"))
       {
        if ((o = ppdFindOption(ppd, "PageRegion")) != NULL)
@@ -1073,6 +1093,8 @@ ppd_mark_option(ppd_file_t *ppd,  /* I - PPD file */
           }
         }
       }
+
+      cupsArrayRestore(ppd->options);
     }
     else if (!strcasecmp(option, "InputSlot"))
     {
@@ -1080,6 +1102,8 @@ ppd_mark_option(ppd_file_t *ppd,  /* I - PPD file */
       * Unmark ManualFeed option...
       */
 
+      cupsArraySave(ppd->options);
+
       if ((o = ppdFindOption(ppd, "ManualFeed")) != NULL)
       {
         key.option = o;
@@ -1089,6 +1113,8 @@ ppd_mark_option(ppd_file_t *ppd,  /* I - PPD file */
           cupsArrayRemove(ppd->marked, oldc);
         }
       }
+
+      cupsArrayRestore(ppd->options);
     }
     else if (!strcasecmp(option, "ManualFeed") &&
             !strcasecmp(choice, "True"))
@@ -1097,6 +1123,8 @@ ppd_mark_option(ppd_file_t *ppd,  /* I - PPD file */
       * Unmark InputSlot option...
       */
 
+      cupsArraySave(ppd->options);
+
       if ((o = ppdFindOption(ppd, "InputSlot")) != NULL)
       {
         key.option = o;
@@ -1106,6 +1134,8 @@ ppd_mark_option(ppd_file_t *ppd,  /* I - PPD file */
           cupsArrayRemove(ppd->marked, oldc);
         }
       }
+
+      cupsArrayRestore(ppd->options);
     }
   }
 
@@ -1186,7 +1216,7 @@ ppd_mark_size(ppd_file_t *ppd,            /* I - PPD file */
       return;
   }
   else
-    return;    
+    return;
 
  /*
   * Search the PPD file for a matching size...