]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/ppd-emit.c
2 * PPD code emission routines for CUPS.
4 * Copyright 2007-2019 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
10 * PostScript is a trademark of Adobe Systems, Inc.
14 * Include necessary headers...
17 #include "cups-private.h"
18 #include "debug-internal.h"
20 #if defined(_WIN32) || defined(__EMX__)
24 #endif /* _WIN32 || __EMX__ */
31 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
32 static void ppd_handle_media(ppd_file_t
*ppd
);
39 static const char ppd_custom_code
[] =
41 "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
45 * 'ppdCollect()' - Collect all marked options that reside in the specified
48 * The choices array should be freed using @code free@ when you are
52 int /* O - Number of options marked */
53 ppdCollect(ppd_file_t
*ppd
, /* I - PPD file data */
54 ppd_section_t section
, /* I - Section to collect */
55 ppd_choice_t
***choices
) /* O - Pointers to choices */
57 return (ppdCollect2(ppd
, section
, 0.0, choices
));
62 * 'ppdCollect2()' - Collect all marked options that reside in the
63 * specified section and minimum order.
65 * The choices array should be freed using @code free@ when you are
68 * @since CUPS 1.2/macOS 10.5@
71 int /* O - Number of options marked */
72 ppdCollect2(ppd_file_t
*ppd
, /* I - PPD file data */
73 ppd_section_t section
, /* I - Section to collect */
74 float min_order
, /* I - Minimum OrderDependency value */
75 ppd_choice_t
***choices
) /* O - Pointers to choices */
77 ppd_choice_t
*c
; /* Current choice */
78 ppd_section_t csection
; /* Current section */
79 float corder
; /* Current OrderDependency value */
80 int count
; /* Number of choices collected */
81 ppd_choice_t
**collect
; /* Collected choices */
82 float *orders
; /* Collected order values */
85 DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)",
86 ppd
, section
, min_order
, choices
));
97 * Allocate memory for up to N selected choices...
101 if ((collect
= calloc(sizeof(ppd_choice_t
*),
102 (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
108 if ((orders
= calloc(sizeof(float), (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
116 * Loop through all options and add choices as needed...
119 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
121 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
123 csection
= c
->option
->section
;
124 corder
= c
->option
->order
;
126 if (!strcmp(c
->choice
, "Custom"))
128 ppd_attr_t
*attr
; /* NonUIOrderDependency value */
129 float aorder
; /* Order value */
130 char asection
[17], /* Section name */
131 amain
[PPD_MAX_NAME
+ 1],
132 aoption
[PPD_MAX_NAME
];
133 /* *CustomFoo and True */
136 for (attr
= ppdFindAttr(ppd
, "NonUIOrderDependency", NULL
);
138 attr
= ppdFindNextAttr(ppd
, "NonUIOrderDependency", NULL
))
140 sscanf(attr
->value
, "%f%16s%41s%40s", &aorder
, asection
, amain
,
142 !strncmp(amain
, "*Custom", 7) &&
143 !strcmp(amain
+ 7, c
->option
->keyword
) && !strcmp(aoption
, "True"))
146 * Use this NonUIOrderDependency...
151 if (!strcmp(asection
, "DocumentSetup"))
152 csection
= PPD_ORDER_DOCUMENT
;
153 else if (!strcmp(asection
, "ExitServer"))
154 csection
= PPD_ORDER_EXIT
;
155 else if (!strcmp(asection
, "JCLSetup"))
156 csection
= PPD_ORDER_JCL
;
157 else if (!strcmp(asection
, "PageSetup"))
158 csection
= PPD_ORDER_PAGE
;
159 else if (!strcmp(asection
, "Prolog"))
160 csection
= PPD_ORDER_PROLOG
;
162 csection
= PPD_ORDER_ANY
;
168 if (csection
== section
&& corder
>= min_order
)
171 orders
[count
] = corder
;
177 * If we have more than 1 marked choice, sort them...
182 int i
, j
; /* Looping vars */
184 for (i
= 0; i
< (count
- 1); i
++)
185 for (j
= i
+ 1; j
< count
; j
++)
186 if (orders
[i
] > orders
[j
])
190 collect
[i
] = collect
[j
];
191 orders
[i
] = orders
[j
];
199 DEBUG_printf(("2ppdCollect2: %d marked choices...", count
));
202 * Return the array and number of choices; if 0, free the array since
221 * 'ppdEmit()' - Emit code for marked options to a file.
224 int /* O - 0 on success, -1 on failure */
225 ppdEmit(ppd_file_t
*ppd
, /* I - PPD file record */
226 FILE *fp
, /* I - File to write to */
227 ppd_section_t section
) /* I - Section to write */
229 return (ppdEmitAfterOrder(ppd
, fp
, section
, 0, 0.0));
234 * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
236 * When "limit" is non-zero, this function only emits options whose
237 * OrderDependency value is greater than or equal to "min_order".
239 * When "limit" is zero, this function is identical to ppdEmit().
241 * @since CUPS 1.2/macOS 10.5@
244 int /* O - 0 on success, -1 on failure */
246 ppd_file_t
*ppd
, /* I - PPD file record */
247 FILE *fp
, /* I - File to write to */
248 ppd_section_t section
, /* I - Section to write */
249 int limit
, /* I - Non-zero to use min_order */
250 float min_order
) /* I - Lowest OrderDependency */
252 char *buffer
; /* Option code */
253 int status
; /* Return status */
257 * Range check input...
267 buffer
= ppdEmitString(ppd
, section
, limit
? min_order
: 0.0f
);
270 * Write it as needed and return...
275 status
= fputs(buffer
, fp
) < 0 ? -1 : 0;
287 * 'ppdEmitFd()' - Emit code for marked options to a file.
290 int /* O - 0 on success, -1 on failure */
291 ppdEmitFd(ppd_file_t
*ppd
, /* I - PPD file record */
292 int fd
, /* I - File to write to */
293 ppd_section_t section
) /* I - Section to write */
295 char *buffer
, /* Option code */
296 *bufptr
; /* Pointer into code */
297 size_t buflength
; /* Length of option code */
298 ssize_t bytes
; /* Bytes written */
299 int status
; /* Return status */
303 * Range check input...
313 buffer
= ppdEmitString(ppd
, section
, 0.0);
316 * Write it as needed and return...
321 buflength
= strlen(buffer
);
325 while (buflength
> 0)
328 if ((bytes
= (ssize_t
)write(fd
, bufptr
, (unsigned)buflength
)) < 0)
330 if ((bytes
= write(fd
, bufptr
, buflength
)) < 0)
333 if (errno
== EAGAIN
|| errno
== EINTR
)
339 buflength
-= (size_t)bytes
;
343 status
= bytes
< 0 ? -1 : 0;
355 * 'ppdEmitJCL()' - Emit code for JCL options to a file.
358 int /* O - 0 on success, -1 on failure */
359 ppdEmitJCL(ppd_file_t
*ppd
, /* I - PPD file record */
360 FILE *fp
, /* I - File to write to */
361 int job_id
, /* I - Job ID */
362 const char *user
, /* I - Username */
363 const char *title
) /* I - Title */
365 char *ptr
; /* Pointer into JCL string */
366 char temp
[65], /* Local title string */
367 displaymsg
[33]; /* Local display string */
371 * Range check the input...
374 if (!ppd
|| !ppd
->jcl_begin
|| !ppd
->jcl_ps
)
378 * See if the printer supports HP PJL...
381 if (!strncmp(ppd
->jcl_begin
, "\033%-12345X@", 10))
384 * This printer uses HP PJL commands for output; filter the output
385 * so that we only have a single "@PJL JOB" command in the header...
387 * To avoid bugs in the PJL implementation of certain vendors' products
388 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
389 * of the PJL commands to initialize PJL processing.
392 ppd_attr_t
*charset
; /* PJL charset */
393 ppd_attr_t
*display
; /* PJL display command */
396 if ((charset
= ppdFindAttr(ppd
, "cupsPJLCharset", NULL
)) != NULL
)
398 if (!charset
->value
|| _cups_strcasecmp(charset
->value
, "UTF-8"))
402 if ((display
= ppdFindAttr(ppd
, "cupsPJLDisplay", NULL
)) != NULL
)
408 fputs("\033%-12345X@PJL\n", fp
);
409 for (ptr
= ppd
->jcl_begin
+ 9; *ptr
;)
410 if (!strncmp(ptr
, "@PJL JOB", 8))
413 * Skip job command...
441 * Clean up the job title...
447 if ((ptr
= strrchr(title
, '/')) != NULL
)
450 * Only show basename of file path...
456 if (!strncmp(title
, "smbprn.", 7))
459 * Skip leading smbprn.######## from Samba jobs...
462 for (title
+= 7; *title
&& isdigit(*title
& 255); title
++);
463 while (_cups_isspace(*title
))
466 if ((ptr
= strstr(title
, " - ")) != NULL
)
469 * Skip application name in "Some Application - Title of job"...
477 * Replace double quotes with single quotes and UTF-8 characters with
478 * question marks so that the title does not cause a PJL syntax error.
481 strlcpy(temp
, title
, sizeof(temp
));
483 for (ptr
= temp
; *ptr
; ptr
++)
486 else if (!charset
&& (*ptr
& 128))
490 * CUPS STR #3125: Long PJL JOB NAME causes problems with some printers
492 * Generate the display message, truncating at 32 characters + nul to avoid
493 * issues with some printer's PJL implementations...
499 snprintf(displaymsg
, sizeof(displaymsg
), "%d %s %s", job_id
, user
, temp
);
502 * Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
505 if (display
&& strcmp(display
->value
, "job"))
506 fprintf(fp
, "@PJL JOB NAME = \"%s\"\n", temp
);
507 else if (display
&& !strcmp(display
->value
, "rdymsg"))
508 fprintf(fp
, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg
);
510 fprintf(fp
, "@PJL JOB NAME = \"%s\" DISPLAY = \"%s\"\n", temp
,
514 * Replace double quotes with single quotes and UTF-8 characters with
515 * question marks so that the user does not cause a PJL syntax error.
518 strlcpy(temp
, user
, sizeof(temp
));
520 for (ptr
= temp
; *ptr
; ptr
++)
523 else if (!charset
&& (*ptr
& 128))
526 fprintf(fp
, "@PJL SET USERNAME = \"%s\"\n", temp
);
529 fputs(ppd
->jcl_begin
, fp
);
531 ppdEmit(ppd
, fp
, PPD_ORDER_JCL
);
532 fputs(ppd
->jcl_ps
, fp
);
539 * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
541 * @since CUPS 1.2/macOS 10.5@
544 int /* O - 0 on success, -1 on failure */
545 ppdEmitJCLEnd(ppd_file_t
*ppd
, /* I - PPD file record */
546 FILE *fp
) /* I - File to write to */
549 * Range check the input...
557 if (ppd
->num_filters
== 0)
564 * See if the printer supports HP PJL...
567 if (!strncmp(ppd
->jcl_end
, "\033%-12345X@", 10))
570 * This printer uses HP PJL commands for output; filter the output
571 * so that we only have a single "@PJL JOB" command in the header...
573 * To avoid bugs in the PJL implementation of certain vendors' products
574 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
575 * of the PJL commands to initialize PJL processing.
578 fputs("\033%-12345X@PJL\n", fp
);
579 fputs("@PJL RDYMSG DISPLAY = \"\"\n", fp
);
580 fputs(ppd
->jcl_end
+ 9, fp
);
583 fputs(ppd
->jcl_end
, fp
);
590 * 'ppdEmitString()' - Get a string containing the code for marked options.
592 * When "min_order" is greater than zero, this function only includes options
593 * whose OrderDependency value is greater than or equal to "min_order".
594 * Otherwise, all options in the specified section are included in the
597 * The return string is allocated on the heap and should be freed using
598 * @code free@ when you are done with it.
600 * @since CUPS 1.2/macOS 10.5@
603 char * /* O - String containing option code or @code NULL@ if there is no option code */
604 ppdEmitString(ppd_file_t
*ppd
, /* I - PPD file record */
605 ppd_section_t section
, /* I - Section to write */
606 float min_order
) /* I - Lowest OrderDependency */
608 int i
, j
, /* Looping vars */
609 count
; /* Number of choices */
610 ppd_choice_t
**choices
; /* Choices */
611 ppd_size_t
*size
; /* Custom page size */
612 ppd_coption_t
*coption
; /* Custom option */
613 ppd_cparam_t
*cparam
; /* Custom parameter */
614 size_t bufsize
; /* Size of string buffer needed */
615 char *buffer
, /* String buffer */
616 *bufptr
, /* Pointer into buffer */
617 *bufend
; /* End of buffer */
618 struct lconv
*loc
; /* Locale data */
621 DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)",
622 ppd
, section
, min_order
));
625 * Range check input...
632 * Use PageSize or PageRegion as required...
635 ppd_handle_media(ppd
);
638 * Collect the options we need to emit...
641 if ((count
= ppdCollect2(ppd
, section
, min_order
, &choices
)) == 0)
645 * Count the number of bytes that are required to hold all of the
649 for (i
= 0, bufsize
= 1; i
< count
; i
++)
651 if (section
== PPD_ORDER_JCL
)
653 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
654 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
658 * Add space to account for custom parameter substitution...
661 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
663 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
665 switch (cparam
->type
)
667 case PPD_CUSTOM_CURVE
:
668 case PPD_CUSTOM_INVCURVE
:
669 case PPD_CUSTOM_POINTS
:
670 case PPD_CUSTOM_REAL
:
671 case PPD_CUSTOM_INT
:
675 case PPD_CUSTOM_PASSCODE
:
676 case PPD_CUSTOM_PASSWORD
:
677 case PPD_CUSTOM_STRING
:
678 if (cparam
->current
.custom_string
)
679 bufsize
+= strlen(cparam
->current
.custom_string
);
685 else if (section
!= PPD_ORDER_EXIT
)
687 bufsize
+= 3; /* [{\n */
689 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
690 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
691 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
693 DEBUG_puts("2ppdEmitString: Custom size set!");
695 bufsize
+= 37; /* %%BeginFeature: *CustomPageSize True\n */
696 bufsize
+= 50; /* Five 9-digit numbers + newline */
698 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
699 (coption
= ppdFindCustomOption(ppd
,
700 choices
[i
]->option
->keyword
))
703 bufsize
+= 23 + strlen(choices
[i
]->option
->keyword
) + 6;
704 /* %%BeginFeature: *Customkeyword True\n */
707 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
709 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
711 switch (cparam
->type
)
713 case PPD_CUSTOM_CURVE
:
714 case PPD_CUSTOM_INVCURVE
:
715 case PPD_CUSTOM_POINTS
:
716 case PPD_CUSTOM_REAL
:
717 case PPD_CUSTOM_INT
:
721 case PPD_CUSTOM_PASSCODE
:
722 case PPD_CUSTOM_PASSWORD
:
723 case PPD_CUSTOM_STRING
:
725 if (cparam
->current
.custom_string
)
726 bufsize
+= 4 * strlen(cparam
->current
.custom_string
);
732 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 1 +
733 strlen(choices
[i
]->choice
) + 1;
734 /* %%BeginFeature: *keyword choice\n */
736 bufsize
+= 13; /* %%EndFeature\n */
737 bufsize
+= 22; /* } stopped cleartomark\n */
740 if (choices
[i
]->code
)
741 bufsize
+= strlen(choices
[i
]->code
) + 1;
743 bufsize
+= strlen(ppd_custom_code
);
750 DEBUG_printf(("2ppdEmitString: Allocating %d bytes for string...",
753 if ((buffer
= calloc(1, bufsize
)) == NULL
)
759 bufend
= buffer
+ bufsize
- 1;
763 * Copy the option code to the buffer...
766 for (i
= 0, bufptr
= buffer
; i
< count
; i
++, bufptr
+= strlen(bufptr
))
767 if (section
== PPD_ORDER_JCL
)
769 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
771 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
775 * Handle substitutions in custom JCL options...
778 char *cptr
; /* Pointer into code */
779 int pnum
; /* Parameter number */
782 for (cptr
= choices
[i
]->code
; *cptr
&& bufptr
< bufend
;)
788 if (isdigit(*cptr
& 255))
791 * Substitute parameter...
794 pnum
= *cptr
++ - '0';
795 while (isdigit(*cptr
& 255))
796 pnum
= pnum
* 10 + *cptr
++ - '0';
798 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
800 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
801 if (cparam
->order
== pnum
)
806 switch (cparam
->type
)
808 case PPD_CUSTOM_CURVE
:
809 case PPD_CUSTOM_INVCURVE
:
810 case PPD_CUSTOM_POINTS
:
811 case PPD_CUSTOM_REAL
:
812 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
813 cparam
->current
.custom_real
,
817 case PPD_CUSTOM_INT
:
818 snprintf(bufptr
, (size_t)(bufend
- bufptr
), "%d", cparam
->current
.custom_int
);
819 bufptr
+= strlen(bufptr
);
822 case PPD_CUSTOM_PASSCODE
:
823 case PPD_CUSTOM_PASSWORD
:
824 case PPD_CUSTOM_STRING
:
825 if (cparam
->current
.custom_string
)
827 strlcpy(bufptr
, cparam
->current
.custom_string
, (size_t)(bufend
- bufptr
));
828 bufptr
+= strlen(bufptr
);
841 else if (choices
[i
]->code
)
844 * Otherwise just copy the option code directly...
847 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
848 bufptr
+= strlen(bufptr
);
851 else if (section
!= PPD_ORDER_EXIT
)
854 * Add wrapper commands to prevent printer errors for unsupported
858 strlcpy(bufptr
, "[{\n", (size_t)(bufend
- bufptr
+ 1));
862 * Send DSC comments with option...
865 DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
866 choices
[i
]->option
->keyword
, choices
[i
]->choice
));
868 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
869 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
870 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
873 * Variable size; write out standard size options, using the
874 * parameter positions defined in the PPD file...
877 ppd_attr_t
*attr
; /* PPD attribute */
878 int pos
, /* Position of custom value */
879 orientation
; /* Orientation to use */
880 float values
[5]; /* Values for custom command */
883 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n", (size_t)(bufend
- bufptr
+ 1));
886 size
= ppdPageSize(ppd
, "Custom");
888 memset(values
, 0, sizeof(values
));
890 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
892 pos
= atoi(attr
->value
) - 1;
894 if (pos
< 0 || pos
> 4)
900 values
[pos
] = size
->width
;
902 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
904 pos
= atoi(attr
->value
) - 1;
906 if (pos
< 0 || pos
> 4)
912 values
[pos
] = size
->length
;
915 * According to the Adobe PPD specification, an orientation of 1
916 * will produce a print that comes out upside-down with the X
917 * axis perpendicular to the direction of feed, which is exactly
918 * what we want to be consistent with non-PS printers.
920 * We could also use an orientation of 3 to produce output that
921 * comes out rightside-up (this is the default for many large format
922 * printer PPDs), however for consistency we will stick with the
925 * If we wanted to get fancy, we could use orientations of 0 or
926 * 2 and swap the width and length, however we don't want to get
927 * fancy, we just want it to work consistently.
929 * The orientation value is range limited by the Orientation
930 * parameter definition, so certain non-PS printer drivers that
931 * only support an Orientation of 0 will get the value 0 as
937 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
938 "Orientation")) != NULL
)
940 int min_orient
, max_orient
; /* Minimum and maximum orientations */
943 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
950 if (pos
< 0 || pos
> 4)
953 if (orientation
> max_orient
)
954 orientation
= max_orient
;
955 else if (orientation
< min_orient
)
956 orientation
= min_orient
;
962 values
[pos
] = (float)orientation
;
964 for (pos
= 0; pos
< 5; pos
++)
966 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
970 if (!choices
[i
]->code
)
973 * This can happen with certain buggy PPD files that don't include
974 * a CustomPageSize command sequence... We just use a generic
975 * Level 2 command sequence...
978 strlcpy(bufptr
, ppd_custom_code
, (size_t)(bufend
- bufptr
+ 1));
979 bufptr
+= strlen(bufptr
);
982 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
983 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
990 const char *s
; /* Pointer into string value */
991 cups_array_t
*params
; /* Parameters in the correct output order */
994 params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
996 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
998 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
999 cupsArrayAdd(params
, cparam
);
1001 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
1002 bufptr
+= strlen(bufptr
);
1004 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(params
);
1006 cparam
= (ppd_cparam_t
*)cupsArrayNext(params
))
1008 switch (cparam
->type
)
1010 case PPD_CUSTOM_CURVE
:
1011 case PPD_CUSTOM_INVCURVE
:
1012 case PPD_CUSTOM_POINTS
:
1013 case PPD_CUSTOM_REAL
:
1014 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
1015 cparam
->current
.custom_real
, loc
);
1019 case PPD_CUSTOM_INT
:
1020 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%d\n", cparam
->current
.custom_int
);
1021 bufptr
+= strlen(bufptr
);
1024 case PPD_CUSTOM_PASSCODE
:
1025 case PPD_CUSTOM_PASSWORD
:
1026 case PPD_CUSTOM_STRING
:
1029 if (cparam
->current
.custom_string
)
1031 for (s
= cparam
->current
.custom_string
; *s
; s
++)
1033 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
1035 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "\\%03o", *s
& 255);
1036 bufptr
+= strlen(bufptr
);
1049 cupsArrayDelete(params
);
1053 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *%s %s\n", choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1054 bufptr
+= strlen(bufptr
);
1057 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1059 j
= (int)strlen(choices
[i
]->code
);
1060 memcpy(bufptr
, choices
[i
]->code
, (size_t)j
);
1063 if (choices
[i
]->code
[j
- 1] != '\n')
1067 strlcpy(bufptr
, "%%EndFeature\n"
1068 "} stopped cleartomark\n", (size_t)(bufend
- bufptr
+ 1));
1069 bufptr
+= strlen(bufptr
);
1071 DEBUG_printf(("2ppdEmitString: Offset in string is %d...",
1072 (int)(bufptr
- buffer
)));
1074 else if (choices
[i
]->code
)
1076 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
1077 bufptr
+= strlen(bufptr
);
1081 * Nul-terminate, free, and return...
1093 * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
1096 static int /* O - Result of comparison */
1097 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
1098 ppd_cparam_t
*b
) /* I - Second parameter */
1100 return (a
->order
- b
->order
);
1105 * 'ppd_handle_media()' - Handle media selection...
1109 ppd_handle_media(ppd_file_t
*ppd
) /* I - PPD file */
1111 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1112 *input_slot
; /* InputSlot choice, if any */
1113 ppd_size_t
*size
; /* Current media size */
1114 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1118 * This function determines what page size code to use, if any, for the
1119 * current media size, InputSlot, and ManualFeed selections.
1121 * We use the PageSize code if:
1123 * 1. A custom media size is selected.
1124 * 2. ManualFeed and InputSlot are not selected (or do not exist).
1125 * 3. ManualFeed is selected but is False and InputSlot is not selected or
1126 * the selection has no code - the latter check done to support "auto" or
1127 * "printer default" InputSlot options.
1129 * We use the PageRegion code if:
1131 * 4. RequiresPageRegion does not exist and the PPD contains cupsFilter
1132 * keywords, indicating this is a CUPS-based driver.
1133 * 5. RequiresPageRegion exists for the selected InputSlot (or "All" for any
1134 * InputSlot or ManualFeed selection) and is True.
1136 * If none of the 5 conditions are true, no page size code is used and we
1137 * unmark any existing PageSize or PageRegion choices.
1140 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1143 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1144 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1146 if (input_slot
!= NULL
)
1147 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1152 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1154 if (!_cups_strcasecmp(size
->name
, "Custom") ||
1155 (!manual_feed
&& !input_slot
) ||
1156 (manual_feed
&& !_cups_strcasecmp(manual_feed
->choice
, "False") &&
1157 (!input_slot
|| (input_slot
->code
&& !input_slot
->code
[0]))) ||
1158 (!rpr
&& ppd
->num_filters
> 0))
1161 * Use PageSize code...
1164 ppdMarkOption(ppd
, "PageSize", size
->name
);
1166 else if (rpr
&& rpr
->value
&& !_cups_strcasecmp(rpr
->value
, "True"))
1169 * Use PageRegion code...
1172 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1177 * Do not use PageSize or PageRegion code...
1180 ppd_choice_t
*page
; /* PageSize/Region choice, if any */
1182 if ((page
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
1185 * Unmark PageSize...
1189 cupsArrayRemove(ppd
->marked
, page
);
1192 if ((page
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
1195 * Unmark PageRegion...
1199 cupsArrayRemove(ppd
->marked
, page
);