2 * Copyright (C) 2000, Matias Atria
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 static const DviPaperSpec papers[] = {
27 {"4A0", "1682mm", "2378mm"},
28 {"2A0", "1189mm", "1682mm"},
29 {"A0", "841mm", "1189mm"},
30 {"A1", "594mm", "841mm"},
31 {"A2", "420mm", "594mm"},
32 {"A3", "297mm", "420mm"},
33 {"A4", "210mm", "297mm"},
34 {"A5", "148mm", "210mm"},
35 {"A6", "105mm", "148mm"},
36 {"A7", "74mm", "105mm"},
37 {"A8", "52mm", "74mm"},
38 {"A9", "37mm", "52mm"},
39 {"A10", "26mm", "37mm"},
40 {"B0", "1000mm", "1414mm"},
41 {"B1", "707mm", "1000mm"},
42 {"B2", "500mm", "707mm"},
43 {"B3", "353mm", "500mm"},
44 {"B4", "250mm", "353mm"},
45 {"B5", "176mm", "250mm"},
46 {"B6", "125mm", "176mm"},
47 {"B7", "88mm", "125mm"},
48 {"B8", "62mm", "88mm"},
49 {"B9", "44mm", "62mm"},
50 {"B10", "31mm", "44mm"},
51 {"C0", "917mm", "1297mm"},
52 {"C1", "648mm", "917mm"},
53 {"C2", "458mm", "648mm"},
54 {"C3", "324mm", "458mm"},
55 {"C4", "229mm", "324mm"},
56 {"C5", "162mm", "229mm"},
57 {"C6", "114mm", "162mm"},
58 {"C7", "81mm", "114mm"},
59 {"C8", "57mm", "81mm"},
60 {"C9", "40mm", "57mm"},
61 {"C10", "28mm", "40mm"},
63 {"archA", "9in", "12in"},
64 {"archB", "12in", "18in"},
65 {"archC", "18in", "24in"},
66 {"archD", "24in", "36in"},
67 {"archE", "36in", "48in"},
68 {"executive", "7.5in", "10in"},
69 {"flsa", "8.5in", "13in"},
70 {"flse", "8.5in", "13in"},
71 {"halfletter", "5.5in", "8.5in"},
72 {"letter", "8.5in", "11in"},
73 {"legal", "8.5in", "14in"},
74 {"ledger", "17in", "11in"},
75 {"note", "7.5in", "10in"},
76 {"tabloid", "11in", "17in"},
77 {"statement", "5.5in", "8.5in"},
81 static DviPaperClass str2class(const char *name)
83 if(STRCEQ(name, "ISO"))
84 return MDVI_PAPER_CLASS_ISO;
85 else if(STRCEQ(name, "US"))
86 return MDVI_PAPER_CLASS_US;
87 return MDVI_PAPER_CLASS_CUSTOM;
90 int mdvi_get_paper_size(const char *name, DviPaper *paper)
92 const DviPaperSpec *sp;
97 paper->pclass = MDVI_PAPER_CLASS_CUSTOM;
98 if(sscanf(name, "%lfx%lf%c%c", &a, &b, &c, &d) == 4) {
99 sprintf(buf, "%12.16f%c%c", a, c, d);
100 paper->inches_wide = unit2pix_factor(buf);
101 sprintf(buf, "%12.16f%c%c", b, c, d);
102 paper->inches_tall = unit2pix_factor(buf);
103 paper->name = _("custom");
105 } else if(sscanf(name, "%lf%c%c,%lf%c%c", &a, &c, &d, &b, &e, &f) == 6) {
106 sprintf(buf, "%12.16f%c%c", a, c, d);
107 paper->inches_wide = unit2pix_factor(buf);
108 sprintf(buf, "%12.16f%c%c", b, e, f);
109 paper->inches_tall = unit2pix_factor(buf);
110 paper->name = _("custom");
114 for(sp = &papers[0]; sp->name; sp++) {
115 if(!sp->width || !sp->height) {
116 paper->pclass = str2class(sp->name);
119 if(strcasecmp(sp->name, name) == 0) {
120 paper->inches_wide = unit2pix_factor(sp->width);
121 paper->inches_tall = unit2pix_factor(sp->height);
122 paper->name = sp->name;
129 DviPaperSpec *mdvi_get_paper_specs(DviPaperClass pclass)
133 DviPaperSpec *spec, *ptr;
137 if(pclass == MDVI_PAPER_CLASS_ANY ||
138 pclass == MDVI_PAPER_CLASS_CUSTOM) {
140 count = (sizeof(papers) / sizeof(papers[0])) - 3;
141 } else for(i = 0; papers[i].name; i++) {
142 if(papers[i].width == NULL) {
143 if(str2class(papers[i].name) == pclass)
147 } else if(first >= 0)
150 ptr = spec = xnalloc(DviPaperSpec, count + 1);
151 for(i = first; papers[i].name&& count > 0; i++) {
152 if(papers[i].width) {
153 ptr->name = papers[i].name;
154 ptr->width = papers[i].width;
155 ptr->height = papers[i].height;
167 void mdvi_free_paper_specs(DviPaperSpec *spec)