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)  

pbmtopk.c
Go to the documentation of this file.
1 /*
2  pbmtopk, adapted from "pxtopk.c by tomas rokicki" by AJCD 1/8/90
3 
4  compile with: cc -o pbmtopk pbmtopk.c -lm -lpbm
5  */
6 
7 #include <stdio.h>
8 #include <math.h>
9 #include <ctype.h>
10 #include <string.h>
11 #include "pbm.h"
12 
13 #define MAXPKCHAR 256
14 #define MAXOPTLINE 200
15 #define MAXWIDTHTAB 256
16 #define MAXHEIGHTTAB 16
17 #define MAXDEPTHTAB 16
18 #define MAXITALICTAB 64
19 #define MAXPARAMS 30
20 #define NAMELENGTH 80
21 
22 #define round(a) ((int)(a+.5))
23 #define fixword(d) ((int)((double)(d)*1048576))
24 #define unfixword(f) ((double)(f) / 1048576)
25 #define fixrange(f) ((f) < 16777216 && (f) > -16777216)
26 #define designunits(p) ((p)*72.27/(double)resolution/unfixword(designsize))
27 
28 /* character flags: in order of appearance in option files. */
29 #define XOFFSET 1
30 #define YOFFSET 2
31 #define HORZESC 4
32 #define VERTESC 8
33 #define TFMWIDTH 16
34 #define TFMHEIGHT 32
35 #define TFMDEPTH 64
36 #define TFMITALIC 128
37 
38 typedef int integer ;
39 typedef char quarterword ;
40 typedef char boolean ;
43 typedef unsigned char byte ;
44 
47 
52 
58 
64 char *codingscheme = "GRAPHIC" ;
65 char *familyname = "PBM" ;
66 
67 integer widthtab[MAXWIDTHTAB] = {0}; /* TFM widths */
68 integer numwidth = 1; /* number of entries in width table */
77 
78 static ASCIIcode xord[128] ;
79 static char xchr[256] = {
80  '?', '?', '?', '?', '?', '?', '?', '?',
81  '?', '?', '?', '?', '?', '?', '?', '?',
82  '?', '?', '?', '?', '?', '?', '?', '?',
83  '?', '?', '?', '?', '?', '?', '?', '?',
84  ' ', '!', '"', '#', '$', '%', '&', '\'',
85  '(', ')', '*', '+', ',', '-', '.', '/',
86  '0', '1', '2', '3', '4', '5', '6', '7',
87  '8', '9', ':', ';', '<', '=', '>', '?',
88  '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
89  'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
90  'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
91  'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
92  '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
93  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
94  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
95  'x', 'y', 'z', '{', '|', '}', '~', '?' };
96 
97 static FILE *tfmfile, *pkfile ;
98 static char tfmname[NAMELENGTH+1], pkname[NAMELENGTH+1] ;
99 static integer pbmtopk_pkloc = 0 ;
102 static integer car ;
103 static integer hppp ;
104 static integer width ;
105 static integer height ;
106 
107 /* checksum not computed at the moment
108 static integer compute_checksum()
109 {
110  begin
111  c0:=bc; c1:=ec; c2:=bc; c3:=ec;
112  for c:=bc to ec do if char_wd[c]>0 then
113  begin
114  temp_width:=memory[char_wd[c]];
115  if design_units<>unity then
116  temp_width:=round((temp_width/design_units)*1048576.0);
117  temp_width:=temp_width + (c+4)*@'20000000; {this should be positive}
118  c0:=(c0+c0+temp_width) mod 255;
119  c1:=(c1+c1+temp_width) mod 253;
120  c2:=(c2+c2+temp_width) mod 251;
121  c3:=(c3+c3+temp_width) mod 247;
122  end;
123  header_bytes[check_sum_loc]:=c0;
124  header_bytes[check_sum_loc+1]:=c1;
125  header_bytes[check_sum_loc+2]:=c2;
126  header_bytes[check_sum_loc+3]:=c3;
127  end
128 }
129 */
130 
131 #define add_tfmwidth(v) (add_tfmtable(widthtab, &numwidth, v, MAXWIDTHTAB,\
132  "TFM width"))
133 #define add_tfmheight(v) (add_tfmtable(heighttab, &numheight, v, MAXHEIGHTTAB,\
134  "TFM height"))
135 #define add_tfmdepth(v) (add_tfmtable(depthtab, &numdepth, v, MAXDEPTHTAB,\
136  "TFM depth"))
137 #define add_tfmitalic(v) (add_tfmtable(italictab, &numitalic, v, MAXITALICTAB,\
138  "Italic correction"))
139 static byte
141  integer *table, *count, value, max_count;
142  char *name;
143 {
144  integer i;
145  for (i = 0; i < *count; i++) /* search for value in tfm table */
146  if (table[i] == value) return (byte)i;
147  if (*count >= max_count)
148  pm_error("too many values in %s table", name) ;
149  if (!fixrange(value))
150  pm_error("%s %f for char %d out of range",
151  name, unfixword(value), car);
152  table[*count] = value ;
153  return (*count)++ ;
154 }
155 
156 /* add a suffix to a filename in an allocated space */
158  char *name, *suffix ;
159 {
160  char *slash = rindex(name, '/');
161  char *dot = rindex(name, '.');
162 
163  if ((dot && slash ? dot < slash : !dot) && strcmp(name, "-"))
164  strcat(name, suffix);
165 }
166 
167 /* initialize the PK parameters */
168 static void initialize_pk()
169 {
170  integer i ;
171  pm_message("This is PBMtoPK, version 2.4") ;
172  for (i = 127 ; i <= 255 ; i ++) xchr[i] = '?' ;
173  for (i = 0 ; i <= 127 ; i ++) xord[i] = 32 ;
174  for (i = 32 ; i < 127 ; i ++) xord[(int)xchr[i]] = i ;
175  for (i = 0; i < MAXPKCHAR; i++) {
176  filename[i] = NULL;
177  charflags[i] = 0;
178  }
179  designsize = fixword(1.0) ;
180 }
181 
182 /* write a single byte to the PK file */
183 static void pbmtopk_pkbyte(b)
184  integer b ;
185 {
186  if (b < 0) b += 256 ;
187  putc(b, pkfile) ;
188  pbmtopk_pkloc++ ;
189 }
190 
191 /* write two bytes to the PK file */
192 static void pkhalfword(a)
193  integer a ;
194 {
195  if (a < 0) a += 65536 ;
196  pbmtopk_pkbyte(a >> 8) ;
197  pbmtopk_pkbyte(a & 255) ;
198 }
199 
200 /* write three bytes to the PK file */
201 static void pkthreebytes(a)
202  integer a ;
203 {
204  pbmtopk_pkbyte((a>>16) & 255) ;
205  pbmtopk_pkbyte((a>>8) & 255) ;
206  pbmtopk_pkbyte(a & 255) ;
207 }
208 
209 /* write four bytes to the PK file */
210 static void pkword(a)
211  integer a ;
212 {
213  pbmtopk_pkbyte((a>>24) & 255) ;
214  pbmtopk_pkbyte((a>>16) & 255) ;
215  pbmtopk_pkbyte((a>>8) & 255) ;
216  pbmtopk_pkbyte(a & 255) ;
217 }
218 
219 /* write a nibble to the PK file */
220 static void pknyb(a)
221  integer a ;
222 {
223  if (bitweight == 16) {
224  outputbyte = (a<<4) ;
225  bitweight = 1 ;
226  } else {
228  bitweight = 16 ;
229  }
230 }
231 
232 /* write preamble to PK file */
233 static void writepreamble()
234 {
235  integer i ;
236  char *comment = "PBMtoPK 2.4 output" ;
237 
238  pbmtopk_pkbyte(247) ; /* PRE command */
239  pbmtopk_pkbyte(89) ; /* PK file type */
240  pbmtopk_pkbyte(strlen(comment)) ; /* output comment */
241  for (i = 0 ; i < strlen(comment); i++) pbmtopk_pkbyte(xord[(int)comment[i]]) ;
242  pkword(designsize) ; /* write designsize */
243  pkword(checksum) ; /* write checksum; calculate if possible */
244  pkword(hppp) ; /* write H pixels per point */
245  pkword(hppp) ; /* write V pixels per point */
246 }
247 
248 /* write postamble to PK file, padded to word length */
249 static void writepostamble()
250 {
251  pbmtopk_pkbyte(245) ; /* POST command */
252  while (pbmtopk_pkloc % 4)
253  pbmtopk_pkbyte(246) ; /* pad with no-ops */
254  pm_message("%d bytes written to packed file.", pbmtopk_pkloc) ;
255 }
256 
257 /* write a byte to the TFM file */
258 static void tfmbyte(b)
259  integer b ;
260 {
261  if (b < 0) b += 256 ;
262  putc(b, tfmfile) ;
263 }
264 
265 /* write a half word to the TFM file */
266 static void tfmhalfword(a)
267  integer a ;
268 {
269  if (a < 0) a += 65536 ;
270  tfmbyte(a >> 8) ;
271  tfmbyte(a & 255) ;
272 }
273 
274 /* write a word to the TFM file */
275 static void tfmword(a)
276  integer a ;
277 {
278  tfmbyte((a>>24) & 255) ;
279  tfmbyte((a>>16) & 255) ;
280  tfmbyte((a>>8) & 255) ;
281  tfmbyte(a & 255) ;
282 }
283 
284 /* write the whole TFM file for the font */
285 static void writetfmfile()
286 {
287  integer totallength ;
288  integer headersize = 17;
289  integer i ;
290 
291  if (largestch - smallestch < 0) {
292  largestch = 0;
293  smallestch = 1;
294  }
295  if (numparam < 7) /* set default parameters */
296  switch (numparam) {
297  case 0: /* slant */
298  parameters[numparam++] = 0 ;
299  case 1: /* space */
301  case 2: /* space_stretch */
303  case 3: /* space_shrink */
305  case 4: /* x_height */
306  parameters[numparam++] = fixword(0.45);
307  case 5: /* quad */
309  case 6: /* extra_space */
311  }
312  totallength = 6 + headersize + (largestch+1-smallestch) +
314  /* lengths */
315  tfmhalfword(totallength) ; /* write file TFM length */
316  tfmhalfword(headersize) ; /* write TFM header length */
317  tfmhalfword(smallestch) ; /* write lowest char index */
318  tfmhalfword(largestch) ; /* write highest char index */
319  tfmhalfword(numwidth) ; /* write number of widths */
320  tfmhalfword(numheight) ; /* write number of heights */
321  tfmhalfword(numdepth) ; /* write number of depths */
322  tfmhalfword(numitalic) ; /* write number of italcorrs */
323  tfmhalfword(0) ; /* lig/kern table */
324  tfmhalfword(0) ; /* kern table */
325  tfmhalfword(0) ; /* extensible char table */
326  tfmhalfword(numparam) ; /* number of fontdimens */
327  /* header */
328  tfmword(checksum) ; /* write checksum */
329  tfmword(designsize) ; /* write designsize */
330  if (strlen(codingscheme) > 39) tfmbyte(39) ; /* write coding scheme len */
331  else tfmbyte(strlen(codingscheme)) ;
332  for (i = 0; i < 39; i++) /* write coding scheme */
333  if (*codingscheme) tfmbyte(xord[(int)(*codingscheme++)]) ;
334  else tfmbyte(0) ;
335  if (strlen(familyname) > 19) tfmbyte(19) ; /* write family length */
336  else tfmbyte(strlen(familyname)) ;
337  for (i = 0; i < 19; i++) /* write family */
338  if (*familyname) tfmbyte(xord[(int)(*familyname++)]) ;
339  else tfmbyte(0) ;
340  /* char_info */
341  for (car = smallestch; car <= largestch; car++)
342  if (filename[car]) { /* write character info */
343  tfmbyte(tfmindex[car]) ;
344  tfmbyte((hgtindex[car]<<4) + depindex[car]) ;
345  tfmbyte(italindex[car]<<2) ;
346  tfmbyte(0) ;
347  } else tfmword(0) ;
348  /* width table */
349  for (i = 0; i < numwidth; i++) tfmword(widthtab[i]) ;
350  /* height table */
351  for (i = 0; i < numheight; i++) tfmword(heighttab[i]) ;
352  /* depth table */
353  for (i = 0; i < numdepth; i++) tfmword(depthtab[i]) ;
354  /* italic correction table */
355  for (i = 0; i < numitalic; i++) tfmword(italictab[i]) ;
356  /* no lig_kern, kern, or exten tables */
357  /* fontdimen table */
358  for (i = 0; i < numparam; i++)
359  if (i && !fixrange(parameters[i]))
360  pm_error("parameter %d out of range (-p)", i);
361  else
362  tfmword(parameters[i]) ;
363  pm_message("%d bytes written to tfm file.", totallength*4) ;
364 }
365 
366 /* read a character from a PBM file */
367 static void readcharacter()
368 {
369  FILE *fp;
370 
371  fp = pm_openr(filename[car]);
372  bitmap = pbm_readpbm(fp, &width, &height) ;
373  pm_close(fp) ;
374 
375  if ((charflags[car] & HORZESC) == 0) horzesc[car] = width ;
376  if ((charflags[car] & VERTESC) == 0) vertesc[car] = 0;
377  if ((charflags[car] & XOFFSET) == 0) xoffset[car] = 0;
378  if ((charflags[car] & YOFFSET) == 0) yoffset[car] = height-1;
379  if ((charflags[car] & TFMWIDTH) == 0)
381  if ((charflags[car] & TFMHEIGHT) == 0)
383  if ((charflags[car] & TFMDEPTH) == 0)
385  if ((charflags[car] & TFMITALIC) == 0) italindex[car] = 0;
386 
387  if (car < smallestch) smallestch = car;
388  if (car > largestch) largestch = car;
389  if (width > emwidth) emwidth = width ;
390 }
391 
392 /* test if two rows of the PBM are the same */
393 static int equal(row1, row2)
394  bit *row1, *row2 ;
395 {
396  integer i ;
397 
398  for (i = 0; i < width; i++)
399  if (row1[i] != row2[i]) return (0) ;
400  return(1) ;
401 }
402 
403 static void shipcharacter()
404 {
405  integer compsize ;
406  integer i, j, k ;
407  bit *zerorow, *onesrow ;
408  integer *repeatptr, *bitcounts ;
409  integer count ;
410  integer test ;
411  integer curptr, rowptr ;
412  integer bitval ;
413  integer repeatflag ;
414  integer colptr ;
415  integer currepeat ;
416  integer dynf ;
417  integer deriv[14] ;
418  integer bcompsize ;
419  boolean firston ;
420  integer flagbyte ;
421  boolean state ;
422  boolean on ;
423  integer hbit ;
424  integer pbit ;
425  boolean ron, son ;
426  integer rcount, scount ;
427  integer ri, si ;
428  integer max2 ;
429  integer predpkloc ;
430  integer buff ;
431 
432  integer tfwid = widthtab[tfmindex[car]] ;
433  integer hesc = horzesc[car] ;
434  integer vesc = vertesc[car] ;
435  integer xoff = xoffset[car] ;
436  integer yoff = yoffset[car] ;
437 
438  repeatptr =
439  (integer *)malloc((unsigned int)((height+1)*sizeof(integer))) ;
440  bitcounts =
441  (integer *)malloc((unsigned int)((height*width)*sizeof(integer))) ;
442  if (repeatptr == NULL || bitcounts == NULL)
443  pm_error("out of memory while allocating bit counts");
444  zerorow = pbm_allocrow(width) ; /* initialise plain rows */
445  onesrow = pbm_allocrow(width) ;
446  for (i = 0 ; i < width ; i++) {
447  zerorow[i] = PBM_WHITE ;
448  onesrow[i] = PBM_BLACK ;
449  }
450  for (i=0; i < height; i = k) { /* set repeat pointers */
451  k = i + 1;
452  if (!equal(bitmap[i], zerorow) && !equal(bitmap[i], onesrow)) {
453  while (k < height && equal(bitmap[i], bitmap[k]))
454  k++;
455  repeatptr[i] = k - i - 1;
456  } else {
457  repeatptr[i] = 0;
458  }
459  }
460  repeatptr[height] = 0 ;
461  colptr = width - 1 ;
462  repeatflag = currepeat = curptr = count = rowptr = 0 ;
463  test = PBM_WHITE ;
464  do {
465  colptr++ ;
466  if (colptr == width) { /* end of row, get next row */
467  colptr = 0 ;
468  rowptr = currepeat ;
469  if (repeatptr[currepeat] > 0) {
470  repeatflag = repeatptr[currepeat] ;
471  currepeat += repeatflag ;
472  rowptr += repeatflag ;
473  }
474  currepeat++ ;
475  }
476  if (rowptr >= height) bitval = -1 ;
477  else bitval = bitmap[rowptr][colptr] ;
478  if (bitval == test) count++ ; /* count repeated pixels */
479  else { /* end of pixel run */
480  bitcounts[curptr++] = count ;
481  if (curptr+3 >= height*width)
482  pm_error("out of memory while saving character counts");
483  count = 1 ;
484  test = bitval ;
485  if (repeatflag > 0) {
486  bitcounts[curptr++] = -repeatflag ;
487  repeatflag = 0 ;
488  }
489  }
490  } while (test != -1) ;
491  bitcounts[curptr] = 0 ;
492  bitcounts[curptr + 1] = 0 ;
493  for (i = 1 ; i <= 13 ; i ++) deriv[i] = 0 ;
494  i = firston = (bitcounts[0] == 0) ;
495  compsize = 0 ;
496  while (bitcounts[i] != 0) { /* calculate dyn_f */
497  j = bitcounts[i] ;
498  if (j == -1) compsize++ ;
499  else {
500  if (j < 0) {
501  compsize++ ;
502  j = -j ;
503  }
504  if (j < 209) compsize += 2 ;
505  else {
506  k = j - 193 ;
507  while (k >= 16) {
508  k >>= 4 ;
509  compsize += 2 ;
510  }
511  compsize++ ;
512  }
513  if (j < 14) (deriv[j])-- ;
514  else if (j < 209) (deriv[(223 - j) / 15])++ ;
515  else {
516  k = 16 ;
517  while (((k<<4) < j + 3)) k <<= 4 ;
518  if (j - k <= 192)
519  deriv[(207 - j + k) / 15] += 2 ;
520  }
521  }
522  i++ ;
523  }
524  bcompsize = compsize ;
525  dynf = 0 ;
526  for (i = 1 ; i <= 13 ; i ++) {
527  compsize += deriv[i] ;
528  if (compsize <= bcompsize) {
529  bcompsize = compsize ;
530  dynf = i ;
531  }
532  }
533  compsize = ((bcompsize + 1)>>1) ;
534  if ((compsize > ((height*width+7)>>3)) || (height*width == 0)) {
535  compsize = ((height*width+7)>>3) ;
536  dynf = 14 ;
537  }
538  flagbyte = (dynf<<4) ;
539  if (firston) flagbyte |= 8 ;
540  if (tfwid > 16777215 || tfwid < 0 || hesc < 0 || vesc != 0 ||
541  compsize > 196579 || width > 65535 || height > 65535 ||
542  xoff > 32767 || yoff > 32767 || xoff < -32768 || yoff < -32768) {
543  flagbyte |= 7 ; /* long form preamble */
545  compsize += 28 ;
546  pkword(compsize) ; /* char packet size */
547  pkword(car) ; /* character number */
548  predpkloc = pbmtopk_pkloc + compsize ;
549  pkword(tfwid) ; /* TFM width */
550  pkword(hesc<<16) ; /* horiz escapement */
551  pkword(vesc<<16) ; /* vert escapement */
552  pkword(width) ; /* bounding box width */
553  pkword(height) ; /* bounding box height */
554  pkword(xoff) ; /* horiz offset */
555  pkword(yoff) ; /* vert offset */
556  } else if (hesc > 255 || width > 255 || height > 255 ||
557  xoff > 127 || yoff > 127 || xoff < -128 ||
558  yoff < -128 || compsize > 1016) {
559  compsize += 13 ; /* extended short preamble */
560  flagbyte += (compsize>>16) + 4 ;
562  pkhalfword(compsize & 65535) ; /* char packet size */
563  pbmtopk_pkbyte(car) ; /* character number */
564  predpkloc = pbmtopk_pkloc + compsize ;
565  pkthreebytes(tfwid) ; /* TFM width */
566  pkhalfword(hesc) ; /* horiz escapement */
567  pkhalfword(width) ; /* bounding box width */
568  pkhalfword(height) ; /* bounding box height */
569  pkhalfword(xoff) ; /* horiz offset */
570  pkhalfword(yoff) ; /* vert offset */
571  } else {
572  compsize += 8 ; /* short form preamble */
573  flagbyte = flagbyte + (compsize>>8) ;
575  pbmtopk_pkbyte(compsize & 255) ; /* char packet size */
576  pbmtopk_pkbyte(car) ; /* character number */
577  predpkloc = pbmtopk_pkloc + compsize ;
578  pkthreebytes(tfwid) ; /* TFM width */
579  pbmtopk_pkbyte(hesc) ; /* horiz escapement */
580  pbmtopk_pkbyte(width) ; /* bounding box width */
581  pbmtopk_pkbyte(height) ; /* bounding box height */
582  pbmtopk_pkbyte(xoff) ; /* horiz offset */
583  pbmtopk_pkbyte(yoff) ; /* vert offset */
584  }
585  if (dynf != 14) { /* write packed character */
586  bitweight = 16 ;
587  max2 = 208 - 15 * dynf ;
588  i = firston ;
589  while (bitcounts[i] != 0) {
590  j = bitcounts[i] ;
591  if (j == - 1) pknyb(15) ;
592  else {
593  if (j < 0) {
594  pknyb(14) ;
595  j = -j ;
596  }
597  if (j <= dynf) pknyb(j) ;
598  else if (j <= max2) {
599  j -= dynf + 1 ;
600  pknyb((j >> 4) + dynf + 1) ;
601  pknyb((j & 15)) ;
602  } else {
603  j -= max2 - 15 ;
604  k = 16 ;
605  while (k <= j) {
606  k <<= 4 ;
607  pknyb(0) ;
608  }
609  while (k > 1) {
610  k >>= 4 ;
611  pknyb(j / k) ;
612  j = j % k ;
613  }
614  }
615  }
616  i++ ;
617  }
618  if (bitweight != 16) pbmtopk_pkbyte(outputbyte) ;
619  } else { /* write bitmap character */
620  buff = 0 ;
621  pbit = 8 ;
622  i = firston ;
623  hbit = width ;
624  on = ! firston ;
625  state = 0 ;
626  count = repeatflag = 0 ;
627  while ((bitcounts[i] != 0) || state || (count > 0)) {
628  if (state) {
629  count = rcount ;
630  i = ri ;
631  on = ron ;
632  repeatflag-- ;
633  } else {
634  rcount = count ;
635  ri = i ;
636  ron = on ;
637  }
638  do {
639  if (count == 0) {
640  if (bitcounts[i] < 0) {
641  if (! state) repeatflag = -bitcounts[i] ;
642  i++ ;
643  }
644  count = bitcounts[i] ;
645  i++ ;
646  on = !on ;
647  }
648  if ((count >= pbit) && (pbit < hbit)) {
649  if (on) buff += (1 << pbit) - 1 ;
651  buff = 0 ;
652  hbit -= pbit ;
653  count -= pbit ;
654  pbit = 8 ;
655  } else if ((count < pbit) && (count < hbit)) {
656  if (on) buff += (1 << pbit) - (1 << (pbit - count)) ;
657  pbit -= count ;
658  hbit -= count ;
659  count = 0 ;
660  } else {
661  if (on) buff += (1 << pbit) - (1 << (pbit - hbit)) ;
662  count -= hbit ;
663  pbit -= hbit ;
664  hbit = width ;
665  if (pbit == 0) {
667  buff = 0 ;
668  pbit = 8 ;
669  }
670  }
671  } while (hbit != width) ;
672  if (state && (repeatflag == 0)) {
673  count = scount ;
674  i = si ;
675  on = son ;
676  state = 0 ;
677  } else if (! state && (repeatflag > 0)) {
678  scount = count ;
679  si = i ;
680  son = on ;
681  state = 1 ;
682  }
683  }
684  if (pbit != 8) pbmtopk_pkbyte(buff) ;
685  }
686  if (predpkloc != pbmtopk_pkloc)
687  pm_error("bad predicted character length: character %d", car);
688  pbm_freerow(zerorow);
689  pbm_freerow(onesrow);
690  free((char *)repeatptr);
691  free((char *)bitcounts);
692 }
693 
694 /* check that character is in valid range */
695 static void checkchar()
696 {
697  if (car < 0 || car >= MAXPKCHAR)
698  pm_error("character must be in range 0 to %d", MAXPKCHAR-1) ;
699 }
700 
701 /* read character information from an option file */
702 static void optionfile(name)
703  char *name ;
704 {
705  FILE *fp ;
706  char buffer[MAXOPTLINE] ;
707 
708  fp = pm_openr(name);
709  while (!feof(fp)) {
710  char *here = buffer;
711 
712  if (fgets(buffer, MAXOPTLINE, fp) == NULL) break ;
713  while (isspace(*here)) here++ ;
714  if (*here && *here == '=') {
715  if (sscanf(here+1, "%d", &car) != 1)
716  pm_error("bad option file line %s", buffer) ;
717  } else if (*here && *here != '%' && *here != '#') {
718  char str[NAMELENGTH] ;
719  integer i, n;
720 
721  checkchar() ;
722  if (sscanf(here, "%s%n", str, &n) != 1)
723  pm_error("bad option file line %s", buffer) ;
724  filename[car] =
725  (char *)malloc((unsigned int)(sizeof(char)*(strlen(str)+1))) ;
726  if (filename[car] == NULL)
727  pm_error("out of memory allocating filename %s", str);
728  strcpy(filename[car], str) ;
729  for (i = 1; i < 256; i<<=1) {
730  here += n;
731  if (sscanf(here, "%s%n", str, &n) != 1) break ;
732  if (strcmp(str, "*")) {
733  charflags[car] |= i ;
734  switch (i) {
735  case XOFFSET:
736  xoffset[car] = atoi(str) ;
737  break ;
738  case YOFFSET:
739  yoffset[car] = atoi(str) ;
740  break ;
741  case HORZESC:
742  horzesc[car] = atoi(str) ;
743  break ;
744  case VERTESC:
745  vertesc[car] = atoi(str) ;
746  break ;
747  case TFMWIDTH:
749  break ;
750  case TFMHEIGHT:
752  break ;
753  case TFMDEPTH:
755  break ;
756  case TFMITALIC:
758  break ;
759  }
760  }
761  }
762  car++ ;
763  }
764  }
765  pm_close(fp) ;
766 }
767 
768 int
770  int argc ;
771  char *argv[] ;
772 {
773  integer i, hesc, vesc, xoff, yoff, tfwid, tfdep, tfhgt, tfital ;
774  byte flags ;
775  char *usage = "pkfile[.pk] tfmfile[.tfm] dpi [-s designsize] [-p num param...]\n\
776  [-C codingscheme ] [-F family] [-c num | <char>]...\n\
777  <char> is:\n\
778  [-W tfmwidth] [-H tfmheight] [-D tfmdepth] [-I ital_corr] [-h horiz]\n\
779  [-v vert] [-x xoffset] [-y yoffset] file\n\
780  or:\n\
781  -f optfile\n" ;
782 
783  pbm_init(&argc, argv);
784  initialize_pk() ;
785 
786  if (--argc < 1) pm_usage(usage) ;
787  strcpy(pkname, *++argv) ;
788  pbmtopk_add_suffix(pkname, ".pk") ;
789 
790  if (--argc < 1) pm_usage(usage) ;
791  strcpy(tfmname, *++argv) ;
792  pbmtopk_add_suffix(tfmname, ".tfm") ;
793 
794  if (--argc < 1) pm_usage(usage) ;
795  resolution = atoi(*++argv) ;
796  if (resolution < 1 || resolution > 32767)
797  pm_error("unlikely resolution %d dpi", resolution);
798 
799  car = flags = hesc = vesc = xoff = yoff = tfwid = 0;
800  while (++argv, --argc) {
801  if (argv[0][0] == '-' && argv[0][1]) {
802  char c, *p;
803  c = argv[0][1] ;
804  if (argv[0][2]) p = *argv + 2 ; /* set argument pointer */
805  else if (++argv, --argc) p = *argv ;
806  else pm_usage(usage) ;
807  switch (c) {
808  case 'C':
809  codingscheme = p;
810  break ;
811  case 'F':
812  familyname = p;
813  break ;
814  case 'c':
815  car = atoi(p) ;
816  break ;
817  case 's':
818  designsize = fixword(atof(p));
819  if (designsize < 1048576)
820  pm_error("design size %f out of range", unfixword(designsize));
821  case 'h':
822  hesc = atoi(p) ;
823  flags |= HORZESC ;
824  break ;
825  case 'v':
826  vesc = atoi(p) ;
827  flags |= VERTESC ;
828  break ;
829  case 'x':
830  xoff = atoi(p) ;
831  flags |= XOFFSET ;
832  break ;
833  case 'y':
834  yoff = atoi(p) ;
835  flags |= YOFFSET ;
836  break ;
837  case 'W':
838  tfwid = fixword(atof(p)) ;
839  flags |= TFMWIDTH ;
840  break ;
841  case 'H':
842  tfhgt = fixword(atof(p)) ;
843  flags |= TFMHEIGHT ;
844  break ;
845  case 'D':
846  tfdep = fixword(atof(p)) ;
847  flags |= TFMDEPTH ;
848  break ;
849  case 'I':
850  tfital = fixword(atof(p)) ;
851  flags |= TFMITALIC ;
852  break ;
853  case 'f':
854  optionfile(p) ;
855  break ;
856  case 'p':
857  numparam = atoi(p);
858  if (numparam < 1 || numparam > MAXPARAMS)
859  pm_error("parameter count %d out of range", numparam);
860  for (i=0; i<numparam; i++)
861  if (++argv,--argc)
862  parameters[i] = fixword(atof(*argv)) ;
863  else
864  pm_error("not enough parameters (-p)");
865  break ;
866  default:
867  pm_usage(usage) ;
868  }
869  } else {
870  checkchar() ;
871  if (flags & TFMWIDTH)
872  tfmindex[car] = add_tfmwidth(tfwid);
873  if (flags & TFMDEPTH)
874  depindex[car] = add_tfmdepth(tfdep);
875  if (flags & TFMHEIGHT)
876  hgtindex[car] = add_tfmheight(tfhgt);
877  if (flags & TFMITALIC)
878  italindex[car] = add_tfmitalic(tfital);
879  horzesc[car] = hesc ;
880  vertesc[car] = vesc ;
881  xoffset[car] = xoff ;
882  yoffset[car] = yoff ;
883  filename[car] = *argv ;
884  charflags[car] = flags ;
885  car++ ;
886  flags = 0;
887  }
888  }
889  hppp = round((resolution<<16) / 72.27) ;
892  writepreamble() ;
893  for (car = 0 ; car < MAXPKCHAR ; car++)
894  if (filename[car]) {
895  readcharacter() ;
896  shipcharacter() ;
897  }
898  writepostamble() ;
899  writetfmfile() ;
900  pm_close(pkfile) ;
901  pm_close(tfmfile) ;
902  exit(0);
903 }
904 
struct @88 table[500]
#define state
Definition: aptex-macros.h:996
#define count(a)
Definition: aptex-macros.h:781
#define name
END END END break
Definition: bibtex-3.c:1974
#define n
Definition: t4ht.c:1290
#define b
Definition: jpegint.h:372
#define free(a)
Definition: decNumber.cpp:310
#define fgets
Definition: xxstdio.h:29
int strcmp()
Definition: coll.cpp:143
int sscanf()
char * strcpy()
static char buff[2 *10240]
Definition: genind.c:46
static char usage[]
Definition: giftopnm.c:59
#define dot
Definition: globals.h:56
#define c(n)
Definition: gpos-common.c:150
#define a(n)
Definition: gpos-common.c:148
char comment[255+1]
Definition: hbf2gf.c:350
#define putc
Definition: jbib.h:20
#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
void exit()
int atoi(const char *)
double atof(const char *)
int scount
Definition: exvar.h:5
#define malloc
Definition: alloca.c:91
#define test
Definition: tie.c:129
unsigned char bitval[8]
Definition: bbox.c:60
union value value
Definition: obx.h:44
int k
Definition: otp-parser.c:70
FILE * pm_openw(char *name)
Definition: libpbm1.c:624
void pm_usage(char *usage)
Definition: libpbm1.c:343
void pbm_init(int *argcP, argv)
Definition: libpbm1.c:332
FILE * pm_openr(char *name)
Definition: libpbm1.c:600
bit ** pbm_readpbm(FILE *file, int *colsP, int *rowsP)
Definition: libpbm2.c:161
#define pbm_allocrow(cols)
Definition: pbm.h:36
unsigned char bit
Definition: pbm.h:9
#define pbm_freerow(bitrow)
Definition: pbm.h:38
#define PBM_BLACK
Definition: pbm.h:11
#define PBM_WHITE
Definition: pbm.h:10
integer checksum
Definition: pbmtopk.c:63
static void initialize_pk()
Definition: pbmtopk.c:168
integer xoffset[256]
Definition: pbmtopk.c:48
static FILE * pkfile
Definition: pbmtopk.c:97
byte depindex[256]
Definition: pbmtopk.c:55
static void writepreamble()
Definition: pbmtopk.c:233
integer emwidth
Definition: pbmtopk.c:62
#define MAXWIDTHTAB
Definition: pbmtopk.c:15
unsigned char byte
Definition: pbmtopk.c:43
byte italindex[256]
Definition: pbmtopk.c:56
static void readcharacter()
Definition: pbmtopk.c:367
static void tfmword(a)
Definition: pbmtopk.c:275
integer yoffset[256]
Definition: pbmtopk.c:49
static int equal(bit *row1, bit *row2)
Definition: pbmtopk.c:393
static char tfmname[80+1]
Definition: pbmtopk.c:98
static char xchr[256]
Definition: pbmtopk.c:79
#define add_tfmwidth(v)
Definition: pbmtopk.c:131
integer numitalic
Definition: pbmtopk.c:74
#define fixrange(f)
Definition: pbmtopk.c:25
static void tfmhalfword(a)
Definition: pbmtopk.c:266
static integer pbmtopk_pkloc
Definition: pbmtopk.c:99
static void shipcharacter()
Definition: pbmtopk.c:403
char boolean
Definition: pbmtopk.c:40
static void checkchar()
Definition: pbmtopk.c:695
int integer
Definition: pbmtopk.c:38
static integer bitweight
Definition: pbmtopk.c:100
#define add_tfmitalic(v)
Definition: pbmtopk.c:137
#define TFMWIDTH
Definition: pbmtopk.c:33
#define round(a)
Definition: pbmtopk.c:22
#define XOFFSET
Definition: pbmtopk.c:29
integer numdepth
Definition: pbmtopk.c:72
static integer width
Definition: pbmtopk.c:104
static integer height
Definition: pbmtopk.c:105
#define MAXPARAMS
Definition: pbmtopk.c:19
integer smallestch
Definition: pbmtopk.c:60
byte charflags[256]
Definition: pbmtopk.c:57
static integer hppp
Definition: pbmtopk.c:103
integer resolution
Definition: pbmtopk.c:45
#define fixword(d)
Definition: pbmtopk.c:23
#define NAMELENGTH
Definition: pbmtopk.c:20
#define YOFFSET
Definition: pbmtopk.c:30
integer largestch
Definition: pbmtopk.c:61
static void writepostamble()
Definition: pbmtopk.c:249
integer parameters[30]
Definition: pbmtopk.c:75
#define MAXITALICTAB
Definition: pbmtopk.c:18
integer vertesc[256]
Definition: pbmtopk.c:51
static void pkword(a)
Definition: pbmtopk.c:210
char * filename[256]
Definition: pbmtopk.c:46
byte tfmindex[256]
Definition: pbmtopk.c:53
static FILE * tfmfile
Definition: pbmtopk.c:97
#define TFMITALIC
Definition: pbmtopk.c:36
static void pkthreebytes(a)
Definition: pbmtopk.c:201
#define HORZESC
Definition: pbmtopk.c:31
integer numheight
Definition: pbmtopk.c:70
static void pknyb(a)
Definition: pbmtopk.c:220
static void pkhalfword(a)
Definition: pbmtopk.c:192
#define add_tfmheight(v)
Definition: pbmtopk.c:133
byte hgtindex[256]
Definition: pbmtopk.c:54
integer italictab[64]
Definition: pbmtopk.c:73
char * familyname
Definition: pbmtopk.c:65
static void pbmtopk_pkbyte(b)
Definition: pbmtopk.c:183
integer numwidth
Definition: pbmtopk.c:68
bit ** bitmap
Definition: pbmtopk.c:59
integer horzesc[256]
Definition: pbmtopk.c:50
static void optionfile(name)
Definition: pbmtopk.c:702
int main(argc, argv)
Definition: pbmtopk.c:769
quarterword eightbits
Definition: pbmtopk.c:42
quarterword ASCIIcode
Definition: pbmtopk.c:41
char * codingscheme
Definition: pbmtopk.c:64
static ASCIIcode xord[128]
Definition: pbmtopk.c:78
#define MAXPKCHAR
Definition: pbmtopk.c:13
#define MAXOPTLINE
Definition: pbmtopk.c:14
integer widthtab[256]
Definition: pbmtopk.c:67
#define TFMDEPTH
Definition: pbmtopk.c:35
static void pbmtopk_add_suffix(char *name, char *suffix)
Definition: pbmtopk.c:157
integer designsize
Definition: pbmtopk.c:45
#define VERTESC
Definition: pbmtopk.c:32
static void tfmbyte(b)
Definition: pbmtopk.c:258
#define MAXHEIGHTTAB
Definition: pbmtopk.c:16
integer depthtab[16]
Definition: pbmtopk.c:71
static integer outputbyte
Definition: pbmtopk.c:101
#define add_tfmdepth(v)
Definition: pbmtopk.c:135
integer heighttab[16]
Definition: pbmtopk.c:69
static void writetfmfile()
Definition: pbmtopk.c:285
char quarterword
Definition: pbmtopk.c:39
static integer car
Definition: pbmtopk.c:102
integer numparam
Definition: pbmtopk.c:76
#define designunits(p)
Definition: pbmtopk.c:26
static char pkname[80+1]
Definition: pbmtopk.c:98
static byte add_tfmtable(integer *table, integer *count, integer value, integer max_count, char *name)
Definition: pbmtopk.c:140
#define TFMHEIGHT
Definition: pbmtopk.c:34
#define MAXDEPTHTAB
Definition: pbmtopk.c:17
#define unfixword(f)
Definition: pbmtopk.c:24
#define fp
const char * suffix
Definition: pkg_icu.cpp:27
static integer flagbyte
Definition: pktopbm.c:29
static integer dynf
Definition: pktopbm.c:25
#define pm_error
Definition: png22pnm.c:118
#define pm_close(file)
Definition: png22pnm.c:120
#define pm_message
Definition: png22pnm.c:116
#define flags
#define isspace(ch)
Definition: utype.h:87
test
Definition: parser.c:257
#define str(s)
Definition: sh6.c:399
Definition: gf2pbm.c:137
Definition: utils.c:300
Definition: sh5.c:97
Definition: table.h:30
#define FILE
Definition: t1stdio.h:34
#define feof(f)
Definition: t1stdio.h:109
int j
Definition: t4ht.c:1589
*job_name strlen((char *) job_name) - 4)
Definition: obx.h:51
char * rindex(char *s, int c)
Definition: shhopt.c:47
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269
#define buffer
Definition: xmlparse.c:611