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"
19
hashmap<string,tree> font_conversion ("rule");
21
/******************************************************************************
23
******************************************************************************/
26
font_rule (tree which, tree by) {
27
if ((arity (which) * arity (by) == 0) || is_compound (which[0])) return;
28
if (!font_conversion->contains (which[0]->label))
29
font_conversion (which[0]->label)=
30
tree (TUPLE, tree (ASSOCIATE, which, by));
31
else font_conversion (which[0]->label) << tree (ASSOCIATE, which, by);
34
/******************************************************************************
36
******************************************************************************/
39
matches (tree t, tree which, hashmap<string,tree>& H) {
40
int i, n= arity (which);
41
if (arity (t) != n) return false;
43
if (which[i]->label[0]=='$') H (which[i]->label)= t[i];
44
else if (t[i]!=which[i]) return false;
50
substitute (tree by, hashmap<string,tree>& H) {
51
if (is_atomic (by)) return copy (by);
56
if (is_atomic (by[i]) && starts (by[i]->label, "$"))
57
r[i]= H [by[i]->label];
58
else r[i]= substitute (by[i], H);
65
find_font_bis (display dis, tree t) {
66
// cout << "Find " << t << "\n";
68
if ((arity (t)==0) || is_compound (t[0])) return font ();
70
if (is_tuple (t, "compound"))
71
return compound_font (dis, t (1, N(t)));
73
if (is_tuple (t, "truetype", 3))
74
return tt_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
76
if (is_tuple (t, "unicode", 3))
77
return unicode_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
79
if (is_tuple (t, "x", 3))
80
return x_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
82
if (is_tuple (t, "tex", 3))
83
return tex_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
85
if (is_tuple (t, "tex", 4))
86
return tex_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]),
89
if (is_tuple (t, "cm", 3))
90
return tex_cm_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
92
if (is_tuple (t, "cm", 4))
93
return tex_cm_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]),
96
if (is_tuple (t, "ec", 3))
97
return tex_ec_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
99
if (is_tuple (t, "ec", 4))
100
return tex_ec_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]),
103
if (is_tuple (t, "la", 3))
104
return tex_la_font (dis, as_string (t[1]), as_int (t[2]) * 100,
105
as_int (t[3]), 1000);
107
if (is_tuple (t, "la", 4))
108
return tex_la_font (dis, as_string (t[1]), as_int (t[2]) * 100,
109
as_int (t[3]), as_int (t[4]) * 100);
111
if (is_tuple (t, "adobe", 3))
112
return tex_adobe_font (dis, as_string (t[1]), as_int (t[2]),
115
if (is_tuple (t, "adobe", 4))
116
return tex_adobe_font (dis, as_string (t[1]), as_int (t[2]),
117
as_int (t[3]), as_int (t[4]));
119
if (is_tuple (t, "tex-rubber", 4))
120
return tex_rubber_font (dis, as_string (t[1]), as_string (t[2]),
121
as_int (t[3]), as_int (t[4]));
123
if (is_tuple (t, "tex-rubber", 5))
124
return tex_rubber_font (dis, as_string (t[1]), as_string (t[2]),
125
as_int (t[3]), as_int (t[4]), as_int (t[5]));
127
if (is_tuple (t, "tex-dummy-rubber", 1)) {
128
font fn= find_font (dis, t[1]);
129
if (nil (fn)) return fn;
130
return tex_dummy_rubber_font (fn);
133
if (is_tuple (t, "error", 1)) {
134
font fn= find_font (dis, t[1]);
135
if (nil (fn)) return fn;
136
return error_font (fn);
139
if (is_tuple (t, "math", 4) && is_tuple (t[1]) && is_tuple (t[2])) {
140
font fn= find_font (dis, t[3]);
141
if (nil (fn)) return fn;
142
font error_fn= error_font (find_font (dis, t[4]));
143
if (nil (error_fn)) error_fn= error_font (fn);
144
return math_font (t, fn, error_fn);
147
if (!font_conversion->contains (t[0]->label)) return font ();
149
tree rule= font_conversion [t[0]->label];
151
for (i=0; i<n; i++) {
152
hashmap<string,tree> H ("?");
153
if (matches (t, rule[i][0], H))
154
return find_font (dis, substitute (rule[i][1], H));
161
find_font (display dis, tree t) {
162
bench_start ("find font");
163
font fn= find_font_bis (dis, t);
164
bench_cumul ("find font");
168
/******************************************************************************
170
******************************************************************************/
173
find_font (display dis, string family, string fn_class,
174
string series, string shape, int sz, int dpi)
177
family * "-" * fn_class * "-" *
178
series * "-" * shape * "-" *
179
as_string (sz) * "-" * as_string (dpi);
180
if (font::instances->contains (s)) return font (s);
185
t1[2]= series; t1[3]= shape;
186
t1[4]= as_string (sz); t1[5]= as_string (dpi);
187
font fn= find_font (dis, t1);
189
font::instances (s)= (pointer) fn.rep;
195
t2[1]= fn_class; t2[2]= series;
196
t2[3]= as_string (sz); t2[4]= as_string (dpi);
197
fn= find_font (dis, t2);
199
font::instances (s)= (pointer) fn.rep;
205
t3[1]= fn_class; t3[2]= as_string (sz); t3[3]= as_string (dpi);
206
fn= find_font (dis, t3);
208
font::instances (s)= (pointer) fn.rep;
212
tree panic (TUPLE, "tex", "cmr", as_string (sz), as_string (dpi));
213
fn= find_font (dis, panic);
214
font::instances (s)= (pointer) fn.rep;