~ubuntu-branches/ubuntu/intrepid/luatex/intrepid

« back to all changes in this revision

Viewing changes to src/texk/web2c/luatexdir/font/texfont.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2008-07-07 11:01:13 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080707110113-1y7lam37zbbb7bbt
Tags: 0.28.0-1
* two new upstream releases, see the respective ANNOUCE files
* add luasocket license statement to debian/copyright
* activate the pdfluatex format
* prepare for latex based formats
  - add the ini files from TeX Live
  - add debian/formats file
  - adjust dh_installtex incantation
  the problem is that luatex dies when loading ukrhypmp.tex from 
  texlive-lang-cyrillic, but we don't want to conflict with it by now.
* policy 3.8.0, rename README.Debian-source to README.source, and add
  notes about quilt usage
* disable patch fix-pwd-inclusion (it was from svn)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Copyright (c) 1996-2006 Taco Hoekwater <taco@luatex.org>
3
 
  
4
 
  This file is part of LuaTeX.
5
 
  
6
 
  LuaTeX is free software; you can redistribute it and/or modify
7
 
  it under the terms of the GNU General Public License as published by
8
 
  the Free Software Foundation; either version 2 of the License, or
9
 
  (at your option) any later version.
10
 
 
11
 
  LuaTeX is distributed in the hope that it will be useful,
12
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
  GNU General Public License for more details.
15
 
  
16
 
  You should have received a copy of the GNU General Public License
17
 
  along with LuaTeX; if not, write to the Free Software
18
 
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
 
20
 
  $Id: texfont.c 1013 2008-02-14 00:09:02Z oneiros $ */
 
1
/* texfont.c Main font API implementation for the pascal parts
 
2
   
 
3
   Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
 
4
 
 
5
   This file is part of LuaTeX.
 
6
 
 
7
   LuaTeX is free software; you can redistribute it and/or modify it under
 
8
   the terms of the GNU General Public License as published by the Free
 
9
   Software Foundation; either version 2 of the License, or (at your
 
10
   option) any later version.
 
11
 
 
12
   LuaTeX is distributed in the hope that it will be useful, but WITHOUT
 
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
14
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
15
   License for more details.
 
16
 
 
17
   You should have received a copy of the GNU General Public License along
 
18
   with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
21
19
 
22
20
/* Main font API implementation for the pascal parts */
23
21
 
36
34
#include "ptexlib.h"
37
35
#include "luatex-api.h"
38
36
 
 
37
static const char _svn_version[] =
 
38
    "$Id: texfont.c 1309 2008-06-06 16:38:07Z taco $ $URL: http://scm.foundry.supelec.fr/svn/luatex/tags/beta-0.28.0/src/texk/web2c/luatexdir/font/texfont.c $";
 
39
 
39
40
#define proper_char_index(c) (c<=font_ec(f) && c>=font_bc(f))
40
41
#define dxfree(a,b) { xfree(a); a = b ; }
41
42
#define do_realloc(a,b,d)    a = xrealloc(a,(b)*sizeof(d))
45
46
static integer font_arr_max = 0;
46
47
static integer font_id_maxval = 0;
47
48
 
48
 
static void grow_font_table (integer id) {
49
 
  int j;
50
 
  if (id>=font_arr_max) {
51
 
    font_bytes += (font_arr_max-id+8)*sizeof(texfont *);
52
 
    font_tables = xrealloc(font_tables,(id+8)*sizeof(texfont *));
53
 
    j = 8;
54
 
    while (j--) {
55
 
      font_tables[id+j] = NULL;
56
 
    }
57
 
    font_arr_max = id+8;
58
 
  }
59
 
}
60
 
 
61
 
integer
62
 
new_font_id (void) {
63
 
  int i;
64
 
  for (i=0;i<font_arr_max;i++) {
65
 
    if (font_tables[i]==NULL) {
66
 
      break;
67
 
    }
68
 
  }
69
 
  if (i>=font_arr_max)
70
 
    grow_font_table (i);
71
 
  if (i>font_id_maxval)
 
49
static void grow_font_table(integer id)
 
50
{
 
51
    int j;
 
52
    if (id >= font_arr_max) {
 
53
        font_bytes += (font_arr_max - id + 8) * sizeof(texfont *);
 
54
        font_tables = xrealloc(font_tables, (id + 8) * sizeof(texfont *));
 
55
        j = 8;
 
56
        while (j--) {
 
57
            font_tables[id + j] = NULL;
 
58
        }
 
59
        font_arr_max = id + 8;
 
60
    }
 
61
}
 
62
 
 
63
integer new_font_id(void)
 
64
{
 
65
    int i;
 
66
    for (i = 0; i < font_arr_max; i++) {
 
67
        if (font_tables[i] == NULL) {
 
68
            break;
 
69
        }
 
70
    }
 
71
    if (i >= font_arr_max)
 
72
        grow_font_table(i);
 
73
    if (i > font_id_maxval)
 
74
        font_id_maxval = i;
 
75
    return i;
 
76
}
 
77
 
 
78
integer max_font_id(void)
 
79
{
 
80
    return font_id_maxval;
 
81
}
 
82
 
 
83
void set_max_font_id(integer i)
 
84
{
72
85
    font_id_maxval = i;
73
 
  return i;
74
 
}
75
 
 
76
 
integer
77
 
max_font_id (void) {
78
 
  return font_id_maxval;
79
 
}
80
 
 
81
 
void
82
 
set_max_font_id (integer i) {
83
 
  font_id_maxval = i;
84
 
}
85
 
 
86
 
integer
87
 
new_font (void) {
88
 
  int k;
89
 
  int id;
90
 
  charinfo *ci;
91
 
  id = new_font_id();
92
 
  font_bytes += sizeof(texfont);
93
 
  /* most stuff is zero */
94
 
  font_tables[id] = xcalloc(1,sizeof(texfont));
95
 
  font_tables[id]->_font_name = NULL;   
96
 
  font_tables[id]->_font_area = NULL;   
97
 
  font_tables[id]->_font_filename = NULL;   
98
 
  font_tables[id]->_font_fullname = NULL;   
99
 
  font_tables[id]->_font_encodingname = NULL;   
100
 
  font_tables[id]->_font_cidregistry = NULL;   
101
 
  font_tables[id]->_font_cidordering = NULL;   
102
 
  font_tables[id]->_left_boundary = NULL;   
103
 
  font_tables[id]->_right_boundary = NULL;   
104
 
  font_tables[id]->_param_base = NULL;   
105
 
  
106
 
  set_font_bc(id, 1); /* ec = 0 */
107
 
  set_hyphen_char(id,'-');
108
 
  set_skew_char(id,-1);
109
 
 
110
 
  /* allocate eight values including 0 */
111
 
  set_font_params(id,7);
112
 
  for (k=0;k<=7;k++) { 
113
 
    set_font_param(id,k,0);
114
 
  }
115
 
  /* character info zero is reserved for notdef */  
116
 
  font_tables[id]->characters = new_sa_tree(1, 0); /* stack size 1, default item value 0 */
117
 
 
118
 
  ci = xcalloc(1,sizeof(charinfo));
119
 
  set_charinfo_name(ci,xstrdup(".notdef"));
120
 
  font_tables[id]->charinfo = ci;
121
 
  font_tables[id]->charinfo_cache = NULL;
122
 
 
123
 
  return id;
 
86
}
 
87
 
 
88
integer new_font(void)
 
89
{
 
90
    int k;
 
91
    int id;
 
92
    charinfo *ci;
 
93
    id = new_font_id();
 
94
    font_bytes += sizeof(texfont);
 
95
    /* most stuff is zero */
 
96
    font_tables[id] = xcalloc(1, sizeof(texfont));
 
97
    font_tables[id]->_font_name = NULL;
 
98
    font_tables[id]->_font_area = NULL;
 
99
    font_tables[id]->_font_filename = NULL;
 
100
    font_tables[id]->_font_fullname = NULL;
 
101
    font_tables[id]->_font_encodingname = NULL;
 
102
    font_tables[id]->_font_cidregistry = NULL;
 
103
    font_tables[id]->_font_cidordering = NULL;
 
104
    font_tables[id]->_left_boundary = NULL;
 
105
    font_tables[id]->_right_boundary = NULL;
 
106
    font_tables[id]->_param_base = NULL;
 
107
 
 
108
    set_font_bc(id, 1);         /* ec = 0 */
 
109
    set_hyphen_char(id, '-');
 
110
    set_skew_char(id, -1);
 
111
 
 
112
    /* allocate eight values including 0 */
 
113
    set_font_params(id, 7);
 
114
    for (k = 0; k <= 7; k++) {
 
115
        set_font_param(id, k, 0);
 
116
    }
 
117
    /* character info zero is reserved for notdef */
 
118
    font_tables[id]->characters = new_sa_tree(1, 0);    /* stack size 1, default item value 0 */
 
119
 
 
120
    ci = xcalloc(1, sizeof(charinfo));
 
121
    set_charinfo_name(ci, xstrdup(".notdef"));
 
122
    font_tables[id]->charinfo = ci;
 
123
    font_tables[id]->charinfo_cache = NULL;
 
124
 
 
125
    return id;
124
126
}
125
127
 
126
128
#define Charinfo_count(a) font_tables[a]->charinfo_count
127
129
#define Charinfo_size(a) font_tables[a]->charinfo_size
128
130
#define Characters(a) font_tables[a]->characters
129
131
 
130
 
charinfo *
131
 
get_charinfo (internal_font_number f, integer c) { 
132
 
  sa_tree_item glyph;
133
 
  charinfo *ci;
134
 
  if (proper_char_index(c)) {
135
 
    glyph = get_sa_item(Characters(f), c);
136
 
    if (!glyph) {
137
 
      /* this could be optimized using controlled growth */
138
 
      font_bytes += sizeof(charinfo);
139
 
      glyph = ++font_tables[f]->charinfo_count;
140
 
      do_realloc(font_tables[f]->charinfo, (glyph+1), charinfo); 
141
 
      memset (&(font_tables[f]->charinfo[glyph]),0,sizeof(charinfo));
142
 
          font_tables[f]->charinfo[glyph].ef = 1000; /* init */
143
 
      font_tables[f]->charinfo_size = glyph;
144
 
      set_sa_item(font_tables[f]->characters, c, glyph, 1); /* 1= global */
145
 
    }
146
 
    return &(font_tables[f]->charinfo[glyph]);
147
 
  } else if (c == left_boundarychar) {
148
 
    if (left_boundary(f)==NULL) {
149
 
      ci = xcalloc(1,sizeof(charinfo));
150
 
      font_bytes += sizeof(charinfo);
151
 
      set_left_boundary(f,ci);
152
 
    }
153
 
    return left_boundary(f);
154
 
  } else if (c == right_boundarychar) {
155
 
    if (right_boundary(f)==NULL) {
156
 
      ci = xcalloc(1,sizeof(charinfo));
157
 
      font_bytes += sizeof(charinfo);
158
 
      set_right_boundary(f,ci);
159
 
    }
160
 
    return right_boundary(f);
161
 
  }
162
 
  return &(font_tables[f]->charinfo[0]);
163
 
}
164
 
 
165
 
void
166
 
set_charinfo (internal_font_number f, integer c, charinfo *ci) { 
167
 
  sa_tree_item glyph;
168
 
  if (proper_char_index(c)) {
169
 
    glyph = get_sa_item(Characters(f), c);
170
 
    if (glyph) {
171
 
      font_tables[f]->charinfo[glyph] = *ci;
172
 
    } else {
173
 
      pdftex_fail("font: %s","character insertion failed");
174
 
    }
175
 
  } else if (c == left_boundarychar) {
176
 
    set_left_boundary(f,ci);
177
 
  } else if (c == right_boundarychar) {
178
 
    set_right_boundary(f,ci);
179
 
  }
180
 
}
181
 
 
182
 
 
183
 
 
184
 
charinfo *
185
 
copy_charinfo (charinfo *ci) {
186
 
  int x;
187
 
  kerninfo *kern;
188
 
  liginfo *lig;
189
 
  real_eight_bits *packet;
190
 
  charinfo *co = NULL;
191
 
  if (ci==NULL)
192
 
    return NULL;
193
 
  co = xmalloc(sizeof(charinfo));
194
 
  memcpy(co,ci,sizeof(charinfo));
195
 
  set_charinfo_used(co,false);
196
 
  co->name = NULL;
197
 
  co->tounicode = NULL;
198
 
  co->packets = NULL;
199
 
  co->ligatures = NULL;
200
 
  co->kerns = NULL;
201
 
  co->extensible = NULL;
202
 
  if (ci->name!=NULL) {
203
 
    co->name = xstrdup(ci->name);
204
 
  }
205
 
  if (ci->tounicode!=NULL) {
206
 
    co->tounicode = xstrdup(ci->tounicode);
207
 
  }
208
 
  /* kerns */
209
 
  if ((kern = get_charinfo_kerns(ci)) != NULL) {
210
 
    x = 0;
211
 
    while (!kern_end(kern[x])) { x++; } x++;
212
 
    co->kerns = xmalloc (x*sizeof(kerninfo));
213
 
    memcpy(co->kerns,ci->kerns,(x*sizeof(kerninfo)));
214
 
  } 
215
 
  /* ligs */
216
 
  if ((lig = get_charinfo_ligatures(ci)) != NULL) {
217
 
    x = 0;
218
 
    while (!lig_end(lig[x])) { x++; } x++;
219
 
    co->ligatures = xmalloc (x*sizeof(liginfo));
220
 
    memcpy(co->ligatures,ci->ligatures,(x*sizeof(liginfo)));
221
 
  } 
222
 
  /* packets */
223
 
  if ((packet = get_charinfo_packets(ci)) != NULL) {
224
 
    x = vf_packet_bytes(ci);
225
 
    co->packets = xmalloc (x);
226
 
    memcpy(co->packets,ci->packets,x);
227
 
  }
228
 
  if (get_charinfo_tag(ci)==ext_tag) {
229
 
    int top, bot, rep, mid;
230
 
    top = get_charinfo_extensible(ci,EXT_TOP);
231
 
    bot = get_charinfo_extensible(ci,EXT_BOT);
232
 
    mid = get_charinfo_extensible(ci,EXT_MID);
233
 
    rep = get_charinfo_extensible(ci,EXT_REP);
234
 
    set_charinfo_extensible(co,top,bot,mid,rep);
235
 
  }
236
 
  return co;
 
132
charinfo *get_charinfo(internal_font_number f, integer c)
 
133
{
 
134
    sa_tree_item glyph;
 
135
    charinfo *ci;
 
136
    if (proper_char_index(c)) {
 
137
        glyph = get_sa_item(Characters(f), c);
 
138
        if (!glyph) {
 
139
            /* this could be optimized using controlled growth */
 
140
            font_bytes += sizeof(charinfo);
 
141
            glyph = ++font_tables[f]->charinfo_count;
 
142
            do_realloc(font_tables[f]->charinfo, (glyph + 1), charinfo);
 
143
            memset(&(font_tables[f]->charinfo[glyph]), 0, sizeof(charinfo));
 
144
            font_tables[f]->charinfo[glyph].ef = 1000;  /* init */
 
145
            font_tables[f]->charinfo_size = glyph;
 
146
            set_sa_item(font_tables[f]->characters, c, glyph, 1);       /* 1= global */
 
147
        }
 
148
        return &(font_tables[f]->charinfo[glyph]);
 
149
    } else if (c == left_boundarychar) {
 
150
        if (left_boundary(f) == NULL) {
 
151
            ci = xcalloc(1, sizeof(charinfo));
 
152
            font_bytes += sizeof(charinfo);
 
153
            set_left_boundary(f, ci);
 
154
        }
 
155
        return left_boundary(f);
 
156
    } else if (c == right_boundarychar) {
 
157
        if (right_boundary(f) == NULL) {
 
158
            ci = xcalloc(1, sizeof(charinfo));
 
159
            font_bytes += sizeof(charinfo);
 
160
            set_right_boundary(f, ci);
 
161
        }
 
162
        return right_boundary(f);
 
163
    }
 
164
    return &(font_tables[f]->charinfo[0]);
 
165
}
 
166
 
 
167
void set_charinfo(internal_font_number f, integer c, charinfo * ci)
 
168
{
 
169
    sa_tree_item glyph;
 
170
    if (proper_char_index(c)) {
 
171
        glyph = get_sa_item(Characters(f), c);
 
172
        if (glyph) {
 
173
            font_tables[f]->charinfo[glyph] = *ci;
 
174
        } else {
 
175
            pdftex_fail("font: %s", "character insertion failed");
 
176
        }
 
177
    } else if (c == left_boundarychar) {
 
178
        set_left_boundary(f, ci);
 
179
    } else if (c == right_boundarychar) {
 
180
        set_right_boundary(f, ci);
 
181
    }
 
182
}
 
183
 
 
184
 
 
185
 
 
186
charinfo *copy_charinfo(charinfo * ci)
 
187
{
 
188
    int x;
 
189
    kerninfo *kern;
 
190
    liginfo *lig;
 
191
    real_eight_bits *packet;
 
192
    charinfo *co = NULL;
 
193
    if (ci == NULL)
 
194
        return NULL;
 
195
    co = xmalloc(sizeof(charinfo));
 
196
    memcpy(co, ci, sizeof(charinfo));
 
197
    set_charinfo_used(co, false);
 
198
    co->name = NULL;
 
199
    co->tounicode = NULL;
 
200
    co->packets = NULL;
 
201
    co->ligatures = NULL;
 
202
    co->kerns = NULL;
 
203
    co->extensible = NULL;
 
204
    if (ci->name != NULL) {
 
205
        co->name = xstrdup(ci->name);
 
206
    }
 
207
    if (ci->tounicode != NULL) {
 
208
        co->tounicode = xstrdup(ci->tounicode);
 
209
    }
 
210
    /* kerns */
 
211
    if ((kern = get_charinfo_kerns(ci)) != NULL) {
 
212
        x = 0;
 
213
        while (!kern_end(kern[x])) {
 
214
            x++;
 
215
        }
 
216
        x++;
 
217
        co->kerns = xmalloc(x * sizeof(kerninfo));
 
218
        memcpy(co->kerns, ci->kerns, (x * sizeof(kerninfo)));
 
219
    }
 
220
    /* ligs */
 
221
    if ((lig = get_charinfo_ligatures(ci)) != NULL) {
 
222
        x = 0;
 
223
        while (!lig_end(lig[x])) {
 
224
            x++;
 
225
        }
 
226
        x++;
 
227
        co->ligatures = xmalloc(x * sizeof(liginfo));
 
228
        memcpy(co->ligatures, ci->ligatures, (x * sizeof(liginfo)));
 
229
    }
 
230
    /* packets */
 
231
    if ((packet = get_charinfo_packets(ci)) != NULL) {
 
232
        x = vf_packet_bytes(ci);
 
233
        co->packets = xmalloc(x);
 
234
        memcpy(co->packets, ci->packets, x);
 
235
    }
 
236
    if (get_charinfo_tag(ci) == ext_tag) {
 
237
        int top, bot, rep, mid;
 
238
        top = get_charinfo_extensible(ci, EXT_TOP);
 
239
        bot = get_charinfo_extensible(ci, EXT_BOT);
 
240
        mid = get_charinfo_extensible(ci, EXT_MID);
 
241
        rep = get_charinfo_extensible(ci, EXT_REP);
 
242
        set_charinfo_extensible(co, top, bot, mid, rep);
 
243
    }
 
244
    return co;
237
245
}
238
246
 
239
247
#if 0
240
 
int 
241
 
find_charinfo_id (internal_font_number f, integer c) {
242
 
  register int g=0;
243
 
  if (font_tables[f]->charinfo_cache==NULL) {
244
 
    int i  = (font_ec(f)+1)*sizeof(int);
245
 
    font_tables[f]->charinfo_cache = xmalloc(i);
246
 
    memset(font_tables[f]->charinfo_cache,0,i);
247
 
  } else {
248
 
    g = font_tables[f]->charinfo_cache[c];
249
 
  }
250
 
  if (g==0) {
251
 
    g = get_sa_item(font_tables[f]->characters, c);
252
 
    font_tables[f]->charinfo_cache[c] = g;
253
 
  }
254
 
  return g;
 
248
int find_charinfo_id(internal_font_number f, integer c)
 
249
{
 
250
    register int g = 0;
 
251
    if (font_tables[f]->charinfo_cache == NULL) {
 
252
        int i = (font_ec(f) + 1) * sizeof(int);
 
253
        font_tables[f]->charinfo_cache = xmalloc(i);
 
254
        memset(font_tables[f]->charinfo_cache, 0, i);
 
255
    } else {
 
256
        g = font_tables[f]->charinfo_cache[c];
 
257
    }
 
258
    if (g == 0) {
 
259
        g = get_sa_item(font_tables[f]->characters, c);
 
260
        font_tables[f]->charinfo_cache[c] = g;
 
261
    }
 
262
    return g;
255
263
}
256
264
#else
257
 
#define find_charinfo_id(f,c) get_sa_item(font_tables[f]->characters,c)
 
265
#  define find_charinfo_id(f,c) get_sa_item(font_tables[f]->characters,c)
258
266
#endif
259
267
 
260
268
 
261
 
charinfo *
262
 
char_info (internal_font_number f, integer c) {
263
 
  if (f>font_id_maxval)
264
 
        return 0;
265
 
  if (proper_char_index(c)) {
266
 
    register int glyph = find_charinfo_id(f,c);
267
 
    return &(font_tables[f]->charinfo[glyph]);
268
 
  } else if (c == left_boundarychar && left_boundary(f)!=NULL) {
269
 
    return left_boundary(f);
270
 
  } else if (c == right_boundarychar && right_boundary(f)!=NULL) {
271
 
    return right_boundary(f);
272
 
  }
273
 
  return &(font_tables[f]->charinfo[0]);
274
 
}
275
 
 
276
 
charinfo_short
277
 
char_info_short (internal_font_number f, integer c) {
278
 
  charinfo_short s;
279
 
  charinfo *i;
280
 
  i = char_info(f,c);
281
 
  s.ci_wd = i->width;
282
 
  s.ci_dp = i->depth;
283
 
  s.ci_ht = i->height;
284
 
  return s;
285
 
}
286
 
 
287
 
integer
288
 
char_exists (internal_font_number f, integer c) {
289
 
  if (f>font_id_maxval)
290
 
        return 0;
291
 
  if (proper_char_index(c)) {
292
 
    return find_charinfo_id(f,c);
293
 
  } else if ((c == left_boundarychar) && has_left_boundary(f)) {
294
 
    return 1;
295
 
  } else if ((c == right_boundarychar) && has_right_boundary(f)) {
296
 
    return 1;
297
 
  }
298
 
  return 0;
299
 
}
300
 
 
301
 
int
302
 
lua_char_exists_callback (internal_font_number f, integer c) {
303
 
  integer callback_id ; 
304
 
  lua_State *L = Luas[0];
305
 
  int ret=0;
306
 
  callback_id = callback_defined(char_exists_callback);
307
 
  if (callback_id!=0) {
308
 
        lua_rawgeti(L,LUA_REGISTRYINDEX,callback_callbacks_id);
309
 
        lua_rawgeti(L,-1, callback_id);
310
 
        if (!lua_isfunction(L,-1)) {
311
 
          lua_pop(L,2);
312
 
          return 0;
313
 
        }
314
 
        lua_pushnumber(L,f);
315
 
        lua_pushnumber(L,c);
316
 
        if (lua_pcall(L,2,1,0) != 0) { /* two args, 1 result */
317
 
          fprintf(stdout,"error: %s\n",lua_tostring(L,-1));
318
 
          lua_pop(L,2);
319
 
          error();
320
 
        } else {
321
 
          ret = lua_toboolean(L,-1);
322
 
        }
323
 
  }
324
 
  return ret;
325
 
}
326
 
 
327
 
 
328
 
void set_charinfo_width       (charinfo *ci, scaled val)          { ci->width = val;     }
329
 
void set_charinfo_height      (charinfo *ci, scaled val)          { ci->height = val;    }
330
 
void set_charinfo_depth       (charinfo *ci, scaled val)          { ci->depth = val;     }
331
 
void set_charinfo_italic      (charinfo *ci, scaled val)          { ci->italic = val;    }
332
 
void set_charinfo_tag         (charinfo *ci, scaled val)          { ci->tag = val;       }
333
 
void set_charinfo_remainder   (charinfo *ci, scaled val)          { ci->remainder = val; }
334
 
void set_charinfo_used        (charinfo *ci, scaled val)          { ci->used = val;      }
335
 
void set_charinfo_index       (charinfo *ci, scaled val)          { ci->index = val;     }
336
 
void set_charinfo_name        (charinfo *ci, char *val)           { dxfree(ci->name,val);        }
337
 
void set_charinfo_tounicode   (charinfo *ci, char *val)           { dxfree(ci->tounicode,val);        }
338
 
void set_charinfo_ligatures   (charinfo *ci, liginfo *val)        { dxfree(ci->ligatures,val);   }
339
 
void set_charinfo_kerns       (charinfo *ci, kerninfo *val)       { dxfree(ci->kerns,val);       }
340
 
void set_charinfo_packets     (charinfo *ci, real_eight_bits *val){ dxfree(ci->packets,val);     }
341
 
void set_charinfo_ef         (charinfo *ci, scaled val)          { ci->ef = val;       }
342
 
void set_charinfo_lp         (charinfo *ci, scaled val)          { ci->lp = val;       }
343
 
void set_charinfo_rp         (charinfo *ci, scaled val)          { ci->rp = val;       }
344
 
 
345
 
 
346
 
 
347
 
void set_charinfo_extensible  (charinfo *ci, int top, int bot, int mid, int rep) { 
348
 
  if (top == 0 && bot == 0 && mid == 0 && rep == 0) {
349
 
    if (ci->extensible != NULL) {
350
 
      free(ci->extensible);
351
 
      ci->extensible = NULL;
352
 
    }
353
 
  } else {
354
 
    if (ci->extensible == NULL) {
355
 
      ci->extensible = xmalloc(4*sizeof(integer));
356
 
    }
357
 
    ci->extensible[EXT_TOP] = top;
358
 
    ci->extensible[EXT_BOT] = bot;
359
 
    ci->extensible[EXT_MID] = mid;
360
 
    ci->extensible[EXT_REP] = rep;
361
 
  }
362
 
}
363
 
 
364
 
scaled           get_charinfo_width       (charinfo *ci) { return ci->width;     }
365
 
scaled           get_charinfo_height      (charinfo *ci) { return ci->height;    }
366
 
scaled           get_charinfo_depth       (charinfo *ci) { return ci->depth;     }
367
 
scaled           get_charinfo_italic      (charinfo *ci) { return ci->italic;    }
368
 
char             get_charinfo_tag         (charinfo *ci) { return ci->tag;       }
369
 
integer          get_charinfo_remainder   (charinfo *ci) { return ci->remainder; }
370
 
char             get_charinfo_used        (charinfo *ci) { return ci->used;      }
371
 
integer          get_charinfo_index       (charinfo *ci) { return ci->index;     }
372
 
char            *get_charinfo_name        (charinfo *ci) { return ci->name;      }
373
 
char            *get_charinfo_tounicode   (charinfo *ci) { return ci->tounicode; }
374
 
liginfo         *get_charinfo_ligatures   (charinfo *ci) { return ci->ligatures; }
375
 
kerninfo        *get_charinfo_kerns       (charinfo *ci) { return ci->kerns;     }
376
 
real_eight_bits *get_charinfo_packets     (charinfo *ci) { return ci->packets;   }
377
 
integer          get_charinfo_ef          (charinfo *ci) { return ci->ef;        }
378
 
integer          get_charinfo_rp          (charinfo *ci) { return ci->rp;        }
379
 
integer          get_charinfo_lp          (charinfo *ci) { return ci->lp;        }
380
 
 
381
 
integer get_charinfo_extensible  (charinfo *ci, int whch) { 
382
 
  int w = 0;
383
 
  if (ci->extensible != NULL) 
384
 
    w = ci->extensible[whch];
385
 
  return w;
386
 
}
387
 
 
388
 
integer ext_top  (internal_font_number f, integer c) { 
389
 
  charinfo *ci = char_info(f,c);
390
 
  integer w = get_charinfo_extensible(ci,EXT_TOP);
391
 
  /*  fprintf(stdout,"top of char 0x%4x in font %s: %i\n",c,font_name(f),w);*/
392
 
  return w;
393
 
}
394
 
 
395
 
integer ext_bot  (internal_font_number f, integer c) { 
396
 
  charinfo *ci = char_info(f,c);
397
 
  integer w = get_charinfo_extensible(ci,EXT_BOT);
398
 
  /*fprintf(stdout,"bot of char 0x%4x in font %s: %i\n",c,font_name(f),w);*/
399
 
  return w;
400
 
}
401
 
integer ext_mid  (internal_font_number f, integer c) { 
402
 
  charinfo *ci = char_info(f,c);
403
 
  integer w = get_charinfo_extensible(ci,EXT_MID);
404
 
  /*fprintf(stdout,"mid of char 0x%4x in font %s: %i\n",c,font_name(f),w);*/
405
 
  return w;
406
 
}
407
 
integer ext_rep  (internal_font_number f, integer c) { 
408
 
  charinfo *ci = char_info(f,c);
409
 
  integer w = get_charinfo_extensible(ci,EXT_REP);
410
 
  /*fprintf(stdout,"rep of char 0x%4x in font %s: %i\n",c,font_name(f),w);*/
411
 
  return w;
412
 
}
413
 
 
414
 
scaled char_width (internal_font_number f, integer c) { 
415
 
  charinfo *ci = char_info(f,c);
416
 
  scaled w = get_charinfo_width(ci);
417
 
  /*fprintf(stdout,"width of char 0x%x in font %s: %i\n",c,font_name(f),w);*/
418
 
  return w;
419
 
}
420
 
 
421
 
scaled char_depth (internal_font_number f, integer c) { 
422
 
  charinfo *ci = char_info(f,c);
423
 
  scaled w = get_charinfo_depth(ci);
424
 
  /*fprintf(stdout,"depth of char 0x%x in font %s: %i\n",c,font_name(f),w);*/
425
 
  return w;
426
 
}
427
 
 
428
 
scaled char_height (internal_font_number f, integer c) { 
429
 
  charinfo *ci = char_info(f,c);
430
 
  scaled w = get_charinfo_height(ci);
431
 
  /*fprintf(stdout,"height of char 0x%x in font %s: %i\n",c,font_name(f),w);*/
432
 
  return w;
433
 
}
434
 
 
435
 
scaled char_italic (internal_font_number f, integer c) { 
436
 
  charinfo *ci = char_info(f,c);
437
 
  return get_charinfo_italic(ci);
438
 
}
439
 
 
440
 
integer char_remainder (internal_font_number f, integer c) {
441
 
  charinfo *ci = char_info(f,c);
442
 
  return get_charinfo_remainder(ci);
443
 
}
444
 
 
445
 
char char_tag (internal_font_number f, integer c) {
446
 
  charinfo *ci = char_info(f,c);
447
 
  return get_charinfo_tag(ci);
448
 
}
449
 
 
450
 
char char_used (internal_font_number f, integer c) {
451
 
  charinfo *ci = char_info(f,c);
452
 
  return get_charinfo_used(ci);
453
 
}
454
 
    
455
 
char *char_name (internal_font_number f, integer c) {
456
 
  charinfo *ci = char_info(f,c);
457
 
  return get_charinfo_name(ci);
458
 
}
459
 
    
460
 
integer char_index (internal_font_number f, integer c) {
461
 
  charinfo *ci = char_info(f,c);
462
 
  return get_charinfo_index(ci);
463
 
}
464
 
 
465
 
liginfo * char_ligatures (internal_font_number f, integer c) {
466
 
  charinfo *ci = char_info(f,c);
467
 
  return get_charinfo_ligatures(ci);
468
 
}
469
 
 
470
 
kerninfo * char_kerns (internal_font_number f, integer c) {
471
 
  charinfo *ci = char_info(f,c);
472
 
  return get_charinfo_kerns(ci);
473
 
}
474
 
 
475
 
real_eight_bits * char_packets (internal_font_number f, integer c) {
476
 
  charinfo *ci = char_info(f,c);
477
 
  return get_charinfo_packets(ci);
478
 
}
479
 
    
480
 
 
481
 
void
482
 
set_font_params(internal_font_number f, int b) {
483
 
  int i;
484
 
  i = font_params(f);
485
 
  if (i!=b) {                                                              
486
 
    font_bytes += (b-font_params(f))*sizeof(scaled); 
487
 
    do_realloc(param_base(f), (b+1), integer);  
488
 
    font_params(f) = b;
489
 
    if (b>i) {
490
 
      while (i<b) {
491
 
        i++;
492
 
        set_font_param(f,i,0);
493
 
      }
494
 
    }
495
 
  } 
496
 
}
497
 
 
498
 
 
499
 
integer
500
 
copy_font (integer f) {
501
 
  int i;
502
 
  charinfo *ci , *co;
503
 
  integer k = new_font();
504
 
  memcpy(font_tables[k],font_tables[f],sizeof(texfont));
505
 
 
506
 
  set_font_cache_id(k,0);
507
 
  set_font_used(k,0);
508
 
  set_font_touched(k,0);
509
 
  
510
 
  font_tables[k]->_font_name = NULL;   
511
 
  font_tables[k]->_font_filename = NULL;   
512
 
  font_tables[k]->_font_fullname = NULL;   
513
 
  font_tables[k]->_font_encodingname = NULL;   
514
 
  font_tables[k]->_font_area = NULL;   
515
 
  font_tables[k]->_font_cidregistry = NULL;   
516
 
  font_tables[k]->_font_cidordering = NULL; 
517
 
  font_tables[k]->_left_boundary = NULL; 
518
 
  font_tables[k]->_right_boundary = NULL; 
519
 
 
520
 
  set_font_name(k,xstrdup(font_name(f)));
521
 
  if (font_filename(f)!= NULL)
522
 
    set_font_filename(k,xstrdup(font_filename(f)));
523
 
  if (font_fullname(f)!= NULL)
524
 
    set_font_fullname(k,xstrdup(font_fullname(f)));
525
 
  if (font_encodingname(f)!= NULL)
526
 
    set_font_encodingname(k,xstrdup(font_encodingname(f)));
527
 
  if (font_area(f)!= NULL)
528
 
    set_font_area(k,xstrdup(font_area(f)));
529
 
  if (font_cidregistry(f)!= NULL)
530
 
    set_font_cidregistry(k,xstrdup(font_cidregistry(f)));
531
 
  if (font_cidordering(f)!= NULL)
532
 
    set_font_cidordering(k,xstrdup(font_cidordering(f)));
533
 
 
534
 
  i = sizeof(*param_base(f))*font_params(f);  
535
 
  font_bytes += i;
536
 
  param_base(k) = xmalloc (i);
537
 
  memcpy(param_base(k),param_base(f), i);
538
 
 
539
 
  i = sizeof(charinfo)*(Charinfo_size(f)+1);  
540
 
  font_bytes += i;
541
 
  font_tables[k]->charinfo = xmalloc(i);
542
 
  memset(font_tables[k]->charinfo,0,i);
543
 
  for(i=0;i<=Charinfo_size(k);i++) {
544
 
        ci = copy_charinfo(&font_tables[f]->charinfo[i]);
545
 
        font_tables[k]->charinfo[i] = *ci;
546
 
  }
547
 
 
548
 
  if (left_boundary(f)!= NULL ) {
549
 
    ci = copy_charinfo(left_boundary(f));
550
 
    set_charinfo(k,left_boundarychar,ci);
551
 
  }
552
 
 
553
 
  if (right_boundary(f)!= NULL ) {
554
 
    ci = copy_charinfo(right_boundary(f));
555
 
    set_charinfo(k,right_boundarychar,ci);
556
 
  }
557
 
  return k;
558
 
}
559
 
 
560
 
void delete_font (integer f) {
561
 
  int i;
562
 
  charinfo *co;
563
 
  assert(f>0);
564
 
  if (font_tables[f]!=NULL) {
565
 
    set_font_name(f,NULL);
566
 
    set_font_filename(f,NULL);
567
 
    set_font_fullname(f,NULL);
568
 
    set_font_encodingname(f,NULL);
569
 
    set_font_area(f,NULL);
570
 
    set_font_cidregistry(f,NULL);
571
 
    set_font_cidordering(f,NULL);
572
 
    set_left_boundary(f,NULL);
573
 
    set_right_boundary(f,NULL);
574
 
    
575
 
    for(i=font_bc(f); i<=font_ec(f); i++) {
576
 
      if (char_exists(f,i)) {
577
 
                co = char_info(f,i);
578
 
                set_charinfo_name(co,NULL);
579
 
                set_charinfo_tounicode(co,NULL);
580
 
                set_charinfo_packets(co,NULL);
581
 
                set_charinfo_ligatures(co,NULL);
582
 
                set_charinfo_kerns(co,NULL);
583
 
                set_charinfo_extensible(co,0,0,0,0);
584
 
      }
585
 
    }
586
 
        /* free .notdef */
587
 
        set_charinfo_name(font_tables[f]->charinfo+0,NULL);
588
 
    free(font_tables[f]->charinfo);
589
 
    destroy_sa_tree(font_tables[f]->characters);
590
 
 
591
 
    free(param_base(f));
592
 
    free(font_tables[f]);
593
 
    font_tables[f] = NULL;
594
 
 
595
 
    if (font_id_maxval==f) {
596
 
      font_id_maxval--;
597
 
    }
598
 
  }
599
 
}
600
 
 
601
 
void 
602
 
create_null_font (void) {
603
 
  int i = new_font();
604
 
  assert(i==0);
605
 
  set_font_name(i,xstrdup("nullfont")); 
606
 
  set_font_area(i,xstrdup(""));
607
 
  set_font_touched(i,1);
608
 
}
609
 
 
610
 
boolean 
611
 
is_valid_font (integer id) {
612
 
  int ret=0;
613
 
  if (id>=0 && id<=font_id_maxval && font_tables[id]!=NULL)
614
 
    ret=1;
615
 
  return ret;
 
269
charinfo *char_info(internal_font_number f, integer c)
 
270
{
 
271
    if (f > font_id_maxval)
 
272
        return 0;
 
273
    if (proper_char_index(c)) {
 
274
        register int glyph = find_charinfo_id(f, c);
 
275
        return &(font_tables[f]->charinfo[glyph]);
 
276
    } else if (c == left_boundarychar && left_boundary(f) != NULL) {
 
277
        return left_boundary(f);
 
278
    } else if (c == right_boundarychar && right_boundary(f) != NULL) {
 
279
        return right_boundary(f);
 
280
    }
 
281
    return &(font_tables[f]->charinfo[0]);
 
282
}
 
283
 
 
284
charinfo_short char_info_short(internal_font_number f, integer c)
 
285
{
 
286
    charinfo_short s;
 
287
    charinfo *i;
 
288
    i = char_info(f, c);
 
289
    s.ci_wd = i->width;
 
290
    s.ci_dp = i->depth;
 
291
    s.ci_ht = i->height;
 
292
    return s;
 
293
}
 
294
 
 
295
integer char_exists(internal_font_number f, integer c)
 
296
{
 
297
    if (f > font_id_maxval)
 
298
        return 0;
 
299
    if (proper_char_index(c)) {
 
300
        return find_charinfo_id(f, c);
 
301
    } else if ((c == left_boundarychar) && has_left_boundary(f)) {
 
302
        return 1;
 
303
    } else if ((c == right_boundarychar) && has_right_boundary(f)) {
 
304
        return 1;
 
305
    }
 
306
    return 0;
 
307
}
 
308
 
 
309
int lua_char_exists_callback(internal_font_number f, integer c)
 
310
{
 
311
    integer callback_id;
 
312
    lua_State *L = Luas[0];
 
313
    int ret = 0;
 
314
    callback_id = callback_defined(char_exists_callback);
 
315
    if (callback_id != 0) {
 
316
        lua_rawgeti(L, LUA_REGISTRYINDEX, callback_callbacks_id);
 
317
        lua_rawgeti(L, -1, callback_id);
 
318
        if (!lua_isfunction(L, -1)) {
 
319
            lua_pop(L, 2);
 
320
            return 0;
 
321
        }
 
322
        lua_pushnumber(L, f);
 
323
        lua_pushnumber(L, c);
 
324
        if (lua_pcall(L, 2, 1, 0) != 0) {       /* two args, 1 result */
 
325
            fprintf(stdout, "error: %s\n", lua_tostring(L, -1));
 
326
            lua_pop(L, 2);
 
327
            error();
 
328
        } else {
 
329
            ret = lua_toboolean(L, -1);
 
330
        }
 
331
    }
 
332
    return ret;
 
333
}
 
334
 
 
335
 
 
336
void set_charinfo_width(charinfo * ci, scaled val)
 
337
{
 
338
    ci->width = val;
 
339
}
 
340
 
 
341
void set_charinfo_height(charinfo * ci, scaled val)
 
342
{
 
343
    ci->height = val;
 
344
}
 
345
 
 
346
void set_charinfo_depth(charinfo * ci, scaled val)
 
347
{
 
348
    ci->depth = val;
 
349
}
 
350
 
 
351
void set_charinfo_italic(charinfo * ci, scaled val)
 
352
{
 
353
    ci->italic = val;
 
354
}
 
355
 
 
356
void set_charinfo_tag(charinfo * ci, scaled val)
 
357
{
 
358
    ci->tag = val;
 
359
}
 
360
 
 
361
void set_charinfo_remainder(charinfo * ci, scaled val)
 
362
{
 
363
    ci->remainder = val;
 
364
}
 
365
 
 
366
void set_charinfo_used(charinfo * ci, scaled val)
 
367
{
 
368
    ci->used = val;
 
369
}
 
370
 
 
371
void set_charinfo_index(charinfo * ci, scaled val)
 
372
{
 
373
    ci->index = val;
 
374
}
 
375
void set_charinfo_name(charinfo * ci, char *val)
 
376
{
 
377
    dxfree(ci->name, val);
 
378
}
 
379
void set_charinfo_tounicode(charinfo * ci, char *val)
 
380
{
 
381
    dxfree(ci->tounicode, val);
 
382
}
 
383
 
 
384
void set_charinfo_ligatures(charinfo * ci, liginfo * val)
 
385
{
 
386
    dxfree(ci->ligatures, val);
 
387
}
 
388
 
 
389
void set_charinfo_kerns(charinfo * ci, kerninfo * val)
 
390
{
 
391
    dxfree(ci->kerns, val);
 
392
}
 
393
 
 
394
void set_charinfo_packets(charinfo * ci, real_eight_bits * val)
 
395
{
 
396
    dxfree(ci->packets, val);
 
397
}
 
398
 
 
399
void set_charinfo_ef(charinfo * ci, scaled val)
 
400
{
 
401
    ci->ef = val;
 
402
}
 
403
 
 
404
void set_charinfo_lp(charinfo * ci, scaled val)
 
405
{
 
406
    ci->lp = val;
 
407
}
 
408
 
 
409
void set_charinfo_rp(charinfo * ci, scaled val)
 
410
{
 
411
    ci->rp = val;
 
412
}
 
413
 
 
414
 
 
415
 
 
416
void set_charinfo_extensible(charinfo * ci, int top, int bot, int mid, int rep)
 
417
{
 
418
    if (top == 0 && bot == 0 && mid == 0 && rep == 0) {
 
419
        if (ci->extensible != NULL) {
 
420
            free(ci->extensible);
 
421
            ci->extensible = NULL;
 
422
        }
 
423
    } else {
 
424
        if (ci->extensible == NULL) {
 
425
            ci->extensible = xmalloc(4 * sizeof(integer));
 
426
        }
 
427
        ci->extensible[EXT_TOP] = top;
 
428
        ci->extensible[EXT_BOT] = bot;
 
429
        ci->extensible[EXT_MID] = mid;
 
430
        ci->extensible[EXT_REP] = rep;
 
431
    }
 
432
}
 
433
 
 
434
scaled get_charinfo_width(charinfo * ci)
 
435
{
 
436
    return ci->width;
 
437
}
 
438
 
 
439
scaled get_charinfo_height(charinfo * ci)
 
440
{
 
441
    return ci->height;
 
442
}
 
443
 
 
444
scaled get_charinfo_depth(charinfo * ci)
 
445
{
 
446
    return ci->depth;
 
447
}
 
448
 
 
449
scaled get_charinfo_italic(charinfo * ci)
 
450
{
 
451
    return ci->italic;
 
452
}
 
453
 
 
454
char get_charinfo_tag(charinfo * ci)
 
455
{
 
456
    return ci->tag;
 
457
}
 
458
 
 
459
integer get_charinfo_remainder(charinfo * ci)
 
460
{
 
461
    return ci->remainder;
 
462
}
 
463
 
 
464
char get_charinfo_used(charinfo * ci)
 
465
{
 
466
    return ci->used;
 
467
}
 
468
 
 
469
integer get_charinfo_index(charinfo * ci)
 
470
{
 
471
    return ci->index;
 
472
}
 
473
 
 
474
char *get_charinfo_name(charinfo * ci)
 
475
{
 
476
    return ci->name;
 
477
}
 
478
 
 
479
char *get_charinfo_tounicode(charinfo * ci)
 
480
{
 
481
    return ci->tounicode;
 
482
}
 
483
 
 
484
liginfo *get_charinfo_ligatures(charinfo * ci)
 
485
{
 
486
    return ci->ligatures;
 
487
}
 
488
 
 
489
kerninfo *get_charinfo_kerns(charinfo * ci)
 
490
{
 
491
    return ci->kerns;
 
492
}
 
493
 
 
494
real_eight_bits *get_charinfo_packets(charinfo * ci)
 
495
{
 
496
    return ci->packets;
 
497
}
 
498
 
 
499
integer get_charinfo_ef(charinfo * ci)
 
500
{
 
501
    return ci->ef;
 
502
}
 
503
 
 
504
integer get_charinfo_rp(charinfo * ci)
 
505
{
 
506
    return ci->rp;
 
507
}
 
508
 
 
509
integer get_charinfo_lp(charinfo * ci)
 
510
{
 
511
    return ci->lp;
 
512
}
 
513
 
 
514
integer get_charinfo_extensible(charinfo * ci, int whch)
 
515
{
 
516
    int w = 0;
 
517
    if (ci->extensible != NULL)
 
518
        w = ci->extensible[whch];
 
519
    return w;
 
520
}
 
521
 
 
522
integer ext_top(internal_font_number f, integer c)
 
523
{
 
524
    charinfo *ci = char_info(f, c);
 
525
    integer w = get_charinfo_extensible(ci, EXT_TOP);
 
526
    /*  fprintf(stdout,"top of char 0x%4x in font %s: %i\n",c,font_name(f),w); */
 
527
    return w;
 
528
}
 
529
 
 
530
integer ext_bot(internal_font_number f, integer c)
 
531
{
 
532
    charinfo *ci = char_info(f, c);
 
533
    integer w = get_charinfo_extensible(ci, EXT_BOT);
 
534
    /*fprintf(stdout,"bot of char 0x%4x in font %s: %i\n",c,font_name(f),w); */
 
535
    return w;
 
536
}
 
537
 
 
538
integer ext_mid(internal_font_number f, integer c)
 
539
{
 
540
    charinfo *ci = char_info(f, c);
 
541
    integer w = get_charinfo_extensible(ci, EXT_MID);
 
542
    /*fprintf(stdout,"mid of char 0x%4x in font %s: %i\n",c,font_name(f),w); */
 
543
    return w;
 
544
}
 
545
 
 
546
integer ext_rep(internal_font_number f, integer c)
 
547
{
 
548
    charinfo *ci = char_info(f, c);
 
549
    integer w = get_charinfo_extensible(ci, EXT_REP);
 
550
    /*fprintf(stdout,"rep of char 0x%4x in font %s: %i\n",c,font_name(f),w); */
 
551
    return w;
 
552
}
 
553
 
 
554
scaled char_width(internal_font_number f, integer c)
 
555
{
 
556
    charinfo *ci = char_info(f, c);
 
557
    scaled w = get_charinfo_width(ci);
 
558
    /*fprintf(stdout,"width of char 0x%x in font %s: %i\n",c,font_name(f),w); */
 
559
    return w;
 
560
}
 
561
 
 
562
scaled char_depth(internal_font_number f, integer c)
 
563
{
 
564
    charinfo *ci = char_info(f, c);
 
565
    scaled w = get_charinfo_depth(ci);
 
566
    /*fprintf(stdout,"depth of char 0x%x in font %s: %i\n",c,font_name(f),w); */
 
567
    return w;
 
568
}
 
569
 
 
570
scaled char_height(internal_font_number f, integer c)
 
571
{
 
572
    charinfo *ci = char_info(f, c);
 
573
    scaled w = get_charinfo_height(ci);
 
574
    /*fprintf(stdout,"height of char 0x%x in font %s: %i\n",c,font_name(f),w); */
 
575
    return w;
 
576
}
 
577
 
 
578
scaled char_italic(internal_font_number f, integer c)
 
579
{
 
580
    charinfo *ci = char_info(f, c);
 
581
    return get_charinfo_italic(ci);
 
582
}
 
583
 
 
584
integer char_remainder(internal_font_number f, integer c)
 
585
{
 
586
    charinfo *ci = char_info(f, c);
 
587
    return get_charinfo_remainder(ci);
 
588
}
 
589
 
 
590
char char_tag(internal_font_number f, integer c)
 
591
{
 
592
    charinfo *ci = char_info(f, c);
 
593
    return get_charinfo_tag(ci);
 
594
}
 
595
 
 
596
char char_used(internal_font_number f, integer c)
 
597
{
 
598
    charinfo *ci = char_info(f, c);
 
599
    return get_charinfo_used(ci);
 
600
}
 
601
 
 
602
char *char_name(internal_font_number f, integer c)
 
603
{
 
604
    charinfo *ci = char_info(f, c);
 
605
    return get_charinfo_name(ci);
 
606
}
 
607
 
 
608
integer char_index(internal_font_number f, integer c)
 
609
{
 
610
    charinfo *ci = char_info(f, c);
 
611
    return get_charinfo_index(ci);
 
612
}
 
613
 
 
614
liginfo *char_ligatures(internal_font_number f, integer c)
 
615
{
 
616
    charinfo *ci = char_info(f, c);
 
617
    return get_charinfo_ligatures(ci);
 
618
}
 
619
 
 
620
kerninfo *char_kerns(internal_font_number f, integer c)
 
621
{
 
622
    charinfo *ci = char_info(f, c);
 
623
    return get_charinfo_kerns(ci);
 
624
}
 
625
 
 
626
real_eight_bits *char_packets(internal_font_number f, integer c)
 
627
{
 
628
    charinfo *ci = char_info(f, c);
 
629
    return get_charinfo_packets(ci);
 
630
}
 
631
 
 
632
 
 
633
void set_font_params(internal_font_number f, int b)
 
634
{
 
635
    int i;
 
636
    i = font_params(f);
 
637
    if (i != b) {
 
638
        font_bytes += (b - font_params(f) + 1) * sizeof(scaled);
 
639
        do_realloc(param_base(f), (b + 2), integer);
 
640
        font_params(f) = b;
 
641
        if (b > i) {
 
642
            while (i < b) {
 
643
                i++;
 
644
                set_font_param(f, i, 0);
 
645
            }
 
646
        }
 
647
    }
 
648
}
 
649
 
 
650
 
 
651
integer copy_font(integer f)
 
652
{
 
653
    int i;
 
654
    charinfo *ci;
 
655
    integer k = new_font();
 
656
    memcpy(font_tables[k], font_tables[f], sizeof(texfont));
 
657
 
 
658
    set_font_cache_id(k, 0);
 
659
    set_font_used(k, 0);
 
660
    set_font_touched(k, 0);
 
661
 
 
662
    font_tables[k]->_font_name = NULL;
 
663
    font_tables[k]->_font_filename = NULL;
 
664
    font_tables[k]->_font_fullname = NULL;
 
665
    font_tables[k]->_font_encodingname = NULL;
 
666
    font_tables[k]->_font_area = NULL;
 
667
    font_tables[k]->_font_cidregistry = NULL;
 
668
    font_tables[k]->_font_cidordering = NULL;
 
669
    font_tables[k]->_left_boundary = NULL;
 
670
    font_tables[k]->_right_boundary = NULL;
 
671
 
 
672
    set_font_name(k, xstrdup(font_name(f)));
 
673
    if (font_filename(f) != NULL)
 
674
        set_font_filename(k, xstrdup(font_filename(f)));
 
675
    if (font_fullname(f) != NULL)
 
676
        set_font_fullname(k, xstrdup(font_fullname(f)));
 
677
    if (font_encodingname(f) != NULL)
 
678
        set_font_encodingname(k, xstrdup(font_encodingname(f)));
 
679
    if (font_area(f) != NULL)
 
680
        set_font_area(k, xstrdup(font_area(f)));
 
681
    if (font_cidregistry(f) != NULL)
 
682
        set_font_cidregistry(k, xstrdup(font_cidregistry(f)));
 
683
    if (font_cidordering(f) != NULL)
 
684
        set_font_cidordering(k, xstrdup(font_cidordering(f)));
 
685
 
 
686
    i = sizeof(*param_base(f)) * font_params(f);
 
687
    font_bytes += i;
 
688
    param_base(k) = xmalloc(i);
 
689
    memcpy(param_base(k), param_base(f), i);
 
690
 
 
691
    i = sizeof(charinfo) * (Charinfo_size(f) + 1);
 
692
    font_bytes += i;
 
693
    font_tables[k]->charinfo = xmalloc(i);
 
694
    memset(font_tables[k]->charinfo, 0, i);
 
695
    for (i = 0; i <= Charinfo_size(k); i++) {
 
696
        ci = copy_charinfo(&font_tables[f]->charinfo[i]);
 
697
        font_tables[k]->charinfo[i] = *ci;
 
698
    }
 
699
 
 
700
    if (left_boundary(f) != NULL) {
 
701
        ci = copy_charinfo(left_boundary(f));
 
702
        set_charinfo(k, left_boundarychar, ci);
 
703
    }
 
704
 
 
705
    if (right_boundary(f) != NULL) {
 
706
        ci = copy_charinfo(right_boundary(f));
 
707
        set_charinfo(k, right_boundarychar, ci);
 
708
    }
 
709
    return k;
 
710
}
 
711
 
 
712
void delete_font(integer f)
 
713
{
 
714
    int i;
 
715
    charinfo *co;
 
716
    assert(f > 0);
 
717
    if (font_tables[f] != NULL) {
 
718
        set_font_name(f, NULL);
 
719
        set_font_filename(f, NULL);
 
720
        set_font_fullname(f, NULL);
 
721
        set_font_encodingname(f, NULL);
 
722
        set_font_area(f, NULL);
 
723
        set_font_cidregistry(f, NULL);
 
724
        set_font_cidordering(f, NULL);
 
725
        set_left_boundary(f, NULL);
 
726
        set_right_boundary(f, NULL);
 
727
 
 
728
        for (i = font_bc(f); i <= font_ec(f); i++) {
 
729
            if (char_exists(f, i)) {
 
730
                co = char_info(f, i);
 
731
                set_charinfo_name(co, NULL);
 
732
                set_charinfo_tounicode(co, NULL);
 
733
                set_charinfo_packets(co, NULL);
 
734
                set_charinfo_ligatures(co, NULL);
 
735
                set_charinfo_kerns(co, NULL);
 
736
                set_charinfo_extensible(co, 0, 0, 0, 0);
 
737
            }
 
738
        }
 
739
        /* free .notdef */
 
740
        set_charinfo_name(font_tables[f]->charinfo + 0, NULL);
 
741
        free(font_tables[f]->charinfo);
 
742
        destroy_sa_tree(font_tables[f]->characters);
 
743
 
 
744
        free(param_base(f));
 
745
        free(font_tables[f]);
 
746
        font_tables[f] = NULL;
 
747
 
 
748
        if (font_id_maxval == f) {
 
749
            font_id_maxval--;
 
750
        }
 
751
    }
 
752
}
 
753
 
 
754
void create_null_font(void)
 
755
{
 
756
    int i = new_font();
 
757
    assert(i == 0);
 
758
    set_font_name(i, xstrdup("nullfont"));
 
759
    set_font_area(i, xstrdup(""));
 
760
    set_font_touched(i, 1);
 
761
}
 
762
 
 
763
boolean is_valid_font(integer id)
 
764
{
 
765
    int ret = 0;
 
766
    if (id >= 0 && id <= font_id_maxval && font_tables[id] != NULL)
 
767
        ret = 1;
 
768
    return ret;
616
769
}
617
770
 
618
771
/* return 1 == identical */
619
 
boolean
620
 
cmp_font_name (integer id, strnumber t) {
621
 
  char *tid , *tt;
622
 
  if (!is_valid_font(id)) 
623
 
    return 0;
624
 
  tt = makecstring(t);
625
 
  tid = font_name(id);
626
 
  if (tt == NULL && tid == NULL)
627
 
    return 1;
628
 
  if (tt == NULL || tid == NULL || strcmp(tid,tt)!=0)
629
 
    return 0;
630
 
  return 1;
631
 
}
632
 
 
633
 
boolean
634
 
cmp_font_area (integer id, strnumber t) {
635
 
  char *tt = NULL;
636
 
  char *tid = font_area(id);
637
 
  if (t == 0) {
638
 
    if (tid == NULL || strlen(tid)==0)
639
 
      return 1;
640
 
    else 
641
 
      return 0;
642
 
  }
643
 
  tt = makecstring(t);
644
 
  if ((tt == NULL || strlen(tt)==0) && (tid == NULL  || strlen(tid)==0))
645
 
    return 1;
646
 
  if (tt == NULL || strcmp(tid,tt)!=0)
647
 
    return 0;
648
 
  return 1;
649
 
}
650
 
 
651
 
 
652
 
static boolean
653
 
same_font_name (integer id, integer t) {
654
 
  int ret = 0;
655
 
  if (font_name(t) == NULL || 
656
 
      font_name(id) == NULL || 
657
 
      strcmp(font_name(t),font_name(id))!=0) {
658
 
    ;
659
 
  } else {
660
 
        ret =1 ;
661
 
  }
662
 
  return ret;
663
 
}
664
 
 
665
 
boolean
666
 
font_shareable (internal_font_number f, internal_font_number k) {
667
 
  int ret = 0;
668
 
  if (font_cidregistry(f) == NULL) {
669
 
    if ( hasfmentry ( k ) 
670
 
         && ( font_map ( k ) == font_map ( f ) ) 
671
 
         && ( same_font_name ( k , f ) 
672
 
              || 
673
 
              ( pdf_font_auto_expand (f)
674
 
                && ( pdf_font_blink (f) != 0 )  /* 0 = nullfont */
675
 
                &&  same_font_name ( k , pdf_font_blink (f) ) ) ) ) {
676
 
      ret = 1;
677
 
        }
678
 
  } else {
679
 
    if ((font_filename(k) != NULL && font_filename(f) != NULL &&
680
 
                 strcmp(font_filename(k),font_filename(f)) == 0)
681
 
        ||
682
 
        ( pdf_font_auto_expand (f)
683
 
          && ( pdf_font_blink (f) != 0 )  /* 0 = nullfont */
684
 
          &&  same_font_name ( k , pdf_font_blink (f) ) ) ) {
685
 
      ret = 1;
686
 
    }
687
 
  }
688
 
  return ret;
689
 
}
690
 
 
691
 
integer 
692
 
test_no_ligatures (internal_font_number f) {
693
 
 integer c;
694
 
 for (c=font_bc(f);c<=font_ec(f);c++) {
695
 
   if (has_lig(f,c)) /* char_exists(f,c) */
696
 
     return 0;
697
 
 }
698
 
 return 1;
699
 
}
700
 
 
701
 
integer
702
 
get_tag_code (internal_font_number f, integer c) {
703
 
  small_number i;
704
 
  if (char_exists(f,c)) {
705
 
    i = char_tag(f,c);
706
 
    if      (i==lig_tag)   return 1;
707
 
    else if (i==list_tag)  return 2;
708
 
    else if (i==ext_tag)   return 4;
709
 
    else                   return 0;
710
 
  }
711
 
  return  -1;
712
 
}
713
 
 
714
 
integer
715
 
get_lp_code (internal_font_number f, integer c) {
716
 
  charinfo *ci = char_info(f,c);
717
 
  return get_charinfo_lp(ci);
718
 
}
719
 
 
720
 
integer
721
 
get_rp_code (internal_font_number f, integer c) {
722
 
  charinfo *ci = char_info(f,c);
723
 
  return get_charinfo_rp(ci);
724
 
}
725
 
 
726
 
integer
727
 
get_ef_code (internal_font_number f, integer c) {
728
 
  charinfo *ci = char_info(f,c);
729
 
  return get_charinfo_ef(ci);
730
 
}
731
 
 
732
 
void
733
 
set_tag_code (internal_font_number f, integer c, integer i) {
734
 
  integer fixedi;
735
 
  charinfo * co;
736
 
  if (char_exists(f,c)) {
737
 
    /* abs(fix_int(i-7,0)) */
738
 
    fixedi = - (i<-7 ? -7 : (i>0 ? 0 : i )) ;
739
 
    co = char_info(f,c);
740
 
    if (fixedi >= 4) {
741
 
      if (char_tag(f,c) == ext_tag) 
742
 
        set_charinfo_tag(co,(char_tag(f,c)- ext_tag));
743
 
      fixedi = fixedi - 4;
744
 
    }
745
 
    if (fixedi >= 2) {
746
 
      if (char_tag(f,c) == list_tag) 
747
 
        set_charinfo_tag(co,(char_tag(f,c)- list_tag));
748
 
      fixedi = fixedi - 2;
749
 
    };
750
 
    if (fixedi >= 1) {
751
 
      if (has_lig(f,c)) 
752
 
        set_charinfo_ligatures(co,NULL);
753
 
      if (has_kern(f,c)) 
754
 
        set_charinfo_kerns(co,NULL);
755
 
    }
756
 
  }
757
 
}
758
 
 
759
 
 
760
 
void 
761
 
set_lp_code(internal_font_number f, integer c, integer i) {
762
 
  charinfo * co;
763
 
  if (char_exists(f,c)) {
764
 
    co = char_info(f,c);
765
 
        set_charinfo_lp(co,i);
766
 
  }
767
 
}
768
 
 
769
 
void 
770
 
set_rp_code(internal_font_number f, integer c, integer i) {
771
 
  charinfo * co;
772
 
  if (char_exists(f,c)) {
773
 
    co = char_info(f,c);
774
 
        set_charinfo_rp(co,i);
775
 
  }
776
 
}
777
 
 
778
 
void 
779
 
set_ef_code(internal_font_number f, integer c, integer i) {
780
 
  charinfo * co;
781
 
  if (char_exists(f,c)) {
782
 
    co = char_info(f,c);
783
 
        set_charinfo_ef(co,i);
784
 
  }
785
 
}
786
 
 
787
 
void 
788
 
set_no_ligatures (internal_font_number f) {
789
 
  integer c;
790
 
  charinfo * co;
791
 
  
792
 
  if (font_tables[f]->ligatures_disabled)
793
 
        return;
794
 
 
795
 
  co = char_info(f,left_boundarychar);
796
 
  set_charinfo_ligatures(co,NULL);
797
 
  co = char_info(f,right_boundarychar); /* this is weird */
798
 
  set_charinfo_ligatures(co,NULL);
799
 
  for (c=0;c<font_tables[f]->charinfo_count;c++) {
800
 
        co = font_tables[f]->charinfo+c;
801
 
        set_charinfo_ligatures(co,NULL);
802
 
  }
803
 
  font_tables[f]->ligatures_disabled =1;
804
 
}
805
 
 
806
 
liginfo 
807
 
get_ligature (internal_font_number f, integer lc, integer rc) {
808
 
  liginfo t, u;
809
 
  charinfo * co;
810
 
  t.lig = 0;
811
 
  t.type = 0;
812
 
  t.adj = 0;
813
 
  if (lc == non_boundarychar || rc == non_boundarychar || (!has_lig(f,lc)) )
 
772
boolean cmp_font_name(integer id, strnumber t)
 
773
{
 
774
    char *tid, *tt;
 
775
    if (!is_valid_font(id))
 
776
        return 0;
 
777
    tt = makecstring(t);
 
778
    tid = font_name(id);
 
779
    if (tt == NULL && tid == NULL)
 
780
        return 1;
 
781
    if (tt == NULL || tid == NULL || strcmp(tid, tt) != 0)
 
782
        return 0;
 
783
    return 1;
 
784
}
 
785
 
 
786
boolean cmp_font_area(integer id, strnumber t)
 
787
{
 
788
    char *tt = NULL;
 
789
    char *tid = font_area(id);
 
790
    if (t == 0) {
 
791
        if (tid == NULL || strlen(tid) == 0)
 
792
            return 1;
 
793
        else
 
794
            return 0;
 
795
    }
 
796
    tt = makecstring(t);
 
797
    if ((tt == NULL || strlen(tt) == 0) && (tid == NULL || strlen(tid) == 0))
 
798
        return 1;
 
799
    if (tt == NULL || strcmp(tid, tt) != 0)
 
800
        return 0;
 
801
    return 1;
 
802
}
 
803
 
 
804
 
 
805
static boolean same_font_name(integer id, integer t)
 
806
{
 
807
    int ret = 0;
 
808
    if (font_name(t) == NULL ||
 
809
        font_name(id) == NULL || strcmp(font_name(t), font_name(id)) != 0) {
 
810
        ;
 
811
    } else {
 
812
        ret = 1;
 
813
    }
 
814
    return ret;
 
815
}
 
816
 
 
817
boolean font_shareable(internal_font_number f, internal_font_number k)
 
818
{
 
819
    int ret = 0;
 
820
    if (font_cidregistry(f) == NULL) {
 
821
        if (hasfmentry(k)
 
822
            && (font_map(k) == font_map(f))
 
823
            && (same_font_name(k, f)
 
824
                || (pdf_font_auto_expand(f)
 
825
                    && (pdf_font_blink(f) != 0) /* 0 = nullfont */
 
826
                    &&same_font_name(k, pdf_font_blink(f))))) {
 
827
            ret = 1;
 
828
        }
 
829
    } else {
 
830
        if ((font_filename(k) != NULL && font_filename(f) != NULL &&
 
831
             strcmp(font_filename(k), font_filename(f)) == 0)
 
832
            || (pdf_font_auto_expand(f)
 
833
                && (pdf_font_blink(f) != 0)     /* 0 = nullfont */
 
834
                &&same_font_name(k, pdf_font_blink(f)))) {
 
835
            ret = 1;
 
836
        }
 
837
    }
 
838
    return ret;
 
839
}
 
840
 
 
841
integer test_no_ligatures(internal_font_number f)
 
842
{
 
843
    integer c;
 
844
    for (c = font_bc(f); c <= font_ec(f); c++) {
 
845
        if (has_lig(f, c))      /* char_exists(f,c) */
 
846
            return 0;
 
847
    }
 
848
    return 1;
 
849
}
 
850
 
 
851
integer get_tag_code(internal_font_number f, integer c)
 
852
{
 
853
    small_number i;
 
854
    if (char_exists(f, c)) {
 
855
        i = char_tag(f, c);
 
856
        if (i == lig_tag)
 
857
            return 1;
 
858
        else if (i == list_tag)
 
859
            return 2;
 
860
        else if (i == ext_tag)
 
861
            return 4;
 
862
        else
 
863
            return 0;
 
864
    }
 
865
    return -1;
 
866
}
 
867
 
 
868
integer get_lp_code(internal_font_number f, integer c)
 
869
{
 
870
    charinfo *ci = char_info(f, c);
 
871
    return get_charinfo_lp(ci);
 
872
}
 
873
 
 
874
integer get_rp_code(internal_font_number f, integer c)
 
875
{
 
876
    charinfo *ci = char_info(f, c);
 
877
    return get_charinfo_rp(ci);
 
878
}
 
879
 
 
880
integer get_ef_code(internal_font_number f, integer c)
 
881
{
 
882
    charinfo *ci = char_info(f, c);
 
883
    return get_charinfo_ef(ci);
 
884
}
 
885
 
 
886
void set_tag_code(internal_font_number f, integer c, integer i)
 
887
{
 
888
    integer fixedi;
 
889
    charinfo *co;
 
890
    if (char_exists(f, c)) {
 
891
        /* abs(fix_int(i-7,0)) */
 
892
        fixedi = -(i < -7 ? -7 : (i > 0 ? 0 : i));
 
893
        co = char_info(f, c);
 
894
        if (fixedi >= 4) {
 
895
            if (char_tag(f, c) == ext_tag)
 
896
                set_charinfo_tag(co, (char_tag(f, c) - ext_tag));
 
897
            fixedi = fixedi - 4;
 
898
        }
 
899
        if (fixedi >= 2) {
 
900
            if (char_tag(f, c) == list_tag)
 
901
                set_charinfo_tag(co, (char_tag(f, c) - list_tag));
 
902
            fixedi = fixedi - 2;
 
903
        };
 
904
        if (fixedi >= 1) {
 
905
            if (has_lig(f, c))
 
906
                set_charinfo_ligatures(co, NULL);
 
907
            if (has_kern(f, c))
 
908
                set_charinfo_kerns(co, NULL);
 
909
        }
 
910
    }
 
911
}
 
912
 
 
913
 
 
914
void set_lp_code(internal_font_number f, integer c, integer i)
 
915
{
 
916
    charinfo *co;
 
917
    if (char_exists(f, c)) {
 
918
        co = char_info(f, c);
 
919
        set_charinfo_lp(co, i);
 
920
    }
 
921
}
 
922
 
 
923
void set_rp_code(internal_font_number f, integer c, integer i)
 
924
{
 
925
    charinfo *co;
 
926
    if (char_exists(f, c)) {
 
927
        co = char_info(f, c);
 
928
        set_charinfo_rp(co, i);
 
929
    }
 
930
}
 
931
 
 
932
void set_ef_code(internal_font_number f, integer c, integer i)
 
933
{
 
934
    charinfo *co;
 
935
    if (char_exists(f, c)) {
 
936
        co = char_info(f, c);
 
937
        set_charinfo_ef(co, i);
 
938
    }
 
939
}
 
940
 
 
941
void set_no_ligatures(internal_font_number f)
 
942
{
 
943
    integer c;
 
944
    charinfo *co;
 
945
 
 
946
    if (font_tables[f]->ligatures_disabled)
 
947
        return;
 
948
 
 
949
    co = char_info(f, left_boundarychar);
 
950
    set_charinfo_ligatures(co, NULL);
 
951
    co = char_info(f, right_boundarychar);      /* this is weird */
 
952
    set_charinfo_ligatures(co, NULL);
 
953
    for (c = 0; c < font_tables[f]->charinfo_count; c++) {
 
954
        co = font_tables[f]->charinfo + c;
 
955
        set_charinfo_ligatures(co, NULL);
 
956
    }
 
957
    font_tables[f]->ligatures_disabled = 1;
 
958
}
 
959
 
 
960
liginfo get_ligature(internal_font_number f, integer lc, integer rc)
 
961
{
 
962
    liginfo t, u;
 
963
    charinfo *co;
 
964
    t.lig = 0;
 
965
    t.type = 0;
 
966
    t.adj = 0;
 
967
    if (lc == non_boundarychar || rc == non_boundarychar || (!has_lig(f, lc)))
 
968
        return t;
 
969
    k = 0;
 
970
    co = char_info(f, lc);
 
971
    while (1) {
 
972
        u = charinfo_ligature(co, k);
 
973
        if (lig_end(u))
 
974
            break;
 
975
        if (lig_char(u) == rc) {
 
976
            if (lig_disabled(u)) {
 
977
                return t;
 
978
            } else {
 
979
                return u;
 
980
            }
 
981
        }
 
982
        k++;
 
983
    }
814
984
    return t;
815
 
  k = 0;
816
 
  co = char_info(f,lc);
817
 
  while (1) {
818
 
    u = charinfo_ligature(co,k);
819
 
    if (lig_end(u))
820
 
      break;    
821
 
    if (lig_char(u) == rc) {
822
 
      if (lig_disabled(u)) {
823
 
        return t;
824
 
      } else {
825
 
        return u;
826
 
      }
827
 
    }
828
 
    k++;
829
 
  }
830
 
  return t;
831
985
}
832
986
 
833
987
 
834
 
scaled 
835
 
get_kern(internal_font_number f, integer lc, integer rc)
 
988
scaled get_kern(internal_font_number f, integer lc, integer rc)
836
989
{
837
 
  integer k;
838
 
  kerninfo u;
839
 
  charinfo * co;
840
 
  if (lc == non_boundarychar || rc == non_boundarychar || (!has_kern(f,lc)) )
 
990
    integer k;
 
991
    kerninfo u;
 
992
    charinfo *co;
 
993
    if (lc == non_boundarychar || rc == non_boundarychar || (!has_kern(f, lc)))
 
994
        return 0;
 
995
    k = 0;
 
996
    co = char_info(f, lc);
 
997
    while (1) {
 
998
        u = charinfo_kern(co, k);
 
999
        if (kern_end(u))
 
1000
            break;
 
1001
        if (kern_char(u) == rc) {
 
1002
            if (kern_disabled(u))
 
1003
                return 0;
 
1004
            else
 
1005
                return kern_kern(u);
 
1006
        }
 
1007
        k++;
 
1008
    }
841
1009
    return 0;
842
 
  k = 0;
843
 
  co = char_info(f,lc);
844
 
  while (1) {
845
 
    u = charinfo_kern(co,k);
846
 
    if (kern_end(u))
847
 
      break;
848
 
    if (kern_char(u) == rc) {
849
 
      if (kern_disabled(u))
850
 
        return 0;
851
 
      else
852
 
        return kern_kern(u);
853
 
    }
854
 
    k++;
855
 
  }
856
 
  return 0;
857
1010
}
858
1011
 
859
1012
 
860
1013
/* dumping and undumping fonts */
861
1014
 
862
 
#define dump_string(a)                          \
863
 
  if (a!=NULL) {                                \
864
 
    x = strlen(a)+1;                            \
865
 
    dump_int(x);  dump_things(*a, x);           \
866
 
  } else {                                      \
867
 
    x = 0; dump_int(x);                         \
 
1015
#define dump_string(a)        \
 
1016
  if (a!=NULL) {        \
 
1017
    x = strlen(a)+1;        \
 
1018
    dump_int(x);  dump_things(*a, x);   \
 
1019
  } else {          \
 
1020
    x = 0; dump_int(x);       \
868
1021
  }
869
1022
 
870
 
void
871
 
dump_charinfo (int f , int c) {
872
 
  charinfo *co;
873
 
  int x;
874
 
  liginfo *lig;
875
 
  kerninfo *kern;
876
 
 
877
 
  dump_int(c);
878
 
  co = char_info(f,c);
879
 
  set_charinfo_used(co,0);
880
 
  dump_int(get_charinfo_width(co));
881
 
  dump_int(get_charinfo_height(co));
882
 
  dump_int(get_charinfo_depth(co));
883
 
  dump_int(get_charinfo_italic(co));
884
 
  dump_int(get_charinfo_tag(co));
885
 
  dump_int(get_charinfo_ef(co));
886
 
  dump_int(get_charinfo_rp(co));
887
 
  dump_int(get_charinfo_lp(co));
888
 
  dump_int(get_charinfo_remainder(co));
889
 
  dump_int(get_charinfo_used(co));
890
 
  dump_int(get_charinfo_index(co));
891
 
  dump_string(get_charinfo_name(co));
892
 
  dump_string(get_charinfo_tounicode(co));
893
 
 
894
 
  /* ligatures */
895
 
  x = 0;
896
 
  if ((lig = get_charinfo_ligatures(co)) != NULL) {
897
 
    while (!lig_end(lig[x])) { x++; }
898
 
    x++;
899
 
    dump_int(x);  dump_things(*lig, x);
900
 
  } else {
 
1023
void dump_charinfo(int f, int c)
 
1024
{
 
1025
    charinfo *co;
 
1026
    int x;
 
1027
    liginfo *lig;
 
1028
    kerninfo *kern;
 
1029
 
 
1030
    dump_int(c);
 
1031
    co = char_info(f, c);
 
1032
    set_charinfo_used(co, 0);
 
1033
    dump_int(get_charinfo_width(co));
 
1034
    dump_int(get_charinfo_height(co));
 
1035
    dump_int(get_charinfo_depth(co));
 
1036
    dump_int(get_charinfo_italic(co));
 
1037
    dump_int(get_charinfo_tag(co));
 
1038
    dump_int(get_charinfo_ef(co));
 
1039
    dump_int(get_charinfo_rp(co));
 
1040
    dump_int(get_charinfo_lp(co));
 
1041
    dump_int(get_charinfo_remainder(co));
 
1042
    dump_int(get_charinfo_used(co));
 
1043
    dump_int(get_charinfo_index(co));
 
1044
    dump_string(get_charinfo_name(co));
 
1045
    dump_string(get_charinfo_tounicode(co));
 
1046
 
 
1047
    /* ligatures */
 
1048
    x = 0;
 
1049
    if ((lig = get_charinfo_ligatures(co)) != NULL) {
 
1050
        while (!lig_end(lig[x])) {
 
1051
            x++;
 
1052
        }
 
1053
        x++;
 
1054
        dump_int(x);
 
1055
        dump_things(*lig, x);
 
1056
    } else {
 
1057
        dump_int(x);
 
1058
    }
 
1059
    /* kerns */
 
1060
    x = 0;
 
1061
    if ((kern = get_charinfo_kerns(co)) != NULL) {
 
1062
        while (!kern_end(kern[x])) {
 
1063
            x++;
 
1064
        }
 
1065
        x++;
 
1066
        dump_int(x);
 
1067
        dump_things(*kern, x);
 
1068
    } else {
 
1069
        dump_int(x);
 
1070
    }
 
1071
    /* packets */
 
1072
    x = vf_packet_bytes(co);
901
1073
    dump_int(x);
902
 
  }
903
 
  /* kerns */
904
 
  x = 0;
905
 
  if ((kern = get_charinfo_kerns(co)) != NULL) {
906
 
    while (!kern_end(kern[x])) { x++; }
907
 
    x++;
908
 
    dump_int(x);  dump_things(*kern, x);
909
 
  } else {
910
 
    dump_int(x);        
911
 
  }
912
 
  /* packets */
913
 
  x= vf_packet_bytes(co);
914
 
  dump_int(x);  
915
 
  if (x>0) {
916
 
    dump_things(*get_charinfo_packets(co), x);
917
 
  }
918
 
 
919
 
  if (get_charinfo_tag(co)==ext_tag) {
920
 
    x = get_charinfo_extensible(co,EXT_TOP);       dump_int(x);
921
 
    x = get_charinfo_extensible(co,EXT_BOT);       dump_int(x);
922
 
    x = get_charinfo_extensible(co,EXT_MID);       dump_int(x);
923
 
    x = get_charinfo_extensible(co,EXT_REP);       dump_int(x);
924
 
  }
925
 
}
926
 
 
927
 
void
928
 
dump_font (int f) {
929
 
  int i,x;
930
 
 
931
 
  set_font_used(f,0);
932
 
  font_tables[f]->charinfo_cache = NULL;
933
 
  dump_things(*(font_tables[f]), 1);
934
 
  dump_string(font_name(f));
935
 
  dump_string(font_area(f));
936
 
  dump_string(font_filename(f));
937
 
  dump_string(font_fullname(f));
938
 
  dump_string(font_encodingname(f));
939
 
  dump_string(font_cidregistry(f));
940
 
  dump_string(font_cidordering(f));
941
 
 
942
 
  dump_things(*param_base(f),(font_params(f)+1));
943
 
 
944
 
  if (has_left_boundary(f)) {
945
 
    dump_int(1);  dump_charinfo(f,left_boundarychar);
946
 
  } else {
947
 
    dump_int(0);
948
 
  }
949
 
  if (has_right_boundary(f)) {
950
 
    dump_int(1);  dump_charinfo(f,right_boundarychar);
951
 
  } else {
952
 
    dump_int(0);
953
 
  }
954
 
 
955
 
  for(i=font_bc(f); i<=font_ec(f); i++) {
956
 
    if (char_exists(f,i)) {
957
 
      dump_charinfo(f,i);
958
 
    }
959
 
  }
960
 
}
961
 
 
962
 
int
963
 
undump_charinfo (int f) {
964
 
  charinfo *co;
965
 
  int x,i;
966
 
  char *s = NULL;
967
 
  liginfo *lig = NULL;
968
 
  kerninfo *kern = NULL;
969
 
  real_eight_bits *packet = NULL;
970
 
  int top = 0, bot = 0, mid = 0, rep = 0;
971
 
 
972
 
  undump_int(i);
973
 
  co = get_charinfo(f,i);
974
 
  undump_int(x); set_charinfo_width(co,x);
975
 
  undump_int(x); set_charinfo_height(co,x);
976
 
  undump_int(x); set_charinfo_depth(co,x);
977
 
  undump_int(x); set_charinfo_italic(co,x);
978
 
  undump_int(x); set_charinfo_tag(co,x);
979
 
  undump_int(x); set_charinfo_ef(co,x);
980
 
  undump_int(x); set_charinfo_rp(co,x);
981
 
  undump_int(x); set_charinfo_lp(co,x);
982
 
  undump_int(x); set_charinfo_remainder(co,x);
983
 
  undump_int(x); set_charinfo_used(co,x);
984
 
  undump_int(x); set_charinfo_index(co,x);
985
 
 
986
 
  /* name */
987
 
  undump_int (x);
988
 
  if (x>0) {
989
 
    font_bytes += x;
990
 
    s = xmalloc(x); 
991
 
    undump_things(*s,x);
992
 
  }
993
 
  set_charinfo_name(co,s); 
994
 
 
995
 
  /* tounicode */
996
 
  undump_int (x);
997
 
  if (x>0) {
998
 
    font_bytes += x;
999
 
    s = xmalloc(x); 
1000
 
    undump_things(*s,x);
1001
 
  }
1002
 
  set_charinfo_tounicode(co,s); 
1003
 
 
1004
 
  /* ligatures */
1005
 
  undump_int (x);      
1006
 
  if (x>0) {
1007
 
    font_bytes += x*sizeof(liginfo);
1008
 
    lig = xmalloc(x*sizeof(liginfo)); 
1009
 
    undump_things(*lig,x);
1010
 
  }
1011
 
  set_charinfo_ligatures(co,lig); 
1012
 
 
1013
 
  /* kerns */
1014
 
  undump_int (x);      
1015
 
  if (x>0) {
1016
 
    font_bytes += x*sizeof(kerninfo);
1017
 
    kern = xmalloc(x*sizeof(kerninfo)); 
1018
 
    undump_things(*kern,x);
1019
 
  }
1020
 
  set_charinfo_kerns(co,kern); 
1021
 
 
1022
 
  /* packets */
1023
 
  undump_int (x);      
1024
 
  if (x>0) {
1025
 
    font_bytes += x;
1026
 
    packet = xmalloc(x); 
1027
 
    undump_things(*packet,x);
1028
 
  }
1029
 
  set_charinfo_packets(co,packet); 
1030
 
 
1031
 
  if (get_charinfo_tag(co)==ext_tag) {
1032
 
    undump_int(top);
1033
 
    undump_int(bot);
1034
 
    undump_int(mid);
1035
 
    undump_int(rep);
1036
 
    set_charinfo_extensible(co,top,bot,mid,rep);
1037
 
  }
1038
 
  return i;
1039
 
}
1040
 
 
1041
 
#define undump_font_string(a)   undump_int (x); \
1042
 
  if (x>0) {                                    \
1043
 
    font_bytes += x;                            \
1044
 
    s = xmalloc(x); undump_things(*s,x);        \
 
1074
    if (x > 0) {
 
1075
        dump_things(*get_charinfo_packets(co), x);
 
1076
    }
 
1077
 
 
1078
    if (get_charinfo_tag(co) == ext_tag) {
 
1079
        x = get_charinfo_extensible(co, EXT_TOP);
 
1080
        dump_int(x);
 
1081
        x = get_charinfo_extensible(co, EXT_BOT);
 
1082
        dump_int(x);
 
1083
        x = get_charinfo_extensible(co, EXT_MID);
 
1084
        dump_int(x);
 
1085
        x = get_charinfo_extensible(co, EXT_REP);
 
1086
        dump_int(x);
 
1087
    }
 
1088
}
 
1089
 
 
1090
void dump_font(int f)
 
1091
{
 
1092
    int i, x;
 
1093
 
 
1094
    set_font_used(f, 0);
 
1095
    font_tables[f]->charinfo_cache = NULL;
 
1096
    dump_things(*(font_tables[f]), 1);
 
1097
    dump_string(font_name(f));
 
1098
    dump_string(font_area(f));
 
1099
    dump_string(font_filename(f));
 
1100
    dump_string(font_fullname(f));
 
1101
    dump_string(font_encodingname(f));
 
1102
    dump_string(font_cidregistry(f));
 
1103
    dump_string(font_cidordering(f));
 
1104
 
 
1105
    dump_things(*param_base(f), (font_params(f) + 1));
 
1106
 
 
1107
    if (has_left_boundary(f)) {
 
1108
        dump_int(1);
 
1109
        dump_charinfo(f, left_boundarychar);
 
1110
    } else {
 
1111
        dump_int(0);
 
1112
    }
 
1113
    if (has_right_boundary(f)) {
 
1114
        dump_int(1);
 
1115
        dump_charinfo(f, right_boundarychar);
 
1116
    } else {
 
1117
        dump_int(0);
 
1118
    }
 
1119
 
 
1120
    for (i = font_bc(f); i <= font_ec(f); i++) {
 
1121
        if (char_exists(f, i)) {
 
1122
            dump_charinfo(f, i);
 
1123
        }
 
1124
    }
 
1125
}
 
1126
 
 
1127
int undump_charinfo(int f)
 
1128
{
 
1129
    charinfo *co;
 
1130
    int x, i;
 
1131
    char *s = NULL;
 
1132
    liginfo *lig = NULL;
 
1133
    kerninfo *kern = NULL;
 
1134
    real_eight_bits *packet = NULL;
 
1135
    int top = 0, bot = 0, mid = 0, rep = 0;
 
1136
 
 
1137
    undump_int(i);
 
1138
    co = get_charinfo(f, i);
 
1139
    undump_int(x);
 
1140
    set_charinfo_width(co, x);
 
1141
    undump_int(x);
 
1142
    set_charinfo_height(co, x);
 
1143
    undump_int(x);
 
1144
    set_charinfo_depth(co, x);
 
1145
    undump_int(x);
 
1146
    set_charinfo_italic(co, x);
 
1147
    undump_int(x);
 
1148
    set_charinfo_tag(co, x);
 
1149
    undump_int(x);
 
1150
    set_charinfo_ef(co, x);
 
1151
    undump_int(x);
 
1152
    set_charinfo_rp(co, x);
 
1153
    undump_int(x);
 
1154
    set_charinfo_lp(co, x);
 
1155
    undump_int(x);
 
1156
    set_charinfo_remainder(co, x);
 
1157
    undump_int(x);
 
1158
    set_charinfo_used(co, x);
 
1159
    undump_int(x);
 
1160
    set_charinfo_index(co, x);
 
1161
 
 
1162
    /* name */
 
1163
    undump_int(x);
 
1164
    if (x > 0) {
 
1165
        font_bytes += x;
 
1166
        s = xmalloc(x);
 
1167
        undump_things(*s, x);
 
1168
    }
 
1169
    set_charinfo_name(co, s);
 
1170
 
 
1171
    /* tounicode */
 
1172
    undump_int(x);
 
1173
    if (x > 0) {
 
1174
        font_bytes += x;
 
1175
        s = xmalloc(x);
 
1176
        undump_things(*s, x);
 
1177
    }
 
1178
    set_charinfo_tounicode(co, s);
 
1179
 
 
1180
    /* ligatures */
 
1181
    undump_int(x);
 
1182
    if (x > 0) {
 
1183
        font_bytes += x * sizeof(liginfo);
 
1184
        lig = xmalloc(x * sizeof(liginfo));
 
1185
        undump_things(*lig, x);
 
1186
    }
 
1187
    set_charinfo_ligatures(co, lig);
 
1188
 
 
1189
    /* kerns */
 
1190
    undump_int(x);
 
1191
    if (x > 0) {
 
1192
        font_bytes += x * sizeof(kerninfo);
 
1193
        kern = xmalloc(x * sizeof(kerninfo));
 
1194
        undump_things(*kern, x);
 
1195
    }
 
1196
    set_charinfo_kerns(co, kern);
 
1197
 
 
1198
    /* packets */
 
1199
    undump_int(x);
 
1200
    if (x > 0) {
 
1201
        font_bytes += x;
 
1202
        packet = xmalloc(x);
 
1203
        undump_things(*packet, x);
 
1204
    }
 
1205
    set_charinfo_packets(co, packet);
 
1206
 
 
1207
    if (get_charinfo_tag(co) == ext_tag) {
 
1208
        undump_int(top);
 
1209
        undump_int(bot);
 
1210
        undump_int(mid);
 
1211
        undump_int(rep);
 
1212
        set_charinfo_extensible(co, top, bot, mid, rep);
 
1213
    }
 
1214
    return i;
 
1215
}
 
1216
 
 
1217
#define undump_font_string(a)   undump_int (x); \
 
1218
  if (x>0) {          \
 
1219
    font_bytes += x;        \
 
1220
    s = xmalloc(x); undump_things(*s,x);  \
1045
1221
    a(f,s); }
1046
1222
 
1047
1223
 
1048
 
void
1049
 
undump_font(int f)
 
1224
void undump_font(int f)
1050
1225
{
1051
 
  int x, i;
1052
 
  texfont *tt;
1053
 
  charinfo *ci;
1054
 
  char *s;
1055
 
  grow_font_table (f);
1056
 
  font_tables[f] = NULL;
1057
 
  font_bytes += sizeof(texfont);
1058
 
  tt = xmalloc(sizeof(texfont));
1059
 
  undump_things(*tt,1);
1060
 
  font_tables[f] = tt;
1061
 
 
1062
 
  undump_font_string(set_font_name);
1063
 
  undump_font_string(set_font_area);
1064
 
  undump_font_string(set_font_filename);
1065
 
  undump_font_string(set_font_fullname);
1066
 
  undump_font_string(set_font_encodingname);
1067
 
  undump_font_string(set_font_cidregistry);
1068
 
  undump_font_string(set_font_cidordering);
1069
 
 
1070
 
  i = sizeof(*param_base(f))*(font_params(f)+1); 
1071
 
  font_bytes += i;
1072
 
  param_base(f) = xmalloc (i);
1073
 
  undump_things(*param_base(f),    (font_params(f)+1));
1074
 
 
1075
 
  font_tables[f]->_left_boundary = NULL;
1076
 
  undump_int(x);
1077
 
  if (x) {  i =  undump_charinfo(f);  } /* left boundary */
1078
 
 
1079
 
  font_tables[f]->_right_boundary = NULL;
1080
 
  undump_int(x);
1081
 
  if (x) {  i =  undump_charinfo(f);  } /* right boundary */
1082
 
 
1083
 
 
1084
 
  font_tables[f]->characters = new_sa_tree(1, 0); /* stack size 1, default item value 0 */
1085
 
  ci = xcalloc(1,sizeof(charinfo));
1086
 
  set_charinfo_name(ci,xstrdup(".notdef"));
1087
 
  font_tables[f]->charinfo = ci;
1088
 
 
1089
 
  i = font_bc(f);
1090
 
  while(i<font_ec(f)) {
1091
 
    i = undump_charinfo(f);
1092
 
  }
 
1226
    int x, i;
 
1227
    texfont *tt;
 
1228
    charinfo *ci;
 
1229
    char *s;
 
1230
    grow_font_table(f);
 
1231
    font_tables[f] = NULL;
 
1232
    font_bytes += sizeof(texfont);
 
1233
    tt = xmalloc(sizeof(texfont));
 
1234
    undump_things(*tt, 1);
 
1235
    /* these |char *| need resetting */
 
1236
    tt->_font_name = NULL;
 
1237
    tt->_font_area = NULL;
 
1238
    tt->_font_filename = NULL;
 
1239
    tt->_font_fullname = NULL;
 
1240
    tt->_font_encodingname = NULL;
 
1241
    tt->_font_cidregistry = NULL;
 
1242
    tt->_font_cidordering = NULL;
 
1243
    font_tables[f] = tt;
 
1244
 
 
1245
    undump_font_string(set_font_name);
 
1246
    undump_font_string(set_font_area);
 
1247
    undump_font_string(set_font_filename);
 
1248
    undump_font_string(set_font_fullname);
 
1249
    undump_font_string(set_font_encodingname);
 
1250
    undump_font_string(set_font_cidregistry);
 
1251
    undump_font_string(set_font_cidordering);
 
1252
 
 
1253
    i = sizeof(*param_base(f)) * (font_params(f) + 1);
 
1254
    font_bytes += i;
 
1255
    param_base(f) = xmalloc(i);
 
1256
    undump_things(*param_base(f), (font_params(f) + 1));
 
1257
 
 
1258
    font_tables[f]->_left_boundary = NULL;
 
1259
    undump_int(x);
 
1260
    if (x) {
 
1261
        i = undump_charinfo(f);
 
1262
    }
 
1263
    /* left boundary */
 
1264
    font_tables[f]->_right_boundary = NULL;
 
1265
    undump_int(x);
 
1266
    if (x) {
 
1267
        i = undump_charinfo(f);
 
1268
    }
 
1269
 
 
1270
    /* right boundary */
 
1271
    font_tables[f]->characters = new_sa_tree(1, 0);     /* stack size 1, default item value 0 */
 
1272
    ci = xcalloc(1, sizeof(charinfo));
 
1273
    set_charinfo_name(ci, xstrdup(".notdef"));
 
1274
    font_tables[f]->charinfo = ci;
 
1275
 
 
1276
    i = font_bc(f);
 
1277
    while (i < font_ec(f)) {
 
1278
        i = undump_charinfo(f);
 
1279
    }
1093
1280
}
1094