w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

bifont.c
Go to the documentation of this file.
1 /*
2  * built-in font
3  */
4 
5 #include "defs.h"
6 #include "global.h"
7 #include "bifont.h"
8 #include "jsub.h"
9 #ifdef KPATHSEA
10 #include <kpathsea/tex-file.h>
11 #include <kpathsea/pathsearch.h>
12 #endif
13 
14 /*
15  There are three kinds of tfm files, e.g.
16  Times-Roman.tfm, Courier.tfm, ...
17  XXjhira10.tfm, XXja10.tfm, ... (XX: japanese font)
18  XX.tfm, ... (jfm format, XX: japanese font)
19  The first one: (TYPE tfm)
20  easy.
21  The second one: (TYPE jstfm)
22  dev_font: assgined when XX first appears
23  dev_ku, dev_ten: calculated from j?? and charcode
24  The third one: (TYPE jfm)
25  easy, but tfmw information can be stored efficiently
26  by using jfm structure
27 */
28 
29 /* tfm_access, jstfm_access, jfm_access may be device dependent,
30  because not all devices allow arbitrary magnification. */
31 
32 int tfm_access();
34 int jfm_access();
38 
39 struct fontop tfmop = {
40  "tfm",
42  tfm_access,
44 };
45 
46 #ifdef UNDEF
47 struct fontop jstfmop = {
48  "jstfm",
52 };
53 #endif
54 
55 struct fontop jfmop = {
56  "jfm",
58  tfm_access,
60 };
61 
62 struct biaccessinfo biainfo;
63 
64 /* set by readtfm, readjfm */
65 static byte width[4*256];
66 static int id, nt, lh, bc, ec, nw;
67 #define JSTFMHEAD 4*2
68 static byte header[JSTFMHEAD];
69 
70 /* TYPE: tfm
71  */
72 tfm_access(proto, fe, acca)
73 char *proto;
74 struct font_entry *fe;
75 struct accarg *acca;
76 {
77  char *filename;
78  int ok;
79 
80 #ifdef KPATHSEA
81  filename = kpsearch_make(proto, fe->n, kpse_tfm_format, NULL, acca,
82  fe->name);
83  if (ok = (filename != NULL))
84  strcpy(fe->name, filename);
85 #else
86  pave(fe->name, proto, acca);
87  ok = access(fe->name, R_OK) == 0;
88 #endif
89 #ifdef DEBUG
90  if (Debuguser)
91  (void)fprintf(stderr, "trying to access %s\n", fe->name);
92 #endif
93  if (ok) {
94  fe->finfo = (struct finfo *)&biainfo;
95  return TRUE;
96  }
97  return FALSE;
98 }
99 
100 void
102 struct font_entry *fe;
103 {
104  int null_markchar();
106 
107  bfinfo(fe) = biaccinfo(fe)->bf;
108  openfontfile(fe);
109  if (checkjfm(fe->openfile)) {
110  fe->fnt_type = FT_JFM;
111  /*fe->base_fe->fnt_use = FU_USED;*/
112  fe->fnt_markchar = null_markchar;
114  } else {
115  fe->fnt_type = FT_TFM;
116  /*fe->base_fe->fnt_use = FU_USED;*/
117  fe->fnt_markchar = null_markchar;
119  }
120 }
121 
122 void
124 struct font_entry *fe;
125 {
126  FILE *fntfp;
127  struct tfmchar_entry *ce;
128  int i;
129  SCALED s;
130 
131  openfontfile(fe);
132  readtfm(fntfp = fe->openfile);
133  tfmfinfo(fe)->lastfntchar = ec;
134  s = (SCALED)fe->s;
135  for (i = bc, ce = (tfmfinfo(fe)->ch)+bc; i <= ec; i++, ce++) {
136  /* ce->dev_font = fe->k; /* Not used */
137  ce->dev_char = i;
138  ce->tfmw = scale(makeuint(width+4*getuint(fntfp,1),4), s);
139  (void)fseek(fntfp, 3L, SEEK_CUR);
140  }
141 }
142 
143 void
145 struct font_entry *fe;
146 {
147  struct tfmfntinfo *tfmfi;
148 
149  tfmfi = NEW(struct tfmfntinfo, "tfmfont info");
150  tfmfi->tfm_bf = bfinfo(fe);
151  tfmfinfo(fe) = tfmfi;
152  read_tfm_finfo(fe);
153  dev_tfm_initfe(fe);
155 }
156 
157 #ifdef UNDEF
158 /* ARGSUSED */
159 DEV_FONT
160 tfm_fontdict(fe, c)
161 struct font_entry *fe;
162 int c;
163 {
164  return fe->k;
165 }
166 #endif
167 
168 #ifdef UNDEF
169 /* TYPE: jstfm
170  */
171 struct jsubshare *jsubshares = NULL;
172 struct jsubshare **nextjss = &jsubshares;
173 
174 struct jsubshare *
175 getjsubshare(fe)
176 struct font_entry *fe;
177 {
178  int s;
179  struct jsubshare *jss;
180  struct bifont *jbf;
181 
182  s = fe->s;
183  jbf = biaccinfo(fe)->bf;
184  for (jss = jsubshares; jss != NULL; jss = jss->jss_next)
185  if (jss->jss_s == s && jss->jss_bf == jbf) {
186  return jss;
187  }
188  jss = NEW(struct jsubshare, "jsubshare");
189  jss->jss_s = s;
190  jss->jss_bf = jbf;
191  jss->jss_stat = JSS_CLOSED;
192  jss->jss_parent = strsave(dev_jstfm_parent(jbf, fe->n));
193  jss->jss_next = NULL;
194  *nextjss = jss;
195  nextjss = &(jss->jss_next);
196  return jss;
197 }
198 
199 jstfm_access(proto, fe, acca)
200 char *proto;
201 struct font_entry *fe;
202 struct accarg *acca;
203 {
204  int dev_is_jstfm();
205 
206  return gentfm_access(proto, fe, acca, dev_is_jstfm, "jstfm");
207 }
208 
209 void
211 struct font_entry *fe;
212 {
213  struct jstfmfntinfo *jsfi;
214  int null_markchar();
215  void read_jstfm_fontinfo();
217 
218  jsfi = NEW(struct jstfmfntinfo, "jstfmfont info");
219  jsfi->jsubfont = biaccinfo(fe)->jsubf;
220  jsfi->js_bf = biaccinfo(fe)->bf;
221  jsfi->js_share = getjsubshare(fe);
222  jstfmfinfo(fe) = jsfi;
223  switch (dev_jstfm_kind(fe)) {
224  case MF_KIND_PRINTER:
225  fe->fnt_markchar = null_markchar;
227  break;
228  case MF_KIND_TYPE1:
229  init_jswl_fontinfo(fe);
230  break;
231  case MF_KIND_FT:
232  case MF_KIND_FTO:
233  init_jsft_fontinfo(fe);
234  break;
235  case MF_KIND_VFLIB:
236  case MF_KIND_VFLIBO:
238  break;
239  default:
240  Fatal("%s implementation error: init_jstfm_fontinfo", G_progname);
241  }
242 }
243 
244 void
246 struct font_entry *fe;
247 {
248  FILE *fntfp;
249  struct jstfmchar_entry *ce;
250  int i;
251  SCALED s;
252  int subfont;
253 
254  openfontfile(fe);
255  readtfm(fntfp = fe->openfile);
256  if (lh <= 2 || makeuint(header, 4) != JSTFM_MAGIC)
257  Fatal("%s is not japanese subfont", fe->name);
258  subfont = header[JSTFMHEAD-1];
259  if (subfont != jstfmfinfo(fe)->jsubfont)
260  Warning("%s has subfont number %d", fe->name, subfont);
261  jstfmfinfo(fe)->lastfntchar = ec;
262  s = (SCALED)fe->s;
263  jstfmfinfo(fe)->em = scale(makeuint(param+4*5,4), s);
264  for (i = bc, ce = (jstfmfinfo(fe)->ch)+bc; i <= ec; i++, ce++) {
265  jsub_to_jis(subfont, i, &(ce->dev_ku), &(ce->dev_ten));
266  ce->tfmw = scale(makeuint(width+4*getuint(fntfp,1),4), s);
267  (void)fseek(fntfp, 3L, SEEK_CUR);
268  }
269  /* hack for space */
270  if (subfont == 1 && bc == 2) {
271  ce = (jstfmfinfo(fe)->ch)+bc-1;
272  jsub_to_jis(subfont, bc-1, &(ce->dev_ku), &(ce->dev_ten));
273  ce->tfmw = (ce+1)->tfmw;
274  }
275 }
276 
277 void
279 struct font_entry *fe;
280 {
281  struct jsubshare *jss;
282 
283  read_jstfm_finfo(fe);
284  dev_jstfm_initfe(fe);
285  jss = jstfmfinfo(fe)->js_share;
286  if (jss->jss_stat < JSS_READ) {
288  jss->jss_stat = JSS_READ;
289  }
290  jstfmfinfo(fe)->dev_font = jss->jss_dev_font;
291 }
292 
293 /* ARGSUSED */
294 DEV_FONT
295 jstfm_fontdict(fe, c)
296 struct font_entry *fe;
297 int c;
298 {
299  return jstfmfinfo(fe)->dev_font;
300 }
301 #endif
302 
303 /* TYPE: jfm
304  */
305 #ifdef UNDEF
306 jfm_access(proto, fe, acca)
307 char *proto;
308 struct font_entry *fe;
309 struct accarg *acca;
310 {
311  int dev_is_jfm();
312 
313  return gentfm_access(proto, fe, acca, dev_is_jfm, "jfm");
314 }
315 #endif
316 
317 void
319 struct font_entry *fe;
320 {
321  int null_markchar();
322  void read_jfm_fontinfo();
323 
324  bfinfo(fe) = biaccinfo(fe)->bf;
325  fe->fnt_type = FT_JFM;
326  /*fe->base_fe->fnt_use = FU_USED;*/
327  fe->fnt_markchar = null_markchar;
329 }
330 
331 void
333 struct font_entry *fe;
334 {
335  FILE *fntfp;
336  struct jfmtype_entry *te;
337  struct jfmchar_entry *ce;
338  int i;
339  SCALED s;
340 
341  openfontfile(fe);
342  if (!readjfm(fntfp = fe->openfile))
343  Fatal("%s is not jfm file", fe->name);
344  jfmfinfo(fe)->nctype = nt;
345  jfmfinfo(fe)->ctype = NEWTAB(struct jfmtype_entry, nt, "jfmtype table");
346  for (i = 0, te = jfmfinfo(fe)->ctype; i < nt; i++, te++) {
347  te->jfm_code = getuint(fntfp, 2);
348  te->jfm_type = getuint(fntfp, 2);
349  }
350  jfmfinfo(fe)->lasttypecode = (te-1)->jfm_code;
351  jfmfinfo(fe)->ch = NEWTAB(struct jfmchar_entry, ec+1, "jfmchar table");
352  s = (SCALED)fe->s;
353  for (i = bc, ce = (jfmfinfo(fe)->ch)+bc; i <= ec; i++, ce++) {
354  ce->tfmw = scale(makeuint(width+4*getuint(fntfp,1),4), s);
355  (void)fseek(fntfp, 3L, SEEK_CUR);
356  }
357 }
358 
359 void
361 struct font_entry *fe;
362 {
363  struct jfmfntinfo *jfmfi;
364 
365  jfmfi = NEW(struct jfmfntinfo, "jfmfont info");
366  jfmfi->jfm_bf = bfinfo(fe);
367  jfmfinfo(fe) = jfmfi;
368  read_jfm_finfo(fe);
369  dev_jfm_initfe(fe, id);
371 }
372 
373 getctype(c, jfmfi)
374 int c;
375 struct jfmfntinfo *jfmfi;
376 {
377  int m;
378  int left, right;
379  struct jfmtype_entry *te;
380  int code;
381 
382  if (c > jfmfi->lasttypecode)
383  return 0;
384  for (left = 0, right = jfmfi->nctype, te = jfmfi->ctype; left <= right;) {
385  m = (left+right)/2;
386  if (c < (code = (te+m)->jfm_code))
387  right = m-1;
388  else if (c > code)
389  left = m+1;
390  else if (c == code)
391  return (te+m)->jfm_type;
392  }
393  return 0;
394 }
395 
396 
397 /* utilities
398  */
400 {
401  (void)fseek(fntfp, 2L, SEEK_SET); /* lf */
402  lh = getuint(fntfp, 2);
403  bc = getuint(fntfp, 2);
404  ec = getuint(fntfp, 2);
405  nw = getuint(fntfp, 2);
406  (void)fseek(fntfp, 8*4L, SEEK_SET);
407  getbytes(fntfp, header, (lh-2)*4 > JSTFMHEAD ? JSTFMHEAD : (lh-2)*4);
408  (void)fseek(fntfp, (6+lh+(ec-bc)+1)*4L, SEEK_SET);
409  getbytes(fntfp, width, 4*nw);
410  (void)fseek(fntfp, (6+lh)*4L, SEEK_SET); /* ready to read char_info */
411  return 0;
412 }
413 
415 {
416  int id;
417 
418  if ((id=getuint(fntfp, 2)) != JFM_ID && id != TJFM_ID)
419  return FALSE;
420  return TRUE;
421 }
422 
424 {
425  if ((id=getuint(fntfp, 2)) != JFM_ID && id != TJFM_ID)
426  return FALSE;
427  nt = getuint(fntfp, 2);
428  (void)fseek(fntfp, 2L, SEEK_CUR); /* lf */
429  lh = getuint(fntfp, 2);
430  bc = getuint(fntfp, 2); /* bc should be 0 */
431  ec = getuint(fntfp, 2);
432  nw = getuint(fntfp, 2);
433  (void)fseek(fntfp, (7+lh+nt+(ec-bc)+1)*4L, SEEK_SET);
434  getbytes(fntfp, width, 4*nw);
435  (void)fseek(fntfp, (7+lh)*4L, SEEK_SET); /* ready to read char_type and char_info */
436  return TRUE;
437 }
int code
Definition: aftopl.c:52
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
void Warning(const char *sb1, const char *sb2)
Definition: detex.c:4677
int jstfm_access()
checkjfm(FILE *fntfp)
Definition: bifont.c:414
void read_jfm_finfo(struct font_entry *fe)
Definition: bifont.c:332
struct fontop tfmop
Definition: bifont.c:39
struct fontop jfmop
Definition: bifont.c:55
void init_jfm_fontinfo()
static int ec
Definition: bifont.c:66
static int nw
Definition: bifont.c:66
void init_tfm_fontinfo()
static int id
Definition: bifont.c:66
void read_tfm_fontinfo(struct font_entry *fe)
Definition: bifont.c:144
getctype(int c, struct jfmfntinfo *jfmfi)
Definition: bifont.c:373
void init_jstfm_fontinfo()
struct biaccessinfo biainfo
Definition: bifont.c:62
readtfm(FILE *fntfp)
Definition: bifont.c:399
static int bc
Definition: bifont.c:66
static int nt
Definition: bifont.c:66
void read_tfm_finfo(struct font_entry *fe)
Definition: bifont.c:123
readjfm(FILE *fntfp)
Definition: bifont.c:423
static int lh
Definition: bifont.c:66
int jfm_access()
void read_jfm_fontinfo(struct font_entry *fe)
Definition: bifont.c:360
int tfm_access()
#define JSTFMHEAD
Definition: bifont.c:67
static byte width[4 *256]
Definition: bifont.c:65
int dev_is_jfm()
#define TJFM_ID
Definition: bifont.h:45
#define biaccinfo(fe)
Definition: bifont.h:172
#define JSS_READ
Definition: bifont.h:142
#define bfinfo(fe)
Definition: bifont.h:174
#define jstfmfinfo(fe)
Definition: bifont.h:40
#define jfmfinfo(fe)
Definition: bifont.h:67
#define JSS_CLOSED
Definition: bifont.h:140
int dev_is_jstfm()
#define tfmfinfo(fe)
Definition: bifont.h:18
#define JFM_ID
Definition: bifont.h:44
int dev_jstfm_kind()
#define Debuguser
Definition: defs.h:88
#define R_OK
Definition: defs.h:31
#define NEWTAB(A, n, e)
Definition: defs.h:145
#define FT_JFM
Definition: defs.h:185
#define FT_TFM
Definition: defs.h:184
int SCALED
Definition: defs.h:158
char * G_progname
Definition: dvi2.c:77
null_markchar(struct font_entry *fe, int c)
Definition: fontcom.c:150
pathtype_init(char *proto, struct funcfont **ff)
Definition: fontdesc.c:521
void pave(char *path, char *proto, struct accarg *acca)
Definition: fontdesc.c:946
void openfontfile()
int getuint()
void Fatal()
int makeuint()
char * strsave()
#define JSTFM_MAGIC
Definition: jsub.h:4
void jsub_to_jis(short f, short c, unsigned short *ku, unsigned short *ten)
Definition: kanji.c:80
#define fseek
Definition: xxstdio.h:30
struct fontop jstfmop
Definition: bifont.c:45
gentfm_access(char *proto, struct font_entry *fe, struct accarg *acca, int *dev_is_format, char *type)
Definition: bifont.c:70
DEV_FONT jstfm_fontdict(struct font_entry *fe, int c)
Definition: bifont.c:315
static byte param[4 *32]
Definition: bifont.c:63
struct jsubshare * jsubshares
Definition: bifont.c:190
struct jsubshare * getjsubshare(struct font_entry *fe)
Definition: bifont.c:194
struct jsubshare ** nextjss
Definition: bifont.c:191
DEV_FONT tfm_fontdict(struct font_entry *fe, int c)
Definition: bifont.c:181
void read_jstfm_fontinfo(struct font_entry *fe)
Definition: bifont.c:298
void read_jstfm_finfo(struct font_entry *fe)
Definition: bifont.c:265
#define MF_KIND_PRINTER
Definition: bifont.h:181
#define MF_KIND_TYPE1
Definition: bifont.h:182
#define MF_KIND_VFLIB
Definition: bifont.h:185
#define MF_KIND_FT
Definition: bifont.h:183
#define MF_KIND_FTO
Definition: bifont.h:184
#define MF_KIND_VFLIBO
Definition: bifont.h:186
char * strcpy()
dev_jfm_initfe(struct font_entry *fe, int id)
Definition: dvitfm.c:157
dev_tfm_initfe(struct font_entry *fe)
Definition: dvitfm.c:15
dev_jfm_initfontdict(struct font_entry *fe)
Definition: dvitfm.c:152
dev_tfm_initfontdict(struct font_entry *fe)
Definition: dvitfm.c:10
static void
Definition: fpif.c:118
#define s
Definition: afcover.h:80
static FILE * fntfp
Definition: gffont.c:22
#define c(n)
Definition: gpos-common.c:150
#define SEEK_SET
Definition: jmemansi.c:26
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
for(n=0;n< outline->n_points;n++)
Definition: ftbbox.c:494
#define SCALED(x)
#define SEEK_CUR
Definition: ftzconf.h:250
@ right
Definition: annotate.c:15
#define NEW
Definition: gdkanji.c:77
@ kpse_tfm_format
Definition: types.h:106
#define access
Definition: win32lib.h:59
#define fprintf
Definition: mendex.h:64
dictionary ce
static int getbytes(FILE *fptr, int width, unsigned char *data)
Definition: pbm.c:49
char * filename[256]
Definition: pbmtopk.c:46
double scale
Definition: pnmhistmap.c:38
char * dev_jstfm_parent(struct bifont *bf, char *name)
Definition: psbi.c:575
void dev_jstfm_initfe(struct font_entry *fe)
Definition: pstfm.c:121
void dev_jstfm_initfontdict(struct font_entry *fe)
Definition: pstfm.c:107
lft_cell * left
Definition: routines.h:73
Definition: defs.h:253
Definition: psbi.c:77
Definition: inftrees.h:24
Definition: ffi.h:327
Definition: defs.h:190
char fnt_type
Definition: defs.h:194
char n[257]
Definition: defs.h:193
FILE * openfile
Definition: defs.h:208
int s
Definition: defs.h:192
void(* fnt_readfontinfo)()
Definition: defs.h:199
char name[1024]
Definition: defs.h:207
struct finfo * finfo
Definition: defs.h:205
int k
Definition: defs.h:191
Definition: defs.h:234
Definition: bifont.h:52
int nctype
Definition: bifont.h:58
struct bifont * jfm_bf
Definition: bifont.h:57
struct jfmtype_entry * ctype
Definition: bifont.h:59
int lasttypecode
Definition: bifont.h:60
Definition: bifont.h:47
int jfm_code
Definition: bifont.h:48
int jfm_type
Definition: bifont.h:49
Definition: bifont.h:22
int tfmw
Definition: bifont.h:24
short jsubfont
Definition: bifont.h:31
struct bifont * js_bf
Definition: bifont.h:28
struct jsubshare * js_share
Definition: bifont.h:34
char * jss_parent
Definition: bifont.h:151
struct jsubshare * jss_next
Definition: bifont.h:150
struct bifont * jss_bf
Definition: bifont.h:146
int jss_s
Definition: bifont.h:147
int jss_dev_font
Definition: bifont.h:148
int jss_stat
Definition: bifont.h:145
Definition: bifont.h:4
struct bifont * tfm_bf
Definition: bifont.h:10
#define FILE
Definition: t1stdio.h:34
ch
Definition: t4ht.c:1443
m
Definition: tex4ht.c:3990
void init_jsft_fontinfo(struct font_entry *fe)
Definition: ttfont.c:705
void init_jsvfl_fontinfo(struct font_entry *fe)
Definition: vflfont.c:262
void init_jswl_fontinfo(struct font_entry *fe)
Definition: wlfont.c:160