]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/page.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / page.c
CommitLineData
ef416fc2 1/*
f7deaa1a 2 * "$Id: page.c 6187 2007-01-10 16:20:42Z mike $"
ef416fc2 3 *
4 * Page size functions for the Common UNIX Printing System (CUPS).
5 *
b86bc4cf 6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 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 48ppd_size_t * /* O - Size record for page or NULL */
49ppdPageSize(ppd_file_t *ppd, /* I - PPD file record */
50 const char *name) /* I - Size name */
ef416fc2 51{
757d2cad 52 int i; /* Looping var */
b86bc4cf 53 ppd_size_t *size; /* Current page size */
757d2cad 54 float w, l; /* Width and length of page */
55 char *nameptr; /* Pointer into name */
56 struct lconv *loc; /* Locale data */
b86bc4cf 57 ppd_coption_t *coption; /* Custom option for page size */
58 ppd_cparam_t *cparam; /* Custom option parameter */
ef416fc2 59
60
757d2cad 61 if (!ppd)
ef416fc2 62 return (NULL);
63
757d2cad 64 if (name)
ef416fc2 65 {
757d2cad 66 if (!strncmp(name, "Custom.", 7) && ppd->variable_sizes)
ef416fc2 67 {
68 /*
69 * Find the custom page size...
70 */
71
b86bc4cf 72 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
73 if (!strcmp("Custom", size->name))
ef416fc2 74 break;
75
b86bc4cf 76 if (!i)
ef416fc2 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
757d2cad 88 loc = localeconv();
b86bc4cf 89 w = (float)_cupsStrScand(name + 7, &nameptr, loc);
757d2cad 90 if (!nameptr || *nameptr != 'x')
ef416fc2 91 return (NULL);
92
b86bc4cf 93 l = (float)_cupsStrScand(nameptr + 1, &nameptr, loc);
757d2cad 94 if (!nameptr)
95 return (NULL);
96
97 if (!strcasecmp(nameptr, "in"))
ef416fc2 98 {
b86bc4cf 99 w *= 72.0f;
100 l *= 72.0f;
ef416fc2 101 }
b86bc4cf 102 else if (!strcasecmp(nameptr, "ft"))
ef416fc2 103 {
b86bc4cf 104 w *= 12.0f * 72.0f;
105 l *= 12.0f * 72.0f;
ef416fc2 106 }
757d2cad 107 else if (!strcasecmp(nameptr, "mm"))
ef416fc2 108 {
b86bc4cf 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;
ef416fc2 116 }
b86bc4cf 117 else if (!strcasecmp(nameptr, "m"))
ef416fc2 118 {
b86bc4cf 119 w *= 72.0f / 0.0254f;
120 l *= 72.0f / 0.0254f;
ef416fc2 121 }
122
b86bc4cf 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);
ef416fc2 148 }
149 else
150 {
151 /*
152 * Lookup by name...
153 */
154
b86bc4cf 155 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
156 if (!strcmp(name, size->name))
157 return (size);
ef416fc2 158 }
159 }
160 else
161 {
162 /*
163 * Find default...
164 */
165
b86bc4cf 166 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
167 if (size->marked)
168 return (size);
ef416fc2 169 }
170
171 return (NULL);
172}
173
174
175/*
176 * 'ppdPageWidth()' - Get the page width for the given size.
177 */
178
179float /* O - Width of page in points or 0.0 */
180ppdPageWidth(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
197float /* O - Length of page in points or 0.0 */
198ppdPageLength(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/*
f7deaa1a 212 * End of "$Id: page.c 6187 2007-01-10 16:20:42Z mike $".
ef416fc2 213 */