]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/emit.c
2 * "$Id: emit.c 7863 2008-08-26 03:39:59Z mike $"
4 * PPD code emission routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2009 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 * ppdCollect() - Collect all marked options that reside in the
23 * ppdCollect2() - Collect all marked options that reside in the
24 * specified section and minimum order.
25 * ppdEmit() - Emit code for marked options to a file.
26 * ppdEmitAfterOrder() - Emit a subset of the code for marked options to a
28 * ppdEmitFd() - Emit code for marked options to a file.
29 * ppdEmitJCL() - Emit code for JCL options to a file.
30 * ppdEmitJCLEnd() - Emit JCLEnd code to a file.
31 * ppdEmitString() - Get a string containing the code for marked
33 * ppd_compare_cparams() - Compare the order of two custom parameters.
34 * ppd_handle_media() - Handle media selection...
38 * Include necessary headers...
47 #if defined(WIN32) || defined(__EMX__)
51 #endif /* WIN32 || __EMX__ */
58 static int ppd_compare_cparams(ppd_cparam_t
*a
, ppd_cparam_t
*b
);
59 static void ppd_handle_media(ppd_file_t
*ppd
);
66 static const char ppd_custom_code
[] =
68 "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
72 * 'ppdCollect()' - Collect all marked options that reside in the specified
75 * The choices array should be freed using @code free@ when you are
79 int /* O - Number of options marked */
80 ppdCollect(ppd_file_t
*ppd
, /* I - PPD file data */
81 ppd_section_t section
, /* I - Section to collect */
82 ppd_choice_t
***choices
) /* O - Pointers to choices */
84 return (ppdCollect2(ppd
, section
, 0.0, choices
));
89 * 'ppdCollect2()' - Collect all marked options that reside in the
90 * specified section and minimum order.
92 * The choices array should be freed using @code free@ when you are
95 * @since CUPS 1.2/Mac OS X 10.5@
98 int /* O - Number of options marked */
99 ppdCollect2(ppd_file_t
*ppd
, /* I - PPD file data */
100 ppd_section_t section
, /* I - Section to collect */
101 float min_order
, /* I - Minimum OrderDependency value */
102 ppd_choice_t
***choices
) /* O - Pointers to choices */
104 ppd_choice_t
*c
; /* Current choice */
105 ppd_section_t csection
; /* Current section */
106 float corder
; /* Current OrderDependency value */
107 int count
; /* Number of choices collected */
108 ppd_choice_t
**collect
; /* Collected choices */
109 float *orders
; /* Collected order values */
112 DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)",
113 ppd
, section
, min_order
, choices
));
115 if (!ppd
|| !choices
)
124 * Allocate memory for up to N selected choices...
128 if ((collect
= calloc(sizeof(ppd_choice_t
*),
129 cupsArrayCount(ppd
->marked
))) == NULL
)
135 if ((orders
= calloc(sizeof(float), cupsArrayCount(ppd
->marked
))) == NULL
)
143 * Loop through all options and add choices as needed...
146 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
148 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
150 csection
= c
->option
->section
;
151 corder
= c
->option
->order
;
153 if (!strcmp(c
->choice
, "Custom"))
155 ppd_attr_t
*attr
; /* NonUIOrderDependency value */
156 float aorder
; /* Order value */
157 char asection
[17], /* Section name */
158 amain
[PPD_MAX_NAME
+ 1],
159 aoption
[PPD_MAX_NAME
];
160 /* *CustomFoo and True */
163 for (attr
= ppdFindAttr(ppd
, "NonUIOrderDependency", NULL
);
165 attr
= ppdFindNextAttr(ppd
, "NonUIOrderDependency", NULL
))
167 sscanf(attr
->value
, "%f%16s%41s%40s", &aorder
, asection
, amain
,
169 !strncmp(amain
, "*Custom", 7) &&
170 !strcmp(amain
+ 7, c
->option
->keyword
) && !strcmp(aoption
, "True"))
173 * Use this NonUIOrderDependency...
178 if (!strcmp(asection
, "DocumentSetup"))
179 csection
= PPD_ORDER_DOCUMENT
;
180 else if (!strcmp(asection
, "ExitServer"))
181 csection
= PPD_ORDER_EXIT
;
182 else if (!strcmp(asection
, "JCLSetup"))
183 csection
= PPD_ORDER_JCL
;
184 else if (!strcmp(asection
, "PageSetup"))
185 csection
= PPD_ORDER_PAGE
;
186 else if (!strcmp(asection
, "Prolog"))
187 csection
= PPD_ORDER_PROLOG
;
189 csection
= PPD_ORDER_ANY
;
195 if (csection
== section
&& corder
>= min_order
)
198 orders
[count
] = corder
;
204 * If we have more than 1 marked choice, sort them...
209 int i
, j
; /* Looping vars */
211 for (i
= 0; i
< (count
- 1); i
++)
212 for (j
= i
+ 1; j
< count
; j
++)
213 if (orders
[i
] > orders
[j
])
217 collect
[i
] = collect
[j
];
218 orders
[i
] = orders
[j
];
226 DEBUG_printf(("2ppdCollect2: %d marked choices...", count
));
229 * Return the array and number of choices; if 0, free the array since
248 * 'ppdEmit()' - Emit code for marked options to a file.
251 int /* O - 0 on success, -1 on failure */
252 ppdEmit(ppd_file_t
*ppd
, /* I - PPD file record */
253 FILE *fp
, /* I - File to write to */
254 ppd_section_t section
) /* I - Section to write */
256 return (ppdEmitAfterOrder(ppd
, fp
, section
, 0, 0.0));
261 * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
263 * When "limit" is non-zero, this function only emits options whose
264 * OrderDependency value is greater than or equal to "min_order".
266 * When "limit" is zero, this function is identical to ppdEmit().
268 * @since CUPS 1.2/Mac OS X 10.5@
271 int /* O - 0 on success, -1 on failure */
273 ppd_file_t
*ppd
, /* I - PPD file record */
274 FILE *fp
, /* I - File to write to */
275 ppd_section_t section
, /* I - Section to write */
276 int limit
, /* I - Non-zero to use min_order */
277 float min_order
) /* I - Lowest OrderDependency */
279 char *buffer
; /* Option code */
280 int status
; /* Return status */
284 * Range check input...
294 buffer
= ppdEmitString(ppd
, section
, min_order
);
297 * Write it as needed and return...
302 status
= fputs(buffer
, fp
) < 0 ? -1 : 0;
314 * 'ppdEmitFd()' - Emit code for marked options to a file.
317 int /* O - 0 on success, -1 on failure */
318 ppdEmitFd(ppd_file_t
*ppd
, /* I - PPD file record */
319 int fd
, /* I - File to write to */
320 ppd_section_t section
) /* I - Section to write */
322 char *buffer
, /* Option code */
323 *bufptr
; /* Pointer into code */
324 size_t buflength
; /* Length of option code */
325 ssize_t bytes
; /* Bytes written */
326 int status
; /* Return status */
330 * Range check input...
340 buffer
= ppdEmitString(ppd
, section
, 0.0);
343 * Write it as needed and return...
348 buflength
= strlen(buffer
);
352 while (buflength
> 0)
355 if ((bytes
= (ssize_t
)write(fd
, bufptr
, (unsigned)buflength
)) < 0)
357 if ((bytes
= write(fd
, bufptr
, buflength
)) < 0)
360 if (errno
== EAGAIN
|| errno
== EINTR
)
370 status
= bytes
< 0 ? -1 : 0;
382 * 'ppdEmitJCL()' - Emit code for JCL options to a file.
385 int /* O - 0 on success, -1 on failure */
386 ppdEmitJCL(ppd_file_t
*ppd
, /* I - PPD file record */
387 FILE *fp
, /* I - File to write to */
388 int job_id
, /* I - Job ID */
389 const char *user
, /* I - Username */
390 const char *title
) /* I - Title */
392 char *ptr
; /* Pointer into JCL string */
393 char temp
[65], /* Local title string */
394 displaymsg
[33]; /* Local display string */
398 * Range check the input...
401 if (!ppd
|| !ppd
->jcl_begin
|| !ppd
->jcl_ps
)
405 * See if the printer supports HP PJL...
408 if (!strncmp(ppd
->jcl_begin
, "\033%-12345X@", 10))
411 * This printer uses HP PJL commands for output; filter the output
412 * so that we only have a single "@PJL JOB" command in the header...
414 * To avoid bugs in the PJL implementation of certain vendors' products
415 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
416 * of the PJL commands to initialize PJL processing.
419 ppd_attr_t
*charset
; /* PJL charset */
420 ppd_attr_t
*display
; /* PJL display command */
423 if ((charset
= ppdFindAttr(ppd
, "cupsPJLCharset", NULL
)) != NULL
)
425 if (!charset
->value
|| strcasecmp(charset
->value
, "UTF-8"))
429 if ((display
= ppdFindAttr(ppd
, "cupsPJLDisplay", NULL
)) != NULL
)
435 fputs("\033%-12345X@PJL\n", fp
);
436 for (ptr
= ppd
->jcl_begin
+ 9; *ptr
;)
437 if (!strncmp(ptr
, "@PJL JOB", 8))
440 * Skip job command...
468 * Clean up the job title...
471 if ((ptr
= strrchr(title
, '/')) != NULL
)
474 * Only show basename of file path...
480 if (!strncmp(title
, "smbprn.", 7))
483 * Skip leading smbprn.######## from Samba jobs...
486 for (title
+= 7; *title
&& isdigit(*title
& 255); title
++);
487 for (; *title
&& isspace(*title
& 255); title
++);
489 if ((ptr
= strstr(title
, " - ")) != NULL
)
492 * Skip application name in "Some Application - Title of job"...
500 * Replace double quotes with single quotes and UTF-8 characters with
501 * question marks so that the title does not cause a PJL syntax error.
504 strlcpy(temp
, title
, sizeof(temp
));
506 for (ptr
= temp
; *ptr
; ptr
++)
509 else if (!charset
&& (*ptr
& 128))
513 * CUPS STR #3125: Long PJL JOB NAME causes problems with some printers
515 * Generate the display message, truncating at 32 characters + nul to avoid
516 * issues with some printer's PJL implementations...
519 snprintf(displaymsg
, sizeof(displaymsg
), "%d %s %s", job_id
, user
, temp
);
522 * Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
525 if (display
&& strcmp(display
->value
, "job"))
527 fprintf(fp
, "@PJL JOB NAME = \"%s\"\n", temp
);
529 if (display
&& !strcmp(display
->value
, "rdymsg"))
530 fprintf(fp
, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg
);
533 fprintf(fp
, "@PJL JOB NAME = \"%s\" DISPLAY = \"%s\"\n", temp
,
537 fputs(ppd
->jcl_begin
, fp
);
539 ppdEmit(ppd
, fp
, PPD_ORDER_JCL
);
540 fputs(ppd
->jcl_ps
, fp
);
547 * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
549 * @since CUPS 1.2/Mac OS X 10.5@
552 int /* O - 0 on success, -1 on failure */
553 ppdEmitJCLEnd(ppd_file_t
*ppd
, /* I - PPD file record */
554 FILE *fp
) /* I - File to write to */
557 * Range check the input...
565 if (ppd
->num_filters
== 0)
572 * See if the printer supports HP PJL...
575 if (!strncmp(ppd
->jcl_end
, "\033%-12345X@", 10))
578 * This printer uses HP PJL commands for output; filter the output
579 * so that we only have a single "@PJL JOB" command in the header...
581 * To avoid bugs in the PJL implementation of certain vendors' products
582 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
583 * of the PJL commands to initialize PJL processing.
586 fputs("\033%-12345X@PJL\n", fp
);
587 fputs("@PJL RDYMSG DISPLAY = \"\"\n", fp
);
588 fputs(ppd
->jcl_end
+ 9, fp
);
591 fputs(ppd
->jcl_end
, fp
);
598 * 'ppdEmitString()' - Get a string containing the code for marked options.
600 * When "min_order" is greater than zero, this function only includes options
601 * whose OrderDependency value is greater than or equal to "min_order".
602 * Otherwise, all options in the specified section are included in the
605 * The return string is allocated on the heap and should be freed using
606 * @code free@ when you are done with it.
608 * @since CUPS 1.2/Mac OS X 10.5@
611 char * /* O - String containing option code or @code NULL@ if there is no option code */
612 ppdEmitString(ppd_file_t
*ppd
, /* I - PPD file record */
613 ppd_section_t section
, /* I - Section to write */
614 float min_order
) /* I - Lowest OrderDependency */
616 int i
, j
, /* Looping vars */
617 count
; /* Number of choices */
618 ppd_choice_t
**choices
; /* Choices */
619 ppd_size_t
*size
; /* Custom page size */
620 ppd_coption_t
*coption
; /* Custom option */
621 ppd_cparam_t
*cparam
; /* Custom parameter */
622 size_t bufsize
; /* Size of string buffer needed */
623 char *buffer
, /* String buffer */
624 *bufptr
, /* Pointer into buffer */
625 *bufend
; /* End of buffer */
626 struct lconv
*loc
; /* Locale data */
629 DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)",
630 ppd
, section
, min_order
));
633 * Range check input...
640 * Use PageSize or PageRegion as required...
643 ppd_handle_media(ppd
);
646 * Collect the options we need to emit...
649 if ((count
= ppdCollect2(ppd
, section
, min_order
, &choices
)) == 0)
653 * Count the number of bytes that are required to hold all of the
657 for (i
= 0, bufsize
= 1; i
< count
; i
++)
659 if (section
== PPD_ORDER_JCL
)
661 if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
662 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
666 * Add space to account for custom parameter substitution...
669 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
671 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
673 switch (cparam
->type
)
675 case PPD_CUSTOM_CURVE
:
676 case PPD_CUSTOM_INVCURVE
:
677 case PPD_CUSTOM_POINTS
:
678 case PPD_CUSTOM_REAL
:
679 case PPD_CUSTOM_INT
:
683 case PPD_CUSTOM_PASSCODE
:
684 case PPD_CUSTOM_PASSWORD
:
685 case PPD_CUSTOM_STRING
:
686 bufsize
+= strlen(cparam
->current
.custom_string
);
692 else if (section
!= PPD_ORDER_EXIT
)
694 bufsize
+= 3; /* [{\n */
696 if ((!strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
697 !strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
698 !strcasecmp(choices
[i
]->choice
, "Custom"))
700 DEBUG_puts("2ppdEmitString: Custom size set!");
702 bufsize
+= 37; /* %%BeginFeature: *CustomPageSize True\n */
703 bufsize
+= 50; /* Five 9-digit numbers + newline */
705 else if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
706 (coption
= ppdFindCustomOption(ppd
,
707 choices
[i
]->option
->keyword
))
710 bufsize
+= 23 + strlen(choices
[i
]->option
->keyword
) + 6;
711 /* %%BeginFeature: *Customkeyword True\n */
714 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
716 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
718 switch (cparam
->type
)
720 case PPD_CUSTOM_CURVE
:
721 case PPD_CUSTOM_INVCURVE
:
722 case PPD_CUSTOM_POINTS
:
723 case PPD_CUSTOM_REAL
:
724 case PPD_CUSTOM_INT
:
728 case PPD_CUSTOM_PASSCODE
:
729 case PPD_CUSTOM_PASSWORD
:
730 case PPD_CUSTOM_STRING
:
731 bufsize
+= 3 + 4 * strlen(cparam
->current
.custom_string
);
737 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 1 +
738 strlen(choices
[i
]->choice
) + 1;
739 /* %%BeginFeature: *keyword choice\n */
741 bufsize
+= 13; /* %%EndFeature\n */
742 bufsize
+= 22; /* } stopped cleartomark\n */
745 if (choices
[i
]->code
)
746 bufsize
+= strlen(choices
[i
]->code
) + 1;
748 bufsize
+= strlen(ppd_custom_code
);
755 DEBUG_printf(("2ppdEmitString: Allocating %d bytes for string...",
758 if ((buffer
= calloc(1, bufsize
)) == NULL
)
764 bufend
= buffer
+ bufsize
- 1;
768 * Copy the option code to the buffer...
771 for (i
= 0, bufptr
= buffer
; i
< count
; i
++, bufptr
+= strlen(bufptr
))
772 if (section
== PPD_ORDER_JCL
)
774 if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
775 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
779 * Handle substitutions in custom JCL options...
782 char *cptr
; /* Pointer into code */
783 int pnum
; /* Parameter number */
786 for (cptr
= choices
[i
]->code
; *cptr
&& bufptr
< bufend
;)
792 if (isdigit(*cptr
& 255))
795 * Substitute parameter...
798 pnum
= *cptr
++ - '0';
799 while (isalnum(*cptr
& 255))
800 pnum
= pnum
* 10 + *cptr
- '0';
802 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
804 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
805 if (cparam
->order
== pnum
)
810 switch (cparam
->type
)
812 case PPD_CUSTOM_CURVE
:
813 case PPD_CUSTOM_INVCURVE
:
814 case PPD_CUSTOM_POINTS
:
815 case PPD_CUSTOM_REAL
:
816 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
817 cparam
->current
.custom_real
,
821 case PPD_CUSTOM_INT
:
822 snprintf(bufptr
, bufend
- bufptr
, "%d",
823 cparam
->current
.custom_int
);
824 bufptr
+= strlen(bufptr
);
827 case PPD_CUSTOM_PASSCODE
:
828 case PPD_CUSTOM_PASSWORD
:
829 case PPD_CUSTOM_STRING
:
830 strlcpy(bufptr
, cparam
->current
.custom_string
,
832 bufptr
+= strlen(bufptr
);
847 * Otherwise just copy the option code directly...
850 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
851 bufptr
+= strlen(bufptr
);
854 else if (section
!= PPD_ORDER_EXIT
)
857 * Add wrapper commands to prevent printer errors for unsupported
861 strlcpy(bufptr
, "[{\n", bufend
- bufptr
+ 1);
865 * Send DSC comments with option...
868 DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
869 choices
[i
]->option
->keyword
, choices
[i
]->choice
));
871 if ((!strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
872 !strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
873 !strcasecmp(choices
[i
]->choice
, "Custom"))
876 * Variable size; write out standard size options, using the
877 * parameter positions defined in the PPD file...
880 ppd_attr_t
*attr
; /* PPD attribute */
881 int pos
, /* Position of custom value */
882 orientation
; /* Orientation to use */
883 float values
[5]; /* Values for custom command */
886 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n",
887 bufend
- bufptr
+ 1);
890 size
= ppdPageSize(ppd
, "Custom");
892 memset(values
, 0, sizeof(values
));
894 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
896 pos
= atoi(attr
->value
) - 1;
898 if (pos
< 0 || pos
> 4)
904 values
[pos
] = size
->width
;
906 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
908 pos
= atoi(attr
->value
) - 1;
910 if (pos
< 0 || pos
> 4)
916 values
[pos
] = size
->length
;
919 * According to the Adobe PPD specification, an orientation of 1
920 * will produce a print that comes out upside-down with the X
921 * axis perpendicular to the direction of feed, which is exactly
922 * what we want to be consistent with non-PS printers.
924 * We could also use an orientation of 3 to produce output that
925 * comes out rightside-up (this is the default for many large format
926 * printer PPDs), however for consistency we will stick with the
929 * If we wanted to get fancy, we could use orientations of 0 or
930 * 2 and swap the width and length, however we don't want to get
931 * fancy, we just want it to work consistently.
933 * The orientation value is range limited by the Orientation
934 * parameter definition, so certain non-PS printer drivers that
935 * only support an Orientation of 0 will get the value 0 as
941 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
942 "Orientation")) != NULL
)
944 int min_orient
, max_orient
; /* Minimum and maximum orientations */
947 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
954 if (pos
< 0 || pos
> 4)
957 if (orientation
> max_orient
)
958 orientation
= max_orient
;
959 else if (orientation
< min_orient
)
960 orientation
= min_orient
;
966 values
[pos
] = (float)orientation
;
968 for (pos
= 0; pos
< 5; pos
++)
970 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
974 if (!choices
[i
]->code
)
977 * This can happen with certain buggy PPD files that don't include
978 * a CustomPageSize command sequence... We just use a generic
979 * Level 2 command sequence...
982 strlcpy(bufptr
, ppd_custom_code
, bufend
- bufptr
+ 1);
983 bufptr
+= strlen(bufptr
);
986 else if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
987 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
994 const char *s
; /* Pointer into string value */
995 cups_array_t
*params
; /* Parameters in the correct output order */
998 params
= cupsArrayNew((cups_array_func_t
)ppd_compare_cparams
, NULL
);
1000 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
1002 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
1003 cupsArrayAdd(params
, cparam
);
1005 snprintf(bufptr
, bufend
- bufptr
+ 1,
1006 "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
1007 bufptr
+= strlen(bufptr
);
1009 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(params
);
1011 cparam
= (ppd_cparam_t
*)cupsArrayNext(params
))
1013 switch (cparam
->type
)
1015 case PPD_CUSTOM_CURVE
:
1016 case PPD_CUSTOM_INVCURVE
:
1017 case PPD_CUSTOM_POINTS
:
1018 case PPD_CUSTOM_REAL
:
1019 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
1020 cparam
->current
.custom_real
, loc
);
1024 case PPD_CUSTOM_INT
:
1025 snprintf(bufptr
, bufend
- bufptr
+ 1, "%d\n",
1026 cparam
->current
.custom_int
);
1027 bufptr
+= strlen(bufptr
);
1030 case PPD_CUSTOM_PASSCODE
:
1031 case PPD_CUSTOM_PASSWORD
:
1032 case PPD_CUSTOM_STRING
:
1035 for (s
= cparam
->current
.custom_string
; *s
; s
++)
1036 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
1038 snprintf(bufptr
, bufend
- bufptr
+ 1, "\\%03o", *s
& 255);
1039 bufptr
+= strlen(bufptr
);
1050 cupsArrayDelete(params
);
1054 snprintf(bufptr
, bufend
- bufptr
+ 1, "%%%%BeginFeature: *%s %s\n",
1055 choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1056 bufptr
+= strlen(bufptr
);
1059 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1061 j
= (int)strlen(choices
[i
]->code
);
1062 memcpy(bufptr
, choices
[i
]->code
, j
);
1065 if (choices
[i
]->code
[j
- 1] != '\n')
1069 strlcpy(bufptr
, "%%EndFeature\n"
1070 "} stopped cleartomark\n", bufend
- bufptr
+ 1);
1071 bufptr
+= strlen(bufptr
);
1073 DEBUG_printf(("2ppdEmitString: Offset in string is %d...",
1074 (int)(bufptr
- buffer
)));
1078 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
1079 bufptr
+= strlen(bufptr
);
1083 * Nul-terminate, free, and return...
1095 * 'ppd_compare_cparams()' - Compare the order of two custom parameters.
1098 static int /* O - Result of comparison */
1099 ppd_compare_cparams(ppd_cparam_t
*a
, /* I - First parameter */
1100 ppd_cparam_t
*b
) /* I - Second parameter */
1102 return (a
->order
- b
->order
);
1107 * 'ppd_handle_media()' - Handle media selection...
1111 ppd_handle_media(ppd_file_t
*ppd
) /* I - PPD file */
1113 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1114 *input_slot
; /* InputSlot choice, if any */
1115 ppd_size_t
*size
; /* Current media size */
1116 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1120 * This function determines what page size code to use, if any, for the
1121 * current media size, InputSlot, and ManualFeed selections.
1123 * We use the PageSize code if:
1125 * 1. A custom media size is selected.
1126 * 2. ManualFeed and InputSlot are not selected (or do not exist).
1127 * 3. ManualFeed is selected but is False and InputSlot is not selected or
1128 * the selection has no code - the latter check done to support "auto" or
1129 * "printer default" InputSlot options.
1131 * We use the PageRegion code if:
1133 * 4. RequiresPageRegion does not exist and the PPD contains cupsFilter
1134 * keywords, indicating this is a CUPS-based driver.
1135 * 5. RequiresPageRegion exists for the selected InputSlot (or "All" for any
1136 * InputSlot or ManualFeed selection) and is True.
1138 * If none of the 5 conditions are true, no page size code is used and we
1139 * unmark any existing PageSize or PageRegion choices.
1142 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1145 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1146 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1148 if (input_slot
!= NULL
)
1149 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1154 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1156 if (!strcasecmp(size
->name
, "Custom") ||
1157 (!manual_feed
&& !input_slot
) ||
1158 (manual_feed
&& !strcasecmp(manual_feed
->choice
, "False") &&
1159 (!input_slot
|| (input_slot
->code
&& !input_slot
->code
[0]))) ||
1160 (!rpr
&& ppd
->num_filters
> 0))
1163 * Use PageSize code...
1166 ppdMarkOption(ppd
, "PageSize", size
->name
);
1168 else if (rpr
&& rpr
->value
&& !strcasecmp(rpr
->value
, "True"))
1171 * Use PageRegion code...
1174 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1179 * Do not use PageSize or PageRegion code...
1182 ppd_choice_t
*page
; /* PageSize/Region choice, if any */
1184 if ((page
= ppdFindMarkedChoice(ppd
, "PageSize")) != NULL
)
1187 * Unmark PageSize...
1191 cupsArrayRemove(ppd
->marked
, page
);
1194 if ((page
= ppdFindMarkedChoice(ppd
, "PageRegion")) != NULL
)
1197 * Unmark PageRegion...
1201 cupsArrayRemove(ppd
->marked
, page
);
1208 * End of "$Id: emit.c 7863 2008-08-26 03:39:59Z mike $".