/*
- * "$Id: emit.c 5257 2006-03-09 15:27:27Z mike $"
+ * "$Id$"
*
- * PPD code emission routines for the Common UNIX Printing System (CUPS).
+ * PPD code emission routines for CUPS.
*
- * Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2012 by Apple Inc.
+ * Copyright 1997-2007 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
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* PostScript is a trademark of Adobe Systems, Inc.
*
*
* Contents:
*
- * 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.
- * ppdEmitString() - Get a string containing the code for marked options.
- * 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.
+ * ppdEmitString() - Get a string containing the code for marked
+ * options.
+ * ppd_compare_cparams() - Compare the order of two custom parameters.
+ * ppd_handle_media() - Handle media selection...
*/
/*
* Include necessary headers...
*/
-#include "ppd.h"
-#include <stdlib.h>
-#include "string.h"
-#include <errno.h>
-
+#include "cups-private.h"
#if defined(WIN32) || defined(__EMX__)
# include <io.h>
#else
* Local functions...
*/
+static int ppd_compare_cparams(ppd_cparam_t *a, ppd_cparam_t *b);
static void ppd_handle_media(ppd_file_t *ppd);
-static int ppd_sort(ppd_choice_t **c1, ppd_choice_t **c2);
/*
/*
* 'ppdCollect()' - Collect all marked options that reside in the specified
* section.
+ *
+ * The choices array should be freed using @code free@ when you are
+ * finished with it.
*/
int /* O - Number of options marked */
* 'ppdCollect2()' - Collect all marked options that reside in the
* specified section and minimum order.
*
- * @since CUPS 1.2@
+ * The choices array should be freed using @code free@ when you are
+ * finished with it.
+ *
+ * @since CUPS 1.2/OS X 10.5@
*/
int /* O - Number of options marked */
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 */
- *sg; /* Current sub-group */
- ppd_option_t *o; /* Current option */
ppd_choice_t *c; /* Current choice */
+ ppd_section_t csection; /* Current section */
+ float corder; /* Current OrderDependency value */
int count; /* Number of choices collected */
ppd_choice_t **collect; /* Collected choices */
+ float *orders; /* Collected order values */
+
+ DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)",
+ ppd, section, min_order, choices));
+
+ if (!ppd || !choices)
+ {
+ if (choices)
+ *choices = NULL;
- if (ppd == NULL)
return (0);
+ }
/*
- * Allocate memory for up to 1000 selected choices...
+ * Allocate memory for up to N selected choices...
*/
- count = 0;
- collect = calloc(sizeof(ppd_choice_t *), 1000);
+ count = 0;
+ if ((collect = calloc(sizeof(ppd_choice_t *),
+ cupsArrayCount(ppd->marked))) == NULL)
+ {
+ *choices = NULL;
+ return (0);
+ }
+
+ if ((orders = calloc(sizeof(float), cupsArrayCount(ppd->marked))) == NULL)
+ {
+ *choices = NULL;
+ free(collect);
+ return (0);
+ }
/*
* Loop through all options and add choices as needed...
*/
- for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
+ for (c = (ppd_choice_t *)cupsArrayFirst(ppd->marked);
+ c;
+ c = (ppd_choice_t *)cupsArrayNext(ppd->marked))
{
- for (j = g->num_options, o = g->options; j > 0; j --, o ++)
- 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)
- {
- collect[count] = c;
- count ++;
- }
+ csection = c->option->section;
+ corder = c->option->order;
- 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 && o->order >= min_order)
- for (m = o->num_choices, c = o->choices; m > 0; m --, c ++)
- if (c->marked && count < 1000)
- {
- collect[count] = c;
- count ++;
- }
+ if (!strcmp(c->choice, "Custom"))
+ {
+ ppd_attr_t *attr; /* NonUIOrderDependency value */
+ float aorder; /* Order value */
+ char asection[17], /* Section name */
+ amain[PPD_MAX_NAME + 1],
+ aoption[PPD_MAX_NAME];
+ /* *CustomFoo and True */
+
+
+ for (attr = ppdFindAttr(ppd, "NonUIOrderDependency", NULL);
+ attr;
+ attr = ppdFindNextAttr(ppd, "NonUIOrderDependency", NULL))
+ if (attr->value &&
+ sscanf(attr->value, "%f%16s%41s%40s", &aorder, asection, amain,
+ aoption) == 4 &&
+ !strncmp(amain, "*Custom", 7) &&
+ !strcmp(amain + 7, c->option->keyword) && !strcmp(aoption, "True"))
+ {
+ /*
+ * Use this NonUIOrderDependency...
+ */
+
+ corder = aorder;
+
+ if (!strcmp(asection, "DocumentSetup"))
+ csection = PPD_ORDER_DOCUMENT;
+ else if (!strcmp(asection, "ExitServer"))
+ csection = PPD_ORDER_EXIT;
+ else if (!strcmp(asection, "JCLSetup"))
+ csection = PPD_ORDER_JCL;
+ else if (!strcmp(asection, "PageSetup"))
+ csection = PPD_ORDER_PAGE;
+ else if (!strcmp(asection, "Prolog"))
+ csection = PPD_ORDER_PROLOG;
+ else
+ csection = PPD_ORDER_ANY;
+
+ break;
+ }
+ }
+
+ if (csection == section && corder >= min_order)
+ {
+ collect[count] = c;
+ orders[count] = corder;
+ count ++;
+ }
}
/*
*/
if (count > 1)
- qsort(collect, count, sizeof(ppd_choice_t *),
- (int (*)(const void *, const void *))ppd_sort);
+ {
+ int i, j; /* Looping vars */
+
+ for (i = 0; i < (count - 1); i ++)
+ for (j = i + 1; j < count; j ++)
+ if (orders[i] > orders[j])
+ {
+ c = collect[i];
+ corder = orders[i];
+ collect[i] = collect[j];
+ orders[i] = orders[j];
+ collect[j] = c;
+ orders[j] = corder;
+ }
+ }
+
+ free(orders);
+
+ DEBUG_printf(("2ppdCollect2: %d marked choices...", count));
/*
* Return the array and number of choices; if 0, free the array since
*
* When "limit" is zero, this function is identical to ppdEmit().
*
- * @since CUPS 1.2@
+ * @since CUPS 1.2/OS X 10.5@
*/
int /* O - 0 on success, -1 on failure */
* Get the string...
*/
- buffer = ppdEmitString(ppd, section, min_order);
+ buffer = ppdEmitString(ppd, section, limit ? min_order : 0.0f);
/*
* Write it as needed and return...
while (buflength > 0)
{
+#ifdef WIN32
+ if ((bytes = (ssize_t)write(fd, bufptr, (unsigned)buflength)) < 0)
+#else
if ((bytes = write(fd, bufptr, buflength)) < 0)
+#endif /* WIN32 */
{
if (errno == EAGAIN || errno == EINTR)
continue;
const char *title) /* I - Title */
{
char *ptr; /* Pointer into JCL string */
- char temp[81]; /* Local title string */
+ char temp[65], /* Local title string */
+ displaymsg[33]; /* Local display string */
/*
* of the PJL commands to initialize PJL processing.
*/
+ ppd_attr_t *charset; /* PJL charset */
+ ppd_attr_t *display; /* PJL display command */
+
+
+ if ((charset = ppdFindAttr(ppd, "cupsPJLCharset", NULL)) != NULL)
+ {
+ if (!charset->value || _cups_strcasecmp(charset->value, "UTF-8"))
+ charset = NULL;
+ }
+
+ if ((display = ppdFindAttr(ppd, "cupsPJLDisplay", NULL)) != NULL)
+ {
+ if (!display->value)
+ display = NULL;
+ }
+
fputs("\033%-12345X@PJL\n", fp);
for (ptr = ppd->jcl_begin + 9; *ptr;)
if (!strncmp(ptr, "@PJL JOB", 8))
}
/*
- * Eliminate any path info from the job title...
+ * Clean up the job title...
*/
if ((ptr = strrchr(title, '/')) != NULL)
+ {
+ /*
+ * Only show basename of file path...
+ */
+
title = ptr + 1;
+ }
+
+ if (!strncmp(title, "smbprn.", 7))
+ {
+ /*
+ * Skip leading smbprn.######## from Samba jobs...
+ */
+
+ for (title += 7; *title && isdigit(*title & 255); title ++);
+ while (_cups_isspace(*title))
+ title ++;
+
+ if ((ptr = strstr(title, " - ")) != NULL)
+ {
+ /*
+ * Skip application name in "Some Application - Title of job"...
+ */
+
+ title = ptr + 3;
+ }
+ }
/*
- * Replace double quotes with single quotes so that the title
- * does not cause a PJL syntax error.
+ * Replace double quotes with single quotes and UTF-8 characters with
+ * question marks so that the title does not cause a PJL syntax error.
*/
strlcpy(temp, title, sizeof(temp));
for (ptr = temp; *ptr; ptr ++)
if (*ptr == '\"')
*ptr = '\'';
+ else if (!charset && (*ptr & 128))
+ *ptr = '?';
+
+ /*
+ * CUPS STR #3125: Long PJL JOB NAME causes problems with some printers
+ *
+ * Generate the display message, truncating at 32 characters + nul to avoid
+ * issues with some printer's PJL implementations...
+ */
+
+ snprintf(displaymsg, sizeof(displaymsg), "%d %s %s", job_id, user, temp);
/*
* Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
*/
- fprintf(fp, "@PJL JOB NAME = \"%s\" DISPLAY = \"%d %s %s\"\n", temp,
- job_id, user, temp);
- fprintf(fp, "@PJL RDYMSG DISPLAY = \"%d %s %s\"\n", job_id, user, temp);
+ if (display && strcmp(display->value, "job"))
+ fprintf(fp, "@PJL JOB NAME = \"%s\"\n", temp);
+ else if (display && !strcmp(display->value, "rdymsg"))
+ fprintf(fp, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg);
+ else
+ fprintf(fp, "@PJL JOB NAME = \"%s\" DISPLAY = \"%s\"\n", temp,
+ displaymsg);
+
+ /*
+ * Replace double quotes with single quotes and UTF-8 characters with
+ * question marks so that the user does not cause a PJL syntax error.
+ */
+
+ strlcpy(temp, user, sizeof(temp));
+
+ for (ptr = temp; *ptr; ptr ++)
+ if (*ptr == '\"')
+ *ptr = '\'';
+ else if (!charset && (*ptr & 128))
+ *ptr = '?';
+
+ fprintf(fp, "@PJL SET USERNAME = \"%s\"\n", temp);
}
else
fputs(ppd->jcl_begin, fp);
/*
* 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
*
- * @since CUPS 1.2@
+ * @since CUPS 1.2/OS X 10.5@
*/
int /* O - 0 on success, -1 on failure */
*/
fputs("\033%-12345X@PJL\n", fp);
- fputs("@PJL RDYMSG DISPLAY = \"READY\"\n", fp);
+ fputs("@PJL RDYMSG DISPLAY = \"\"\n", fp);
fputs(ppd->jcl_end + 9, fp);
}
else
* returned string.
*
* The return string is allocated on the heap and should be freed using
- * free() when you are done with it.
+ * @code free@ when you are done with it.
*
- * @since CUPS 1.2@
+ * @since CUPS 1.2/OS X 10.5@
*/
-char * /* O - String containing option code */
+char * /* O - String containing option code or @code NULL@ if there is no option code */
ppdEmitString(ppd_file_t *ppd, /* I - PPD file record */
ppd_section_t section, /* I - Section to write */
float min_order) /* I - Lowest OrderDependency */
struct lconv *loc; /* Locale data */
+ DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)",
+ ppd, section, min_order));
+
/*
* Range check input...
*/
for (i = 0, bufsize = 1; i < count; i ++)
{
- if (section != PPD_ORDER_EXIT && section != PPD_ORDER_JCL)
+ if (section == PPD_ORDER_JCL)
+ {
+ if (!_cups_strcasecmp(choices[i]->choice, "Custom") &&
+ (coption = ppdFindCustomOption(ppd, choices[i]->option->keyword))
+ != NULL)
+ {
+ /*
+ * Add space to account for custom parameter substitution...
+ */
+
+ for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
+ cparam;
+ cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
+ {
+ switch (cparam->type)
+ {
+ case PPD_CUSTOM_CURVE :
+ case PPD_CUSTOM_INVCURVE :
+ case PPD_CUSTOM_POINTS :
+ case PPD_CUSTOM_REAL :
+ case PPD_CUSTOM_INT :
+ bufsize += 10;
+ break;
+
+ case PPD_CUSTOM_PASSCODE :
+ case PPD_CUSTOM_PASSWORD :
+ case PPD_CUSTOM_STRING :
+ if (cparam->current.custom_string)
+ bufsize += strlen(cparam->current.custom_string);
+ break;
+ }
+ }
+ }
+ }
+ else if (section != PPD_ORDER_EXIT)
{
bufsize += 3; /* [{\n */
- if ((!strcasecmp(choices[i]->option->keyword, "PageSize") ||
- !strcasecmp(choices[i]->option->keyword, "PageRegion")) &&
- !strcasecmp(choices[i]->choice, "Custom"))
+ if ((!_cups_strcasecmp(choices[i]->option->keyword, "PageSize") ||
+ !_cups_strcasecmp(choices[i]->option->keyword, "PageRegion")) &&
+ !_cups_strcasecmp(choices[i]->choice, "Custom"))
{
+ DEBUG_puts("2ppdEmitString: Custom size set!");
+
bufsize += 37; /* %%BeginFeature: *CustomPageSize True\n */
bufsize += 50; /* Five 9-digit numbers + newline */
}
- else if (!strcasecmp(choices[i]->choice, "Custom") &&
+ else if (!_cups_strcasecmp(choices[i]->choice, "Custom") &&
(coption = ppdFindCustomOption(ppd,
choices[i]->option->keyword))
!= NULL)
{
- bufsize += 17 + strlen(choices[i]->option->keyword) + 6;
- /* %%BeginFeature: *keyword True\n */
+ bufsize += 23 + strlen(choices[i]->option->keyword) + 6;
+ /* %%BeginFeature: *Customkeyword True\n */
+
-
for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
cparam;
cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
case PPD_CUSTOM_PASSCODE :
case PPD_CUSTOM_PASSWORD :
case PPD_CUSTOM_STRING :
- bufsize += 3 + 4 * strlen(cparam->current.custom_string);
+ bufsize += 3;
+ if (cparam->current.custom_string)
+ bufsize += 4 * strlen(cparam->current.custom_string);
break;
}
}
* Allocate memory...
*/
+ DEBUG_printf(("2ppdEmitString: Allocating %d bytes for string...",
+ (int)bufsize));
+
if ((buffer = calloc(1, bufsize)) == NULL)
{
free(choices);
*/
for (i = 0, bufptr = buffer; i < count; i ++, bufptr += strlen(bufptr))
- if (section != PPD_ORDER_EXIT && section != PPD_ORDER_JCL)
+ if (section == PPD_ORDER_JCL)
+ {
+ if (!_cups_strcasecmp(choices[i]->choice, "Custom") &&
+ choices[i]->code &&
+ (coption = ppdFindCustomOption(ppd, choices[i]->option->keyword))
+ != NULL)
+ {
+ /*
+ * Handle substitutions in custom JCL options...
+ */
+
+ char *cptr; /* Pointer into code */
+ int pnum; /* Parameter number */
+
+
+ for (cptr = choices[i]->code; *cptr && bufptr < bufend;)
+ {
+ if (*cptr == '\\')
+ {
+ cptr ++;
+
+ if (isdigit(*cptr & 255))
+ {
+ /*
+ * Substitute parameter...
+ */
+
+ pnum = *cptr++ - '0';
+ while (isdigit(*cptr & 255))
+ pnum = pnum * 10 + *cptr++ - '0';
+
+ for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
+ cparam;
+ cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
+ if (cparam->order == pnum)
+ break;
+
+ if (cparam)
+ {
+ switch (cparam->type)
+ {
+ case PPD_CUSTOM_CURVE :
+ case PPD_CUSTOM_INVCURVE :
+ case PPD_CUSTOM_POINTS :
+ case PPD_CUSTOM_REAL :
+ bufptr = _cupsStrFormatd(bufptr, bufend,
+ cparam->current.custom_real,
+ loc);
+ break;
+
+ case PPD_CUSTOM_INT :
+ snprintf(bufptr, bufend - bufptr, "%d",
+ cparam->current.custom_int);
+ bufptr += strlen(bufptr);
+ break;
+
+ case PPD_CUSTOM_PASSCODE :
+ case PPD_CUSTOM_PASSWORD :
+ case PPD_CUSTOM_STRING :
+ if (cparam->current.custom_string)
+ {
+ strlcpy(bufptr, cparam->current.custom_string,
+ bufend - bufptr);
+ bufptr += strlen(bufptr);
+ }
+ break;
+ }
+ }
+ }
+ else if (*cptr)
+ *bufptr++ = *cptr++;
+ }
+ else
+ *bufptr++ = *cptr++;
+ }
+ }
+ else
+ {
+ /*
+ * Otherwise just copy the option code directly...
+ */
+
+ strlcpy(bufptr, choices[i]->code, bufend - bufptr + 1);
+ bufptr += strlen(bufptr);
+ }
+ }
+ else if (section != PPD_ORDER_EXIT)
{
/*
* Add wrapper commands to prevent printer errors for unsupported
* Send DSC comments with option...
*/
- if ((!strcasecmp(choices[i]->option->keyword, "PageSize") ||
- !strcasecmp(choices[i]->option->keyword, "PageRegion")) &&
- !strcasecmp(choices[i]->choice, "Custom"))
+ DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
+ choices[i]->option->keyword, choices[i]->choice));
+
+ if ((!_cups_strcasecmp(choices[i]->option->keyword, "PageSize") ||
+ !_cups_strcasecmp(choices[i]->option->keyword, "PageRegion")) &&
+ !_cups_strcasecmp(choices[i]->choice, "Custom"))
{
/*
* Variable size; write out standard size options, using the
else
pos = 4;
- values[pos] = orientation;
+ values[pos] = (float)orientation;
for (pos = 0; pos < 5; pos ++)
{
bufptr += strlen(bufptr);
}
}
- else if (!strcasecmp(choices[i]->choice, "Custom") &&
- (coption = ppdFindCustomOption(ppd,
- choices[i]->option->keyword))
+ else if (!_cups_strcasecmp(choices[i]->choice, "Custom") &&
+ (coption = ppdFindCustomOption(ppd, choices[i]->option->keyword))
!= NULL)
{
/*
*/
const char *s; /* Pointer into string value */
+ cups_array_t *params; /* Parameters in the correct output order */
+
+
+ params = cupsArrayNew((cups_array_func_t)ppd_compare_cparams, NULL);
+ for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
+ cparam;
+ cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
+ cupsArrayAdd(params, cparam);
snprintf(bufptr, bufend - bufptr + 1,
"%%%%BeginFeature: *Custom%s True\n", coption->keyword);
bufptr += strlen(bufptr);
- for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
+ for (cparam = (ppd_cparam_t *)cupsArrayFirst(params);
cparam;
- cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
+ cparam = (ppd_cparam_t *)cupsArrayNext(params))
{
switch (cparam->type)
{
case PPD_CUSTOM_STRING :
*bufptr++ = '(';
- for (s = cparam->current.custom_string; *s; s ++)
- if (*s < ' ' || *s == '(' || *s == ')' || *s >= 127)
+ if (cparam->current.custom_string)
+ {
+ for (s = cparam->current.custom_string; *s; s ++)
{
- snprintf(bufptr, bufend - bufptr + 1, "\\%03o", *s & 255);
- bufptr += strlen(bufptr);
+ if (*s < ' ' || *s == '(' || *s == ')' || *s >= 127)
+ {
+ snprintf(bufptr, bufend - bufptr + 1, "\\%03o", *s & 255);
+ bufptr += strlen(bufptr);
+ }
+ else
+ *bufptr++ = *s;
}
- else
- *bufptr++ = *s;
+ }
*bufptr++ = ')';
*bufptr++ = '\n';
break;
}
}
+
+ cupsArrayDelete(params);
}
else
{
if (choices[i]->code && choices[i]->code[0])
{
- j = strlen(choices[i]->code);
+ j = (int)strlen(choices[i]->code);
memcpy(bufptr, choices[i]->code, j);
bufptr += j;
strlcpy(bufptr, "%%EndFeature\n"
"} stopped cleartomark\n", bufend - bufptr + 1);
bufptr += strlen(bufptr);
+
+ DEBUG_printf(("2ppdEmitString: Offset in string is %d...",
+ (int)(bufptr - buffer)));
}
else
{
}
+/*
+ * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
+ */
+
+static int /* O - Result of comparison */
+ppd_compare_cparams(ppd_cparam_t *a, /* I - First parameter */
+ ppd_cparam_t *b) /* I - Second parameter */
+{
+ return (a->order - b->order);
+}
+
+
/*
* 'ppd_handle_media()' - Handle media selection...
*/
static void
-ppd_handle_media(ppd_file_t *ppd)
+ppd_handle_media(ppd_file_t *ppd) /* I - PPD file */
{
ppd_choice_t *manual_feed, /* ManualFeed choice, if any */
- *input_slot, /* InputSlot choice, if any */
- *page; /* PageSize/PageRegion */
+ *input_slot; /* InputSlot choice, if any */
ppd_size_t *size; /* Current media size */
ppd_attr_t *rpr; /* RequiresPageRegion value */
/*
- * This function determines if the user has selected a media source
- * via the InputSlot or ManualFeed options; if so, it marks the
- * PageRegion option corresponding to the current media size.
- * Otherwise it marks the PageSize option.
+ * This function determines what page size code to use, if any, for the
+ * current media size, InputSlot, and ManualFeed selections.
+ *
+ * We use the PageSize code if:
+ *
+ * 1. A custom media size is selected.
+ * 2. ManualFeed and InputSlot are not selected (or do not exist).
+ * 3. ManualFeed is selected but is False and InputSlot is not selected or
+ * the selection has no code - the latter check done to support "auto" or
+ * "printer default" InputSlot options.
+ *
+ * We use the PageRegion code if:
+ *
+ * 4. RequiresPageRegion does not exist and the PPD contains cupsFilter
+ * keywords, indicating this is a CUPS-based driver.
+ * 5. RequiresPageRegion exists for the selected InputSlot (or "All" for any
+ * InputSlot or ManualFeed selection) and is True.
+ *
+ * If none of the 5 conditions are true, no page size code is used and we
+ * unmark any existing PageSize or PageRegion choices.
*/
if ((size = ppdPageSize(ppd, NULL)) == NULL)
if (!rpr)
rpr = ppdFindAttr(ppd, "RequiresPageRegion", "All");
- 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])))
+ if (!_cups_strcasecmp(size->name, "Custom") ||
+ (!manual_feed && !input_slot) ||
+ (manual_feed && !_cups_strcasecmp(manual_feed->choice, "False") &&
+ (!input_slot || (input_slot->code && !input_slot->code[0]))) ||
+ (!rpr && ppd->num_filters > 0))
{
/*
- * Manual feed was not selected and/or the input slot selection does
- * not contain any PostScript code. Use the PageSize option...
+ * Use PageSize code...
*/
ppdMarkOption(ppd, "PageSize", size->name);
}
- else
+ else if (rpr && rpr->value && !_cups_strcasecmp(rpr->value, "True"))
{
/*
- * Manual feed was selected and/or the input slot selection contains
- * PostScript code. Use the PageRegion option...
+ * Use PageRegion code...
*/
ppdMarkOption(ppd, "PageRegion", size->name);
-
+ }
+ else
+ {
/*
- * RequiresPageRegion does not apply to manual feed so we need to
- * check that we are not doing manual feed before unmarking PageRegion.
+ * Do not use PageSize or PageRegion code...
*/
- if (!(manual_feed && !strcasecmp(manual_feed->choice, "True")) &&
- ((rpr && rpr->value && !strcmp(rpr->value, "False")) ||
- (!rpr && !ppd->num_filters)))
+ ppd_choice_t *page; /* PageSize/Region choice, if any */
+
+ if ((page = ppdFindMarkedChoice(ppd, "PageSize")) != NULL)
{
/*
- * Either the PPD file specifies no PageRegion code or the PPD file
- * not for a CUPS raster driver and thus defaults to no PageRegion
- * code... Unmark the PageRegion choice so that we don't output the
- * code...
+ * Unmark PageSize...
*/
- page = ppdFindMarkedChoice(ppd, "PageRegion");
-
- if (page)
- page->marked = 0;
+ page->marked = 0;
+ cupsArrayRemove(ppd->marked, page);
}
- }
-}
-
-/*
- * 'ppd_sort()' - Sort options by ordering numbers...
- */
+ if ((page = ppdFindMarkedChoice(ppd, "PageRegion")) != NULL)
+ {
+ /*
+ * Unmark PageRegion...
+ */
-static int /* O - -1 if c1 < c2, 0 if equal, 1 otherwise */
-ppd_sort(ppd_choice_t **c1, /* I - First choice */
- ppd_choice_t **c2) /* I - Second choice */
-{
- if ((*c1)->option->order < (*c2)->option->order)
- return (-1);
- else if ((*c1)->option->order > (*c2)->option->order)
- return (1);
- else
- return (0);
+ page->marked = 0;
+ cupsArrayRemove(ppd->marked, page);
+ }
+ }
}
/*
- * End of "$Id: emit.c 5257 2006-03-09 15:27:27Z mike $".
+ * End of "$Id$".
*/