]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/page.c
Y2k copyright changes.
[thirdparty/cups.git] / cups / page.c
1 /*
2 * "$Id: page.c,v 1.11 2000/01/04 13:45:36 mike Exp $"
3 *
4 * Page size functions for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2000 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-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * PostScript is a trademark of Adobe Systems, Inc.
25 *
26 * Contents:
27 *
28 * ppdPageSize() - Get the page size record for the given size.
29 * ppdPageWidth() - Get the page width for the given size.
30 * ppdPageLength() - Get the page length for the given size.
31 */
32
33 /*
34 * Include necessary headers...
35 */
36
37 #include "ppd.h"
38 #include "string.h"
39 #include <ctype.h>
40
41
42 /*
43 * 'ppdPageSize()' - Get the page size record for the given size.
44 */
45
46 ppd_size_t * /* O - Size record for page or NULL */
47 ppdPageSize(ppd_file_t *ppd, /* I - PPD file record */
48 const char *name) /* I - Size name */
49 {
50 int i; /* Looping var */
51 float w, l; /* Width and length of page */
52 char units[255]; /* Page size units... */
53
54
55 if (ppd == NULL)
56 return (NULL);
57
58 if (name != NULL)
59 {
60 if (strncmp(name, "Custom.", 7) == 0 && ppd->variable_sizes)
61 {
62 /*
63 * Find the custom page size...
64 */
65
66 for (i = 0; i < ppd->num_sizes; i ++)
67 if (strcmp("Custom", ppd->sizes[i].name) == 0)
68 break;
69
70 if (i == ppd->num_sizes)
71 return (NULL);
72
73 /*
74 * Variable size; size name can be one of the following:
75 *
76 * Custom.WIDTHxLENGTHin - Size in inches
77 * Custom.WIDTHxLENGTHcm - Size in centimeters
78 * Custom.WIDTHxLENGTHmm - Size in millimeters
79 * Custom.WIDTHxLENGTH[pt] - Size in points
80 */
81
82 units[0] = '\0';
83 if (sscanf(name + 7, "%fx%f%254s", &w, &l, units) < 2)
84 return (NULL);
85
86 if (strcasecmp(units, "in") == 0)
87 {
88 ppd->sizes[i].width = w * 72.0f;
89 ppd->sizes[i].length = l * 72.0f;
90 ppd->sizes[i].left = ppd->custom_margins[0];
91 ppd->sizes[i].bottom = ppd->custom_margins[1];
92 ppd->sizes[i].right = w * 72.0f - ppd->custom_margins[2];
93 ppd->sizes[i].top = l * 72.0f - ppd->custom_margins[3];
94 }
95 else if (strcasecmp(units, "cm") == 0)
96 {
97 ppd->sizes[i].width = w / 2.54f * 72.0f;
98 ppd->sizes[i].length = l / 2.54f * 72.0f;
99 ppd->sizes[i].left = ppd->custom_margins[0];
100 ppd->sizes[i].bottom = ppd->custom_margins[1];
101 ppd->sizes[i].right = w / 2.54f * 72.0f - ppd->custom_margins[2];
102 ppd->sizes[i].top = l / 2.54f * 72.0f - ppd->custom_margins[3];
103 }
104 else if (strcasecmp(units, "mm") == 0)
105 {
106 ppd->sizes[i].width = w / 25.4f * 72.0f;
107 ppd->sizes[i].length = l / 25.4f * 72.0f;
108 ppd->sizes[i].left = ppd->custom_margins[0];
109 ppd->sizes[i].bottom = ppd->custom_margins[1];
110 ppd->sizes[i].right = w / 25.4f * 72.0f - ppd->custom_margins[2];
111 ppd->sizes[i].top = l / 25.4f * 72.0f - ppd->custom_margins[3];
112 }
113 else
114 {
115 ppd->sizes[i].width = w;
116 ppd->sizes[i].length = l;
117 ppd->sizes[i].left = ppd->custom_margins[0];
118 ppd->sizes[i].bottom = ppd->custom_margins[1];
119 ppd->sizes[i].right = w - ppd->custom_margins[2];
120 ppd->sizes[i].top = l - ppd->custom_margins[3];
121 }
122
123 return (ppd->sizes + i);
124 }
125 else
126 {
127 /*
128 * Lookup by name...
129 */
130
131 for (i = 0; i < ppd->num_sizes; i ++)
132 if (strcmp(name, ppd->sizes[i].name) == 0)
133 return (ppd->sizes + i);
134 }
135 }
136 else
137 {
138 /*
139 * Find default...
140 */
141
142 for (i = 0; i < ppd->num_sizes; i ++)
143 if (ppd->sizes[i].marked)
144 return (ppd->sizes + i);
145 }
146
147 return (NULL);
148 }
149
150
151 /*
152 * 'ppdPageWidth()' - Get the page width for the given size.
153 */
154
155 float /* O - Width of page in points or 0.0 */
156 ppdPageWidth(ppd_file_t *ppd, /* I - PPD file record */
157 const char *name) /* I - Size name */
158 {
159 ppd_size_t *size; /* Page size */
160
161
162 if ((size = ppdPageSize(ppd, name)) == NULL)
163 return (0.0);
164 else
165 return (size->width);
166 }
167
168
169 /*
170 * 'ppdPageLength()' - Get the page length for the given size.
171 */
172
173 float /* O - Length of page in points or 0.0 */
174 ppdPageLength(ppd_file_t *ppd, /* I - PPD file */
175 const char *name) /* I - Size name */
176 {
177 ppd_size_t *size; /* Page size */
178
179
180 if ((size = ppdPageSize(ppd, name)) == NULL)
181 return (0.0);
182 else
183 return (size->length);
184 }
185
186
187 /*
188 * End of "$Id: page.c,v 1.11 2000/01/04 13:45:36 mike Exp $".
189 */