]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/page.c
Y2k copyright changes.
[thirdparty/cups.git] / cups / page.c
CommitLineData
c359b2e9 1/*
71fe22b7 2 * "$Id: page.c,v 1.11 2000/01/04 13:45:36 mike Exp $"
c359b2e9 3 *
3a193f5e 4 * Page size functions for the Common UNIX Printing System (CUPS).
c359b2e9 5 *
71fe22b7 6 * Copyright 1997-2000 by Easy Software Products, all rights reserved.
c359b2e9 7 *
3a193f5e 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
c359b2e9 16 * Easy Software Products
58ec2a95 17 * 44141 Airport View Drive, Suite 204
c359b2e9 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 *
2b85e375 24 * PostScript is a trademark of Adobe Systems, Inc.
25 *
c359b2e9 26 * Contents:
27 *
2b85e375 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.
c359b2e9 31 */
32
33/*
34 * Include necessary headers...
35 */
36
2b85e375 37#include "ppd.h"
3b960317 38#include "string.h"
6fdf969a 39#include <ctype.h>
2b85e375 40
41
42/*
43 * 'ppdPageSize()' - Get the page size record for the given size.
44 */
45
46ppd_size_t * /* O - Size record for page or NULL */
47ppdPageSize(ppd_file_t *ppd, /* I - PPD file record */
063e1ac7 48 const char *name) /* I - Size name */
2b85e375 49{
50 int i; /* Looping var */
6fdf969a 51 float w, l; /* Width and length of page */
52 char units[255]; /* Page size units... */
2b85e375 53
54
58ec2a95 55 if (ppd == NULL)
2b85e375 56 return (NULL);
57
58ec2a95 58 if (name != NULL)
59 {
9af859e2 60 if (strncmp(name, "Custom.", 7) == 0 && ppd->variable_sizes)
6fdf969a 61 {
9af859e2 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
6fdf969a 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';
04d61d56 83 if (sscanf(name + 7, "%fx%f%254s", &w, &l, units) < 2)
6fdf969a 84 return (NULL);
85
86 if (strcasecmp(units, "in") == 0)
87 {
977acbd3 88 ppd->sizes[i].width = w * 72.0f;
89 ppd->sizes[i].length = l * 72.0f;
9af859e2 90 ppd->sizes[i].left = ppd->custom_margins[0];
91 ppd->sizes[i].bottom = ppd->custom_margins[1];
977acbd3 92 ppd->sizes[i].right = w * 72.0f - ppd->custom_margins[2];
93 ppd->sizes[i].top = l * 72.0f - ppd->custom_margins[3];
6fdf969a 94 }
95 else if (strcasecmp(units, "cm") == 0)
96 {
977acbd3 97 ppd->sizes[i].width = w / 2.54f * 72.0f;
98 ppd->sizes[i].length = l / 2.54f * 72.0f;
9af859e2 99 ppd->sizes[i].left = ppd->custom_margins[0];
100 ppd->sizes[i].bottom = ppd->custom_margins[1];
977acbd3 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];
6fdf969a 103 }
104 else if (strcasecmp(units, "mm") == 0)
105 {
977acbd3 106 ppd->sizes[i].width = w / 25.4f * 72.0f;
107 ppd->sizes[i].length = l / 25.4f * 72.0f;
9af859e2 108 ppd->sizes[i].left = ppd->custom_margins[0];
109 ppd->sizes[i].bottom = ppd->custom_margins[1];
977acbd3 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];
6fdf969a 112 }
113 else
114 {
9af859e2 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];
6fdf969a 121 }
122
9af859e2 123 return (ppd->sizes + i);
6fdf969a 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 }
58ec2a95 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 }
2b85e375 146
147 return (NULL);
148}
149
150
151/*
152 * 'ppdPageWidth()' - Get the page width for the given size.
153 */
154
155float /* O - Width of page in points or 0.0 */
156ppdPageWidth(ppd_file_t *ppd, /* I - PPD file record */
063e1ac7 157 const char *name) /* I - Size name */
2b85e375 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
173float /* O - Length of page in points or 0.0 */
58ec2a95 174ppdPageLength(ppd_file_t *ppd, /* I - PPD file */
063e1ac7 175 const char *name) /* I - Size name */
2b85e375 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}
c359b2e9 185
186
187/*
71fe22b7 188 * End of "$Id: page.c,v 1.11 2000/01/04 13:45:36 mike Exp $".
c359b2e9 189 */