utils/ctext2pgm-1.5.2/ctext2pgm.c

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

FUNCTIONS

This source file includes following functions.
  1. main
  2. parse_args
  3. usage
  4. make_text_bitmap
  5. parser
  6. parser_eol
  7. parser_check_wdir
  8. parser_wdir_push
  9. parser_wdir_pop
  10. parser_wdir_do_push
  11. parser_wdir_do_pop
  12. charset_wdirection
  13. draw_char
  14. cp_conv
  15. put_bitmap
  16. reverse_bitmap
  17. swap_refpt_nextpt
  18. parser_cmd
  19. change_fonts
  20. try_font_open
  21. parser_init
  22. charset_name
  23. show_font_list
  24. wprint

   1 /* ctext2pgm.c
   2  *  --- make a bitmap of a text encoded in compound text.
   3  *      Bitmap is printed in PBM or PGM format.
   4  *
   5  * by Hirotsugu Kakugawa (h.kakugawa@computer.org)
   6  * 
   7  * Copyright (C) 1998,1999  by H. Kakugawa
   8  *
   9  * The following character sets are supported:
  10  *    ASCII               (English), 
  11  *    ISO 8859-1,2,3,4,9  (English, German, Italy, French, Spanish, etc)
  12  *    ISO 8859-5          (Russian)
  13  *    ISO 8859-7          (Greek)
  14  *    ISO 8859-8          (Hebrew)
  15  *    JIS X 0201          (Japanese Roman and and Roman)
  16  *    JIS X 0208          (Japanese Kanji)
  17  *    GB 2312             (Chinese Hanzi)
  18  *    KSC 5601            (Hangle)
  19  *    Mule Arabic         (Arabic by the Mule editor)
  20  *    Mule Big 5          (Chinese BIG5 by the Mule editor)
  21  *    Mule Viscii 1.1     (Vietnamese by the Mule editor)
  22  *    Mule Ethiopic       (Ethiopic by the Mule editor)
  23  *
  24  * The following encodings are supported:
  25  *    Compound text      
  26  *    Japanese EUC 
  27  *    Korean EUC 
  28  *    Chinese EUC 
  29  *    Shift JIS 
  30  *
  31  *
  32  * Edition History
  33  *   5 Jun 1998  Support for character sets ISO8859-1, JIS X0208, KSC 5601, and
  34  *               GB 2312. Output in PBM format.  Font face selection feature. 
  35  *   6 Jun 1998  Added font family selection.
  36  *   7 Jun 1998  Support for output of PGM format and anti-aliasing.
  37  *   8 Jun 1998  Support for ISO8859-2,3,4,5,7,9 charsets.
  38  *   9 Jun 1998  Support for JIS X0201-Roman and JIS X0201-Kana charsets.
  39  *               Fixed bugs in the compound text parser.
  40  *  11 Jun 1998  Support for EUC-JP, EUC-KR, and EUC-GB, EUC-CNS for input 
  41  *               text encodings.
  42  *  12 Jun 1998  Support for right-to-left directionality (e.g., Hebrew)
  43  *               in left-to-right directionality text. 
  44  *  13 Jun 1998  Support for right-to-left directionality. ISO8859-8
  45  *               (Hebrew) charset is supported. Scripts of left-to-right 
  46  *               directionality in right-to-left script is also supported.
  47  *               Support for code sets 2 and 4 of EUC-JP encoding. 
  48  *  15 Jun 1998  Support for Shift-JIS encoding. Added a command line option 
  49  *               for page width and height specification. 
  50  *               Added reversed character command in input text.
  51  *               Support for arabic text file created by Mule.
  52  *  16 Jun 1998  Added page width/height and center/flush-left/flush-right
  53  *               features.
  54  *  18 Jun 1998  Enhanced searcing mechanism for opening fonts. 
  55  *               Added a feature to print font list.
  56  *  22 Jun 1998  Added ASCII art output format.
  57  *  23 Jun 1998  Added EPS and vertical ASCII art output formats.
  58  *  25 Nov 1998  Image file output code is adopted in VFlib; ctext2pgm
  59  *               is changed to use image output functions in VFlib.
  60  *  15 Dec 1998  Added -center-line, -h-center-line, -v-center-line,
  61  *               -left-line and -right-line options.
  62  *  22 Apr 1999  Added -bbx option for generating minimum image.
  63  *  11 Jan 1999  Added Mule-VISCII, Mule-Ethiopic Mule-Big5 charsets
  64  *  12 Jan 1999  Improved to handle jisx0201-kana designated in G0.
  65  *  13 Jan 1999  Added tab stop feature.
  66  */
  67    
  68 /*
  69  * Copyright (C) 1998,1999  Hirotsugu Kakugawa. 
  70  * All rights reserved.
  71  *
  72  * This program is free software; you can redistribute it and/or modify
  73  * it under the terms of the GNU General Public License as published by
  74  * the Free Software Foundation; either version 2, or (at your option)
  75  * any later version.
  76  * 
  77  * This program is distributed in the hope that it will be useful,
  78  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  79  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  80  * GNU General Public License for more details.
  81  * 
  82  * You should have received a copy of the GNU General Public License
  83  * along with this program; if not, write to the Free Software
  84  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
  85  */
  86 
  87 
  88 #include <stdio.h>
  89 #include <stdlib.h>
  90 
  91 #include <VFlib-3_6.h>
  92 
  93 #include "ctext2pgm.h"
  94 #include "fontdef.h"
  95 
  96 
  97 void  parse_args(int *argcp, char ***argvp);
  98 void  usage(int level);
  99 void  make_text_bitmap(FILE *fp, char *title);
 100 void  parser(FILE *fp, VF_BITMAPLIST page_buff);
 101 void  parser_eol(VF_BITMAPLIST *line_buff_p, VF_BITMAPLIST page_buff, 
 102                  int vposx, int vposy);
 103 void  parser_check_wdir(int i, VF_BITMAPLIST *line_buff_p);
 104 void  parser_wdir_push(int wdir, VF_BITMAPLIST *line_buff_p);
 105 void  parser_wdir_pop(VF_BITMAPLIST *line_buff_p);
 106 void  parser_wdir_do_push(int wdir, VF_BITMAPLIST *line_buff_p);
 107 void  parser_wdir_do_pop(VF_BITMAPLIST *line_buff_p);
 108 int   charset_wdirection(int charset);
 109 void  parser_cmd(long code_point, VF_BITMAPLIST page_buff, 
 110                  int *charset_saved_p, int g, int *posxp, int *posyp);
 111 void  parser_init(void);
 112 void  draw_char(long code_point, VF_BITMAPLIST bmlist, int g, 
 113                 int *posxp, int *posyp);
 114 void  put_bitmap(VF_BITMAPLIST buff, VF_BITMAP bm, 
 115                  int wdir, int *posxp, int *posyp);
 116 long  cp_conv(long code_point, int i);
 117 void  reverse_bitmap(VF_BITMAP bm);
 118 void  swap_refpt_nextpt(VF_BITMAP bm);
 119 void  change_fonts(int g);
 120 int   try_font_open(int table_index);
 121 char* charset_name(int charset, char *if_unknown);
 122 void  show_font_list(void);
 123 void  wprint(char *str, int w);
 124 
 125 
 126 extern VF_BITMAP  vf_alloc_bitmap(int,int);
 127 
 128 
 129 int     input_encoding;
 130 int     output_format;
 131 
 132 char    *vflibcap;
 133 double  magx, magy;
 134 int     xpixel;
 135 int     pixel;
 136 double  baselineskip;
 137 int     pix_reverse;
 138 int     output_format;
 139 int     minimum_image;
 140 int     shrink_factor;
 141 double  tab_skip;
 142 int     wdirection;
 143 int     page_width, page_height;
 144 int     margin_x, margin_y;
 145 int     line_typeset;
 146 int     image_position_h, image_position_v;
 147 int     default_family;
 148 int     default_face;
 149 double  eps_ptsize;
 150 
 151 /* For debugging */
 152 
 153 int     debug_state;
 154 int     debug_r2l;
 155 int     debug_font;
 156 int     debug_page_bitmap;
 157 int     debug_line_bitmap;
 158 int     debug_char_bitmap;
 159 int     debug_vflib;
 160 
 161 
 162 /* For encoding parser: parser states  */
 163 int  current_family;           /* current font family */
 164 int  current_face;             /* current font face */
 165 int  current_reverse;          /* reverse black and white of char */
 166 int  current_font_g[4];        /* current fonts for G0 and G1 */
 167 int  font_exists_g[4];         /* font existence flag for G0 and G1 */
 168 int  current_wdir_g[4];
 169 int   type_g[4];                /* 94/96 of G0/G1 */
 170 int   charset_g[4];             /* charset IDs of G0/G1 */
 171 int   chlen_g[4];               /* bytes per char of G0/G1 */
 172 
 173 struct s_dir_stack_elem dir_stack[MAX_DIR_STACK];  /* direction stack */
 174 int  dir_sp;                                       /* stack pointer */
 175 int  nchars_in_line;
 176 
 177 /* Parser parameters */
 178 int   use_esc;
 179 int   use_csi;
 180 int   use_si;
 181 int   use_so;
 182 int   use_ss2;
 183 int   use_ss3;
 184 int   use_sjis;
 185 int   use_g1;
 186 int   use_g2;
 187 int   use_g3;
 188 
 189 
 190 
 191 int
 192 main(int argc, char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
 193 {
 194   FILE   *fp; 
 195   int     i;
 196 
 197   input_encoding = ENC_DEFAULT;
 198   output_format  = OFORM_DEFAULT;
 199   minimum_image  = 0;
 200 
 201   vflibcap         = DEFAULT_VFLIBCAP;
 202   magx             = DEFAULT_MAG;
 203   magy             = DEFAULT_MAG;
 204   pixel            = DEFAULT_PIXEL_SIZE;
 205   baselineskip     = DEFAULT_BASELINESKIP;
 206   shrink_factor    = 1;
 207   tab_skip         = DEFAULT_TAB_SKIP;
 208   pix_reverse      = DEFAULT_REVERSE;
 209   wdirection       = WDIR_DEFAULT;
 210   xpixel           = -1;
 211   eps_ptsize       = -1;
 212   margin_x         = DEFAULT_MARGIN;
 213   margin_y         = DEFAULT_MARGIN;
 214   page_width       = -1;
 215   page_height      = -1;
 216   line_typeset     = DEFAULT_LINE_POS;
 217   image_position_h = VF_IMAGEOUT_POSITION_NONE;
 218   image_position_v = VF_IMAGEOUT_POSITION_NONE;
 219 
 220   default_family  = FAM_DEFAULT;
 221   default_face    = FACE_DEFAULT;
 222   current_reverse = 0;
 223 
 224   debug_state       = 0;
 225   debug_r2l         = 0;
 226   debug_font        = 0;
 227   debug_page_bitmap = 0;
 228   debug_line_bitmap = 0;
 229   debug_char_bitmap = 0;
 230   debug_vflib       = 0;
 231  
 232   argc--; argv++;
 233   parse_args(&argc, &argv);
 234 
 235   current_family  = default_family;
 236   current_face    = default_face;
 237 
 238   if (debug_vflib == 1){
 239     if (vflibcap == NULL)
 240       printf("VF_Init(NULL, NULL)\n");
 241     else 
 242       printf("VF_Init(\"%s\", NULL)\n", vflibcap);
 243   }
 244 
 245   if (VF_Init(vflibcap, NULL) < 0){
 246     switch (vf_error){
 247     case VF_ERR_NO_VFLIBCAP:
 248       PR2("ctext2pgm: vflibcap is not found: \"%s\".\n",
 249           (vflibcap==NULL)?DEFAULT_VFLIBCAP:vflibcap);
 250       break;
 251     default:
 252       PR1("ctext2pgm: failed to initialize.\n");
 253       break;
 254     }
 255     exit(0);
 256   }
 257 
 258   for (i = 0; font_info[i].font_id >= 0; i++){
 259     font_info[i].font_id = NOT_OPENED;
 260   }
 261 
 262   if (argc == 0){
 263     make_text_bitmap(stdin, "stdin");
 264   } else {
 265     if ((fp = fopen(argv[0], "r")) == NULL){
 266       perror(argv[0]);
 267       exit(1);
 268     }
 269     make_text_bitmap(fp, argv[0]);
 270     fclose(fp);
 271   }
 272 
 273   return 0;
 274 }
 275 
 276 
 277 void
 278 parse_args(int *argcp, char ***argvp)
     /* [<][>][^][v][top][bottom][index][help] */
 279 {
 280   int  argc; 
 281   char **argv;
 282 
 283   argc = *argcp; 
 284   argv = *argvp;
 285 
 286   while ((argc > 0) && (*argv[0] == '-')){
 287     if (strcmp(argv[0], "-v") == 0){
 288       vflibcap = argv[1];
 289       argc--; argv++;
 290     } else if (strcmp(argv[0], "-m") == 0){
 291       magx = magy = atof(argv[1]); 
 292       argc--; argv++;
 293     } else if (strcmp(argv[0], "-mx") == 0){
 294       magx = atof(argv[1]);
 295       argc--; argv++;
 296     } else if (strcmp(argv[0], "-my") == 0){
 297       magy = atof(argv[1]);
 298       argc--; argv++;
 299     } else if (strcmp(argv[0], "-b") == 0){
 300       baselineskip = atof(argv[1]);
 301       if (baselineskip <= 0)
 302         baselineskip = 1.2;
 303       argc--; argv++;
 304     } else if (strcmp(argv[0], "-bbx") == 0){
 305       minimum_image = 1;
 306     } else if (strcmp(argv[0], "-g") == 0){
 307       margin_x = margin_y = atoi(argv[1]);
 308       argc--; argv++;
 309     } else if (strcmp(argv[0], "-gx") == 0){
 310       margin_x = atoi(argv[1]);
 311       argc--; argv++;
 312     } else if (strcmp(argv[0], "-gy") == 0){
 313       margin_y = atoi(argv[1]);
 314       argc--; argv++;
 315     } else if (strcmp(argv[0], "-r") == 0){
 316       pix_reverse = 1;
 317     } else if (strcmp(argv[0], "-14") == 0){
 318       pixel = 14;
 319     } else if (strcmp(argv[0], "-16") == 0){
 320       pixel = 16;
 321     } else if (strcmp(argv[0], "-18") == 0){
 322       pixel = 18;
 323     } else if (strcmp(argv[0], "-24") == 0){
 324       pixel = 24;
 325     } else if (strcmp(argv[0], "-scale") == 0){
 326       pixel = 0;
 327       xpixel = atoi(argv[1]);
 328       argc--; argv++;
 329     } else if (strcmp(argv[0], "-fixed") == 0){
 330       default_family = FAM_FIXED;
 331     } else if (strcmp(argv[0], "-times") == 0){
 332       default_family = FAM_TIMES;
 333     } else if (strcmp(argv[0], "-helv") == 0){
 334       default_family = FAM_HELV;
 335     } else if (strcmp(argv[0], "-cour") == 0){
 336       default_family = FAM_COUR;
 337     } else if (strcmp(argv[0], "-normal") == 0){
 338       default_face = FACE_NORMAL;
 339     } else if (strcmp(argv[0], "-bold") == 0){
 340       default_face = FACE_BOLD;
 341     } else if (strcmp(argv[0], "-italic") == 0){
 342       default_face = FACE_ITALIC;
 343     } else if (strcmp(argv[0], "-ctext") == 0){
 344       input_encoding = ENC_CTEXT;
 345     } else if (strcmp(argv[0], "-iso-8859-1") == 0){
 346       input_encoding = ENC_ISO8859_1;
 347     } else if (strcmp(argv[0], "-latin-1") == 0){
 348       input_encoding = ENC_ISO8859_1;
 349     } else if (strcmp(argv[0], "-iso-8859-2") == 0){
 350       input_encoding = ENC_ISO8859_2;
 351     } else if (strcmp(argv[0], "-latin-2") == 0){
 352       input_encoding = ENC_ISO8859_2;
 353     } else if (strcmp(argv[0], "-iso-8859-3") == 0){
 354       input_encoding = ENC_ISO8859_3;
 355     } else if (strcmp(argv[0], "-latin-3") == 0){
 356       input_encoding = ENC_ISO8859_3;
 357     } else if (strcmp(argv[0], "-iso-8859-4") == 0){
 358       input_encoding = ENC_ISO8859_4;
 359     } else if (strcmp(argv[0], "-latin-4") == 0){
 360       input_encoding = ENC_ISO8859_4;
 361     } else if (strcmp(argv[0], "-iso-8859-5") == 0){
 362       input_encoding = ENC_ISO8859_5;
 363     } else if (strcmp(argv[0], "-cyrillic") == 0){
 364       input_encoding = ENC_ISO8859_5;
 365     } else if (strcmp(argv[0], "-russian") == 0){
 366       input_encoding = ENC_ISO8859_5;
 367     } else if (strcmp(argv[0], "-iso-8859-6") == 0){
 368       input_encoding = ENC_ISO8859_6;
 369     } else if (strcmp(argv[0], "-iso-8859-7") == 0){
 370       input_encoding = ENC_ISO8859_7;
 371     } else if (strcmp(argv[0], "-greek") == 0){
 372       input_encoding = ENC_ISO8859_7;
 373     } else if (strcmp(argv[0], "-iso-8859-8") == 0){
 374       input_encoding = ENC_ISO8859_8;
 375     } else if (strcmp(argv[0], "-hebrew") == 0){
 376       input_encoding = ENC_ISO8859_8;
 377     } else if (strcmp(argv[0], "-iso-8859-9") == 0){
 378       input_encoding = ENC_ISO8859_9;
 379     } else if (strcmp(argv[0], "-iso-2022-jp") == 0){
 380       input_encoding = ENC_ISO2022_JP;
 381     } else if (strcmp(argv[0], "-junet") == 0){
 382       input_encoding = ENC_ISO2022_JP;
 383 #if 0
 384     } else if (strcmp(argv[0], "-iso-2022-kr") == 0){
 385       input_encoding = ENC_ISO2022_KR;
 386     } else if (strcmp(argv[0], "-iso-2022-cn") == 0){
 387       input_encoding = ENC_ISO2022_CN;
 388 #endif
 389     } else if (strcmp(argv[0], "-euc-jp") == 0){
 390       input_encoding = ENC_EUC_JP1;
 391     } else if (strcmp(argv[0], "-euc-jp1") == 0){
 392       input_encoding = ENC_EUC_JP1;
 393     } else if (strcmp(argv[0], "-euc-jp2") == 0){
 394       input_encoding = ENC_EUC_JP2;
 395     } else if (strcmp(argv[0], "-euc-kr") == 0){
 396       input_encoding = ENC_EUC_KR;
 397     } else if (strcmp(argv[0], "-euc-ch") == 0){
 398       input_encoding = ENC_EUC_CH_GB;
 399     } else if (strcmp(argv[0], "-euc-gb") == 0){
 400       input_encoding = ENC_EUC_CH_GB;
 401     } else if (strcmp(argv[0], "-euc-cns") == 0){
 402       input_encoding = ENC_EUC_CH_CNS;
 403     } else if (strcmp(argv[0], "-sjis") == 0){
 404       input_encoding = ENC_SJIS;
 405     } else if (strcmp(argv[0], "-l2r") == 0){
 406       wdirection = WDIR_L2R;
 407     } else if (strcmp(argv[0], "-r2l") == 0){
 408       wdirection = WDIR_R2L;
 409     } else if (strcmp(argv[0], "-pbm") == 0){
 410       output_format = OFORM_PBM_ASCII;
 411     } else if (strcmp(argv[0], "-pgm") == 0){
 412       output_format = OFORM_PGM_RAW;
 413     } else if (strcmp(argv[0], "-pbm-ascii") == 0){
 414       output_format = OFORM_PBM_ASCII;
 415     } else if (strcmp(argv[0], "-pgm-ascii") == 0){
 416       output_format = OFORM_PGM_ASCII;
 417 #if 0
 418     } else if (strcmp(argv[0], "-pbm-raw") == 0){
 419       output_format = OFORM_PBM_RAW;
 420 #endif
 421     } else if (strcmp(argv[0], "-pgm-raw") == 0){
 422       output_format = OFORM_PGM_RAW;
 423     } else if (strcmp(argv[0], "-eps") == 0){
 424       output_format = OFORM_EPS;
 425     } else if (strcmp(argv[0], "-eps-ptsize") == 0){
 426       if ((eps_ptsize = atof(argv[1])) <= 0)
 427         eps_ptsize = DEFAULT_EPS_POINT_SIZE;
 428       argc--; argv++;
 429     } else if (strcmp(argv[0], "-ascii-art") == 0){
 430       output_format = OFORM_ASCII_ART;
 431     } else if (strcmp(argv[0], "-ascii-art-h") == 0){
 432       output_format = OFORM_ASCII_ART;
 433     } else if (strcmp(argv[0], "-ascii-art-v") == 0){
 434       output_format = OFORM_ASCII_ART_V;
 435     } else if (strcmp(argv[0], "-none") == 0){
 436       output_format = OFORM_NONE;
 437     } else if (strcmp(argv[0], "-s") == 0){
 438       shrink_factor = atoi(argv[1]);
 439       argc--; argv++;
 440       if (shrink_factor <= 0){
 441         PR1("Shrink factor is too small. ");
 442         shrink_factor = 1;
 443       }
 444       if (shrink_factor > 8){
 445         PR1("Shrink factor is too large. ");
 446         shrink_factor = 8;
 447       }
 448     } else if (strcmp(argv[0], "-tab") == 0){
 449       tab_skip = atof(argv[1]);
 450       argc--; argv++;
 451     } else if (strcmp(argv[0], "-pw") == 0){
 452       page_width = atoi(argv[1]);
 453       argc--; argv++;
 454     } else if (strcmp(argv[0], "-ph") == 0){
 455       page_height = atoi(argv[1]);
 456       argc--; argv++;
 457     } else if (strcmp(argv[0], "-flush-left") == 0){
 458       line_typeset = LINE_FLUSH_LEFT;
 459       image_position_h = VF_IMAGEOUT_POSITION_LEFT;
 460     } else if (strcmp(argv[0], "-flush-right") == 0){
 461       line_typeset = LINE_FLUSH_RIGHT;
 462       image_position_h = VF_IMAGEOUT_POSITION_RIGHT;
 463     } else if (strcmp(argv[0], "-center") == 0){
 464       line_typeset = LINE_CENTER;
 465       image_position_h = VF_IMAGEOUT_POSITION_CENTER;
 466       image_position_v = VF_IMAGEOUT_POSITION_CENTER;
 467     } else if (strcmp(argv[0], "-center-line") == 0){
 468       line_typeset = LINE_CENTER;
 469     } else if (strcmp(argv[0], "-left-line") == 0){
 470       line_typeset = LINE_FLUSH_LEFT;
 471     } else if (strcmp(argv[0], "-right-line") == 0){
 472       line_typeset = LINE_FLUSH_RIGHT;
 473     } else if (strcmp(argv[0], "-center-image") == 0){
 474       image_position_h = VF_IMAGEOUT_POSITION_CENTER;
 475       image_position_v = VF_IMAGEOUT_POSITION_CENTER;
 476     } else if (strcmp(argv[0], "-h-center-image") == 0){
 477       image_position_h = VF_IMAGEOUT_POSITION_CENTER;
 478     } else if (strcmp(argv[0], "-v-center-image") == 0){
 479       image_position_v = VF_IMAGEOUT_POSITION_CENTER;
 480     } else if (strcmp(argv[0], "-left-image") == 0){
 481       image_position_h = VF_IMAGEOUT_POSITION_LEFT;
 482     } else if (strcmp(argv[0], "-right-image") == 0){
 483       image_position_h = VF_IMAGEOUT_POSITION_RIGHT;
 484     } else if (strcmp(argv[0], "-top-image") == 0){
 485       image_position_v = VF_IMAGEOUT_POSITION_TOP;
 486     } else if (strcmp(argv[0], "-bottom-image") == 0){
 487       image_position_v = VF_IMAGEOUT_POSITION_BOTTOM;
 488     } else if (strcmp(argv[0], "-ds") == 0){
 489       debug_state = 1;
 490     } else if (strcmp(argv[0], "-dr2l") == 0){
 491       debug_r2l = 1;
 492     } else if (strcmp(argv[0], "-df") == 0){
 493       debug_font = 1;
 494     } else if (strcmp(argv[0], "-dbc") == 0){
 495       debug_char_bitmap = 1;
 496     } else if (strcmp(argv[0], "-dbl") == 0){
 497       debug_line_bitmap = 1;
 498     } else if (strcmp(argv[0], "-dbp") == 0){
 499       debug_page_bitmap = 1;
 500     } else if (strcmp(argv[0], "-dvflib") == 0){
 501       debug_vflib = 1;
 502     } else if (strcmp(argv[0], "-dall") == 0){
 503       debug_state       = 1;
 504       debug_r2l         = 1;
 505       debug_font        = 1;
 506       debug_char_bitmap = 1;
 507       debug_line_bitmap = 1;
 508       debug_page_bitmap = 1;
 509       debug_vflib       = 1;
 510     } else if (strcmp(argv[0], "-font-list") == 0){
 511       show_font_list();
 512       exit(0);
 513     } else if (strcmp(argv[0], "-h") == 0){
 514       usage(0);
 515     } else if (strcmp(argv[0], "-help") == 0){
 516       usage(0);
 517     } else if (strcmp(argv[0], "-more-help") == 0){
 518       usage(1);
 519     } else if (strcmp(argv[0], "-version") == 0){
 520       printf("%s %s\n", PROG_NAME, VERSION);
 521       exit(0);
 522     } else {
 523       printf("Unknown option: %s\n", *argv);
 524       usage(0);
 525     }
 526     argc--; argv++;
 527   }
 528 
 529   *argcp = argc; 
 530   *argvp = argv;
 531 }
 532 
 533 void
 534 usage(int level)
     /* [<][>][^][v][top][bottom][index][help] */
 535 {
 536   PR3("%s --- %s\n", PROG_NAME, 
 537       "Make a bitmap of multilingual text in compound text format");
 538   PR2("Usage:  %s [OPTIONS] [FILE]\n", PROG_NAME);
 539   PR1("Options:\n");
 540   PR2(" -v FILE     vflibcap file (default: %s)\n",   
 541       DEFAULT_VFLIBCAP);
 542   PR1(" -bbx        generate a minimun image file\n");
 543   PR1(" -ctext, -euc-jp, -euc-kr, -euc-ch\n");
 544   PR1("             select encoding of input text (default: -ctext)\n");
 545   if (level > 0){
 546     PR1(" -iso-8859-1, -iso-8859-2, ..., -iso-8859-9, \n");
 547     PR1(" -latin-1, -latin-2, ..., -latin-4, -greek, -hebrew, -cyrillic\n");
 548     PR1("             select encoding of input text (1-byte encoding)\n");
 549   }
 550   PR1(" -times, -helv, -cour, -fixed\n");
 551   PR1("             select times/helvetica/courie/fixed font family (default: times)\n");
 552   PR1(" -normal, -bold, -italic\n");
 553   PR1("             select normal/bold/italic font face\n");
 554   PR1(" -14, -16, -18, -24\n");
 555   PR2("             select 14-/16-/18-/24-dot font set (default: %d)\n", 
 556       (int)DEFAULT_PIXEL_SIZE);
 557   PR1(" -scale PIXEL\n");
 558   PR1("             select scalable font set and specify pixel size.\n"); 
 559   if (level > 0){
 560     PR1(" -center, -flush-left, -flush-right\n");
 561     PR1("             Each line is centered or flushed left/right.\n");
 562     PR1(" -l2r, -r2l\n");
 563     PR1("             Select writing directionality left-to-right/right-to-left.\n");
 564     PR2(" -b SKIP     baseline skip (default: %.2f)\n", 
 565         (double)DEFAULT_BASELINESKIP);
 566   }
 567   PR1(" -pbm-ascii, -pgm-ascii, -pgm-raw, -eps, -ascii-art, -none\n");
 568   PR1("             select output format (default: -pgm-ascii)\n");
 569   if (level > 0){
 570     PR1(" -eps-ptsize POINT\n");
 571     PR1("             select point size of characters (EPS mode only)\n");
 572   }
 573   PR2(" -s N        shrink factor for PGM output (default: %d)\n", 
 574       (int)DEFAULT_SHRINK);
 575   if (level > 0){
 576     PR1(" -g N        vertical and horizontal margins in pixels\n");
 577   }
 578   PR1(" -gx N, -gy N\n");
 579   PR1("             horizontal/vertical margin in pixels\n");
 580   PR1(" -r          reverse black and white\n");
 581   PR2(" -tab N      Tab skip (default: %d)\n", DEFAULT_TAB_SKIP);
 582   PR1(" -font-list  print list of defined fonts\n");
 583   PR1(" -more-help  print full descriptions of command line options\n");
 584   if (level > 0){
 585     PR1(" -ds         Print state transision of a compound text parser\n");    
 586     PR1(" -df         Print font open processes\n");    
 587     PR1(" -dr2l       Print state transision of bi-directionality system\n");        PR1(" -dbc        Print image of each chracter in ascii-art form\n");
 588     PR1(" -dbl        Print image of each line in ascii-art form\n");
 589     PR1(" -dbp        Print image of a page in ascii-art form\n");
 590   }
 591   exit(0);
 592 }
 593 
 594 
 595 void
 596 make_text_bitmap(FILE *fp, char *title)
     /* [<][>][^][v][top][bottom][index][help] */
 597 {
 598   struct vf_s_bitmaplist  the_page_buff;
 599   VF_BITMAP               bm;
 600 
 601   VF_BitmapListInit(&the_page_buff);
 602 
 603   parser(fp, &the_page_buff);
 604 
 605   { 
 606     VF_BITMAP  bm0;
 607 
 608     bm0 = VF_BitmapListCompose(&the_page_buff);
 609     VF_BitmapListFinish(&the_page_buff);
 610 
 611     if (minimum_image == 1){
 612       bm = VF_MinimizeBitmap(bm0);
 613       VF_FreeBitmap(bm0);
 614     } else {
 615       bm = bm0;
 616     }
 617   }
 618 
 619   bm->off_x = 0;
 620   bm->off_y = bm->bbx_height;
 621   bm->mv_x  = bm->bbx_width;
 622   bm->mv_y  = 0;
 623 
 624   if (debug_page_bitmap == 1)
 625     VF_DumpBitmap(bm);
 626 
 627   switch (output_format){
 628   default:
 629   case OFORM_PBM_ASCII:
 630     VF_ImageOut_PBMAscii(bm, stdout, page_width, page_height,
 631                          image_position_h, image_position_v, 
 632                          margin_x, margin_x, margin_y, margin_y,
 633                          pix_reverse, shrink_factor, "ctext2pgm", title);
 634     break;
 635   case OFORM_PGM_ASCII:
 636     VF_ImageOut_PGMAscii(bm, stdout, page_width, page_height,
 637                          image_position_h, image_position_v, 
 638                          margin_x, margin_x, margin_y, margin_y,
 639                          pix_reverse, shrink_factor, "ctext2pgm", title);
 640     break;
 641 #if 0
 642   case OFORM_PBM_RAW:
 643     break;
 644 #endif
 645   case OFORM_PGM_RAW:
 646     VF_ImageOut_PGMRaw(bm, stdout, page_width, page_height,
 647                        image_position_h, image_position_v, 
 648                        margin_x, margin_x, margin_y, margin_y,
 649                        pix_reverse, shrink_factor, "ctext2pgm", title);
 650     break;
 651   case OFORM_EPS:
 652     VF_ImageOut_EPS(bm, stdout, page_width, page_height,
 653                     image_position_h, image_position_v, 
 654                     margin_x, margin_x, margin_y, margin_y,
 655                     pix_reverse, shrink_factor, "ctext2pgm", title,
 656                     eps_ptsize, (pixel!=0) ? pixel : xpixel);
 657     break;
 658   case OFORM_ASCII_ART:
 659     VF_ImageOut_ASCIIArt(bm, stdout, page_width, page_height,
 660                          image_position_h, image_position_v, 
 661                          margin_x, margin_x, margin_y, margin_y,
 662                          pix_reverse, shrink_factor);
 663     break;
 664   case OFORM_ASCII_ART_V:
 665     VF_ImageOut_ASCIIArtV(bm, stdout, page_width, page_height,
 666                           image_position_h, image_position_v, 
 667                           margin_x, margin_x, margin_y, margin_y,
 668                           pix_reverse, shrink_factor);
 669     break;
 670   case OFORM_NONE:
 671     break;
 672   }
 673 }
 674 
 675 
 676 void
 677 parser(FILE *fp, VF_BITMAPLIST page_buff)
     /* [<][>][^][v][top][bottom][index][help] */
 678 {
 679   int   chlen, chmask, ch, ch1, ch2, ch3, ch4;
 680   long  code_point, last_code_point;
 681   int   charset_saved;
 682   int   v_pos_x, v_pos_y, lineskip;
 683   int   g, i;
 684   VF_BITMAPLIST   line_buff;
 685 
 686   parser_init();
 687 
 688   v_pos_x = 0;
 689   v_pos_y = 0;
 690   if (pixel > 0)
 691     lineskip = - pixel * baselineskip * magy;
 692   else
 693     lineskip = - xpixel * baselineskip * magy;
 694   last_code_point = 0;
 695   nchars_in_line = 0;
 696 
 697   dir_sp = 0;
 698   dir_stack[dir_sp].dir     = wdirection;
 699   dir_stack[dir_sp].h_pos_x = 0;
 700   dir_stack[dir_sp].h_pos_y = 0;
 701   VF_BitmapListInit(&dir_stack[dir_sp].the_line_buff);
 702 
 703   line_buff = &dir_stack[dir_sp].the_line_buff;
 704 
 705 
 706   while ((ch = getc(fp)) != EOF){
 707 
 708     /* HT (0x09) */
 709     if (ch == '\t'){
 710       int  p;
 711       if (debug_state == 1)
 712         printf("Code point: 0x%02x\n", ch);
 713       p = tab_skip * ((pixel != 0) ? pixel : xpixel);
 714       if ((dir_stack[dir_sp].h_pos_x >= 0)
 715           && (dir_stack[dir_sp].dir == WDIR_L2R)){
 716         dir_stack[dir_sp].h_pos_x 
 717           = ((dir_stack[dir_sp].h_pos_x / p) + 1) * p;
 718       } else {
 719         dir_stack[dir_sp].h_pos_x 
 720           = ((dir_stack[dir_sp].h_pos_x / p) - 1) * p;
 721       }
 722       nchars_in_line++;
 723 
 724     /* CR (0x0d) */
 725     } else if (ch == 0x0d){
 726       ;
 727 
 728     /* LF (0x0a) */
 729     } else if (ch == 0x0a){
 730       nchars_in_line = 0;
 731       parser_eol(&line_buff, page_buff, v_pos_x, v_pos_y);
 732       v_pos_x = 0;
 733       v_pos_y += lineskip;
 734       dir_stack[dir_sp].h_pos_x = 0;
 735       dir_stack[dir_sp].h_pos_y = 0;
 736 
 737     /* ESC (0x1b) */
 738     } else if ((use_esc == 1) && (ch == 0x1b)){
 739       if ((ch1 = getc(fp)) == EOF)
 740         goto end_of_file;
 741       if ((ch2 = getc(fp)) == EOF)
 742         goto end_of_file;
 743       if (debug_state == 1)
 744         printf("Escape Sequence: %02x %02x %02x\n", 0x1b, ch1, ch2);
 745       switch (ch1){
 746       default:
 747         fprintf(stderr, "Parsing Error: %02x %02x %02x\n", 0x1b, ch1, ch2);
 748         break;
 749       case 0x28:
 750         type_g[0]         = TYPEID94;
 751         charset_g[0]      = CSID(TYPEID94,ch2);
 752         chlen_g[0]        = 1;
 753         current_wdir_g[0] = charset_wdirection(charset_g[0]);
 754         if (debug_state == 1)
 755           printf("Designate a 94 charset \"%s\" to G0, G0 is invoked to GL\n",
 756                  charset_name(charset_g[0], "???"));
 757         change_fonts(0);
 758         g = 0;
 759         break;
 760       case 0x29:
 761         type_g[1]         = TYPEID94; 
 762         charset_g[1]      = CSID(TYPEID94,ch2);
 763         chlen_g[1]        = 1;
 764         current_wdir_g[1] = charset_wdirection(charset_g[1]);
 765         if (debug_state == 1)
 766           printf("Designate a 94 charset \"%s\" to G1, G1 is invoked to GR\n",
 767                  charset_name(charset_g[1], "???"));
 768         change_fonts(1);
 769         g = 1;
 770         break;
 771       case 0x2d:
 772         type_g[1]         = TYPEID96;
 773         charset_g[1]      = CSID(TYPEID96,ch2);
 774         chlen_g[1]        = 1;
 775         current_wdir_g[1] = charset_wdirection(charset_g[1]);
 776         if (debug_state == 1)
 777           printf("Designate a 96 charset \"%s\" to G1, G1 is invoked to GR\n",
 778                  charset_name(charset_g[1], "???"));
 779         change_fonts(1);
 780         g = 1;
 781         break;
 782       case 0x24: /* Designate a 94^n charset to G0 or G1 */
 783         switch (ch2){
 784         case 0x28:
 785           /* XXX: support for 94^2 charsets only */
 786           if ((ch3 = getc(fp)) == EOF)
 787             goto end_of_file;
 788           type_g[0]         = TYPEID94_2;
 789           charset_g[0]      = CSID(TYPEID94_2,ch3);
 790           chlen_g[0]        = 2;
 791           current_wdir_g[0] = charset_wdirection(charset_g[0]);
 792           if (debug_state == 1)
 793             printf("Designate a 94^2 charset \"%s\" to G0, "
 794                    "G0 is invoked to GL\n",
 795                    charset_name(charset_g[0], "???"));
 796           change_fonts(0);
 797           g = 0;
 798           break;
 799         case 0x29:
 800           /* XXX: support for 94^2 charsets only */
 801           if ((ch3 = getc(fp)) == EOF)
 802             goto end_of_file;
 803           type_g[1]         = TYPEID94_2;
 804           charset_g[1]      = CSID(TYPEID94_2,ch3);
 805           chlen_g[1]        = 2;
 806           current_wdir_g[1] = charset_wdirection(charset_g[1]);
 807           if (debug_state == 1)
 808             printf("Designate a 94^2 charset \"%s\" to G1, "
 809                    "G1 is invoked to GR\n",
 810                    charset_name(charset_g[1], "???"));
 811           change_fonts(1);
 812           g = 1;
 813           break;
 814         case 0x40:  /* JIS C6226-1978 */ 
 815         case 0x41:  /* GB 2312 */ 
 816         case 0x42:  /* JIS X 0208 */ 
 817           /* XXX: support for 2-byte charsets only */
 818           type_g[0]         = TYPEID94_2;
 819           charset_g[0]      = CSID(TYPEID94_2,ch2);
 820           chlen_g[0]        = 2;
 821           current_wdir_g[0] = charset_wdirection(charset_g[0]);
 822           if (debug_state == 1)
 823             printf("Designate a 94^2 charset \"%s\" to G0, "
 824                    "G0 is invoked to GL\n",
 825                    charset_name(charset_g[0], "???"));
 826           change_fonts(0);
 827           g = 0;
 828           break;
 829         default:
 830           g = -1;
 831           break;
 832         }
 833         if (debug_r2l == 1)
 834           printf("Charset directionality: %s %s\n", 
 835                  charset_name(charset_g[g], "???"),
 836                  (charset_g[g]==WDIR_L2R)?"left-to-right":"right-to-left");
 837         parser_check_wdir(g, &line_buff);
 838         break;
 839       }
 840 
 841     /* SI (0x0f) */
 842     } else if ((use_si == 1) && (ch == 0x0f)){
 843       ;
 844 
 845     /* SO (0x0e) */
 846     } else if ((use_so == 1) && (ch == 0x0e)){
 847       ;
 848 
 849     /* CSI (0x9b) */
 850     } else if ((use_csi == 1) && (ch == 0x9b)){
 851       if ((ch1 = getc(fp)) == EOF)
 852         goto end_of_file;
 853       switch (ch1){
 854       case 0x31:  /* begin left-to-right text */
 855         if ((ch2 = getc(fp)) == EOF)
 856           goto end_of_file;
 857         if (ch2 != 0x5d)
 858           continue;
 859         if ((debug_r2l == 1) || (debug_state == 1))
 860           printf("Begin left-to-right string\n");
 861         parser_wdir_push(WDIR_L2R, &line_buff);
 862         break;
 863       case 0x32:  /* begin right-to-left text */
 864         if ((ch2 = getc(fp)) == EOF)
 865           goto end_of_file;
 866         if (ch2 != 0x5d)
 867           continue;
 868         if ((debug_r2l == 1) || (debug_state == 1))
 869           printf("Begin right-to-left string\n");
 870         parser_wdir_push(WDIR_R2L, &line_buff);
 871         break;
 872       case 0x5d:  /* end of string */
 873         if ((debug_r2l == 1) || (debug_state == 1))
 874           printf("End of string\n");
 875         parser_wdir_pop(&line_buff);
 876         break;
 877       default:
 878         ;
 879       }
 880       
 881     /* Code points */
 882     } else {
 883       if (use_sjis == 0){  /* non-sjis encodings */
 884         if ((use_ss2 == 1) && (ch == 0x8e)){ 
 885           /* SS2: 0x8e */
 886           code_point = 0;
 887           chlen = chlen_g[2] + 1;
 888           chmask = 0xff;
 889           g = 2;
 890         } else if ((use_ss3 == 1) && (ch == 0x8f)){
 891           /* SS3: 0x8f */
 892           code_point = 0;
 893           chlen = chlen_g[3] + 1;
 894           chmask = 0x7f;
 895           g = 3;
 896         }  else {
 897           code_point = (long) ch;
 898           chlen  = ((code_point & 0x80) == 0) ? chlen_g[0] : chlen_g[1];
 899           chmask = (chlen >= 2) ? 0x7f : 0xff;
 900           g      = ((code_point & 0x80) == 0) ? 0 : 1;
 901         }
 902         code_point = code_point & chmask;
 903         for (i = 1; i < chlen; i++){
 904           if ((ch = getc(fp)) == EOF)
 905             goto end_of_file;
 906           code_point = code_point * 256 + (long)(ch & chmask);
 907         }
 908       } else {             /* sjis encoding */
 909         ch1 = ch;
 910         if (((ch1 >= 129) && (ch1 <= 159)) || ((ch1 >= 224) && (ch1 <=239))){
 911           /* 1st byte of Kanji */
 912           if ((ch2 = getc(fp)) == EOF)
 913             goto end_of_file;
 914           if ((ch2 >= 64) && (ch2 <= 252)){
 915             /* 2nd byte of Kanji */
 916             ch3 = (((ch1 - ((ch1<160)?112:176)) << 1) - ((ch2<159)?1:0));
 917             ch4 = ch2 - ((ch2<159) ? (ch2>127?32:31) : 126);
 918             code_point = ch3 * 256 + ch4;
 919           } else
 920             code_point = 0x2121;
 921           g = 1;
 922         } else if ((ch >= 161) && (ch <= 223)){
 923           /* kana, 1byte */
 924           code_point = (long) ch;
 925           g = 2;
 926         } else {
 927           /* jisx0201 */
 928           code_point = (long) ch;
 929           g = 0;
 930         }
 931       }
 932 
 933       if (last_code_point != (long)'\\'){
 934         /* characters to be printed or backslash */
 935         if (code_point != (long)'\\'){
 936           /* print char */
 937           last_code_point = 0;
 938           if (debug_state == 1){
 939             if ((0x20 <= code_point) && (code_point < 0x7e)){
 940               printf("Code point: 0x%lx '%c' (G%d)\n",
 941                      code_point, (int)code_point, g);
 942             } else {
 943               printf("Code point: 0x%lx (G%d)\n", code_point, g);
 944             }
 945           }
 946           parser_check_wdir(g, &line_buff);
 947           draw_char(code_point, line_buff, g, 
 948                     &dir_stack[dir_sp].h_pos_x, &dir_stack[dir_sp].h_pos_y);
 949           nchars_in_line++;
 950         } else {
 951           /* a command by backslash */
 952           last_code_point = code_point;
 953         }
 954 
 955       } else {
 956         /* backslash command */
 957         parser_cmd(code_point, line_buff, &charset_saved, g, 
 958                    &dir_stack[dir_sp].h_pos_x, &dir_stack[dir_sp].h_pos_y);
 959         last_code_point = 0;
 960       }
 961     }
 962   }
 963 
 964 end_of_file:
 965   if (nchars_in_line > 0)    /* the last line does not end by '\n' char */
 966     parser_eol(&line_buff, page_buff, v_pos_x, v_pos_y);
 967 }
 968 
 969 void
 970 parser_eol(VF_BITMAPLIST *line_buff_p, VF_BITMAPLIST page_buff, 
     /* [<][>][^][v][top][bottom][index][help] */
 971            int vposx, int vposy)
 972 {
 973   int        x;
 974   VF_BITMAP  line_bm;
 975 
 976   while (dir_sp > 0)
 977     parser_wdir_pop(line_buff_p);
 978   if ((line_bm = VF_BitmapListCompose(*line_buff_p)) == NULL){ 
 979     PR1("No memory\n");
 980     exit(1);
 981   }
 982   if (debug_line_bitmap == 1)
 983     VF_DumpBitmap(line_bm);
 984   VF_BitmapListFinish(*line_buff_p);
 985 
 986   switch (line_typeset){
 987   default:
 988   case LINE_DEFAULT:      
 989     x = vposx; 
 990     break;
 991   case LINE_FLUSH_LEFT:
 992     if (wdirection == WDIR_R2L)
 993       swap_refpt_nextpt(line_bm);
 994     x = vposx;
 995     break;
 996   case LINE_FLUSH_RIGHT:
 997     if (wdirection == WDIR_L2R){
 998       swap_refpt_nextpt(line_bm);
 999       x = vposx;
1000     } else {
1001       x = vposx - line_bm->bbx_width;
1002     }
1003     break;
1004   case LINE_CENTER:
1005     x = vposx - line_bm->bbx_width/2;
1006     break;
1007   }    
1008   VF_BitmapListPut(page_buff, line_bm, x, vposy);
1009 }
1010 
1011 
1012 void
1013 parser_check_wdir(int i, VF_BITMAPLIST *line_buff_p)
     /* [<][>][^][v][top][bottom][index][help] */
1014 {
1015   if ((i < 0) || (1 < i))
1016     return;
1017   
1018   if (debug_r2l == 1)
1019     printf("dir_stack[%d].dir=%s, current_wdir_g[%d]=%d\n", 
1020            dir_sp, (dir_stack[dir_sp].dir==WDIR_L2R)?"WDIR_L2R":"WDIR_R2L",
1021            i, current_wdir_g[i]);
1022 
1023   if (dir_stack[dir_sp].dir != current_wdir_g[i]){
1024     if  (current_wdir_g[i] != wdirection){
1025       if (current_wdir_g[i] == WDIR_L2R){
1026         if (debug_r2l == 1)
1027           printf("Change directionality to left-to-right mode\n");
1028         parser_wdir_push(WDIR_L2R, line_buff_p);
1029       } else {
1030         if (debug_r2l == 1)
1031           printf("Change directionality to right-to-left mode\n");
1032         parser_wdir_push(WDIR_R2L, line_buff_p);
1033       }
1034     } else {
1035       if (debug_r2l == 1)
1036         printf("End of directionality change\n");
1037       parser_wdir_pop(line_buff_p);
1038     }
1039   }
1040 }
1041 
1042 void
1043 parser_wdir_push(int wdir, VF_BITMAPLIST *line_buff_p)
     /* [<][>][^][v][top][bottom][index][help] */
1044 {
1045   if ((wdirection == WDIR_R2L)
1046       && (dir_sp == 1) && (wdir == WDIR_R2L)){
1047     /* darty trick for right-to-left text */
1048     parser_wdir_do_pop(line_buff_p);
1049   } else {
1050     parser_wdir_do_push(wdir, line_buff_p);
1051   }
1052 }
1053 
1054 void
1055 parser_wdir_pop(VF_BITMAPLIST *line_buff_p)
     /* [<][>][^][v][top][bottom][index][help] */
1056 {
1057   if ((wdirection == WDIR_R2L) 
1058       && (dir_sp == 0) && (dir_stack[dir_sp].dir == WDIR_R2L)){
1059     /* darty trick for right-to-left text */
1060     parser_wdir_do_push(WDIR_L2R, line_buff_p); 
1061   } else {
1062     parser_wdir_do_pop(line_buff_p);
1063   }
1064 }
1065 
1066 void
1067 parser_wdir_do_push(int wdir, VF_BITMAPLIST *line_buff_p)
     /* [<][>][^][v][top][bottom][index][help] */
1068 {
1069   int  s;
1070 
1071   dir_sp++;
1072   dir_stack[dir_sp].dir = wdir;
1073   dir_stack[dir_sp].h_pos_x = 0;
1074   VF_BitmapListInit(&dir_stack[dir_sp].the_line_buff);
1075   *line_buff_p = &dir_stack[dir_sp].the_line_buff;
1076 
1077   if (debug_r2l == 1){
1078     printf("Push to dir_stack\n");
1079     for (s = dir_sp; s >= 0; s--){
1080       printf("  dir_stack[%d].dir=%s\n", 
1081              s, (dir_stack[s].dir==WDIR_L2R)?"WDIR_L2R":"WDIR_R2L");
1082     }
1083   }
1084 }
1085 
1086 void 
1087 parser_wdir_do_pop(VF_BITMAPLIST *line_buff_p)
     /* [<][>][^][v][top][bottom][index][help] */
1088 {
1089   int        s;
1090   VF_BITMAP  inline_bm;
1091 
1092   inline_bm = VF_BitmapListCompose(&dir_stack[dir_sp].the_line_buff);
1093   dir_sp--;
1094   *line_buff_p = &dir_stack[dir_sp].the_line_buff;
1095 
1096   if (debug_r2l == 1){
1097     printf("Pop dir_stack\n");
1098     for (s = dir_sp; s >= 0; s--){
1099       printf("  dir_stack[%d].dir=%s\n", 
1100              s, (dir_stack[s].dir==WDIR_L2R)?"WDIR_L2R":"WDIR_R2L");
1101     }
1102     printf("current_wdir_g[0]=%s, current_wdir_g[1]=%s\n", 
1103            (current_wdir_g[0]==WDIR_L2R)?"WDIR_L2R":"WDIR_R2L", 
1104            (current_wdir_g[1]==WDIR_L2R)?"WDIR_L2R":"WDIR_R2L");
1105   }
1106 
1107   if (debug_r2l == 1)
1108     VF_DumpBitmap(inline_bm);
1109   if (dir_stack[dir_sp].dir != dir_stack[dir_sp+1].dir)
1110     swap_refpt_nextpt(inline_bm);
1111   if (debug_r2l == 1)
1112     VF_DumpBitmap(inline_bm);
1113 
1114   put_bitmap(*line_buff_p, inline_bm, dir_stack[dir_sp].dir, 
1115              &dir_stack[dir_sp].h_pos_x, &dir_stack[dir_sp].h_pos_y);
1116 }
1117 
1118 int
1119 charset_wdirection(int charset)
     /* [<][>][^][v][top][bottom][index][help] */
1120 {
1121   int dir;
1122 
1123   switch (charset){
1124   case CS_ISO8859_6:  /* Latin/Arabic */
1125   case CS_ISO8859_8:  /* Latin/Hebrew */
1126   case CS_MULE_ARAB1: /* Mule Arabic 1 */
1127   case CS_MULE_ARAB2: /* Mule Arabic 2 */
1128     dir = WDIR_R2L;
1129     break;
1130   case CS_MULE_ARAB0: /* Mule Arabic 0 */
1131   default:
1132     dir = WDIR_L2R;
1133     break;
1134   }
1135 
1136   return dir;
1137 }
1138 
1139 
1140 void
1141 draw_char(long code_point, VF_BITMAPLIST buff, int i, int *posxp, int *posyp)
     /* [<][>][^][v][top][bottom][index][help] */
1142 {
1143   VF_BITMAP  bm;
1144 
1145   if ((font_exists_g[i] == 1) && (font_info[current_font_g[i]].font_id >= 0)){
1146 
1147     code_point = cp_conv(code_point, i);
1148 
1149     if (debug_vflib == 1){
1150       printf("VF_GetBitmap2(%d, 0x%lx, 1, 1);\n",
1151              font_info[current_font_g[i]].font_id, code_point);
1152     }
1153     if ((bm = VF_GetBitmap2(font_info[current_font_g[i]].font_id,
1154                             code_point, 1, 1)) == NULL){
1155       PR3("Cannot get bitmap 0x%lx of font %s\n", 
1156           code_point, font_info[current_font_g[i]].font_name);
1157       *posxp = *posxp + ((pixel != 0)?pixel:xpixel)/2;
1158     } else {
1159       if (current_reverse == 1)
1160         reverse_bitmap(bm);
1161       if ((current_wdir_g[i] == WDIR_R2L) && (bm->mv_x > 0))
1162         swap_refpt_nextpt(bm);
1163       if (debug_char_bitmap == 1)
1164         VF_DumpBitmap(bm);
1165       put_bitmap(buff, bm, current_wdir_g[i], posxp, posyp);
1166     }
1167   }
1168 }
1169 
1170 long
1171 cp_conv(long code_point, int i)
     /* [<][>][^][v][top][bottom][index][help] */
1172 {
1173   int   r0, r1;
1174   static int  tbl_mule_visvii_l[] = {
1175       0,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
1176     176,177,178,  0,  0,181,182,183,184,  0,  0,  0,  0,189,190,  0,
1177       0,  0,  0,  0,  0,  0,198,199,  0,  0,  0,  0,  0,  0,  0,207,
1178       0,209,  0,  0,  0,213,214,215,216,  0,  0,219,220,  0,222,223,
1179     224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
1180     240,241,242,243,244,245,246,247,248,249,250,251,252,253,254, 0
1181     };
1182   static int  tbl_mule_visvii_u[] = {
1183       0,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
1184     144,145,146,  0,  0,147,150,151,152,  0,  0,  0,  0,180,149,  0,
1185       0,  0,  0,  0,  0,  0,  2,  5,  0,  0,  0,  0,  0,  0,  0,159,
1186       0,186,  0,  0,  0,128, 20,187,188,  0,  0, 25, 30,  0,179,191,
1187     192,193,194,195,196,197,255,  6,200,201,202,203,204,205,206,155,
1188     208,185,210,211,212,160,153,154,158,217,218,157,156,221,148,  0
1189     };
1190 
1191   r0 = code_point % 0x100;
1192   r1 = code_point / 0x100;
1193 
1194   switch (font_info[current_font_g[i]].charset_id){
1195   default:
1196     break;
1197   case CS_JISX0201R:
1198     if (i == 1)
1199       r0 &= ~0x80;
1200     break;
1201   case CS_JISX0201K:
1202     if (i == 0)
1203       r0 |= 0x80;
1204     break;
1205   case CS_MULE_BIG5_L1:
1206   case CS_MULE_BIG5_L2:
1207     r0 = (r1 - 0x21) * 94 + (r0 - 0x21);
1208     r1 = (r0 / 157) + 0xa1;
1209     r0 = r0 % 157;
1210     if (r0 < 0x3f)
1211       r0 += 0x40;
1212     else
1213       r0 += 0x62;
1214     if (font_info[current_font_g[i]].charset_id == CS_MULE_BIG5_L2)
1215       r1 += 0x25;
1216     break;
1217   case CS_MULE_ETHIOPIC:
1218     r1 = (r1 - 33) * 94;
1219     r0 = (r0 - 33) + r1;
1220     if (r0 < 256){
1221       r1 = 0x12;
1222     } else if (r0 < 448){
1223       r1 = 0x13;
1224       r0 -= 256;
1225     } else {
1226       r1 = 0xfd;
1227       r0 -= 208;
1228     }
1229     break;
1230   case CS_MULE_VISCII_L:
1231     if (r0 < 128)
1232       break;
1233     r0 = tbl_mule_visvii_l[r0 - 160];
1234     break;
1235   case CS_MULE_VISCII_U:
1236     if (r0 < 128)
1237       break;
1238     r0 = tbl_mule_visvii_u[r0 - 160];
1239     break;
1240   }
1241 
1242   return  r1 * 0x100 + r0;
1243 }
1244 
1245 void
1246 put_bitmap(VF_BITMAPLIST buff, VF_BITMAP bm, int wdir, int *posxp, int *posyp)
     /* [<][>][^][v][top][bottom][index][help] */
1247 {
1248   VF_BitmapListPut(buff, bm, *posxp, *posyp);
1249   *posxp += bm->mv_x;
1250   *posyp += bm->mv_y;
1251 }
1252 
1253 void
1254 reverse_bitmap(VF_BITMAP bm)
     /* [<][>][^][v][top][bottom][index][help] */
1255 {
1256   int             x, y, b, m;
1257   unsigned char  *p, w;
1258   static unsigned char  bits[] = {
1259     0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
1260 
1261 
1262   if (bm == NULL)
1263     return;
1264 
1265   b = bm->bbx_width / 8;
1266   m = bm->bbx_width % 8;
1267 
1268   for (y = 0; y < bm->bbx_height; y++){
1269     p = &bm->bitmap[y * bm->raster];
1270     for (x = 0; x < b; x++){
1271       *p = *p ^ 0xff;
1272       p++;
1273     }
1274   }
1275 
1276   if (m != 0){
1277     w = bits[m];
1278     p = &bm->bitmap[b];
1279     for (y = 0; y < bm->bbx_height; y++){
1280       *p = *p ^ w;
1281       p = p + bm->raster;
1282     }
1283   }
1284 }
1285 
1286 void 
1287 swap_refpt_nextpt(VF_BITMAP bm)
     /* [<][>][^][v][top][bottom][index][help] */
1288 {
1289   int  offx, offy;
1290   int  movx, movy;
1291 
1292   offx = bm->off_x - bm->mv_x;
1293   offy = bm->off_y - bm->mv_y;
1294   movx = -bm->mv_x;
1295   movy = -bm->mv_y;
1296 
1297   bm->off_x = offx;
1298   bm->off_y = offy;
1299   bm->mv_x  = movx;
1300   bm->mv_y  = movy;
1301 }
1302 
1303 void parser_cmd(long code_point, VF_BITMAPLIST buff, int *charset_saved_p, 
     /* [<][>][^][v][top][bottom][index][help] */
1304                 int g, int *posxp, int *posyp)
1305 {
1306   switch ((char)code_point){
1307   default: 
1308     PR2("Unknown command: \\%c\n", (char)code_point);
1309     break;
1310   case '\\': 
1311     parser_check_wdir(g, &buff);
1312     draw_char((long)'\\', buff, 0, posxp, posyp);      
1313     nchars_in_line++;
1314     break;
1315   case '.': 
1316     current_family = default_family;
1317     current_face   = default_face; 
1318     break;
1319   case 'd': current_family = default_family; break;
1320   case 'f': current_family = FAM_FIXED;      break;
1321   case 't': current_family = FAM_TIMES;      break;
1322   case 'h': current_family = FAM_HELV;       break;
1323   case 'c': current_family = FAM_COUR;       break;
1324   case 'D': current_face = default_face;  break;
1325   case 'N': current_face = FACE_NORMAL;   break;
1326   case 'B': current_face = FACE_BOLD;     break;
1327   case 'I': current_face = FACE_ITALIC;   break;
1328   case '(': current_reverse = 1;  break;
1329   case ')': current_reverse = 0;  break;
1330     /* \< and \> commands swicthes fonts to iso8859-1 font */
1331     /* This is effective (but ad-hoc) if looks of fonts of GL and */
1332     /* GR are different. */
1333   case '<':                     /* switch to a iso8859-1 font */
1334     *charset_saved_p = charset_g[0];
1335     charset_g[0] = CS_ISO8859_1;
1336     if (debug_state == 1)
1337       printf("Use iso8859-1 font temporarily\n");
1338     break;
1339   case '>':                     /* switch back to the original */
1340     charset_g[0] = *charset_saved_p;
1341     if (debug_state == 1)
1342       printf("Go back to the original font\n");
1343     break;
1344   }
1345 
1346   change_fonts(0);
1347   if (use_g1 == 1)
1348     change_fonts(1);
1349   if (use_g2 == 2)
1350     change_fonts(2);
1351   if (use_g3 == 3)
1352     change_fonts(3);
1353 }
1354 
1355 void
1356 change_fonts(int i)
     /* [<][>][^][v][top][bottom][index][help] */
1357 {
1358   int   opened, j;
1359 
1360   opened = -1;
1361 
1362   /* search an exact font */
1363   for (j = 0; font_info[j].charset_id >= 0; j++){
1364     if (   (font_info[j].pixel_size == pixel)
1365         && (font_info[j].charset_id == charset_g[i])
1366         && (font_info[j].family_id  == current_family)
1367         && (font_info[j].face_id    == current_face)){
1368       if (try_font_open(j) >= 0){
1369         opened = j;
1370         break;
1371       }
1372     }
1373   }
1374   /* search a font of the default face */
1375   if (   (opened < 0) 
1376       && (current_face != default_face)){
1377       for (j = 0; font_info[j].charset_id >= 0; j++){
1378       if (   (font_info[j].pixel_size == pixel)
1379           && (font_info[j].charset_id == charset_g[i])
1380           && (font_info[j].family_id  == current_family)
1381           && (font_info[j].face_id    == default_face)){
1382         if (try_font_open(j) >= 0){
1383           opened = j;
1384           break;
1385         }
1386       }
1387     }
1388   }
1389   /* search a font of the default face */
1390   if (   (opened < 0) 
1391       && (current_face != FACE_DEFAULT)
1392       && (default_face != FACE_DEFAULT)){
1393       for (j = 0; font_info[j].charset_id >= 0; j++){
1394       if (   (font_info[j].pixel_size == pixel)
1395           && (font_info[j].charset_id == charset_g[i])
1396           && (font_info[j].family_id  == current_family)
1397           && (font_info[j].face_id    == FACE_DEFAULT)){
1398         if (try_font_open(j) >= 0){
1399           opened = j;
1400           break;
1401         }
1402       }
1403     }
1404   }
1405   /* search a font of default face and default family */
1406   if (   (opened < 0)
1407       && (current_family != default_family)){
1408   for (j = 0; font_info[j].charset_id >= 0; j++){
1409       if (   (font_info[j].pixel_size == pixel)
1410           && (font_info[j].charset_id == charset_g[i])
1411           && (font_info[j].family_id  == default_family)
1412           && (font_info[j].face_id    == FACE_DEFAULT)){
1413         if (try_font_open(j) >= 0){
1414           opened = j;
1415           break;
1416         }
1417       }
1418     }
1419   }
1420   /* search a font of default face of default family */
1421   if (   (opened < 0)
1422       && (current_family != FAM_DEFAULT)
1423       && (default_family != FAM_DEFAULT)){
1424     for (j = 0; font_info[j].charset_id >= 0; j++){
1425       if (   (font_info[j].pixel_size == pixel)
1426           && (font_info[j].charset_id == charset_g[i])
1427           && (font_info[j].family_id  == FAM_DEFAULT)
1428           && (font_info[j].face_id    == FACE_DEFAULT)){
1429         if (try_font_open(j) >= 0){
1430           opened = j;
1431           break;
1432         }
1433       }
1434     }
1435   }
1436   /* search any font of the charset */
1437   if (opened < 0){
1438     for (j = 0; font_info[j].charset_id >= 0; j++){
1439       if (   (font_info[j].pixel_size == pixel)
1440           && (font_info[j].charset_id == charset_g[i])){
1441         if (try_font_open(j) >= 0){
1442           opened = j;
1443           break;
1444         }
1445       }
1446     }
1447   }
1448   
1449   /* Not found */
1450   if (opened < 0){
1451     font_exists_g[i]  = 0;      /* NO FONT */
1452     current_font_g[i] = 0;
1453     PR2("No font for %s\n", charset_name(charset_g[i], "???"));
1454   } else {
1455     font_exists_g[i]  = 1;
1456     current_font_g[i] = opened;
1457     if (debug_state == 1)
1458       printf("** Charset: %s\n", charset_name(charset_g[i], "???"));
1459   }
1460 }
1461 
1462 int
1463 try_font_open(int table_index)
     /* [<][>][^][v][top][bottom][index][help] */
1464 {
1465   if (debug_font == 1)
1466     printf("Try font open: %s", font_info[table_index].font_name);
1467 
1468   switch (font_info[table_index].font_id){
1469   case NOT_OPENED:
1470     if (debug_vflib == 1){
1471       printf("VF_OpenFont2(\"%s\", %d, %.3f, %.3f);\n",
1472              font_info[table_index].font_name, xpixel, magx, magy);
1473     }
1474     font_info[table_index].font_id 
1475       = VF_OpenFont2(font_info[table_index].font_name, xpixel, magx, magy);
1476     if (debug_vflib == 1)
1477       printf("   VFlib font ID = %d\n", font_info[table_index].font_id );
1478     if (font_info[table_index].font_id < 0){
1479       font_info[table_index].font_id = NOT_FOUND;
1480       if (debug_font == 1)
1481         printf("... cannot open\n");
1482       return -1;
1483     }
1484     if (debug_font == 1)
1485       printf("... successfully opened!\n");
1486     break;
1487   case NOT_FOUND:
1488     if (debug_font == 1)
1489       printf("... could not opened before\n");
1490     return -1;
1491   default:
1492     if (debug_font == 1)
1493       printf("... opened before\n");
1494     break;
1495   }
1496   
1497   if (debug_font == 1)
1498     printf("Font switch: %s\n", font_info[table_index].font_name);
1499   return 1;
1500 }
1501 
1502 void
1503 parser_init(void)
     /* [<][>][^][v][top][bottom][index][help] */
1504 {
1505   int  i;
1506 
1507   for (i = 0; i < 4; i++){
1508     font_exists_g[i] = 0;  /* font does not exist */
1509     type_g[i]    = TYPEID94;
1510     charset_g[i] = CS_ISO8859_1;
1511     chlen_g[i]   = 1;
1512   }
1513 
1514   /* Default values */
1515   use_esc  = 0;
1516   use_csi  = 0;
1517   use_si   = 0;
1518   use_so   = 0;
1519   use_ss2  = 0;
1520   use_ss3  = 0;
1521   use_g1   = 0;
1522   use_g2   = 0;
1523   use_g3   = 0;
1524   use_sjis = 0;
1525 
1526   switch (input_encoding){
1527   case ENC_CTEXT:
1528     use_esc  = 1;
1529     use_csi  = 1;
1530     use_g1   = 1;
1531     /* Designate ISO8859-1 into G0 */
1532     type_g[0]    = TYPEID94;
1533     charset_g[0] = CS_ISO8859_1;
1534     chlen_g[0]   = 1;
1535     change_fonts(0);
1536     /* Designate right-hand of ISO Latin-1 into G1 */
1537     type_g[1]    = TYPEID96;
1538     charset_g[1] = CS_ISO8859_1;
1539     chlen_g[1]   = 1;
1540     change_fonts(1);
1541     break;
1542   case ENC_ISO8859_1:
1543     use_g1   = 1;
1544     /* Designate ISO8859-1 into G0 */
1545     type_g[0]    = TYPEID94;
1546     charset_g[0] = CS_ISO8859_1;
1547     chlen_g[0]   = 1;
1548     change_fonts(0);
1549     /* Designate right-hand of ISO Latin-1 into G1 */
1550     type_g[1]    = TYPEID96;
1551     charset_g[1] = CS_ISO8859_1;
1552     chlen_g[1]   = 1;
1553     change_fonts(1);
1554     break;
1555   case ENC_ISO8859_2:
1556     use_g1   = 1;
1557     /* Designate ISO8859-2 into G0 */
1558     type_g[0]    = TYPEID94;
1559     charset_g[0] = CS_ISO8859_2;
1560     chlen_g[0]   = 1;
1561     change_fonts(0);
1562     /* Designate right-hand of ISO8859-1 into G1 */
1563     type_g[1]    = TYPEID96;
1564     charset_g[1] = CS_ISO8859_2;
1565     chlen_g[1]   = 1;
1566     change_fonts(1);
1567     break;
1568   case ENC_ISO8859_3:
1569     use_g1   = 1;
1570     /* Designate ISO8859-3 into G0 */
1571     type_g[0]    = TYPEID94;
1572     charset_g[0] = CS_ISO8859_3;
1573     chlen_g[0]   = 1;
1574     change_fonts(0);
1575     /* Designate right-hand of ISO8859-2 into G1 */
1576     type_g[1]    = TYPEID96;
1577     charset_g[1] = CS_ISO8859_2;
1578     chlen_g[1]   = 1;
1579     change_fonts(1);
1580     break;
1581   case ENC_ISO8859_4:
1582     use_g1   = 1;
1583     /* Designate ISO8859-4 into G0 */
1584     type_g[0]    = TYPEID94;
1585     charset_g[0] = CS_ISO8859_4;
1586     chlen_g[0]   = 1;
1587     change_fonts(0);
1588     /* Designate right-hand of ISO8859-4 into G1 */
1589     type_g[1]    = TYPEID96;
1590     charset_g[1] = CS_ISO8859_4;
1591     chlen_g[1]   = 1;
1592     change_fonts(1);
1593     break;
1594   case ENC_ISO8859_5: /* Cryillic */
1595     use_g1   = 1;
1596     /* Designate ISO8859-1 into G0 */
1597     type_g[0]    = TYPEID94;
1598     charset_g[0] = CS_ISO8859_1;
1599     chlen_g[0]   = 1;
1600     change_fonts(0);
1601     /* Designate right-hand of ISO8859-5 into G1 */
1602     type_g[1]    = TYPEID96;
1603     charset_g[1] = CS_ISO8859_5;
1604     chlen_g[1]   = 1;
1605     change_fonts(1);
1606     break;
1607   case ENC_ISO8859_6: /* Arabic */
1608     use_g1   = 1;
1609     wdirection = WDIR_R2L;
1610     /* Designate ISO8859-1 into G0 */
1611     type_g[0]    = TYPEID94;
1612     charset_g[0] = CS_ISO8859_1;
1613     chlen_g[0]   = 1;
1614     change_fonts(0);
1615     /* Designate right-hand of ISO8859-6 into G1 */
1616     type_g[1]    = TYPEID96;
1617     charset_g[1] = CS_ISO8859_6;
1618     chlen_g[1]   = 1;
1619     change_fonts(1);
1620     break;
1621   case ENC_ISO8859_7: /* Greek */
1622     use_g1   = 1;
1623     /* Designate ISO8859-1 into G0 */
1624     type_g[0]    = TYPEID94;
1625     charset_g[0] = CS_ISO8859_1;
1626     chlen_g[0]   = 1;
1627     change_fonts(0);
1628     /* Designate right-hand of ISO8859-7 into G1 */
1629     type_g[1]    = TYPEID96;
1630     charset_g[1] = CS_ISO8859_7;
1631     chlen_g[1]   = 1;
1632     change_fonts(1);
1633     break;
1634   case ENC_ISO8859_8: /* Hebrew */
1635     use_g1   = 1;
1636     wdirection = WDIR_R2L;
1637     /* Designate ISO8859-1 into G0 */
1638     type_g[0]    = TYPEID94;
1639     charset_g[0] = CS_ISO8859_1;
1640     chlen_g[0]   = 1;
1641     change_fonts(0);
1642     /* Designate right-hand of ISO8859-8 into G1 */
1643     type_g[1]    = TYPEID96;
1644     charset_g[1] = CS_ISO8859_8;
1645     chlen_g[1]   = 1;
1646     change_fonts(1);
1647     break;
1648   case ENC_ISO8859_9:
1649     use_g1   = 1;
1650     /* Designate ISO8859-9 into G0 */
1651     type_g[0]    = TYPEID94;
1652     charset_g[0] = CS_ISO8859_9;
1653     chlen_g[0]   = 1;
1654     change_fonts(0);
1655     /* Designate right-hand of ISO8859-9 into G1 */
1656     type_g[1]    = TYPEID96;
1657     charset_g[1] = CS_ISO8859_9;
1658     chlen_g[1]   = 1;
1659     change_fonts(1);
1660     break;
1661   case ENC_ISO2022_JP:
1662     use_esc  = 1;
1663     /* Designate ASCII into G0 */
1664     type_g[0]    = TYPEID94;
1665     charset_g[0] = CS_ASCII;
1666     chlen_g[0]   = 1;
1667     change_fonts(0);
1668     break;
1669 #if 0
1670   case ENC_ISO2022_KR:
1671     use_si   = 1;
1672     use_so   = 1;
1673     use_g1   = 1;
1674     /* Designate ASCII into G0 */
1675     type_g[0]    = TYPEID94;
1676     charset_g[0] = CS_ASCII;
1677     chlen_g[0]   = 1;
1678     change_fonts(0);
1679     /* Designate KSC5601 into G1 */
1680     type_g[1]    = TYPEID94_2;
1681     charset_g[1] = CS_KSC5601;
1682     chlen_g[1]   = 2;
1683     change_fonts(1);
1684     break;
1685   case ENC_ISO2022_CN:
1686     use_esc  = 1;
1687     use_si   = 1;
1688     use_so   = 1;
1689     use_ss2  = 1;
1690     use_ss3  = 1;
1691     use_g1   = 1;
1692     use_g2   = 1;
1693     /* Designate ASCII into G0 */
1694     type_g[0]    = TYPEID94;
1695     charset_g[0] = CS_ASCII;
1696     chlen_g[0]   = 1;
1697     change_fonts(0);
1698     break;
1699 #endif
1700   case ENC_EUC_JP1:
1701   case ENC_EUC_JP2:  
1702     use_ss2  = 1;
1703     use_ss3  = 1;
1704     use_g1   = 1;
1705     use_g2   = 1;
1706     use_g3   = 1;
1707     if (input_encoding == ENC_EUC_JP1){
1708       /* Designate JIS X0201 into G0 (code set 0) */
1709       type_g[0]    = TYPEID94;
1710       charset_g[0] = CS_JISX0201R;
1711       chlen_g[0]   = 1;
1712       change_fonts(0);
1713     } else {
1714       /* Designate ISO8859-1 into G0 (code set 0) */
1715       type_g[0]    = TYPEID94;
1716       charset_g[0] = CS_ISO8859_1;
1717       chlen_g[0]   = 1;
1718       change_fonts(0);
1719     }
1720     /* Designate JIS X0208 into G1 (code set 1) */
1721     type_g[1]    = TYPEID94_2;
1722     charset_g[1] = CS_JISX0208;
1723     chlen_g[1]   = 2;
1724     change_fonts(1);
1725     /* Designate JIS X0208 into G2 (code set 2) */
1726     type_g[2]    = TYPEID94;
1727     charset_g[2] = CS_JISX0201K;
1728     chlen_g[2]   = 1;
1729     change_fonts(2);
1730     /* Designate JIS X0212 into G3 (code set 3) */
1731     type_g[3]    = TYPEID94_2;
1732     charset_g[3] = CS_JISX0212;
1733     chlen_g[3]   = 2;
1734     change_fonts(3);
1735     break;
1736   case ENC_EUC_KR:
1737     use_g1   = 1;
1738     /* Designate ISO8859-1 into G0 (code set 0) */
1739     type_g[0]    = TYPEID94;
1740     charset_g[0] = CS_ISO8859_1;
1741     chlen_g[0]   = 1;
1742     change_fonts(0);
1743     /* Designate KSC5601 into G1 (code set 1) */
1744     type_g[1]    = TYPEID94_2;
1745     charset_g[1] = CS_KSC5601;
1746     chlen_g[1]   = 2;
1747     change_fonts(1);
1748     break;
1749   case ENC_EUC_CH_GB:
1750     use_g1   = 1;
1751     /* Designate ISO8859-1 into G0 (code set 0) */
1752     type_g[0]    = TYPEID94;
1753     charset_g[0] = CS_ISO8859_1;
1754     chlen_g[0]   = 1;
1755     change_fonts(0);
1756     /* Designate GB2312 into G1 (code set 1) */
1757     type_g[1]    = TYPEID94_2;
1758     charset_g[1] = CS_GB2312;
1759     chlen_g[1]   = 2;
1760     change_fonts(1);
1761     break;
1762   case ENC_EUC_CH_CNS:
1763     use_ss2  = 1;
1764     use_ss3  = 1;
1765     use_g1   = 1;
1766     use_g3   = 1;
1767     /* Designate ISO8859-1 into G0 (code set 0) */
1768     type_g[0]    = TYPEID94;
1769     charset_g[0] = CS_ISO8859_1;
1770     chlen_g[0]   = 1;
1771     change_fonts(0);
1772     /* Designate CNS11643-1 into G1 (code set 1) */
1773     type_g[1]    = TYPEID94_2;
1774     charset_g[1] = CS_CNS11643_1;
1775     chlen_g[1]   = 2;
1776     change_fonts(1);
1777     /* Designate CNS11643-2 into G3 (code set 3) */
1778     type_g[3]    = TYPEID94_2;
1779     charset_g[3] = CS_CNS11643_2;
1780     chlen_g[3]   = 2;
1781     change_fonts(3);
1782     break;
1783   case ENC_SJIS:
1784     use_g1   = 1;
1785     use_g2   = 1;
1786     use_sjis = 1;
1787     /* JISX0201 Roman into G0 */
1788     type_g[0]    = TYPEID94;
1789     charset_g[0] = CS_JISX0201R;
1790     chlen_g[0]   = 1;
1791     change_fonts(0);
1792     /* JISX0208 into G1 */
1793     type_g[1]    = TYPEID94_2;
1794     charset_g[1] = CS_JISX0208;
1795     chlen_g[1]   = 2;
1796     change_fonts(1);
1797     /* JISX0201 Kana into G2 */
1798     type_g[2]    = TYPEID94;
1799     charset_g[2] = CS_JISX0201K;
1800     chlen_g[2]   = 1;
1801     change_fonts(2);
1802     break;
1803   default:
1804     fprintf(stderr, "Input encoding is unknown.\n");
1805     exit(1);
1806   }
1807 
1808   for (i = 0; i < 4; i++){
1809     current_wdir_g[i] = charset_wdirection(charset_g[i]);
1810   }
1811 }
1812 
1813 char*
1814 charset_name(int charset, char *if_unknown)
     /* [<][>][^][v][top][bottom][index][help] */
1815 {
1816   char *name;
1817 
1818   name = if_unknown;
1819 
1820   switch (charset){
1821   case CS_ASCII:       name = "ASCII";                       break;
1822   case CS_ISO8859_1:   name = "ISO 8859-1 (Latin-1)";        break;
1823   case CS_ISO8859_2:   name = "ISO 8859-2 (Latin-2)";        break;
1824   case CS_ISO8859_3:   name = "ISO 8859-3 (Latin-3)";        break;
1825   case CS_ISO8859_4:   name = "ISO 8859-4 (Latin-4)";        break;
1826   case CS_ISO8859_5:   name = "ISO 8859-5 (Cyrillic)";       break;
1827   case CS_ISO8859_6:   name = "ISO 8859-6 (Arabic)";         break;
1828   case CS_ISO8859_7:   name = "ISO 8859-7 (Greek)";          break;
1829   case CS_ISO8859_8:   name = "ISO 8859-8 (Hebrew)";         break;
1830   case CS_ISO8859_9:   name = "ISO 8859-9 (Latin-5)";        break;
1831   case CS_JISX0201R:   name = "JIS X 0201-Roman";            break;
1832   case CS_JISX0201K:   name = "JIS X 0201-Kana";             break;
1833   case CS_JISX0208:    name = "JIS X 0208 (Japanese)";       break;
1834   case CS_JISX0212:    name = "JIS X 0212 (Japanese)";       break;
1835   case CS_KSC5601:     name = "KSC 5601 (Hangle)";           break;
1836   case CS_GB2312:      name = "GB 2312 (Chinese)";           break;
1837   case CS_CNS11643_1:  name = "CNS 11643-1 (Chinese)";       break;
1838   case CS_CNS11643_2:  name = "CNS 11643-2 (Chinese)";       break;
1839   case CS_CNS11643_3:  name = "CNS 11643-3 (Chinese)";       break;
1840   case CS_CNS11643_4:  name = "CNS 11643-4 (Chinese)";       break;
1841   case CS_CNS11643_5:  name = "CNS 11643-5 (Chinese)";       break;
1842   case CS_CNS11643_6:  name = "CNS 11643-6 (Chinese)";       break;
1843   case CS_CNS11643_7:  name = "CNS 11643-7 (Chinese)";       break;
1844   case CS_MULE_BIG5_L1:   name = "BIG5 Level 1 (Chinese)";      break;
1845   case CS_MULE_BIG5_L2:   name = "BIG5 Level 2 (Chinese)";      break;
1846   case CS_MULE_ARAB0:     name = "Mule Arabic 0";            break;
1847   case CS_MULE_ARAB1:     name = "Mule Arabic 1";            break;
1848   case CS_MULE_ARAB2:     name = "Mule Arabic 2";            break;
1849   case CS_MULE_ETHIOPIC:  name = "Mule Ethiopic";            break;
1850   case CS_MULE_VISCII_L:  name = "Mule VISCII 1.1 Lower";    break;
1851   case CS_MULE_VISCII_U:  name = "Mule VISCII 1.1 Upper";    break;
1852   }
1853   return name;
1854 }
1855 
1856 
1857 #define FONTLIST_W_CHARSET   28
1858 #define FONTLIST_W_FAM_FACE  17
1859 #define FONTLIST_W_PIXEL     12
1860 #define FONTLIST_W_FONT      -1
1861 
1862 
1863 void  
1864 show_font_list(void)
     /* [<][>][^][v][top][bottom][index][help] */
1865 {
1866   char  buff[80], *s1, *s2;
1867   int   i;
1868 
1869   wprint("Character Set Name",   FONTLIST_W_CHARSET);
1870   wprint("Family&Face",          FONTLIST_W_FAM_FACE);
1871   wprint("Pixel Size",           FONTLIST_W_PIXEL);
1872   wprint("Font Name",            FONTLIST_W_FONT);
1873   wprint("\n\n", -1);
1874   
1875   for (i = 0; font_info[i].charset_id >= 0; i++){
1876 
1877     /* charset name */
1878     sprintf(buff, "%s", charset_name(font_info[i].charset_id, "???"));
1879     wprint(buff, FONTLIST_W_CHARSET);
1880 
1881     /* font family & font face */
1882     switch (font_info[i].family_id){
1883     default:
1884     case FAM_FIXED:   s1 = "Fixed";    break;
1885     case FAM_TIMES:   s1 = "Times";    break;
1886     case FAM_HELV:    s1 = "Helvetia"; break;
1887     case FAM_COUR:    s1 = "Courier";  break;
1888     }
1889     switch (font_info[i].face_id){
1890     default:
1891     case FACE_NORMAL:   s2 = "Normal";   break;
1892     case FACE_ITALIC:   s2 = "Italic";   break;
1893     case FACE_BOLD:     s2 = "Bold";     break;
1894     }
1895     sprintf(buff, "%s %s", s1, s2);
1896     wprint(buff, FONTLIST_W_FAM_FACE);
1897 
1898     /* pixel size */
1899     if (font_info[i].pixel_size == 0)
1900       sprintf(buff, "%s", "scalable");
1901     else
1902       sprintf(buff, "%d", font_info[i].pixel_size);
1903     wprint(buff, FONTLIST_W_PIXEL);
1904 
1905     /* font name */
1906     wprint(font_info[i].font_name, FONTLIST_W_FONT);
1907 
1908     wprint("\n", -1);
1909   }
1910 }
1911 
1912 void  
1913 wprint(char *str, int w)
     /* [<][>][^][v][top][bottom][index][help] */
1914 {
1915   int  i;
1916   char *p;
1917 
1918   if (w <= 0){
1919     printf("%s", str);
1920     return;
1921   }
1922 
1923   if (str == NULL){
1924     for (i = 0; i < w; i++){
1925       putchar(' ');
1926     }
1927     return;
1928   }
1929 
1930   i = w;
1931   p = str;
1932   while (i > 0){
1933     if (*p == '\0')
1934       break;
1935     putchar(*p);
1936     p++;
1937     --i;
1938   }
1939   while (i > 0){
1940     putchar(' ');
1941     --i;
1942   }
1943 }
1944 
1945 
1946 /*EOF*/

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