]> 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/*
bc44d920 2 * "$Id: page.c 6649 2007-07-11 21:46:42Z mike $"
ef416fc2 3 *
4 * Page size functions for the Common UNIX Printing System (CUPS).
5 *
bc44d920 6 * Copyright 2007 by Apple Inc.
b86bc4cf 7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 14 *
15 * PostScript is a trademark of Adobe Systems, Inc.
16 *
17 * This file is subject to the Apple OS-Developed Software exception.
18 *
19 * Contents:
20 *
21 * ppdPageSize() - Get the page size record for the given size.
22 * ppdPageWidth() - Get the page width for the given size.
23 * ppdPageLength() - Get the page length for the given size.
24 */
25
26/*
27 * Include necessary headers...
28 */
29
30#include "ppd.h"
31#include "string.h"
32#include <ctype.h>
33
34
35/*
36 * 'ppdPageSize()' - Get the page size record for the given size.
37 */
38
757d2cad 39ppd_size_t * /* O - Size record for page or NULL */
40ppdPageSize(ppd_file_t *ppd, /* I - PPD file record */
41 const char *name) /* I - Size name */
ef416fc2 42{
757d2cad 43 int i; /* Looping var */
b86bc4cf 44 ppd_size_t *size; /* Current page size */
757d2cad 45 float w, l; /* Width and length of page */
46 char *nameptr; /* Pointer into name */
47 struct lconv *loc; /* Locale data */
b86bc4cf 48 ppd_coption_t *coption; /* Custom option for page size */
49 ppd_cparam_t *cparam; /* Custom option parameter */
ef416fc2 50
51
757d2cad 52 if (!ppd)
ef416fc2 53 return (NULL);
54
757d2cad 55 if (name)
ef416fc2 56 {
757d2cad 57 if (!strncmp(name, "Custom.", 7) && ppd->variable_sizes)
ef416fc2 58 {
59 /*
60 * Find the custom page size...
61 */
62
b86bc4cf 63 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
64 if (!strcmp("Custom", size->name))
ef416fc2 65 break;
66
b86bc4cf 67 if (!i)
ef416fc2 68 return (NULL);
69
70 /*
71 * Variable size; size name can be one of the following:
72 *
73 * Custom.WIDTHxLENGTHin - Size in inches
74 * Custom.WIDTHxLENGTHcm - Size in centimeters
75 * Custom.WIDTHxLENGTHmm - Size in millimeters
76 * Custom.WIDTHxLENGTH[pt] - Size in points
77 */
78
757d2cad 79 loc = localeconv();
b86bc4cf 80 w = (float)_cupsStrScand(name + 7, &nameptr, loc);
757d2cad 81 if (!nameptr || *nameptr != 'x')
ef416fc2 82 return (NULL);
83
b86bc4cf 84 l = (float)_cupsStrScand(nameptr + 1, &nameptr, loc);
757d2cad 85 if (!nameptr)
86 return (NULL);
87
88 if (!strcasecmp(nameptr, "in"))
ef416fc2 89 {
b86bc4cf 90 w *= 72.0f;
91 l *= 72.0f;
ef416fc2 92 }
b86bc4cf 93 else if (!strcasecmp(nameptr, "ft"))
ef416fc2 94 {
b86bc4cf 95 w *= 12.0f * 72.0f;
96 l *= 12.0f * 72.0f;
ef416fc2 97 }
757d2cad 98 else if (!strcasecmp(nameptr, "mm"))
ef416fc2 99 {
b86bc4cf 100 w *= 72.0f / 25.4f;
101 l *= 72.0f / 25.4f;
102 }
103 else if (!strcasecmp(nameptr, "cm"))
104 {
105 w *= 72.0f / 2.54f;
106 l *= 72.0f / 2.54f;
ef416fc2 107 }
b86bc4cf 108 else if (!strcasecmp(nameptr, "m"))
ef416fc2 109 {
b86bc4cf 110 w *= 72.0f / 0.0254f;
111 l *= 72.0f / 0.0254f;
ef416fc2 112 }
113
b86bc4cf 114 size->width = w;
115 size->length = l;
116 size->left = ppd->custom_margins[0];
117 size->bottom = ppd->custom_margins[1];
118 size->right = w - ppd->custom_margins[2];
119 size->top = l - ppd->custom_margins[3];
120
121 /*
122 * Update the custom option records for the page size, too...
123 */
124
125 if ((coption = ppdFindCustomOption(ppd, "PageSize")) != NULL)
126 {
127 if ((cparam = ppdFindCustomParam(coption, "Width")) != NULL)
128 cparam->current.custom_points = w;
129
130 if ((cparam = ppdFindCustomParam(coption, "Height")) != NULL)
131 cparam->current.custom_points = l;
132 }
133
134 /*
135 * Return the page size...
136 */
137
138 return (size);
ef416fc2 139 }
140 else
141 {
142 /*
143 * Lookup by name...
144 */
145
b86bc4cf 146 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
147 if (!strcmp(name, size->name))
148 return (size);
ef416fc2 149 }
150 }
151 else
152 {
153 /*
154 * Find default...
155 */
156
b86bc4cf 157 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
158 if (size->marked)
159 return (size);
ef416fc2 160 }
161
162 return (NULL);
163}
164
165
166/*
167 * 'ppdPageWidth()' - Get the page width for the given size.
168 */
169
170float /* O - Width of page in points or 0.0 */
171ppdPageWidth(ppd_file_t *ppd, /* I - PPD file record */
172 const char *name) /* I - Size name */
173{
174 ppd_size_t *size; /* Page size */
175
176
177 if ((size = ppdPageSize(ppd, name)) == NULL)
178 return (0.0);
179 else
180 return (size->width);
181}
182
183
184/*
185 * 'ppdPageLength()' - Get the page length for the given size.
186 */
187
188float /* O - Length of page in points or 0.0 */
189ppdPageLength(ppd_file_t *ppd, /* I - PPD file */
190 const char *name) /* I - Size name */
191{
192 ppd_size_t *size; /* Page size */
193
194
195 if ((size = ppdPageSize(ppd, name)) == NULL)
196 return (0.0);
197 else
198 return (size->length);
199}
200
201
202/*
bc44d920 203 * End of "$Id: page.c 6649 2007-07-11 21:46:42Z mike $".
ef416fc2 204 */