]> 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 4494 2005-02-18 02:18:11Z mike $"
3 *
4 * Page size functions for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2005 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 float w, l; /* Width and length of page */
54 char units[255]; /* Page size units... */
55
56
57 if (ppd == NULL)
58 return (NULL);
59
60 if (name != NULL)
61 {
62 if (strncmp(name, "Custom.", 7) == 0 && ppd->variable_sizes)
63 {
64 /*
65 * Find the custom page size...
66 */
67
68 for (i = 0; i < ppd->num_sizes; i ++)
69 if (strcmp("Custom", ppd->sizes[i].name) == 0)
70 break;
71
72 if (i == ppd->num_sizes)
73 return (NULL);
74
75 /*
76 * Variable size; size name can be one of the following:
77 *
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
82 */
83
84 units[0] = '\0';
85 if (sscanf(name + 7, "%fx%f%254s", &w, &l, units) < 2)
86 return (NULL);
87
88 if (strcasecmp(units, "in") == 0)
89 {
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];
96 }
97 else if (strcasecmp(units, "cm") == 0)
98 {
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];
105 }
106 else if (strcasecmp(units, "mm") == 0)
107 {
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];
114 }
115 else
116 {
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];
123 }
124
125 return (ppd->sizes + i);
126 }
127 else
128 {
129 /*
130 * Lookup by name...
131 */
132
133 for (i = 0; i < ppd->num_sizes; i ++)
134 if (strcmp(name, ppd->sizes[i].name) == 0)
135 return (ppd->sizes + i);
136 }
137 }
138 else
139 {
140 /*
141 * Find default...
142 */
143
144 for (i = 0; i < ppd->num_sizes; i ++)
145 if (ppd->sizes[i].marked)
146 return (ppd->sizes + i);
147 }
148
149 return (NULL);
150 }
151
152
153 /*
154 * 'ppdPageWidth()' - Get the page width for the given size.
155 */
156
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 */
160 {
161 ppd_size_t *size; /* Page size */
162
163
164 if ((size = ppdPageSize(ppd, name)) == NULL)
165 return (0.0);
166 else
167 return (size->width);
168 }
169
170
171 /*
172 * 'ppdPageLength()' - Get the page length for the given size.
173 */
174
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 */
178 {
179 ppd_size_t *size; /* Page size */
180
181
182 if ((size = ppdPageSize(ppd, name)) == NULL)
183 return (0.0);
184 else
185 return (size->length);
186 }
187
188
189 /*
190 * End of "$Id: page.c 4494 2005-02-18 02:18:11Z mike $".
191 */