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)  

ttf2pfb.c
Go to the documentation of this file.
1 /*
2  * ttf2pfb.c -- TrueType to PostScript Type 1 Font converter.
3  *
4  * Author: Chun-Yu Lee <d791013@ce.ntu.edu.tw>
5  * Maintainer: Werner Lemberg <wl@gnu.org>
6  *
7  * The generated output is in a raw Type 1 Font format. An encoder
8  * (e.g. t1asm or t1binary) is needed to convert it into PFA or PFB format.
9  *
10  * This program was adapted from the ntu2cjk package (which was part of the
11  * LaTeX2e CJK package (by Werner Lemberg <wl@gnu.org>)).
12  *
13  *
14  * Modified by Joachim H. Kaiser <jhk@cmpnetmail.com> to include real glyph
15  * names and other font infos (see PS_Head function).
16  * The test programs of the FreeType distribution have been heavily used as
17  * templates.
18  *
19  */
20 
21 /*
22  * Requirements:
23  * - the FreeType library.
24  * - t1asm or a similar converter if PFA or PFB format is required.
25  * - getafm or a similar program if AFM font metrics are required.
26  * - afm2tfm or a similar program if TFM font metrics are required.
27  * - for compact fonts: the CJK package for typesetting LaTeX documents.
28  * - dvips 5.66 or higher if self-contained PostScript document
29  * outputs with partially downloaded fonts are required. Note that
30  * the partial download code in dvips is still buggy, causing strange
31  * error messages during loading of the created PS fonts.
32  * - Ghostscript 3.33 or newer (this is optional).
33  */
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <stdarg.h>
38 #include <string.h>
39 /*
40 #include <unistd.h>
41 */
42 #include <time.h>
43 #ifdef TM_IN_SYS_TIME
44 #include <sys/time.h>
45 #endif
46 #include <ctype.h>
47 
48 #include "freetype.h"
49 #include "extend/ftxpost.h" /* we are in the FreeType package tree */
50 
51 #ifdef WIN32
52 #include <kpathsea/kpathsea.h>
53 #include <fcntl.h>
54 #include <io.h>
55 #endif
56 
57 char rcsid[] = "$Id: ttf2pfb.c,v 1.14 2000/01/16 21:49:22 werner Exp $";
58 
59 
60 #define PID_UNICODE 3
61 #define EID_UNICODE 1
62 #define PID_SJIS 3
63 #define EID_SJIS 2
64 #define PID_GB 3
65 #define EID_GB 3
66 #define PID_BIG5 3
67 #define EID_BIG5 4
68 #define PID_KS 3 /* KS is also called Wansung */
69 #define EID_KS 5
70 #define PID_JOHAB 3
71 #define EID_JOHAB 6
72 
73 /* Set default values */
74 #ifndef DEFAULT_PLATFORM_ID
75 #define DEFAULT_PLATFORM_ID PID_UNICODE /* MS platform */
76 #endif
77 
78 #ifndef DEFAULT_ENCODING_ID
79 #define DEFAULT_ENCODING_ID EID_UNICODE
80 #endif
81 
82 /* The possible values for the `force_enc' variable. */
83 typedef enum enc_type_
84 {
85  GB = 1, Big5, JIS, KS, Johab, SJIS, X
87 
88 /* A variable to enforce a certain font encoding (if > 0). */
90 
91 
92 #ifndef TRUE
93 #define TRUE 1
94 #endif
95 
96 #ifndef FALSE
97 #define FALSE 0
98 #endif
99 
100 #ifndef FAILURE
101 #define FAILURE 500
102 #endif
103 
104 
105 #define LINELEN 40 /* max # of columns of code range file */
106 #define NAMELEN 80 /* max length of name used from LookUp */
107 
108 
109 /*
110  * Flags and globals
111  */
112 
113 int verbose = FALSE; /* messages should be printed or not. */
114 int compact = FALSE; /* generate compact font? */
115 int keep = FALSE; /* keep output font in case of error? */
116 int mapping = FALSE; /* use encoding file as mapping? */
117 float fontShift = 0;
118 
119 #ifndef UShort
120 typedef unsigned short UShort;
121 #endif
122 #ifndef UChar
123 typedef unsigned char UChar;
124 #endif
125 
126 #define TT_Flag_On_Curve 1
127 
128 /* default platform and encoding ID's. */
131 
132 
133 char* prog; /* program name */
134 
135 
136 /* for orthogonality with fprintf */
137 #define Fputs(_string_) fprintf(out, "%s\n", _string_)
138 
139 
140 /* Postscript font related defines and functions */
142 
143 #define Coord(x) (int)(x)
144 #define PS_LastPt(x, y) lastpsx = x; lastpsy = y
145 #define PS_Moveto(x, y) \
146  fprintf(out, "%d %d rmoveto\n", \
147  Coord(x - lastpsx), Coord(y - lastpsy)); \
148  PS_LastPt(x, y)
149 #define PS_Lineto(x, y) \
150  fprintf(out, "%d %d rlineto\n", \
151  Coord(x - lastpsx), Coord(y - lastpsy)); \
152  PS_LastPt(x, y)
153 
154 
155 /*
156  * Freetype globals.
157  */
158 
166 
170 
171 
172 /*
173  * Data structures defined for encoding vectors
174  */
175 
176 /*
177  * A code range file for the encoding vector of a font contains code
178  * range pairs, each pair a line. The values for the begin and end of the
179  * ranges are separated by ` - '. Note that the spaces before and after the
180  * minus sign are significant. The possible syntax is as follows:
181  *
182  * (Note that code ranges must appear in ascending order.)
183  *
184  * 1. Absolute range, i.e., the code is at least a two-byte number, e.g.:
185  *
186  * 0xA140 - 0xA17E
187  * 41280 - 41342
188  * 0xE00000 - 0xE000FF
189  *
190  * The first two lines represent the same range.
191  *
192  * 2. Relative range, i.e., the code is a one-byte number. If the line ends
193  * with a colon `:', it designates the high byte(s) range, otherwise the
194  * low byte range. If there is no high byte(s) range declared before the low
195  * byte range, the last defined high byte(s) range or `0x00 - 0x00:' will be
196  * used. e.g.:
197  *
198  * 0xA1 - 0xFE:
199  * 0x40 - 0x7E
200  * 0xA1 - 0xFE
201  *
202  * which is Big-5 Encoding.
203  *
204  * 3. Single code. Similar to absolute or relative range but the second
205  * number of the range is the same as the first number. E.g.:
206  *
207  * 0xA141 == 0xA141 - 0xA141
208  * 0xA1: == 0xA1 - 0xA1:
209  * 0xA1 == 0xA1 - 0xA1
210  *
211  * 4. If the high byte range is declared and there is no low byte range
212  * declared consecutively, the assumed low byte range is `0x00 - 0xFF'.
213  *
214  * 5. Comment line. A line starting with a hash mark `#' followed by any
215  * characters up to the end of the line is ignored. Blank lines are also
216  * discarded.
217  */
218 
219 typedef struct _EVHigh
220 {
223 
224 typedef struct _EVLow
225 {
228 
229 typedef struct _EVcRange
230 {
235 
236 typedef struct _EncVec
237 {
241 
242 /* Select encoding vector with respect to pid and eid */
243 EncVec* eVecMap[5][10];
244 
245 /* Select encoding vector with respect to force_enc */
247 
248 
249 /*************/
250 /* Functions */
251 /*************/
252 
253 
254 void
255 mesg(const char *msg, ...)
256 {
257  va_list ap;
258 
259  va_start(ap, msg);
260  vfprintf(stderr, msg, ap);
261  va_end(ap);
262 }
263 
264 
265 /*
266  * Usage.
267  */
268 
269 void
271 {
272 #ifdef DEBUG
273  mesg("Usage: %s [-h][-v][-c][-k][-m][-d charcode][-l][-ng][-nc]\n", prog);
274 #else
275  mesg("Usage: %s [-h][-v][-c][-k][-m]\n", prog);
276 #endif
277  mesg("\t[-pid id] [-eid id] [-force enc] [-enc file]\n");
278  mesg("\t[-plane pl] [-f fname] [-uid id] [-s shift]\n");
279  mesg("\t[-o output] [-ttf font.ttf | font.ttf]\n");
280  mesg("-h\t\tThis message.\n");
281  mesg("-v\t\tPrint messages during conversion.\n");
282  mesg("-c\t\tCompact font");
283  mesg(" (256 chars per font; useful for the CJK package).\n");
284  mesg("-k\t\tKeep output file in case of error.\n");
285  mesg("-m\t\tUse encoding file as mapping file.\n");
286 #ifdef DEBUG
287  mesg("-d charcode\tDebug CharString for the given character code.\n");
288  mesg("-l\t\tDisplay point labels.\n");
289  mesg("-ng\t\tDo not show glyph outline.\n");
290  mesg("-nc\t\tDo not show control paths.\n");
291 #endif
292  mesg("-pid id\t\tSet the platform ID [%d].\n", DEFAULT_PLATFORM_ID);
293  mesg("-eid id\t\tSet the encoding ID [%d].\n", DEFAULT_ENCODING_ID);
294  mesg("\t\t(Use a strange pid,eid pair to list all possible pid,eid)\n");
295  mesg("-force enc\tForce a certain encoding [none].\n");
296  mesg("\t\t(Possible values are `GB', `JIS', `KS', `SJIS', and `X').\n");
297  mesg("-enc file\tFile contains code ranges [none].\n");
298  mesg("-plane pl\tA single font plane [0x0].\n");
299  mesg("-f fname\tFont name [UNKNOWN].\n");
300  mesg("-uid id\t\tUnique font ID, for private fonts 4000000-4999999 [4999999].\n");
301  mesg("-s shift\tY-offset factor [%5.3f].\n", fontShift);
302  mesg("-o outfile\tSet the output filename [stdout].\n");
303  mesg("-ttf ttfpath\tThe TTF font pathname.\n");
304 
305  exit(eval);
306 }
307 
308 
309 void
310 fatal(const char *msg,
311  ...)
312 {
313  va_list ap;
314 
315  va_start(ap, msg);
316  fprintf(stderr, "%s: ", prog);
317  vfprintf(stderr, msg, ap);
318  fprintf(stderr, "\n");
319  va_end(ap);
320  exit(FAILURE);
321 }
322 
323 
324 void
325 fatal_error(const char *msg,
326  ...)
327 {
328  va_list ap;
329 
330  va_start(ap, msg);
331  fprintf(stderr, "%s: Error code 0x%04lx: ", prog, error);
332  vfprintf(stderr, msg, ap);
333  fprintf(stderr, "\n");
334  va_end(ap);
335  exit(FAILURE);
336 }
337 
338 
339 /*
340  * Reallocate a pointer.
341  */
342 
343 void *
344 re_alloc(void* ptr,
345  size_t size,
346  char* sub)
347 {
348  register void* value = realloc(ptr, size);
349 
350  if (value == NULL)
351  fatal("%s: Virtual memory exhausted", sub);
352  return value;
353 }
354 
355 
356 /*
357  * We have to introduce the `dummy' integer to assure correct handling of
358  * the stack. Using `UShort' as the first parameter may fail in case
359  * this type is promoted to a different type (as happens e.g. under
360  * emx for DOS).
361  */
362 
363 EncVec*
365  ...)
366 {
367  va_list vp;
368  EncVec* encVec = NULL;
369  EVcRange* cRange = NULL;
370  EVLow* evLow = NULL;
371  UShort numCR, numLows;
372  int i, j;
373 
374  va_start(vp, dummy);
375  numCR = (UShort)va_arg(vp, int);
376 
377  encVec = re_alloc(encVec, 1 * sizeof (EncVec), "Alloc_EncVec");
378  encVec->numCodeRanges = numCR;
379 
380  cRange = re_alloc(cRange, numCR * sizeof (EVcRange), "Alloc_EncVec");
381  for (i = 0; i < numCR; i++)
382  {
383  (cRange + i)->high.start = (UShort)va_arg(vp, int);
384  (cRange + i)->high.end = (UShort)va_arg(vp, int);
385  (cRange + i)->numLowRanges = numLows = (UShort)va_arg(vp, int);
386  evLow = NULL;
387  evLow = re_alloc(evLow, numLows * sizeof (EVLow), "Alloc_EncVec");
388  for (j = 0; j < numLows; j++)
389  {
390  (evLow + j)->start = (UChar)va_arg(vp, int);
391  (evLow + j)->end = (UChar)va_arg(vp, int);
392  }
393  (cRange + i)->low = evLow;
394  }
395  encVec->codeRange = cRange;
396 
397  va_end(vp);
398  return encVec;
399 }
400 
401 
402 void
404 {
405  EncVec* encVec;
406 
407  /* Big-5 encoding */
408  encVec = Alloc_EncVec(1,
409  1, 0xA1, 0xFE,
410  2, 0x40, 0x7E, 0xA1, 0xFE);
411  eVecMap[PID_BIG5][EID_BIG5] = encVec;
412  eVecMap_force[Big5] = encVec;
413 
414  /* GB encoding */
415  encVec = Alloc_EncVec(2,
416  1, 0xA1, 0xF7,
417  1, 0xA1, 0xFE);
418  eVecMap[PID_GB][EID_GB] = encVec;
419  eVecMap_force[GB] = encVec;
420 
421  /* KS encoding */
422  encVec = Alloc_EncVec(3,
423  1, 0xA1, 0xFE,
424  1, 0xA1, 0xFE);
425  eVecMap[PID_KS][EID_KS] = encVec;
426  eVecMap_force[KS] = encVec;
427 
428  /* Johab encoding */
429  encVec = Alloc_EncVec(4,
430  3, 0x84, 0xD3,
431  2, 0x41, 0x7E,
432  0x81, 0xFE,
433  0xD8, 0xDE,
434  2, 0x31, 0x7E,
435  0x91, 0xFE,
436  0xE0, 0xF9,
437  2, 0x31, 0x7E,
438  0x91, 0xFE);
439  eVecMap[PID_JOHAB][EID_JOHAB] = encVec;
440  eVecMap_force[Johab] = encVec;
441 
442  /* JIS encoding */
443  encVec = Alloc_EncVec(5,
444  1, 0xA1, 0xF4,
445  1, 0xA1, 0xFE);
446  eVecMap_force[JIS] = encVec;
447  eVecMap_force[X] = encVec; /* will be internally translated to SJIS */
448 
449  /* Unicode encoding */
450  encVec = Alloc_EncVec(6,
451  1, 0x00, 0xFF,
452  1, 0x00, 0xFF);
453  eVecMap[PID_UNICODE][EID_UNICODE] = encVec;
454 
455  /* SJIS encoding */
456  encVec = Alloc_EncVec(7,
457  3, 0x0, 0x0,
458  1, 0xA1, 0xDF,
459  0x81, 0x9F,
460  2, 0x40, 0x7E,
461  0x80, 0xFC,
462  0xE0, 0xEF,
463  2, 0x40, 0x7E,
464  0x80, 0xFC);
465  eVecMap[PID_SJIS][EID_SJIS] = encVec;
466  eVecMap_force[SJIS] = encVec;
467 }
468 
469 
470 /*
471  * Convert JIS to SJIS encoding.
472  */
473 
474 UShort
476 {
477  UShort index;
478  UShort cc0 = (code >> 8) & 0xFF;
479  UShort cc1 = code & 0xFF;
480 
481  index = (cc0 - 0xa1) * (0xfe - 0xa1 + 1) + (cc1 - 0xa1);
482  cc0 = index / ((0x7e - 0x40 + 1) + (0xfc - 0x80 + 1));
483  cc1 = index % ((0x7e - 0x40 + 1) + (0xfc - 0x80 + 1));
484  if (cc0 < (0x9f - 0x81 + 1))
485  cc0 += 0x81;
486  else
487  cc0 += 0xe0 - (0x9f - 0x81 + 1);
488  if (cc1 < (0x7e - 0x40 + 1))
489  cc1 += 0x40;
490  else
491  cc1 += 0x80 - (0x7E - 0x40 + 1);
492 
493  return (cc0 << 8) + cc1;
494 }
495 
496 
497 /*
498  * Open TTF file and select cmap.
499  */
500 
501 int
503 {
504 #ifdef WIN32
505  char *akp, *akfp;
506 #endif
507 
508  UShort cmapindex, platformID, encodingID, num_cmap;
509 
510  if (verbose)
511  printf("Initializing TrueType font engine...\n");
512 
513  /* initialization of the FreeType engine */
515  if (error)
516  fatal_error("Couldn't initialize FreeType engine");
517 
518  /* initialization of the post extension */
520  if (error)
521  fatal_error("Couldn't initialize the post extension");
522 
523  /* open the input file */
524 
525 /*--ak */
526 #ifdef WIN32
527  akp = kpse_var_value("TTFONTS");
528  if(!akp) {
529  fprintf(stderr, "Define the variable TTFONTS in texmf.cnf.\n");
530  exit(100);
531  }
532  akfp = kpse_brace_expand(akp); free(akp);
533  akp = kpse_path_search(akfp, infile, 0); free(akfp);
534  if(!akp) {
535  fatal_error("Unable to find input file `%s'", infile);
536  }
537  error = TT_Open_Face(engine, akp, &face);
538  if(akp) free(akp); if(akfp) free(akfp);
539 #else
541 #endif
542  if (error)
543  fatal_error("Unable to open input file `%s'", infile);
544 
545  /* load full post table */
547  if (error)
548  fatal_error("Unable to load post table");
549 
550  /* get face properties */
552 
553  /* Load the instance. */
555  if (error)
556  fatal_error("Couldn't create instance");
557 
559  if (error)
560  fatal_error("Error setting resolutions");
561 
563  if (error)
564  fatal_error("Error setting character size");
565 
567  if (error)
568  fatal_error("Couldn't create new glyph");
569 
570  /* Get the requested cmap. */
571  num_cmap = TT_Get_CharMap_Count(face);
572  for (cmapindex = 0; cmapindex < num_cmap; cmapindex++)
573  {
574  TT_Get_CharMap_ID(face, cmapindex, &platformID, &encodingID);
575  if (platformID == pid && encodingID == eid)
576  break;
577  }
578  if (cmapindex == num_cmap)
579  {
580  mesg("Possible platform and encoding ID pairs:");
581  for (cmapindex = 0; cmapindex < num_cmap; cmapindex++)
582  {
583  TT_Get_CharMap_ID(face, cmapindex, &platformID, &encodingID);
584  mesg(" (%d, %d)", platformID, encodingID);
585  }
586  mesg ("\n");
587  fatal("No character map for given platform %d, encoding %d", pid, eid);
588  }
589 
590  /* malloc for glyph data */
591  error = TT_Get_CharMap(face, cmapindex, &cmap);
592  if (error)
593  fatal_error("Cannot load cmap");
594 
595  return TRUE;
596 }
597 
598 
599 /*
600  * Get font infos: name, version, copyright.
601  */
602 
603 char*
605 {
607  char* string;
608  UShort string_len;
609  UShort i, n;
610 
612 
613  for (i = 0; i < n; i++)
614  {
616  TT_Get_Name_String(face, i, &string, &string_len);
617 
618  if (id == index)
619  break;
620  }
621  i = (string_len > NAMELEN) ? NAMELEN : string_len;
622  string[i] = '\0';
623  return string;
624 }
625 
626 
627 /*
628  * Load a glyph's outline and metrics.
629  */
630 
631 int
633 {
634  TT_Matrix scale = {(1 << 16) / 64, 0, 0, (1 << 16) / 64};
635 
637  if (error)
638  fatal_error("Load glyph");
639 
641  if (error)
642  fatal_error("Get glyph outlines");
643 
645 
647  if (error)
648  fatal_error("Get glyph_metrics");
649 
650  return TRUE;
651 }
652 
653 
654 /*
655  * Get PS name of a glyph.
656  */
657 
658 char*
660  UShort code)
661 {
662  char *glyphname = ".notdef";
663  static char CJK_glyphname[8];
664 
665  if (compact)
666  {
667  sprintf(CJK_glyphname, "cjk%04X", code);
668  glyphname = CJK_glyphname;
669  }
670  else
671  {
672  if (idx)
674  }
675 
676  return glyphname;
677 }
678 
679 
680 /*
681  * Header of Type 1 font.
682  */
683 
684 void
686  int plane,
687  EncVec* planeEV,
688  char* font,
689  int UID)
690 {
691  EVcRange* cRange = planeEV->codeRange;
692  UShort numCR = planeEV->numCodeRanges;
693  int cjk = 0, nGlyph = 0, irange;
694  EVLow* pLow = cRange->low;
695  UShort nLow = cRange->numLowRanges;
696  int ipl, ilow, ich;
697  int idx;
698  UShort code;
699  time_t curtime;
700  struct tm *loctime;
701  char text[NAMELEN];
702  char fam_name[NAMELEN];
703  char* version;
704  char fullname[NAMELEN];
705  char copyright[NAMELEN];
706 
707  /* Get the current time with local representation */
708  curtime = time(NULL);
709  loctime = localtime(&curtime);
710 
711  /* Get font infos: family name, version, notice */
712  strcpy(fullname, LookUp_Name(6));
713  strcpy(fam_name, LookUp_Name(1));
714  strcpy(text, LookUp_Name(5));
715  version = &text[strcspn(text, "1234567890.")];
716  version[strspn(version, "1234567890.")] = '\0';
718 
719  fprintf(out, "%%!FontType1-1.0: %s %s\n", font, version);
720  fprintf(out, "%%%%Creator: %s, ", prog);
721  fprintf(out, "%s\n", rcsid);
722  fprintf(out, "%%%%CreationDate: %s", asctime(loctime));
723 
724  Fputs("%%VMusage: 030000 030000");
725  Fputs("11 dict begin");
726  Fputs("/FontInfo 8 dict dup begin");
727  fprintf(out, "/version (%s) readonly def\n", version);
728  fprintf(out, "/Copyright (%s) readonly def\n", copyright);
729  fprintf(out, "/Notice (Plane %d) readonly def\n", plane);
730  fprintf(out, "/FullName (%s) readonly def\n", fullname);
731  fprintf(out, "/FamilyName (%s) readonly def\n", fam_name);
732  Fputs("/Weight (Regular) readonly def");
733  Fputs("/ItalicAngle 0 def");
734  Fputs("/isFixedPitch false def");
735  /* Fputs("/UnderlineThickness 50 def"); */
736  Fputs("end readonly def");
737  fprintf(out, "/FontName /%s def\n", font);
738  Fputs("/PaintType 0 def");
739  Fputs("/FontType 1 def");
740 
741  if (fontShift == 0)
742  Fputs("/FontMatrix [0.001 0 0 0.001 0 0] readonly def");
743  else
744  fprintf(out, "/FontMatrix [0.001 0 0 0.001 0 %5.3f] readonly def\n",
745  fontShift);
746 
747  Fputs("/Encoding 256 array");
748  Fputs("0 1 255 {1 index exch /.notdef put} for");
749  /* encoding vector */
750  for (irange = 0; irange < numCR; irange++, cRange++)
751  {
752  pLow = cRange->low;
753  nLow = cRange->numLowRanges;
754  for (ipl = cRange->high.start; ipl <= cRange->high.end; ipl++)
755  {
756  if (nLow == 0)
757  {
758  nGlyph = 0x100;
759  for (ich = 0; ich <= 0xff; ich++)
760  {
761  code = ipl<<8 | ich;
763  fprintf(out, "dup %d /%s put\n", ich, PS_GlyphName(idx, code));
764  }
765  }
766  else
767  {
768  for (ilow = 0; ilow < nLow; ilow++, pLow++)
769  {
770  if (!compact && !mapping)
771  cjk = pLow->start;
772  nGlyph += pLow->end - pLow->start + 1;
773  for (ich = pLow->start; ich <= pLow->end; ich++, cjk++)
774  {
775  code = ipl<<8 | ich;
777  fprintf(out, "dup %d /%s put\n", cjk, PS_GlyphName(idx, code));
778  if (mapping && cjk == 0xFF)
779  goto done;
780  }
781  }
782  }
783  }
784  }
785 
786 done:
787 
788  Fputs("readonly def");
789  Fputs("/FontBBox [0 -300 1000 1000] readonly def");
790  fprintf(out, "/UniqueID %d def\n",UID);
791  Fputs("currentdict end");
792  Fputs("currentfile eexec");
793 
794  Fputs("dup /Private 8 dict dup begin");
795  Fputs("/-| { string currentfile exch readstring pop } executeonly def");
796  Fputs("/|- { noaccess def } executeonly def");
797  Fputs("/| { noaccess put } executeonly def");
798  Fputs("/BlueValues [ ] |-");
799  Fputs("/ForceBold true def");
800  Fputs("/LanguageGroup 1 def");
801  Fputs("/RndStemUp false def");
802  Fputs("/MinFeature{16 16} |-");
803  /* Fputs("/password 5839 def"); */
804  fprintf(out, "/UniqueID %d def\n",UID);
805 
806  Fputs("/Subrs 4 array");
807  Fputs("dup 0 { 3 0 callothersubr pop pop setcurrentpoint return } |");
808  Fputs("dup 1 { 0 1 callothersubr return } |");
809  Fputs("dup 2 { 0 2 callothersubr return } |");
810  Fputs("dup 3 { return } |");
811  Fputs("|-");
812 
813  fprintf(out, "2 index /CharStrings %d dict dup begin\n", nGlyph + 1);
814 }
815 
816 
817 /*
818  * Tail of Type 1 font.
819  */
820 
821 void
823 {
824  Fputs("/.notdef { 0 250 hsbw endchar } |-");
825  Fputs("end end readonly put noaccess put");
826  Fputs("dup /FontName get exch definefont pop");
827  Fputs("mark currentfile closefile");
828 }
829 
830 
831 /*
832  * Use the `rrcurveto' command on more than one `off' points.
833  */
834 
835 void
837  TT_F26Dot6 x,
838  TT_F26Dot6 y,
839  int s,
840  int e)
841 {
842  int N, i;
843  TT_F26Dot6 sx[3], sy[3], cx[4], cy[4];
844 
845  N = e - s + 1;
846  cx[0] = lastpsx; cy[0] = lastpsy;
847  if (s == e)
848  {
849  cx[1] = (2 * outline.points[s].x + outline.points[s - 1].x) / 3;
850  cy[1] = (2 * outline.points[s].y + outline.points[s - 1].y) / 3;
851  cx[2] = (2 * outline.points[s].x + x) / 3;
852  cy[2] = (2 * outline.points[s].y + y) / 3;
853  cx[3] = x;
854  cy[3] = y;
855 
856  fprintf(out, "%d %d %d %d %d %d rrcurveto\n",
857  Coord(cx[1] - cx[0]), Coord(cy[1] - cy[0]),
858  Coord(cx[2] - cx[1]), Coord(cy[2] - cy[1]),
859  Coord(cx[3] - cx[2]), Coord(cy[3] - cy[2]));
860  }
861  else
862  {
863  for(i = 0; i < N; i++)
864  {
865  sx[0] = (i == 0) ?
866  outline.points[s - 1].x :
867  (outline.points[i + s].x + outline.points[i + s - 1].x) / 2;
868  sy[0] = (i == 0) ?
869  outline.points[s - 1].y :
870  (outline.points[i + s].y + outline.points[i + s - 1].y) / 2;
871  sx[1] = outline.points[s + i].x;
872  sy[1] = outline.points[s + i].y;
873  sx[2] = (i == N - 1) ?
874  x :
875  (outline.points[s + i].x + outline.points[s + i + 1].x) / 2;
876  sy[2] = (i == N - 1) ?
877  y :
878  (outline.points[s + i].y + outline.points[s + i + 1].y) / 2;
879 
880  cx[1] = (2 * sx[1] + sx[0]) / 3;
881  cy[1] = (2 * sy[1] + sy[0]) / 3;
882  cx[2] = (2 * sx[1] + sx[2]) / 3;
883  cy[2] = (2 * sy[1] + sy[2]) / 3;
884  cx[3] = sx[2];
885  cy[3] = sy[2];
886 
887  fprintf(out, "%d %d %d %d %d %d rrcurveto\n",
888  Coord(cx[1] - cx[0]), Coord(cy[1] - cy[0]),
889  Coord(cx[2] - cx[1]), Coord(cy[2] - cy[1]),
890  Coord(cx[3] - cx[2]), Coord(cy[3] - cy[2]));
891 
892  cx[0] = cx[3];
893  cy[0] = cy[3];
894  }
895  }
896  PS_LastPt(x, y);
897 }
898 
899 
900 #ifdef DEBUG
901 int debug_Char_Code = 0xFFFF;
902 FILE* tmpout;
903 int showlabel = FALSE;
904 int no_glyph = FALSE;
905 int no_control= FALSE;
906 
907 #define Fputps(_msg_) fprintf(tmpout, "%s\n", _msg_)
908 
909 
910 void
911 tmp_out(FILE* tmpout)
912 {
913  int i, j;
914 
915  Fputps("%!PS");
916  Fputps("%%% CharString debugging program.");
917  Fputps("%%% Generated by: ttf2pfb $Revision: 1.14 $");
918  Fputps("%%% plot char-string (pathes defined in /cjkxxxx)");
919  Fputps("");
920  Fputps("%%% user-defined parameter");
921  Fputps("/scalefactor .6 def");
922  Fputps("%% 0 black, 1 white");
923  Fputps("/glyph-outline-gray 0 def");
924  Fputps("/control-point-gray 0.7 def");
925  Fputps("");
926  Fputps("%%% calculate shifts and scale factor");
927  Fputps("currentpagedevice /PageSize get dup");
928  Fputps("0 get /pagewidth exch def");
929  Fputps("1 get /pageheight exch def");
930  Fputps("");
931  fprintf(tmpout,
932  "/llx %d.0 def /lly %d.0 def /urx %d.0 def /ury %d.0 def\n",
933  Coord(metrics.bbox.xMin / 64), Coord(metrics.bbox.yMin / 64),
934  Coord(metrics.bbox.xMax / 64), Coord(metrics.bbox.yMax / 64));
935  Fputps("/olwidth urx llx sub def");
936  Fputps("/olheight ury lly sub def");
937  Fputps("");
938  Fputps("/scale scalefactor pagewidth mul olwidth div def");
939  Fputps("/xshift pagewidth 1 scalefactor sub mul 2 div def");
940  Fputps("/yshift pageheight olheight scale mul sub 2 div def");
941  Fputps("");
942  Fputps("%% save old gray-scale value");
943  Fputps("/oldgray currentgray def");
944  Fputps("");
945  Fputps("%%% for point sequence label");
946  Fputps("/TimesRoman 8 selectfont");
947  Fputps("/i++ {i /i i 1 add def} def");
948  Fputps("/itos {4 string cvs} def");
949  Fputps("/point {2 copy i++ 3 1 roll 5 3 roll} def");
950  Fputps("/drawlabel");
951  Fputps(" {{moveto dup 0 eq {exit}");
952  Fputps(" {itos show} ifelse} loop pop} def");
953  Fputps("/nodrawlabel {clear} def");
954  Fputps("/i 0 def");
955  Fputps("");
956  Fputps("%%% for drawing glyph paths, redefine commands used in CharString");
957  Fputps("%% scaled to proper size");
958  Fputps("/addr {scale mul 3 -1 roll add 3 1 roll");
959  Fputps(" scale mul add exch 2 copy} def");
960  if (no_glyph)
961  {
962  Fputps("/rmoveto {addr pop pop point} def");
963  Fputps("/rlineto {addr pop pop point} def");
964  Fputps("/rrcurveto {8 4 roll addr 8 -2 roll addr 8 -2 roll addr");
965  Fputps(" 8 2 roll 6 {pop} repeat point} def");
966  }
967  else
968  {
969  Fputps("/rmoveto {addr moveto point} def");
970  Fputps("/rlineto {addr lineto point} def");
971  Fputps("/rrcurveto {8 4 roll addr 8 -2 roll addr 8 -2 roll addr");
972  Fputps(" 8 2 roll curveto point} def");
973  }
974  Fputps("/hsbw {pop pop");
975  Fputps(" xshift llx scale mul sub");
976  Fputps(" yshift lly scale mul sub} def");
977  Fputps("/endchar {stroke pop pop} def");
978  Fputps("");
979  Fputps("%%% for drawing control paths");
980  Fputps("/T {pop lly sub scale mul yshift add exch");
981  Fputps(" llx sub scale mul xshift add exch } def");
982  Fputps("/mt {T 2 copy moveto} def");
983  if (no_control)
984  Fputps("/lt {T} def");
985  else
986  Fputps("/lt {T 2 copy lineto} def");
987  Fputps("");
988  Fputps("1 setlinecap 1 setlinejoin");
989  Fputps("%%% draw control points and paths");
990  Fputps("control-point-gray setgray");
991 
992  for (i = 0, j = 0; i < outline.n_contours; i++)
993  {
994  Fputps("");
995  fprintf(tmpout,
996  "%d %d %d %d mt\n",
997  j,
999  outline.flags[j]);
1000  j++;
1001  for (; j <= outline.contours[i]; j++)
1002  fprintf(tmpout,
1003  "%d %d %d %d lt\n",
1004  j,
1006  outline.flags[j]);
1007  Fputps("closepath");
1008  }
1009  Fputps("stroke");
1010  if (showlabel && !no_control)
1011  Fputps("drawlabel");
1012  else
1013  Fputps("nodrawlabel");
1014  Fputps("");
1015  Fputps("%%% draw glyph outlines");
1016  Fputps("glyph-outline-gray setgray");
1017  Fputps("");
1018 }
1019 #endif
1020 
1021 
1022 /*
1023  * Construct CharString of a glyph.
1024  */
1025 
1026 short
1028  UShort char_Code)
1029 {
1030  int idx, i, j;
1031  UShort start_offpt, end_offpt = 0, fst;
1032 #if DEBUG
1033  FILE* oldout = out;
1034  int loop = 1;
1035 #endif
1036 
1037  if (force_enc == X)
1038  char_Code = JIS_to_SJIS(char_Code);
1039 
1040  idx = TT_Char_Index(cmap, char_Code);
1041  if (idx == 0)
1042  return FALSE;
1043 
1044  if (!LoadTrueTypeChar(idx))
1045  fatal("Couldn't load character with index %d (code %d)", idx, char_Code);
1046 
1047  if (verbose)
1048  printf("0x%04x (%05d): %s\n",
1049  char_Code, idx, PS_GlyphName(idx, char_Code));
1050 
1051  /* Begin string */
1052  fprintf(out, "/%s {\n", PS_GlyphName(idx, char_Code));
1053 
1054 #ifdef DEBUG
1055  if (char_Code == debug_Char_Code)
1056  {
1057  tmp_out(tmpout);
1058  out = tmpout;
1059  loop = 0;
1060  }
1061  for (; loop < 2; loop++)
1062  {
1063 #endif
1064 
1065  /* coordinates are all relative to (0,0) in FreeType */
1066  fprintf(out, "0 %d hsbw\n", (int)(metrics.advance / 64));
1067 
1068  /* Initialize ending contour point, relative coordinates */
1069  lastpsx = lastpsy = 0;
1070 
1071  for (i = 0, j = 0; i < outline.n_contours; i++)
1072  {
1073  fst = j;
1075  j++;
1076 
1077  start_offpt = 0; /* start at least 1 */
1078 
1079  /*
1080  * data pts for all contours stored in one array.
1081  * each round j init at last j + 1
1082  */
1083 
1084  /*
1085  * start_offpt means start of off points.
1086  * 0 means no off points in record.
1087  * N means the position of the off point.
1088  * end_offpt means the ending off point.
1089  * lastx, lasty is the last ON point from which Curve and Line
1090  * shall start.
1091  */
1092 
1093  /*
1094  * start with j=0. into loop, j=1.
1095  * if pt[1] off, if start_offpt == 0, toggle start_offpt
1096  * next j=2. if on, now start_off != 0, run Curveto.
1097  * if pt[1] on, start_off == 0, will run Lineto.
1098  */
1099 
1100  for (; j <= outline.contours[i]; j++)
1101  {
1102  if (!(outline.flags[j] & TT_Flag_On_Curve))
1103  {
1104  if (!start_offpt)
1105  start_offpt = end_offpt = j;
1106  else
1107  end_offpt++;
1108  }
1109  else
1110  { /* On Curve */
1111  if (start_offpt)
1112  {
1113  /*
1114  * start_offpt stuck at j, end_offpt++.
1115  * end_offpt - start_offpt gives no of off pts.
1116  * start_offpt gives start of sequence.
1117  * why need outline.xCoord[j] outline.yCoord[j]?
1118  */
1119 
1120  PS_Curveto(out,
1122  start_offpt, end_offpt);
1123  start_offpt = 0;
1124 
1125  /*
1126  * also use start_offpt as indicator to save one variable!!
1127  * after curveto, reset condition.
1128  */
1129  }
1130  else
1132  }
1133  }
1134 
1135  /*
1136  * looks like closepath fst = first, i.e. go back to first
1137  */
1138 
1139  if (start_offpt)
1140  PS_Curveto(out,
1141  outline.points[fst].x, outline.points[fst].y,
1142  start_offpt, end_offpt);
1143  else
1144  Fputs("closepath");
1145  }
1146 
1147  Fputs("endchar");
1148 
1149 #if DEBUG
1150  out = oldout;
1151  }
1152  if (char_Code == debug_Char_Code)
1153  {
1154  if (showlabel && !no_glyph)
1155  Fputps("drawlabel");
1156  else
1157  Fputps("nodrawlabel");
1158  Fputps("");
1159  Fputps("%%% end of drawing");
1160  Fputps("oldgray setgray");
1161  Fputps("showpage");
1162  fclose(tmpout);
1163  }
1164 #endif
1165 
1166  Fputs(" } |-");
1167  return TRUE;
1168 }
1169 
1170 
1171 /*
1172  * Get code ranges of an encoding scheme either from
1173  * the eVecMap or a code range file.
1174  */
1175 
1176 EncVec*
1178 {
1179  EncVec* encVec = NULL;
1180  EVcRange* cRange = NULL;
1181  EVLow* lByte = NULL;
1182  UShort numCR = 0, numLow = 0;
1183  int start, end;
1184  int buflen = LINELEN, numAssigned;
1185  char buf[LINELEN];
1186 
1187  if (force_enc != 0)
1188  return eVecMap_force[force_enc];
1189 
1190  if (enc == NULL && eVecMap[pid][eid] != NULL)
1191  return eVecMap[pid][eid];
1192 
1193  /* parse each code range line */
1194  while (fgets(buf, buflen, enc) != NULL)
1195  {
1196  if (buf[0] != '#' && buf[0] != '\n')
1197  {
1198  if (strrchr(buf,':') != NULL)
1199  {
1200  /* if there is no high value declared before low value */
1201  if (lByte != NULL)
1202  {
1203  if (cRange == NULL)
1204  {
1205  /* default code range `0x00-0x00:' */
1206  cRange = re_alloc(cRange, ++numCR * sizeof (EVcRange),
1207  "Get_EncVec");
1208  cRange->high.start = cRange->high.end = 0;
1209  }
1210  /* Assign the last low value */
1211  (cRange + numCR - 1)->low = lByte;
1212  (cRange + numCR - 1)->numLowRanges = numLow;
1213  }
1214 
1215  /* New high byte range */
1216  cRange = re_alloc(cRange, ++numCR * sizeof (EVcRange), "Get_EncVec");
1217  (cRange + numCR - 1)->numLowRanges = numLow = 0;
1218  lByte = NULL;
1219 
1220  /* Parse code range */
1221  numAssigned = sscanf(buf, "%i %*40s %i", &start, &end);
1222  if (numAssigned <= 0 || numAssigned > 2)
1223  {
1224  mesg("%s: Get_EncVec: Invalid high code range.\n", prog);
1225  return NULL;
1226  }
1227  else
1228  {
1229  (cRange + numCR - 1)->high.start = start;
1230  if (numAssigned == 1)
1231  (cRange + numCR - 1)->high.end = start;
1232  else
1233  (cRange + numCR - 1)->high.end = end;
1234  }
1235  }
1236  else
1237  {
1238  lByte = re_alloc(lByte, ++numLow * sizeof (EVLow), "Get_EncVec");
1239  numAssigned = sscanf(buf, "%i %*40s %i", &start, &end);
1240  if (numAssigned <= 0 || numAssigned > 2)
1241  {
1242  mesg("%s: Get_EncVec: Invalid long code range.\n", prog);
1243  return NULL;
1244  }
1245  else
1246  {
1247  (lByte + numLow - 1)->start = start;
1248  if (numAssigned == 1)
1249  (lByte + numLow - 1)->end = start;
1250  else
1251  (lByte + numLow - 1)->end = end;
1252  }
1253  }
1254  }
1255  }
1256 
1257  if (cRange == NULL)
1258  {
1259  cRange = re_alloc(cRange, ++numCR * sizeof (EVcRange), "Get_EncVec");
1260  cRange->high.start = cRange->high.end = 0;
1261  cRange->numLowRanges = 0;
1262  }
1263 
1264  if (lByte != NULL)
1265  {
1266  (cRange + numCR - 1)->low = lByte;
1267  (cRange + numCR - 1)->numLowRanges = numLow;
1268  }
1269 
1270  encVec = re_alloc(encVec, 1 * sizeof (EncVec), "Get_EncVec");
1271  encVec->numCodeRanges = numCR;
1272  encVec->codeRange = cRange;
1273  return encVec;
1274 }
1275 
1276 
1277 /*
1278  * Match code ranges by a font plane.
1279  */
1280 
1281 EncVec*
1283  int plane)
1284 {
1285  UShort numCR = encVec->numCodeRanges;
1286  EVcRange* cRange = encVec->codeRange;
1287 
1288  EncVec* encV = NULL;
1289  EVcRange* planeCR = NULL;
1290  EVLow* planeLow = NULL;
1291  UShort nCR = 0, nLow = 0;
1292 
1293  int icr;
1294 
1295  if (compact)
1296  {
1297  int iChar = 0; /* summed # of chars */
1298  int nChar = (plane-1) * 256; /* the first char code ranges recorded */
1299  int recording = 0;
1300 
1301  /* if compact, plane starts from 1 to be */
1302  /* compatible with the CJK package */
1303 #ifdef WIN32
1304  if (plane < 1 || plane > 256)
1305 #else
1306  if (plane < 1 || plane > 99)
1307 #endif
1308  fatal("Get_PlaneEV: Given plane out of range");
1309 
1310  for (icr = 0; icr < numCR; icr++, cRange++)
1311  {
1312  UShort numLow = cRange->numLowRanges;
1313  int ipl;
1314 
1315  for (ipl = cRange->high.start; ipl <= cRange->high.end; ipl++)
1316  {
1317  EVLow* pLow = cRange->low;
1318  int ilow;
1319 
1320  if (recording)
1321  { /* if we have made a hit */
1322  if (planeLow != NULL)
1323  { /* if low byte range has not been saved */
1324  (planeCR + nCR - 1)->low = planeLow;
1325  (planeCR + nCR - 1)->numLowRanges = nLow;
1326  planeLow = NULL;
1327  }
1328 
1329  /* each new plane starts a EVcRange if */
1330  /* iChar is still less than nChar */
1331  if (iChar <= nChar)
1332  {
1333  planeCR = re_alloc(planeCR, ++nCR * sizeof (EVcRange),
1334  "Get_PlaneEV");
1335  (planeCR + nCR - 1)->high.start =
1336  (planeCR + nCR - 1)->high.end = ipl;
1337  (planeCR + nCR - 1)->numLowRanges = nLow = 0;
1338  }
1339  }
1340 
1341  /* scan each low byte range */
1342  for (ilow = 0; ilow < (numLow == 0 ? 1 : numLow); ilow++, pLow++)
1343  {
1344  int start, end, nLowChar;
1345 
1346  if (numLow == 0)
1347  { /* default range */
1348  start = 0x0;
1349  end = 0xff;
1350  }
1351  else
1352  {
1353  start = pLow->start;
1354  end = pLow->end;
1355  }
1356  nLowChar = end - start + 1;
1357  if (iChar + nLowChar > nChar)
1358  { /* a hit! */
1359  int bchar = start + nChar - iChar;
1360  if (planeCR == NULL)
1361  {
1362  /* the first time code range is recorded */
1363  planeCR = re_alloc(planeCR, ++nCR * sizeof (EVcRange),
1364  "Get_PlaneEV");
1365  (planeCR + nCR - 1)->high.start = ipl;
1366  (planeCR + nCR - 1)->high.end = ipl;
1367  }
1368 
1369  /* adjust range boundary */
1370  if (recording == 0)
1371  start = bchar;
1372  else
1373  end = bchar;
1374  nChar += 0xff;
1375 
1376  /* recording starts */
1377  recording++;
1378  }
1379 
1380  iChar += nLowChar; /* next range */
1381 
1382  if (recording)
1383  {
1384  /* a new low range */
1385  if (iChar <= nChar)
1386  {
1387  planeLow = re_alloc(planeLow, ++nLow * sizeof (EVLow),
1388  "Get_PlaneEV");
1389  (planeLow + nLow - 1)->start = start;
1390  (planeLow + nLow - 1)->end = end;
1391  }
1392  if (recording > 1 || iChar > nChar)
1393  {
1394  /* beyond recording range */
1395  (planeCR + nCR - 1)->numLowRanges = nLow;
1396  (planeCR + nCR - 1)->low = planeLow;
1397  encV = re_alloc(encV, 1 * sizeof (EncVec), "Get_PlaneEV");
1398  encV->numCodeRanges = nCR;
1399  encV->codeRange = planeCR;
1400  return encV;
1401  }
1402  }
1403  }
1404  }
1405  }
1406  /* we must finalize the ranges */
1407  if (recording)
1408  {
1409  (planeCR + nCR - 1)->numLowRanges = nLow;
1410  (planeCR + nCR - 1)->low = planeLow;
1411  encV = re_alloc(encV, 1 * sizeof (EncVec), "Get_PlaneEV");
1412  encV->numCodeRanges = nCR;
1413  encV->codeRange = planeCR;
1414  return encV;
1415  }
1416  }
1417  else
1418  {
1419  for (icr = 0; icr < numCR; icr++, cRange++)
1420  {
1421  if (plane >= cRange->high.start && plane <= cRange->high.end)
1422  {
1423  encV = re_alloc(encV, 1 * sizeof (EncVec), "Get_PlaneEV");
1424  planeCR = re_alloc(planeCR, 1 * sizeof (EVcRange), "Get_PlaneEV");
1425 
1426  planeCR->high.start = planeCR->high.end = plane;
1427  planeCR->numLowRanges = cRange->numLowRanges;
1428  planeCR->low = cRange->low;
1429  encV->numCodeRanges = 1;
1430  encV->codeRange = planeCR;
1431  return encV;
1432  }
1433  }
1434  }
1435  return NULL;
1436 }
1437 
1438 
1439 /*
1440  * The main subroutine for generating Type 1 fonts.
1441  * One subfont per call.
1442  */
1443 
1444 short
1446  int plane,
1447  FILE *enc,
1448  char *fname,
1449  int UID)
1450 {
1451  EncVec* encVec = Get_EncVec(enc);
1452  EncVec* planeEncVec;
1453  EVcRange* cRange;
1454  UShort numCR;
1455  UShort code;
1456  int ilow, iplan, ichar, irange;
1457 
1458  if (verbose)
1459  printf("Generating fonts...\n\n");
1460 
1461  if (encVec == NULL)
1462  return FALSE;
1463  if (mapping)
1464  planeEncVec = encVec;
1465  else
1466  if ((planeEncVec = Get_PlaneEV(encVec, plane)) == NULL)
1467  {
1468  mesg("%s: Can't find encoding vector for the font plane 0x%X.\n",
1469  prog, plane);
1470  return FALSE;
1471  }
1472 
1473  /* Header of Type1 font */
1474  PS_Head(out, plane, planeEncVec, fname, UID);
1475 
1476  numCR = planeEncVec->numCodeRanges;
1477  cRange = planeEncVec->codeRange;
1478 
1479  for (irange = 0; irange < numCR; irange++, cRange++)
1480  {
1481  EVLow* pLow = cRange->low;
1482  UShort nLow = cRange->numLowRanges;
1483 
1484  for (iplan = cRange->high.start; iplan <= cRange->high.end; iplan++)
1485  {
1486  if (nLow == 0)
1487  {
1488  for (ichar = 0; ichar <= 0xff; ichar++)
1489  {
1490  code = iplan << 8 | ichar;
1492  }
1493  }
1494  else
1495  {
1496  for (ilow = 0; ilow < nLow; ilow++, pLow++)
1497  {
1498  for (ichar = pLow->start; ichar <= pLow->end; ichar++)
1499  {
1500  code = iplan << 8 | ichar;
1502  }
1503  }
1504  }
1505  }
1506  }
1507  PS_Tail(out);
1508 
1509  return TRUE;
1510 }
1511 
1512 
1513 /*
1514  * Main: process options, file I/O, etc.
1515  */
1516 
1517 int
1519  char *argv[])
1520 {
1521  char *infile, *outfile, *encFile, *fname = "UNKNOWN";
1522  FILE *out, *enc;
1523  int result, plane = 0, UID = 4999999;
1524 
1525 #if defined(WIN32)
1527 #endif
1528 
1529 #ifndef KPATHSEA
1530  if ((prog = strrchr(argv[0], '/')))
1531  prog++;
1532  else
1533  prog = argv[0];
1534 #endif
1535 
1536 #ifdef KPATHSEA
1537  kpse_set_program_name(argv[0], NULL);
1539 #endif
1540 
1541  /* set up known encoding vectors */
1542  Known_Encodings();
1543 
1544  out = stdout;
1545  enc = NULL;
1546  infile = outfile = encFile = NULL;
1547 
1548  argc--;
1549  argv++;
1550 
1551  while (argc > 0)
1552  {
1553  if (argv[0][0] == '-')
1554  {
1555  switch (argv[0][1])
1556  {
1557  case 'v':
1558  case 'V':
1559  verbose = TRUE;
1560  break;
1561  case 'c':
1562  case 'C':
1563  compact = TRUE;
1564  break;
1565  case 'k':
1566  case 'K':
1567  keep = TRUE;
1568  break;
1569  case 'm':
1570  case 'M':
1571  mapping = TRUE;
1572  break;
1573  case 'p':
1574  case 'P':
1575  result = argv[0][2];
1576  argc--;
1577  argv++;
1578  if (result == 'i' || result == 'I')
1579  {
1580  /* Set the platform ID. Assumed upper bound is 64 */
1581  if ((pid = atoi(argv[0])) < 0 || pid > 64)
1582  /* Check the platform and encoding IDs. */
1583  fatal("Invalid platform ID %d", pid);
1584  }
1585  else if (result == 'l' || result == 'L')
1586  {
1587  result = 0;
1588  while (argv[0][result] == '0' &&
1589  toupper(argv[0][result + 1]) != 'X')
1590  result++; /* no octal number */
1591  sscanf(&argv[0][result], "%i", &plane);
1592  }
1593  break;
1594  case 'e':
1595  case 'E':
1596  result = argv[0][2];
1597  argc--;
1598  argv++;
1599  if (result == 'i' || result == 'I')
1600  {
1601  /* Set the encoding ID. */
1602  if ((eid = atoi(argv[0])) < 0 || eid > 64)
1603  fatal("Invalid encoding ID %d", eid);
1604  }
1605  else if (result == 'n' || result == 'N')
1606  encFile = argv[0];
1607  break;
1608  case 'u':
1609  case 'U':
1610  argc--;
1611  argv++;
1612  UID = atoi(argv[0]);
1613  break;
1614  case 'f':
1615  case 'F':
1616  result = argv[0][2];
1617  argc--;
1618  argv++;
1619  if (result == '\0')
1620  fname = argv[0];
1621  else if (result == 'o' || result == 'O')
1622  {
1623  switch (argv[0][0])
1624  {
1625  case 'g':
1626  case 'G':
1627  force_enc = GB;
1628  break;
1629  case 'k':
1630  case 'K':
1631  force_enc = KS;
1632  break;
1633  case 'b':
1634  case 'B':
1635  force_enc = Big5;
1636  break;
1637  case 'j':
1638  case 'J':
1639  result = argv[0][1];
1640  if (result == 'o' || result == 'O')
1641  force_enc = Johab;
1642  else
1643  force_enc = JIS;
1644  break;
1645  case 's':
1646  case 'S':
1647  force_enc = SJIS;
1648  break;
1649  case 'x':
1650  case 'X':
1651  force_enc = X;
1652  }
1653  }
1654  break;
1655  case 't': /* Get the TTF file name. */
1656  case 'T':
1657  argc--;
1658  argv++;
1659  infile = argv[0];
1660  break;
1661  case 'o': /* Set the output file name. */
1662  case 'O':
1663  argc--;
1664  argv++;
1665  outfile = argv[0];
1666  break;
1667  case 's': /* shift font bbox up or down */
1668  case 'S':
1669  argc--;
1670  argv++;
1671  sscanf(argv[0], "%f", &fontShift);
1672  break;
1673 #ifdef DEBUG
1674  case 'd': /* character code for debugging */
1675  case 'D':
1676  argc--;
1677  argv++;
1678  sscanf(argv[0], "%i", &debug_Char_Code);
1679  tmpout = fopen("ch-debug.ps", "wb");
1680  mesg("You have specified the character code 0x%04x for debugging.\n",
1681  debug_Char_Code);
1682  mesg("A PostScript program named `ch-debug.ps' will be created.\n");
1683  break;
1684  case 'l':
1685  case 'L':
1686  showlabel = TRUE;
1687  break;
1688  case 'n':
1689  case 'N':
1690  result = argv[0][2];
1691  if (result == 'g' || result == 'G')
1692  no_glyph = TRUE;
1693  else if (result == 'c' || result == 'C')
1694  no_control = TRUE;
1695  break;
1696 #endif
1697  default:
1698  Usage(1);
1699  }
1700  }
1701  else
1702  /* Set the input file name. */
1703  infile = argv[0];
1704 
1705  argc--;
1706  argv++;
1707  }
1708 
1709  /* Open the output file if specified. */
1710  if (outfile != NULL)
1711  /* Attempt to open the output file. */
1712  if ((out = fopen(outfile, "wb")) == 0)
1713  {
1714  fatal("Unable to open the output file `%s'", outfile);
1715  exit(FAILURE);
1716  }
1717 
1718  /* Validate the values passed on the command line. */
1719  if (infile == NULL)
1720  {
1721  mesg("%s: No input TTF file provided\n", prog);
1722  Usage(1);
1723  }
1724 
1725  if (encFile != NULL)
1726  {
1727 #ifdef WIN32
1728  char *name;
1729  name = kpse_find_file(encFile, kpse_enc_format, 0);
1730  if(name) {
1731  enc = fopen(name, "r");
1732  free(name);
1733  }
1734  else
1735  enc = NULL;
1736  if(!enc)
1737 #else
1738  if ((enc = fopen(encFile, "rt")) == 0)
1739 #endif
1740  fatal("No input code range file");
1741  }
1742 
1743  /* Initialize font engine */
1744  if (!Init_Font_Engine(infile))
1745  {
1746  if (out != stdout)
1747  {
1748  fclose(out);
1749  if (!keep)
1750  (void)unlink(outfile);
1751  }
1752  exit(FAILURE);
1753  }
1754 
1755  /* Generate the disassembled PFB font from the TrueType font */
1756  if (Generate_Font(out, plane, enc, fname, UID))
1757  result = 0;
1758  else
1759  result = 2;
1760 
1761  if (out != stdout)
1762  {
1763  fclose(out);
1764  if (result != 0)
1765  {
1766  mesg("%s: An error occurred while generating the font", prog);
1767  if (!keep)
1768  (void)unlink(outfile);
1769  }
1770  }
1771 
1774 
1775  exit(result);
1776 
1777  return 0; /* never reached */
1778 }
1779 
1780 
1781 /* end of ttf2pfb.c */
#define buflen
Definition: afm2pl.c:181
@ kpse_enc_format
Definition: afm2pl.c:372
int code
Definition: aftopl.c:52
#define name
#define language
Definition: aptex-macros.h:837
char * asctime(register const struct tm *timeptr)
Definition: asctime.c:129
size_t __cdecl strspn(char const *_Str, char const *_Control)
size_t __cdecl strcspn(char const *_Str, char const *_Control)
#define n
Definition: t4ht.c:1290
#define ap
#define free(a)
Definition: decNumber.cpp:310
#define strrchr
Definition: detex.c:67
int dummy
Definition: dummy.c:29
static int id
Definition: bifont.c:66
#define fopen
Definition: xxstdio.h:21
#define fgets
Definition: xxstdio.h:29
int sscanf()
int printf()
char * strcpy()
static void
Definition: fpif.c:118
TT_Error TT_Init_Post_Extension(TT_Engine engine)
Definition: ftxpost.c:365
TT_Error TT_Get_PS_Name(TT_Face face, TT_UShort index, TT_String **PSname)
Definition: ftxpost.c:481
TT_Error TT_Load_PS_Names(TT_Face face, TT_Post *ppost)
Definition: ftxpost.c:395
#define s
Definition: afcover.h:80
FILE * out
Definition: hbf2gf.c:286
static FILE * infile
Definition: rdjpgcom.c:61
static FILE * outfile
Definition: wrjpgcom.c:80
unsigned char UChar
Definition: bzip2.c:163
long TT_Error
Definition: freetype.h:664
TT_Error TT_Open_Face(TT_Engine engine, const TT_Text *fontPathName, TT_Face *face)
Definition: ttapi.c:261
TT_Error TT_New_Instance(TT_Face face, TT_Instance *instance)
Definition: ttapi.c:695
TT_UShort TT_Char_Index(TT_CharMap charMap, TT_ULong charCode)
Definition: ttapi.c:1984
TT_Error TT_Close_Face(TT_Face face)
Definition: ttapi.c:662
int TT_Get_CharMap_Count(TT_Face face)
Definition: ttapi.c:1851
TT_Error TT_Set_Instance_Resolutions(TT_Instance instance, TT_UShort xResolution, TT_UShort yResolution)
Definition: ttapi.c:752
TT_Error TT_Get_CharMap(TT_Face face, TT_UShort charmapIndex, TT_CharMap *charMap)
Definition: ttapi.c:1918
signed long TT_F26Dot6
Definition: freetype.h:123
TT_Error TT_Done_FreeType(TT_Engine engine)
Definition: ttapi.c:180
TT_Error TT_Set_Instance_CharSize(TT_Instance instance, TT_F26Dot6 charSize)
Definition: ttapi.c:862
TT_Error TT_Get_Face_Properties(TT_Face face, TT_Face_Properties *properties)
Definition: ttapi.c:387
TT_Error TT_Get_Glyph_Metrics(TT_Glyph glyph, TT_Glyph_Metrics *metrics)
Definition: ttapi.c:1276
TT_Error TT_Get_Glyph_Outline(TT_Glyph glyph, TT_Outline *outline)
Definition: ttapi.c:1244
TT_Error TT_New_Glyph(TT_Face face, TT_Glyph *glyph)
Definition: ttapi.c:1121
TT_Error TT_Init_FreeType(TT_Engine *engine)
Definition: ttapi.c:111
TT_Error TT_Get_Name_String(TT_Face face, TT_UShort nameIndex, TT_String **stringPtr, TT_UShort *length)
Definition: ttapi.c:2107
void TT_Transform_Outline(TT_Outline *outline, TT_Matrix *matrix)
Definition: ttapi.c:1677
TT_Error TT_Get_Name_ID(TT_Face face, TT_UShort nameIndex, TT_UShort *platformID, TT_UShort *encodingID, TT_UShort *languageID, TT_UShort *nameID)
Definition: ttapi.c:2057
TT_Error TT_Get_CharMap_ID(TT_Face face, TT_UShort charmapIndex, TT_UShort *platformID, TT_UShort *encodingID)
Definition: ttapi.c:1877
#define TTLOAD_DEFAULT
Definition: freetype.h:908
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
FT_UInt idx
Definition: cffcmap.c:135
void exit()
unsigned short UShort
Definition: ftraster.c:310
else
Definition: ftgrays.c:1658
kerning y
Definition: ttdriver.c:212
TT_Load_Glyph(TT_Size size, TT_GlyphSlot glyph, FT_UInt glyph_index, FT_Int32 load_flags)
Definition: ttgload.c:2807
int int cy
Definition: gdfx.h:13
int cx
Definition: gdfx.h:12
int atoi(const char *)
#define unlink(file)
Definition: config.h:413
unsigned short platform
Definition: cidtype2.c:153
#define buf
#define fclose
Definition: debug.h:100
#define kpse_program_name
Definition: types.h:322
#define fileno
Definition: win32lib.h:72
#define fprintf
Definition: mendex.h:64
FILE * enc
Definition: encoding.c:64
#define string
Definition: ctangleboot.c:111
#define loop
Definition: tie.c:8
long time_t
Definition: types.h:18
int setmode()
static void eval(struct ebuffer *buffer, int flags)
Definition: read.c:568
#define sprintf
Definition: snprintf.c:44
unsigned bchar
struct tm * localtime(const time_t *const timep)
Definition: localtime.c:1332
static struct tm tm
Definition: localtime.c:216
#define _O_BINARY
Definition: lfs.c:127
int low
Definition: combiners.h:904
int high
Definition: combiners.h:904
#define realloc
Definition: glob.c:206
float x
Definition: cordic.py:15
#define version
Definition: nup.c:10
union value value
Definition: obx.h:44
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF base if bpp PF set rept prefetch_distance PF set OFFSET endr endif endm macro preload_leading_step2 base if bpp ifc DST PF PF else if bpp lsl PF PF lsl PF sub
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst base endif endm macro PF ptr
char * fname
Definition: plain2.c:121
#define index(s, c)
Definition: plain2.h:351
integer ipl[4800]
Definition: pmxab.c:202
double scale
Definition: pnmhistmap.c:38
static int size
Definition: ppmlabel.c:24
type_C toupper(type_C)
time_t time()
static char * glyphname
Definition: splineoverlap.c:78
ShellFileEnvironment e
Definition: sh6.c:388
TT_Pos yMax
Definition: freetype.h:227
TT_Pos xMin
Definition: freetype.h:224
TT_Pos yMin
Definition: freetype.h:225
TT_Pos xMax
Definition: freetype.h:226
TT_UShort num_Names
Definition: freetype.h:602
TT_Short n_contours
Definition: freetype.h:175
TT_Byte * flags
Definition: freetype.h:179
TT_UShort * contours
Definition: freetype.h:180
TT_Vector * points
Definition: freetype.h:178
Definition: ftxpost.h:72
TT_F26Dot6 y
Definition: freetype.h:149
TT_F26Dot6 x
Definition: freetype.h:148
UShort end
Definition: ttf2pfb.c:221
UShort start
Definition: ttf2pfb.c:221
UChar end
Definition: ttf2pfb.c:226
UChar start
Definition: ttf2pfb.c:226
UShort numLowRanges
Definition: ttf2pfb.c:232
EVLow * low
Definition: ttf2pfb.c:233
EVHigh high
Definition: ttf2pfb.c:231
EVcRange * codeRange
Definition: ttf2pfb.c:239
UShort numCodeRanges
Definition: ttf2pfb.c:238
Definition: inftrees.h:24
Definition: pbmfont.h:11
Definition: pbmfont.h:4
Definition: mendex.h:20
Definition: texview.c:48
Definition: ttf.h:449
#define FILE
Definition: t1stdio.h:34
int j
Definition: t4ht.c:1589
long unsigned N
Definition: tex4ht.c:2765
TT_CharMap cmap
Definition: ttf2pfb.c:163
void fatal(const char *msg,...)
Definition: ttf2pfb.c:310
int verbose
Definition: ttf2pfb.c:113
TT_Face face
Definition: ttf2pfb.c:160
char * LookUp_Name(int index)
Definition: ttf2pfb.c:604
int keep
Definition: ttf2pfb.c:115
int main(int argc, char *argv[])
Definition: ttf2pfb.c:1518
void * re_alloc(void *ptr, size_t size, char *sub)
Definition: ttf2pfb.c:344
void mesg(const char *msg,...)
Definition: ttf2pfb.c:255
#define PS_Lineto(x, y)
Definition: ttf2pfb.c:149
#define Fputs(_string_)
Definition: ttf2pfb.c:137
unsigned short UShort
Definition: ttf2pfb.c:120
void PS_Tail(FILE *out)
Definition: ttf2pfb.c:822
TT_Face_Properties properties
Definition: ttf2pfb.c:169
int mapping
Definition: ttf2pfb.c:116
short Generate_Font(FILE *out, int plane, FILE *enc, char *fname, int UID)
Definition: ttf2pfb.c:1445
struct _EVLow EVLow
#define EID_SJIS
Definition: ttf2pfb.c:63
enc_type force_enc
Definition: ttf2pfb.c:89
struct _EVcRange EVcRange
int Init_Font_Engine(char *infile)
Definition: ttf2pfb.c:502
#define NAMELEN
Definition: ttf2pfb.c:106
#define PID_BIG5
Definition: ttf2pfb.c:66
#define TT_Flag_On_Curve
Definition: ttf2pfb.c:126
unsigned char UChar
Definition: ttf2pfb.c:123
TT_Glyph glyph
Definition: ttf2pfb.c:162
#define EID_JOHAB
Definition: ttf2pfb.c:71
TT_Outline outline
Definition: ttf2pfb.c:167
struct _EncVec EncVec
void Usage(int eval)
Definition: ttf2pfb.c:270
#define EID_GB
Definition: ttf2pfb.c:65
#define FAILURE
Definition: ttf2pfb.c:101
EncVec * Alloc_EncVec(int dummy,...)
Definition: ttf2pfb.c:364
#define LINELEN
Definition: ttf2pfb.c:105
TT_Glyph_Metrics metrics
Definition: ttf2pfb.c:168
TT_Engine engine
Definition: ttf2pfb.c:159
void PS_Head(FILE *out, int plane, EncVec *planeEV, char *font, int UID)
Definition: ttf2pfb.c:685
#define PID_SJIS
Definition: ttf2pfb.c:62
float fontShift
Definition: ttf2pfb.c:117
void Known_Encodings(void)
Definition: ttf2pfb.c:403
#define PID_JOHAB
Definition: ttf2pfb.c:70
#define EID_UNICODE
Definition: ttf2pfb.c:61
EncVec * Get_PlaneEV(EncVec *encVec, int plane)
Definition: ttf2pfb.c:1282
#define PID_UNICODE
Definition: ttf2pfb.c:60
#define PID_KS
Definition: ttf2pfb.c:68
TT_Post post
Definition: ttf2pfb.c:165
#define TRUE
Definition: ttf2pfb.c:93
#define FALSE
Definition: ttf2pfb.c:97
#define EID_BIG5
Definition: ttf2pfb.c:67
TT_F26Dot6 lastpsx
Definition: ttf2pfb.c:141
int compact
Definition: ttf2pfb.c:114
void fatal_error(const char *msg,...)
Definition: ttf2pfb.c:325
UShort JIS_to_SJIS(UShort code)
Definition: ttf2pfb.c:475
TT_Error error
Definition: ttf2pfb.c:164
short PS_CharString(FILE *out, UShort char_Code)
Definition: ttf2pfb.c:1027
#define PS_Moveto(x, y)
Definition: ttf2pfb.c:145
char * prog
Definition: ttf2pfb.c:133
char * PS_GlyphName(UShort idx, UShort code)
Definition: ttf2pfb.c:659
TT_Instance instance
Definition: ttf2pfb.c:161
#define DEFAULT_ENCODING_ID
Definition: ttf2pfb.c:79
EncVec * eVecMap_force[10]
Definition: ttf2pfb.c:246
#define PS_LastPt(x, y)
Definition: ttf2pfb.c:144
void PS_Curveto(FILE *out, TT_F26Dot6 x, TT_F26Dot6 y, int s, int e)
Definition: ttf2pfb.c:836
enc_type_
Definition: ttf2pfb.c:84
@ SJIS
Definition: ttf2pfb.c:85
@ KS
Definition: ttf2pfb.c:85
@ JIS
Definition: ttf2pfb.c:85
@ GB
Definition: ttf2pfb.c:85
@ X
Definition: ttf2pfb.c:85
@ Johab
Definition: ttf2pfb.c:85
@ Big5
Definition: ttf2pfb.c:85
int LoadTrueTypeChar(int idx)
Definition: ttf2pfb.c:632
#define DEFAULT_PLATFORM_ID
Definition: ttf2pfb.c:75
EncVec * eVecMap[5][10]
Definition: ttf2pfb.c:243
#define Coord(x)
Definition: ttf2pfb.c:143
int eid
Definition: ttf2pfb.c:130
struct _EVHigh EVHigh
#define PID_GB
Definition: ttf2pfb.c:64
char rcsid[]
Definition: ttf2pfb.c:57
int pid
Definition: ttf2pfb.c:129
enum enc_type_ enc_type
EncVec * Get_EncVec(FILE *enc)
Definition: ttf2pfb.c:1177
#define EID_KS
Definition: ttf2pfb.c:69
TT_F26Dot6 lastpsy
Definition: ttf2pfb.c:141
Definition: obx.h:51
@ start
Definition: preamble.c:52
#define va_start(pvar)
Definition: varargs.h:30
#define va_arg(pvar, type)
Definition: varargs.h:35
#define va_end(pvar)
Definition: varargs.h:38
char * va_list
Definition: varargs.h:22
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269
const char * copyright
Definition: xmain.c:73
#define encoding
Definition: xmlparse.c:588
#define end(cp)
Definition: zic.c:71