]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/page.c
9d653fec02f101cc48f8f0d130f9577ddcb28f32
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 * ppdPageSizeLimits() - Return the custom page size limits.
23 * ppdPageWidth() - Get the page width for the given size.
24 * ppdPageLength() - Get the page length for the given size.
28 * Include necessary headers...
38 * 'ppdPageSize()' - Get the page size record for the given size.
41 ppd_size_t
* /* O - Size record for page or NULL */
42 ppdPageSize(ppd_file_t
*ppd
, /* I - PPD file record */
43 const char *name
) /* I - Size name */
45 int i
; /* Looping var */
46 ppd_size_t
*size
; /* Current page size */
47 float w
, l
; /* Width and length of page */
48 char *nameptr
; /* Pointer into name */
49 struct lconv
*loc
; /* Locale data */
50 ppd_coption_t
*coption
; /* Custom option for page size */
51 ppd_cparam_t
*cparam
; /* Custom option parameter */
54 DEBUG_printf(("2ppdPageSize(ppd=%p, name=\"%s\")", ppd
, name
));
58 DEBUG_puts("3ppdPageSize: Bad PPD pointer, returning NULL...");
64 if (!strncmp(name
, "Custom.", 7) && ppd
->variable_sizes
)
67 * Find the custom page size...
70 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
71 if (!strcmp("Custom", size
->name
))
76 DEBUG_puts("3ppdPageSize: No custom sizes, returning NULL...");
81 * Variable size; size name can be one of the following:
83 * Custom.WIDTHxLENGTHin - Size in inches
84 * Custom.WIDTHxLENGTHcm - Size in centimeters
85 * Custom.WIDTHxLENGTHmm - Size in millimeters
86 * Custom.WIDTHxLENGTH[pt] - Size in points
90 w
= (float)_cupsStrScand(name
+ 7, &nameptr
, loc
);
91 if (!nameptr
|| *nameptr
!= 'x')
94 l
= (float)_cupsStrScand(nameptr
+ 1, &nameptr
, loc
);
98 if (!strcasecmp(nameptr
, "in"))
103 else if (!strcasecmp(nameptr
, "ft"))
108 else if (!strcasecmp(nameptr
, "mm"))
113 else if (!strcasecmp(nameptr
, "cm"))
118 else if (!strcasecmp(nameptr
, "m"))
120 w
*= 72.0f
/ 0.0254f
;
121 l
*= 72.0f
/ 0.0254f
;
126 size
->left
= ppd
->custom_margins
[0];
127 size
->bottom
= ppd
->custom_margins
[1];
128 size
->right
= w
- ppd
->custom_margins
[2];
129 size
->top
= l
- ppd
->custom_margins
[3];
132 * Update the custom option records for the page size, too...
135 if ((coption
= ppdFindCustomOption(ppd
, "PageSize")) != NULL
)
137 if ((cparam
= ppdFindCustomParam(coption
, "Width")) != NULL
)
138 cparam
->current
.custom_points
= w
;
140 if ((cparam
= ppdFindCustomParam(coption
, "Height")) != NULL
)
141 cparam
->current
.custom_points
= l
;
145 * Return the page size...
148 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
149 size
->name
, size
->width
, size
->length
));
159 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
160 if (!strcasecmp(name
, size
->name
))
162 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
163 size
->name
, size
->width
, size
->length
));
175 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
178 DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size
,
179 size
->name
, size
->width
, size
->length
));
185 DEBUG_puts("3ppdPageSize: Size not found, returning NULL");
192 * 'ppdPageSizeLimits()' - Return the custom page size limits.
194 * This function returns the minimum and maximum custom page sizes and printable
195 * areas based on the currently-marked (selected) options.
197 * If the specified PPD file does not support custom page sizes, both
198 * "minimum" and "maximum" are filled with zeroes.
200 * @since CUPS 1.4/Mac OS X 10.6@
203 int /* O - 1 if custom sizes are supported, 0 otherwise */
204 ppdPageSizeLimits(ppd_file_t
*ppd
, /* I - PPD file record */
205 ppd_size_t
*minimum
, /* O - Minimum custom size */
206 ppd_size_t
*maximum
) /* O - Maximum custom size */
208 ppd_choice_t
*qualifier2
, /* Second media qualifier */
209 *qualifier3
; /* Third media qualifier */
210 ppd_attr_t
*attr
; /* Attribute */
211 float width
, /* Min/max width */
212 length
; /* Min/max length */
213 char spec
[PPD_MAX_NAME
]; /* Selector for min/max */
217 * Range check input...
220 if (!ppd
|| !ppd
->variable_sizes
|| !minimum
|| !maximum
)
223 memset(minimum
, 0, sizeof(ppd_size_t
));
226 memset(maximum
, 0, sizeof(ppd_size_t
));
232 * See if we have the cupsMediaQualifier2 and cupsMediaQualifier3 attributes...
235 cupsArraySave(ppd
->sorted_attrs
);
237 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier2", NULL
)) != NULL
&&
239 qualifier2
= ppdFindMarkedChoice(ppd
, attr
->value
);
243 if ((attr
= ppdFindAttr(ppd
, "cupsMediaQualifier3", NULL
)) != NULL
&&
245 qualifier3
= ppdFindMarkedChoice(ppd
, attr
->value
);
250 * Figure out the current minimum width and length...
256 * Try getting cupsMinSize...
261 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
263 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
270 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
271 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
274 if (!attr
&& qualifier3
)
276 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
277 attr
= ppdFindAttr(ppd
, "cupsMinSize", spec
);
281 (attr
->value
&& sscanf(attr
->value
, "%f%f", &width
, &length
) != 2))
283 width
= ppd
->custom_min
[0];
284 length
= ppd
->custom_min
[1];
289 width
= ppd
->custom_min
[0];
290 length
= ppd
->custom_min
[1];
293 minimum
->width
= width
;
294 minimum
->length
= length
;
295 minimum
->left
= ppd
->custom_margins
[0];
296 minimum
->bottom
= ppd
->custom_margins
[1];
297 minimum
->right
= width
- ppd
->custom_margins
[2];
298 minimum
->top
= length
- ppd
->custom_margins
[3];
301 * Figure out the current maximum width and length...
307 * Try getting cupsMaxSize...
312 snprintf(spec
, sizeof(spec
), ".%s.%s", qualifier2
->choice
,
314 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
321 snprintf(spec
, sizeof(spec
), ".%s.", qualifier2
->choice
);
322 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
325 if (!attr
&& qualifier3
)
327 snprintf(spec
, sizeof(spec
), "..%s", qualifier3
->choice
);
328 attr
= ppdFindAttr(ppd
, "cupsMaxSize", spec
);
332 (attr
->value
&& sscanf(attr
->value
, "%f%f", &width
, &length
) != 2))
334 width
= ppd
->custom_max
[0];
335 length
= ppd
->custom_max
[1];
340 width
= ppd
->custom_max
[0];
341 length
= ppd
->custom_max
[1];
344 maximum
->width
= width
;
345 maximum
->length
= length
;
346 maximum
->left
= ppd
->custom_margins
[0];
347 maximum
->bottom
= ppd
->custom_margins
[1];
348 maximum
->right
= width
- ppd
->custom_margins
[2];
349 maximum
->top
= length
- ppd
->custom_margins
[3];
352 * Return the min and max...
355 cupsArrayRestore(ppd
->sorted_attrs
);
362 * 'ppdPageWidth()' - Get the page width for the given size.
365 float /* O - Width of page in points or 0.0 */
366 ppdPageWidth(ppd_file_t
*ppd
, /* I - PPD file record */
367 const char *name
) /* I - Size name */
369 ppd_size_t
*size
; /* Page size */
372 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
375 return (size
->width
);
380 * 'ppdPageLength()' - Get the page length for the given size.
383 float /* O - Length of page in points or 0.0 */
384 ppdPageLength(ppd_file_t
*ppd
, /* I - PPD file */
385 const char *name
) /* I - Size name */
387 ppd_size_t
*size
; /* Page size */
390 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
393 return (size
->length
);
398 * End of "$Id: page.c 7791 2008-07-24 00:55:30Z mike $".