]>
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 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
9 * PostScript is a trademark of Adobe Systems, Inc.
13 * Include necessary headers...
16 #include "cups-private.h"
18 #if defined(WIN32) || defined(__EMX__)
22 #endif /* WIN32 || __EMX__ */
29 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
30 static void ppd_handle_media(ppd_file_t
*ppd
);
37 static const char ppd_custom_code
[] =
39 "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
43 * 'ppdCollect()' - Collect all marked options that reside in the specified
46 * The choices array should be freed using @code free@ when you are
50 int /* O - Number of options marked */
51 ppdCollect(ppd_file_t
*ppd
, /* I - PPD file data */
52 ppd_section_t section
, /* I - Section to collect */
53 ppd_choice_t
***choices
) /* O - Pointers to choices */
55 return (ppdCollect2(ppd
, section
, 0.0, choices
));
60 * 'ppdCollect2()' - Collect all marked options that reside in the
61 * specified section and minimum order.
63 * The choices array should be freed using @code free@ when you are
66 * @since CUPS 1.2/macOS 10.5@
69 int /* O - Number of options marked */
70 ppdCollect2(ppd_file_t
*ppd
, /* I - PPD file data */
71 ppd_section_t section
, /* I - Section to collect */
72 float min_order
, /* I - Minimum OrderDependency value */
73 ppd_choice_t
***choices
) /* O - Pointers to choices */
75 ppd_choice_t
*c
; /* Current choice */
76 ppd_section_t csection
; /* Current section */
77 float corder
; /* Current OrderDependency value */
78 int count
; /* Number of choices collected */
79 ppd_choice_t
**collect
; /* Collected choices */
80 float *orders
; /* Collected order values */
83 DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)",
84 ppd
, section
, min_order
, choices
));
95 * Allocate memory for up to N selected choices...
99 if ((collect
= calloc(sizeof(ppd_choice_t
*),
100 (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
106 if ((orders
= calloc(sizeof(float), (size_t)cupsArrayCount(ppd
->marked
))) == NULL
)
114 * Loop through all options and add choices as needed...
117 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
119 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
121 csection
= c
->option
->section
;
122 corder
= c
->option
->order
;
124 if (!strcmp(c
->choice
, "Custom"))
126 ppd_attr_t
*attr
; /* NonUIOrderDependency value */
127 float aorder
; /* Order value */
128 char asection
[17], /* Section name */
129 amain
[PPD_MAX_NAME
+ 1],
130 aoption
[PPD_MAX_NAME
];
131 /* *CustomFoo and True */
134 for (attr
= ppdFindAttr(ppd
, "NonUIOrderDependency", NULL
);
136 attr
= ppdFindNextAttr(ppd
, "NonUIOrderDependency", NULL
))
138 sscanf(attr
->value
, "%f%16s%41s%40s", &aorder
, asection
, amain
,
140 !strncmp(amain
, "*Custom", 7) &&
141 !strcmp(amain
+ 7, c
->option
->keyword
) && !strcmp(aoption
, "True"))
144 * Use this NonUIOrderDependency...
149 if (!strcmp(asection
, "DocumentSetup"))
150 csection
= PPD_ORDER_DOCUMENT
;
151 else if (!strcmp(asection
, "ExitServer"))
152 csection
= PPD_ORDER_EXIT
;
153 else if (!strcmp(asection
, "JCLSetup"))
154 csection
= PPD_ORDER_JCL
;
155 else if (!strcmp(asection
, "PageSetup"))
156 csection
= PPD_ORDER_PAGE
;
157 else if (!strcmp(asection
, "Prolog"))
158 csection
= PPD_ORDER_PROLOG
;
160 csection
= PPD_ORDER_ANY
;
166 if (csection
== section
&& corder
>= min_order
)
169 orders
[count
] = corder
;
175 * If we have more than 1 marked choice, sort them...
180 int i
, j
; /* Looping vars */
182 for (i
= 0; i
< (count
- 1); i
++)
183 for (j
= i
+ 1; j
< count
; j
++)
184 if (orders
[i
] > orders
[j
])
188 collect
[i
] = collect
[j
];
189 orders
[i
] = orders
[j
];
197 DEBUG_printf(("2ppdCollect2: %d marked choices...", count
));
200 * Return the array and number of choices; if 0, free the array since
219 * 'ppdEmit()' - Emit code for marked options to a file.
222 int /* O - 0 on success, -1 on failure */
223 ppdEmit(ppd_file_t
*ppd
, /* I - PPD file record */
224 FILE *fp
, /* I - File to write to */
225 ppd_section_t section
) /* I - Section to write */
227 return (ppdEmitAfterOrder(ppd
, fp
, section
, 0, 0.0));
232 * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
234 * When "limit" is non-zero, this function only emits options whose
235 * OrderDependency value is greater than or equal to "min_order".
237 * When "limit" is zero, this function is identical to ppdEmit().
239 * @since CUPS 1.2/macOS 10.5@
242 int /* O - 0 on success, -1 on failure */
244 ppd_file_t
*ppd
, /* I - PPD file record */
245 FILE *fp
, /* I - File to write to */
246 ppd_section_t section
, /* I - Section to write */
247 int limit
, /* I - Non-zero to use min_order */
248 float min_order
) /* I - Lowest OrderDependency */
250 char *buffer
; /* Option code */
251 int status
; /* Return status */
255 * Range check input...
265 buffer
= ppdEmitString(ppd
, section
, limit
? min_order
: 0.0f
);
268 * Write it as needed and return...
273 status
= fputs(buffer
, fp
) < 0 ? -1 : 0;
285 * 'ppdEmitFd()' - Emit code for marked options to a file.
288 int /* O - 0 on success, -1 on failure */
289 ppdEmitFd(ppd_file_t
*ppd
, /* I - PPD file record */
290 int fd
, /* I - File to write to */
291 ppd_section_t section
) /* I - Section to write */
293 char *buffer
, /* Option code */
294 *bufptr
; /* Pointer into code */
295 size_t buflength
; /* Length of option code */
296 ssize_t bytes
; /* Bytes written */
297 int status
; /* Return status */
301 * Range check input...
311 buffer
= ppdEmitString(ppd
, section
, 0.0);
314 * Write it as needed and return...
319 buflength
= strlen(buffer
);
323 while (buflength
> 0)
326 if ((bytes
= (ssize_t
)write(fd
, bufptr
, (unsigned)buflength
)) < 0)
328 if ((bytes
= write(fd
, bufptr
, buflength
)) < 0)
331 if (errno
== EAGAIN
|| errno
== EINTR
)
337 buflength
-= (size_t)bytes
;
341 status
= bytes
< 0 ? -1 : 0;
353 * 'ppdEmitJCL()' - Emit code for JCL options to a file.
356 int /* O - 0 on success, -1 on failure */
357 ppdEmitJCL(ppd_file_t
*ppd
, /* I - PPD file record */
358 FILE *fp
, /* I - File to write to */
359 int job_id
, /* I - Job ID */
360 const char *user
, /* I - Username */
361 const char *title
) /* I - Title */
363 char *ptr
; /* Pointer into JCL string */
364 char temp
[65], /* Local title string */
365 displaymsg
[33]; /* Local display string */
369 * Range check the input...
372 if (!ppd
|| !ppd
->jcl_begin
|| !ppd
->jcl_ps
)
376 * See if the printer supports HP PJL...
379 if (!strncmp(ppd
->jcl_begin
, "\033%-12345X@", 10))
382 * This printer uses HP PJL commands for output; filter the output
383 * so that we only have a single "@PJL JOB" command in the header...
385 * To avoid bugs in the PJL implementation of certain vendors' products
386 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
387 * of the PJL commands to initialize PJL processing.
390 ppd_attr_t
*charset
; /* PJL charset */
391 ppd_attr_t
*display
; /* PJL display command */
394 if ((charset
= ppdFindAttr(ppd
, "cupsPJLCharset", NULL
)) != NULL
)
396 if (!charset
->value
|| _cups_strcasecmp(charset
->value
, "UTF-8"))
400 if ((display
= ppdFindAttr(ppd
, "cupsPJLDisplay", NULL
)) != NULL
)
406 fputs("\033%-12345X@PJL\n", fp
);
407 for (ptr
= ppd
->jcl_begin
+ 9; *ptr
;)
408 if (!strncmp(ptr
, "@PJL JOB", 8))
411 * Skip job command...
439 * Clean up the job title...
442 if ((ptr
= strrchr(title
, '/')) != NULL
)
445 * Only show basename of file path...
451 if (!strncmp(title
, "smbprn.", 7))
454 * Skip leading smbprn.######## from Samba jobs...
457 for (title
+= 7; *title
&& isdigit(*title
& 255); title
++);
458 while (_cups_isspace(*title
))
461 if ((ptr
= strstr(title
, " - ")) != NULL
)
464 * Skip application name in "Some Application - Title of job"...
472 * Replace double quotes with single quotes and UTF-8 characters with
473 * question marks so that the title does not cause a PJL syntax error.
476 strlcpy(temp
, title
, sizeof(temp
));
478 for (ptr
= temp
; *ptr
; ptr
++)
481 else if (!charset
&& (*ptr
& 128))
485 * CUPS STR #3125: Long PJL JOB NAME causes problems with some printers
487 * Generate the display message, truncating at 32 characters + nul to avoid
488 * issues with some printer's PJL implementations...
491 snprintf(displaymsg
, sizeof(displaymsg
), "%d %s %s", job_id
, user
, temp
);
494 * Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
497 if (display
&& strcmp(display
->value
, "job"))
498 fprintf(fp
, "@PJL JOB NAME = \"%s\"\n", temp
);
499 else if (display
&& !strcmp(display
->value
, "rdymsg"))
500 fprintf(fp
, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg
);
502 fprintf(fp
, "@PJL JOB NAME = \"%s\" DISPLAY = \"%s\"\n", temp
,
506 * Replace double quotes with single quotes and UTF-8 characters with
507 * question marks so that the user does not cause a PJL syntax error.
510 strlcpy(temp
, user
, sizeof(temp
));
512 for (ptr
= temp
; *ptr
; ptr
++)
515 else if (!charset
&& (*ptr
& 128))
518 fprintf(fp
, "@PJL SET USERNAME = \"%s\"\n", temp
);
521 fputs(ppd
->jcl_begin
, fp
);
523 ppdEmit(ppd
, fp
, PPD_ORDER_JCL
);
524 fputs(ppd
->jcl_ps
, fp
);
531 * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
533 * @since CUPS 1.2/macOS 10.5@
536 int /* O - 0 on success, -1 on failure */
537 ppdEmitJCLEnd(ppd_file_t
*ppd
, /* I - PPD file record */
538 FILE *fp
) /* I - File to write to */
541 * Range check the input...
549 if (ppd
->num_filters
== 0)
556 * See if the printer supports HP PJL...
559 if (!strncmp(ppd
->jcl_end
, "\033%-12345X@", 10))
562 * This printer uses HP PJL commands for output; filter the output
563 * so that we only have a single "@PJL JOB" command in the header...
565 * To avoid bugs in the PJL implementation of certain vendors' products
566 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
567 * of the PJL commands to initialize PJL processing.
570 fputs("\033%-12345X@PJL\n", fp
);
571 fputs("@PJL RDYMSG DISPLAY = \"\"\n", fp
);
572 fputs(ppd
->jcl_end
+ 9, fp
);
575 fputs(ppd
->jcl_end
, fp
);
582 * 'ppdEmitString()' - Get a string containing the code for marked options.
584 * When "min_order" is greater than zero, this function only includes options
585 * whose OrderDependency value is greater than or equal to "min_order".
586 * Otherwise, all options in the specified section are included in the
589 * The return string is allocated on the heap and should be freed using
590 * @code free@ when you are done with it.
592 * @since CUPS 1.2/macOS 10.5@
595 char * /* O - String containing option code or @code NULL@ if there is no option code */
596 ppdEmitString(ppd_file_t
*ppd
, /* I - PPD file record */
597 ppd_section_t section
, /* I - Section to write */
598 float min_order
) /* I - Lowest OrderDependency */
600 int i
, j
, /* Looping vars */
601 count
; /* Number of choices */
602 ppd_choice_t
**choices
; /* Choices */
603 ppd_size_t
*size
; /* Custom page size */
604 ppd_coption_t
*coption
; /* Custom option */
605 ppd_cparam_t
*cparam
; /* Custom parameter */
606 size_t bufsize
; /* Size of string buffer needed */
607 char *buffer
, /* String buffer */
608 *bufptr
, /* Pointer into buffer */
609 *bufend
; /* End of buffer */
610 struct lconv
*loc
; /* Locale data */
613 DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)",
614 ppd
, section
, min_order
));
617 * Range check input...
624 * Use PageSize or PageRegion as required...
627 ppd_handle_media(ppd
);
630 * Collect the options we need to emit...
633 if ((count
= ppdCollect2(ppd
, section
, min_order
, &choices
)) == 0)
637 * Count the number of bytes that are required to hold all of the
641 for (i
= 0, bufsize
= 1; i
< count
; i
++)
643 if (section
== PPD_ORDER_JCL
)
645 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
646 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
650 * Add space to account for custom parameter substitution...
653 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
655 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
657 switch (cparam
->type
)
659 case PPD_CUSTOM_CURVE
:
660 case PPD_CUSTOM_INVCURVE
:
661 case PPD_CUSTOM_POINTS
:
662 case PPD_CUSTOM_REAL
:
663 case PPD_CUSTOM_INT
:
667 case PPD_CUSTOM_PASSCODE
:
668 case PPD_CUSTOM_PASSWORD
:
669 case PPD_CUSTOM_STRING
:
670 if (cparam
->current
.custom_string
)
671 bufsize
+= strlen(cparam
->current
.custom_string
);
677 else if (section
!= PPD_ORDER_EXIT
)
679 bufsize
+= 3; /* [{\n */
681 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
682 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
683 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
685 DEBUG_puts("2ppdEmitString: Custom size set!");
687 bufsize
+= 37; /* %%BeginFeature: *CustomPageSize True\n */
688 bufsize
+= 50; /* Five 9-digit numbers + newline */
690 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
691 (coption
= ppdFindCustomOption(ppd
,
692 choices
[i
]->option
->keyword
))
695 bufsize
+= 23 + strlen(choices
[i
]->option
->keyword
) + 6;
696 /* %%BeginFeature: *Customkeyword True\n */
699 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
701 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
703 switch (cparam
->type
)
705 case PPD_CUSTOM_CURVE
:
706 case PPD_CUSTOM_INVCURVE
:
707 case PPD_CUSTOM_POINTS
:
708 case PPD_CUSTOM_REAL
:
709 case PPD_CUSTOM_INT
:
713 case PPD_CUSTOM_PASSCODE
:
714 case PPD_CUSTOM_PASSWORD
:
715 case PPD_CUSTOM_STRING
:
717 if (cparam
->current
.custom_string
)
718 bufsize
+= 4 * strlen(cparam
->current
.custom_string
);
724 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 1 +
725 strlen(choices
[i
]->choice
) + 1;
726 /* %%BeginFeature: *keyword choice\n */
728 bufsize
+= 13; /* %%EndFeature\n */
729 bufsize
+= 22; /* } stopped cleartomark\n */
732 if (choices
[i
]->code
)
733 bufsize
+= strlen(choices
[i
]->code
) + 1;
735 bufsize
+= strlen(ppd_custom_code
);
742 DEBUG_printf(("2ppdEmitString: Allocating %d bytes for string...",
745 if ((buffer
= calloc(1, bufsize
)) == NULL
)
751 bufend
= buffer
+ bufsize
- 1;
755 * Copy the option code to the buffer...
758 for (i
= 0, bufptr
= buffer
; i
< count
; i
++, bufptr
+= strlen(bufptr
))
759 if (section
== PPD_ORDER_JCL
)
761 if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
763 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
767 * Handle substitutions in custom JCL options...
770 char *cptr
; /* Pointer into code */
771 int pnum
; /* Parameter number */
774 for (cptr
= choices
[i
]->code
; *cptr
&& bufptr
< bufend
;)
780 if (isdigit(*cptr
& 255))
783 * Substitute parameter...
786 pnum
= *cptr
++ - '0';
787 while (isdigit(*cptr
& 255))
788 pnum
= pnum
* 10 + *cptr
++ - '0';
790 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
792 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
793 if (cparam
->order
== pnum
)
798 switch (cparam
->type
)
800 case PPD_CUSTOM_CURVE
:
801 case PPD_CUSTOM_INVCURVE
:
802 case PPD_CUSTOM_POINTS
:
803 case PPD_CUSTOM_REAL
:
804 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
805 cparam
->current
.custom_real
,
809 case PPD_CUSTOM_INT
:
810 snprintf(bufptr
, (size_t)(bufend
- bufptr
), "%d", cparam
->current
.custom_int
);
811 bufptr
+= strlen(bufptr
);
814 case PPD_CUSTOM_PASSCODE
:
815 case PPD_CUSTOM_PASSWORD
:
816 case PPD_CUSTOM_STRING
:
817 if (cparam
->current
.custom_string
)
819 strlcpy(bufptr
, cparam
->current
.custom_string
, (size_t)(bufend
- bufptr
));
820 bufptr
+= strlen(bufptr
);
836 * Otherwise just copy the option code directly...
839 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
840 bufptr
+= strlen(bufptr
);
843 else if (section
!= PPD_ORDER_EXIT
)
846 * Add wrapper commands to prevent printer errors for unsupported
850 strlcpy(bufptr
, "[{\n", (size_t)(bufend
- bufptr
+ 1));
854 * Send DSC comments with option...
857 DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
858 choices
[i
]->option
->keyword
, choices
[i
]->choice
));
860 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
861 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
862 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
865 * Variable size; write out standard size options, using the
866 * parameter positions defined in the PPD file...
869 ppd_attr_t
*attr
; /* PPD attribute */
870 int pos
, /* Position of custom value */
871 orientation
; /* Orientation to use */
872 float values
[5]; /* Values for custom command */
875 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n", (size_t)(bufend
- bufptr
+ 1));
878 size
= ppdPageSize(ppd
, "Custom");
880 memset(values
, 0, sizeof(values
));
882 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
884 pos
= atoi(attr
->value
) - 1;
886 if (pos
< 0 || pos
> 4)
892 values
[pos
] = size
->width
;
894 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
896 pos
= atoi(attr
->value
) - 1;
898 if (pos
< 0 || pos
> 4)
904 values
[pos
] = size
->length
;
907 * According to the Adobe PPD specification, an orientation of 1
908 * will produce a print that comes out upside-down with the X
909 * axis perpendicular to the direction of feed, which is exactly
910 * what we want to be consistent with non-PS printers.
912 * We could also use an orientation of 3 to produce output that
913 * comes out rightside-up (this is the default for many large format
914 * printer PPDs), however for consistency we will stick with the
917 * If we wanted to get fancy, we could use orientations of 0 or
918 * 2 and swap the width and length, however we don't want to get
919 * fancy, we just want it to work consistently.
921 * The orientation value is range limited by the Orientation
922 * parameter definition, so certain non-PS printer drivers that
923 * only support an Orientation of 0 will get the value 0 as
929 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
930 "Orientation")) != NULL
)
932 int min_orient
, max_orient
; /* Minimum and maximum orientations */
935 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
942 if (pos
< 0 || pos
> 4)
945 if (orientation
> max_orient
)
946 orientation
= max_orient
;
947 else if (orientation
< min_orient
)
948 orientation
= min_orient
;
954 values
[pos
] = (float)orientation
;
956 for (pos
= 0; pos
< 5; pos
++)
958 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
962 if (!choices
[i
]->code
)
965 * This can happen with certain buggy PPD files that don't include
966 * a CustomPageSize command sequence... We just use a generic
967 * Level 2 command sequence...
970 strlcpy(bufptr
, ppd_custom_code
, (size_t)(bufend
- bufptr
+ 1));
971 bufptr
+= strlen(bufptr
);
974 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
975 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
982 const char *s
; /* Pointer into string value */
983 cups_array_t
*params
; /* Parameters in the correct output order */
986 params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
988 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
990 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
991 cupsArrayAdd(params
, cparam
);
993 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
994 bufptr
+= strlen(bufptr
);
996 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(params
);
998 cparam
= (ppd_cparam_t
*)cupsArrayNext(params
))
1000 switch (cparam
->type
)
1002 case PPD_CUSTOM_CURVE
:
1003 case PPD_CUSTOM_INVCURVE
:
1004 case PPD_CUSTOM_POINTS
:
1005 case PPD_CUSTOM_REAL
:
1006 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
1007 cparam
->current
.custom_real
, loc
);
1011 case PPD_CUSTOM_INT
:
1012 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%d\n", cparam
->current
.custom_int
);
1013 bufptr
+= strlen(bufptr
);
1016 case PPD_CUSTOM_PASSCODE
:
1017 case PPD_CUSTOM_PASSWORD
:
1018 case PPD_CUSTOM_STRING
:
1021 if (cparam
->current
.custom_string
)
1023 for (s
= cparam
->current
.custom_string
; *s
; s
++)
1025 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
1027 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "\\%03o", *s
& 255);
1028 bufptr
+= strlen(bufptr
);
1041 cupsArrayDelete(params
);
1045 snprintf(bufptr
, (size_t)(bufend
- bufptr
+ 1), "%%%%BeginFeature: *%s %s\n", choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1046 bufptr
+= strlen(bufptr
);
1049 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1051 j
= (int)strlen(choices
[i
]->code
);
1052 memcpy(bufptr
, choices
[i
]->code
, (size_t)j
);
1055 if (choices
[i
]->code
[j
- 1] != '\n')
1059 strlcpy(bufptr
, "%%EndFeature\n"
1060 "} stopped cleartomark\n", (size_t)(bufend
- bufptr
+ 1));
1061 bufptr
+= strlen(bufptr
);
1063 DEBUG_printf(("2ppdEmitString: Offset in string is %d...",
1064 (int)(bufptr
- buffer
)));
1068 strlcpy(bufptr
, choices
[i
]->code
, (size_t)(bufend
- bufptr
+ 1));
1069 bufptr
+= strlen(bufptr
);
1073 * Nul-terminate, free, and return...
1085 * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
1088 static int /* O - Result of comparison */
1089 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
1090 ppd_cparam_t
*b
) /* I - Second parameter */
1092 return (a
->order
- b
->order
);
1097 * 'ppd_handle_media()' - Handle media selection...
1101 ppd_handle_media(ppd_file_t
*ppd
) /* I - PPD file */
1103 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1104 *input_slot
; /* InputSlot choice, if any */
1105 ppd_size_t
*size
; /* Current media size */
1106 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1110 * This function determines what page size code to use, if any, for the
1111 * current media size, InputSlot, and ManualFeed selections.
1113 * We use the PageSize code if:
1115 * 1. A custom media size is selected.
1116 * 2. ManualFeed and InputSlot are not selected (or do not exist).
1117 * 3. ManualFeed is selected but is False and InputSlot is not selected or
1118 * the selection has no code - the latter check done to support "auto" or
1119 * "printer default" InputSlot options.
1121 * We use the PageRegion code if:
1123 * 4. RequiresPageRegion does not exist and the PPD contains cupsFilter
1124 * keywords, indicating this is a CUPS-based driver.
1125 * 5. RequiresPageRegion exists for the selected InputSlot (or "All" for any
1126 * InputSlot or ManualFeed selection) and is True.
1128 * If none of the 5 conditions are true, no page size code is used and we
1129 * unmark any existing PageSize or PageRegion choices.
1132 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1135 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1136 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1138 if (input_slot
!= NULL
)
1139 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1144 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1146 if (!_cups_strcasecmp(size
->name
, "Custom") ||
1147 (!manual_feed
&& !input_slot
) ||
1148 (manual_feed
&& !_cups_strcasecmp(manual_feed
->choice
, "False") &&
1149 (!input_slot
|| (input_slot
->code
&& !input_slot
->code
[0]))) ||
1150 (!rpr
&& ppd
->num_filters
> 0))
1153 * Use PageSize code...
1156 ppdMarkOption(ppd
, "PageSize", size
->name
);
1158 else if (rpr
&& rpr
->value
&& !_cups_strcasecmp(rpr
->value
, "True"))
1161 * Use PageRegion code...
1164 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1169 * Do not use PageSize or PageRegion code...
1172 ppd_choice_t
*page
; /* PageSize/Region choice, if any */
1174 if ((page
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
1177 * Unmark PageSize...
1181 cupsArrayRemove(ppd
->marked
, page
);
1184 if ((page
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
1187 * Unmark PageRegion...
1191 cupsArrayRemove(ppd
->marked
, page
);