]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/ppd-page.c
4 * Page size functions for CUPS.
6 * Copyright 2007-2015 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 "string-private.h"
25 #include "debug-private.h"
30 * 'ppdPageSize()' - Get the page size record for the named size.
33 ppd_size_t
* /* O - Size record for page or NULL */
34 ppdPageSize(ppd_file_t
*ppd
, /* I - PPD file record */
35 const char *name
) /* I - Size name */
37 int i
; /* Looping var */
38 ppd_size_t
*size
; /* Current page size */
39 double w
, l
; /* Width and length of page */
40 char *nameptr
; /* Pointer into name */
41 struct lconv
*loc
; /* Locale data */
42 ppd_coption_t
*coption
; /* Custom option for page size */
43 ppd_cparam_t
*cparam
; /* Custom option parameter */
46 DEBUG_printf(("2ppdPageSize(ppd=%p, name=\"%s\")", ppd
, name
));
50 DEBUG_puts("3ppdPageSize: Bad PPD pointer, returning NULL...");
56 if (!strncmp(name
, "Custom.", 7) && ppd
->variable_sizes
)
59 * Find the custom page size...
62 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
63 if (!strcmp("Custom", size
->name
))
68 DEBUG_puts("3ppdPageSize: No custom sizes, returning NULL...");
73 * Variable size; size name can be one of the following:
75 * Custom.WIDTHxLENGTHin - Size in inches
76 * Custom.WIDTHxLENGTHft - Size in feet
77 * Custom.WIDTHxLENGTHcm - Size in centimeters
78 * Custom.WIDTHxLENGTHmm - Size in millimeters
79 * Custom.WIDTHxLENGTHm - Size in meters
80 * Custom.WIDTHxLENGTH[pt] - Size in points
84 w
= _cupsStrScand(name
+ 7, &nameptr
, loc
);
85 if (!nameptr
|| *nameptr
!= 'x')
88 l
= _cupsStrScand(nameptr
+ 1, &nameptr
, loc
);
92 if (!_cups_strcasecmp(nameptr
, "in"))
97 else if (!_cups_strcasecmp(nameptr
, "ft"))
102 else if (!_cups_strcasecmp(nameptr
, "mm"))
107 else if (!_cups_strcasecmp(nameptr
, "cm"))
112 else if (!_cups_strcasecmp(nameptr
, "m"))
118 size
->width
= (float)w
;
119 size
->length
= (float)l
;
120 size
->left
= ppd
->custom_margins
[0];
121 size
->bottom
= ppd
->custom_margins
[1];
122 size
->right
= (float)(w
- ppd
->custom_margins
[2]);
123 size
->top
= (float)(l
- ppd
->custom_margins
[3]);
126 * Update the custom option records for the page size, too...
129 if ((coption
= ppdFindCustomOption(ppd
, "PageSize")) != NULL
)
131 if ((cparam
= ppdFindCustomParam(coption
, "Width")) != NULL
)
132 cparam
->current
.custom_points
= (float)w
;
134 if ((cparam
= ppdFindCustomParam(coption
, "Height")) != NULL
)
135 cparam
->current
.custom_points
= (float)l
;
139 * Return the page size...
142 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
143 size
->name
, size
->width
, size
->length
));
153 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
154 if (!_cups_strcasecmp(name
, size
->name
))
156 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
157 size
->name
, size
->width
, size
->length
));
169 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
172 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
173 size
->name
, size
->width
, size
->length
));
179 DEBUG_puts("3ppdPageSize: Size not found, returning NULL");
186 * 'ppdPageSizeLimits()' - Return the custom page size limits.
188 * This function returns the minimum and maximum custom page sizes and printable
189 * areas based on the currently-marked (selected) options.
191 * If the specified PPD file does not support custom page sizes, both
192 * "minimum" and "maximum" are filled with zeroes.
194 * @since CUPS 1.4/OS X 10.6@
197 int /* O - 1 if custom sizes are supported, 0 otherwise */
198 ppdPageSizeLimits(ppd_file_t
*ppd
, /* I - PPD file record */
199 ppd_size_t
*minimum
, /* O - Minimum custom size */
200 ppd_size_t
*maximum
) /* O - Maximum custom size */
202 ppd_choice_t
*qualifier2
, /* Second media qualifier */
203 *qualifier3
; /* Third media qualifier */
204 ppd_attr_t
*attr
; /* Attribute */
205 float width
, /* Min/max width */
206 length
; /* Min/max length */
207 char spec
[PPD_MAX_NAME
]; /* Selector for min/max */
211 * Range check input...
214 if (!ppd
|| !ppd
->variable_sizes
|| !minimum
|| !maximum
)
217 memset(minimum
, 0, sizeof(ppd_size_t
));
220 memset(maximum
, 0, sizeof(ppd_size_t
));
226 * See if we have the cupsMediaQualifier2 and cupsMediaQualifier3 attributes...
229 cupsArraySave(ppd
->sorted_attrs
);
231 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier2", NULL
)) != NULL
&&
233 qualifier2
= ppdFindMarkedChoice(ppd
, attr
->value
);
237 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier3", NULL
)) != NULL
&&
239 qualifier3
= ppdFindMarkedChoice(ppd
, attr
->value
);
244 * Figure out the current minimum width and length...
247 width
= ppd
->custom_min
[0];
248 length
= ppd
->custom_min
[1];
253 * Try getting cupsMinSize...
258 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
260 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
267 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
268 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
271 if (!attr
&& qualifier3
)
273 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
274 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
277 if ((attr
&& attr
->value
&&
278 sscanf(attr
->value
, "%f%f", &width
, &length
) != 2) || !attr
)
280 width
= ppd
->custom_min
[0];
281 length
= ppd
->custom_min
[1];
285 minimum
->width
= width
;
286 minimum
->length
= length
;
287 minimum
->left
= ppd
->custom_margins
[0];
288 minimum
->bottom
= ppd
->custom_margins
[1];
289 minimum
->right
= width
- ppd
->custom_margins
[2];
290 minimum
->top
= length
- ppd
->custom_margins
[3];
293 * Figure out the current maximum width and length...
296 width
= ppd
->custom_max
[0];
297 length
= ppd
->custom_max
[1];
302 * Try getting cupsMaxSize...
307 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
309 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
316 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
317 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
320 if (!attr
&& qualifier3
)
322 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
323 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
327 (attr
->value
&& sscanf(attr
->value
, "%f%f", &width
, &length
) != 2))
329 width
= ppd
->custom_max
[0];
330 length
= ppd
->custom_max
[1];
334 maximum
->width
= width
;
335 maximum
->length
= length
;
336 maximum
->left
= ppd
->custom_margins
[0];
337 maximum
->bottom
= ppd
->custom_margins
[1];
338 maximum
->right
= width
- ppd
->custom_margins
[2];
339 maximum
->top
= length
- ppd
->custom_margins
[3];
342 * Return the min and max...
345 cupsArrayRestore(ppd
->sorted_attrs
);
352 * 'ppdPageWidth()' - Get the page width for the given size.
355 float /* O - Width of page in points or 0.0 */
356 ppdPageWidth(ppd_file_t
*ppd
, /* I - PPD file record */
357 const char *name
) /* I - Size name */
359 ppd_size_t
*size
; /* Page size */
362 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
365 return (size
->width
);
370 * 'ppdPageLength()' - Get the page length for the given size.
373 float /* O - Length of page in points or 0.0 */
374 ppdPageLength(ppd_file_t
*ppd
, /* I - PPD file */
375 const char *name
) /* I - Size name */
377 ppd_size_t
*size
; /* Page size */
380 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
383 return (size
->length
);