]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/ppd-page.c
2 * Page size functions 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
10 * PostScript is a trademark of Adobe Systems, Inc.
14 * Include necessary headers...
17 #include "string-private.h"
18 #include "debug-private.h"
23 * 'ppdPageSize()' - Get the page size record for the named size.
26 ppd_size_t
* /* O - Size record for page or NULL */
27 ppdPageSize(ppd_file_t
*ppd
, /* I - PPD file record */
28 const char *name
) /* I - Size name */
30 int i
; /* Looping var */
31 ppd_size_t
*size
; /* Current page size */
32 double w
, l
; /* Width and length of page */
33 char *nameptr
; /* Pointer into name */
34 struct lconv
*loc
; /* Locale data */
35 ppd_coption_t
*coption
; /* Custom option for page size */
36 ppd_cparam_t
*cparam
; /* Custom option parameter */
39 DEBUG_printf(("2ppdPageSize(ppd=%p, name=\"%s\")", ppd
, name
));
43 DEBUG_puts("3ppdPageSize: Bad PPD pointer, returning NULL...");
49 if (!strncmp(name
, "Custom.", 7) && ppd
->variable_sizes
)
52 * Find the custom page size...
55 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
56 if (!strcmp("Custom", size
->name
))
61 DEBUG_puts("3ppdPageSize: No custom sizes, returning NULL...");
66 * Variable size; size name can be one of the following:
68 * Custom.WIDTHxLENGTHin - Size in inches
69 * Custom.WIDTHxLENGTHft - Size in feet
70 * Custom.WIDTHxLENGTHcm - Size in centimeters
71 * Custom.WIDTHxLENGTHmm - Size in millimeters
72 * Custom.WIDTHxLENGTHm - Size in meters
73 * Custom.WIDTHxLENGTH[pt] - Size in points
77 w
= _cupsStrScand(name
+ 7, &nameptr
, loc
);
78 if (!nameptr
|| *nameptr
!= 'x')
81 l
= _cupsStrScand(nameptr
+ 1, &nameptr
, loc
);
85 if (!_cups_strcasecmp(nameptr
, "in"))
90 else if (!_cups_strcasecmp(nameptr
, "ft"))
95 else if (!_cups_strcasecmp(nameptr
, "mm"))
100 else if (!_cups_strcasecmp(nameptr
, "cm"))
105 else if (!_cups_strcasecmp(nameptr
, "m"))
111 size
->width
= (float)w
;
112 size
->length
= (float)l
;
113 size
->left
= ppd
->custom_margins
[0];
114 size
->bottom
= ppd
->custom_margins
[1];
115 size
->right
= (float)(w
- ppd
->custom_margins
[2]);
116 size
->top
= (float)(l
- ppd
->custom_margins
[3]);
119 * Update the custom option records for the page size, too...
122 if ((coption
= ppdFindCustomOption(ppd
, "PageSize")) != NULL
)
124 if ((cparam
= ppdFindCustomParam(coption
, "Width")) != NULL
)
125 cparam
->current
.custom_points
= (float)w
;
127 if ((cparam
= ppdFindCustomParam(coption
, "Height")) != NULL
)
128 cparam
->current
.custom_points
= (float)l
;
132 * Return the page size...
135 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
136 size
->name
, size
->width
, size
->length
));
146 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
147 if (!_cups_strcasecmp(name
, size
->name
))
149 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
150 size
->name
, size
->width
, size
->length
));
162 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
165 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
166 size
->name
, size
->width
, size
->length
));
172 DEBUG_puts("3ppdPageSize: Size not found, returning NULL");
179 * 'ppdPageSizeLimits()' - Return the custom page size limits.
181 * This function returns the minimum and maximum custom page sizes and printable
182 * areas based on the currently-marked (selected) options.
184 * If the specified PPD file does not support custom page sizes, both
185 * "minimum" and "maximum" are filled with zeroes.
187 * @since CUPS 1.4/macOS 10.6@
190 int /* O - 1 if custom sizes are supported, 0 otherwise */
191 ppdPageSizeLimits(ppd_file_t
*ppd
, /* I - PPD file record */
192 ppd_size_t
*minimum
, /* O - Minimum custom size */
193 ppd_size_t
*maximum
) /* O - Maximum custom size */
195 ppd_choice_t
*qualifier2
, /* Second media qualifier */
196 *qualifier3
; /* Third media qualifier */
197 ppd_attr_t
*attr
; /* Attribute */
198 float width
, /* Min/max width */
199 length
; /* Min/max length */
200 char spec
[PPD_MAX_NAME
]; /* Selector for min/max */
204 * Range check input...
207 if (!ppd
|| !ppd
->variable_sizes
|| !minimum
|| !maximum
)
210 memset(minimum
, 0, sizeof(ppd_size_t
));
213 memset(maximum
, 0, sizeof(ppd_size_t
));
219 * See if we have the cupsMediaQualifier2 and cupsMediaQualifier3 attributes...
222 cupsArraySave(ppd
->sorted_attrs
);
224 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier2", NULL
)) != NULL
&&
226 qualifier2
= ppdFindMarkedChoice(ppd
, attr
->value
);
230 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier3", NULL
)) != NULL
&&
232 qualifier3
= ppdFindMarkedChoice(ppd
, attr
->value
);
237 * Figure out the current minimum width and length...
240 width
= ppd
->custom_min
[0];
241 length
= ppd
->custom_min
[1];
246 * Try getting cupsMinSize...
251 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
253 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
260 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
261 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
264 if (!attr
&& qualifier3
)
266 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
267 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
270 if ((attr
&& attr
->value
&&
271 sscanf(attr
->value
, "%f%f", &width
, &length
) != 2) || !attr
)
273 width
= ppd
->custom_min
[0];
274 length
= ppd
->custom_min
[1];
278 minimum
->width
= width
;
279 minimum
->length
= length
;
280 minimum
->left
= ppd
->custom_margins
[0];
281 minimum
->bottom
= ppd
->custom_margins
[1];
282 minimum
->right
= width
- ppd
->custom_margins
[2];
283 minimum
->top
= length
- ppd
->custom_margins
[3];
286 * Figure out the current maximum width and length...
289 width
= ppd
->custom_max
[0];
290 length
= ppd
->custom_max
[1];
295 * Try getting cupsMaxSize...
300 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
302 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
309 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
310 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
313 if (!attr
&& qualifier3
)
315 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
316 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
320 (attr
->value
&& sscanf(attr
->value
, "%f%f", &width
, &length
) != 2))
322 width
= ppd
->custom_max
[0];
323 length
= ppd
->custom_max
[1];
327 maximum
->width
= width
;
328 maximum
->length
= length
;
329 maximum
->left
= ppd
->custom_margins
[0];
330 maximum
->bottom
= ppd
->custom_margins
[1];
331 maximum
->right
= width
- ppd
->custom_margins
[2];
332 maximum
->top
= length
- ppd
->custom_margins
[3];
335 * Return the min and max...
338 cupsArrayRestore(ppd
->sorted_attrs
);
345 * 'ppdPageWidth()' - Get the page width for the given size.
348 float /* O - Width of page in points or 0.0 */
349 ppdPageWidth(ppd_file_t
*ppd
, /* I - PPD file record */
350 const char *name
) /* I - Size name */
352 ppd_size_t
*size
; /* Page size */
355 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
358 return (size
->width
);
363 * 'ppdPageLength()' - Get the page length for the given size.
366 float /* O - Length of page in points or 0.0 */
367 ppdPageLength(ppd_file_t
*ppd
, /* I - PPD file */
368 const char *name
) /* I - Size name */
370 ppd_size_t
*size
; /* Page size */
373 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
376 return (size
->length
);