]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/ppd-page.c
f18e68d0d6f600d55e1564ca8d448c24e7ce0469
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 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
13 * PostScript is a trademark of Adobe Systems, Inc.
15 * This file is subject to the Apple OS-Developed Software exception.
19 * Include necessary headers...
22 #include "string-private.h"
23 #include "debug-private.h"
28 * 'ppdPageSize()' - Get the page size record for the named size.
31 ppd_size_t
* /* O - Size record for page or NULL */
32 ppdPageSize(ppd_file_t
*ppd
, /* I - PPD file record */
33 const char *name
) /* I - Size name */
35 int i
; /* Looping var */
36 ppd_size_t
*size
; /* Current page size */
37 double w
, l
; /* Width and length of page */
38 char *nameptr
; /* Pointer into name */
39 struct lconv
*loc
; /* Locale data */
40 ppd_coption_t
*coption
; /* Custom option for page size */
41 ppd_cparam_t
*cparam
; /* Custom option parameter */
44 DEBUG_printf(("2ppdPageSize(ppd=%p, name=\"%s\")", ppd
, name
));
48 DEBUG_puts("3ppdPageSize: Bad PPD pointer, returning NULL...");
54 if (!strncmp(name
, "Custom.", 7) && ppd
->variable_sizes
)
57 * Find the custom page size...
60 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
61 if (!strcmp("Custom", size
->name
))
66 DEBUG_puts("3ppdPageSize: No custom sizes, returning NULL...");
71 * Variable size; size name can be one of the following:
73 * Custom.WIDTHxLENGTHin - Size in inches
74 * Custom.WIDTHxLENGTHft - Size in feet
75 * Custom.WIDTHxLENGTHcm - Size in centimeters
76 * Custom.WIDTHxLENGTHmm - Size in millimeters
77 * Custom.WIDTHxLENGTHm - Size in meters
78 * Custom.WIDTHxLENGTH[pt] - Size in points
82 w
= _cupsStrScand(name
+ 7, &nameptr
, loc
);
83 if (!nameptr
|| *nameptr
!= 'x')
86 l
= _cupsStrScand(nameptr
+ 1, &nameptr
, loc
);
90 if (!_cups_strcasecmp(nameptr
, "in"))
95 else if (!_cups_strcasecmp(nameptr
, "ft"))
100 else if (!_cups_strcasecmp(nameptr
, "mm"))
105 else if (!_cups_strcasecmp(nameptr
, "cm"))
110 else if (!_cups_strcasecmp(nameptr
, "m"))
116 size
->width
= (float)w
;
117 size
->length
= (float)l
;
118 size
->left
= ppd
->custom_margins
[0];
119 size
->bottom
= ppd
->custom_margins
[1];
120 size
->right
= (float)(w
- ppd
->custom_margins
[2]);
121 size
->top
= (float)(l
- ppd
->custom_margins
[3]);
124 * Update the custom option records for the page size, too...
127 if ((coption
= ppdFindCustomOption(ppd
, "PageSize")) != NULL
)
129 if ((cparam
= ppdFindCustomParam(coption
, "Width")) != NULL
)
130 cparam
->current
.custom_points
= (float)w
;
132 if ((cparam
= ppdFindCustomParam(coption
, "Height")) != NULL
)
133 cparam
->current
.custom_points
= (float)l
;
137 * Return the page size...
140 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
141 size
->name
, size
->width
, size
->length
));
151 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
152 if (!_cups_strcasecmp(name
, size
->name
))
154 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
155 size
->name
, size
->width
, size
->length
));
167 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
170 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
171 size
->name
, size
->width
, size
->length
));
177 DEBUG_puts("3ppdPageSize: Size not found, returning NULL");
184 * 'ppdPageSizeLimits()' - Return the custom page size limits.
186 * This function returns the minimum and maximum custom page sizes and printable
187 * areas based on the currently-marked (selected) options.
189 * If the specified PPD file does not support custom page sizes, both
190 * "minimum" and "maximum" are filled with zeroes.
192 * @since CUPS 1.4/macOS 10.6@
195 int /* O - 1 if custom sizes are supported, 0 otherwise */
196 ppdPageSizeLimits(ppd_file_t
*ppd
, /* I - PPD file record */
197 ppd_size_t
*minimum
, /* O - Minimum custom size */
198 ppd_size_t
*maximum
) /* O - Maximum custom size */
200 ppd_choice_t
*qualifier2
, /* Second media qualifier */
201 *qualifier3
; /* Third media qualifier */
202 ppd_attr_t
*attr
; /* Attribute */
203 float width
, /* Min/max width */
204 length
; /* Min/max length */
205 char spec
[PPD_MAX_NAME
]; /* Selector for min/max */
209 * Range check input...
212 if (!ppd
|| !ppd
->variable_sizes
|| !minimum
|| !maximum
)
215 memset(minimum
, 0, sizeof(ppd_size_t
));
218 memset(maximum
, 0, sizeof(ppd_size_t
));
224 * See if we have the cupsMediaQualifier2 and cupsMediaQualifier3 attributes...
227 cupsArraySave(ppd
->sorted_attrs
);
229 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier2", NULL
)) != NULL
&&
231 qualifier2
= ppdFindMarkedChoice(ppd
, attr
->value
);
235 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier3", NULL
)) != NULL
&&
237 qualifier3
= ppdFindMarkedChoice(ppd
, attr
->value
);
242 * Figure out the current minimum width and length...
245 width
= ppd
->custom_min
[0];
246 length
= ppd
->custom_min
[1];
251 * Try getting cupsMinSize...
256 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
258 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
265 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
266 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
269 if (!attr
&& qualifier3
)
271 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
272 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
275 if ((attr
&& attr
->value
&&
276 sscanf(attr
->value
, "%f%f", &width
, &length
) != 2) || !attr
)
278 width
= ppd
->custom_min
[0];
279 length
= ppd
->custom_min
[1];
283 minimum
->width
= width
;
284 minimum
->length
= length
;
285 minimum
->left
= ppd
->custom_margins
[0];
286 minimum
->bottom
= ppd
->custom_margins
[1];
287 minimum
->right
= width
- ppd
->custom_margins
[2];
288 minimum
->top
= length
- ppd
->custom_margins
[3];
291 * Figure out the current maximum width and length...
294 width
= ppd
->custom_max
[0];
295 length
= ppd
->custom_max
[1];
300 * Try getting cupsMaxSize...
305 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
307 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
314 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
315 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
318 if (!attr
&& qualifier3
)
320 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
321 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
325 (attr
->value
&& sscanf(attr
->value
, "%f%f", &width
, &length
) != 2))
327 width
= ppd
->custom_max
[0];
328 length
= ppd
->custom_max
[1];
332 maximum
->width
= width
;
333 maximum
->length
= length
;
334 maximum
->left
= ppd
->custom_margins
[0];
335 maximum
->bottom
= ppd
->custom_margins
[1];
336 maximum
->right
= width
- ppd
->custom_margins
[2];
337 maximum
->top
= length
- ppd
->custom_margins
[3];
340 * Return the min and max...
343 cupsArrayRestore(ppd
->sorted_attrs
);
350 * 'ppdPageWidth()' - Get the page width for the given size.
353 float /* O - Width of page in points or 0.0 */
354 ppdPageWidth(ppd_file_t
*ppd
, /* I - PPD file record */
355 const char *name
) /* I - Size name */
357 ppd_size_t
*size
; /* Page size */
360 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
363 return (size
->width
);
368 * 'ppdPageLength()' - Get the page length for the given size.
371 float /* O - Length of page in points or 0.0 */
372 ppdPageLength(ppd_file_t
*ppd
, /* I - PPD file */
373 const char *name
) /* I - Size name */
375 ppd_size_t
*size
; /* Page size */
378 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
381 return (size
->length
);