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
|
#include <kpathsea/kpathsea.h>
#include "makejvf.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int nt,nl,unit,zh,zw,jfm_id,rightamount;
int *width,*height,*depth,*italic,*kern,*glue,*param;
unsigned char *header,*char_type,*char_info,*glue_kern;
int jfmread(int kcode)
{
int i,ctype=0,w_ind,w,ll=0,rr=0,tag,gk_ind,gk2_ind;
for (i = 0 ; i < nt ; i++) {
/* support new JFM spec by texjporg */
if (upair(&char_type[i*4])+char_type[i*4+2]*65536 == kcode) {
ctype = char_type[i*4+3];
break;
}
}
/* get character width of <kcode> */
w_ind = char_info[ctype*4];
w = width[w_ind];
rightamount = 0;
if (enhanced && w != zw && ctype > 0) {
/* get natural length of JFM glue between <type0> and <type of kcode> */
tag = char_info[0*4+2] % 4;
if (tag == 1) {
gk_ind = char_info[0*4+3]; /* remainder for <type0> */
if (glue_kern[gk_ind*4] > 128) /* huge gluekern table rearranged */
gk_ind = upair(&glue_kern[gk_ind*4+2]);
for (i = 0 ; i < nl-gk_ind ; i++) {
/* if rearrangement already handled ... */
if (glue_kern[(gk_ind+i)*4] > 128) break; /* ... skip loop */
if (glue_kern[(gk_ind+i)*4+1] == ctype) {
if (glue_kern[(gk_ind+i)*4+2] >= 128) {
gk2_ind = glue_kern[(gk_ind+i)*4+3];
ll = kern[gk2_ind];
}
else {
gk2_ind = glue_kern[(gk_ind+i)*4+3];
ll = glue[3*gk2_ind];
}
break;
}
if (glue_kern[(gk_ind+i)*4] >= 128) /* end of program */
break;
else /* SKIP */
i += glue_kern[(gk_ind+i)*4];
}
}
/* get natural length of JFM glue between <type of kcode> and <type0> */
tag = char_info[ctype*4+2] % 4;
if (tag == 1) {
gk_ind = char_info[ctype*4+3]; /* remainder for <type of kcode> */
if (glue_kern[gk_ind*4] > 128) /* huge gluekern table rearranged */
gk_ind = upair(&glue_kern[gk_ind*4+2]);
for (i = 0 ; i < nl-gk_ind ; i++) {
/* if rearrangement already handled ... */
if (glue_kern[(gk_ind+i)*4] > 128) break; /* ... skip loop */
if (glue_kern[(gk_ind+i)*4+1] == 0) {
if (glue_kern[(gk_ind+i)*4+2] >= 128) {
gk2_ind = glue_kern[(gk_ind+i)*4+3];
rr = kern[gk2_ind];
}
else {
gk2_ind = glue_kern[(gk_ind+i)*4+3];
rr = glue[3*gk2_ind];
}
break;
}
if (glue_kern[(gk_ind+i)*4] >= 128) /* end of program */
break;
else /* SKIP */
i += glue_kern[(gk_ind+i)*4];
}
}
if (abs(zw - ll - w - rr) <= 1) /* allow round-off error */
/* character width is truncated,
and metric glue/kern is inserted as a substitute to fill zenkaku */
rightamount = ll;
else
/* character width is actually truncated */
rightamount = (zw - w)/2;
}
return(w);
}
int tfmget(char *name)
{
char *nbuff;
FILE *fp;
nbuff = xmalloc(strlen(name)+4+1);
strcpy(nbuff,name);
strcat(nbuff,".tfm");
fp = fopen(nbuff,"rb");
if (fp == NULL) {
fp = fopen(name,"rb"); /* just in case ... */
if (fp == NULL) {
fprintf(stderr,"Cannot open %s for input.\n",nbuff);
exit(1);
}
}
tfmidx(fp);
fclose(fp);
free(nbuff);
return 0;
}
int tfmidx(FILE *fp)
{
int i;
int lh,ec,nw,nh,nd,ni,nk,ng,np;
jfm_id = fpair(fp);
if ((jfm_id == 9) || (jfm_id == 11)) {
nt = ufpair(fp);
fpair(fp);
lh = ufpair(fp);
fpair(fp);
ec = ufpair(fp);
nw = ufpair(fp);
nh = ufpair(fp);
nd = ufpair(fp);
ni = ufpair(fp);
nl = ufpair(fp);
nk = ufpair(fp);
ng = ufpair(fp);
np = ufpair(fp);
header = xmalloc(lh*4);
for (i = 0 ; i < lh*4 ; i++) {
header[i] = (char)fgetc(fp);
}
char_type = xmalloc(nt*4);
for (i = 0 ; i < nt*4 ; i++) {
char_type[i] = (char)fgetc(fp);
}
char_info = xmalloc((ec+1)*4);
for (i = 0 ; i < (ec+1)*4 ; i++) {
char_info[i] = (char)fgetc(fp);
}
width = xmalloc(nw*sizeof(int));
for (i = 0 ; i < nw ; i++) {
width[i] = fquad(fp);
}
height = xmalloc(nh*sizeof(int));
for (i = 0 ; i < nh ; i++) {
height[i] = fquad(fp);
}
depth = xmalloc(nd*sizeof(int));
for (i = 0 ; i < nd ; i++) {
depth[i] = fquad(fp);
}
italic = xmalloc(ni*sizeof(int));
for (i = 0 ; i < ni ; i++) {
italic[i] = fquad(fp);
}
glue_kern = xmalloc(nl*4);
for (i = 0 ; i < nl*4 ; i++) {
glue_kern[i] = (char)fgetc(fp);
}
kern = xmalloc(nk*sizeof(int));
for (i = 0 ; i < nk ; i++) {
kern[i] = fquad(fp);
}
glue = xmalloc(ng*sizeof(int));
for (i = 0 ; i < ng ; i++) {
glue[i] = fquad(fp);
}
param = xmalloc(np*sizeof(int));
for (i = 0 ; i < np ; i++) {
param[i] = fquad(fp);
}
unit = mquad(&header[4]);
zh = param[4];
zw = param[5];
if (baseshift)
baseshift = (int)(zh*baseshift/1000.0+0.5);
}
else {
fprintf(stderr,"This TFM is not for Japanese.\n");
exit(100);
}
return 0;
}
|