]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/page.c
2 * "$Id: page.c 7791 2008-07-24 00:55:30Z mike $"
4 * Page size functions for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2009 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...
37 * 'ppdPageSize()' - Get the page size record for the given size.
40 ppd_size_t
* /* O - Size record for page or NULL */
41 ppdPageSize(ppd_file_t
*ppd
, /* I - PPD file record */
42 const char *name
) /* I - Size name */
44 int i
; /* Looping var */
45 ppd_size_t
*size
; /* Current page size */
46 float w
, l
; /* Width and length of page */
47 char *nameptr
; /* Pointer into name */
48 struct lconv
*loc
; /* Locale data */
49 ppd_coption_t
*coption
; /* Custom option for page size */
50 ppd_cparam_t
*cparam
; /* Custom option parameter */
53 DEBUG_printf(("2ppdPageSize(ppd=%p, name=\"%s\")", ppd
, name
));
57 DEBUG_puts("3ppdPageSize: Bad PPD pointer, returning NULL...");
63 if (!strncmp(name
, "Custom.", 7) && ppd
->variable_sizes
)
66 * Find the custom page size...
69 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
70 if (!strcmp("Custom", size
->name
))
75 DEBUG_puts("3ppdPageSize: No custom sizes, returning NULL...");
80 * Variable size; size name can be one of the following:
82 * Custom.WIDTHxLENGTHin - Size in inches
83 * Custom.WIDTHxLENGTHcm - Size in centimeters
84 * Custom.WIDTHxLENGTHmm - Size in millimeters
85 * Custom.WIDTHxLENGTH[pt] - Size in points
89 w
= (float)_cupsStrScand(name
+ 7, &nameptr
, loc
);
90 if (!nameptr
|| *nameptr
!= 'x')
93 l
= (float)_cupsStrScand(nameptr
+ 1, &nameptr
, loc
);
97 if (!strcasecmp(nameptr
, "in"))
102 else if (!strcasecmp(nameptr
, "ft"))
107 else if (!strcasecmp(nameptr
, "mm"))
112 else if (!strcasecmp(nameptr
, "cm"))
117 else if (!strcasecmp(nameptr
, "m"))
119 w
*= 72.0f
/ 0.0254f
;
120 l
*= 72.0f
/ 0.0254f
;
125 size
->left
= ppd
->custom_margins
[0];
126 size
->bottom
= ppd
->custom_margins
[1];
127 size
->right
= w
- ppd
->custom_margins
[2];
128 size
->top
= l
- ppd
->custom_margins
[3];
131 * Update the custom option records for the page size, too...
134 if ((coption
= ppdFindCustomOption(ppd
, "PageSize")) != NULL
)
136 if ((cparam
= ppdFindCustomParam(coption
, "Width")) != NULL
)
137 cparam
->current
.custom_points
= w
;
139 if ((cparam
= ppdFindCustomParam(coption
, "Height")) != NULL
)
140 cparam
->current
.custom_points
= l
;
144 * Return the page size...
147 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
148 size
->name
, size
->width
, size
->length
));
158 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
159 if (!strcasecmp(name
, size
->name
))
161 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
162 size
->name
, size
->width
, size
->length
));
174 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
177 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
178 size
->name
, size
->width
, size
->length
));
184 DEBUG_puts("3ppdPageSize: Size not found, returning NULL");
191 * 'ppdPageSizeLimits()' - Return the custom page size limits.
193 * This function returns the minimum and maximum custom page sizes and printable
194 * areas based on the currently-marked (selected) options.
196 * If the specified PPD file does not support custom page sizes, both
197 * "minimum" and "maximum" are filled with zeroes.
202 int /* O - 1 if custom sizes are supported, 0 otherwise */
203 ppdPageSizeLimits(ppd_file_t
*ppd
, /* I - PPD file record */
204 ppd_size_t
*minimum
, /* O - Minimum custom size */
205 ppd_size_t
*maximum
) /* O - Maximum custom size */
207 ppd_choice_t
*qualifier2
, /* Second media qualifier */
208 *qualifier3
; /* Third media qualifier */
209 ppd_attr_t
*attr
; /* Attribute */
210 float width
, /* Min/max width */
211 length
; /* Min/max length */
212 char spec
[PPD_MAX_NAME
]; /* Selector for min/max */
216 * Range check input...
219 if (!ppd
|| !ppd
->variable_sizes
|| !minimum
|| !maximum
)
222 memset(minimum
, 0, sizeof(ppd_size_t
));
225 memset(maximum
, 0, sizeof(ppd_size_t
));
231 * See if we have the cupsMediaQualifier2 and cupsMediaQualifier3 attributes...
234 cupsArraySave(ppd
->sorted_attrs
);
236 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier2", NULL
)) != NULL
&&
238 qualifier2
= ppdFindMarkedChoice(ppd
, attr
->value
);
242 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier3", NULL
)) != NULL
&&
244 qualifier3
= ppdFindMarkedChoice(ppd
, attr
->value
);
249 * Figure out the current minimum width and length...
255 * Try getting cupsMinSize...
260 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
262 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
269 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
270 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
273 if (!attr
&& qualifier3
)
275 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
276 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
280 (attr
->value
&& sscanf(attr
->value
, "%f%f", &width
, &length
) != 2))
282 width
= ppd
->custom_min
[0];
283 length
= ppd
->custom_min
[1];
288 width
= ppd
->custom_min
[0];
289 length
= ppd
->custom_min
[1];
292 minimum
->width
= width
;
293 minimum
->length
= length
;
294 minimum
->left
= ppd
->custom_margins
[0];
295 minimum
->bottom
= ppd
->custom_margins
[1];
296 minimum
->right
= width
- ppd
->custom_margins
[2];
297 minimum
->top
= length
- ppd
->custom_margins
[3];
300 * Figure out the current maximum width and length...
306 * Try getting cupsMaxSize...
311 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
313 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
320 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
321 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
324 if (!attr
&& qualifier3
)
326 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
327 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
331 (attr
->value
&& sscanf(attr
->value
, "%f%f", &width
, &length
) != 2))
333 width
= ppd
->custom_max
[0];
334 length
= ppd
->custom_max
[1];
339 width
= ppd
->custom_max
[0];
340 length
= ppd
->custom_max
[1];
343 maximum
->width
= width
;
344 maximum
->length
= length
;
345 maximum
->left
= ppd
->custom_margins
[0];
346 maximum
->bottom
= ppd
->custom_margins
[1];
347 maximum
->right
= width
- ppd
->custom_margins
[2];
348 maximum
->top
= length
- ppd
->custom_margins
[3];
351 * Return the min and max...
354 cupsArrayRestore(ppd
->sorted_attrs
);
361 * 'ppdPageWidth()' - Get the page width for the given size.
364 float /* O - Width of page in points or 0.0 */
365 ppdPageWidth(ppd_file_t
*ppd
, /* I - PPD file record */
366 const char *name
) /* I - Size name */
368 ppd_size_t
*size
; /* Page size */
371 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
374 return (size
->width
);
379 * 'ppdPageLength()' - Get the page length for the given size.
382 float /* O - Length of page in points or 0.0 */
383 ppdPageLength(ppd_file_t
*ppd
, /* I - PPD file */
384 const char *name
) /* I - Size name */
386 ppd_size_t
*size
; /* Page size */
389 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
392 return (size
->length
);
397 * End of "$Id: page.c 7791 2008-07-24 00:55:30Z mike $".