]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/page.c
2 * "$Id: page.c 4494 2005-02-18 02:18:11Z mike $"
4 * Page size functions for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * PostScript is a trademark of Adobe Systems, Inc.
26 * This file is subject to the Apple OS-Developed Software exception.
30 * ppdPageSize() - Get the page size record for the given size.
31 * ppdPageWidth() - Get the page width for the given size.
32 * ppdPageLength() - Get the page length for the given size.
36 * Include necessary headers...
45 * 'ppdPageSize()' - Get the page size record for the given size.
48 ppd_size_t
* /* O - Size record for page or NULL */
49 ppdPageSize(ppd_file_t
*ppd
, /* I - PPD file record */
50 const char *name
) /* I - Size name */
52 int i
; /* Looping var */
53 float w
, l
; /* Width and length of page */
54 char units
[255]; /* Page size units... */
62 if (strncmp(name
, "Custom.", 7) == 0 && ppd
->variable_sizes
)
65 * Find the custom page size...
68 for (i
= 0; i
< ppd
->num_sizes
; i
++)
69 if (strcmp("Custom", ppd
->sizes
[i
].name
) == 0)
72 if (i
== ppd
->num_sizes
)
76 * Variable size; size name can be one of the following:
78 * Custom.WIDTHxLENGTHin - Size in inches
79 * Custom.WIDTHxLENGTHcm - Size in centimeters
80 * Custom.WIDTHxLENGTHmm - Size in millimeters
81 * Custom.WIDTHxLENGTH[pt] - Size in points
85 if (sscanf(name
+ 7, "%fx%f%254s", &w
, &l
, units
) < 2)
88 if (strcasecmp(units
, "in") == 0)
90 ppd
->sizes
[i
].width
= w
* 72.0f
;
91 ppd
->sizes
[i
].length
= l
* 72.0f
;
92 ppd
->sizes
[i
].left
= ppd
->custom_margins
[0];
93 ppd
->sizes
[i
].bottom
= ppd
->custom_margins
[1];
94 ppd
->sizes
[i
].right
= w
* 72.0f
- ppd
->custom_margins
[2];
95 ppd
->sizes
[i
].top
= l
* 72.0f
- ppd
->custom_margins
[3];
97 else if (strcasecmp(units
, "cm") == 0)
99 ppd
->sizes
[i
].width
= w
/ 2.54f
* 72.0f
;
100 ppd
->sizes
[i
].length
= l
/ 2.54f
* 72.0f
;
101 ppd
->sizes
[i
].left
= ppd
->custom_margins
[0];
102 ppd
->sizes
[i
].bottom
= ppd
->custom_margins
[1];
103 ppd
->sizes
[i
].right
= w
/ 2.54f
* 72.0f
- ppd
->custom_margins
[2];
104 ppd
->sizes
[i
].top
= l
/ 2.54f
* 72.0f
- ppd
->custom_margins
[3];
106 else if (strcasecmp(units
, "mm") == 0)
108 ppd
->sizes
[i
].width
= w
/ 25.4f
* 72.0f
;
109 ppd
->sizes
[i
].length
= l
/ 25.4f
* 72.0f
;
110 ppd
->sizes
[i
].left
= ppd
->custom_margins
[0];
111 ppd
->sizes
[i
].bottom
= ppd
->custom_margins
[1];
112 ppd
->sizes
[i
].right
= w
/ 25.4f
* 72.0f
- ppd
->custom_margins
[2];
113 ppd
->sizes
[i
].top
= l
/ 25.4f
* 72.0f
- ppd
->custom_margins
[3];
117 ppd
->sizes
[i
].width
= w
;
118 ppd
->sizes
[i
].length
= l
;
119 ppd
->sizes
[i
].left
= ppd
->custom_margins
[0];
120 ppd
->sizes
[i
].bottom
= ppd
->custom_margins
[1];
121 ppd
->sizes
[i
].right
= w
- ppd
->custom_margins
[2];
122 ppd
->sizes
[i
].top
= l
- ppd
->custom_margins
[3];
125 return (ppd
->sizes
+ i
);
133 for (i
= 0; i
< ppd
->num_sizes
; i
++)
134 if (strcmp(name
, ppd
->sizes
[i
].name
) == 0)
135 return (ppd
->sizes
+ i
);
144 for (i
= 0; i
< ppd
->num_sizes
; i
++)
145 if (ppd
->sizes
[i
].marked
)
146 return (ppd
->sizes
+ i
);
154 * 'ppdPageWidth()' - Get the page width for the given size.
157 float /* O - Width of page in points or 0.0 */
158 ppdPageWidth(ppd_file_t
*ppd
, /* I - PPD file record */
159 const char *name
) /* I - Size name */
161 ppd_size_t
*size
; /* Page size */
164 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
167 return (size
->width
);
172 * 'ppdPageLength()' - Get the page length for the given size.
175 float /* O - Length of page in points or 0.0 */
176 ppdPageLength(ppd_file_t
*ppd
, /* I - PPD file */
177 const char *name
) /* I - Size name */
179 ppd_size_t
*size
; /* Page size */
182 if ((size
= ppdPageSize(ppd
, name
)) == NULL
)
185 return (size
->length
);
190 * End of "$Id: page.c 4494 2005-02-18 02:18:11Z mike $".