]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Clean up some PostScript output issues and add new order-dependent APIs.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 25 Jan 2006 19:57:45 +0000 (19:57 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 25 Jan 2006 19:57:45 +0000 (19:57 +0000)
cups/emit.c:
- ppdCollect2(): Added
- ppdEmitAfterOrder(): Added, support floating point page sizes.
- ppd_handle_media(): Fix manual feed/input slot detection code
  so that PageRegion is used as needed.

cups/ppd.h:
- Add ppdCollect2() and ppdEmitAfterOrder() functions.

cups/mark.c:
- ppdMarkOption(): Add support for AP_D_InputSlot pseudo-option
  and fix InputSlot/ManualFeed option issues.

cups/options.c:
- cupsMarkOptions(): Don't allow an empty PageSize option to
  override media.

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

cups/emit.c
cups/mark.c
cups/options.c
cups/ppd.h

index 859a61d38ee05eeadf7b10e9f7bfa78cd492b210..76a7e83dbbb0ab097ecdcc9ff5a45dacd205005b 100644 (file)
  *
  * Contents:
  *
- *   ppdCollect()       - Collect all marked options that reside in the
- *                        specified section.
- *   ppdEmit()          - Emit code for marked options to a file.
- *   ppdEmitFd()        - Emit code for marked options to a file.
- *   ppdEmitJCL()       - Emit code for JCL options to a file.
- *   ppdEmitJCLEnd()    - Emit JCLEnd code to a file.
- *   ppd_handle_media() - Handle media selection...
- *   ppd_sort()         - Sort options by ordering numbers...
+ *   ppdCollect()        - Collect all marked options that reside in the
+ *                         specified section.
+ *   ppdCollect2()       - Collect all marked options that reside in the
+ *                         specified section and minimum order.
+ *   ppdEmit()           - Emit code for marked options to a file.
+ *   ppdEmitAfterOrder() - Emit a subset of the code for marked options to a file.
+ *   ppdEmitFd()         - Emit code for marked options to a file.
+ *   ppdEmitJCL()        - Emit code for JCL options to a file.
+ *   ppdEmitJCLEnd()     - Emit JCLEnd code to a file.
+ *   ppd_handle_media()  - Handle media selection...
+ *   ppd_sort()          - Sort options by ordering numbers...
  */
 
 /*
@@ -78,6 +81,23 @@ int                                  /* O - Number of options marked */
 ppdCollect(ppd_file_t    *ppd,         /* I - PPD file data */
            ppd_section_t section,      /* I - Section to collect */
            ppd_choice_t  ***choices)   /* O - Pointers to choices */
+{
+  return (ppdCollect2(ppd, section, 0.0, choices));
+}
+
+
+/*
+ * 'ppdCollect2()' - Collect all marked options that reside in the
+ *                   specified section and minimum order.
+ *
+ * @since CUPS 1.2@
+ */
+
+int                                    /* O - Number of options marked */
+ppdCollect2(ppd_file_t    *ppd,                /* I - PPD file data */
+            ppd_section_t section,     /* I - Section to collect */
+           float         min_order,    /* I - Minimum OrderDependency value */
+            ppd_choice_t  ***choices)  /* O - Pointers to choices */
 {
   int          i, j, k, m;             /* Looping vars */
   ppd_group_t  *g,                     /* Current group */
@@ -105,7 +125,7 @@ ppdCollect(ppd_file_t    *ppd,              /* I - PPD file data */
   for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
   {
     for (j = g->num_options, o = g->options; j > 0; j --, o ++)
-      if (o->section == section)
+      if (o->section == section && o->order >= min_order)
        for (k = o->num_choices, c = o->choices; k > 0; k --, c ++)
          if (c->marked && count < 1000)
          {
@@ -115,7 +135,7 @@ ppdCollect(ppd_file_t    *ppd,              /* I - PPD file data */
 
     for (j = g->num_subgroups, sg = g->subgroups; j > 0; j --, sg ++)
       for (k = sg->num_options, o = sg->options; k > 0; k --, o ++)
-       if (o->section == section)
+       if (o->section == section && o->order >= min_order)
          for (m = o->num_choices, c = o->choices; m > 0; m --, c ++)
            if (c->marked && count < 1000)
            {
@@ -159,6 +179,29 @@ int                                        /* O - 0 on success, -1 on failure */
 ppdEmit(ppd_file_t    *ppd,            /* I - PPD file record */
         FILE          *fp,             /* I - File to write to */
         ppd_section_t section)         /* I - Section to write */
+{
+  return (ppdEmitAfterOrder(ppd, fp, section, 0, 0.0));
+}
+
+
+/*
+ * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
+ *
+ * When "limit" is non-zero, this function only emits options whose
+ * OrderDependency value is greater than or equal to "min_order".
+ *
+ * When "limit" is zero, this function is identical to ppdEmit().
+ *
+ * @since CUPS 1.2@
+ */
+
+int                                    /* O - 0 on success, -1 on failure */
+ppdEmitAfterOrder(
+    ppd_file_t    *ppd,                        /* I - PPD file record */
+    FILE          *fp,                 /* I - File to write to */
+    ppd_section_t section,             /* I - Section to write */
+    int                  limit,                /* I - Non-zero to use min_order, 0 to include all */
+    float         min_order)           /* I - Lowest order dependency to include */
 {
   int          i,                      /* Looping var */
                count;                  /* Number of choices */
@@ -176,7 +219,7 @@ ppdEmit(ppd_file_t    *ppd,         /* I - PPD file record */
   * Collect the options we need to emit and emit them!
   */
 
-  if ((count = ppdCollect(ppd, section, &choices)) == 0)
+  if ((count = ppdCollect2(ppd, section, min_order, &choices)) == 0)
     return (0);
 
   for (i = 0; i < count; i ++)
@@ -208,15 +251,16 @@ ppdEmit(ppd_file_t    *ppd,               /* I - PPD file record */
 
         ppd_attr_t     *attr;          /* PPD attribute */
        int             pos,            /* Position of custom value */
-                       values[5],      /* Values for custom command */
                        orientation;    /* Orientation to use */
-
+       float           values[5];      /* Values for custom command */
+        int            isfloat[5];     /* Whether each value is float or int */
 
         fputs("%%BeginFeature: *CustomPageSize True\n", fp);
 
         size = ppdPageSize(ppd, "Custom");
 
         memset(values, 0, sizeof(values));
+        memset(isfloat, 0, sizeof(isfloat));
 
        if ((attr = ppdFindAttr(ppd, "ParamCustomPageSize", "Width")) != NULL)
        {
@@ -228,7 +272,8 @@ ppdEmit(ppd_file_t    *ppd,         /* I - PPD file record */
        else
          pos = 0;
 
-       values[pos] = (int)size->width;
+       values[pos]  = size->width;
+       isfloat[pos] = 1;
 
        if ((attr = ppdFindAttr(ppd, "ParamCustomPageSize", "Height")) != NULL)
        {
@@ -240,7 +285,8 @@ ppdEmit(ppd_file_t    *ppd,         /* I - PPD file record */
        else
          pos = 1;
 
-       values[pos] = (int)size->length;
+       values[pos]  = size->length;
+       isfloat[pos] = 1;
 
        /*
         * According to the Adobe PPD specification, an orientation of 1
@@ -292,8 +338,11 @@ ppdEmit(ppd_file_t    *ppd,                /* I - PPD file record */
 
        values[pos] = orientation;
 
-        fprintf(fp, "%d %d %d %d %d\n", values[0], values[1],
-               values[2], values[3], values[4]);
+        for (pos = 0; pos < 5; pos ++)
+         if (isfloat[pos])
+           fprintf(fp, "%.2f\n", values[pos]);
+          else
+           fprintf(fp, "%.0f\n", values[pos]);
 
        if (choices[i]->code == NULL)
        {
@@ -814,10 +863,9 @@ ppd_handle_media(ppd_file_t *ppd)
   if (!rpr)
     rpr = ppdFindAttr(ppd, "RequiresPageRegion", "All");
 
-  if (!strcasecmp(size->name, "Custom") ||
-      (manual_feed == NULL && input_slot == NULL) ||
-      (manual_feed != NULL && !strcasecmp(manual_feed->choice, "False")) ||
-      (input_slot != NULL && (input_slot->code == NULL || !input_slot->code[0])))
+  if (!strcasecmp(size->name, "Custom") || (!manual_feed && !input_slot) ||
+      !((manual_feed && !strcasecmp(manual_feed->choice, "True")) ||
+        (input_slot && input_slot->code && input_slot->code[0])))
   {
    /*
     * Manual feed was not selected and/or the input slot selection does
index f915acd92c9466f44c9ca2caadb7d76fda93daaa..a157dae0fb5d8c1e86da726e4e487af837b3268d 100644 (file)
@@ -330,6 +330,18 @@ ppdMarkOption(ppd_file_t *ppd,             /* I - PPD file record */
   if (!ppd || !option || !choice)
     return (0);
 
+ /*
+  * AP_D_InputSlot is the "default input slot" on MacOS X, and setting
+  * it clears the regular InputSlot choices...
+  */
+
+  if (!strcasecmp(option, "AP_D_InputSlot"))
+  {
+    if ((o = ppdFindOption(ppd, "InputSlot")) != NULL)
+      for (i = 0; i < o->num_choices; i ++)
+       o->choices[i].marked = 0;
+  }
+
  /*
   * Check for custom options...
   */
@@ -477,14 +489,16 @@ ppdMarkOption(ppd_file_t *ppd,            /* I - PPD file record */
        else if (!strcasecmp(option, "InputSlot"))
        {
         /*
-         * Unmark ManualFeed option...
+         * Unmark ManualFeed True and possibly mark ManualFeed False
+         * option...
          */
 
          if ((o = ppdFindOption(ppd, "ManualFeed")) != NULL)
            for (j = 0; j < o->num_choices; j ++)
-              o->choices[j].marked = 0;
+              o->choices[j].marked = !strcasecmp(o->choices[j].choice, "False");
        }
-       else if (!strcasecmp(option, "ManualFeed"))
+       else if (!strcasecmp(option, "ManualFeed") &&
+                !strcasecmp(choice, "True"))
        {
         /*
          * Unmark InputSlot option...
index 49ebd65c47ee0521900491e496ff22cb2f488a7f..1ccbe1bc04fd87c775675d4342d989a56f3e1d1e 100644 (file)
@@ -367,6 +367,7 @@ cupsMarkOptions(
   char         *val,                   /* Pointer into value */
                *ptr,                   /* Pointer into string */
                s[255];                 /* Temporary string */
+  const char   *page_size;             /* PageSize option */
   cups_option_t        *optptr;                /* Current option */
   ppd_option_t *option;                /* PPD option */
   static const char * const duplex_options[] =
@@ -407,16 +408,23 @@ cupsMarkOptions(
   * Mark options...
   */
 
-  conflict = 0;
+  conflict  = 0;
 
   for (i = num_options, optptr = options; i > 0; i --, optptr ++)
     if (!strcasecmp(optptr->name, "media"))
     {
      /*
       * Loop through the option string, separating it at commas and
-      * marking each individual option.
+      * marking each individual option as long as the corresponding
+      * PPD option (PageSize, InputSlot, etc.) is not also set.
+      *
+      * For PageSize, we also check for an empty option value since
+      * some versions of MacOS X use it to specify auto-selection
+      * of the media based solely on the size.
       */
 
+      page_size = cupsGetOption("PageSize", num_options, options);
+
       for (val = optptr->value; *val;)
       {
        /*
@@ -434,7 +442,7 @@ cupsMarkOptions(
         * Mark it...
        */
 
-        if (cupsGetOption("PageSize", num_options, options) == NULL)
+        if (!page_size || !page_size[0])
          if (ppdMarkOption(ppd, "PageSize", s))
             conflict = 1;
 
index a565bbafea64eb389627657e9848ead44586368a..2d5b22f9ffe949ecb9f5732ad52ec95aa6dc160d 100644 (file)
@@ -4,7 +4,7 @@
  *   PostScript Printer Description definitions for the Common UNIX Printing
  *   System (CUPS).
  *
- *   Copyright 1997-2005 by Easy Software Products, all rights reserved.
+ *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  *   property of Easy Software Products and are protected by Federal
@@ -362,6 +362,11 @@ extern ppd_status_t        ppdLastError(int *line);
 extern void            ppdSetConformance(ppd_conform_t c);
 
 /**** New in CUPS 1.2 ****/
+extern int             ppdCollect2(ppd_file_t *ppd, ppd_section_t section,
+                                   float min_order, ppd_choice_t  ***choices);
+extern int             ppdEmitAfterOrder(ppd_file_t *ppd, FILE *fp,
+                                         ppd_section_t section, int limit,
+                                         float min_order);
 extern int             ppdEmitJCLEnd(ppd_file_t *ppd, FILE *fp);
 extern ppd_coption_t   *ppdFindCustomOption(ppd_file_t *ppd,
                                             const char *keyword);