]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
757d2cad | 2 | * "$Id: page.c 5238 2006-03-07 04:41:42Z mike $" |
ef416fc2 | 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 | ||
757d2cad | 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 */ | |
ef416fc2 | 51 | { |
757d2cad | 52 | int i; /* Looping var */ |
53 | float w, l; /* Width and length of page */ | |
54 | char *nameptr; /* Pointer into name */ | |
55 | struct lconv *loc; /* Locale data */ | |
ef416fc2 | 56 | |
57 | ||
757d2cad | 58 | if (!ppd) |
ef416fc2 | 59 | return (NULL); |
60 | ||
757d2cad | 61 | if (name) |
ef416fc2 | 62 | { |
757d2cad | 63 | if (!strncmp(name, "Custom.", 7) && ppd->variable_sizes) |
ef416fc2 | 64 | { |
65 | /* | |
66 | * Find the custom page size... | |
67 | */ | |
68 | ||
69 | for (i = 0; i < ppd->num_sizes; i ++) | |
757d2cad | 70 | if (!strcmp("Custom", ppd->sizes[i].name)) |
ef416fc2 | 71 | break; |
72 | ||
73 | if (i == ppd->num_sizes) | |
74 | return (NULL); | |
75 | ||
76 | /* | |
77 | * Variable size; size name can be one of the following: | |
78 | * | |
79 | * Custom.WIDTHxLENGTHin - Size in inches | |
80 | * Custom.WIDTHxLENGTHcm - Size in centimeters | |
81 | * Custom.WIDTHxLENGTHmm - Size in millimeters | |
82 | * Custom.WIDTHxLENGTH[pt] - Size in points | |
83 | */ | |
84 | ||
757d2cad | 85 | loc = localeconv(); |
86 | w = _cupsStrScand(name + 7, &nameptr, loc); | |
87 | if (!nameptr || *nameptr != 'x') | |
ef416fc2 | 88 | return (NULL); |
89 | ||
757d2cad | 90 | l = _cupsStrScand(nameptr, &nameptr, loc); |
91 | if (!nameptr) | |
92 | return (NULL); | |
93 | ||
94 | if (!strcasecmp(nameptr, "in")) | |
ef416fc2 | 95 | { |
96 | ppd->sizes[i].width = w * 72.0f; | |
97 | ppd->sizes[i].length = l * 72.0f; | |
98 | ppd->sizes[i].left = ppd->custom_margins[0]; | |
99 | ppd->sizes[i].bottom = ppd->custom_margins[1]; | |
100 | ppd->sizes[i].right = w * 72.0f - ppd->custom_margins[2]; | |
101 | ppd->sizes[i].top = l * 72.0f - ppd->custom_margins[3]; | |
102 | } | |
757d2cad | 103 | else if (!strcasecmp(nameptr, "cm")) |
ef416fc2 | 104 | { |
105 | ppd->sizes[i].width = w / 2.54f * 72.0f; | |
106 | ppd->sizes[i].length = l / 2.54f * 72.0f; | |
107 | ppd->sizes[i].left = ppd->custom_margins[0]; | |
108 | ppd->sizes[i].bottom = ppd->custom_margins[1]; | |
109 | ppd->sizes[i].right = w / 2.54f * 72.0f - ppd->custom_margins[2]; | |
110 | ppd->sizes[i].top = l / 2.54f * 72.0f - ppd->custom_margins[3]; | |
111 | } | |
757d2cad | 112 | else if (!strcasecmp(nameptr, "mm")) |
ef416fc2 | 113 | { |
114 | ppd->sizes[i].width = w / 25.4f * 72.0f; | |
115 | ppd->sizes[i].length = l / 25.4f * 72.0f; | |
116 | ppd->sizes[i].left = ppd->custom_margins[0]; | |
117 | ppd->sizes[i].bottom = ppd->custom_margins[1]; | |
118 | ppd->sizes[i].right = w / 25.4f * 72.0f - ppd->custom_margins[2]; | |
119 | ppd->sizes[i].top = l / 25.4f * 72.0f - ppd->custom_margins[3]; | |
120 | } | |
121 | else | |
122 | { | |
123 | ppd->sizes[i].width = w; | |
124 | ppd->sizes[i].length = l; | |
125 | ppd->sizes[i].left = ppd->custom_margins[0]; | |
126 | ppd->sizes[i].bottom = ppd->custom_margins[1]; | |
127 | ppd->sizes[i].right = w - ppd->custom_margins[2]; | |
128 | ppd->sizes[i].top = l - ppd->custom_margins[3]; | |
129 | } | |
130 | ||
131 | return (ppd->sizes + i); | |
132 | } | |
133 | else | |
134 | { | |
135 | /* | |
136 | * Lookup by name... | |
137 | */ | |
138 | ||
139 | for (i = 0; i < ppd->num_sizes; i ++) | |
757d2cad | 140 | if (!strcasecmp(name, ppd->sizes[i].name)) |
ef416fc2 | 141 | return (ppd->sizes + i); |
142 | } | |
143 | } | |
144 | else | |
145 | { | |
146 | /* | |
147 | * Find default... | |
148 | */ | |
149 | ||
150 | for (i = 0; i < ppd->num_sizes; i ++) | |
151 | if (ppd->sizes[i].marked) | |
152 | return (ppd->sizes + i); | |
153 | } | |
154 | ||
155 | return (NULL); | |
156 | } | |
157 | ||
158 | ||
159 | /* | |
160 | * 'ppdPageWidth()' - Get the page width for the given size. | |
161 | */ | |
162 | ||
163 | float /* O - Width of page in points or 0.0 */ | |
164 | ppdPageWidth(ppd_file_t *ppd, /* I - PPD file record */ | |
165 | const char *name) /* I - Size name */ | |
166 | { | |
167 | ppd_size_t *size; /* Page size */ | |
168 | ||
169 | ||
170 | if ((size = ppdPageSize(ppd, name)) == NULL) | |
171 | return (0.0); | |
172 | else | |
173 | return (size->width); | |
174 | } | |
175 | ||
176 | ||
177 | /* | |
178 | * 'ppdPageLength()' - Get the page length for the given size. | |
179 | */ | |
180 | ||
181 | float /* O - Length of page in points or 0.0 */ | |
182 | ppdPageLength(ppd_file_t *ppd, /* I - PPD file */ | |
183 | const char *name) /* I - Size name */ | |
184 | { | |
185 | ppd_size_t *size; /* Page size */ | |
186 | ||
187 | ||
188 | if ((size = ppdPageSize(ppd, name)) == NULL) | |
189 | return (0.0); | |
190 | else | |
191 | return (size->length); | |
192 | } | |
193 | ||
194 | ||
195 | /* | |
757d2cad | 196 | * End of "$Id: page.c 5238 2006-03-07 04:41:42Z mike $". |
ef416fc2 | 197 | */ |