]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/emit.c
759e634c04fe7e59626ab4d489561e0bfc1f2a38
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
, bufend
- bufptr
, "%d",
818 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
,
829 bufptr
+= strlen(bufptr
);
845 * Otherwise just copy the option code directly...
848 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
849 bufptr
+= strlen(bufptr
);
852 else if (section
!= PPD_ORDER_EXIT
)
855 * Add wrapper commands to prevent printer errors for unsupported
859 strlcpy(bufptr
, "[{\n", bufend
- bufptr
+ 1);
863 * Send DSC comments with option...
866 DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
867 choices
[i
]->option
->keyword
, choices
[i
]->choice
));
869 if ((!_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
870 !_cups_strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
871 !_cups_strcasecmp(choices
[i
]->choice
, "Custom"))
874 * Variable size; write out standard size options, using the
875 * parameter positions defined in the PPD file...
878 ppd_attr_t
*attr
; /* PPD attribute */
879 int pos
, /* Position of custom value */
880 orientation
; /* Orientation to use */
881 float values
[5]; /* Values for custom command */
884 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n",
885 bufend
- bufptr
+ 1);
888 size
= ppdPageSize(ppd
, "Custom");
890 memset(values
, 0, sizeof(values
));
892 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
894 pos
= atoi(attr
->value
) - 1;
896 if (pos
< 0 || pos
> 4)
902 values
[pos
] = size
->width
;
904 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
906 pos
= atoi(attr
->value
) - 1;
908 if (pos
< 0 || pos
> 4)
914 values
[pos
] = size
->length
;
917 * According to the Adobe PPD specification, an orientation of 1
918 * will produce a print that comes out upside-down with the X
919 * axis perpendicular to the direction of feed, which is exactly
920 * what we want to be consistent with non-PS printers.
922 * We could also use an orientation of 3 to produce output that
923 * comes out rightside-up (this is the default for many large format
924 * printer PPDs), however for consistency we will stick with the
927 * If we wanted to get fancy, we could use orientations of 0 or
928 * 2 and swap the width and length, however we don't want to get
929 * fancy, we just want it to work consistently.
931 * The orientation value is range limited by the Orientation
932 * parameter definition, so certain non-PS printer drivers that
933 * only support an Orientation of 0 will get the value 0 as
939 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
940 "Orientation")) != NULL
)
942 int min_orient
, max_orient
; /* Minimum and maximum orientations */
945 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
952 if (pos
< 0 || pos
> 4)
955 if (orientation
> max_orient
)
956 orientation
= max_orient
;
957 else if (orientation
< min_orient
)
958 orientation
= min_orient
;
964 values
[pos
] = (float)orientation
;
966 for (pos
= 0; pos
< 5; pos
++)
968 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
972 if (!choices
[i
]->code
)
975 * This can happen with certain buggy PPD files that don't include
976 * a CustomPageSize command sequence... We just use a generic
977 * Level 2 command sequence...
980 strlcpy(bufptr
, ppd_custom_code
, bufend
- bufptr
+ 1);
981 bufptr
+= strlen(bufptr
);
984 else if (!_cups_strcasecmp(choices
[i
]->choice
, "Custom") &&
985 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
992 const char *s
; /* Pointer into string value */
993 cups_array_t
*params
; /* Parameters in the correct output order */
996 params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
998 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
1000 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
1001 cupsArrayAdd(params
, cparam
);
1003 snprintf(bufptr
, bufend
- bufptr
+ 1,
1004 "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
1005 bufptr
+= strlen(bufptr
);
1007 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(params
);
1009 cparam
= (ppd_cparam_t
*)cupsArrayNext(params
))
1011 switch (cparam
->type
)
1013 case PPD_CUSTOM_CURVE
:
1014 case PPD_CUSTOM_INVCURVE
:
1015 case PPD_CUSTOM_POINTS
:
1016 case PPD_CUSTOM_REAL
:
1017 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
1018 cparam
->current
.custom_real
, loc
);
1022 case PPD_CUSTOM_INT
:
1023 snprintf(bufptr
, bufend
- bufptr
+ 1, "%d\n",
1024 cparam
->current
.custom_int
);
1025 bufptr
+= strlen(bufptr
);
1028 case PPD_CUSTOM_PASSCODE
:
1029 case PPD_CUSTOM_PASSWORD
:
1030 case PPD_CUSTOM_STRING
:
1033 if (cparam
->current
.custom_string
)
1035 for (s
= cparam
->current
.custom_string
; *s
; s
++)
1037 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
1039 snprintf(bufptr
, bufend
- bufptr
+ 1, "\\%03o", *s
& 255);
1040 bufptr
+= strlen(bufptr
);
1053 cupsArrayDelete(params
);
1057 snprintf(bufptr
, bufend
- bufptr
+ 1, "%%%%BeginFeature: *%s %s\n",
1058 choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1059 bufptr
+= strlen(bufptr
);
1062 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1064 j
= (int)strlen(choices
[i
]->code
);
1065 memcpy(bufptr
, choices
[i
]->code
, j
);
1068 if (choices
[i
]->code
[j
- 1] != '\n')
1072 strlcpy(bufptr
, "%%EndFeature\n"
1073 "} stopped cleartomark\n", bufend
- bufptr
+ 1);
1074 bufptr
+= strlen(bufptr
);
1076 DEBUG_printf(("2ppdEmitString: Offset in string is %d...",
1077 (int)(bufptr
- buffer
)));
1081 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
1082 bufptr
+= strlen(bufptr
);
1086 * Nul-terminate, free, and return...
1098 * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
1101 static int /* O - Result of comparison */
1102 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
1103 ppd_cparam_t
*b
) /* I - Second parameter */
1105 return (a
->order
- b
->order
);
1110 * 'ppd_handle_media()' - Handle media selection...
1114 ppd_handle_media(ppd_file_t
*ppd
) /* I - PPD file */
1116 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1117 *input_slot
; /* InputSlot choice, if any */
1118 ppd_size_t
*size
; /* Current media size */
1119 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1123 * This function determines what page size code to use, if any, for the
1124 * current media size, InputSlot, and ManualFeed selections.
1126 * We use the PageSize code if:
1128 * 1. A custom media size is selected.
1129 * 2. ManualFeed and InputSlot are not selected (or do not exist).
1130 * 3. ManualFeed is selected but is False and InputSlot is not selected or
1131 * the selection has no code - the latter check done to support "auto" or
1132 * "printer default" InputSlot options.
1134 * We use the PageRegion code if:
1136 * 4. RequiresPageRegion does not exist and the PPD contains cupsFilter
1137 * keywords, indicating this is a CUPS-based driver.
1138 * 5. RequiresPageRegion exists for the selected InputSlot (or "All" for any
1139 * InputSlot or ManualFeed selection) and is True.
1141 * If none of the 5 conditions are true, no page size code is used and we
1142 * unmark any existing PageSize or PageRegion choices.
1145 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1148 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1149 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1151 if (input_slot
!= NULL
)
1152 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1157 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1159 if (!_cups_strcasecmp(size
->name
, "Custom") ||
1160 (!manual_feed
&& !input_slot
) ||
1161 (manual_feed
&& !_cups_strcasecmp(manual_feed
->choice
, "False") &&
1162 (!input_slot
|| (input_slot
->code
&& !input_slot
->code
[0]))) ||
1163 (!rpr
&& ppd
->num_filters
> 0))
1166 * Use PageSize code...
1169 ppdMarkOption(ppd
, "PageSize", size
->name
);
1171 else if (rpr
&& rpr
->value
&& !_cups_strcasecmp(rpr
->value
, "True"))
1174 * Use PageRegion code...
1177 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1182 * Do not use PageSize or PageRegion code...
1185 ppd_choice_t
*page
; /* PageSize/Region choice, if any */
1187 if ((page
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
1190 * Unmark PageSize...
1194 cupsArrayRemove(ppd
->marked
, page
);
1197 if ((page
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
1200 * Unmark PageRegion...
1204 cupsArrayRemove(ppd
->marked
, page
);