2
/******************************************************************************
3
* MODULE : find_font.cpp
4
* DESCRIPTION: decoding font names
5
* COPYRIGHT : (C) 1999 Joris van der Hoeven
6
*******************************************************************************
7
* This software falls under the GNU general public license and comes WITHOUT
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11
******************************************************************************/
13
#include "analyze.hpp"
16
#include "hashmap.hpp"
18
hashmap<string,tree> font_conversion ("rule");
20
/******************************************************************************
22
******************************************************************************/
25
font_rule (tree which, tree by) {
26
if ((arity (which) * arity (by) == 0) || is_compound (which[0])) return;
27
if (!font_conversion->contains (which[0]->label))
28
font_conversion (which[0]->label)=
29
tree (TUPLE, tree (ASSOCIATE, which, by));
30
else font_conversion (which[0]->label) << tree (ASSOCIATE, which, by);
33
/******************************************************************************
35
******************************************************************************/
38
matches (tree t, tree which, hashmap<string,tree>& H) {
39
int i, n= arity (which);
40
if (arity (t) != n) return false;
42
if (which[i]->label[0]=='$') H (which[i]->label)= t[i];
43
else if (t[i]!=which[i]) return false;
49
substitute (tree by, hashmap<string,tree>& H) {
50
if (is_atomic (by)) return copy (by);
55
if (is_atomic (by[i]) && starts (by[i]->label, "$"))
56
r[i]= H [by[i]->label];
57
else r[i]= substitute (by[i], H);
64
find_font (display dis, tree t) {
65
// cout << "Find " << t << "\n";
67
if ((arity (t)==0) || is_compound (t[0])) return font ();
69
if (is_tuple (t, "truetype", 3))
70
return tt_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
72
if (is_tuple (t, "ps", 3))
73
return ps_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
75
if (is_tuple (t, "tex", 3))
76
return tex_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
78
if (is_tuple (t, "tex", 4))
79
return tex_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]),
82
if (is_tuple (t, "cm", 3))
83
return tex_cm_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
85
if (is_tuple (t, "cm", 4))
86
return tex_cm_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]),
89
if (is_tuple (t, "ec", 3))
90
return tex_ec_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
92
if (is_tuple (t, "ec", 4))
93
return tex_ec_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]),
96
if (is_tuple (t, "la", 3))
97
return tex_la_font (dis, as_string (t[1]), as_int (t[2]) * 100,
100
if (is_tuple (t, "la", 4))
101
return tex_la_font (dis, as_string (t[1]), as_int (t[2]) * 100,
102
as_int (t[3]), as_int (t[4]) * 100);
104
if (is_tuple (t, "adobe", 3))
105
return tex_adobe_font (dis, as_string (t[1]), as_int (t[2]),
108
if (is_tuple (t, "adobe", 4))
109
return tex_adobe_font (dis, as_string (t[1]), as_int (t[2]),
110
as_int (t[3]), as_int (t[4]));
112
if (is_tuple (t, "tex-rubber", 4))
113
return tex_rubber_font (dis, as_string (t[1]), as_string (t[2]),
114
as_int (t[3]), as_int (t[4]));
116
if (is_tuple (t, "tex-rubber", 5))
117
return tex_rubber_font (dis, as_string (t[1]), as_string (t[2]),
118
as_int (t[3]), as_int (t[4]), as_int (t[5]));
120
if (is_tuple (t, "tex-dummy-rubber", 1)) {
121
font fn= find_font (dis, t[1]);
122
if (nil (fn)) return fn;
123
return tex_dummy_rubber_font (fn);
126
if (is_tuple (t, "error", 1)) {
127
font fn= find_font (dis, t[1]);
128
if (nil (fn)) return fn;
129
return error_font (fn);
132
if (is_tuple (t, "numeric", 1)) {
133
font fn= find_font (dis, t[1]);
134
if (nil (fn)) return fn;
135
return subfont (fn, num_enc ());
138
if (is_tuple (t, "capital", 1)) {
139
font fn= find_font (dis, t[1]);
140
if (nil (fn)) return fn;
141
return subfont (fn, capital_enc ());
144
if (is_tuple (t, "alpha", 1)) {
145
font fn= find_font (dis, t[1]);
146
if (nil (fn)) return fn;
147
return subfont (fn, alpha_enc ());
150
if (is_tuple (t, "alpha-numeric", 1)) {
151
font fn= find_font (dis, t[1]);
152
if (nil (fn)) return fn;
153
return subfont (fn, alpha_num_enc ());
156
if (is_tuple (t, "join", 2)) {
157
font fn1= find_font (dis, t[1]);
158
font fn2= find_font (dis, t[2]);
159
if (nil (fn1) || nil (fn2)) return fn1;
160
return join (fn1, fn2);
163
if (is_tuple (t, "math", 4) && is_tuple (t[1]) && is_tuple (t[2])) {
164
font fn= find_font (dis, t[3]);
165
if (nil (fn)) return fn;
166
font error_fn= error_font (find_font (dis, t[4]));
167
if (nil (error_fn)) error_fn= error_font (fn);
168
return math_font (t, fn, error_fn);
171
if (!font_conversion->contains (t[0]->label)) return font ();
173
tree rule= font_conversion [t[0]->label];
175
for (i=0; i<n; i++) {
176
hashmap<string,tree> H ("?");
177
if (matches (t, rule[i][0], H))
178
return find_font (dis, substitute (rule[i][1], H));
184
/******************************************************************************
186
******************************************************************************/
189
find_font (display dis, string family, string fn_class,
190
string series, string shape, int sz, int dpi)
193
family * "-" * fn_class * "-" *
194
series * "-" * shape * "-" *
195
as_string (sz) * "-" * as_string (dpi);
196
if (font::instances->contains (s)) return font (s);
201
t1[2]= series; t1[3]= shape;
202
t1[4]= as_string (sz); t1[5]= as_string (dpi);
203
font fn= find_font (dis, t1);
205
font::instances (s)= (pointer) fn.rep;
211
t2[1]= fn_class; t2[2]= series;
212
t2[3]= as_string (sz); t2[4]= as_string (dpi);
213
fn= find_font (dis, t2);
215
font::instances (s)= (pointer) fn.rep;
221
t3[1]= fn_class; t3[2]= as_string (sz); t3[3]= as_string (dpi);
222
fn= find_font (dis, t3);
224
font::instances (s)= (pointer) fn.rep;
228
tree panic (TUPLE, "tex", "cmr", as_string (sz), as_string (dpi));
229
fn= find_font (dis, panic);
230
font::instances (s)= (pointer) fn.rep;