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 #endif
12 
13 /*
14  There are three kinds of tfm files, e.g.
15  Times-Roman.tfm, Courier.tfm, ...
16  XXjhira10.tfm, XXja10.tfm, ... (XX: japanese font)
17  XX.tfm, ... (jfm format, XX: japanese font)
18  The first one: (TYPE tfm)
19  easy.
20  The second one: (TYPE jstfm)
21  dev_font: assgined when XX first appears
22  dev_ku, dev_ten: calculated from j?? and charcode
23  The third one: (TYPE jfm)
24  easy, but tfmw information can be stored efficiently
25  by using jfm structure
26 */
27 
28 /* tfm_access, jstfm_access, jfm_access may be device dependent,
29  because not all devices allow arbitrary magnification. */
30 
31 int tfm_access();
33 int jfm_access();
37 
38 struct fontop tfmop = {
39  "tfm",
41  tfm_access,
43 };
44 
45 struct fontop jstfmop = {
46  "jstfm",
50 };
51 
52 struct fontop jfmop = {
53  "jfm",
55  jfm_access,
57 };
58 
59 struct biaccessinfo biainfo;
60 
61 /* set by readtfm, readjfm */
62 static byte width[4*256];
63 static byte param[4*32];
64 static int id, nt, lh, bc, ec, nw, np;
65 #define JSTFMHEAD 4*2
66 static byte header[JSTFMHEAD];
67 
68 /* generic template for tfm access
69  */
70 gentfm_access(proto, fe, acca, dev_is_format, type)
71 char *proto;
72 struct font_entry *fe;
73 struct accarg *acca;
74 int (*dev_is_format)();
75 char *type;
76 {
77  char *filename;
78  __BOOLEAN__ 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) %s\n", type, fe->name);
92 #endif
93  if (ok) {
94  /* used to pass information set in dev_is_format to init_FF_fontinfo */
95  fe->finfo = (struct finfo *)&biainfo;
96  return dev_is_format(fe, acca->acc_mode);
97  }
98  return FALSE;
99 }
100 
101 /* TYPE: tfm
102  */
103 tfm_access(proto, fe, acca)
104 char *proto;
105 struct font_entry *fe;
106 struct accarg *acca;
107 {
108  int dev_is_tfm();
109 
110  return gentfm_access(proto, fe, acca, dev_is_tfm, "tfm");
111 }
112 
113 void
115 struct font_entry *fe;
116 {
117  int null_markchar();
118  void read_tfm_fontinfo();
119  void init_t1_fontinfo();
120 
121  switch (dev_tfm_kind(fe)) {
122  case MF_KIND_PRINTER:
123  bfinfo(fe) = biaccinfo(fe)->bf;
124  fe->fnt_markchar = null_markchar;
126  break;
127  case MF_KIND_TYPE1:
128  init_t1_fontinfo(fe);
129  break;
130  case MF_KIND_FT:
131  case MF_KIND_FTO:
132  init_ft_fontinfo(fe);
133  break;
134  default:
135  Fatal("%s implementation error: init_tfm_fontinfo", G_progname);
136  }
137 }
138 
139 /* forward decl */
140 void readtfm(FILE *fntfp);
141 
142 void
144 struct font_entry *fe;
145 {
146  FILE *fntfp;
147  struct tfmchar_entry *ce;
148  int i;
149  SCALED s;
150 
151  openfontfile(fe);
152  readtfm(fntfp = fe->openfile);
153  tfmfinfo(fe)->lastfntchar = ec;
154  s = (SCALED)fe->s;
155  tfmfinfo(fe)->em = scale(makeuint(param+4*5,4), s);
156  for (i = bc, ce = (tfmfinfo(fe)->ch)+bc; i <= ec; i++, ce++) {
157  /* ce->dev_font = fe->k; /* Not used */
158  ce->dev_char = i;
159  ce->tfmw = scale(makeuint(width+4*getuint(fntfp,1),4), s);
160  (void)fseek(fntfp, 3L, SEEK_CUR);
161  }
162 }
163 
164 void
166 struct font_entry *fe;
167 {
168  struct tfmfntinfo *tfmfi;
169 
170  tfmfi = NEW(struct tfmfntinfo, "tfmfont info");
171  tfmfi->tfm_bf = bfinfo(fe);
172  tfmfinfo(fe) = tfmfi;
173  read_tfm_finfo(fe);
174  dev_tfm_initfe(fe);
175  (void)enc_read(tfmfi->tfm_bf);
177 }
178 
179 /* ARGSUSED */
180 DEV_FONT
182 struct font_entry *fe;
183 int c;
184 {
185  return fe->k;
186 }
187 
188 /* TYPE: jstfm
189  */
192 
193 struct jsubshare *
195 struct font_entry *fe;
196 {
197  int s;
198  struct jsubshare *jss;
199  struct bifont *jbf;
200  char *dev_jstfm_parent();
201 
202  s = fe->s;
203  jbf = biaccinfo(fe)->bf;
204  for (jss = jsubshares; jss != NULL; jss = jss->jss_next)
205  if (jss->jss_s == s && jss->jss_bf == jbf) {
206  return jss;
207  }
208  jss = NEW(struct jsubshare, "jsubshare");
209  jss->jss_s = s;
210  jss->jss_bf = jbf;
211  jss->jss_stat = JSS_CLOSED;
212  jss->jss_parent = strsave(dev_jstfm_parent(jbf, fe->n));
213  jss->jss_next = NULL;
214  *nextjss = jss;
215  nextjss = &(jss->jss_next);
216  return jss;
217 }
218 
219 jstfm_access(proto, fe, acca)
220 char *proto;
221 struct font_entry *fe;
222 struct accarg *acca;
223 {
224  int dev_is_jstfm();
225 
226  return gentfm_access(proto, fe, acca, dev_is_jstfm, "jstfm");
227 }
228 
229 void
231 struct font_entry *fe;
232 {
233  struct jstfmfntinfo *jsfi;
234  int null_markchar();
235  void read_jstfm_fontinfo();
237 
238  jsfi = NEW(struct jstfmfntinfo, "jstfmfont info");
239  jsfi->jsubfont = biaccinfo(fe)->jsubf;
240  jsfi->js_bf = biaccinfo(fe)->bf;
241  jsfi->js_share = getjsubshare(fe);
242  jstfmfinfo(fe) = jsfi;
243  switch (dev_jstfm_kind(fe)) {
244  case MF_KIND_PRINTER:
245  fe->fnt_markchar = null_markchar;
247  break;
248  case MF_KIND_TYPE1:
249  init_jswl_fontinfo(fe);
250  break;
251  case MF_KIND_FT:
252  case MF_KIND_FTO:
253  init_jsft_fontinfo(fe);
254  break;
255  case MF_KIND_VFLIB:
256  case MF_KIND_VFLIBO:
258  break;
259  default:
260  Fatal("%s implementation error: init_jstfm_fontinfo", G_progname);
261  }
262 }
263 
264 void
266 struct font_entry *fe;
267 {
268  FILE *fntfp;
269  struct jstfmchar_entry *ce;
270  int i;
271  SCALED s;
272  int subfont;
273 
274  openfontfile(fe);
275  readtfm(fntfp = fe->openfile);
276  if (lh <= 2 || makeuint(header, 4) != JSTFM_MAGIC)
277  Fatal("%s is not japanese subfont", fe->name);
278  subfont = header[JSTFMHEAD-1];
279  if (subfont != jstfmfinfo(fe)->jsubfont)
280  Warning("%s has subfont number %d", fe->name, subfont);
281  jstfmfinfo(fe)->lastfntchar = ec;
282  s = (SCALED)fe->s;
283  jstfmfinfo(fe)->em = scale(makeuint(param+4*5,4), s);
284  for (i = bc, ce = (jstfmfinfo(fe)->ch)+bc; i <= ec; i++, ce++) {
285  jsub_to_jis(subfont, i, &(ce->dev_ku), &(ce->dev_ten));
286  ce->tfmw = scale(makeuint(width+4*getuint(fntfp,1),4), s);
287  (void)fseek(fntfp, 3L, SEEK_CUR);
288  }
289  /* hack for space */
290  if (subfont == 1 && bc == 2) {
291  ce = (jstfmfinfo(fe)->ch)+bc-1;
292  jsub_to_jis(subfont, bc-1, &(ce->dev_ku), &(ce->dev_ten));
293  ce->tfmw = (ce+1)->tfmw;
294  }
295 }
296 
297 void
299 struct font_entry *fe;
300 {
301  struct jsubshare *jss;
302 
303  read_jstfm_finfo(fe);
304  dev_jstfm_initfe(fe);
305  jss = jstfmfinfo(fe)->js_share;
306  if (jss->jss_stat < JSS_READ) {
308  jss->jss_stat = JSS_READ;
309  }
310  jstfmfinfo(fe)->dev_font = jss->jss_dev_font;
311 }
312 
313 /* ARGSUSED */
314 DEV_FONT
316 struct font_entry *fe;
317 int c;
318 {
319  return jstfmfinfo(fe)->dev_font;
320 }
321 
322 /* TYPE: jfm
323  */
324 jfm_access(proto, fe, acca)
325 char *proto;
326 struct font_entry *fe;
327 struct accarg *acca;
328 {
329  int dev_is_jfm();
330 
331  return gentfm_access(proto, fe, acca, dev_is_jfm, "jfm");
332 }
333 
334 void
336 struct font_entry *fe;
337 {
338  int null_markchar();
339  void read_jfm_fontinfo();
341 
342  switch (dev_jfm_kind(fe)) {
343  case MF_KIND_PRINTER:
344  bfinfo(fe) = biaccinfo(fe)->bf;
345  fe->fnt_markchar = null_markchar;
347  break;
348  case MF_KIND_TYPE1:
349  init_wl_fontinfo(fe);
350  break;
351  case MF_KIND_FT:
352  case MF_KIND_FTO:
353  init_jft_fontinfo(fe);
354  break;
355  case MF_KIND_VFLIB:
356  case MF_KIND_VFLIBO:
357  init_vfl_fontinfo(fe);
358  break;
359  default:
360  Fatal("%s implementation error: init_jfm_fontinfo", G_progname);
361  }
362 }
363 
364 void
366 struct font_entry *fe;
367 {
368  FILE *fntfp;
369  struct jfmtype_entry *te;
370  struct jfmchar_entry *ce;
371  int i;
372  SCALED s;
373 
374  openfontfile(fe);
375  if (!readjfm(fntfp = fe->openfile))
376  Fatal("%s is not jfm file", fe->name);
377  jfmfinfo(fe)->nctype = nt;
378  jfmfinfo(fe)->ctype = NEWTAB(struct jfmtype_entry, nt, "jfmtype table");
379  for (i = 0, te = jfmfinfo(fe)->ctype; i < nt; i++, te++) {
380  te->jfm_code = getuint(fntfp, 2);
381  te->jfm_type = getuint(fntfp, 2);
382  }
383  jfmfinfo(fe)->lasttypecode = (te-1)->jfm_code;
384  jfmfinfo(fe)->ch = NEWTAB(struct jfmchar_entry, ec+1, "jfmchar table");
385  s = (SCALED)fe->s;
386  jfmfinfo(fe)->em = scale(makeuint(param+4*5,4), s);
387  for (i = bc, ce = (jfmfinfo(fe)->ch)+bc; i <= ec; i++, ce++) {
388  ce->tfmw = scale(makeuint(width+4*getuint(fntfp,1),4), s);
389  (void)fseek(fntfp, 3L, SEEK_CUR);
390  }
391 }
392 
393 void
395 struct font_entry *fe;
396 {
397  struct jfmfntinfo *jfmfi;
398 
399  jfmfi = NEW(struct jfmfntinfo, "jfmfont info");
400  jfmfi->jfm_bf = bfinfo(fe);
401  jfmfinfo(fe) = jfmfi;
402  read_jfm_finfo(fe);
403  dev_jfm_initfe(fe, id);
405 }
406 
407 getctype(c, jfmfi)
408 int c;
409 struct jfmfntinfo *jfmfi;
410 {
411  int m;
412  int left, right;
413  struct jfmtype_entry *te;
414  int code;
415 
416  if (c > jfmfi->lasttypecode)
417  return 0;
418  for (left = 0, right = jfmfi->nctype, te = jfmfi->ctype; left <= right;) {
419  m = (left+right)/2;
420  if (c < (code = (te+m)->jfm_code))
421  right = m-1;
422  else if (c > code)
423  left = m+1;
424  else if (c == code)
425  return (te+m)->jfm_type;
426  }
427  return 0;
428 }
429 
430 
431 /* utilities
432  */
434 {
435  (void)fseek(fntfp, 2L, SEEK_SET); /* lf */
436  lh = getuint(fntfp, 2);
437  bc = getuint(fntfp, 2);
438  ec = getuint(fntfp, 2);
439  nw = getuint(fntfp, 2);
440  (void)fseek(fntfp, 11*2L, SEEK_SET);
441  np = getuint(fntfp, 2);
442  (void)fseek(fntfp, 2*4L, SEEK_CUR);
443  getbytes(fntfp, header, (lh-2)*4 > JSTFMHEAD ? JSTFMHEAD : (lh-2)*4);
444  (void)fseek(fntfp, (6+lh+(ec-bc)+1)*4L, SEEK_SET);
445  getbytes(fntfp, width, 4*nw);
446  (void)fseek(fntfp, -np*4L, SEEK_END);
447  getbytes(fntfp, param, 4*np);
448  (void)fseek(fntfp, (6+lh)*4L, SEEK_SET); /* ready to read char_info */
449 }
450 
452 FILE *fntfp;
453 {
454  if ((id=getuint(fntfp, 2)) != JFM_ID && id != TJFM_ID)
455  return FALSE;
456  nt = getuint(fntfp, 2);
457  (void)fseek(fntfp, 2L, SEEK_CUR); /* lf */
458  lh = getuint(fntfp, 2);
459  bc = getuint(fntfp, 2); /* bc should be 0 */
460  ec = getuint(fntfp, 2);
461  nw = getuint(fntfp, 2);
462  (void)fseek(fntfp, 13*2L, SEEK_SET);
463  np = getuint(fntfp, 2);
464  (void)fseek(fntfp, (7+lh+nt+(ec-bc)+1)*4L, SEEK_SET);
465  getbytes(fntfp, width, 4*nw);
466  (void)fseek(fntfp, -np*4L, SEEK_END);
467  getbytes(fntfp, param, 4*np);
468  (void)fseek(fntfp, (7+lh)*4L, SEEK_SET); /* ready to read char_type and char_info */
469  return TRUE;
470 }
int code
Definition: aftopl.c:52
#define type(a)
Definition: aptex-macros.h:171
@ 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()
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()
void init_tfm_fontinfo()
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
void read_tfm_finfo(struct font_entry *fe)
Definition: bifont.c:123
readjfm(FILE *fntfp)
Definition: bifont.c:423
int jfm_access()
void read_jfm_fontinfo(struct font_entry *fe)
Definition: bifont.c:360
int tfm_access()
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_jfm_kind()
int dev_is_jstfm()
#define tfmfinfo(fe)
Definition: bifont.h:18
#define JFM_ID
Definition: bifont.h:44
int dev_jstfm_kind()
int dev_is_tfm()
#define Debuguser
Definition: defs.h:88
#define R_OK
Definition: defs.h:31
#define NEWTAB(A, n, e)
Definition: defs.h:145
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
static int ec
Definition: bifont.c:64
static int nw
Definition: bifont.c:64
gentfm_access(char *proto, struct font_entry *fe, struct accarg *acca, int *dev_is_format, char *type)
Definition: bifont.c:70
static int id
Definition: bifont.c:64
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
static int np
Definition: bifont.c:64
static int bc
Definition: bifont.c:64
static int nt
Definition: bifont.c:64
DEV_FONT tfm_fontdict(struct font_entry *fe, int c)
Definition: bifont.c:181
static int lh
Definition: bifont.c:64
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 JSTFMHEAD
Definition: bifont.c:65
static byte width[4 *256]
Definition: bifont.c:62
#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 * enc_read()
int __BOOLEAN__
Definition: defs.h:174
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
#define SCALED(x)
#define SEEK_CUR
Definition: ftzconf.h:250
#define SEEK_END
Definition: ftzconf.h:251
@ 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
dev_tfm_kind(struct font_entry *fe)
Definition: psbi.c:483
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
int acc_mode
Definition: defs.h:254
Definition: psbi.c:77
Definition: inftrees.h:24
Definition: ffi.h:327
Definition: defs.h:190
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
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
void init_jft_fontinfo(struct font_entry *fe)
Definition: ttfont.c:698
void init_jsft_fontinfo(struct font_entry *fe)
Definition: ttfont.c:705
void init_ft_fontinfo(struct font_entry *fe)
Definition: ttfont.c:685
void init_t1_fontinfo(struct font_entry *fe)
Definition: type1font.c:12
void init_vfl_fontinfo(struct font_entry *fe)
Definition: vflfont.c:249
void init_jsvfl_fontinfo(struct font_entry *fe)
Definition: vflfont.c:262
void init_wl_fontinfo(struct font_entry *fe)
Definition: wlfont.c:12
void init_jswl_fontinfo(struct font_entry *fe)
Definition: wlfont.c:160