src/vflmkajt.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. main
  2. gen_class_deafult
  3. gen_fonts
  4. gen_fonts_jtex
  5. gen_fonts_pcf
  6. gen_fonts_ekan
  7. gen_fonts_ttf
  8. gen_fonts_ttf_opt
  9. read_tex_ttf
  10. read_tex_ttf2

   1 /* 
   2  * vflmkajt.c 
   3  * - a vflibcap entry generator for TrueType fonts
   4  *
   5  * - This program prints vflibcap entries to standard output.
   6  *
   7  *
   8  * by Hirotsugu Kakugawa
   9  *
  10  *  15 May 2001
  11  */
  12 /*
  13  * Copyright (C) 2001  Hirotsugu Kakugawa. 
  14  * All rights reserved.
  15  *
  16  * This program is free software; you can redistribute it and/or modify
  17  * it under the terms of the GNU General Public License as published by
  18  * the Free Software Foundation; either version 2, or (at your option)
  19  * any later version.
  20  * 
  21  * This program is distributed in the hope that it will be useful,
  22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24  * GNU General Public License for more details.
  25  * 
  26  * You should have received a copy of the GNU General Public License
  27  * along with this program; if not, write to the Free Software
  28  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
  29  */
  30 
  31 
  32 #include "config.h"
  33 #include "with.h"
  34 #include <stdio.h>
  35 #include <stdlib.h>
  36 #include <ctype.h>
  37 #include <unistd.h>
  38 #ifdef HAVE_STRING_H
  39 #include <string.h>
  40 #endif
  41 #include <sys/param.h>
  42 #include <sys/time.h>
  43 
  44 #include  "VFlib-3_6.h"
  45 #include  "VFsys.h"
  46 #include  "vflibcap.h"
  47 #include  "texfonts.h"
  48 #include  "jtex.h"
  49 #include  "fsearch.h"
  50 #include  "vflmklib.h"
  51 
  52 
  53 
  54 void  gen_class_deafult(void);
  55 
  56 
  57 char  *dpi   = NULL;
  58 int    dpi_i = DEFAULT_KPS_DPI;
  59 
  60 #define NDIRS    64
  61 int   n_dirs; 
  62 char  *fontdirs[NDIRS];
  63 
  64 char  *cs_name[2] = { "JISX0208", "JISX0212" };
  65 char  *font_name[2][5] = { { "min",   "goth",  "tmin",  "tgoth",  NULL },
  66                            { "minh",  "gothh", "tminh", "tgothh", NULL } };
  67 int   font_type[] =  {           0,        1,       2,        3,    -1 };
  68 char  *font_class = "pcf";
  69 
  70 char  *suffix = ".pk";
  71 char  *ttf_ff_min[2] = { "dfmimp3.ttc", "dfmin3_u.ttc" };
  72 char  *ttf_ff_got[2] = { "dfgotp5.ttc", "dfgot5_u.ttc" };
  73 char  *ttf_ad_min[2] = { "dfmimp3",     "dfmin3_u" };
  74 char  *ttf_ad_got[2] = { "dfgotp5",     "dfgot5_u" };
  75 
  76 #define NTTFS    1024
  77 int   n_ttfs; 
  78 char  *ext_texf[NTTFS];
  79 char  *ext_ttff[NTTFS];
  80 #define JTTF  ".jttf"
  81 
  82 int  use_jis0212 = 0;
  83 
  84 char *cmdline = NULL; 
  85 
  86 
  87 void  gen_fonts(void);
  88 void  gen_fonts_jtex(int cs);
  89 void  gen_fonts_pcf(int cs);
  90 void  gen_fonts_ekan(int cs);
  91 void  gen_fonts_ttf(int cs);
  92 void  gen_fonts_ttf_opt(int cs);
  93 
  94 void  read_tex_ttf(char *f);
  95 void  read_tex_ttf2(FILE *fp, char *f);
  96 
  97 
  98 
  99 int 
 100 main(int argc, char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
 101 {
 102   int     i;
 103   int    xargc;
 104   char **xargv;
 105 
 106   dpi = malloc(256);
 107   sprintf(dpi, "%d", dpi_i);
 108 
 109   cmdline = copy_cmdline(argc, argv);
 110 
 111   n_dirs = 0;
 112   for (i = 0; i < NDIRS; i++){
 113     fontdirs[i] = NULL;
 114   }
 115 
 116   n_ttfs = 0;
 117   for (i = 0; i < NTTFS; i++){
 118     ext_texf[i] = NULL;
 119     ext_ttff[i] = NULL;
 120   }
 121 
 122   xargc = argc; 
 123   xargv = argv;
 124 
 125   for (xargc--,xargv++; xargc > 0; xargc--,xargv++){
 126     if ((strcmp(*xargv, "--help") == 0)
 127         || (strcmp(*xargv, "-help") == 0)){
 128       printf("vflmkajt: generates vflibcap entriy for ASCII Japanese TeX\n");
 129       printf("Usage: vflmkajt [options]\n");
 130       printf("Options\n");
 131       printf("  -d DIR    : TFM file directory\n");
 132       printf("  -c CLASS  : Font class of Kanji font file\n");
 133       printf("              Supported class: 'pcf', 'ttf', or ekanji'\n");
 134       printf("              Default is 'pcf' class.\n");
 135       printf("  -x EXT    : A suffix added for font name mapping\n");
 136       printf("              Default: '.pk'\n");
 137       printf("  -jisx0212 : Generate vflibcap entries for JISX0212 fonts\n");
 138       printf("Options (when 'ttf' class is selected for Kanji font file)\n");
 139       printf("  -tm TTF      : Use TrueType file TTF for JISX0208 'min'fonts\n");
 140       printf("  -tg TTF      : Use TrueType file TTF for JISX0208 'goth' fonts\n");
 141       printf("  -tm0212 TTF  : Use TrueType file TTF for JISX0212 'minh' fonts\n");
 142       printf("  -tg0212 TTF  : Use TrueType file TTF for JISX0212 'gothh' fonts\n");
 143       printf("  -tf FILE     : A database file for TeX font and TrueType font file");
 144       printf("  -tx FONT TTF : A TeX font entry with TrueType file\n");
 145       printf("  The format of a file for -tf option is a sequence of");
 146       printf("  lines, each of which contains TeX font name and TrueType");
 147       printf("  font file name.");
 148 
 149       printf("Example: vflmkajt -d TEXMF -c pcf\n");
 150       exit(0);
 151 
 152     } else if (strcmp(*xargv, "-d") == 0){
 153       /* font dir */
 154       if (n_dirs == NDIRS){
 155         fprintf(stderr, "Too many TFM font directories\n");
 156         exit(1);
 157       }
 158       xargv++; xargc--;
 159       check_argc(xargc);
 160       fontdirs[n_dirs++] = x_strdup(*xargv);
 161 
 162     } else if (strcmp(*xargv, "-c") == 0){
 163       xargv++; xargc--;
 164       check_argc(xargc);
 165       font_class = strdup(*xargv);
 166       if ((strcmp(font_class, "pcf") != 0) 
 167           && (strcmp(font_class, "ekanji") != 0)
 168           && (strcmp(font_class, "ttf") != 0)){
 169         fprintf(stderr, 
 170                 "Unknown name. ('ttf', 'pcf', or 'ekanji' for -c option)\n");
 171         exit(1);
 172       }
 173 
 174     } else if (strcmp(*xargv, "-x") == 0){
 175       xargv++; xargc--;
 176       check_argc(xargc);
 177       if (strlen(*xargv) == 0){
 178         fprintf(stderr, "Suffix for -x option should not be zero length\n");
 179         exit(1);
 180       }
 181       suffix = strdup(*xargv);
 182 
 183     } else if (strcmp(*xargv, "-jisx0212") == 0){
 184       use_jis0212 = 1;
 185 
 186     } else if ((strcmp(*xargv, "-tm") == 0)
 187                || (strcmp(*xargv, "-tm0208") == 0)){
 188       xargv++; xargc--;
 189       check_argc(xargc);
 190       ttf_ff_min[0] = strdup(*xargv);
 191 
 192     } else if ((strcmp(*xargv, "-tg") == 0)
 193                || (strcmp(*xargv, "-tg0208") == 0)){
 194       xargv++; xargc--;
 195       check_argc(xargc);
 196       ttf_ff_got[0] = strdup(*xargv);
 197 
 198     } else if (strcmp(*xargv, "-tm0212") == 0){
 199       xargv++; xargc--;
 200       check_argc(xargc);
 201       ttf_ff_min[1] = strdup(*xargv);
 202 
 203     } else if (strcmp(*xargv, "-tg0212") == 0){
 204       xargv++; xargc--;
 205       check_argc(xargc);
 206       ttf_ff_got[1] = strdup(*xargv);
 207 
 208     } else if (strcmp(*xargv, "-tx") == 0){
 209       xargv++; xargc--;
 210       check_argc(xargc);
 211       if (n_ttfs == NTTFS){
 212         printf("Too many extra TrueType fonts\n"); 
 213         exit(1);
 214       }
 215       ext_texf[n_ttfs] = strdup(*xargv);
 216       xargv++; xargc--;
 217       check_argc(xargc);
 218       ext_ttff[n_ttfs] = strdup(*xargv);
 219       n_ttfs++;
 220 
 221     } else if (strcmp(*xargv, "-tf") == 0){
 222       xargv++; xargc--;
 223       check_argc(xargc);
 224       read_tex_ttf(*xargv);
 225 
 226     } else {
 227       if (*xargv[0] == '-'){
 228         fprintf(stderr, "vflmkajt: unknown option %s\n", *xargv);
 229         exit(1);
 230       }
 231       break;
 232 
 233     }
 234   }
 235 
 236   banner("Japanese TeX (ASCII Co. version)", "vflmkajt", cmdline);
 237 
 238   gen_class_deafult();    
 239   gen_fonts();
 240 
 241   return 0;
 242 }
 243 
 244 
 245 
 246 void
 247 gen_class_deafult(void)
     /* [<][>][^][v][top][bottom][index][help] */
 248 {
 249   int   i;
 250 
 251   printf("(%s %s", 
 252          VF_CAPE_VFLIBCAP_CLASS_DEFAULT_DEFINITION, FONTCLASS_NAME_JTEX);
 253   printf("\n  (%s", VF_CAPE_TEX_TFM_DIRECTORIES);
 254   for (i = 0; i < n_dirs; i++)
 255     printf("\n       \"%s\"", fontdirs[i]);
 256   printf(")");
 257   printf("\n  (%s \".tfm\")", VF_CAPE_TEX_TFM_EXTENSIONS);
 258   printf("\n  (%s \"%s\")", VF_CAPE_JTEX_MAP_SUFIX, suffix);
 259   printf(")");
 260   printf("\n");
 261 }
 262 
 263 
 264 void
 265 gen_fonts(void)
     /* [<][>][^][v][top][bottom][index][help] */
 266 {
 267   if (strcmp(font_class, "pcf") == 0){
 268     printf("\n; %s", cs_name[0]);
 269     gen_fonts_pcf(0);
 270     gen_fonts_jtex(0);
 271     if (use_jis0212 == 1){
 272       printf("\n; %s", cs_name[1]);
 273       gen_fonts_pcf(1);
 274       gen_fonts_jtex(1);
 275     }
 276   } else if (strcmp(font_class, "ekanji") == 0){
 277     printf("\n; %s", cs_name[0]);
 278     gen_fonts_ekan(0);
 279     gen_fonts_jtex(0);
 280     if (use_jis0212 == 1){
 281       printf("\n; %s", cs_name[1]);
 282       gen_fonts_ekan(1);
 283       gen_fonts_jtex(1);
 284     }
 285   } else if (strcmp(font_class, "ttf") == 0){
 286     printf("\n; %s", cs_name[0]);
 287     gen_fonts_ttf(0);
 288     gen_fonts_jtex(0);
 289     gen_fonts_ttf_opt(0);
 290     if (use_jis0212 == 1){
 291       printf("\n; %s", cs_name[1]);
 292       gen_fonts_ttf(1);
 293       gen_fonts_jtex(1);
 294     }
 295   }
 296   printf("\n");
 297 }
 298 
 299 
 300 void
 301 gen_fonts_jtex(int cs)
     /* [<][>][^][v][top][bottom][index][help] */
 302 {
 303   int   p, i;
 304   static int   pt[] = { 5, 6, 7, 8, 9, 10, 12, -1};
 305 
 306   for (i = 0; font_name[cs][i] != NULL; i++){
 307     for (p = 0; pt[p] > 0; p++){
 308       printf("\n(%s   %s%d%s", 
 309              VF_CAPE_VFLIBCAP_FONT_ENTRY_DEFINITION, 
 310              font_name[cs][i], pt[p], suffix);
 311       printf("    \t(%s %2d)", VF_CAPE_JTEX_KF_POINT_SIZE, pt[p]);
 312       printf(" %s-def)", font_name[cs][i]);
 313     }
 314   }
 315   printf("\n");
 316 }
 317 
 318 
 319 
 320 void
 321 gen_fonts_pcf(int cs)
     /* [<][>][^][v][top][bottom][index][help] */
 322 {
 323   char  *f, *dr;
 324   int  i;
 325   char *adj[2]  = { "jiskan24",  
 326                     "jiskan24" };
 327   char *font[2] = { "\"jiskan24.pcf\" \"jiskan16.pcf\" \"k14.pcf\"",
 328                     "\"jisksp40.pcf\"" };
 329   
 330   for (i = 0; font_name[cs][i] != NULL; i++){
 331     f = font_name[cs][i];
 332     dr = ((font_type[i] & 0x02) == 0) ? "" : "t";
 333     printf("\n");
 334     printf("(define-macro %s-def", f);
 335     printf("\n  (font-class ascii-jtex-kanji) (kanji-font jtex-%s)", f);
 336     printf("\n  (kanji-font-magnification %.2f)", 0.85);
 337     printf("  (metric-adjustment-file \"%s%s.adj\"))", dr, adj[cs]);
 338     printf("\n");
 339     printf("(define-font jtex-%s", f);
 340     printf("\t(font-class pcf)");
 341     printf("\n");
 342     printf("  (font-file %s))", font[cs]);
 343   }
 344 }
 345 
 346 
 347 
 348 void
 349 gen_fonts_ekan(int cs)
     /* [<][>][^][v][top][bottom][index][help] */
 350 {
 351   char  *f, *dr;
 352   int  i;
 353   char *adj[2]  = { "ekanji",  
 354                     "ekanji" };
 355   char *font[2] = { "\"jisx9052.d24\" ",
 356                     "\"ekan0010.d24\"" };
 357   
 358   for (i = 0; font_name[cs][i] != NULL; i++){
 359     f = font_name[cs][i];
 360     dr = ((font_type[i] & 0x02) == 0) ? "" : "t";
 361     printf("\n");
 362     printf("(define-macro %s-def", f);
 363     printf("\n  (font-class ascii-jtex-kanji) (kanji-font jtex-%s)", f);
 364     printf("\n  (kanji-font-magnification %.2f)", 0.85);
 365     printf("  (metric-adjustment-file \"%s%s.adj\"))", dr, adj[cs]);
 366     printf("\n");
 367     printf("(define-font jtex-%s", f);
 368     printf("\t(font-class ekanji)");
 369     printf("\n");
 370     printf("  (font-file %s)", font[cs]);
 371     if ((font_type[i] & 0x02) == 0){
 372       printf(" (writing-direction \"horizontal\")");
 373     } else {
 374       printf(" (writing-direction \"vertical\")");
 375     }
 376     if (cs == 0){ /* jisx0208 */
 377       printf("\n  (character-set \"eKanji\")");
 378       printf(" (encoding \"ISO2022\")");
 379       printf("\n  (font-character-set \"eKanji\")");
 380       printf(" (font-encoding \"SEQUENTIAL2-1\")");
 381     } else {      /* jisx0212 */
 382       printf("\n  (mock-font-encoding with-offset -0x4dff)");
 383       printf("\n  (character-set \"JISX0212\")");
 384       printf(" (encoding \"ISO2022\")");
 385       printf("\n  (font-character-set \"Unicode\")");
 386       printf(" (font-encoding \"Unicode\")");
 387     }
 388     printf(")");
 389   }
 390 }
 391 
 392 
 393 void
 394 gen_fonts_ttf(int cs)
     /* [<][>][^][v][top][bottom][index][help] */
 395 {
 396   char  *f, *ff, *dr, *ad;
 397   int  i;
 398 
 399   for (i = 0; font_name[cs][i] != NULL; i++){
 400     f = font_name[cs][i];
 401     dr = ((font_type[i] & 0x02) == 0) ? "" : "t";
 402     ff = ((font_type[i] % 0x02) == 0) ? ttf_ff_min[cs] : ttf_ff_got[cs];
 403     ad = ((font_type[i] % 0x02) == 0) ? ttf_ad_min[cs] : ttf_ad_got[cs];
 404     printf("\n");
 405     printf("(define-macro %s-def", f);
 406     printf("\t(font-class ascii-jtex-kanji)");
 407     printf(" (kanji-font jtex-%s)", f);
 408     printf("\n ");
 409     printf(" (kanji-font-magnification %.2f)", 0.95);
 410     printf(" (metric-adjustment-file \"%s%s.adj\")", dr, ad);
 411     printf(")");
 412     printf("\n");
 413     printf("(define-font jtex-%s", f);
 414     printf("\t(font-class truetype)");
 415     printf(" (font-file \"%s\")", ff);
 416     printf("\n ");
 417     printf(" (character-set \"%s\")", cs_name[cs]);
 418     printf(" (encoding \"ISO2022\")");
 419     printf(")");
 420   }
 421   printf("\n");
 422 }
 423 
 424 void
 425 gen_fonts_ttf_opt(int cs)
     /* [<][>][^][v][top][bottom][index][help] */
 426 {
 427   int  i;
 428 
 429   if (n_ttfs == 0)
 430     return;
 431 
 432   printf("\n");
 433   printf("(define-macro jtex-h-def");
 434   printf("\t(font-class ascii-jtex-kanji)");
 435   printf("\n ");
 436   printf(" (kanji-font-point-size 10)");
 437   printf(" (metric-adjustment-file \"%s%s\")", "", "f5ajchm3.adj");
 438   printf(")");
 439   printf("\n");
 440   printf("(define-macro jtex-v-def");
 441   printf("\t(font-class ascii-jtex-kanji)");
 442   printf("\n ");
 443   printf(" (kanji-font-point-size 10)");
 444   printf(" (metric-adjustment-file \"%s%s\")", "t", "f5ajchm3.adj");
 445   printf(")");
 446   printf("\n");
 447   printf("(define-macro jtex-ttf");
 448   printf("\t\t(font-class truetype)");
 449   printf(" (dpi $TeX_DPI)");
 450   printf("\n ");
 451   printf(" (platform-id \"microsoft\")");
 452   printf(" (character-set \"%s\")", cs_name[cs]);
 453   printf(" (encoding \"ISO2022\")");
 454   printf(")");
 455   printf("\n");
 456 
 457   for (i = 0; i < n_ttfs; i++){
 458     printf("\n");
 459     printf("(define-font  %s%s\tjtex-h-def (kanji-font  %s%s))",
 460            ext_texf[i], suffix, ext_texf[i], JTTF);
 461     printf("\n");
 462     printf("(define-font  %s%s\tjtex-ttf (font-file \"%s\"))",
 463            ext_texf[i], JTTF, ext_ttff[i]);
 464     printf("\n");
 465     printf("(define-font t%s%s\tjtex-v-def (kanji-font t%s%s))",
 466            ext_texf[i], suffix, ext_texf[i], JTTF);
 467     printf("\n");
 468     printf("(define-font t%s%s\tjtex-ttf (font-file \"%s\"))",
 469            ext_texf[i], JTTF, ext_ttff[i]);
 470   }
 471 }
 472 
 473 
 474 
 475 void
 476 read_tex_ttf(char *f)
     /* [<][>][^][v][top][bottom][index][help] */
 477 {
 478   FILE  *fp;
 479 
 480   if (strcmp(f, "--") == 0){
 481     read_tex_ttf2(stdin, "standard input"); 
 482   } else {
 483     if ((fp = fopen(f, "r")) != NULL){
 484       read_tex_ttf2(fp, f); 
 485       fclose(fp);
 486     }
 487   }
 488 }
 489 
 490 void
 491 read_tex_ttf2(FILE *fp, char *f)
     /* [<][>][^][v][top][bottom][index][help] */
 492 {
 493   char  lbuf[BUFSIZ];
 494   char *p, *q[2];
 495   int  i;
 496 
 497   while (fgets(lbuf, sizeof(lbuf), fp) != NULL){
 498     if ((p = strchr(lbuf, '#')) != NULL)
 499       *p = '\0';
 500     if ((p = strchr(lbuf, '\n')) != NULL)
 501       *p = '\0';
 502     if (lbuf[0] == '\0')
 503       continue;
 504     q[0] = q[1] = NULL;
 505     p = lbuf; 
 506     for (i = 0; i < 2; i++){
 507       while ((*p != '\0') && (isspace((int)*p)))
 508         p++; 
 509       if (*p == '\0')
 510         break;
 511       q[i] = p;
 512       while ((*p != '\0') && (!isspace((int)*p)))
 513         p++;      
 514       if (*p == '\0')
 515         break;
 516       *p = '\0';
 517       p++; 
 518     }
 519     if (q[0] == NULL)
 520       continue;
 521     if (n_ttfs == NTTFS){
 522       printf("Too many extra TrueType fonts in %s\n", f); 
 523       exit(1);
 524     }
 525     if (q[1] == NULL)
 526       q[1] = q[0];
 527     ext_texf[n_ttfs] = x_strdup(q[0]);
 528     ext_ttff[n_ttfs] = x_strdup(q[1]);
 529     n_ttfs++;
 530   }
 531 }

/* [<][>][^][v][top][bottom][index][help] */