]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/page.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / page.c
1 /*
2 * "$Id: page.c 6188 2007-01-10 16:23:06Z mike $"
3 *
4 * Page size functions for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 *
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
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * PostScript is a trademark of Adobe Systems, Inc.
25 *
26 * This file is subject to the Apple OS-Developed Software exception.
27 *
28 * Contents:
29 *
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.
33 */
34
35 /*
36 * Include necessary headers...
37 */
38
39 #include "ppd.h"
40 #include "string.h"
41 #include <ctype.h>
42
43
44 /*
45 * 'ppdPageSize()' - Get the page size record for the given size.
46 */
47
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 */
51 {
52 int i; /* Looping var */
53 ppd_size_t *size; /* Current page size */
54 float w, l; /* Width and length of page */
55 char *nameptr; /* Pointer into name */
56 struct lconv *loc; /* Locale data */
57 ppd_coption_t *coption; /* Custom option for page size */
58 ppd_cparam_t *cparam; /* Custom option parameter */
59
60
61 if (!ppd)
62 return (NULL);
63
64 if (name)
65 {
66 if (!strncmp(name, "Custom.", 7) && ppd->variable_sizes)
67 {
68 /*
69 * Find the custom page size...
70 */
71
72 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
73 if (!strcmp("Custom", size->name))
74 break;
75
76 if (!i)
77 return (NULL);
78
79 /*
80 * Variable size; size name can be one of the following:
81 *
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
86 */
87
88 loc = localeconv();
89 w = (float)_cupsStrScand(name + 7, &nameptr, loc);
90 if (!nameptr || *nameptr != 'x')
91 return (NULL);
92
93 l = (float)_cupsStrScand(nameptr + 1, &nameptr, loc);
94 if (!nameptr)
95 return (NULL);
96
97 if (!strcasecmp(nameptr, "in"))
98 {
99 w *= 72.0f;
100 l *= 72.0f;
101 }
102 else if (!strcasecmp(nameptr, "ft"))
103 {
104 w *= 12.0f * 72.0f;
105 l *= 12.0f * 72.0f;
106 }
107 else if (!strcasecmp(nameptr, "mm"))
108 {
109 w *= 72.0f / 25.4f;
110 l *= 72.0f / 25.4f;
111 }
112 else if (!strcasecmp(nameptr, "cm"))
113 {
114 w *= 72.0f / 2.54f;
115 l *= 72.0f / 2.54f;
116 }
117 else if (!strcasecmp(nameptr, "m"))
118 {
119 w *= 72.0f / 0.0254f;
120 l *= 72.0f / 0.0254f;
121 }
122
123 size->width = w;
124 size->length = l;
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];
129
130 /*
131 * Update the custom option records for the page size, too...
132 */
133
134 if ((coption = ppdFindCustomOption(ppd, "PageSize")) != NULL)
135 {
136 if ((cparam = ppdFindCustomParam(coption, "Width")) != NULL)
137 cparam->current.custom_points = w;
138
139 if ((cparam = ppdFindCustomParam(coption, "Height")) != NULL)
140 cparam->current.custom_points = l;
141 }
142
143 /*
144 * Return the page size...
145 */
146
147 return (size);
148 }
149 else
150 {
151 /*
152 * Lookup by name...
153 */
154
155 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
156 if (!strcmp(name, size->name))
157 return (size);
158 }
159 }
160 else
161 {
162 /*
163 * Find default...
164 */
165
166 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
167 if (size->marked)
168 return (size);
169 }
170
171 return (NULL);
172 }
173
174
175 /*
176 * 'ppdPageWidth()' - Get the page width for the given size.
177 */
178
179 float /* O - Width of page in points or 0.0 */
180 ppdPageWidth(ppd_file_t *ppd, /* I - PPD file record */
181 const char *name) /* I - Size name */
182 {
183 ppd_size_t *size; /* Page size */
184
185
186 if ((size = ppdPageSize(ppd, name)) == NULL)
187 return (0.0);
188 else
189 return (size->width);
190 }
191
192
193 /*
194 * 'ppdPageLength()' - Get the page length for the given size.
195 */
196
197 float /* O - Length of page in points or 0.0 */
198 ppdPageLength(ppd_file_t *ppd, /* I - PPD file */
199 const char *name) /* I - Size name */
200 {
201 ppd_size_t *size; /* Page size */
202
203
204 if ((size = ppdPageSize(ppd, name)) == NULL)
205 return (0.0);
206 else
207 return (size->length);
208 }
209
210
211 /*
212 * End of "$Id: page.c 6188 2007-01-10 16:23:06Z mike $".
213 */