]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Finish up custom option implementation.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 27 Feb 2006 02:42:07 +0000 (02:42 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 27 Feb 2006 02:42:07 +0000 (02:42 +0000)
cups/mark.c:
    - ppdMarkOption(): Support option choices starting with "{",
      e.g. "{param1=value param2=value}".

cups/ppd.c:
    - ppdClose(): Don't free min/max string values.
    - ppdOpen2(): Min/max limits for strings are now integers.

cups/ppd.h:
    - Add ppd_cplimit_u and ppd_cplimit_t types, and use them for
      the minimum and maximum values for a custom parameter.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@5190 7a7537e8-13f0-0310-91df-b6672ffda945

cups/mark.c
cups/ppd.c
cups/ppd.h
doc/Makefile
doc/help/spec-ppd.html

index b350c80f68e2885ec018f1649f977299025a7968..57d057b734bcbbbfc05c189d5e3eb61d5c44e5ec 100644 (file)
@@ -43,7 +43,7 @@
  * Include necessary headers...
  */
 
-#include "ppd.h"
+#include "cups.h"
 #include "string.h"
 #include "debug.h"
 
@@ -355,7 +355,7 @@ ppdMarkOption(ppd_file_t *ppd,              /* I - PPD file record */
     return (0);
 
 
-  if (!strncasecmp(choice, "Custom.", 7) /* TODO || strchr(choice, '=') */ )
+  if (!strncasecmp(choice, "Custom.", 7))
   {
    /*
     * Handle a custom option...
@@ -382,13 +382,6 @@ ppdMarkOption(ppd_file_t *ppd,             /* I - PPD file record */
       ppd_cparam_t     *cparam;        /* Custom parameter */
       char             units[33];      /* Custom points units */
 
-
-     /*
-      * TODO: Detect and support custom option values using the
-      * collection format "{Name1=foo Name2=bar}".  For now, just
-      * support Custom.value for single-valued custom options.
-      */
-
       if ((coption = ppdFindCustomOption(ppd, option)) != NULL)
       {
         if ((cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params)) == NULL)
@@ -435,6 +428,75 @@ ppdMarkOption(ppd_file_t *ppd,             /* I - PPD file record */
       }
     }
   }
+  else if (choice[0] == '{')
+  {
+   /*
+    * Handle multi-value custom options...
+    */
+
+    ppd_coption_t      *coption;       /* Custom option */
+    ppd_cparam_t       *cparam;        /* Custom parameter */
+    char               units[33];      /* Custom points units */
+    int                        num_vals;       /* Number of values */
+    cups_option_t      *vals,          /* Values */
+                       *val;           /* Value */
+
+
+    if ((c = ppdFindChoice(o, "Custom")) == NULL)
+      return (0);
+
+    if ((coption = ppdFindCustomOption(ppd, option)) != NULL)
+    {
+      num_vals = cupsParseOptions(choice + 1, 0, &vals);
+
+      for (i = 0, val = vals; i < num_vals; i ++, val ++)
+      {
+        if ((cparam = ppdFindCustomParam(coption, val->name)) == NULL)
+         continue;
+
+       switch (cparam->type)
+       {
+         case PPD_CUSTOM_CURVE :
+         case PPD_CUSTOM_INVCURVE :
+         case PPD_CUSTOM_REAL :
+             cparam->current.custom_real = atof(val->value);
+             break;
+
+         case PPD_CUSTOM_POINTS :
+             if (sscanf(val->value, "%f%s", &(cparam->current.custom_points),
+                        units) < 2)
+               strcpy(units, "pt");
+
+              if (!strcasecmp(units, "cm"))
+               cparam->current.custom_points *= 72.0 / 2.54;         
+              else if (!strcasecmp(units, "mm"))
+               cparam->current.custom_points *= 72.0 / 25.4;         
+              else if (!strcasecmp(units, "m"))
+               cparam->current.custom_points *= 72.0 / 0.0254;       
+              else if (!strcasecmp(units, "in"))
+               cparam->current.custom_points *= 72.0;        
+              else if (!strcasecmp(units, "ft"))
+               cparam->current.custom_points *= 12 * 72.0;           
+             break;
+
+         case PPD_CUSTOM_INT :
+             cparam->current.custom_int = atoi(val->value);
+             break;
+
+         case PPD_CUSTOM_PASSCODE :
+         case PPD_CUSTOM_PASSWORD :
+         case PPD_CUSTOM_STRING :
+             if (cparam->current.custom_string)
+               free(cparam->current.custom_string);
+
+             cparam->current.custom_string = strdup(val->value);
+             break;
+       }
+      }
+
+      cupsFreeOptions(num_vals, vals);
+    }
+  }
   else
   {
     for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
index c44b044013690e197057decf1f7827c91709f719..609bc908c0c0748b690ccc5acf536df33a113829 100644 (file)
@@ -262,8 +262,6 @@ ppdClose(ppd_file_t *ppd)           /* I - PPD file record */
         case PPD_CUSTOM_PASSWORD :
         case PPD_CUSTOM_STRING :
             ppd_free(cparam->current.custom_string);
-            ppd_free(cparam->minimum.custom_string);
-            ppd_free(cparam->maximum.custom_string);
            break;
 
        default :
@@ -832,17 +830,6 @@ ppdOpen2(cups_file_t *fp)          /* I - File to read from */
       ppd->fonts[ppd->num_fonts] = strdup(name);
       ppd->num_fonts ++;
     }
-#if 0
-    else if (!strcmp(keyword, "ParamCustomPageSize"))
-    {
-      if (!strcmp(name, "Width"))
-        sscanf(string, "%*s%*s%f%f", ppd->custom_min + 0,
-              ppd->custom_max + 0);
-      else if (!strcmp(name, "Height"))
-        sscanf(string, "%*s%*s%f%f", ppd->custom_min + 1,
-              ppd->custom_max + 1);
-    }
-#endif /* 0 */
     else if (!strncmp(keyword, "ParamCustom", 11))
     {
       ppd_coption_t    *coption;       /* Custom option */
@@ -906,14 +893,14 @@ ppdOpen2(cups_file_t *fp)         /* I - File to read from */
       else if (!strcmp(ctype, "passcode"))
       {
         cparam->type = PPD_CUSTOM_PASSCODE;
-       cparam->minimum.custom_passcode = strdup(cminimum);
-       cparam->maximum.custom_passcode = strdup(cmaximum);
+       cparam->minimum.custom_passcode = atoi(cminimum);
+       cparam->maximum.custom_passcode = atoi(cmaximum);
       }
       else if (!strcmp(ctype, "password"))
       {
         cparam->type = PPD_CUSTOM_PASSWORD;
-       cparam->minimum.custom_password = strdup(cminimum);
-       cparam->maximum.custom_password = strdup(cmaximum);
+       cparam->minimum.custom_password = atoi(cminimum);
+       cparam->maximum.custom_password = atoi(cmaximum);
       }
       else if (!strcmp(ctype, "points"))
       {
@@ -930,8 +917,8 @@ ppdOpen2(cups_file_t *fp)           /* I - File to read from */
       else if (!strcmp(ctype, "string"))
       {
         cparam->type = PPD_CUSTOM_STRING;
-       cparam->minimum.custom_string = strdup(cminimum);
-       cparam->maximum.custom_string = strdup(cmaximum);
+       cparam->minimum.custom_string = atoi(cminimum);
+       cparam->maximum.custom_string = atoi(cmaximum);
       }
       else
       {
index 44ef036f5e487032839d018f0bd03b82123e0e9e..a5a99ae6f26b72012bda0ad6e8efb7201f2fc351 100644 (file)
@@ -232,6 +232,18 @@ typedef enum ppd_cptype_e          /**** Custom Parameter Type @since CUPS 1.2@ ****/
   PPD_CUSTOM_STRING                    /* String of characters */
 } ppd_cptype_t;
 
+typedef union ppd_cplimit_u            /**** Custom Parameter Limit @since CUPS 1.2@ ****/
+{
+  float                custom_curve;           /* Gamma value */
+  int          custom_int;             /* Integer value */
+  float                custom_invcurve;        /* Gamma value */
+  int          custom_passcode;        /* Passcode length */
+  int          custom_password;        /* Password length */
+  float                custom_points;          /* Measurement value */
+  float                custom_real;            /* Real value */
+  int          custom_string;          /* String length */
+} ppd_cplimit_t;
+
 typedef union ppd_cpvalue_u            /**** Custom Parameter Value @since CUPS 1.2@ ****/
 {
   float                custom_curve;           /* Gamma value */
@@ -250,9 +262,9 @@ typedef struct ppd_cparam_s         /**** Custom Parameter @since CUPS 1.2@ ****/
   char         text[PPD_MAX_TEXT];     /* Human-readable text */
   int          order;                  /* Order (0 to N) */
   ppd_cptype_t type;                   /* Parameter type */
-  ppd_cpvalue_t        minimum,                /* Minimum value */
-               maximum,                /* Maximum value */
-               current;                /* Current value */
+  ppd_cplimit_t        minimum,                /* Minimum value */
+               maximum;                /* Maximum value */
+  ppd_cpvalue_t        current;                /* Current value */
 } ppd_cparam_t;
 
 typedef struct ppd_coption_s           /**** Custom Option @since CUPS 1.2@ ****/
index 8926d02fc7ac5759f5b4dde1f67397ebbd1cd56e..7c2394ba24a436f1227cb5dc20b0f6dfcdfa8efb 100644 (file)
@@ -3,7 +3,7 @@
 #
 #   Documentation makefile for the Common UNIX Printing System (CUPS).
 #
-#   Copyright 1993-2006 by Easy Software Products.
+#   Copyright 1997-2006 by Easy Software Products.
 #
 #   These coded instructions, statements, and computer programs are the
 #   property of Easy Software Products and are protected by Federal
@@ -117,6 +117,7 @@ HELPFILES   =       \
                        help/man-backend.html \
                        help/man-cancel.html \
                        help/man-classes.conf.html \
+                       help/man-client.conf.html \
                        help/man-cupsaddsmb.html \
                        help/man-cups-config.html \
                        help/man-cupsd.html \
index 574ab8f925a15ebd847e9b465dc3c88062029568..45eccc79b3c91104261fe1ce94bc7f51ec027d23 100644 (file)
@@ -280,14 +280,6 @@ PostScript command string is
 option value is "2.0" then CUPS will output the string
 "2.0 &lt;&lt;/cupsReal1 2 1 roll&gt;&gt;setpagedevice".</p>
 
-<blockquote><b>Note:</b> Currently only CustomPageSize supports
-more than 1 parameter. This restriction is due to value encoding
-issues, since the "Custom.value" format does not allow for
-specification of named parameters. We anticipate supporting the
-collection value format "{Name1=foo Name2=bar}" for the final
-CUPS 1.2 release. In addition, the collection value format will
-allow string values to contain spaces.</blockquote>
-
 <p>The "type" is one of the following keywords:</p>
 
 <ul>