~ubuntu-branches/ubuntu/quantal/texmacs/quantal

« back to all changes in this revision

Viewing changes to src/Resource/Fonts/find_font.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA, Kamaraju Kusumanchi, kohda
  • Date: 2008-04-06 15:11:41 UTC
  • mfrom: (1.1.7 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080406151141-w0sg20jnv86mlt6f
Tags: 1:1.0.6.14-1
[Kamaraju Kusumanchi <kamaraju@gmail.com>]
* New upstream release
* 01_american.dpatch is updated
* Since thread support in guile-1.8 is now disabled, the segmentation faults
  should not arise anymore. More info at #439923. (Closes: #450499, #458685)
[kohda]
* This version fixed menu problem.  (Closes: #447083)
* Reverted orig.tar.gz to the upstream tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
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
 
******************************************************************************/
12
 
 
13
 
#include "analyze.hpp"
14
 
#include "tree.hpp"
15
 
#include "font.hpp"
16
 
#include "hashmap.hpp"
17
 
#include "timer.hpp"
18
 
 
19
 
hashmap<string,tree> font_conversion ("rule");
20
 
 
21
 
/******************************************************************************
22
 
* Declare a new rule
23
 
******************************************************************************/
24
 
 
25
 
void
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);
32
 
}
33
 
 
34
 
/******************************************************************************
35
 
* Find a font
36
 
******************************************************************************/
37
 
 
38
 
static bool
39
 
matches (tree t, tree which, hashmap<string,tree>& H) {
40
 
  int i, n= arity (which);
41
 
  if (arity (t) != n) return false;
42
 
  for (i=0; i<n; i++) {
43
 
    if (which[i]->label[0]=='$') H (which[i]->label)= t[i];
44
 
    else if (t[i]!=which[i]) return false;
45
 
  }
46
 
  return true;
47
 
}
48
 
 
49
 
static tree
50
 
substitute (tree by, hashmap<string,tree>& H) {
51
 
  if (is_atomic (by)) return copy (by);
52
 
  else {
53
 
    int i, n= N(by);
54
 
    tree r (by, n);
55
 
    for (i=0; i<n; i++) {
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);
59
 
    }
60
 
    return r;
61
 
  }
62
 
}
63
 
 
64
 
font
65
 
find_font_bis (display dis, tree t) {
66
 
  // cout << "Find " << t << "\n";
67
 
 
68
 
  if ((arity (t)==0) || is_compound (t[0])) return font ();
69
 
 
70
 
  if (is_tuple (t, "compound"))
71
 
    return compound_font (dis, t (1, N(t)));
72
 
 
73
 
  if (is_tuple (t, "truetype", 3))
74
 
    return tt_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
75
 
 
76
 
  if (is_tuple (t, "unicode", 3))
77
 
    return unicode_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
78
 
 
79
 
  if (is_tuple (t, "x", 3))
80
 
    return x_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
81
 
 
82
 
  if (is_tuple (t, "tex", 3))
83
 
    return tex_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]));
84
 
 
85
 
  if (is_tuple (t, "tex", 4))
86
 
    return tex_font (dis, as_string (t[1]), as_int (t[2]), as_int (t[3]),
87
 
                     as_int (t[4]));
88
 
 
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]));
91
 
 
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]),
94
 
                        as_int (t[4]));
95
 
 
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]));
98
 
 
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]),
101
 
                        as_int (t[4]));
102
 
  
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);
106
 
 
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);
110
 
 
111
 
  if (is_tuple (t, "adobe", 3))
112
 
    return tex_adobe_font (dis, as_string (t[1]), as_int (t[2]),
113
 
                           as_int (t[3]));
114
 
 
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]));
118
 
 
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]));
122
 
 
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]));
126
 
 
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);
131
 
  }
132
 
  
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);
137
 
  }
138
 
 
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);
145
 
  }
146
 
 
147
 
  if (!font_conversion->contains (t[0]->label)) return font ();
148
 
 
149
 
  tree rule= font_conversion [t[0]->label];
150
 
  int i, n= N(rule);
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));
155
 
  }
156
 
 
157
 
  return font ();
158
 
}
159
 
 
160
 
font
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");
165
 
  return fn;
166
 
}
167
 
 
168
 
/******************************************************************************
169
 
* User interface
170
 
******************************************************************************/
171
 
 
172
 
font
173
 
find_font (display dis, string family, string fn_class,
174
 
           string series, string shape, int sz, int dpi)
175
 
{
176
 
  string s=
177
 
    family * "-" * fn_class * "-" *
178
 
    series * "-" * shape * "-" *
179
 
    as_string (sz) * "-" * as_string (dpi);
180
 
  if (font::instances->contains (s)) return font (s);
181
 
 
182
 
  tree t1 (TUPLE, 6);
183
 
  t1[0]= family;
184
 
  t1[1]= fn_class;
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);
188
 
  if (!nil (fn)) {
189
 
    font::instances (s)= (pointer) fn.rep;
190
 
    return fn;
191
 
  }
192
 
 
193
 
  tree t2 (TUPLE, 5);
194
 
  t2[0]= family;
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);
198
 
  if (!nil (fn)) {
199
 
    font::instances (s)= (pointer) fn.rep;
200
 
    return fn;
201
 
  }
202
 
 
203
 
  tree t3 (TUPLE, 4);
204
 
  t3[0]= family;
205
 
  t3[1]= fn_class; t3[2]= as_string (sz); t3[3]= as_string (dpi);
206
 
  fn= find_font (dis, t3);
207
 
  if (!nil (fn)) {
208
 
    font::instances (s)= (pointer) fn.rep;
209
 
    return fn;
210
 
  }
211
 
 
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;
215
 
  return fn;
216
 
}