]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/emit.c
fed81fc48ae09c5e947b33fadd1268fc294d2969
2 * "$Id: emit.c 7493 2008-04-24 00:10:34Z mike $"
4 * PPD code emission routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 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 options.
32 * ppd_handle_media() - Handle media selection...
36 * Include necessary headers...
45 #if defined(WIN32) || defined(__EMX__)
49 #endif /* WIN32 || __EMX__ */
56 static void ppd_handle_media(ppd_file_t
*ppd
);
63 static const char ppd_custom_code
[] =
65 "<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
69 * 'ppdCollect()' - Collect all marked options that reside in the specified
72 * The choices array should be freed using @code free@ when you are
76 int /* O - Number of options marked */
77 ppdCollect(ppd_file_t
*ppd
, /* I - PPD file data */
78 ppd_section_t section
, /* I - Section to collect */
79 ppd_choice_t
***choices
) /* O - Pointers to choices */
81 return (ppdCollect2(ppd
, section
, 0.0, choices
));
86 * 'ppdCollect2()' - Collect all marked options that reside in the
87 * specified section and minimum order.
89 * The choices array should be freed using @code free@ when you are
95 int /* O - Number of options marked */
96 ppdCollect2(ppd_file_t
*ppd
, /* I - PPD file data */
97 ppd_section_t section
, /* I - Section to collect */
98 float min_order
, /* I - Minimum OrderDependency value */
99 ppd_choice_t
***choices
) /* O - Pointers to choices */
101 ppd_choice_t
*c
; /* Current choice */
102 ppd_section_t csection
; /* Current section */
103 float corder
; /* Current OrderDependency value */
104 int count
; /* Number of choices collected */
105 ppd_choice_t
**collect
; /* Collected choices */
106 float *orders
; /* Collected order values */
109 DEBUG_printf(("ppdCollect2(ppd=%p, section=%d, min_order=%f, choices=%p)\n",
110 ppd
, section
, min_order
, choices
));
112 if (!ppd
|| !choices
)
121 * Allocate memory for up to N selected choices...
125 if ((collect
= calloc(sizeof(ppd_choice_t
*),
126 cupsArrayCount(ppd
->marked
))) == NULL
)
132 if ((orders
= calloc(sizeof(float), cupsArrayCount(ppd
->marked
))) == NULL
)
140 * Loop through all options and add choices as needed...
143 for (c
= (ppd_choice_t
*)cupsArrayFirst(ppd
->marked
);
145 c
= (ppd_choice_t
*)cupsArrayNext(ppd
->marked
))
147 csection
= c
->option
->section
;
148 corder
= c
->option
->order
;
150 if (!strcmp(c
->choice
, "Custom"))
152 ppd_attr_t
*attr
; /* NonUIOrderDependency value */
153 float aorder
; /* Order value */
154 char asection
[17], /* Section name */
155 amain
[PPD_MAX_NAME
+ 1],
156 aoption
[PPD_MAX_NAME
];
157 /* *CustomFoo and True */
160 for (attr
= ppdFindAttr(ppd
, "NonUIOrderDependency", NULL
);
162 attr
= ppdFindNextAttr(ppd
, "NonUIOrderDependency", NULL
))
164 sscanf(attr
->value
, "%f%16s%41s%40s", &aorder
, asection
, amain
,
166 !strncmp(amain
, "*Custom", 7) &&
167 !strcmp(amain
+ 7, c
->option
->keyword
) && !strcmp(aoption
, "True"))
170 * Use this NonUIOrderDependency...
175 if (!strcmp(asection
, "DocumentSetup"))
176 csection
= PPD_ORDER_DOCUMENT
;
177 else if (!strcmp(asection
, "ExitServer"))
178 csection
= PPD_ORDER_EXIT
;
179 else if (!strcmp(asection
, "JCLSetup"))
180 csection
= PPD_ORDER_JCL
;
181 else if (!strcmp(asection
, "PageSetup"))
182 csection
= PPD_ORDER_PAGE
;
183 else if (!strcmp(asection
, "Prolog"))
184 csection
= PPD_ORDER_PROLOG
;
186 csection
= PPD_ORDER_ANY
;
192 if (csection
== section
&& corder
>= min_order
)
195 orders
[count
] = corder
;
201 * If we have more than 1 marked choice, sort them...
206 int i
, j
; /* Looping vars */
208 for (i
= 0; i
< (count
- 1); i
++)
209 for (j
= i
+ 1; j
< count
; j
++)
210 if (orders
[i
] > orders
[j
])
214 collect
[i
] = collect
[j
];
215 orders
[i
] = orders
[j
];
223 DEBUG_printf(("ppdCollect2: %d marked choices...\n", count
));
226 * Return the array and number of choices; if 0, free the array since
245 * 'ppdEmit()' - Emit code for marked options to a file.
248 int /* O - 0 on success, -1 on failure */
249 ppdEmit(ppd_file_t
*ppd
, /* I - PPD file record */
250 FILE *fp
, /* I - File to write to */
251 ppd_section_t section
) /* I - Section to write */
253 return (ppdEmitAfterOrder(ppd
, fp
, section
, 0, 0.0));
258 * 'ppdEmitAfterOrder()' - Emit a subset of the code for marked options to a file.
260 * When "limit" is non-zero, this function only emits options whose
261 * OrderDependency value is greater than or equal to "min_order".
263 * When "limit" is zero, this function is identical to ppdEmit().
268 int /* O - 0 on success, -1 on failure */
270 ppd_file_t
*ppd
, /* I - PPD file record */
271 FILE *fp
, /* I - File to write to */
272 ppd_section_t section
, /* I - Section to write */
273 int limit
, /* I - Non-zero to use min_order */
274 float min_order
) /* I - Lowest OrderDependency */
276 char *buffer
; /* Option code */
277 int status
; /* Return status */
281 * Range check input...
291 buffer
= ppdEmitString(ppd
, section
, min_order
);
294 * Write it as needed and return...
299 status
= fputs(buffer
, fp
) < 0 ? -1 : 0;
311 * 'ppdEmitFd()' - Emit code for marked options to a file.
314 int /* O - 0 on success, -1 on failure */
315 ppdEmitFd(ppd_file_t
*ppd
, /* I - PPD file record */
316 int fd
, /* I - File to write to */
317 ppd_section_t section
) /* I - Section to write */
319 char *buffer
, /* Option code */
320 *bufptr
; /* Pointer into code */
321 size_t buflength
; /* Length of option code */
322 ssize_t bytes
; /* Bytes written */
323 int status
; /* Return status */
327 * Range check input...
337 buffer
= ppdEmitString(ppd
, section
, 0.0);
340 * Write it as needed and return...
345 buflength
= strlen(buffer
);
349 while (buflength
> 0)
352 if ((bytes
= (ssize_t
)write(fd
, bufptr
, (unsigned)buflength
)) < 0)
354 if ((bytes
= write(fd
, bufptr
, buflength
)) < 0)
357 if (errno
== EAGAIN
|| errno
== EINTR
)
367 status
= bytes
< 0 ? -1 : 0;
379 * 'ppdEmitJCL()' - Emit code for JCL options to a file.
382 int /* O - 0 on success, -1 on failure */
383 ppdEmitJCL(ppd_file_t
*ppd
, /* I - PPD file record */
384 FILE *fp
, /* I - File to write to */
385 int job_id
, /* I - Job ID */
386 const char *user
, /* I - Username */
387 const char *title
) /* I - Title */
389 char *ptr
; /* Pointer into JCL string */
390 char temp
[81]; /* Local title string */
394 * Range check the input...
397 if (!ppd
|| !ppd
->jcl_begin
|| !ppd
->jcl_ps
)
401 * See if the printer supports HP PJL...
404 if (!strncmp(ppd
->jcl_begin
, "\033%-12345X@", 10))
407 * This printer uses HP PJL commands for output; filter the output
408 * so that we only have a single "@PJL JOB" command in the header...
410 * To avoid bugs in the PJL implementation of certain vendors' products
411 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
412 * of the PJL commands to initialize PJL processing.
415 ppd_attr_t
*charset
; /* PJL charset */
416 ppd_attr_t
*display
; /* PJL display command */
419 if ((charset
= ppdFindAttr(ppd
, "cupsPJLCharset", NULL
)) != NULL
)
421 if (!charset
->value
|| strcasecmp(charset
->value
, "UTF-8"))
425 if ((display
= ppdFindAttr(ppd
, "cupsPJLDisplay", NULL
)) != NULL
)
431 fputs("\033%-12345X@PJL\n", fp
);
432 for (ptr
= ppd
->jcl_begin
+ 9; *ptr
;)
433 if (!strncmp(ptr
, "@PJL JOB", 8))
436 * Skip job command...
464 * Eliminate any path info from the job title...
467 if ((ptr
= strrchr(title
, '/')) != NULL
)
471 * Replace double quotes with single quotes and 8-bit characters with
472 * question marks so that the title does not cause a PJL syntax error.
475 strlcpy(temp
, title
, sizeof(temp
));
477 for (ptr
= temp
; *ptr
; ptr
++)
480 else if (charset
&& (*ptr
& 128))
484 * Send PJL JOB and PJL RDYMSG commands before we enter PostScript mode...
487 if (display
&& strcmp(display
->value
, "job"))
489 fprintf(fp
, "@PJL JOB NAME = \"%s\"\n", temp
);
491 if (display
&& !strcmp(display
->value
, "rdymsg"))
492 fprintf(fp
, "@PJL RDYMSG DISPLAY = \"%d %s %s\"\n", job_id
, user
, temp
);
495 fprintf(fp
, "@PJL JOB NAME = \"%s\" DISPLAY = \"%d %s %s\"\n", temp
,
499 fputs(ppd
->jcl_begin
, fp
);
501 ppdEmit(ppd
, fp
, PPD_ORDER_JCL
);
502 fputs(ppd
->jcl_ps
, fp
);
509 * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
514 int /* O - 0 on success, -1 on failure */
515 ppdEmitJCLEnd(ppd_file_t
*ppd
, /* I - PPD file record */
516 FILE *fp
) /* I - File to write to */
519 * Range check the input...
527 if (ppd
->num_filters
== 0)
534 * See if the printer supports HP PJL...
537 if (!strncmp(ppd
->jcl_end
, "\033%-12345X@", 10))
540 * This printer uses HP PJL commands for output; filter the output
541 * so that we only have a single "@PJL JOB" command in the header...
543 * To avoid bugs in the PJL implementation of certain vendors' products
544 * (Xerox in particular), we add a dummy "@PJL" command at the beginning
545 * of the PJL commands to initialize PJL processing.
548 fputs("\033%-12345X@PJL\n", fp
);
549 fputs("@PJL RDYMSG DISPLAY = \"READY\"\n", fp
);
550 fputs(ppd
->jcl_end
+ 9, fp
);
553 fputs(ppd
->jcl_end
, fp
);
560 * 'ppdEmitString()' - Get a string containing the code for marked options.
562 * When "min_order" is greater than zero, this function only includes options
563 * whose OrderDependency value is greater than or equal to "min_order".
564 * Otherwise, all options in the specified section are included in the
567 * The return string is allocated on the heap and should be freed using
568 * @code free@ when you are done with it.
573 char * /* O - String containing option code or @code NULL@ if there is no option code */
574 ppdEmitString(ppd_file_t
*ppd
, /* I - PPD file record */
575 ppd_section_t section
, /* I - Section to write */
576 float min_order
) /* I - Lowest OrderDependency */
578 int i
, j
, /* Looping vars */
579 count
; /* Number of choices */
580 ppd_choice_t
**choices
; /* Choices */
581 ppd_size_t
*size
; /* Custom page size */
582 ppd_coption_t
*coption
; /* Custom option */
583 ppd_cparam_t
*cparam
; /* Custom parameter */
584 size_t bufsize
; /* Size of string buffer needed */
585 char *buffer
, /* String buffer */
586 *bufptr
, /* Pointer into buffer */
587 *bufend
; /* End of buffer */
588 struct lconv
*loc
; /* Locale data */
591 DEBUG_printf(("ppdEmitString(ppd=%p, section=%d, min_order=%f)\n",
592 ppd
, section
, min_order
));
595 * Range check input...
602 * Use PageSize or PageRegion as required...
605 ppd_handle_media(ppd
);
608 * Collect the options we need to emit...
611 if ((count
= ppdCollect2(ppd
, section
, min_order
, &choices
)) == 0)
615 * Count the number of bytes that are required to hold all of the
619 for (i
= 0, bufsize
= 1; i
< count
; i
++)
621 if (section
== PPD_ORDER_JCL
)
623 if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
624 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
628 * Add space to account for custom parameter substitution...
631 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
633 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
635 switch (cparam
->type
)
637 case PPD_CUSTOM_CURVE
:
638 case PPD_CUSTOM_INVCURVE
:
639 case PPD_CUSTOM_POINTS
:
640 case PPD_CUSTOM_REAL
:
641 case PPD_CUSTOM_INT
:
645 case PPD_CUSTOM_PASSCODE
:
646 case PPD_CUSTOM_PASSWORD
:
647 case PPD_CUSTOM_STRING
:
648 bufsize
+= strlen(cparam
->current
.custom_string
);
654 else if (section
!= PPD_ORDER_EXIT
)
656 bufsize
+= 3; /* [{\n */
658 if ((!strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
659 !strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
660 !strcasecmp(choices
[i
]->choice
, "Custom"))
662 DEBUG_puts("ppdEmitString: Custom size set!");
664 bufsize
+= 37; /* %%BeginFeature: *CustomPageSize True\n */
665 bufsize
+= 50; /* Five 9-digit numbers + newline */
667 else if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
668 (coption
= ppdFindCustomOption(ppd
,
669 choices
[i
]->option
->keyword
))
672 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 6;
673 /* %%BeginFeature: *keyword True\n */
676 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
678 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
680 switch (cparam
->type
)
682 case PPD_CUSTOM_CURVE
:
683 case PPD_CUSTOM_INVCURVE
:
684 case PPD_CUSTOM_POINTS
:
685 case PPD_CUSTOM_REAL
:
686 case PPD_CUSTOM_INT
:
690 case PPD_CUSTOM_PASSCODE
:
691 case PPD_CUSTOM_PASSWORD
:
692 case PPD_CUSTOM_STRING
:
693 bufsize
+= 3 + 4 * strlen(cparam
->current
.custom_string
);
699 bufsize
+= 17 + strlen(choices
[i
]->option
->keyword
) + 1 +
700 strlen(choices
[i
]->choice
) + 1;
701 /* %%BeginFeature: *keyword choice\n */
703 bufsize
+= 13; /* %%EndFeature\n */
704 bufsize
+= 22; /* } stopped cleartomark\n */
707 if (choices
[i
]->code
)
708 bufsize
+= strlen(choices
[i
]->code
) + 1;
710 bufsize
+= strlen(ppd_custom_code
);
717 DEBUG_printf(("ppdEmitString: Allocating %d bytes for string...\n",
720 if ((buffer
= calloc(1, bufsize
)) == NULL
)
726 bufend
= buffer
+ bufsize
- 1;
730 * Copy the option code to the buffer...
733 for (i
= 0, bufptr
= buffer
; i
< count
; i
++, bufptr
+= strlen(bufptr
))
734 if (section
== PPD_ORDER_JCL
)
736 if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
737 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
741 * Handle substitutions in custom JCL options...
744 char *cptr
; /* Pointer into code */
745 int pnum
; /* Parameter number */
748 for (cptr
= choices
[i
]->code
; *cptr
&& bufptr
< bufend
;)
754 if (isdigit(*cptr
& 255))
757 * Substitute parameter...
760 pnum
= *cptr
++ - '0';
761 while (isalnum(*cptr
& 255))
762 pnum
= pnum
* 10 + *cptr
- '0';
764 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
766 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
767 if (cparam
->order
== pnum
)
772 switch (cparam
->type
)
774 case PPD_CUSTOM_CURVE
:
775 case PPD_CUSTOM_INVCURVE
:
776 case PPD_CUSTOM_POINTS
:
777 case PPD_CUSTOM_REAL
:
778 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
779 cparam
->current
.custom_real
,
783 case PPD_CUSTOM_INT
:
784 snprintf(bufptr
, bufend
- bufptr
, "%d",
785 cparam
->current
.custom_int
);
786 bufptr
+= strlen(bufptr
);
789 case PPD_CUSTOM_PASSCODE
:
790 case PPD_CUSTOM_PASSWORD
:
791 case PPD_CUSTOM_STRING
:
792 strlcpy(bufptr
, cparam
->current
.custom_string
,
794 bufptr
+= strlen(bufptr
);
809 * Otherwise just copy the option code directly...
812 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
813 bufptr
+= strlen(bufptr
);
816 else if (section
!= PPD_ORDER_EXIT
)
819 * Add wrapper commands to prevent printer errors for unsupported
823 strlcpy(bufptr
, "[{\n", bufend
- bufptr
+ 1);
827 * Send DSC comments with option...
830 DEBUG_printf(("Adding code for %s=%s...\n", choices
[i
]->option
->keyword
,
831 choices
[i
]->choice
));
833 if ((!strcasecmp(choices
[i
]->option
->keyword
, "PageSize") ||
834 !strcasecmp(choices
[i
]->option
->keyword
, "PageRegion")) &&
835 !strcasecmp(choices
[i
]->choice
, "Custom"))
838 * Variable size; write out standard size options, using the
839 * parameter positions defined in the PPD file...
842 ppd_attr_t
*attr
; /* PPD attribute */
843 int pos
, /* Position of custom value */
844 orientation
; /* Orientation to use */
845 float values
[5]; /* Values for custom command */
848 strlcpy(bufptr
, "%%BeginFeature: *CustomPageSize True\n",
849 bufend
- bufptr
+ 1);
852 size
= ppdPageSize(ppd
, "Custom");
854 memset(values
, 0, sizeof(values
));
856 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Width")) != NULL
)
858 pos
= atoi(attr
->value
) - 1;
860 if (pos
< 0 || pos
> 4)
866 values
[pos
] = size
->width
;
868 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize", "Height")) != NULL
)
870 pos
= atoi(attr
->value
) - 1;
872 if (pos
< 0 || pos
> 4)
878 values
[pos
] = size
->length
;
881 * According to the Adobe PPD specification, an orientation of 1
882 * will produce a print that comes out upside-down with the X
883 * axis perpendicular to the direction of feed, which is exactly
884 * what we want to be consistent with non-PS printers.
886 * We could also use an orientation of 3 to produce output that
887 * comes out rightside-up (this is the default for many large format
888 * printer PPDs), however for consistency we will stick with the
891 * If we wanted to get fancy, we could use orientations of 0 or
892 * 2 and swap the width and length, however we don't want to get
893 * fancy, we just want it to work consistently.
895 * The orientation value is range limited by the Orientation
896 * parameter definition, so certain non-PS printer drivers that
897 * only support an Orientation of 0 will get the value 0 as
903 if ((attr
= ppdFindAttr(ppd
, "ParamCustomPageSize",
904 "Orientation")) != NULL
)
906 int min_orient
, max_orient
; /* Minimum and maximum orientations */
909 if (sscanf(attr
->value
, "%d%*s%d%d", &pos
, &min_orient
,
916 if (pos
< 0 || pos
> 4)
919 if (orientation
> max_orient
)
920 orientation
= max_orient
;
921 else if (orientation
< min_orient
)
922 orientation
= min_orient
;
928 values
[pos
] = (float)orientation
;
930 for (pos
= 0; pos
< 5; pos
++)
932 bufptr
= _cupsStrFormatd(bufptr
, bufend
, values
[pos
], loc
);
936 if (!choices
[i
]->code
)
939 * This can happen with certain buggy PPD files that don't include
940 * a CustomPageSize command sequence... We just use a generic
941 * Level 2 command sequence...
944 strlcpy(bufptr
, ppd_custom_code
, bufend
- bufptr
+ 1);
945 bufptr
+= strlen(bufptr
);
948 else if (!strcasecmp(choices
[i
]->choice
, "Custom") &&
949 (coption
= ppdFindCustomOption(ppd
, choices
[i
]->option
->keyword
))
956 const char *s
; /* Pointer into string value */
959 snprintf(bufptr
, bufend
- bufptr
+ 1,
960 "%%%%BeginFeature: *Custom%s True\n", coption
->keyword
);
961 bufptr
+= strlen(bufptr
);
963 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
965 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
967 switch (cparam
->type
)
969 case PPD_CUSTOM_CURVE
:
970 case PPD_CUSTOM_INVCURVE
:
971 case PPD_CUSTOM_POINTS
:
972 case PPD_CUSTOM_REAL
:
973 bufptr
= _cupsStrFormatd(bufptr
, bufend
,
974 cparam
->current
.custom_real
, loc
);
978 case PPD_CUSTOM_INT
:
979 snprintf(bufptr
, bufend
- bufptr
+ 1, "%d\n",
980 cparam
->current
.custom_int
);
981 bufptr
+= strlen(bufptr
);
984 case PPD_CUSTOM_PASSCODE
:
985 case PPD_CUSTOM_PASSWORD
:
986 case PPD_CUSTOM_STRING
:
989 for (s
= cparam
->current
.custom_string
; *s
; s
++)
990 if (*s
< ' ' || *s
== '(' || *s
== ')' || *s
>= 127)
992 snprintf(bufptr
, bufend
- bufptr
+ 1, "\\%03o", *s
& 255);
993 bufptr
+= strlen(bufptr
);
1006 snprintf(bufptr
, bufend
- bufptr
+ 1, "%%%%BeginFeature: *%s %s\n",
1007 choices
[i
]->option
->keyword
, choices
[i
]->choice
);
1008 bufptr
+= strlen(bufptr
);
1011 if (choices
[i
]->code
&& choices
[i
]->code
[0])
1013 j
= (int)strlen(choices
[i
]->code
);
1014 memcpy(bufptr
, choices
[i
]->code
, j
);
1017 if (choices
[i
]->code
[j
- 1] != '\n')
1021 strlcpy(bufptr
, "%%EndFeature\n"
1022 "} stopped cleartomark\n", bufend
- bufptr
+ 1);
1023 bufptr
+= strlen(bufptr
);
1025 DEBUG_printf(("ppdEmitString: Offset in string is %d...\n",
1026 (int)(bufptr
- buffer
)));
1030 strlcpy(bufptr
, choices
[i
]->code
, bufend
- bufptr
+ 1);
1031 bufptr
+= strlen(bufptr
);
1035 * Nul-terminate, free, and return...
1047 * 'ppd_handle_media()' - Handle media selection...
1051 ppd_handle_media(ppd_file_t
*ppd
)
1053 ppd_choice_t
*manual_feed
, /* ManualFeed choice, if any */
1054 *input_slot
, /* InputSlot choice, if any */
1055 *page
; /* PageSize/PageRegion */
1056 ppd_size_t
*size
; /* Current media size */
1057 ppd_attr_t
*rpr
; /* RequiresPageRegion value */
1061 * This function determines if the user has selected a media source
1062 * via the InputSlot or ManualFeed options; if so, it marks the
1063 * PageRegion option corresponding to the current media size.
1064 * Otherwise it marks the PageSize option.
1067 if ((size
= ppdPageSize(ppd
, NULL
)) == NULL
)
1070 manual_feed
= ppdFindMarkedChoice(ppd
, "ManualFeed");
1071 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
1073 if (input_slot
!= NULL
)
1074 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", input_slot
->choice
);
1079 rpr
= ppdFindAttr(ppd
, "RequiresPageRegion", "All");
1081 if (!strcasecmp(size
->name
, "Custom") || (!manual_feed
&& !input_slot
) ||
1082 !((manual_feed
&& !strcasecmp(manual_feed
->choice
, "True")) ||
1083 (input_slot
&& input_slot
->code
&& input_slot
->code
[0])))
1086 * Manual feed was not selected and/or the input slot selection does
1087 * not contain any PostScript code. Use the PageSize option...
1090 ppdMarkOption(ppd
, "PageSize", size
->name
);
1095 * Manual feed was selected and/or the input slot selection contains
1096 * PostScript code. Use the PageRegion option...
1099 ppdMarkOption(ppd
, "PageRegion", size
->name
);
1102 * RequiresPageRegion does not apply to manual feed so we need to
1103 * check that we are not doing manual feed before unmarking PageRegion.
1106 if (!(manual_feed
&& !strcasecmp(manual_feed
->choice
, "True")) &&
1107 ((rpr
&& rpr
->value
&& !strcmp(rpr
->value
, "False")) ||
1108 (!rpr
&& !ppd
->num_filters
)))
1111 * Either the PPD file specifies no PageRegion code or the PPD file
1112 * not for a CUPS raster driver and thus defaults to no PageRegion
1113 * code... Unmark the PageRegion choice so that we don't output the
1117 page
= ppdFindMarkedChoice(ppd
, "PageRegion");
1127 * End of "$Id: emit.c 7493 2008-04-24 00:10:34Z mike $".