]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/ppd-emit.c
2 * PPD code emission routines for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
13 * PostScript is a trademark of Adobe Systems, Inc.
15 * This file is subject to the Apple OS-Developed Software exception.
19 * Include necessary headers...
22 #include "cups-private.h"
24 #if defined(WIN32) || defined(__EMX__)
28 #endif /* WIN32 || __EMX__ */
35 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
36 static void ppd_handle_media(ppd_file_t
*ppd
);
43 static const char ppd_custom_code
[] =
45 "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
49 * 'ppdCollect()' - Collect all marked options that reside in the specified
52 * The choices array should be freed using @code free@ when you are
56 int /* O - Number of options marked */
57 ppdCollect(ppd_file_t
*ppd
, /* I - PPD file data */
58 ppd_section_t section
, /* I - Section to collect */
59 ppd_choice_t
***choices
) /* O - Pointers to choices */
61 return (ppdCollect2(ppd
, section
, 0.0, choices
));
66 * 'ppdCollect2()' - Collect all marked options that reside in the
67 * specified section and minimum order.
69 * The choices array should be freed using @code free@ when you are
72 * @since CUPS 1.2/macOS 10.5@
75 int /* O - Number of options marked */
76 ppdCollect2(ppd_file_t
*ppd
, /* I - PPD file data */
77 ppd_section_t section
, /* I - Section to collect */
78 float min_order
, /* I - Minimum OrderDependency value */
79 ppd_choice_t
***choices
) /* O - Pointers to choices */
81 ppd_choice_t
*c
; /* Current choice */
82 ppd_section_t csection
; /* Current section */
83 float corder
; /* Current OrderDependency value */
84 int count
; /* Number of choices collected */
85 ppd_choice_t
**collect
; /* Collected choices */
86 float *orders
; /* Collected order values */
89 DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)",
90 ppd
, section
, min_order
, choices
));
101 * Allocate memory for up to N selected choices...
105 if ((collect
= calloc(sizeof(ppd_choice_t
*),
106 (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
112 if ((orders
= calloc(sizeof(float), (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
120 * Loop through all options and add choices as needed...
123 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
125 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
127 csection
= c
->option
->section
;
128 corder
= c
->option
->order
;
130 if (!strcmp(c
->choice
, "Custom"))
132 ppd_attr_t
*attr
; /* NonUIOrderDependency value */
133 float aorder
; /* Order value */
134 char asection
[17], /* Section name */
135 amain
[PPD_MAX_NAME
+ 1],
136 aoption
[PPD_MAX_NAME
];
137 /* *CustomFoo and True */
140 for (attr
= ppdFindAttr(ppd
, "NonUIOrderDependency", NULL
);
142 attr
= ppdFindNextAttr(ppd
, "NonUIOrderDependency", NULL
))
144 sscanf(attr
->value
, "%f%16s%41s%40s", &aorder
, asection
, amain
,
146 !strncmp(amain
, "*Custom", 7) &&
147 !strcmp(amain
+ 7, c
->option
->keyword
) && !strcmp(aoption
, "True"))
150 * Use this NonUIOrderDependency...
155 if (!strcmp(asection
, "DocumentSetup"))
156 csection
= PPD_ORDER_DOCUMENT
;
157 else if (!strcmp(asection
, "ExitServer"))
158 csection
= PPD_ORDER_EXIT
;
159 else if (!strcmp(asection
, "JCLSetup"))
160 csection
= PPD_ORDER_JCL
;
161 else if (!strcmp(asection
, "PageSetup"))
162 csection
= PPD_ORDER_PAGE
;
163 else if (!strcmp(asection
, "Prolog"))
164 csection
= PPD_ORDER_PROLOG
;
166 csection
= PPD_ORDER_ANY
;
172 if (csection
== section
&& corder
>= min_order
)
175 orders
[count
] = corder
;
181 * If we have more than 1 marked choice, sort them...
186 int i
, j
; /* Looping vars */
188 for (i
= 0; i
< (count
- 1); i
++)
189 for (j
= i
+ 1; j
< count
; j
++)
190 if (orders
[i
] > orders
[j
])
194 collect
[i
] = collect
[j
];
195 orders
[i
] = orders
[j
];
203 DEBUG_printf(("2ppdCollect2: %d marked choices...", count
));
206 * Return the array and number of choices; if 0, free the array since
225 * 'ppdEmit()' - Emit code for marked options to a file.
228 int /* O - 0 on success, -1 on failure */
229 ppdEmit(ppd_file_t
*ppd
, /* I - PPD file record */
230 FILE *fp
, /* I - File to write to */
231 ppd_section_t section
) /* I - Section to write */
233 return (ppdEmitAfterOrder(ppd
, fp
, section
, 0, 0.0));
238 * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
240 * When "limit" is non-zero, this function only emits options whose
241 * OrderDependency value is greater than or equal to "min_order".
243 * When "limit" is zero, this function is identical to ppdEmit().
245 * @since CUPS 1.2/macOS 10.5@
248 int /* O - 0 on success, -1 on failure */
250 ppd_file_t
*ppd
, /* I - PPD file record */
251 FILE *fp
, /* I - File to write to */
252 ppd_section_t section
, /* I - Section to write */
253 int limit
, /* I - Non-zero to use min_order */
254 float min_order
) /* I - Lowest OrderDependency */
256 char *buffer
; /* Option code */
257 int status
; /* Return status */
261 * Range check input...
271 buffer
= ppdEmitString(ppd
, section
, limit
? min_order
: 0.0f
);
274 * Write it as needed and return...
279 status
= fputs(buffer
, fp
) < 0 ? -1 : 0;
291 * 'ppdEmitFd()' - Emit code for marked options to a file.
294 int /* O - 0 on success, -1 on failure */
295 ppdEmitFd(ppd_file_t
*ppd
, /* I - PPD file record */
296 int fd
, /* I - File to write to */
297 ppd_section_t section
) /* I - Section to write */
299 char *buffer
, /* Option code */
300 *bufptr
; /* Pointer into code */
301 size_t buflength
; /* Length of option code */
302 ssize_t bytes
; /* Bytes written */
303 int status
; /* Return status */
307 * Range check input...
317 buffer
= ppdEmitString(ppd
, section
, 0.0);
320 * Write it as needed and return...
325 buflength
= strlen(buffer
);
329 while (buflength
> 0)
332 if ((bytes
= (ssize_t
)write(fd
, bufptr
, (unsigned)buflength
)) < 0)
334 if ((bytes
= write(fd
, bufptr
, buflength
)) < 0)
337 if (errno
== EAGAIN
|| errno
== EINTR
)
343 buflength
-= (size_t)bytes
;
347 status
= bytes
< 0 ? -1 : 0;
359 * 'ppdEmitJCL()' - Emit code for JCL options to a file.
362 int /* O - 0 on success, -1 on failure */
363 ppdEmitJCL(ppd_file_t
*ppd
, /* I - PPD file record */
364 FILE *fp
, /* I - File to write to */
365 int job_id
, /* I - Job ID */
366 const char *user
, /* I - Username */
367 const char *title
) /* I - Title */
369 char *ptr
; /* Pointer into JCL string */
370 char temp
[65], /* Local title string */
371 displaymsg
[33]; /* Local display string */
375 * Range check the input...
378 if (!ppd
|| !ppd
->jcl_begin
|| !ppd
->jcl_ps
)
382 * See if the printer supports HP PJL...
385 if (!strncmp(ppd
->jcl_begin
, "\033%-12345X@", 10))
388 * This printer uses HP PJL commands for output; filter the output
389 * so that we only have a single "@PJL JOB" command in the header...
391 * To avoid bugs in the PJL implementation of certain vendors' products
392 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
393 * of the PJL commands to initialize PJL processing.
396 ppd_attr_t
*charset
; /* PJL charset */
397 ppd_attr_t
*display
; /* PJL display command */
400 if ((charset
= ppdFindAttr(ppd
, "cupsPJLCharset", NULL
)) != NULL
)
402 if (!charset
->value
|| _cups_strcasecmp(charset
->value
, "UTF-8"))
406 if ((display
= ppdFindAttr(ppd
, "cupsPJLDisplay", NULL
)) != NULL
)
412 fputs("\033%-12345X@PJL\n", fp
);
413 for (ptr
= ppd
->jcl_begin
+ 9; *ptr
;)
414 if (!strncmp(ptr
, "@PJL JOB", 8))
417 * Skip job command...
445 * Clean up the job title...
448 if ((ptr
= strrchr(title
, '/')) != NULL
)
451 * Only show basename of file path...
457 if (!strncmp(title
, "smbprn.", 7))
460 * Skip leading smbprn.######## from Samba jobs...
463 for (title
+= 7; *title
&& isdigit(*title
& 255); title
++);
464 while (_cups_isspace(*title
))
467 if ((ptr
= strstr(title
, " - ")) != NULL
)
470 * Skip application name in "Some Application - Title of job"...
478 * Replace double quotes with single quotes and UTF-8 characters with
479 * question marks so that the title does not cause a PJL syntax error.
482 strlcpy(temp
, title
, sizeof(temp
));
484 for (ptr
= temp
; *ptr
; ptr
++)
487 else if (!charset
&& (*ptr
& 128))
491 * CUPS STR #3125: Long PJL JOB NAME causes problems with some printers
493 * Generate the display message, truncating at 32 characters + nul to avoid
494 * issues with some printer's PJL implementations...
497 snprintf(displaymsg
, sizeof(displaymsg
), "%d %s %s", job_id
, user
, temp
);
500 * Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
503 if (display
&& strcmp(display
->value
, "job"))
504 fprintf(fp
, "@PJL JOB NAME = \"%s\"\n", temp
);
505 else if (display
&& !strcmp(display
->value
, "rdymsg"))
506 fprintf(fp
, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg
);
508 fprintf(fp
, "@PJL JOB NAME = \"%s\" DISPLAY = \"%s\"\n", temp
,
512 * Replace double quotes with single quotes and UTF-8 characters with
513 * question marks so that the user does not cause a PJL syntax error.
516 strlcpy(temp
, user
, sizeof(temp
));
518 for (ptr
= temp
; *ptr
; ptr
++)
521 else if (!charset
&& (*ptr
& 128))
524 fprintf(fp
, "@PJL SET USERNAME = \"%s\"\n", temp
);
527 fputs(ppd
->jcl_begin
, fp
);
529 ppdEmit(ppd
, fp
, PPD_ORDER_JCL
);
530 fputs(ppd
->jcl_ps
, fp
);
537 * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
539 * @since CUPS 1.2/macOS 10.5@
542 int /* O - 0 on success, -1 on failure */
543 ppdEmitJCLEnd(ppd_file_t
*ppd
, /* I - PPD file record */
544 FILE *fp
) /* I - File to write to */
547 * Range check the input...
555 if (ppd
->num_filters
== 0)
562 * See if the printer supports HP PJL...
565 if (!strncmp(ppd
->jcl_end
, "\033%-12345X@", 10))
568 * This printer uses HP PJL commands for output; filter the output
569 * so that we only have a single "@PJL JOB" command in the header...
571 * To avoid bugs in the PJL implementation of certain vendors' products
572 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
573 * of the PJL commands to initialize PJL processing.
576 fputs("\033%-12345X@PJL\n", fp
);
577 fputs("@PJL RDYMSG DISPLAY = \"\"\n", fp
);
578 fputs(ppd
->jcl_end
+ 9, fp
);
581 fputs(ppd
->jcl_end
, fp
);
588 * 'ppdEmitString()' - Get a string containing the code for marked options.
590 * When "min_order" is greater than zero, this function only includes options
591 * whose OrderDependency value is greater than or equal to "min_order".
592 * Otherwise, all options in the specified section are included in the
595 * The return string is allocated on the heap and should be freed using
596 * @code free@ when you are done with it.
598 * @since CUPS 1.2/macOS 10.5@
601 char * /* O - String containing option code or @code NULL@ if there is no option code */
602 ppdEmitString(ppd_file_t
*ppd
, /* I - PPD file record */
603 ppd_section_t section
, /* I - Section to write */
604 float min_order
) /* I - Lowest OrderDependency */
606 int i
, j
, /* Looping vars */
607 count
; /* Number of choices */
608 ppd_choice_t
**choices
; /* Choices */
609 ppd_size_t
*size
; /* Custom page size */
610 ppd_coption_t
*coption
; /* Custom option */
611 ppd_cparam_t
*cparam
; /* Custom parameter */
612 size_t bufsize
; /* Size of string buffer needed */
613 char *buffer
, /* String buffer */
614 *bufptr
, /* Pointer into buffer */
615 *bufend
; /* End of buffer */
616 struct lconv
*loc
; /* Locale data */
619 DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)",
620 ppd
, section
, min_order
));
623 * Range check input...
630 * Use PageSize or PageRegion as required...
633 ppd_handle_media(ppd
);
636 * Collect the options we need to emit...
639 if ((count
= ppdCollect2(ppd
, section
, min_order
, &choices
)) == 0)
643 * Count the number of bytes that are required to hold all of the
647 for (i
= 0, bufsize
= 1; i
< count
; i
++)
649 if (section
== PPD_ORDER_JCL
)
651 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
652 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
656 * Add space to account for custom parameter substitution...
659 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
661 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
663 switch (cparam
->type
)
665 case PPD_CUSTOM_CURVE
:
666 case PPD_CUSTOM_INVCURVE
:
667 case PPD_CUSTOM_POINTS
:
668 case PPD_CUSTOM_REAL
:
669 case PPD_CUSTOM_INT
:
673 case PPD_CUSTOM_PASSCODE
:
674 case PPD_CUSTOM_PASSWORD
:
675 case PPD_CUSTOM_STRING
:
676 if (cparam
->current
.custom_string
)
677 bufsize
+= strlen(cparam
->current
.custom_string
);
683 else if (section
!= PPD_ORDER_EXIT
)
685 bufsize
+= 3; /* [{\n */
687 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
688 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
689 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
691 DEBUG_puts("2ppdEmitString: Custom size set!");
693 bufsize
+= 37; /* %%BeginFeature: *CustomPageSize True\n */
694 bufsize
+= 50; /* Five 9-digit numbers + newline */
696 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
697 (coption
= ppdFindCustomOption(ppd
,
698 choices
[i
]->option
->keyword
))
701 bufsize
+= 23 + strlen(choices
[i
]->option
->keyword
) + 6;
702 /* %%BeginFeature: *Customkeyword True\n */
705 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
707 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
709 switch (cparam
->type
)
711 case PPD_CUSTOM_CURVE
:
712 case PPD_CUSTOM_INVCURVE
:
713 case PPD_CUSTOM_POINTS
:
714 case PPD_CUSTOM_REAL
:
715 case PPD_CUSTOM_INT
:
719 case PPD_CUSTOM_PASSCODE
:
720 case PPD_CUSTOM_PASSWORD
:
721 case PPD_CUSTOM_STRING
:
723 if (cparam
->current
.custom_string
)
724 bufsize
+= 4 * strlen(cparam
->current
.custom_string
);
730 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 1 +
731 strlen(choices
[i
]->choice
) + 1;
732 /* %%BeginFeature: *keyword choice\n */
734 bufsize
+= 13; /* %%EndFeature\n */
735 bufsize
+= 22; /* } stopped cleartomark\n */
738 if (choices
[i
]->code
)
739 bufsize
+= strlen(choices
[i
]->code
) + 1;
741 bufsize
+= strlen(ppd_custom_code
);
748 DEBUG_printf(("2ppdEmitString: Allocating %d bytes for string...",
751 if ((buffer
= calloc(1, bufsize
)) == NULL
)
757 bufend
= buffer
+ bufsize
- 1;
761 * Copy the option code to the buffer...
764 for (i
= 0, bufptr
= buffer
; i
< count
; i
++, bufptr
+= strlen(bufptr
))
765 if (section
== PPD_ORDER_JCL
)
767 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
769 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
773 * Handle substitutions in custom JCL options...
776 char *cptr
; /* Pointer into code */
777 int pnum
; /* Parameter number */
780 for (cptr
= choices
[i
]->code
; *cptr
&& bufptr
< bufend
;)
786 if (isdigit(*cptr
& 255))
789 * Substitute parameter...
792 pnum
= *cptr
++ - '0';
793 while (isdigit(*cptr
& 255))
794 pnum
= pnum
* 10 + *cptr
++ - '0';
796 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
798 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
799 if (cparam
->order
== pnum
)
804 switch (cparam
->type
)
806 case PPD_CUSTOM_CURVE
:
807 case PPD_CUSTOM_INVCURVE
:
808 case PPD_CUSTOM_POINTS
:
809 case PPD_CUSTOM_REAL
:
810 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
811 cparam
->current
.custom_real
,
815 case PPD_CUSTOM_INT
:
816 snprintf(bufptr
, (size_t)(bufend
- bufptr
), "%d", cparam
->current
.custom_int
);
817 bufptr
+= strlen(bufptr
);
820 case PPD_CUSTOM_PASSCODE
:
821 case PPD_CUSTOM_PASSWORD
:
822 case PPD_CUSTOM_STRING
:
823 if (cparam
->current
.custom_string
)
825 strlcpy(bufptr
, cparam
->current
.custom_string
, (size_t)(bufend
- bufptr
));
826 bufptr
+= strlen(bufptr
);
842 * Otherwise just copy the option code directly...
845 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
846 bufptr
+= strlen(bufptr
);
849 else if (section
!= PPD_ORDER_EXIT
)
852 * Add wrapper commands to prevent printer errors for unsupported
856 strlcpy(bufptr
, "[{\n", (size_t)(bufend
- bufptr
+ 1));
860 * Send DSC comments with option...
863 DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
864 choices
[i
]->option
->keyword
, choices
[i
]->choice
));
866 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
867 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
868 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
871 * Variable size; write out standard size options, using the
872 * parameter positions defined in the PPD file...
875 ppd_attr_t
*attr
; /* PPD attribute */
876 int pos
, /* Position of custom value */
877 orientation
; /* Orientation to use */
878 float values
[5]; /* Values for custom command */
881 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n", (size_t)(bufend
- bufptr
+ 1));
884 size
= ppdPageSize(ppd
, "Custom");
886 memset(values
, 0, sizeof(values
));
888 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
890 pos
= atoi(attr
->value
) - 1;
892 if (pos
< 0 || pos
> 4)
898 values
[pos
] = size
->width
;
900 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
902 pos
= atoi(attr
->value
) - 1;
904 if (pos
< 0 || pos
> 4)
910 values
[pos
] = size
->length
;
913 * According to the Adobe PPD specification, an orientation of 1
914 * will produce a print that comes out upside-down with the X
915 * axis perpendicular to the direction of feed, which is exactly
916 * what we want to be consistent with non-PS printers.
918 * We could also use an orientation of 3 to produce output that
919 * comes out rightside-up (this is the default for many large format
920 * printer PPDs), however for consistency we will stick with the
923 * If we wanted to get fancy, we could use orientations of 0 or
924 * 2 and swap the width and length, however we don't want to get
925 * fancy, we just want it to work consistently.
927 * The orientation value is range limited by the Orientation
928 * parameter definition, so certain non-PS printer drivers that
929 * only support an Orientation of 0 will get the value 0 as
935 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
936 "Orientation")) != NULL
)
938 int min_orient
, max_orient
; /* Minimum and maximum orientations */
941 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
948 if (pos
< 0 || pos
> 4)
951 if (orientation
> max_orient
)
952 orientation
= max_orient
;
953 else if (orientation
< min_orient
)
954 orientation
= min_orient
;
960 values
[pos
] = (float)orientation
;
962 for (pos
= 0; pos
< 5; pos
++)
964 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
968 if (!choices
[i
]->code
)
971 * This can happen with certain buggy PPD files that don't include
972 * a CustomPageSize command sequence... We just use a generic
973 * Level 2 command sequence...
976 strlcpy(bufptr
, ppd_custom_code
, (size_t)(bufend
- bufptr
+ 1));
977 bufptr
+= strlen(bufptr
);
980 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
981 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
988 const char *s
; /* Pointer into string value */
989 cups_array_t
*params
; /* Parameters in the correct output order */
992 params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
994 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
996 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
997 cupsArrayAdd(params
, cparam
);
999 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
1000 bufptr
+= strlen(bufptr
);
1002 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(params
);
1004 cparam
= (ppd_cparam_t
*)cupsArrayNext(params
))
1006 switch (cparam
->type
)
1008 case PPD_CUSTOM_CURVE
:
1009 case PPD_CUSTOM_INVCURVE
:
1010 case PPD_CUSTOM_POINTS
:
1011 case PPD_CUSTOM_REAL
:
1012 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
1013 cparam
->current
.custom_real
, loc
);
1017 case PPD_CUSTOM_INT
:
1018 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%d\n", cparam
->current
.custom_int
);
1019 bufptr
+= strlen(bufptr
);
1022 case PPD_CUSTOM_PASSCODE
:
1023 case PPD_CUSTOM_PASSWORD
:
1024 case PPD_CUSTOM_STRING
:
1027 if (cparam
->current
.custom_string
)
1029 for (s
= cparam
->current
.custom_string
; *s
; s
++)
1031 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
1033 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "\\%03o", *s
& 255);
1034 bufptr
+= strlen(bufptr
);
1047 cupsArrayDelete(params
);
1051 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *%s %s\n", choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1052 bufptr
+= strlen(bufptr
);
1055 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1057 j
= (int)strlen(choices
[i
]->code
);
1058 memcpy(bufptr
, choices
[i
]->code
, (size_t)j
);
1061 if (choices
[i
]->code
[j
- 1] != '\n')
1065 strlcpy(bufptr
, "%%EndFeature\n"
1066 "} stopped cleartomark\n", (size_t)(bufend
- bufptr
+ 1));
1067 bufptr
+= strlen(bufptr
);
1069 DEBUG_printf(("2ppdEmitString: Offset in string is %d...",
1070 (int)(bufptr
- buffer
)));
1074 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
1075 bufptr
+= strlen(bufptr
);
1079 * Nul-terminate, free, and return...
1091 * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
1094 static int /* O - Result of comparison */
1095 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
1096 ppd_cparam_t
*b
) /* I - Second parameter */
1098 return (a
->order
- b
->order
);
1103 * 'ppd_handle_media()' - Handle media selection...
1107 ppd_handle_media(ppd_file_t
*ppd
) /* I - PPD file */
1109 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1110 *input_slot
; /* InputSlot choice, if any */
1111 ppd_size_t
*size
; /* Current media size */
1112 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1116 * This function determines what page size code to use, if any, for the
1117 * current media size, InputSlot, and ManualFeed selections.
1119 * We use the PageSize code if:
1121 * 1. A custom media size is selected.
1122 * 2. ManualFeed and InputSlot are not selected (or do not exist).
1123 * 3. ManualFeed is selected but is False and InputSlot is not selected or
1124 * the selection has no code - the latter check done to support "auto" or
1125 * "printer default" InputSlot options.
1127 * We use the PageRegion code if:
1129 * 4. RequiresPageRegion does not exist and the PPD contains cupsFilter
1130 * keywords, indicating this is a CUPS-based driver.
1131 * 5. RequiresPageRegion exists for the selected InputSlot (or "All" for any
1132 * InputSlot or ManualFeed selection) and is True.
1134 * If none of the 5 conditions are true, no page size code is used and we
1135 * unmark any existing PageSize or PageRegion choices.
1138 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1141 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1142 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1144 if (input_slot
!= NULL
)
1145 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1150 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1152 if (!_cups_strcasecmp(size
->name
, "Custom") ||
1153 (!manual_feed
&& !input_slot
) ||
1154 (manual_feed
&& !_cups_strcasecmp(manual_feed
->choice
, "False") &&
1155 (!input_slot
|| (input_slot
->code
&& !input_slot
->code
[0]))) ||
1156 (!rpr
&& ppd
->num_filters
> 0))
1159 * Use PageSize code...
1162 ppdMarkOption(ppd
, "PageSize", size
->name
);
1164 else if (rpr
&& rpr
->value
&& !_cups_strcasecmp(rpr
->value
, "True"))
1167 * Use PageRegion code...
1170 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1175 * Do not use PageSize or PageRegion code...
1178 ppd_choice_t
*page
; /* PageSize/Region choice, if any */
1180 if ((page
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
1183 * Unmark PageSize...
1187 cupsArrayRemove(ppd
->marked
, page
);
1190 if ((page
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
1193 * Unmark PageRegion...
1197 cupsArrayRemove(ppd
->marked
, page
);