2 |
- |
1 |
/* Copyright (C) 1998 Aladdin Enterprises. All rights reserved.
|
|
|
2 |
|
|
|
3 |
This software is provided AS-IS with no warranty, either express or
|
|
|
4 |
implied.
|
|
|
5 |
|
|
|
6 |
This software is distributed under license and may not be copied,
|
|
|
7 |
modified or distributed except as expressly authorized under the terms
|
|
|
8 |
of the license contained in the file LICENSE in this distribution.
|
|
|
9 |
|
|
|
10 |
For more information about licensing, please refer to
|
|
|
11 |
http://www.ghostscript.com/licensing/. For information on
|
|
|
12 |
commercial licensing, go to http://www.artifex.com/licensing/ or
|
|
|
13 |
contact Artifex Software, Inc., 101 Lucas Valley Road #110,
|
|
|
14 |
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
/* $Id: gdevmeds.c,v 1.4 2002/02/21 22:24:51 giles Exp $ */
|
|
|
18 |
/*
|
|
|
19 |
* Media selection support for printer drivers
|
|
|
20 |
*
|
|
|
21 |
* Select from a NULL terminated list of media the smallest medium which is
|
|
|
22 |
* almost equal or larger then the actual imagesize.
|
|
|
23 |
*
|
|
|
24 |
* Written by Ulrich Schmid, uschmid@mail.hh.provi.de.
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
#include "gdevmeds.h"
|
|
|
28 |
|
|
|
29 |
#define CM * 0.01
|
|
|
30 |
#define INCH * 0.0254
|
|
|
31 |
#define TOLERANCE 0.1 CM
|
|
|
32 |
|
|
|
33 |
private const struct {
|
|
|
34 |
const char* name;
|
|
|
35 |
float width;
|
|
|
36 |
float height;
|
|
|
37 |
float priority;
|
|
|
38 |
} media[] = {
|
|
|
39 |
#define X(name, width, height) {name, width, height, 1 / (width * height)}
|
|
|
40 |
X("a0", 83.9611 CM, 118.816 CM),
|
|
|
41 |
X("a1", 59.4078 CM, 83.9611 CM),
|
|
|
42 |
X("a2", 41.9806 CM, 59.4078 CM),
|
|
|
43 |
X("a3", 29.7039 CM, 41.9806 CM),
|
|
|
44 |
X("a4", 20.9903 CM, 29.7039 CM),
|
|
|
45 |
X("a5", 14.8519 CM, 20.9903 CM),
|
|
|
46 |
X("a6", 10.4775 CM, 14.8519 CM),
|
|
|
47 |
X("a7", 7.40833 CM, 10.4775 CM),
|
|
|
48 |
X("a8", 5.22111 CM, 7.40833 CM),
|
|
|
49 |
X("a9", 3.70417 CM, 5.22111 CM),
|
|
|
50 |
X("a10", 2.61056 CM, 3.70417 CM),
|
|
|
51 |
X("archA", 9 INCH, 12 INCH),
|
|
|
52 |
X("archB", 12 INCH, 18 INCH),
|
|
|
53 |
X("archC", 18 INCH, 24 INCH),
|
|
|
54 |
X("archD", 24 INCH, 36 INCH),
|
|
|
55 |
X("archE", 36 INCH, 48 INCH),
|
|
|
56 |
X("b0", 100.048 CM, 141.393 CM),
|
|
|
57 |
X("b1", 70.6967 CM, 100.048 CM),
|
|
|
58 |
X("b2", 50.0239 CM, 70.6967 CM),
|
|
|
59 |
X("b3", 35.3483 CM, 50.0239 CM),
|
|
|
60 |
X("b4", 25.0119 CM, 35.3483 CM),
|
|
|
61 |
X("b5", 17.6742 CM, 25.0119 CM),
|
|
|
62 |
X("flsa", 8.5 INCH, 13 INCH),
|
|
|
63 |
X("flse", 8.5 INCH, 13 INCH),
|
|
|
64 |
X("halfletter", 5.5 INCH, 8.5 INCH),
|
|
|
65 |
X("ledger", 17 INCH, 11 INCH),
|
|
|
66 |
X("legal", 8.5 INCH, 14 INCH),
|
|
|
67 |
X("letter", 8.5 INCH, 11 INCH),
|
|
|
68 |
X("note", 7.5 INCH, 10 INCH),
|
|
|
69 |
X("executive", 7.25 INCH, 10.5 INCH),
|
|
|
70 |
X("com10", 4.125 INCH, 9.5 INCH),
|
|
|
71 |
X("dl", 11 CM, 22 CM),
|
|
|
72 |
X("c5", 16.2 CM, 22.9 CM),
|
|
|
73 |
X("monarch", 3.875 INCH, 7.5 INCH)};
|
|
|
74 |
|
|
|
75 |
int select_medium(gx_device_printer *pdev, const char **available, int default_index)
|
|
|
76 |
{
|
|
|
77 |
int i, j, index = default_index;
|
|
|
78 |
float priority = 0;
|
|
|
79 |
float width = pdev->width / pdev->x_pixels_per_inch INCH;
|
|
|
80 |
float height = pdev->height / pdev->y_pixels_per_inch INCH;
|
|
|
81 |
|
|
|
82 |
for (i = 0; available[i]; i++) {
|
|
|
83 |
for (j = 0; j < sizeof(media) / sizeof(media[0]); j++) {
|
|
|
84 |
if (!strcmp(available[i], media[j].name) &&
|
|
|
85 |
media[j].width + TOLERANCE > width &&
|
|
|
86 |
media[j].height + TOLERANCE > height &&
|
|
|
87 |
media[j].priority > priority) {
|
|
|
88 |
index = i;
|
|
|
89 |
priority = media[j].priority;
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
return index;
|
|
|
94 |
}
|