1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
/*
* ligkern.c
*
* This file is part of the ttf2pk package.
*
* Copyright 1997-1999, 2000 by
* Frederic Loyer <loyer@ensta.fr>
* Werner Lemberg <wl@gnu.org>
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stddef.h> /* for size_t */
#include <ctype.h>
#include "ttf2tfm.h"
#include "ligkern.h"
#include "ttfenc.h"
#include "texenc.h"
#include "newobj.h"
#include "errormsg.h"
static char *
paramstring(char **curp)
{
register char *p, *q;
p = *curp;
while (*p && !isspace((unsigned char)*p))
p++;
q = *curp;
if (*p != '\0')
*p++ = '\0';
while (isspace((unsigned char)*p))
p++;
*curp = p;
return q;
}
/*
* Some routines to remove kerns that match certain patterns.
*/
static kern *
rmkernmatch(kern *k,
char *s)
{
kern *nk;
while (k && strcmp(k->succ, s) == 0)
k = k->next;
if (k)
{
for (nk = k; nk; nk = nk->next)
while (nk->next && strcmp(nk->next->succ, s) == 0)
nk->next = nk->next->next;
}
return k;
}
/*
* Recursive to one level.
*/
static void
rmkern(char *s1, char *s2,
ttfinfo *ti,
Font *fnt)
{
if (ti == NULL)
{
if (strcmp(s1, "*") == 0)
{
for (ti = fnt->charlist; ti; ti = ti->next)
rmkern(s1, s2, ti, fnt);
return;
}
else
{
ti = findadobe(s1, fnt->charlist);
if (ti == NULL)
return;
}
}
if (strcmp(s2, "*") == 0)
ti->kerns = NULL; /* drop them on the floor */
else
ti->kerns = rmkernmatch(ti->kerns, s2);
}
/*
* Make the kerning for character S1 equivalent to that for S2.
* If either S1 or S2 do not exist, do nothing.
* If S1 already has kerning, do nothing.
*/
static void
addkern(char *s1, char *s2,
Font *fnt)
{
ttfinfo *ti1 = findadobe(s1, fnt->charlist);
ttfinfo *ti2 = findadobe(s2, fnt->charlist);
if (ti1 && ti2 && !ti1->kerns)
{
/* Put the new one at the head of the list, since order is immaterial. */
ttfptr *ap = (ttfptr *)mymalloc(sizeof (ttfptr));
ap->next = ti2->kern_equivs;
ap->ch = ti1;
ti2->kern_equivs = ap;
}
}
/*
* Reads a ligkern line, if this is one. Assumes the first character
* passed is `%'.
*/
void
checkligkern(char *s, Font *fnt)
{
char *mlist[5];
char *os;
char *orig_s, *pos;
size_t offset[5];
int n;
os = newstring(s);
orig_s = s;
s++;
while (isspace((unsigned char)*s))
s++;
if (strncmp(s, "LIGKERN", 7) == 0)
{
fnt->sawligkern = True;
s += 7;
while (isspace((unsigned char)*s))
s++;
pos = s;
while (*pos)
{
for (n = 0; n < 5;)
{
if (*pos == '\0')
break;
offset[n] = pos - orig_s;
mlist[n] = paramstring(&pos);
if (strcmp(mlist[n], ";") == 0)
break;
n++;
}
if (n > 4)
boops(os, pos - orig_s, "Too many parameters in lig kern data.");
if (n < 3)
boops(os, pos - orig_s, "Too few parameters in lig kern data.");
if (n == 3 && strcmp(mlist[1], "{}") == 0) /* rmkern command */
rmkern(mlist[0], mlist[2], (ttfinfo *)0, fnt);
else if (n == 3 && strcmp(mlist[1], "<>") == 0) /* addkern */
addkern(mlist[0], mlist[2], fnt);
else if (n == 3 && strcmp(mlist[0], "||") == 0 &&
strcmp(mlist[1], "=") == 0) /* bc command */
{
ttfinfo *ti = findadobe("||", fnt->charlist);
if (fnt->boundarychar != -1)
boops(os, offset[0], "Multiple boundary character commands?");
if (sscanf(mlist[2], "%d", &n) != 1)
boops(os, offset[2],
"Expected number assignment for boundary char.");
if (n < 0 || n > 0xFF)
boops(os, offset[2], "Boundary character number must be 0..0xFF.");
fnt->boundarychar = n;
if (ti == NULL)
oops("Internal error: boundary char.");
ti->outcode = n; /* prime the pump, so to speak, for lig/kerns */
}
else if (n == 4)
{
int op = -1;
ttfinfo *ti;
for (n = 0; encligops[n]; n++)
if (strcmp(mlist[2], encligops[n]) == 0)
{
op = n;
break;
}
if (op < 0)
boops(os, offset[2], "Bad ligature op specified.");
if (NULL != (ti = findadobe(mlist[0], fnt->charlist)))
{
lig *lig;
if (findadobe(mlist[1], fnt->charlist))
/* remove coincident kerns */
rmkern(mlist[0], mlist[1], ti, fnt);
if (strcmp(mlist[3], "||") == 0)
boops(os, offset[3], "You can't lig to the boundary character!");
if (!fnt->fixedpitch) /* fixed pitch fonts get *0* ligs */
{
for (lig = ti->ligs; lig; lig = lig->next)
if (strcmp(lig->succ, mlist[1]) == 0)
break; /* we'll re-use this structure */
if (lig == NULL)
{
lig = newlig();
lig->succ = newstring(mlist[1]);
lig->next = ti->ligs;
ti->ligs = lig;
}
lig->sub = newstring(mlist[3]);
lig->op = op;
if (strcmp(mlist[1], "||") == 0)
{
lig->boundleft = 1;
if (strcmp(mlist[0], "||") == 0)
boops(os, offset[0],
"You can't lig boundarychar boundarychar!");
}
else
lig->boundleft = 0;
}
}
}
else
boops(os, offset[0], "Bad form in LIGKERN command.");
}
}
free(os);
}
void
getligkerndefaults(Font *fnt)
{
int i;
char *buffer;
for (i = 0; staticligkern[i]; i++)
{
buffer = newstring(staticligkern[i]);
checkligkern(buffer, fnt);
free(buffer);
}
}
/* end */
|