]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/page.c
2 * "$Id: page.c 6649 2007-07-11 21:46:42Z mike $"
4 * Page size functions for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 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 * ppdPageSize() - Get the page size record for the given size.
22 * ppdPageWidth() - Get the page width for the given size.
23 * ppdPageLength() - Get the page length for the given size.
27 * Include necessary headers...
36 * 'ppdPageSize()' - Get the page size record for the given size.
39 ppd_size_t
* /* O - Size record for page or NULL */
40 ppdPageSize(ppd_file_t
*ppd
, /* I - PPD file record */
41 const char *name
) /* I - Size name */
43 int i
; /* Looping var */
44 ppd_size_t
*size
; /* Current page size */
45 float w
, l
; /* Width and length of page */
46 char *nameptr
; /* Pointer into name */
47 struct lconv
*loc
; /* Locale data */
48 ppd_coption_t
*coption
; /* Custom option for page size */
49 ppd_cparam_t
*cparam
; /* Custom option parameter */
57 if (!strncmp(name
, "Custom.", 7) && ppd
->variable_sizes
)
60 * Find the custom page size...
63 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
64 if (!strcmp("Custom", size
->name
))
71 * Variable size; size name can be one of the following:
73 * Custom.WIDTHxLENGTHin - Size in inches
74 * Custom.WIDTHxLENGTHcm - Size in centimeters
75 * Custom.WIDTHxLENGTHmm - Size in millimeters
76 * Custom.WIDTHxLENGTH[pt] - Size in points
80 w
= (float)_cupsStrScand(name
+ 7, &nameptr
, loc
);
81 if (!nameptr
|| *nameptr
!= 'x')
84 l
= (float)_cupsStrScand(nameptr
+ 1, &nameptr
, loc
);
88 if (!strcasecmp(nameptr
, "in"))
93 else if (!strcasecmp(nameptr
, "ft"))
98 else if (!strcasecmp(nameptr
, "mm"))
103 else if (!strcasecmp(nameptr
, "cm"))
108 else if (!strcasecmp(nameptr
, "m"))
110 w
*= 72.0f
/ 0.0254f
;
111 l
*= 72.0f
/ 0.0254f
;
116 size
->left
= ppd
->custom_margins
[0];
117 size
->bottom
= ppd
->custom_margins
[1];
118 size
->right
= w
- ppd
->custom_margins
[2];
119 size
->top
= l
- ppd
->custom_margins
[3];
122 * Update the custom option records for the page size, too...
125 if ((coption
= ppdFindCustomOption(ppd
, "PageSize")) != NULL
)
127 if ((cparam
= ppdFindCustomParam(coption
, "Width")) != NULL
)
128 cparam
->current
.custom_points
= w
;
130 if ((cparam
= ppdFindCustomParam(coption
, "Height")) != NULL
)
131 cparam
->current
.custom_points
= l
;
135 * Return the page size...
146 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
147 if (!strcmp(name
, size
->name
))
157 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
167 * 'ppdPageSizeLimits()' - Return the custom page size limits.
169 * This function returns the minimum and maximum custom page sizes and printable
170 * areas based on the currently-marked (selected) options.
172 * If the specified PPD file does not support custom page sizes, both
173 * "minimum" and "maximum" are filled with zeroes.
178 int /* O - 1 if custom sizes are supported, 0 otherwise */
179 ppdPageSizeLimits(ppd_file_t
*ppd
, /* I - PPD file record */
180 ppd_size_t
*minimum
, /* O - Minimum custom size */
181 ppd_size_t
*maximum
) /* O - Maximum custom size */
183 ppd_choice_t
*qualifier2
, /* Second media qualifier */
184 *qualifier3
; /* Third media qualifier */
185 ppd_attr_t
*attr
; /* Attribute */
186 float width
, /* Min/max width */
187 length
; /* Min/max length */
188 char spec
[PPD_MAX_NAME
]; /* Selector for min/max */
192 * Range check input...
195 if (!ppd
|| !ppd
->variable_sizes
|| !minimum
|| !maximum
)
198 memset(minimum
, 0, sizeof(ppd_size_t
));
201 memset(maximum
, 0, sizeof(ppd_size_t
));
207 * See if we have the cupsMediaQualifier2 and cupsMediaQualifier3 attributes...
210 cupsArraySave(ppd
->sorted_attrs
);
212 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier2", NULL
)) != NULL
&&
214 qualifier2
= ppdFindMarkedChoice(ppd
, attr
->value
);
218 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier3", NULL
)) != NULL
&&
220 qualifier3
= ppdFindMarkedChoice(ppd
, attr
->value
);
225 * Figure out the current minimum width and length...
231 * Try getting cupsMinSize...
236 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
238 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
245 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
246 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
249 if (!attr
&& qualifier3
)
251 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
252 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
256 (attr
->value
&& sscanf(attr
->value
, "%f%f", &width
, &length
) != 2))
258 width
= ppd
->custom_min
[0];
259 length
= ppd
->custom_min
[1];
264 width
= ppd
->custom_min
[0];
265 length
= ppd
->custom_min
[1];
268 minimum
->width
= width
;
269 minimum
->length
= length
;
270 minimum
->left
= ppd
->custom_margins
[0];
271 minimum
->bottom
= ppd
->custom_margins
[1];
272 minimum
->right
= width
- ppd
->custom_margins
[2];
273 minimum
->top
= length
- ppd
->custom_margins
[3];
276 * Figure out the current maximum width and length...
282 * Try getting cupsMaxSize...
287 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
289 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
296 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
297 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
300 if (!attr
&& qualifier3
)
302 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
303 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
307 (attr
->value
&& sscanf(attr
->value
, "%f%f", &width
, &length
) != 2))
309 width
= ppd
->custom_max
[0];
310 length
= ppd
->custom_max
[1];
315 width
= ppd
->custom_max
[0];
316 length
= ppd
->custom_max
[1];
319 maximum
->width
= width
;
320 maximum
->length
= length
;
321 maximum
->left
= ppd
->custom_margins
[0];
322 maximum
->bottom
= ppd
->custom_margins
[1];
323 maximum
->right
= width
- ppd
->custom_margins
[2];
324 maximum
->top
= length
- ppd
->custom_margins
[3];
327 * Return the min and max...
330 cupsArrayRestore(ppd
->sorted_attrs
);
337 * 'ppdPageWidth()' - Get the page width for the given size.
340 float /* O - Width of page in points or 0.0 */
341 ppdPageWidth(ppd_file_t
*ppd
, /* I - PPD file record */
342 const char *name
) /* I - Size name */
344 ppd_size_t
*size
; /* Page size */
347 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
350 return (size
->width
);
355 * 'ppdPageLength()' - Get the page length for the given size.
358 float /* O - Length of page in points or 0.0 */
359 ppdPageLength(ppd_file_t
*ppd
, /* I - PPD file */
360 const char *name
) /* I - Size name */
362 ppd_size_t
*size
; /* Page size */
365 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
368 return (size
->length
);
373 * End of "$Id: page.c 6649 2007-07-11 21:46:42Z mike $".