]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/emit.c
4 * PPD code emission routines for CUPS.
6 * Copyright 2007-2014 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 * Include necessary headers...
24 #include "cups-private.h"
25 #if defined(WIN32) || defined(__EMX__)
29 #endif /* WIN32 || __EMX__ */
36 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
37 static void ppd_handle_media(ppd_file_t
*ppd
);
44 static const char ppd_custom_code
[] =
46 "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
50 * 'ppdCollect()' - Collect all marked options that reside in the specified
53 * The choices array should be freed using @code free@ when you are
57 int /* O - Number of options marked */
58 ppdCollect(ppd_file_t
*ppd
, /* I - PPD file data */
59 ppd_section_t section
, /* I - Section to collect */
60 ppd_choice_t
***choices
) /* O - Pointers to choices */
62 return (ppdCollect2(ppd
, section
, 0.0, choices
));
67 * 'ppdCollect2()' - Collect all marked options that reside in the
68 * specified section and minimum order.
70 * The choices array should be freed using @code free@ when you are
73 * @since CUPS 1.2/OS X 10.5@
76 int /* O - Number of options marked */
77 ppdCollect2(ppd_file_t
*ppd
, /* I - PPD file data */
78 ppd_section_t section
, /* I - Section to collect */
79 float min_order
, /* I - Minimum OrderDependency value */
80 ppd_choice_t
***choices
) /* O - Pointers to choices */
82 ppd_choice_t
*c
; /* Current choice */
83 ppd_section_t csection
; /* Current section */
84 float corder
; /* Current OrderDependency value */
85 int count
; /* Number of choices collected */
86 ppd_choice_t
**collect
; /* Collected choices */
87 float *orders
; /* Collected order values */
90 DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)",
91 ppd
, section
, min_order
, choices
));
102 * Allocate memory for up to N selected choices...
106 if ((collect
= calloc(sizeof(ppd_choice_t
*),
107 (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
113 if ((orders
= calloc(sizeof(float), (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
121 * Loop through all options and add choices as needed...
124 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
126 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
128 csection
= c
->option
->section
;
129 corder
= c
->option
->order
;
131 if (!strcmp(c
->choice
, "Custom"))
133 ppd_attr_t
*attr
; /* NonUIOrderDependency value */
134 float aorder
; /* Order value */
135 char asection
[17], /* Section name */
136 amain
[PPD_MAX_NAME
+ 1],
137 aoption
[PPD_MAX_NAME
];
138 /* *CustomFoo and True */
141 for (attr
= ppdFindAttr(ppd
, "NonUIOrderDependency", NULL
);
143 attr
= ppdFindNextAttr(ppd
, "NonUIOrderDependency", NULL
))
145 sscanf(attr
->value
, "%f%16s%41s%40s", &aorder
, asection
, amain
,
147 !strncmp(amain
, "*Custom", 7) &&
148 !strcmp(amain
+ 7, c
->option
->keyword
) && !strcmp(aoption
, "True"))
151 * Use this NonUIOrderDependency...
156 if (!strcmp(asection
, "DocumentSetup"))
157 csection
= PPD_ORDER_DOCUMENT
;
158 else if (!strcmp(asection
, "ExitServer"))
159 csection
= PPD_ORDER_EXIT
;
160 else if (!strcmp(asection
, "JCLSetup"))
161 csection
= PPD_ORDER_JCL
;
162 else if (!strcmp(asection
, "PageSetup"))
163 csection
= PPD_ORDER_PAGE
;
164 else if (!strcmp(asection
, "Prolog"))
165 csection
= PPD_ORDER_PROLOG
;
167 csection
= PPD_ORDER_ANY
;
173 if (csection
== section
&& corder
>= min_order
)
176 orders
[count
] = corder
;
182 * If we have more than 1 marked choice, sort them...
187 int i
, j
; /* Looping vars */
189 for (i
= 0; i
< (count
- 1); i
++)
190 for (j
= i
+ 1; j
< count
; j
++)
191 if (orders
[i
] > orders
[j
])
195 collect
[i
] = collect
[j
];
196 orders
[i
] = orders
[j
];
204 DEBUG_printf(("2ppdCollect2: %d marked choices...", count
));
207 * Return the array and number of choices; if 0, free the array since
226 * 'ppdEmit()' - Emit code for marked options to a file.
229 int /* O - 0 on success, -1 on failure */
230 ppdEmit(ppd_file_t
*ppd
, /* I - PPD file record */
231 FILE *fp
, /* I - File to write to */
232 ppd_section_t section
) /* I - Section to write */
234 return (ppdEmitAfterOrder(ppd
, fp
, section
, 0, 0.0));
239 * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
241 * When "limit" is non-zero, this function only emits options whose
242 * OrderDependency value is greater than or equal to "min_order".
244 * When "limit" is zero, this function is identical to ppdEmit().
246 * @since CUPS 1.2/OS X 10.5@
249 int /* O - 0 on success, -1 on failure */
251 ppd_file_t
*ppd
, /* I - PPD file record */
252 FILE *fp
, /* I - File to write to */
253 ppd_section_t section
, /* I - Section to write */
254 int limit
, /* I - Non-zero to use min_order */
255 float min_order
) /* I - Lowest OrderDependency */
257 char *buffer
; /* Option code */
258 int status
; /* Return status */
262 * Range check input...
272 buffer
= ppdEmitString(ppd
, section
, limit
? min_order
: 0.0f
);
275 * Write it as needed and return...
280 status
= fputs(buffer
, fp
) < 0 ? -1 : 0;
292 * 'ppdEmitFd()' - Emit code for marked options to a file.
295 int /* O - 0 on success, -1 on failure */
296 ppdEmitFd(ppd_file_t
*ppd
, /* I - PPD file record */
297 int fd
, /* I - File to write to */
298 ppd_section_t section
) /* I - Section to write */
300 char *buffer
, /* Option code */
301 *bufptr
; /* Pointer into code */
302 size_t buflength
; /* Length of option code */
303 ssize_t bytes
; /* Bytes written */
304 int status
; /* Return status */
308 * Range check input...
318 buffer
= ppdEmitString(ppd
, section
, 0.0);
321 * Write it as needed and return...
326 buflength
= strlen(buffer
);
330 while (buflength
> 0)
333 if ((bytes
= (ssize_t
)write(fd
, bufptr
, (unsigned)buflength
)) < 0)
335 if ((bytes
= write(fd
, bufptr
, buflength
)) < 0)
338 if (errno
== EAGAIN
|| errno
== EINTR
)
344 buflength
-= (size_t)bytes
;
348 status
= bytes
< 0 ? -1 : 0;
360 * 'ppdEmitJCL()' - Emit code for JCL options to a file.
363 int /* O - 0 on success, -1 on failure */
364 ppdEmitJCL(ppd_file_t
*ppd
, /* I - PPD file record */
365 FILE *fp
, /* I - File to write to */
366 int job_id
, /* I - Job ID */
367 const char *user
, /* I - Username */
368 const char *title
) /* I - Title */
370 char *ptr
; /* Pointer into JCL string */
371 char temp
[65], /* Local title string */
372 displaymsg
[33]; /* Local display string */
376 * Range check the input...
379 if (!ppd
|| !ppd
->jcl_begin
|| !ppd
->jcl_ps
)
383 * See if the printer supports HP PJL...
386 if (!strncmp(ppd
->jcl_begin
, "\033%-12345X@", 10))
389 * This printer uses HP PJL commands for output; filter the output
390 * so that we only have a single "@PJL JOB" command in the header...
392 * To avoid bugs in the PJL implementation of certain vendors' products
393 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
394 * of the PJL commands to initialize PJL processing.
397 ppd_attr_t
*charset
; /* PJL charset */
398 ppd_attr_t
*display
; /* PJL display command */
401 if ((charset
= ppdFindAttr(ppd
, "cupsPJLCharset", NULL
)) != NULL
)
403 if (!charset
->value
|| _cups_strcasecmp(charset
->value
, "UTF-8"))
407 if ((display
= ppdFindAttr(ppd
, "cupsPJLDisplay", NULL
)) != NULL
)
413 fputs("\033%-12345X@PJL\n", fp
);
414 for (ptr
= ppd
->jcl_begin
+ 9; *ptr
;)
415 if (!strncmp(ptr
, "@PJL JOB", 8))
418 * Skip job command...
446 * Clean up the job title...
449 if ((ptr
= strrchr(title
, '/')) != NULL
)
452 * Only show basename of file path...
458 if (!strncmp(title
, "smbprn.", 7))
461 * Skip leading smbprn.######## from Samba jobs...
464 for (title
+= 7; *title
&& isdigit(*title
& 255); title
++);
465 while (_cups_isspace(*title
))
468 if ((ptr
= strstr(title
, " - ")) != NULL
)
471 * Skip application name in "Some Application - Title of job"...
479 * Replace double quotes with single quotes and UTF-8 characters with
480 * question marks so that the title does not cause a PJL syntax error.
483 strlcpy(temp
, title
, sizeof(temp
));
485 for (ptr
= temp
; *ptr
; ptr
++)
488 else if (!charset
&& (*ptr
& 128))
492 * CUPS STR #3125: Long PJL JOB NAME causes problems with some printers
494 * Generate the display message, truncating at 32 characters + nul to avoid
495 * issues with some printer's PJL implementations...
498 snprintf(displaymsg
, sizeof(displaymsg
), "%d %s %s", job_id
, user
, temp
);
501 * Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
504 if (display
&& strcmp(display
->value
, "job"))
505 fprintf(fp
, "@PJL JOB NAME = \"%s\"\n", temp
);
506 else if (display
&& !strcmp(display
->value
, "rdymsg"))
507 fprintf(fp
, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg
);
509 fprintf(fp
, "@PJL JOB NAME = \"%s\" DISPLAY = \"%s\"\n", temp
,
513 * Replace double quotes with single quotes and UTF-8 characters with
514 * question marks so that the user does not cause a PJL syntax error.
517 strlcpy(temp
, user
, sizeof(temp
));
519 for (ptr
= temp
; *ptr
; ptr
++)
522 else if (!charset
&& (*ptr
& 128))
525 fprintf(fp
, "@PJL SET USERNAME = \"%s\"\n", temp
);
528 fputs(ppd
->jcl_begin
, fp
);
530 ppdEmit(ppd
, fp
, PPD_ORDER_JCL
);
531 fputs(ppd
->jcl_ps
, fp
);
538 * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
540 * @since CUPS 1.2/OS X 10.5@
543 int /* O - 0 on success, -1 on failure */
544 ppdEmitJCLEnd(ppd_file_t
*ppd
, /* I - PPD file record */
545 FILE *fp
) /* I - File to write to */
548 * Range check the input...
556 if (ppd
->num_filters
== 0)
563 * See if the printer supports HP PJL...
566 if (!strncmp(ppd
->jcl_end
, "\033%-12345X@", 10))
569 * This printer uses HP PJL commands for output; filter the output
570 * so that we only have a single "@PJL JOB" command in the header...
572 * To avoid bugs in the PJL implementation of certain vendors' products
573 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
574 * of the PJL commands to initialize PJL processing.
577 fputs("\033%-12345X@PJL\n", fp
);
578 fputs("@PJL RDYMSG DISPLAY = \"\"\n", fp
);
579 fputs(ppd
->jcl_end
+ 9, fp
);
582 fputs(ppd
->jcl_end
, fp
);
589 * 'ppdEmitString()' - Get a string containing the code for marked options.
591 * When "min_order" is greater than zero, this function only includes options
592 * whose OrderDependency value is greater than or equal to "min_order".
593 * Otherwise, all options in the specified section are included in the
596 * The return string is allocated on the heap and should be freed using
597 * @code free@ when you are done with it.
599 * @since CUPS 1.2/OS X 10.5@
602 char * /* O - String containing option code or @code NULL@ if there is no option code */
603 ppdEmitString(ppd_file_t
*ppd
, /* I - PPD file record */
604 ppd_section_t section
, /* I - Section to write */
605 float min_order
) /* I - Lowest OrderDependency */
607 int i
, j
, /* Looping vars */
608 count
; /* Number of choices */
609 ppd_choice_t
**choices
; /* Choices */
610 ppd_size_t
*size
; /* Custom page size */
611 ppd_coption_t
*coption
; /* Custom option */
612 ppd_cparam_t
*cparam
; /* Custom parameter */
613 size_t bufsize
; /* Size of string buffer needed */
614 char *buffer
, /* String buffer */
615 *bufptr
, /* Pointer into buffer */
616 *bufend
; /* End of buffer */
617 struct lconv
*loc
; /* Locale data */
620 DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)",
621 ppd
, section
, min_order
));
624 * Range check input...
631 * Use PageSize or PageRegion as required...
634 ppd_handle_media(ppd
);
637 * Collect the options we need to emit...
640 if ((count
= ppdCollect2(ppd
, section
, min_order
, &choices
)) == 0)
644 * Count the number of bytes that are required to hold all of the
648 for (i
= 0, bufsize
= 1; i
< count
; i
++)
650 if (section
== PPD_ORDER_JCL
)
652 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
653 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
657 * Add space to account for custom parameter substitution...
660 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
662 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
664 switch (cparam
->type
)
666 case PPD_CUSTOM_CURVE
:
667 case PPD_CUSTOM_INVCURVE
:
668 case PPD_CUSTOM_POINTS
:
669 case PPD_CUSTOM_REAL
:
670 case PPD_CUSTOM_INT
:
674 case PPD_CUSTOM_PASSCODE
:
675 case PPD_CUSTOM_PASSWORD
:
676 case PPD_CUSTOM_STRING
:
677 if (cparam
->current
.custom_string
)
678 bufsize
+= strlen(cparam
->current
.custom_string
);
684 else if (section
!= PPD_ORDER_EXIT
)
686 bufsize
+= 3; /* [{\n */
688 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
689 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
690 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
692 DEBUG_puts("2ppdEmitString: Custom size set!");
694 bufsize
+= 37; /* %%BeginFeature: *CustomPageSize True\n */
695 bufsize
+= 50; /* Five 9-digit numbers + newline */
697 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
698 (coption
= ppdFindCustomOption(ppd
,
699 choices
[i
]->option
->keyword
))
702 bufsize
+= 23 + strlen(choices
[i
]->option
->keyword
) + 6;
703 /* %%BeginFeature: *Customkeyword True\n */
706 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
708 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
710 switch (cparam
->type
)
712 case PPD_CUSTOM_CURVE
:
713 case PPD_CUSTOM_INVCURVE
:
714 case PPD_CUSTOM_POINTS
:
715 case PPD_CUSTOM_REAL
:
716 case PPD_CUSTOM_INT
:
720 case PPD_CUSTOM_PASSCODE
:
721 case PPD_CUSTOM_PASSWORD
:
722 case PPD_CUSTOM_STRING
:
724 if (cparam
->current
.custom_string
)
725 bufsize
+= 4 * strlen(cparam
->current
.custom_string
);
731 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 1 +
732 strlen(choices
[i
]->choice
) + 1;
733 /* %%BeginFeature: *keyword choice\n */
735 bufsize
+= 13; /* %%EndFeature\n */
736 bufsize
+= 22; /* } stopped cleartomark\n */
739 if (choices
[i
]->code
)
740 bufsize
+= strlen(choices
[i
]->code
) + 1;
742 bufsize
+= strlen(ppd_custom_code
);
749 DEBUG_printf(("2ppdEmitString: Allocating %d bytes for string...",
752 if ((buffer
= calloc(1, bufsize
)) == NULL
)
758 bufend
= buffer
+ bufsize
- 1;
762 * Copy the option code to the buffer...
765 for (i
= 0, bufptr
= buffer
; i
< count
; i
++, bufptr
+= strlen(bufptr
))
766 if (section
== PPD_ORDER_JCL
)
768 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
770 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
774 * Handle substitutions in custom JCL options...
777 char *cptr
; /* Pointer into code */
778 int pnum
; /* Parameter number */
781 for (cptr
= choices
[i
]->code
; *cptr
&& bufptr
< bufend
;)
787 if (isdigit(*cptr
& 255))
790 * Substitute parameter...
793 pnum
= *cptr
++ - '0';
794 while (isdigit(*cptr
& 255))
795 pnum
= pnum
* 10 + *cptr
++ - '0';
797 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
799 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
800 if (cparam
->order
== pnum
)
805 switch (cparam
->type
)
807 case PPD_CUSTOM_CURVE
:
808 case PPD_CUSTOM_INVCURVE
:
809 case PPD_CUSTOM_POINTS
:
810 case PPD_CUSTOM_REAL
:
811 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
812 cparam
->current
.custom_real
,
816 case PPD_CUSTOM_INT
:
817 snprintf(bufptr
, (size_t)(bufend
- bufptr
), "%d", cparam
->current
.custom_int
);
818 bufptr
+= strlen(bufptr
);
821 case PPD_CUSTOM_PASSCODE
:
822 case PPD_CUSTOM_PASSWORD
:
823 case PPD_CUSTOM_STRING
:
824 if (cparam
->current
.custom_string
)
826 strlcpy(bufptr
, cparam
->current
.custom_string
, (size_t)(bufend
- bufptr
));
827 bufptr
+= strlen(bufptr
);
843 * Otherwise just copy the option code directly...
846 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
847 bufptr
+= strlen(bufptr
);
850 else if (section
!= PPD_ORDER_EXIT
)
853 * Add wrapper commands to prevent printer errors for unsupported
857 strlcpy(bufptr
, "[{\n", (size_t)(bufend
- bufptr
+ 1));
861 * Send DSC comments with option...
864 DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
865 choices
[i
]->option
->keyword
, choices
[i
]->choice
));
867 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
868 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
869 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
872 * Variable size; write out standard size options, using the
873 * parameter positions defined in the PPD file...
876 ppd_attr_t
*attr
; /* PPD attribute */
877 int pos
, /* Position of custom value */
878 orientation
; /* Orientation to use */
879 float values
[5]; /* Values for custom command */
882 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n", (size_t)(bufend
- bufptr
+ 1));
885 size
= ppdPageSize(ppd
, "Custom");
887 memset(values
, 0, sizeof(values
));
889 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
891 pos
= atoi(attr
->value
) - 1;
893 if (pos
< 0 || pos
> 4)
899 values
[pos
] = size
->width
;
901 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
903 pos
= atoi(attr
->value
) - 1;
905 if (pos
< 0 || pos
> 4)
911 values
[pos
] = size
->length
;
914 * According to the Adobe PPD specification, an orientation of 1
915 * will produce a print that comes out upside-down with the X
916 * axis perpendicular to the direction of feed, which is exactly
917 * what we want to be consistent with non-PS printers.
919 * We could also use an orientation of 3 to produce output that
920 * comes out rightside-up (this is the default for many large format
921 * printer PPDs), however for consistency we will stick with the
924 * If we wanted to get fancy, we could use orientations of 0 or
925 * 2 and swap the width and length, however we don't want to get
926 * fancy, we just want it to work consistently.
928 * The orientation value is range limited by the Orientation
929 * parameter definition, so certain non-PS printer drivers that
930 * only support an Orientation of 0 will get the value 0 as
936 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
937 "Orientation")) != NULL
)
939 int min_orient
, max_orient
; /* Minimum and maximum orientations */
942 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
949 if (pos
< 0 || pos
> 4)
952 if (orientation
> max_orient
)
953 orientation
= max_orient
;
954 else if (orientation
< min_orient
)
955 orientation
= min_orient
;
961 values
[pos
] = (float)orientation
;
963 for (pos
= 0; pos
< 5; pos
++)
965 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
969 if (!choices
[i
]->code
)
972 * This can happen with certain buggy PPD files that don't include
973 * a CustomPageSize command sequence... We just use a generic
974 * Level 2 command sequence...
977 strlcpy(bufptr
, ppd_custom_code
, (size_t)(bufend
- bufptr
+ 1));
978 bufptr
+= strlen(bufptr
);
981 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
982 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
989 const char *s
; /* Pointer into string value */
990 cups_array_t
*params
; /* Parameters in the correct output order */
993 params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
995 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
997 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
998 cupsArrayAdd(params
, cparam
);
1000 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
1001 bufptr
+= strlen(bufptr
);
1003 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(params
);
1005 cparam
= (ppd_cparam_t
*)cupsArrayNext(params
))
1007 switch (cparam
->type
)
1009 case PPD_CUSTOM_CURVE
:
1010 case PPD_CUSTOM_INVCURVE
:
1011 case PPD_CUSTOM_POINTS
:
1012 case PPD_CUSTOM_REAL
:
1013 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
1014 cparam
->current
.custom_real
, loc
);
1018 case PPD_CUSTOM_INT
:
1019 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%d\n", cparam
->current
.custom_int
);
1020 bufptr
+= strlen(bufptr
);
1023 case PPD_CUSTOM_PASSCODE
:
1024 case PPD_CUSTOM_PASSWORD
:
1025 case PPD_CUSTOM_STRING
:
1028 if (cparam
->current
.custom_string
)
1030 for (s
= cparam
->current
.custom_string
; *s
; s
++)
1032 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
1034 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "\\%03o", *s
& 255);
1035 bufptr
+= strlen(bufptr
);
1048 cupsArrayDelete(params
);
1052 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *%s %s\n", choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1053 bufptr
+= strlen(bufptr
);
1056 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1058 j
= (int)strlen(choices
[i
]->code
);
1059 memcpy(bufptr
, choices
[i
]->code
, (size_t)j
);
1062 if (choices
[i
]->code
[j
- 1] != '\n')
1066 strlcpy(bufptr
, "%%EndFeature\n"
1067 "} stopped cleartomark\n", (size_t)(bufend
- bufptr
+ 1));
1068 bufptr
+= strlen(bufptr
);
1070 DEBUG_printf(("2ppdEmitString: Offset in string is %d...",
1071 (int)(bufptr
- buffer
)));
1075 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
1076 bufptr
+= strlen(bufptr
);
1080 * Nul-terminate, free, and return...
1092 * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
1095 static int /* O - Result of comparison */
1096 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
1097 ppd_cparam_t
*b
) /* I - Second parameter */
1099 return (a
->order
- b
->order
);
1104 * 'ppd_handle_media()' - Handle media selection...
1108 ppd_handle_media(ppd_file_t
*ppd
) /* I - PPD file */
1110 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1111 *input_slot
; /* InputSlot choice, if any */
1112 ppd_size_t
*size
; /* Current media size */
1113 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1117 * This function determines what page size code to use, if any, for the
1118 * current media size, InputSlot, and ManualFeed selections.
1120 * We use the PageSize code if:
1122 * 1. A custom media size is selected.
1123 * 2. ManualFeed and InputSlot are not selected (or do not exist).
1124 * 3. ManualFeed is selected but is False and InputSlot is not selected or
1125 * the selection has no code - the latter check done to support "auto" or
1126 * "printer default" InputSlot options.
1128 * We use the PageRegion code if:
1130 * 4. RequiresPageRegion does not exist and the PPD contains cupsFilter
1131 * keywords, indicating this is a CUPS-based driver.
1132 * 5. RequiresPageRegion exists for the selected InputSlot (or "All" for any
1133 * InputSlot or ManualFeed selection) and is True.
1135 * If none of the 5 conditions are true, no page size code is used and we
1136 * unmark any existing PageSize or PageRegion choices.
1139 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1142 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1143 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1145 if (input_slot
!= NULL
)
1146 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1151 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1153 if (!_cups_strcasecmp(size
->name
, "Custom") ||
1154 (!manual_feed
&& !input_slot
) ||
1155 (manual_feed
&& !_cups_strcasecmp(manual_feed
->choice
, "False") &&
1156 (!input_slot
|| (input_slot
->code
&& !input_slot
->code
[0]))) ||
1157 (!rpr
&& ppd
->num_filters
> 0))
1160 * Use PageSize code...
1163 ppdMarkOption(ppd
, "PageSize", size
->name
);
1165 else if (rpr
&& rpr
->value
&& !_cups_strcasecmp(rpr
->value
, "True"))
1168 * Use PageRegion code...
1171 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1176 * Do not use PageSize or PageRegion code...
1179 ppd_choice_t
*page
; /* PageSize/Region choice, if any */
1181 if ((page
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
1184 * Unmark PageSize...
1188 cupsArrayRemove(ppd
->marked
, page
);
1191 if ((page
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
1194 * Unmark PageRegion...
1198 cupsArrayRemove(ppd
->marked
, page
);