]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/emit.c
7e2520c7dfe5139ba9925184159a0d874d064385
2 * "$Id: emit.c 7863 2008-08-26 03:39:59Z mike $"
4 * PPD code emission routines for CUPS.
6 * Copyright 2007-2010 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * PostScript is a trademark of Adobe Systems, Inc.
17 * This file is subject to the Apple OS-Developed Software exception.
21 * ppdCollect() - Collect all marked options that reside in the
23 * ppdCollect2() - Collect all marked options that reside in the
24 * specified section and minimum order.
25 * ppdEmit() - Emit code for marked options to a file.
26 * ppdEmitAfterOrder() - Emit a subset of the code for marked options to a
28 * ppdEmitFd() - Emit code for marked options to a file.
29 * ppdEmitJCL() - Emit code for JCL options to a file.
30 * ppdEmitJCLEnd() - Emit JCLEnd code to a file.
31 * ppdEmitString() - Get a string containing the code for marked
33 * ppd_compare_cparams() - Compare the order of two custom parameters.
34 * ppd_handle_media() - Handle media selection...
38 * Include necessary headers...
41 #include "cups-private.h"
42 #if defined(WIN32) || defined(__EMX__)
46 #endif /* WIN32 || __EMX__ */
53 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
54 static void ppd_handle_media(ppd_file_t
*ppd
);
61 static const char ppd_custom_code
[] =
63 "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
67 * 'ppdCollect()' - Collect all marked options that reside in the specified
70 * The choices array should be freed using @code free@ when you are
74 int /* O - Number of options marked */
75 ppdCollect(ppd_file_t
*ppd
, /* I - PPD file data */
76 ppd_section_t section
, /* I - Section to collect */
77 ppd_choice_t
***choices
) /* O - Pointers to choices */
79 return (ppdCollect2(ppd
, section
, 0.0, choices
));
84 * 'ppdCollect2()' - Collect all marked options that reside in the
85 * specified section and minimum order.
87 * The choices array should be freed using @code free@ when you are
90 * @since CUPS 1.2/Mac OS X 10.5@
93 int /* O - Number of options marked */
94 ppdCollect2(ppd_file_t
*ppd
, /* I - PPD file data */
95 ppd_section_t section
, /* I - Section to collect */
96 float min_order
, /* I - Minimum OrderDependency value */
97 ppd_choice_t
***choices
) /* O - Pointers to choices */
99 ppd_choice_t
*c
; /* Current choice */
100 ppd_section_t csection
; /* Current section */
101 float corder
; /* Current OrderDependency value */
102 int count
; /* Number of choices collected */
103 ppd_choice_t
**collect
; /* Collected choices */
104 float *orders
; /* Collected order values */
107 DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)",
108 ppd
, section
, min_order
, choices
));
110 if (!ppd
|| !choices
)
119 * Allocate memory for up to N selected choices...
123 if ((collect
= calloc(sizeof(ppd_choice_t
*),
124 cupsArrayCount(ppd
->marked
))) == NULL
)
130 if ((orders
= calloc(sizeof(float), cupsArrayCount(ppd
->marked
))) == NULL
)
138 * Loop through all options and add choices as needed...
141 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
143 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
145 csection
= c
->option
->section
;
146 corder
= c
->option
->order
;
148 if (!strcmp(c
->choice
, "Custom"))
150 ppd_attr_t
*attr
; /* NonUIOrderDependency value */
151 float aorder
; /* Order value */
152 char asection
[17], /* Section name */
153 amain
[PPD_MAX_NAME
+ 1],
154 aoption
[PPD_MAX_NAME
];
155 /* *CustomFoo and True */
158 for (attr
= ppdFindAttr(ppd
, "NonUIOrderDependency", NULL
);
160 attr
= ppdFindNextAttr(ppd
, "NonUIOrderDependency", NULL
))
162 sscanf(attr
->value
, "%f%16s%41s%40s", &aorder
, asection
, amain
,
164 !strncmp(amain
, "*Custom", 7) &&
165 !strcmp(amain
+ 7, c
->option
->keyword
) && !strcmp(aoption
, "True"))
168 * Use this NonUIOrderDependency...
173 if (!strcmp(asection
, "DocumentSetup"))
174 csection
= PPD_ORDER_DOCUMENT
;
175 else if (!strcmp(asection
, "ExitServer"))
176 csection
= PPD_ORDER_EXIT
;
177 else if (!strcmp(asection
, "JCLSetup"))
178 csection
= PPD_ORDER_JCL
;
179 else if (!strcmp(asection
, "PageSetup"))
180 csection
= PPD_ORDER_PAGE
;
181 else if (!strcmp(asection
, "Prolog"))
182 csection
= PPD_ORDER_PROLOG
;
184 csection
= PPD_ORDER_ANY
;
190 if (csection
== section
&& corder
>= min_order
)
193 orders
[count
] = corder
;
199 * If we have more than 1 marked choice, sort them...
204 int i
, j
; /* Looping vars */
206 for (i
= 0; i
< (count
- 1); i
++)
207 for (j
= i
+ 1; j
< count
; j
++)
208 if (orders
[i
] > orders
[j
])
212 collect
[i
] = collect
[j
];
213 orders
[i
] = orders
[j
];
221 DEBUG_printf(("2ppdCollect2: %d marked choices...", count
));
224 * Return the array and number of choices; if 0, free the array since
243 * 'ppdEmit()' - Emit code for marked options to a file.
246 int /* O - 0 on success, -1 on failure */
247 ppdEmit(ppd_file_t
*ppd
, /* I - PPD file record */
248 FILE *fp
, /* I - File to write to */
249 ppd_section_t section
) /* I - Section to write */
251 return (ppdEmitAfterOrder(ppd
, fp
, section
, 0, 0.0));
256 * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
258 * When "limit" is non-zero, this function only emits options whose
259 * OrderDependency value is greater than or equal to "min_order".
261 * When "limit" is zero, this function is identical to ppdEmit().
263 * @since CUPS 1.2/Mac OS X 10.5@
266 int /* O - 0 on success, -1 on failure */
268 ppd_file_t
*ppd
, /* I - PPD file record */
269 FILE *fp
, /* I - File to write to */
270 ppd_section_t section
, /* I - Section to write */
271 int limit
, /* I - Non-zero to use min_order */
272 float min_order
) /* I - Lowest OrderDependency */
274 char *buffer
; /* Option code */
275 int status
; /* Return status */
279 * Range check input...
289 buffer
= ppdEmitString(ppd
, section
, limit
? min_order
: 0.0);
292 * Write it as needed and return...
297 status
= fputs(buffer
, fp
) < 0 ? -1 : 0;
309 * 'ppdEmitFd()' - Emit code for marked options to a file.
312 int /* O - 0 on success, -1 on failure */
313 ppdEmitFd(ppd_file_t
*ppd
, /* I - PPD file record */
314 int fd
, /* I - File to write to */
315 ppd_section_t section
) /* I - Section to write */
317 char *buffer
, /* Option code */
318 *bufptr
; /* Pointer into code */
319 size_t buflength
; /* Length of option code */
320 ssize_t bytes
; /* Bytes written */
321 int status
; /* Return status */
325 * Range check input...
335 buffer
= ppdEmitString(ppd
, section
, 0.0);
338 * Write it as needed and return...
343 buflength
= strlen(buffer
);
347 while (buflength
> 0)
350 if ((bytes
= (ssize_t
)write(fd
, bufptr
, (unsigned)buflength
)) < 0)
352 if ((bytes
= write(fd
, bufptr
, buflength
)) < 0)
355 if (errno
== EAGAIN
|| errno
== EINTR
)
365 status
= bytes
< 0 ? -1 : 0;
377 * 'ppdEmitJCL()' - Emit code for JCL options to a file.
380 int /* O - 0 on success, -1 on failure */
381 ppdEmitJCL(ppd_file_t
*ppd
, /* I - PPD file record */
382 FILE *fp
, /* I - File to write to */
383 int job_id
, /* I - Job ID */
384 const char *user
, /* I - Username */
385 const char *title
) /* I - Title */
387 char *ptr
; /* Pointer into JCL string */
388 char temp
[65], /* Local title string */
389 displaymsg
[33]; /* Local display string */
393 * Range check the input...
396 if (!ppd
|| !ppd
->jcl_begin
|| !ppd
->jcl_ps
)
400 * See if the printer supports HP PJL...
403 if (!strncmp(ppd
->jcl_begin
, "\033%-12345X@", 10))
406 * This printer uses HP PJL commands for output; filter the output
407 * so that we only have a single "@PJL JOB" command in the header...
409 * To avoid bugs in the PJL implementation of certain vendors' products
410 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
411 * of the PJL commands to initialize PJL processing.
414 ppd_attr_t
*charset
; /* PJL charset */
415 ppd_attr_t
*display
; /* PJL display command */
418 if ((charset
= ppdFindAttr(ppd
, "cupsPJLCharset", NULL
)) != NULL
)
420 if (!charset
->value
|| strcasecmp(charset
->value
, "UTF-8"))
424 if ((display
= ppdFindAttr(ppd
, "cupsPJLDisplay", NULL
)) != NULL
)
430 fputs("\033%-12345X@PJL\n", fp
);
431 for (ptr
= ppd
->jcl_begin
+ 9; *ptr
;)
432 if (!strncmp(ptr
, "@PJL JOB", 8))
435 * Skip job command...
463 * Clean up the job title...
466 if ((ptr
= strrchr(title
, '/')) != NULL
)
469 * Only show basename of file path...
475 if (!strncmp(title
, "smbprn.", 7))
478 * Skip leading smbprn.######## from Samba jobs...
481 for (title
+= 7; *title
&& isdigit(*title
& 255); title
++);
482 while (_cups_isspace(*title
))
485 if ((ptr
= strstr(title
, " - ")) != NULL
)
488 * Skip application name in "Some Application - Title of job"...
496 * Replace double quotes with single quotes and UTF-8 characters with
497 * question marks so that the title does not cause a PJL syntax error.
500 strlcpy(temp
, title
, sizeof(temp
));
502 for (ptr
= temp
; *ptr
; ptr
++)
505 else if (!charset
&& (*ptr
& 128))
509 * CUPS STR #3125: Long PJL JOB NAME causes problems with some printers
511 * Generate the display message, truncating at 32 characters + nul to avoid
512 * issues with some printer's PJL implementations...
515 snprintf(displaymsg
, sizeof(displaymsg
), "%d %s %s", job_id
, user
, temp
);
518 * Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
521 if (display
&& strcmp(display
->value
, "job"))
523 fprintf(fp
, "@PJL JOB NAME = \"%s\"\n", temp
);
525 if (display
&& !strcmp(display
->value
, "rdymsg"))
526 fprintf(fp
, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg
);
529 fprintf(fp
, "@PJL JOB NAME = \"%s\" DISPLAY = \"%s\"\n", temp
,
533 fputs(ppd
->jcl_begin
, fp
);
535 ppdEmit(ppd
, fp
, PPD_ORDER_JCL
);
536 fputs(ppd
->jcl_ps
, fp
);
543 * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
545 * @since CUPS 1.2/Mac OS X 10.5@
548 int /* O - 0 on success, -1 on failure */
549 ppdEmitJCLEnd(ppd_file_t
*ppd
, /* I - PPD file record */
550 FILE *fp
) /* I - File to write to */
553 * Range check the input...
561 if (ppd
->num_filters
== 0)
568 * See if the printer supports HP PJL...
571 if (!strncmp(ppd
->jcl_end
, "\033%-12345X@", 10))
574 * This printer uses HP PJL commands for output; filter the output
575 * so that we only have a single "@PJL JOB" command in the header...
577 * To avoid bugs in the PJL implementation of certain vendors' products
578 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
579 * of the PJL commands to initialize PJL processing.
582 fputs("\033%-12345X@PJL\n", fp
);
583 fputs("@PJL RDYMSG DISPLAY = \"\"\n", fp
);
584 fputs(ppd
->jcl_end
+ 9, fp
);
587 fputs(ppd
->jcl_end
, fp
);
594 * 'ppdEmitString()' - Get a string containing the code for marked options.
596 * When "min_order" is greater than zero, this function only includes options
597 * whose OrderDependency value is greater than or equal to "min_order".
598 * Otherwise, all options in the specified section are included in the
601 * The return string is allocated on the heap and should be freed using
602 * @code free@ when you are done with it.
604 * @since CUPS 1.2/Mac OS X 10.5@
607 char * /* O - String containing option code or @code NULL@ if there is no option code */
608 ppdEmitString(ppd_file_t
*ppd
, /* I - PPD file record */
609 ppd_section_t section
, /* I - Section to write */
610 float min_order
) /* I - Lowest OrderDependency */
612 int i
, j
, /* Looping vars */
613 count
; /* Number of choices */
614 ppd_choice_t
**choices
; /* Choices */
615 ppd_size_t
*size
; /* Custom page size */
616 ppd_coption_t
*coption
; /* Custom option */
617 ppd_cparam_t
*cparam
; /* Custom parameter */
618 size_t bufsize
; /* Size of string buffer needed */
619 char *buffer
, /* String buffer */
620 *bufptr
, /* Pointer into buffer */
621 *bufend
; /* End of buffer */
622 struct lconv
*loc
; /* Locale data */
625 DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)",
626 ppd
, section
, min_order
));
629 * Range check input...
636 * Use PageSize or PageRegion as required...
639 ppd_handle_media(ppd
);
642 * Collect the options we need to emit...
645 if ((count
= ppdCollect2(ppd
, section
, min_order
, &choices
)) == 0)
649 * Count the number of bytes that are required to hold all of the
653 for (i
= 0, bufsize
= 1; i
< count
; i
++)
655 if (section
== PPD_ORDER_JCL
)
657 if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
658 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
662 * Add space to account for custom parameter substitution...
665 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
667 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
669 switch (cparam
->type
)
671 case PPD_CUSTOM_CURVE
:
672 case PPD_CUSTOM_INVCURVE
:
673 case PPD_CUSTOM_POINTS
:
674 case PPD_CUSTOM_REAL
:
675 case PPD_CUSTOM_INT
:
679 case PPD_CUSTOM_PASSCODE
:
680 case PPD_CUSTOM_PASSWORD
:
681 case PPD_CUSTOM_STRING
:
682 if (cparam
->current
.custom_string
)
683 bufsize
+= strlen(cparam
->current
.custom_string
);
689 else if (section
!= PPD_ORDER_EXIT
)
691 bufsize
+= 3; /* [{\n */
693 if ((!strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
694 !strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
695 !strcasecmp(choices
[i
]->choice
, "Custom"))
697 DEBUG_puts("2ppdEmitString: Custom size set!");
699 bufsize
+= 37; /* %%BeginFeature: *CustomPageSize True\n */
700 bufsize
+= 50; /* Five 9-digit numbers + newline */
702 else if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
703 (coption
= ppdFindCustomOption(ppd
,
704 choices
[i
]->option
->keyword
))
707 bufsize
+= 23 + strlen(choices
[i
]->option
->keyword
) + 6;
708 /* %%BeginFeature: *Customkeyword True\n */
711 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
713 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
715 switch (cparam
->type
)
717 case PPD_CUSTOM_CURVE
:
718 case PPD_CUSTOM_INVCURVE
:
719 case PPD_CUSTOM_POINTS
:
720 case PPD_CUSTOM_REAL
:
721 case PPD_CUSTOM_INT
:
725 case PPD_CUSTOM_PASSCODE
:
726 case PPD_CUSTOM_PASSWORD
:
727 case PPD_CUSTOM_STRING
:
729 if (cparam
->current
.custom_string
)
730 bufsize
+= 4 * strlen(cparam
->current
.custom_string
);
736 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 1 +
737 strlen(choices
[i
]->choice
) + 1;
738 /* %%BeginFeature: *keyword choice\n */
740 bufsize
+= 13; /* %%EndFeature\n */
741 bufsize
+= 22; /* } stopped cleartomark\n */
744 if (choices
[i
]->code
)
745 bufsize
+= strlen(choices
[i
]->code
) + 1;
747 bufsize
+= strlen(ppd_custom_code
);
754 DEBUG_printf(("2ppdEmitString: Allocating %d bytes for string...",
757 if ((buffer
= calloc(1, bufsize
)) == NULL
)
763 bufend
= buffer
+ bufsize
- 1;
767 * Copy the option code to the buffer...
770 for (i
= 0, bufptr
= buffer
; i
< count
; i
++, bufptr
+= strlen(bufptr
))
771 if (section
== PPD_ORDER_JCL
)
773 if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
775 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
779 * Handle substitutions in custom JCL options...
782 char *cptr
; /* Pointer into code */
783 int pnum
; /* Parameter number */
786 for (cptr
= choices
[i
]->code
; *cptr
&& bufptr
< bufend
;)
792 if (isdigit(*cptr
& 255))
795 * Substitute parameter...
798 pnum
= *cptr
++ - '0';
799 while (isdigit(*cptr
& 255))
800 pnum
= pnum
* 10 + *cptr
++ - '0';
802 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
804 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
805 if (cparam
->order
== pnum
)
810 switch (cparam
->type
)
812 case PPD_CUSTOM_CURVE
:
813 case PPD_CUSTOM_INVCURVE
:
814 case PPD_CUSTOM_POINTS
:
815 case PPD_CUSTOM_REAL
:
816 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
817 cparam
->current
.custom_real
,
821 case PPD_CUSTOM_INT
:
822 snprintf(bufptr
, bufend
- bufptr
, "%d",
823 cparam
->current
.custom_int
);
824 bufptr
+= strlen(bufptr
);
827 case PPD_CUSTOM_PASSCODE
:
828 case PPD_CUSTOM_PASSWORD
:
829 case PPD_CUSTOM_STRING
:
830 if (cparam
->current
.custom_string
)
832 strlcpy(bufptr
, cparam
->current
.custom_string
,
834 bufptr
+= strlen(bufptr
);
850 * Otherwise just copy the option code directly...
853 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
854 bufptr
+= strlen(bufptr
);
857 else if (section
!= PPD_ORDER_EXIT
)
860 * Add wrapper commands to prevent printer errors for unsupported
864 strlcpy(bufptr
, "[{\n", bufend
- bufptr
+ 1);
868 * Send DSC comments with option...
871 DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
872 choices
[i
]->option
->keyword
, choices
[i
]->choice
));
874 if ((!strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
875 !strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
876 !strcasecmp(choices
[i
]->choice
, "Custom"))
879 * Variable size; write out standard size options, using the
880 * parameter positions defined in the PPD file...
883 ppd_attr_t
*attr
; /* PPD attribute */
884 int pos
, /* Position of custom value */
885 orientation
; /* Orientation to use */
886 float values
[5]; /* Values for custom command */
889 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n",
890 bufend
- bufptr
+ 1);
893 size
= ppdPageSize(ppd
, "Custom");
895 memset(values
, 0, sizeof(values
));
897 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
899 pos
= atoi(attr
->value
) - 1;
901 if (pos
< 0 || pos
> 4)
907 values
[pos
] = size
->width
;
909 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
911 pos
= atoi(attr
->value
) - 1;
913 if (pos
< 0 || pos
> 4)
919 values
[pos
] = size
->length
;
922 * According to the Adobe PPD specification, an orientation of 1
923 * will produce a print that comes out upside-down with the X
924 * axis perpendicular to the direction of feed, which is exactly
925 * what we want to be consistent with non-PS printers.
927 * We could also use an orientation of 3 to produce output that
928 * comes out rightside-up (this is the default for many large format
929 * printer PPDs), however for consistency we will stick with the
932 * If we wanted to get fancy, we could use orientations of 0 or
933 * 2 and swap the width and length, however we don't want to get
934 * fancy, we just want it to work consistently.
936 * The orientation value is range limited by the Orientation
937 * parameter definition, so certain non-PS printer drivers that
938 * only support an Orientation of 0 will get the value 0 as
944 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
945 "Orientation")) != NULL
)
947 int min_orient
, max_orient
; /* Minimum and maximum orientations */
950 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
957 if (pos
< 0 || pos
> 4)
960 if (orientation
> max_orient
)
961 orientation
= max_orient
;
962 else if (orientation
< min_orient
)
963 orientation
= min_orient
;
969 values
[pos
] = (float)orientation
;
971 for (pos
= 0; pos
< 5; pos
++)
973 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
977 if (!choices
[i
]->code
)
980 * This can happen with certain buggy PPD files that don't include
981 * a CustomPageSize command sequence... We just use a generic
982 * Level 2 command sequence...
985 strlcpy(bufptr
, ppd_custom_code
, bufend
- bufptr
+ 1);
986 bufptr
+= strlen(bufptr
);
989 else if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
990 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
997 const char *s
; /* Pointer into string value */
998 cups_array_t
*params
; /* Parameters in the correct output order */
1001 params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
1003 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
1005 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
1006 cupsArrayAdd(params
, cparam
);
1008 snprintf(bufptr
, bufend
- bufptr
+ 1,
1009 "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
1010 bufptr
+= strlen(bufptr
);
1012 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(params
);
1014 cparam
= (ppd_cparam_t
*)cupsArrayNext(params
))
1016 switch (cparam
->type
)
1018 case PPD_CUSTOM_CURVE
:
1019 case PPD_CUSTOM_INVCURVE
:
1020 case PPD_CUSTOM_POINTS
:
1021 case PPD_CUSTOM_REAL
:
1022 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
1023 cparam
->current
.custom_real
, loc
);
1027 case PPD_CUSTOM_INT
:
1028 snprintf(bufptr
, bufend
- bufptr
+ 1, "%d\n",
1029 cparam
->current
.custom_int
);
1030 bufptr
+= strlen(bufptr
);
1033 case PPD_CUSTOM_PASSCODE
:
1034 case PPD_CUSTOM_PASSWORD
:
1035 case PPD_CUSTOM_STRING
:
1038 if (cparam
->current
.custom_string
)
1040 for (s
= cparam
->current
.custom_string
; *s
; s
++)
1042 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
1044 snprintf(bufptr
, bufend
- bufptr
+ 1, "\\%03o", *s
& 255);
1045 bufptr
+= strlen(bufptr
);
1058 cupsArrayDelete(params
);
1062 snprintf(bufptr
, bufend
- bufptr
+ 1, "%%%%BeginFeature: *%s %s\n",
1063 choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1064 bufptr
+= strlen(bufptr
);
1067 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1069 j
= (int)strlen(choices
[i
]->code
);
1070 memcpy(bufptr
, choices
[i
]->code
, j
);
1073 if (choices
[i
]->code
[j
- 1] != '\n')
1077 strlcpy(bufptr
, "%%EndFeature\n"
1078 "} stopped cleartomark\n", bufend
- bufptr
+ 1);
1079 bufptr
+= strlen(bufptr
);
1081 DEBUG_printf(("2ppdEmitString: Offset in string is %d...",
1082 (int)(bufptr
- buffer
)));
1086 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
1087 bufptr
+= strlen(bufptr
);
1091 * Nul-terminate, free, and return...
1103 * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
1106 static int /* O - Result of comparison */
1107 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
1108 ppd_cparam_t
*b
) /* I - Second parameter */
1110 return (a
->order
- b
->order
);
1115 * 'ppd_handle_media()' - Handle media selection...
1119 ppd_handle_media(ppd_file_t
*ppd
) /* I - PPD file */
1121 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1122 *input_slot
; /* InputSlot choice, if any */
1123 ppd_size_t
*size
; /* Current media size */
1124 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1128 * This function determines what page size code to use, if any, for the
1129 * current media size, InputSlot, and ManualFeed selections.
1131 * We use the PageSize code if:
1133 * 1. A custom media size is selected.
1134 * 2. ManualFeed and InputSlot are not selected (or do not exist).
1135 * 3. ManualFeed is selected but is False and InputSlot is not selected or
1136 * the selection has no code - the latter check done to support "auto" or
1137 * "printer default" InputSlot options.
1139 * We use the PageRegion code if:
1141 * 4. RequiresPageRegion does not exist and the PPD contains cupsFilter
1142 * keywords, indicating this is a CUPS-based driver.
1143 * 5. RequiresPageRegion exists for the selected InputSlot (or "All" for any
1144 * InputSlot or ManualFeed selection) and is True.
1146 * If none of the 5 conditions are true, no page size code is used and we
1147 * unmark any existing PageSize or PageRegion choices.
1150 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1153 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1154 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1156 if (input_slot
!= NULL
)
1157 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1162 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1164 if (!strcasecmp(size
->name
, "Custom") ||
1165 (!manual_feed
&& !input_slot
) ||
1166 (manual_feed
&& !strcasecmp(manual_feed
->choice
, "False") &&
1167 (!input_slot
|| (input_slot
->code
&& !input_slot
->code
[0]))) ||
1168 (!rpr
&& ppd
->num_filters
> 0))
1171 * Use PageSize code...
1174 ppdMarkOption(ppd
, "PageSize", size
->name
);
1176 else if (rpr
&& rpr
->value
&& !strcasecmp(rpr
->value
, "True"))
1179 * Use PageRegion code...
1182 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1187 * Do not use PageSize or PageRegion code...
1190 ppd_choice_t
*page
; /* PageSize/Region choice, if any */
1192 if ((page
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
1195 * Unmark PageSize...
1199 cupsArrayRemove(ppd
->marked
, page
);
1202 if ((page
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
1205 * Unmark PageRegion...
1209 cupsArrayRemove(ppd
->marked
, page
);
1216 * End of "$Id: emit.c 7863 2008-08-26 03:39:59Z mike $".