]>
Commit | Line | Data |
---|---|---|
54afec33 MS |
1 | /* |
2 | * "$Id$" | |
3 | * | |
4 | * PWG media name API implementation for CUPS. | |
5 | * | |
f14324a7 | 6 | * Copyright 2009-2011 by Apple Inc. |
54afec33 MS |
7 | * |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Apple Inc. and are protected by Federal copyright | |
10 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
11 | * which should have been included with this file. If this file is | |
12 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
13 | * | |
14 | * This file is subject to the Apple OS-Developed Software exception. | |
15 | * | |
16 | * Contents: | |
17 | * | |
18 | * _pwgGenerateSize() - Generate a PWG size keyword. | |
19 | * _pwgInitSize() - Initialize a PWG size using IPP job template | |
20 | * attributes. | |
21 | * _pwgMediaForLegacy() - Find a PWG media size by ISO/IPP legacy name. | |
22 | * _pwgMediaForPPD() - Find a PWG media size by Adobe PPD name. | |
23 | * _pwgMediaForPWG() - Find a PWG media size by 5101.1 self-describing | |
24 | * name. | |
25 | * _pwgMediaForSize() - Get the PWG media name for a given size. | |
26 | * pwg_compare_legacy() - Compare two sizes using the legacy names. | |
27 | * pwg_compare_ppd() - Compare two sizes using the PPD names. | |
28 | * pwg_compare_pwg() - Compare two sizes using the PWG names. | |
29 | */ | |
30 | ||
31 | /* | |
32 | * Include necessary headers... | |
33 | */ | |
34 | ||
71e16022 | 35 | #include "cups-private.h" |
54afec33 MS |
36 | #include <math.h> |
37 | ||
38 | ||
39 | /* | |
40 | * Local macros... | |
41 | */ | |
42 | ||
43 | #define _PWG_MEDIA_IN(p,l,a,x,y) {p, l, a, (int)(x * 2540), (int)(y * 2540)} | |
44 | #define _PWG_MEDIA_MM(p,l,a,x,y) {p, l, a, (int)(x * 100), (int)(y * 100)} | |
45 | ||
46 | ||
47 | /* | |
48 | * Local functions... | |
49 | */ | |
50 | ||
51 | static int pwg_compare_legacy(_pwg_media_t *a, _pwg_media_t *b); | |
52 | static int pwg_compare_pwg(_pwg_media_t *a, _pwg_media_t *b); | |
53 | static int pwg_compare_ppd(_pwg_media_t *a, _pwg_media_t *b); | |
54 | ||
55 | ||
56 | /* | |
57 | * Local globals... | |
58 | */ | |
59 | ||
60 | static _pwg_media_t const cups_pwg_media[] = | |
61 | { /* Media size lookup table */ | |
62 | /* North American Standard Sheet Media Sizes */ | |
7cf5915e | 63 | _PWG_MEDIA_IN("na_index-3x5_3x5in", NULL, "3x5", 3, 5), |
54afec33 MS |
64 | _PWG_MEDIA_IN("na_personal_3.625x6.5in", NULL, "EnvPersonal", 3.625, 6.5), |
65 | _PWG_MEDIA_IN("na_monarch_3.875x7.5in", "monarch-envelope", "EnvMonarch", 3.875, 7.5), | |
66 | _PWG_MEDIA_IN("na_number-9_3.875x8.875in", "na-number-9-envelope", "Env9", 3.875, 8.875), | |
7cf5915e | 67 | _PWG_MEDIA_IN("na_index-4x6_4x6in", NULL, "4x6", 4, 6), |
54afec33 | 68 | _PWG_MEDIA_IN("na_number-10_4.125x9.5in", "na-number-10-envelope", "Env10", 4.125, 9.5), |
dcb445bc | 69 | _PWG_MEDIA_IN("na_a2_4.375x5.75in", NULL, "EnvA2", 4.375, 5.75), |
54afec33 MS |
70 | _PWG_MEDIA_IN("na_number-11_4.5x10.375in", NULL, "Env11", 4.5, 10.375), |
71 | _PWG_MEDIA_IN("na_number-12_4.75x11in", NULL, "Env12", 4.75, 11), | |
7cf5915e MS |
72 | _PWG_MEDIA_IN("na_5x7_5x7in", NULL, "5x7", 5, 7), |
73 | _PWG_MEDIA_IN("na_index-5x8_5x8in", NULL, "5x8", 5, 8), | |
54afec33 MS |
74 | _PWG_MEDIA_IN("na_number-14_5x11.5in", NULL, "Env14", 5, 11.5), |
75 | _PWG_MEDIA_IN("na_invoice_5.5x8.5in", "invoice", "Statement", 5.5, 8.5), | |
76 | _PWG_MEDIA_IN("na_index-4x6-ext_6x8in", NULL, NULL, 6, 8), | |
7cf5915e MS |
77 | _PWG_MEDIA_IN("na_6x9_6x9in", "na-6x9-envelope", "6x9", 6, 9), |
78 | _PWG_MEDIA_IN("na_c5_6.5x9.5in", NULL, "6.5x9.5", 6.5, 9.5), | |
54afec33 MS |
79 | _PWG_MEDIA_IN("na_7x9_7x9in", "na-7x9-envelope", "7x9", 7, 9), |
80 | _PWG_MEDIA_IN("na_executive_7.25x10.5in", "executive", "Executive", 7.25, 10.5), | |
81 | _PWG_MEDIA_IN("na_govt-letter_8x10in", "na-8x10", "8x10", 8, 10), | |
7cf5915e | 82 | _PWG_MEDIA_IN("na_govt-legal_8x13in", NULL, "8x13", 8, 13), |
54afec33 MS |
83 | _PWG_MEDIA_IN("na_quarto_8.5x10.83in", "quarto", "Quarto", 8.5, 10.83), |
84 | _PWG_MEDIA_IN("na_letter_8.5x11in", "na-letter", "Letter", 8.5, 11), | |
85 | _PWG_MEDIA_IN("na_fanfold-eur_8.5x12in", NULL, "FanFoldGerman", 8.5, 12), | |
86 | _PWG_MEDIA_IN("na_letter-plus_8.5x12.69in", NULL, "LetterPlus", 8.5, 12.69), | |
87 | _PWG_MEDIA_IN("na_foolscap_8.5x13in", NULL, "FanFoldGermanLegal", 8.5, 13), | |
88 | _PWG_MEDIA_IN("na_legal_8.5x14in", "na-legal", "Legal", 8.5, 14), | |
89 | _PWG_MEDIA_IN("na_super-a_8.94x14in", NULL, "SuperA", 8.94, 14), | |
90 | _PWG_MEDIA_IN("na_9x11_9x11in", "na-9x11-envelope", "9x11", 9, 11), | |
91 | _PWG_MEDIA_IN("na_arch-a_9x12in", "arch-a", "ARCHA", 9, 12), | |
92 | _PWG_MEDIA_IN("na_letter-extra_9.5x12in", NULL, "LetterExtra", 9.5, 12), | |
93 | _PWG_MEDIA_IN("na_legal-extra_9.5x15in", NULL, "LegalExtra", 9.5, 15), | |
94 | _PWG_MEDIA_IN("na_10x11_10x11in", NULL, "10x11", 10, 11), | |
95 | _PWG_MEDIA_IN("na_10x13_10x13in", "na-10x13-envelope", "10x13", 10, 13), | |
96 | _PWG_MEDIA_IN("na_10x14_10x14in", "na-10x14-envelope", "10x14", 10, 14), | |
7cf5915e MS |
97 | _PWG_MEDIA_IN("na_10x15_10x15in", "na-10x15-envelope", "10x15", 10, 15), |
98 | _PWG_MEDIA_IN("na_11x12_11x12in", NULL, "11x12", 11, 12), | |
99 | _PWG_MEDIA_IN("na_edp_11x14in", NULL, "11x14", 11, 14), | |
54afec33 | 100 | _PWG_MEDIA_IN("na_fanfold-us_11x14.875in", NULL, NULL, 11, 14.875), |
7cf5915e | 101 | _PWG_MEDIA_IN("na_11x15_11x15in", NULL, "11x15", 11, 15), |
54afec33 MS |
102 | _PWG_MEDIA_IN("na_ledger_11x17in", "tabloid", "Tabloid", 11, 17), |
103 | _PWG_MEDIA_IN("na_eur-edp_12x14in", NULL, NULL, 12, 14), | |
104 | _PWG_MEDIA_IN("na_arch-b_12x18in", "arch-b", "ARCHB", 12, 18), | |
7cf5915e | 105 | _PWG_MEDIA_IN("na_12x19_12x19in", NULL, "12x19", 12, 19), |
a2326b5b MS |
106 | _PWG_MEDIA_IN("na_b-plus_12x19.17in", NULL, "SuperB", 12, 19.17), |
107 | _PWG_MEDIA_IN("na_super-b_13x19in", "super-b", "13x19", 13, 19), | |
54afec33 MS |
108 | _PWG_MEDIA_IN("na_c_17x22in", "c", "AnsiC", 17, 22), |
109 | _PWG_MEDIA_IN("na_arch-c_18x24in", "arch-c", "ARCHC", 18, 24), | |
110 | _PWG_MEDIA_IN("na_d_22x34in", "d", "AnsiD", 22, 34), | |
111 | _PWG_MEDIA_IN("na_arch-d_24x36in", "arch-d", "ARCHD", 24, 36), | |
112 | _PWG_MEDIA_IN("asme_f_28x40in", "f", NULL, 28, 40), | |
113 | _PWG_MEDIA_IN("na_wide-format_30x42in", NULL, NULL, 30, 42), | |
114 | _PWG_MEDIA_IN("na_e_34x44in", "e", "AnsiE", 34, 44), | |
115 | _PWG_MEDIA_IN("na_arch-e_36x48in", "arch-e", "ARCHE", 36, 48), | |
7cf5915e | 116 | _PWG_MEDIA_IN("na_f_44x68in", NULL, "AnsiF", 44, 68), |
54afec33 MS |
117 | |
118 | /* Chinese Standard Sheet Media Inch Sizes */ | |
f14324a7 | 119 | _PWG_MEDIA_IN("roc_16k_7.75x10.75in", NULL, "roc16k", 7.75, 10.75), |
54afec33 MS |
120 | _PWG_MEDIA_IN("roc_8k_10.75x15.5in", NULL, NULL, 10.75, 15.5), |
121 | ||
122 | /* ISO Standard Sheet Media Sizes */ | |
123 | _PWG_MEDIA_MM("iso_a10_26x37mm", "iso-a10", "A10", 26, 37), | |
124 | _PWG_MEDIA_MM("iso_a9_37x52mm", "iso-a9", "A9", 37, 52), | |
125 | _PWG_MEDIA_MM("iso_a8_52x74mm", "iso-a8", "A8", 52, 74), | |
126 | _PWG_MEDIA_MM("iso_a7_74x105mm", "iso-a7", "A7", 74, 105), | |
127 | _PWG_MEDIA_MM("iso_a6_105x148mm", "iso-a6", "A6", 105, 148), | |
128 | _PWG_MEDIA_MM("iso_a5_148x210mm", "iso-a5", "A5", 148, 210), | |
129 | _PWG_MEDIA_MM("iso_a5-extra_174x235mm", NULL, "A5Extra", 174, 235), | |
130 | _PWG_MEDIA_MM("iso_a4_210x297mm", "iso-a4", "A4", 210, 297), | |
131 | _PWG_MEDIA_MM("iso_a4-tab_225x297mm", NULL, NULL, 225, 297), | |
132 | _PWG_MEDIA_MM("iso_a4-extra_235.5x322.3mm", NULL, "A4Extra", 235.5, 322.3), | |
133 | _PWG_MEDIA_MM("iso_a3_297x420mm", "iso-a3", "A3", 297, 420), | |
134 | _PWG_MEDIA_MM("iso_a4x3_297x630mm", "iso-a4x3", NULL, 297, 630), | |
135 | _PWG_MEDIA_MM("iso_a4x4_297x841mm", "iso-a4x4", NULL, 297, 841), | |
136 | _PWG_MEDIA_MM("iso_a4x5_297x1051mm", "iso-a4x5", NULL, 297, 1051), | |
137 | _PWG_MEDIA_MM("iso_a4x6_297x1261mm", "iso-a4x6", NULL, 297, 1261), | |
138 | _PWG_MEDIA_MM("iso_a4x7_297x1471mm", "iso-a4x7", NULL, 297, 1471), | |
139 | _PWG_MEDIA_MM("iso_a4x8_297x1682mm", "iso-a4x8", NULL, 297, 1682), | |
140 | _PWG_MEDIA_MM("iso_a4x9_297x1892mm", "iso-a4x9", NULL, 297, 1892), | |
141 | _PWG_MEDIA_MM("iso_a3-extra_322x445mm", "iso-a3-extra", "A3Extra", 322, 445), | |
142 | _PWG_MEDIA_MM("iso_a2_420x594mm", "iso-a2", "A2", 420, 594), | |
143 | _PWG_MEDIA_MM("iso_a3x3_420x891mm", "iso-a3x3", NULL, 420, 891), | |
144 | _PWG_MEDIA_MM("iso_a3x4_420x1189mm", "iso-a3x4", NULL, 420, 1189), | |
145 | _PWG_MEDIA_MM("iso_a3x5_420x1486mm", "iso-a3x5", NULL, 420, 1486), | |
146 | _PWG_MEDIA_MM("iso_a3x6_420x1783mm", "iso-a3x6", NULL, 420, 1783), | |
147 | _PWG_MEDIA_MM("iso_a3x7_420x2080mm", "iso-a3x7", NULL, 420, 2080), | |
148 | _PWG_MEDIA_MM("iso_a1_594x841mm", "iso-a1", "A1", 594, 841), | |
149 | _PWG_MEDIA_MM("iso_a2x3_594x1261mm", "iso-a2x3", NULL, 594, 1261), | |
150 | _PWG_MEDIA_MM("iso_a2x4_594x1682mm", "iso-a2x4", NULL, 594, 1682), | |
151 | _PWG_MEDIA_MM("iso_a2x5_594x2102mm", "iso-a2x5", NULL, 594, 2102), | |
152 | _PWG_MEDIA_MM("iso_a0_841x1189mm", "iso-a0", "A0", 841, 1189), | |
153 | _PWG_MEDIA_MM("iso_a1x3_841x1783mm", "iso-a1x3", NULL, 841, 1783), | |
154 | _PWG_MEDIA_MM("iso_a1x4_841x2378mm", "iso-a1x4", NULL, 841, 2378), | |
155 | _PWG_MEDIA_MM("iso_2a0_1189x1682mm", NULL, NULL, 1189, 1682), | |
156 | _PWG_MEDIA_MM("iso_a0x3_1189x2523mm", NULL, NULL, 1189, 2523), | |
157 | _PWG_MEDIA_MM("iso_b10_31x44mm", "iso-b10", "ISOB10", 31, 44), | |
158 | _PWG_MEDIA_MM("iso_b9_44x62mm", "iso-b9", "ISOB9", 44, 62), | |
159 | _PWG_MEDIA_MM("iso_b8_62x88mm", "iso-b8", "ISOB8", 62, 88), | |
160 | _PWG_MEDIA_MM("iso_b7_88x125mm", "iso-b7", "ISOB7", 88, 125), | |
161 | _PWG_MEDIA_MM("iso_b6_125x176mm", "iso-b6", "ISOB6", 125, 176), | |
162 | _PWG_MEDIA_MM("iso_b6c4_125x324mm", NULL, NULL, 125, 324), | |
163 | _PWG_MEDIA_MM("iso_b5_176x250mm", "iso-b5", "ISOB5", 176, 250), | |
164 | _PWG_MEDIA_MM("iso_b5-extra_201x276mm", NULL, "ISOB5Extra", 201, 276), | |
165 | _PWG_MEDIA_MM("iso_b4_250x353mm", "iso-b4", "ISOB4", 250, 353), | |
166 | _PWG_MEDIA_MM("iso_b3_353x500mm", "iso-b3", "ISOB3", 353, 500), | |
167 | _PWG_MEDIA_MM("iso_b2_500x707mm", "iso-b2", "ISOB2", 500, 707), | |
168 | _PWG_MEDIA_MM("iso_b1_707x1000mm", "iso-b1", "ISOB1", 707, 1000), | |
169 | _PWG_MEDIA_MM("iso_b0_1000x1414mm", "iso-b0", "ISOB0", 1000, 1414), | |
170 | _PWG_MEDIA_MM("iso_c10_28x40mm", "iso-c10", NULL, 28, 40), | |
171 | _PWG_MEDIA_MM("iso_c9_40x57mm", "iso-c9", NULL, 40, 57), | |
172 | _PWG_MEDIA_MM("iso_c8_57x81mm", "iso-c8", NULL, 57, 81), | |
173 | _PWG_MEDIA_MM("iso_c7_81x114mm", "iso-c7", "EnvC7", 81, 114), | |
174 | _PWG_MEDIA_MM("iso_c7c6_81x162mm", NULL, NULL, 81, 162), | |
175 | _PWG_MEDIA_MM("iso_c6_114x162mm", "iso-c6", "EnvC6", 114, 162), | |
176 | _PWG_MEDIA_MM("iso_c6c5_114x229mm", NULL, "EnvC65", 114, 229), | |
177 | _PWG_MEDIA_MM("iso_c5_162x229mm", "iso-c5", "EnvC5", 162, 229), | |
178 | _PWG_MEDIA_MM("iso_c4_229x324mm", "iso-c4", "EnvC4", 229, 324), | |
179 | _PWG_MEDIA_MM("iso_c3_324x458mm", "iso-c3", "EnvC3", 324, 458), | |
180 | _PWG_MEDIA_MM("iso_c2_458x648mm", "iso-c2", "EnvC2", 458, 648), | |
181 | _PWG_MEDIA_MM("iso_c1_648x917mm", "iso-c1", "EnvC1", 648, 917), | |
182 | _PWG_MEDIA_MM("iso_c0_917x1297mm", "iso-c0", "EnvC0", 917, 1297), | |
183 | _PWG_MEDIA_MM("iso_dl_110x220mm", "iso-designated", "EnvDL", 110, 220), | |
184 | _PWG_MEDIA_MM("iso_ra2_430x610mm", "iso-ra2", NULL, 430, 610), | |
185 | _PWG_MEDIA_MM("iso_sra2_450x640mm", "iso-sra2", NULL, 450, 640), | |
186 | _PWG_MEDIA_MM("iso_ra1_610x860mm", "iso-ra1", NULL, 610, 860), | |
187 | _PWG_MEDIA_MM("iso_sra1_640x900mm", "iso-sra1", NULL, 640, 900), | |
188 | _PWG_MEDIA_MM("iso_ra0_860x1220mm", "iso-ra0", NULL, 860, 1220), | |
189 | _PWG_MEDIA_MM("iso_sra0_900x1280mm", "iso-sra0", NULL, 900, 1280), | |
190 | ||
191 | /* Japanese Standard Sheet Media Sizes */ | |
192 | _PWG_MEDIA_MM("jis_b10_32x45mm", "jis-b10", "B10", 32, 45), | |
193 | _PWG_MEDIA_MM("jis_b9_45x64mm", "jis-b9", "B9", 45, 64), | |
194 | _PWG_MEDIA_MM("jis_b8_64x91mm", "jis-b8", "B8", 64, 91), | |
195 | _PWG_MEDIA_MM("jis_b7_91x128mm", "jis-b7", "B7", 91, 128), | |
196 | _PWG_MEDIA_MM("jis_b6_128x182mm", "jis-b6", "B6", 128, 182), | |
197 | _PWG_MEDIA_MM("jis_b5_182x257mm", "jis-b5", "B5", 182, 257), | |
198 | _PWG_MEDIA_MM("jis_b4_257x364mm", "jis-b4", "B4", 257, 364), | |
199 | _PWG_MEDIA_MM("jis_b3_364x515mm", "jis-b3", "B3", 364, 515), | |
200 | _PWG_MEDIA_MM("jis_b2_515x728mm", "jis-b2", "B2", 515, 728), | |
201 | _PWG_MEDIA_MM("jis_b1_728x1030mm", "jis-b1", "B1", 728, 1030), | |
202 | _PWG_MEDIA_MM("jis_b0_1030x1456mm", "jis-b0", "B0", 1030, 1456), | |
203 | _PWG_MEDIA_MM("jis_exec_216x330mm", NULL, NULL, 216, 330), | |
204 | _PWG_MEDIA_MM("jpn_chou4_90x205mm", NULL, "EnvChou4", 90, 205), | |
205 | _PWG_MEDIA_MM("jpn_hagaki_100x148mm", NULL, "Postcard", 100, 148), | |
206 | _PWG_MEDIA_MM("jpn_you4_105x235mm", NULL, "EnvYou4", 105, 235), | |
207 | _PWG_MEDIA_MM("jpn_chou2_111.1x146mm", NULL, NULL, 111.1, 146), | |
208 | _PWG_MEDIA_MM("jpn_chou3_120x235mm", NULL, "EnvChou3", 120, 235), | |
209 | _PWG_MEDIA_MM("jpn_oufuku_148x200mm", NULL, "DoublePostcardRotated", 148, 200), | |
210 | _PWG_MEDIA_MM("jpn_kahu_240x322.1mm", NULL, NULL, 240, 322.1), | |
211 | _PWG_MEDIA_MM("jpn_kaku2_240x332mm", NULL, "EnvKaku2", 240, 332), | |
212 | ||
213 | /* Chinese Standard Sheet Media Sizes */ | |
214 | _PWG_MEDIA_MM("prc_32k_97x151mm", NULL, "PRC32K", 97, 151), | |
215 | _PWG_MEDIA_MM("prc_1_102x165mm", NULL, "EnvPRC1", 102, 165), | |
216 | _PWG_MEDIA_MM("prc_2_102x176mm", NULL, "EnvPRC2", 102, 176), | |
217 | _PWG_MEDIA_MM("prc_4_110x208mm", NULL, "EnvPRC4", 110, 208), | |
218 | _PWG_MEDIA_MM("prc_5_110x220mm", NULL, "EnvPRC5", 110, 220), | |
219 | _PWG_MEDIA_MM("prc_8_120x309mm", NULL, "EnvPRC8", 120, 309), | |
220 | _PWG_MEDIA_MM("prc_6_120x320mm", NULL, NULL, 120, 320), | |
221 | _PWG_MEDIA_MM("prc_3_125x176mm", NULL, "EnvPRC3", 125, 176), | |
222 | _PWG_MEDIA_MM("prc_16k_146x215mm", NULL, "PRC16K", 146, 215), | |
223 | _PWG_MEDIA_MM("prc_7_160x230mm", NULL, "EnvPRC7", 160, 230), | |
224 | _PWG_MEDIA_MM("om_juuro-ku-kai_198x275mm", NULL, NULL, 198, 275), | |
225 | _PWG_MEDIA_MM("om_pa-kai_267x389mm", NULL, NULL, 267, 389), | |
226 | _PWG_MEDIA_MM("om_dai-pa-kai_275x395mm", NULL, NULL, 275, 395), | |
227 | _PWG_MEDIA_MM("prc_10_324x458mm", NULL, "EnvPRC10", 324, 458), | |
228 | ||
f228370c MS |
229 | /* Other English Standard Sheet Media Sizes */ |
230 | _PWG_MEDIA_IN("oe_photo-l_3.5x5in", NULL, "3.5x5", 3.5, 5), | |
231 | ||
54afec33 | 232 | /* Other Metric Standard Sheet Media Sizes */ |
dcb445bc | 233 | _PWG_MEDIA_MM("om_small-photo_100x150mm", NULL, "om_small-photo", 100, 150), |
54afec33 MS |
234 | _PWG_MEDIA_MM("om_italian_110x230mm", NULL, "EnvItalian", 110, 230), |
235 | _PWG_MEDIA_MM("om_postfix_114x229mm", NULL, NULL, 114, 229), | |
236 | _PWG_MEDIA_MM("om_large-photo_200x300", NULL, NULL, 200, 300), | |
237 | _PWG_MEDIA_MM("om_folio_210x330mm", "folio", "Folio", 210, 330), | |
238 | _PWG_MEDIA_MM("om_folio-sp_215x315mm", NULL, NULL, 215, 315), | |
239 | _PWG_MEDIA_MM("om_invite_220x220mm", NULL, "EnvInvite", 220, 220) | |
240 | }; | |
241 | ||
242 | ||
243 | /* | |
244 | * '_pwgGenerateSize()' - Generate a PWG size keyword. | |
245 | */ | |
246 | ||
247 | void | |
248 | _pwgGenerateSize(char *keyword, /* I - Keyword buffer */ | |
249 | size_t keysize, /* I - Size of keyword buffer */ | |
250 | const char *prefix, /* I - Prefix for PWG size or NULL */ | |
251 | const char *name, /* I - Size name or NULL */ | |
252 | int width, /* I - Width of page in 2540ths */ | |
253 | int length) /* I - Length of page in 2540ths */ | |
254 | { | |
255 | struct lconv *loc; /* Locale conversion data */ | |
256 | double uwidth, /* Width in inches or millimeters */ | |
257 | ulength; /* Height in inches or millimeters */ | |
258 | const char *units; /* Units to report */ | |
259 | char usize[12 + 1 + 12 + 3], /* Unit size: NNNNNNNNNNNNxNNNNNNNNNNNNuu */ | |
260 | *uptr; /* Pointer into unit size */ | |
261 | ||
262 | ||
263 | loc = localeconv(); | |
264 | ||
265 | if ((width % 635) == 0 && (length % 635) == 0) | |
266 | { | |
267 | /* | |
268 | * Use inches since the size is a multiple of 1/4 inch. | |
269 | */ | |
270 | ||
271 | uwidth = width / 2540.0; | |
272 | ulength = length / 2540.0; | |
273 | units = "in"; | |
274 | ||
275 | if (!prefix) | |
276 | prefix = "oe"; | |
277 | } | |
278 | else | |
279 | { | |
280 | /* | |
281 | * Use millimeters since the size is not a multiple of 1/4 inch. | |
282 | */ | |
283 | ||
284 | uwidth = width * 0.01; | |
285 | ulength = length * 0.01; | |
286 | units = "mm"; | |
287 | ||
288 | if (!prefix) | |
289 | prefix = "om"; | |
290 | } | |
291 | ||
292 | uptr = usize; | |
293 | _cupsStrFormatd(uptr, uptr + 12, uwidth, loc); | |
294 | uptr += strlen(uptr); | |
295 | *uptr++ = 'x'; | |
296 | _cupsStrFormatd(uptr, uptr + 12, ulength, loc); | |
297 | uptr += strlen(uptr); | |
298 | ||
299 | /* | |
300 | * Safe because usize can hold up to 12 + 1 + 12 + 4 bytes. | |
301 | */ | |
302 | ||
303 | strcpy(uptr, units); | |
304 | ||
305 | if (!name) | |
306 | name = usize; | |
307 | ||
308 | /* | |
309 | * Format the name... | |
310 | */ | |
311 | ||
312 | snprintf(keyword, keysize, "%s_%s_%s", prefix, name, usize); | |
313 | } | |
314 | ||
315 | ||
316 | /* | |
317 | * '_pwgInitSize()' - Initialize a PWG size using IPP job template attributes. | |
318 | */ | |
319 | ||
320 | int /* O - 1 if size was initialize, 0 otherwise */ | |
321 | _pwgInitSize(_pwg_size_t *size, /* I - Size to initialize */ | |
322 | ipp_t *job, /* I - Job template attributes */ | |
323 | int *margins_set) /* O - 1 if margins were set, 0 otherwise */ | |
324 | { | |
325 | ipp_attribute_t *media, /* media attribute */ | |
326 | *media_bottom_margin, /* media-bottom-margin member attribute */ | |
327 | *media_col, /* media-col attribute */ | |
328 | *media_left_margin, /* media-left-margin member attribute */ | |
329 | *media_right_margin, /* media-right-margin member attribute */ | |
330 | *media_size, /* media-size member attribute */ | |
331 | *media_top_margin, /* media-top-margin member attribute */ | |
332 | *x_dimension, /* x-dimension member attribute */ | |
333 | *y_dimension; /* y-dimension member attribute */ | |
334 | _pwg_media_t *pwg; /* PWG media value */ | |
335 | ||
336 | ||
337 | /* | |
338 | * Range check input... | |
339 | */ | |
340 | ||
341 | if (!size || !job || !margins_set) | |
342 | return (0); | |
343 | ||
344 | /* | |
345 | * Look for media-col and then media... | |
346 | */ | |
347 | ||
348 | memset(size, 0, sizeof(_pwg_size_t)); | |
349 | *margins_set = 0; | |
350 | ||
351 | if ((media_col = ippFindAttribute(job, "media-col", | |
352 | IPP_TAG_BEGIN_COLLECTION)) != NULL) | |
353 | { | |
354 | /* | |
355 | * Got media-col, look for media-size member attribute... | |
356 | */ | |
357 | ||
358 | if ((media_size = ippFindAttribute(media_col->values[0].collection, | |
7cf5915e MS |
359 | "media-size", |
360 | IPP_TAG_BEGIN_COLLECTION)) != NULL) | |
54afec33 MS |
361 | { |
362 | /* | |
363 | * Got media-size, look for x-dimension and y-dimension member | |
364 | * attributes... | |
365 | */ | |
366 | ||
367 | x_dimension = ippFindAttribute(media_size->values[0].collection, | |
368 | "x-dimension", IPP_TAG_INTEGER); | |
369 | y_dimension = ippFindAttribute(media_size->values[0].collection, | |
370 | "y-dimension", IPP_TAG_INTEGER); | |
371 | ||
372 | if (x_dimension && y_dimension) | |
373 | { | |
374 | size->width = x_dimension->values[0].integer; | |
375 | size->length = y_dimension->values[0].integer; | |
376 | } | |
377 | else if (!x_dimension) | |
378 | { | |
379 | _cupsSetError(IPP_INTERNAL_ERROR, | |
380 | _("Missing x-dimension in media-size."), 1); | |
381 | return (0); | |
382 | } | |
383 | else if (!y_dimension) | |
384 | { | |
385 | _cupsSetError(IPP_INTERNAL_ERROR, | |
386 | _("Missing y-dimension in media-size."), 1); | |
387 | return (0); | |
388 | } | |
389 | } | |
390 | else | |
391 | { | |
392 | _cupsSetError(IPP_INTERNAL_ERROR, _("Missing media-size in media-col."), | |
393 | 1); | |
394 | return (0); | |
395 | } | |
396 | ||
397 | /* media-*-margin */ | |
398 | media_bottom_margin = ippFindAttribute(media_col->values[0].collection, | |
399 | "media-bottom-margin", | |
400 | IPP_TAG_INTEGER); | |
401 | media_left_margin = ippFindAttribute(media_col->values[0].collection, | |
402 | "media-left-margin", | |
403 | IPP_TAG_INTEGER); | |
404 | media_right_margin = ippFindAttribute(media_col->values[0].collection, | |
405 | "media-right-margin", | |
406 | IPP_TAG_INTEGER); | |
407 | media_top_margin = ippFindAttribute(media_col->values[0].collection, | |
408 | "media-top-margin", | |
409 | IPP_TAG_INTEGER); | |
410 | if (media_bottom_margin && media_left_margin && media_right_margin && | |
411 | media_top_margin) | |
412 | { | |
413 | *margins_set = 1; | |
414 | size->bottom = media_bottom_margin->values[0].integer; | |
415 | size->left = media_left_margin->values[0].integer; | |
416 | size->right = media_right_margin->values[0].integer; | |
417 | size->top = media_top_margin->values[0].integer; | |
418 | } | |
419 | } | |
420 | else | |
421 | { | |
422 | if ((media = ippFindAttribute(job, "media", IPP_TAG_NAME)) == NULL) | |
7cf5915e MS |
423 | if ((media = ippFindAttribute(job, "media", IPP_TAG_KEYWORD)) == NULL) |
424 | if ((media = ippFindAttribute(job, "PageSize", IPP_TAG_NAME)) == NULL) | |
425 | media = ippFindAttribute(job, "PageRegion", IPP_TAG_NAME); | |
54afec33 MS |
426 | |
427 | if (media) | |
428 | { | |
7cf5915e MS |
429 | const char *name = media->values[0].string.text; |
430 | /* Name string */ | |
431 | ||
432 | if ((pwg = _pwgMediaForPWG(name)) == NULL) | |
433 | { | |
434 | /* | |
435 | * Not a PWG name, try a legacy name... | |
436 | */ | |
437 | ||
438 | if ((pwg = _pwgMediaForLegacy(name)) == NULL) | |
439 | { | |
440 | /* | |
441 | * Not a legacy name, try a PPD name... | |
442 | */ | |
443 | ||
444 | const char *suffix; /* Suffix on media string */ | |
445 | ||
446 | pwg = _pwgMediaForPPD(name); | |
84315f46 | 447 | if (pwg && |
7cf5915e | 448 | (suffix = name + strlen(name) - 10 /* .FullBleed */) > name && |
88f9aafc | 449 | !_cups_strcasecmp(suffix, ".FullBleed")) |
7cf5915e MS |
450 | { |
451 | /* | |
452 | * Indicate that margins are set with the default values of 0. | |
453 | */ | |
454 | ||
455 | *margins_set = 1; | |
456 | } | |
457 | } | |
458 | } | |
54afec33 MS |
459 | |
460 | if (pwg) | |
461 | { | |
462 | size->width = pwg->width; | |
463 | size->length = pwg->length; | |
464 | } | |
465 | else | |
466 | { | |
467 | _cupsSetError(IPP_INTERNAL_ERROR, _("Unsupported media value."), 1); | |
468 | return (0); | |
469 | } | |
470 | } | |
471 | else | |
472 | { | |
473 | _cupsSetError(IPP_INTERNAL_ERROR, _("Missing media or media-col."), 1); | |
474 | return (0); | |
475 | } | |
476 | } | |
477 | ||
478 | return (1); | |
479 | } | |
480 | ||
481 | ||
482 | /* | |
483 | * '_pwgMediaForLegacy()' - Find a PWG media size by ISO/IPP legacy name. | |
484 | */ | |
485 | ||
486 | _pwg_media_t * /* O - Matching size or NULL */ | |
487 | _pwgMediaForLegacy( | |
488 | const char *legacy) /* I - Legacy size name */ | |
489 | { | |
490 | _pwg_media_t key; /* Search key */ | |
491 | _cups_globals_t *cg = _cupsGlobals(); /* Global data */ | |
492 | ||
493 | ||
494 | /* | |
495 | * Range check input... | |
496 | */ | |
497 | ||
498 | if (!legacy) | |
499 | return (NULL); | |
500 | ||
501 | /* | |
502 | * Build the lookup table for PWG names as needed... | |
503 | */ | |
504 | ||
505 | if (!cg->leg_size_lut) | |
506 | { | |
507 | int i; /* Looping var */ | |
508 | _pwg_media_t *size; /* Current size */ | |
509 | ||
510 | cg->leg_size_lut = cupsArrayNew((cups_array_func_t)pwg_compare_legacy, | |
511 | NULL); | |
512 | ||
513 | for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])), | |
514 | size = (_pwg_media_t *)cups_pwg_media; | |
515 | i > 0; | |
516 | i --, size ++) | |
517 | if (size->legacy) | |
518 | cupsArrayAdd(cg->leg_size_lut, size); | |
519 | } | |
520 | ||
521 | /* | |
522 | * Lookup the name... | |
523 | */ | |
524 | ||
525 | key.legacy = legacy; | |
526 | return ((_pwg_media_t *)cupsArrayFind(cg->leg_size_lut, &key)); | |
527 | } | |
528 | ||
529 | ||
530 | /* | |
531 | * '_pwgMediaForPPD()' - Find a PWG media size by Adobe PPD name. | |
532 | */ | |
533 | ||
534 | _pwg_media_t * /* O - Matching size or NULL */ | |
535 | _pwgMediaForPPD(const char *ppd) /* I - PPD size name */ | |
536 | { | |
7cf5915e MS |
537 | _pwg_media_t key, /* Search key */ |
538 | *size; /* Matching size */ | |
54afec33 MS |
539 | _cups_globals_t *cg = _cupsGlobals(); /* Global data */ |
540 | ||
541 | ||
542 | /* | |
543 | * Range check input... | |
544 | */ | |
545 | ||
546 | if (!ppd) | |
547 | return (NULL); | |
548 | ||
549 | /* | |
550 | * Build the lookup table for PWG names as needed... | |
551 | */ | |
552 | ||
553 | if (!cg->ppd_size_lut) | |
554 | { | |
7cf5915e | 555 | int i; /* Looping var */ |
54afec33 MS |
556 | |
557 | cg->ppd_size_lut = cupsArrayNew((cups_array_func_t)pwg_compare_ppd, NULL); | |
558 | ||
559 | for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])), | |
560 | size = (_pwg_media_t *)cups_pwg_media; | |
561 | i > 0; | |
562 | i --, size ++) | |
563 | if (size->ppd) | |
564 | cupsArrayAdd(cg->ppd_size_lut, size); | |
565 | } | |
566 | ||
567 | /* | |
568 | * Lookup the name... | |
569 | */ | |
570 | ||
571 | key.ppd = ppd; | |
7cf5915e MS |
572 | if ((size = (_pwg_media_t *)cupsArrayFind(cg->ppd_size_lut, &key)) == NULL) |
573 | { | |
574 | /* | |
575 | * See if the name is of the form: | |
576 | * | |
577 | * [Custom.]WIDTHxLENGTH[.FullBleed] - Size in points/inches [borderless] | |
578 | * [Custom.]WIDTHxLENGTHcm[.FullBleed] - Size in centimeters [borderless] | |
579 | * [Custom.]WIDTHxLENGTHft[.FullBleed] - Size in feet [borderless] | |
580 | * [Custom.]WIDTHxLENGTHin[.FullBleed] - Size in inches [borderless] | |
581 | * [Custom.]WIDTHxLENGTHm[.FullBleed] - Size in meters [borderless] | |
582 | * [Custom.]WIDTHxLENGTHmm[.FullBleed] - Size in millimeters [borderless] | |
583 | * [Custom.]WIDTHxLENGTHpt[.FullBleed] - Size in points [borderless] | |
584 | */ | |
585 | ||
586 | double w, l, /* Width and length of page */ | |
587 | factor; /* Unit scaling factor */ | |
588 | char *ptr; /* Pointer into name */ | |
589 | struct lconv *loc; /* Locale data */ | |
590 | int custom; /* Custom page size? */ | |
591 | ||
88f9aafc | 592 | if (!_cups_strncasecmp(ppd, "Custom.", 7)) |
7cf5915e MS |
593 | { |
594 | custom = 1; | |
595 | factor = 2540.0 / 72.0; | |
596 | ptr = (char *)ppd + 7; | |
597 | } | |
598 | else | |
599 | { | |
600 | custom = 0; | |
601 | factor = 2540.0; | |
602 | ptr = (char *)ppd; | |
603 | } | |
604 | ||
605 | loc = localeconv(); | |
606 | w = _cupsStrScand(ptr, &ptr, loc); | |
607 | ||
608 | if (ptr && ptr > ppd && *ptr == 'x') | |
609 | { | |
610 | l = _cupsStrScand(ptr + 1, &ptr, loc); | |
611 | ||
612 | if (ptr && | |
613 | (!*ptr || | |
88f9aafc MS |
614 | !_cups_strcasecmp(ptr, "FullBleed") || |
615 | !_cups_strcasecmp(ptr, ".FullBleed") || | |
616 | !_cups_strcasecmp(ptr, "cm") || | |
617 | !_cups_strcasecmp(ptr, "cm.FullBleed") || | |
618 | !_cups_strcasecmp(ptr, "ft") || | |
619 | !_cups_strcasecmp(ptr, "ft.FullBleed") || | |
620 | !_cups_strcasecmp(ptr, "in") || | |
621 | !_cups_strcasecmp(ptr, "in.FullBleed") || | |
622 | !_cups_strcasecmp(ptr, "m") || | |
623 | !_cups_strcasecmp(ptr, "m.FullBleed") || | |
624 | !_cups_strcasecmp(ptr, "mm") || | |
625 | !_cups_strcasecmp(ptr, "mm.FullBleed") || | |
626 | !_cups_strcasecmp(ptr, "pt") || | |
627 | !_cups_strcasecmp(ptr, "pt.FullBleed"))) | |
7cf5915e MS |
628 | { |
629 | size = &(cg->pwg_media); | |
630 | ||
88f9aafc | 631 | if (!_cups_strncasecmp(ptr, "cm", 2)) |
7cf5915e | 632 | factor = 1000.0; |
88f9aafc | 633 | else if (!_cups_strncasecmp(ptr, "ft", 2)) |
7cf5915e | 634 | factor = 2540.0 * 12.0; |
88f9aafc | 635 | else if (!_cups_strncasecmp(ptr, "in", 2)) |
7cf5915e | 636 | factor = 2540.0; |
88f9aafc | 637 | else if (!_cups_strncasecmp(ptr, "mm", 2)) |
7cf5915e MS |
638 | factor = 100.0; |
639 | else if (*ptr == 'm' || *ptr == 'M') | |
640 | factor = 100000.0; | |
88f9aafc | 641 | else if (!_cups_strncasecmp(ptr, "pt", 2)) |
7cf5915e MS |
642 | factor = 2540.0 / 72.0; |
643 | ||
644 | /* | |
645 | * Not a standard size; convert it to a PWG custom name of the form: | |
646 | * | |
647 | * [oe|om]_WIDTHxHEIGHTuu_WIDTHxHEIGHTuu | |
648 | */ | |
649 | ||
650 | size->width = (int)(w * factor); | |
651 | size->length = (int)(l * factor); | |
652 | size->pwg = cg->pwg_name; | |
653 | ||
654 | _pwgGenerateSize(cg->pwg_name, sizeof(cg->pwg_name), | |
655 | custom ? "custom" : NULL, custom ? ppd + 7 : NULL, | |
656 | size->width, size->length); | |
657 | } | |
658 | } | |
659 | } | |
660 | ||
661 | return (size); | |
54afec33 MS |
662 | } |
663 | ||
664 | ||
665 | /* | |
666 | * '_pwgMediaForPWG()' - Find a PWG media size by 5101.1 self-describing name. | |
667 | */ | |
668 | ||
669 | _pwg_media_t * /* O - Matching size or NULL */ | |
670 | _pwgMediaForPWG(const char *pwg) /* I - PWG size name */ | |
671 | { | |
7cf5915e MS |
672 | char *ptr; /* Pointer into name */ |
673 | _pwg_media_t key, /* Search key */ | |
674 | *size; /* Matching size */ | |
54afec33 MS |
675 | _cups_globals_t *cg = _cupsGlobals(); /* Global data */ |
676 | ||
677 | ||
678 | /* | |
679 | * Range check input... | |
680 | */ | |
681 | ||
682 | if (!pwg) | |
683 | return (NULL); | |
684 | ||
685 | /* | |
686 | * Build the lookup table for PWG names as needed... | |
687 | */ | |
688 | ||
689 | if (!cg->pwg_size_lut) | |
690 | { | |
7cf5915e | 691 | int i; /* Looping var */ |
54afec33 MS |
692 | |
693 | cg->pwg_size_lut = cupsArrayNew((cups_array_func_t)pwg_compare_pwg, NULL); | |
694 | ||
695 | for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])), | |
696 | size = (_pwg_media_t *)cups_pwg_media; | |
697 | i > 0; | |
698 | i --, size ++) | |
699 | cupsArrayAdd(cg->pwg_size_lut, size); | |
700 | } | |
701 | ||
702 | /* | |
703 | * Lookup the name... | |
704 | */ | |
705 | ||
706 | key.pwg = pwg; | |
7cf5915e MS |
707 | if ((size = (_pwg_media_t *)cupsArrayFind(cg->pwg_size_lut, &key)) == NULL && |
708 | (ptr = (char *)strchr(pwg, '_')) != NULL && | |
709 | (ptr = (char *)strchr(ptr + 1, '_')) != NULL) | |
710 | { | |
711 | /* | |
712 | * Try decoding the self-describing name of the form: | |
713 | * | |
714 | * class_name_WWWxHHHin | |
715 | * class_name_WWWxHHHmm | |
716 | */ | |
717 | ||
718 | double w, l; /* Width and length of page */ | |
719 | struct lconv *loc; /* Locale data */ | |
720 | ||
721 | ptr ++; | |
722 | loc = localeconv(); | |
723 | w = _cupsStrScand(ptr, &ptr, loc); | |
724 | ||
725 | if (ptr && *ptr == 'x') | |
726 | { | |
727 | l = _cupsStrScand(ptr + 1, &ptr, loc); | |
728 | ||
729 | if (ptr && (!strcmp(ptr, "in") || !strcmp(ptr, "mm"))) | |
730 | { | |
731 | size = &(cg->pwg_media); | |
732 | ||
733 | if (!strcmp(ptr, "mm")) | |
734 | { | |
735 | size->width = (int)(w * 100); | |
736 | size->length = (int)(l * 100); | |
737 | } | |
738 | else | |
739 | { | |
740 | size->width = (int)(w * 2540); | |
741 | size->length = (int)(l * 2540); | |
742 | } | |
743 | ||
744 | strlcpy(cg->pwg_name, pwg, sizeof(cg->pwg_name)); | |
745 | size->pwg = cg->pwg_name; | |
746 | } | |
747 | } | |
748 | } | |
749 | ||
750 | return (size); | |
54afec33 MS |
751 | } |
752 | ||
753 | ||
754 | /* | |
755 | * '_pwgMediaForSize()' - Get the PWG media name for a given size. | |
756 | */ | |
757 | ||
758 | _pwg_media_t * /* O - PWG media name */ | |
759 | _pwgMediaForSize(int width, /* I - Width in 2540ths */ | |
760 | int length) /* I - Length in 2540ths */ | |
761 | { | |
762 | int i; /* Looping var */ | |
763 | _pwg_media_t *media; /* Current media */ | |
764 | int dw, dl; /* Difference in width and length */ | |
765 | _cups_globals_t *cg = _cupsGlobals(); /* Global data */ | |
766 | ||
767 | ||
768 | /* | |
769 | * Range check input... | |
770 | */ | |
771 | ||
772 | if (width <= 0 || length <= 0) | |
773 | return (NULL); | |
774 | ||
775 | /* | |
776 | * Look for a standard size... | |
777 | */ | |
778 | ||
779 | for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])), | |
780 | media = (_pwg_media_t *)cups_pwg_media; | |
781 | i > 0; | |
782 | i --, media ++) | |
783 | { | |
784 | /* | |
785 | * Adobe uses a size matching algorithm with an epsilon of 5 points, which | |
786 | * is just about 176/2540ths... | |
787 | */ | |
788 | ||
789 | dw = media->width - width; | |
790 | dl = media->length - length; | |
791 | ||
792 | if (dw > -176 && dw < 176 && dl > -176 && dl < 176) | |
793 | return (media); | |
794 | } | |
795 | ||
796 | /* | |
797 | * Not a standard size; convert it to a PWG custom name of the form: | |
798 | * | |
799 | * custom_WIDTHxHEIGHTuu_WIDTHxHEIGHTuu | |
800 | */ | |
801 | ||
802 | _pwgGenerateSize(cg->pwg_name, sizeof(cg->pwg_name), "custom", NULL, width, | |
803 | length); | |
804 | ||
805 | cg->pwg_media.pwg = cg->pwg_name; | |
806 | cg->pwg_media.width = width; | |
807 | cg->pwg_media.length = length; | |
808 | ||
809 | return (&(cg->pwg_media)); | |
810 | } | |
811 | ||
812 | ||
813 | /* | |
814 | * 'pwg_compare_legacy()' - Compare two sizes using the legacy names. | |
815 | */ | |
816 | ||
817 | static int /* O - Result of comparison */ | |
818 | pwg_compare_legacy(_pwg_media_t *a, /* I - First size */ | |
819 | _pwg_media_t *b) /* I - Second size */ | |
820 | { | |
821 | return (strcmp(a->legacy, b->legacy)); | |
822 | } | |
823 | ||
824 | ||
825 | /* | |
826 | * 'pwg_compare_ppd()' - Compare two sizes using the PPD names. | |
827 | */ | |
828 | ||
829 | static int /* O - Result of comparison */ | |
830 | pwg_compare_ppd(_pwg_media_t *a, /* I - First size */ | |
831 | _pwg_media_t *b) /* I - Second size */ | |
832 | { | |
833 | return (strcmp(a->ppd, b->ppd)); | |
834 | } | |
835 | ||
836 | ||
837 | /* | |
838 | * 'pwg_compare_pwg()' - Compare two sizes using the PWG names. | |
839 | */ | |
840 | ||
841 | static int /* O - Result of comparison */ | |
842 | pwg_compare_pwg(_pwg_media_t *a, /* I - First size */ | |
843 | _pwg_media_t *b) /* I - Second size */ | |
844 | { | |
845 | return (strcmp(a->pwg, b->pwg)); | |
846 | } | |
847 | ||
848 | ||
849 | /* | |
850 | * End of "$Id$". | |
851 | */ |