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)  

pkfont.c
Go to the documentation of this file.
1 /*
2  * This file is based on `texpr/dvi2lpb/pkfont.c'.
3  * The copyright of the original is:
4  * Copyright (c) Japan TeX Users Group, 1986 1987
5  */
6 
7 #include "defs.h"
8 #include "global.h"
9 #include "rastfont.h"
10 #include "pkfont.h"
11 
12 void readpkchar(int flag, struct font_entry *fe, struct rastinitfontinfo *rii);
13 
14 #ifdef KPATHSEA
15 #include <kpathsea/tex-file.h>
16 #endif
17 
20 struct fontop pkop = {
21  "pk",
25 };
26 
27 static FILE *fntfp;
28 void loadpkchar();
29 
30 pktype_access(proto, fe, acca)
31 char *proto;
32 struct font_entry *fe;
33 struct accarg *acca;
34 {
35  char *filename;
36  __BOOLEAN__ ok;
37 
38  rast_mag(fe, acca, 1);
39 #ifdef KPATHSEA
40  if (ok = ((filename = kpsearch_glyph(proto, fe->n, kpse_pk_format,
41  acca, fe->name)) != NULL))
42  strcpy(fe->name, filename);
43 #else
44  pave(fe->name, proto, acca);
45  ok = access(fe->name, R_OK) == 0;
46 #endif
47 #ifdef DEBUG
48  rast_debug_report(fe, acca, ok, "pk");
49 #endif
50  return ok;
51 }
52 
53 void
55 struct font_entry *fe;
56 {
57  void read_pk_fontinfo();
58 
61 }
62 
63 void
65 struct font_entry *fe;
66 {
67  int cmd, i, t;
68  struct rastinitfontinfo *rii;
69  struct rastfntinfo *rfi;
70  int ds;
71 
72  openfontfile(fe);
73  fntfp = fe->openfile;
74  i = 0;
75  do {
76  if (fseek(fntfp, (long)--i, SEEK_END) == -1)
77  Fatal("can't seek to the end of pk file %s\n", fe->name);
78  } while ((t=getuint(fntfp, 1)) == PK_NO_OP);
79  (void)fseek(fntfp, 0L, SEEK_SET);
80  if (t != PK_POST ||
81  getuint(fntfp,1) != PK_PRE || getuint(fntfp,1) != PK_ID)
82  Fatal("bad pk file %s\n", fe->name);
83  (void)fseek(fntfp, (long)getuint(fntfp, 1), SEEK_CUR); /* comment */
84  ds = getuint(fntfp, 4); /* design size */
85  if ((t = getuint(fntfp, 4)) && fe->c && t != fe->c)
86  Warning("font = \"%s\",\n-->font checksum = %d,\n-->dvi checksum = %d",
87  fe->name, fe->c, t);
88  (void)fseek(fntfp, 8L, SEEK_CUR); /* hppp,vppp */
89 
90  rii = rastinifinfo(fe);
91  rastfinfo(fe) = rfi = alloc_rastfinfo(rii->maxc+1, TRUE, rii);
92 #ifdef DEBUG
93  if (Debug) {
94  for (i = 0; i <= rii->maxc; i++)
95  rastfinfo(fe)->ch[i].where.pixptr = NULL;
96  }
97 #endif
98  dev_rast_initfe(fe);
99  /* rfi->designsize = ds; */
100  rfi->nfntchars = rii->maxc + 1;
101  for (;;) {
102  switch (cmd = getuint(fntfp, 1)) {
103 
104  case PK_XXX1: case PK_XXX2: case PK_XXX3: case PK_XXX4:
106  continue;
107 
108  case PK_YYY:
109  skipbytes(fntfp, 4);
110  continue;
111 
112  case PK_NO_OP:
113  continue;
114 
115  case PK_POST:
116  break;
117 
118  default:
119  if (cmd <= PK_FLAG)
120  readpkchar(cmd, fe, rii);
121  else
122  Fatal("illegal pk command %d in %s\n", cmd, fe->name);
123  continue;
124  }
125  break;
126  }
127 
128 #ifdef DEBUG
129  if (Debug) {
130  for (i = 0; i <= rii->maxc; i++)
131  if (rii->mark[i] && rastfinfo(fe)->ch[i].where.pixptr == NULL)
132  (void)fprintf(stderr, "The glyf of char %x in %s missing\n",
133  i, fe->name);
134  }
135 #endif
136  free((char *)rii);
137 }
138 
139 void readpkchar(int flag, struct font_entry *fe, struct rastinitfontinfo *rii)
140 {
141  long pl;
142  unsigned int cc;
143  int n;
144  struct rastchar_entry *ce; /* temporary char_entry pointer */
145 
146  if ((n = flag&7) == 7) { /* long form */
147  pl = getuint(fntfp, 4) - 8; /* without tfmw,dx */
148  if ((cc = getuint(fntfp, 4)) > MAXMARKCHAR) {
149  Warning("cc %d in pk file %s (skipped)", cc, fe->name);
150  (void)fseek(fntfp, pl+8, SEEK_CUR);
151  return;
152  }
153  if (rii->mark[cc] == FALSE) {
154  (void)fseek(fntfp, pl+8, SEEK_CUR);
155  return;
156  }
157  ce = &rastfinfo(fe)->ch[cc];
158  ce->tfmw = scale(getuint(fntfp, 4), fe->s);
159  skipbytes(fntfp, 4); /* dx */
160  n = 4;
161  } else if (n >= 4) { /* extended short form */
162  pl = (n-4)*65536 + getuint(fntfp, 2) - 3; /* without tfmw */
163  ce = &rastfinfo(fe)->ch[cc = getuint(fntfp, 1)];
164  if (rii->mark[cc] == FALSE) {
165  (void)fseek(fntfp, pl+3, SEEK_CUR);
166  return;
167  }
168  ce->tfmw = scale(getuint(fntfp, 3), fe->s);
169  n = 2;
170  } else { /* short form */
171  pl = n*256 + getuint(fntfp, 1) - 3; /* without tfmw */
172  ce = &rastfinfo(fe)->ch[cc = getuint(fntfp, 1)];
173  if (rii->mark[cc] == FALSE) {
174  (void)fseek(fntfp, pl+3, SEEK_CUR);
175  return;
176  }
177  ce->tfmw = scale(getuint(fntfp, 3), fe->s);
178  n = 1;
179  }
180  skipbytes(fntfp, n); /* dy or dm */
181  ce->width = getuint(fntfp, n);
182  ce->height = getuint(fntfp, n);
183  ce->xoffset = getint(fntfp, n);
184  ce->yoffset = getint(fntfp, n);
185  ce->nbpl = (unsigned short)(ce->width + 7) >> 3;
186 
187  loadpkchar(fe, ce, flag, (long)(pl-5*n));
188  dev_rast_initfontdict(fe, cc);
189 }
190 
191 static int width, height, dyn_f;
192 static int b_width, black;
193 static unsigned char *pixel;
194 static unsigned char pat[8] = {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01};
195 
196 /* character shape definition */
197 /* ARGSUSED */
198 void
199 loadpkchar(fe, ce, flag, pl)
200 struct font_entry *fe;
201 struct rastchar_entry *ce;
202 int flag;
203 long pl;
204 {
205  dyn_f = flag/16;
206  black = (flag&8) >> 3;
207  width = ce->width;
208  height = ce->height;
209  b_width = ce->nbpl;
210  if ((pixel = (unsigned char *)calloc((unsigned)height, (unsigned)b_width)) == NULL)
211  Fatal("Unable to allocate memory for char\n");
212  if (dyn_f == 14)
213  unpack_raster();
214  else
215  unpack_run(pl);
216  ce->where.pixptr = (char *)pixel;
217 }
218 
219 /* get nybble */
220 
221 #define get_nyb() ((nyb_f^=1)? (nyb_w=getuint(fntfp,1))/16: nyb_w&15)
222 
223 /* get run_count/repeat_count */
224 
225 #define get_run()\
226  for (;;) {\
227  if ((i=get_nyb()) >= 14) {\
228  rep = i*2-29;\
229  continue;\
230  } else if (i > dyn_f)\
231  run = (i-dyn_f-1)*16 + get_nyb() + dyn_f + 1;\
232  else if (i > 0)\
233  run = i;\
234  else /* i==0 */ {\
235  do ++i;\
236  while ((run = get_nyb()) == 0);\
237  while (--i >= 0)\
238  run = run*16 + get_nyb();\
239  run += (13-dyn_f)*16 + dyn_f - 15;\
240  }\
241  if (rep >= 0)\
242  break;\
243  rep = run;\
244  }\
245 
246 #define min(x,y) ((x)<=(y) ? (x) : (y))
247 
248 /* unpack run_encoded packet */
249 
250 unpack_run(long pl)
251 {
252  unsigned char *p, *q;
253  int i, run, rep, h, h1, v;
254  int nyb_f, nyb_w;
255  long off;
256 
257  nyb_f = 0;
258 #ifdef lint
259  nyb_w = 0;
260 #endif
261  p = pixel;
262  black ^= 1;
263  run = 0;
264  off = ftell(fntfp);
265  for (v=0; v < height; v += rep+1) {
266  rep = 0;
267  for (h=0; h < width; h=h1) {
268  if (run == 0) {
269  get_run();
270  black ^= 1;
271  }
272  h1 = min(h+run, width);
273  if (black) {
274  h1 = min(h1, (h+8)&~7);
275  p[h/8] |= pat[h&7];
276  if(h1 & 7)
277  p[h1/8] &= ~~pat[h1&7];
278  }
279  run -= h1-h;
280  }
281  q = p; p += b_width;
282  for (h=rep*b_width; --h >= 0; )
283  *p++ = *q++;
284  }
285  (void)fseek(fntfp, off+pl, SEEK_SET);
286  return 0;
287 }
288 
289 /* unpack raster packet */
290 
292 {
293  unsigned char *p;
294  int n, m, t, h, v;
295 
296  p = pixel;
297  n = 0;
298  for (v=0; v < height; ++v) {
299  for (h=0; h < width; h+=m) {
300  if (n == 0) {
301  t = getuint(fntfp, 1);
302  n = 8;
303  }
304  m = min(n, 8-(h&7));
305  m = min(m, width-h);
306  p[h/8] |= t >> (h&7);
307  t <<= m; n -= m;
308  }
309  if (width & 7)
310  p[width/8] &= ~~pat[width&7];
311  p += b_width;
312  }
313  return 0;
314 }
q
Definition: afm2pl.c:2287
#define n
Definition: t4ht.c:1290
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
#define free(a)
Definition: decNumber.cpp:310
void Warning(const char *sb1, const char *sb2)
Definition: detex.c:4677
#define R_OK
Definition: defs.h:31
#define Debug
Definition: defs.h:89
int v
Definition: dviconv.c:10
int h
Definition: dviconv.c:9
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()
void skipbytes()
int getint()
#define fseek
Definition: xxstdio.h:30
#define ftell
Definition: xxstdio.h:31
int __BOOLEAN__
Definition: defs.h:174
char * strcpy()
long int flag
Definition: f2c.h:53
static void
Definition: fpif.c:118
#define t
Definition: afcover.h:96
#define SEEK_SET
Definition: jmemansi.c:26
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
#define SEEK_CUR
Definition: ftzconf.h:250
#define SEEK_END
Definition: ftzconf.h:251
voidp calloc()
static int width
Definition: pkfont.c:191
void init_pk_fontinfo()
void readpkchar(int flag, struct font_entry *fe, struct rastinitfontinfo *rii)
Definition: pkfont.c:139
unpack_raster(void)
Definition: pkfont.c:291
void read_pk_fontinfo(struct font_entry *fe)
Definition: pkfont.c:64
static int black
Definition: pkfont.c:192
static FILE * fntfp
Definition: pkfont.c:27
static int dyn_f
Definition: pkfont.c:191
struct fontop pkop
Definition: pkfont.c:20
void loadpkchar()
static int b_width
Definition: pkfont.c:192
int pktype_access()
#define get_run()
Definition: pkfont.c:225
#define min(x, y)
Definition: pkfont.c:246
unpack_run(long pl)
Definition: pkfont.c:250
static unsigned char * pixel
Definition: pkfont.c:193
static int height
Definition: pkfont.c:191
static unsigned char pat[8]
Definition: pkfont.c:194
#define PK_FLAG
Definition: pkfont.h:7
#define PK_ID
Definition: pkfont.h:5
#define PK_YYY
Definition: pkfont.c:494
#define PK_XXX4
Definition: pkfont.c:493
#define PK_NO_OP
Definition: pkfont.c:496
#define PK_XXX2
Definition: pkfont.c:491
#define PK_PRE
Definition: pkfont.c:497
#define PK_XXX1
Definition: pkfont.c:490
#define PK_POST
Definition: pkfont.c:495
#define PK_XXX3
Definition: pkfont.c:492
@ kpse_pk_format
Definition: types.h:104
#define access
Definition: win32lib.h:59
#define fprintf
Definition: mendex.h:64
#define cmd(arg)
Definition: mitsu.h:44
dictionary off
Definition: fc-lang.py:226
dictionary ce
char * filename[256]
Definition: pbmtopk.c:46
double scale
Definition: pnmhistmap.c:38
void dev_rast_initfe(struct font_entry *fe)
Definition: psrast.c:200
void dev_rast_initfontdict(struct font_entry *fe, int c)
Definition: psrast.c:102
rast_mag(struct font_entry *fe, struct accarg *acca, int t)
Definition: rastfont.c:7
struct rastfntinfo * alloc_rastfinfo(int nchars, int init, struct rastinitfontinfo *rii)
Definition: rastfont.c:99
init_rast_fontinfo(struct font_entry *fe)
Definition: rastfont.c:68
rast_debug_report(struct font_entry *fe, struct accarg *acca, __BOOLEAN__ ok, char *type)
Definition: rastfont.c:31
#define rastfinfo(fe)
Definition: rastfont.h:30
#define rastinifinfo(fe)
Definition: rastfont.h:52
#define MAXMARKCHAR
Definition: rastfont.h:1
#define flag
Definition: round_prec.c:45
Definition: defs.h:253
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
int c
Definition: defs.h:192
Definition: defs.h:234
Definition: ppm.h:33
Definition: rastfont.h:4
int nfntchars
Definition: rastfont.h:18
Boolean mark[1]
Definition: rastfont.h:44
Definition: dvips.h:235
#define FILE
Definition: t1stdio.h:34
ch
Definition: t4ht.c:1443
m
Definition: tex4ht.c:3990
int run(char *cmd)
Definition: texdocc.c:233
@ L
Definition: ubidiimp.h:45