*** Doc/xfig.man.orig	Wed Aug 16 01:18:37 1995
--- Doc/xfig.man	Thu Sep  5 12:38:36 1996
***************
*** 485,490 ****
--- 485,504 ----
  You might want to use this for debugging.
  .\"-------
  .At
+ .BR \-kanjisc [ alablefonts ]
+ .Ap
+ Allows use of the kanji scalable fonts (this is the default).
+ If the scalable fonts aren't available
+ .I xfig
+ will automatically switch to non-scaling fonts.
+ .\"-------
+ .At
+ .BR \-kanjinosc [ alablefonts ]
+ .Ap
+ Disables use of the kanji scalable fonts.
+ Recommended to use this when you are using slow, low-memory X server/terminal.
+ .\"-------
+ .At
  .BR \-sh [ owallbuttons ]
  .Ap
  Show all the
***************
*** 2621,2626 ****
--- 2635,2641 ----
  reverseVideo\&\&	ReverseVideo\&\&	boolean	off\&\&\&\&\&\&\&	\-inverse
  rulerthick\&\&\&	RulerThick\&\&\&	integer	24\&\&\&\&\&\&\&	\-rulerthick
  scalablefonts\&\&	ScalableFonts\&\&	boolean	true\&\&\&\&\&\&	\-scalablefonts
+ kanjiscalablefonts\&\&	kanjiScalableFonts\&\&	boolean	true\&\&\&\&\&\&	\-kanjiscalablefonts
  showallbuttons\&	ShowAllButtons\&	boolean	false\&\&\&\&\&\&	\-showallbuttons
  specialtext\&\&\&	SpecialText\&\&\&	boolean	false\&\&\&\&\&\&	\-specialtext
  startfillstyle\&\&	startFillStyle\&	integer	0\&\&\&\&\&\&\&\&	\-startfillstyle
*** Imakefile.orig	Fri Aug  9 14:45:13 1996
--- Imakefile	Thu Oct 10 16:40:46 1996
***************
*** 67,72 ****
--- 67,83 ----
  DEPLIBJPEG = $(JPEGLIBDIR)/libjpeg.a
  #endif
  
+ XCOMM If you want to use Japanese Characters on XFIG, set KANJIDEFINES.
+ XCOMM If you are running X11R5, the use second KANJIDEFINES below with
+ XCOMM KANJI_R5 definition.
+ XCOMM If you want to edit the Japanese String(s) in *.fig file directly,
+ XCOMM add -DKANJIFIGFILE to KANJIDEFINES. (Warning: Read README.3.1.4j
+ XCOMM for more detail.)
+ 
+ KANJIDEFINES = -DKANJI
+ XCOMM KANJIDEFINES = -DKANJI -DKANJI_R5
+ 
+ 
  XCOMM For Solaris: add "-lc" to the LOCAL_LIBRARIES variable in the Imakefile 
  XCOMM to link with /usr/lib/libc for the directory operations.
  
***************
*** 147,153 ****
  
  XCOMM *** You shouldn't have to change anything below this point. ***
  
! DEFINES =             $(STRDEFINES) -DGSBIT $(XPMDEFINES)
  
  XFIGSRC =	d_arc.c d_arcbox.c d_box.c d_ellipse.c d_picobj.c \
  		d_intspline.c d_line.c d_regpoly.c d_spline.c d_text.c \
--- 158,164 ----
  
  XCOMM *** You shouldn't have to change anything below this point. ***
  
! DEFINES =             $(STRDEFINES) -DGSBIT $(XPMDEFINES) $(KANJIDEFINES)
  
  XFIGSRC =	d_arc.c d_arcbox.c d_box.c d_ellipse.c d_picobj.c \
  		d_intspline.c d_line.c d_regpoly.c d_spline.c d_text.c \
***************
*** 168,174 ****
  		w_canvas.c w_cmdpanel.c w_color.c w_cursor.c w_dir.c w_drawprim.c \
  		w_export.c w_file.c w_fontbits.c w_fontpanel.c w_grid.c \
  		w_icons.c w_indpanel.c w_modepanel.c w_mousefun.c w_msgpanel.c \
! 		w_print.c w_rottext.c w_rulers.c w_setup.c w_util.c w_zoom.c
  
  XFIGOBJ =	d_arc.o d_arcbox.o d_box.o d_ellipse.o d_picobj.o \
  		d_intspline.o d_line.o d_regpoly.o d_spline.o d_text.o \
--- 179,186 ----
  		w_canvas.c w_cmdpanel.c w_color.c w_cursor.c w_dir.c w_drawprim.c \
  		w_export.c w_file.c w_fontbits.c w_fontpanel.c w_grid.c \
  		w_icons.c w_indpanel.c w_modepanel.c w_mousefun.c w_msgpanel.c \
! 		w_print.c w_rottext.c w_rulers.c w_setup.c w_util.c w_zoom.c \
! 		convlib.c kconvert.c
  
  XFIGOBJ =	d_arc.o d_arcbox.o d_box.o d_ellipse.o d_picobj.o \
  		d_intspline.o d_line.o d_regpoly.o d_spline.o d_text.o \
***************
*** 189,195 ****
  		w_canvas.o w_cmdpanel.o w_color.o w_cursor.o w_dir.o w_drawprim.o \
  		w_export.o w_file.o w_fontbits.o w_fontpanel.o w_grid.o \
  		w_icons.o w_indpanel.o w_modepanel.o w_mousefun.o w_msgpanel.o \
! 		w_print.o w_rottext.o w_rulers.o w_setup.o w_util.o w_zoom.o
  
  XCOMM Other dependencies should be handled by "make depend"
  
--- 201,208 ----
  		w_canvas.o w_cmdpanel.o w_color.o w_cursor.o w_dir.o w_drawprim.o \
  		w_export.o w_file.o w_fontbits.o w_fontpanel.o w_grid.o \
  		w_icons.o w_indpanel.o w_modepanel.o w_mousefun.o w_msgpanel.o \
! 		w_print.o w_rottext.o w_rulers.o w_setup.o w_util.o w_zoom.o \
! 		convlib.o kconvert.o
  
  XCOMM Other dependencies should be handled by "make depend"
  
*** d_text.c.orig	Tue Aug  8 09:53:34 1995
--- d_text.c	Tue Sep  3 16:54:31 1996
***************
*** 34,50 ****
--- 34,60 ----
  #include "w_zoom.h"
  
  extern PIX_FONT lookfont();
+ #ifdef KANJI
+ extern PIX_FONT lookkfont();
+ #endif
  
  #define CTRL_H	8
  #define NL	10
  #define CR	13
  #define CTRL_X	24
+ #ifdef KANJI
+ #define CTRL_Y  25
+ #endif
  #define SP	32
  #define DEL	127
  
  #define			BUF_SIZE	400
  
+ #ifdef KANJI
+ unsigned char	prefix[BUF_SIZE],	/* part of string left of mouse click */
+ #else
  char		prefix[BUF_SIZE],	/* part of string left of mouse click */
+ #endif
  		suffix[BUF_SIZE];	/* part to right of click */
  int		leng_prefix, leng_suffix;
  static int	char_ht;
***************
*** 57,62 ****
--- 67,78 ----
  static PIX_FONT work_fontstruct;
  static float	work_angle;		/* in RADIANS */
  static double	sin_t, cos_t;		/* sin(work_angle) and cos(work_angle) */
+ 
+ #ifdef KANJI
+ static PIX_FONT canvas_zoomed_kfont;
+ static PIX_FONT work_kfontstruct;
+ #endif
+ 
  static		finish_n_start();
  static		init_text_input(), cancel_text_input();
  static		wrap_up();
***************
*** 165,171 ****
--- 181,191 ----
  	    if ((new_t->cstring = new_string(leng_prefix + 1)) != NULL)
  		strcpy(new_t->cstring, prefix);
  	}
+ #ifdef KANJI
+ 	size = textsize(canvas_font, canvas_kfont, leng_prefix, prefix);
+ #else
  	size = textsize(canvas_font, leng_prefix, prefix);
+ #endif
  	new_t->ascent = size.ascent;
  	new_t->descent = size.descent;
  	new_t->length = size.length;
***************
*** 233,238 ****
--- 253,269 ----
  			   round(work_fontsize*display_zoomscale));
  	    /* save the working font structure */
  	    work_fontstruct = canvas_zoomed_font;
+ 
+ #ifdef KANJI
+ 	    put_msg("Please wait for intializing kanji font (%dpt)",
+ 		    work_fontsize);
+ 	    canvas_kfont = lookkfont(x_fontnum(work_psflag, work_font),
+ 				     work_fontsize);
+             canvas_zoomed_kfont = lookkfont(x_fontnum(work_psflag, work_font),
+                            round(work_fontsize*display_zoomscale));
+ 	    work_kfontstruct = canvas_zoomed_kfont;
+ #endif
+ 
  	}
      } else {			/* clicked on existing text */
  	if (hidden_text(cur_t)) {
***************
*** 245,250 ****
--- 276,284 ----
  	work_textcolor = cur_t->color;
  	work_font = cur_t->font;
  	work_fontstruct = canvas_zoomed_font = cur_t->fontstruct;
+ #ifdef KANJI
+ 	work_kfontstruct = canvas_zoomed_kfont = cur_t->kfontstruct;
+ #endif
  	work_fontsize = cur_t->size;
  	work_psflag   = cur_t->flags & PSFONT_TEXT;
  	work_flags    = cur_t->flags;
***************
*** 259,264 ****
--- 293,302 ----
  	/* this is to get widths etc for the unzoomed chars */
  	canvas_font = lookfont(x_fontnum(work_psflag, work_font), 
  			   work_fontsize);
+ #ifdef KANJI
+ 	canvas_kfont = lookkfont(x_fontnum(work_psflag, work_font), 
+ 			   work_fontsize);
+ #endif
  
  	toggle_textmarker(cur_t);
  	draw_text(cur_t, ERASE);
***************
*** 286,292 ****
--- 324,334 ----
  	leng_suffix -= leng_prefix;
  	cpy_n_char(prefix, cur_t->cstring, leng_prefix);
  	strcpy(suffix, &cur_t->cstring[leng_prefix]);
+ #ifdef KANJI
+ 	tsize = textsize(canvas_font, canvas_kfont, leng_prefix, prefix);
+ #else
  	tsize = textsize(canvas_font, leng_prefix, prefix);
+ #endif
  
  	cur_x = round(base_x + tsize.length * cos_t);
  	cur_y = round(base_y - tsize.length * sin_t);
***************
*** 315,320 ****
--- 357,365 ----
      text->type = work_textjust;
      text->font = work_font;	/* put in current font number */
      text->fontstruct = work_fontstruct;
+ #ifdef KANJI
+     text->kfontstruct = work_kfontstruct;
+ #endif
      text->zoom = zoomscale;
      text->size = work_fontsize;
      text->angle = work_angle;
***************
*** 322,328 ****
--- 367,377 ----
      text->color = cur_pencolor;
      text->depth = cur_depth;
      text->pen_style = 0;
+ #ifdef KANJI
+     size = textsize(canvas_font, canvas_kfont, leng_prefix, prefix);
+ #else
      size = textsize(canvas_font, leng_prefix, prefix);
+ #endif
      text->length = size.length;
      text->ascent = size.ascent;
      text->descent = size.descent;
***************
*** 345,352 ****
--- 394,435 ----
      *dst = '\0';
  }
  
+ #ifdef KANJI
+ /*    Nov.5.'94, rewrite for kanji handling by T. Sugimoto    */
+ /*    Sep.9.'96, modified by H.Goto */
  static int
  prefix_length(string, where_p)
+     unsigned char   *string;
+     int		    where_p;
+ {
+     /* c stands for character unit and p for pixel unit */
+     int		    l, len_c;
+     int		    char_wid, where_c;
+     PR_SIZE	    size;
+     int		    pref_p = 0;
+ 
+     len_c = strlen(string);
+     size = textsize(canvas_font, canvas_kfont, len_c, string);
+     if (where_p >= size.length)
+ 	return (len_c);		/* entire string is the prefix */
+ 
+     for (where_c = 0; where_c < len_c; where_c++)
+       {
+       if (string[where_c] > 0x7f)
+         char_wid = ZOOM_FACTOR * char_width(canvas_kfont);
+       else
+         char_wid = ZOOM_FACTOR * char_advance(canvas_font, string[where_c]);
+       if (where_p < (pref_p + char_wid / 2))    break;
+       pref_p += char_wid;
+       if (string[where_c] > 0x7f)     where_c++;      /* kanji is 2 bytes */
+       }
+     return (where_c);
+ }
+ 
+ #else	/* KANJI */
+ 
+ static int
+ prefix_length(string, where_p)
      char	   *string;
      int		    where_p;
  {
***************
*** 389,394 ****
--- 472,478 ----
  	return (len_c);
      return (where_c);
  }
+ #endif	/* KANJI */
  
  /*******************************************************************
  
***************
*** 404,409 ****
--- 488,496 ----
  static float	rbase_x, rbase_y, rcur_x, rcur_y;
  
  static		(*cr_proc) ();
+ #ifdef KANJI
+ int             paste_cut_buffer();
+ #endif
  
  static
  draw_cursor(x, y)
***************
*** 443,463 ****
--- 530,566 ----
  static int
  erase_char_string()
  {
+ #ifdef KANJI
      pw_text(pw, cbase_x, cbase_y, ERASE, canvas_zoomed_font, 
+ 	    canvas_zoomed_kfont, work_angle, prefix, work_textcolor);
+     if (leng_suffix)
+ 	pw_text(pw, cur_x, cur_y, ERASE, canvas_zoomed_font, 
+ 		canvas_zoomed_kfont, work_angle, suffix, work_textcolor);
+ #else
+     pw_text(pw, cbase_x, cbase_y, ERASE, canvas_zoomed_font, 
  	    work_angle, prefix, work_textcolor);
      if (leng_suffix)
  	pw_text(pw, cur_x, cur_y, ERASE, canvas_zoomed_font, 
  		work_angle, suffix, work_textcolor);
+ #endif
  }
  
  static int
  draw_char_string()
  {
+ #ifdef KANJI
      pw_text(pw, cbase_x, cbase_y, PAINT, canvas_zoomed_font, 
+ 	    canvas_zoomed_kfont, work_angle, prefix, work_textcolor);
+     if (leng_suffix)
+ 	pw_text(pw, cur_x, cur_y, PAINT, canvas_zoomed_font, 
+ 		canvas_zoomed_kfont, work_angle, suffix, work_textcolor);
+ #else
+     pw_text(pw, cbase_x, cbase_y, PAINT, canvas_zoomed_font, 
  	    work_angle, prefix, work_textcolor);
      if (leng_suffix)
  	pw_text(pw, cur_x, cur_y, PAINT, canvas_zoomed_font, 
  		work_angle, suffix, work_textcolor);
+ #endif
      move_blinking_cursor(cur_x, cur_y);
  }
  
***************
*** 465,472 ****
--- 568,580 ----
  draw_suffix()
  {
      if (leng_suffix)
+ #ifdef KANJI
  	pw_text(pw, cur_x, cur_y, PAINT, canvas_zoomed_font, 
+ 		canvas_zoomed_kfont, work_angle, suffix, work_textcolor);
+ #else
+ 	pw_text(pw, cur_x, cur_y, PAINT, canvas_zoomed_font, 
  		work_angle, suffix, work_textcolor);
+ #endif
  }
  
  static int
***************
*** 473,480 ****
--- 581,593 ----
  erase_suffix()
  {
      if (leng_suffix)
+ #ifdef KANJI
  	pw_text(pw, cur_x, cur_y, ERASE/*INV_PAINT*/, canvas_zoomed_font, 
+ 		canvas_zoomed_kfont, work_angle, suffix, work_textcolor);
+ #else
+ 	pw_text(pw, cur_x, cur_y, ERASE/*INV_PAINT*/, canvas_zoomed_font, 
  		work_angle, suffix, work_textcolor);
+ #endif
  }
  
  static int
***************
*** 484,491 ****
--- 597,609 ----
      char	s[2];
      s[0]=c;
      s[1]='\0';
+ #ifdef KANJI
      pw_text(pw, cur_x, cur_y, PAINT/*INV_PAINT*/, canvas_zoomed_font, 
+ 	    canvas_zoomed_kfont, work_angle, s, work_textcolor);
+ #else
+     pw_text(pw, cur_x, cur_y, PAINT/*INV_PAINT*/, canvas_zoomed_font, 
  	    work_angle, s, work_textcolor);
+ #endif
  }
  
  char_handler(c)
***************
*** 503,510 ****
--- 621,639 ----
      } else if (c == DEL || c == CTRL_H) {
  	if (leng_prefix > 0) {
  	    erase_char_string();
+ #ifdef KANJI
+           if (prefix[leng_prefix-1] <= 0x80)
+           {
+             cwidth = (float) (ZOOM_FACTOR * char_advance(canvas_font,
+                         (unsigned char) prefix[leng_prefix - 1]));
+           } else {
+               cwidth = ZOOM_FACTOR * char_width(canvas_kfont);
+               prefix[--leng_prefix]='\0';
+             }
+ #else
  	    cwidth = (float) (ZOOM_FACTOR * char_advance(canvas_font, 
  			(unsigned char) prefix[leng_prefix - 1]));
+ #endif
  	    cw2 = cwidth/2.0;
  	    cwsin = cwidth*sin_t;
  	    cwcos = cwidth*cos_t;
***************
*** 568,573 ****
--- 697,707 ----
  	    *prefix = '\0';
  	    draw_char_string();
  	}
+ #ifdef KANJI
+ 	if (c == CTRL_Y) {
+ 	    paste_cut_buffer(cur_x,cur_y);
+ 	}
+ #endif
      } else if (c < SP) {
  	put_msg("Invalid character ignored");
      } else if (leng_prefix + leng_suffix == BUF_SIZE) {
***************
*** 610,615 ****
--- 744,864 ----
      }
  }
  
+ #ifdef KANJI
+ static int char_received;
+ 
+ putch(ch)
+ unsigned char ch;
+ { 
+   float           cwidth, cw2;
+   float           cwsin, cwcos;
+   float           cw2sin, cw2cos;
+ 
+   erase_char_string();
+   char_received = 1;
+   if(ch > 0x80)
+     cwidth = (float) (ZOOM_FACTOR * char_width(canvas_kfont)) / 2;
+   else
+     cwidth = (float) (ZOOM_FACTOR * char_advance(canvas_font, ch));
+ 
+   cw2 = cwidth / 2.0;
+   cwsin = cwidth * sin_t;
+   cwcos = cwidth * cos_t;
+   cw2sin = cw2 * sin_t;
+   cw2cos = cw2 * cos_t;
+ 
+   switch (work_textjust) {
+   case T_LEFT_JUSTIFIED:
+       rcur_x += cwcos;			/* move the suffix to the left */
+       rcur_y -= cwsin;
+       break;
+   case T_CENTER_JUSTIFIED:
+       rbase_x -= cw2cos;		/* advance right by half cwidth */
+       rbase_y += cw2sin;
+       rcur_x += cw2cos;			/* move suffix left half cwidth */
+       rcur_y -= cw2sin;
+       break;
+   case T_RIGHT_JUSTIFIED:
+       rbase_x -= cwcos;			/* move the prefix to the right */
+       rbase_y += cwsin;
+       break;
+   }
+   cbase_x = round(rbase_x);		/* fix */
+   cbase_y = round(rbase_y);
+   cur_x = round(rcur_x);
+   cur_y = round(rcur_y);
+   prefix[leng_prefix++] = (ch);
+   prefix[leng_prefix] = '\0';
+   draw_char_string();
+ }
+     
+ paste_cut_buffer(x,y)
+ int x,y;
+ {
+     register char   *buffer, *endp;
+     register int    kanji;
+     int nbytes;
+ 
+     buffer = XFetchBytes(XtDisplay(tool), &nbytes);
+     if (!nbytes) return;
+ 
+ /* patch by kono%mtl.u-tokyo.junet (12/2/1988)
+  *   original line is
+  *  endp = buffer + nbytes - 2;
+  *   and new line is */
+     for (endp=buffer; (endp<=buffer+nbytes-2 && *endp!='\n'); endp++) ;
+ /* end of patch */
+     kanji = 0;
+ 
+     while (buffer < endp) {
+         if (to_kanji(buffer)) {
+         kanji = 1; buffer += 3;
+         } else if (to_ascii(buffer)) {
+         kanji = 0; buffer += 3;
+         } else if (kanji) {
+         putch(*buffer++ | 0x80);
+         putch(*buffer++ | 0x80);
+         } else {
+         putch(*buffer++);
+         }
+     }
+     if (buffer == endp) {
+         if (kanji) {
+         putch(*buffer++ | 0x80);
+         putch(*buffer++ | 0x80);
+         } else {
+         putch(*buffer++);
+         }
+     }
+     else if (buffer == endp + 1) {
+         putch(*buffer++);
+     }
+     XFree(buffer);
+ }
+ 
+ #define ESC 	'\033'
+ #define KI1 	'$'
+ #define KI2 	'B'
+ #define KO1 	'('
+ #define KO2 	'J'
+ 
+ to_kanji(buf)
+ char *buf;
+ {
+ if(*buf == ESC && *(buf+1) == KI1 && *(buf+2) == KI2)
+   return(1);
+ else return(0);
+ }
+ 
+ to_ascii(buf)
+ char *buf;
+ {
+ if(*buf == ESC && *(buf+1) == KO1 && *(buf+2) == KO2)
+   return(1);
+ else return(0);
+ }
+ #endif /* KANJI */
+ 
  /*******************************************************************
  
  	blinking cursor handling routines
***************
*** 734,738 ****
--- 983,991 ----
  {
      t->fontstruct = lookfont(x_fontnum(psfont_text(t), t->font), 
  			round(t->size*display_zoomscale));
+ #ifdef KANJI
+     t->kfontstruct = lookkfont(x_fontnum(psfont_text(t), t->font), 
+ 			round(t->size*display_zoomscale));
+ #endif
      t->zoom = zoomscale;
  }
*** e_edit.c.orig	Fri Aug 18 09:36:33 1995
--- e_edit.c	Tue Sep  3 16:35:38 1996
***************
*** 49,54 ****
--- 49,57 ----
  extern choice_info arrowtype_choices[];
  extern char    *panel_get_value();
  extern PIX_FONT lookfont();
+ #ifdef KANJI
+ extern PIX_FONT lookkfont();
+ #endif
  
  Widget		make_popup_menu();
  static Widget	make_popup_menu_images();
***************
*** 1230,1236 ****
--- 1233,1245 ----
      /* get the fontstruct for zoom = 1 to get the size of the string */
      canvas_font = lookfont(x_fontnum(psfont_text(new_t), new_t->font),
  			new_t->size);
+ #ifdef KANJI
+     canvas_kfont = lookkfont(x_fontnum(psfont_text(new_t), new_t->font),
+ 			new_t->size);
+     size = textsize(canvas_font, canvas_kfont, strlen(s), s);
+ #else
      size = textsize(canvas_font, strlen(s), s);
+ #endif
      new_t->ascent = size.ascent;
      new_t->descent = size.descent;
      new_t->length = size.length;
***************
*** 2500,2506 ****
--- 2509,2520 ----
  {
      int		    width, nlines, i;
      Dimension	    pwidth;
+ #ifdef KANJI
+     XFontSet        fontset;
+     XFontSetExtents *fontsetext;
+ #else
      PIX_FONT	    temp_font;
+ #endif
      char	   *labelname, *textname;
  
      /* make the labels of the widgets xxx_label for the label part and xxx_text for
***************
*** 2515,2524 ****
--- 2529,2546 ----
      FirstArg(XtNfromVert, below);
      NextArg(XtNlabel, name);
      NextArg(XtNborderWidth, 0);
+ #ifdef KANJI_R5
+     beside = XtCreateManagedWidget(labelname, labelLocaleWidgetClass, form, Args, ArgCount);
+ #else
      beside = XtCreateManagedWidget(labelname, labelWidgetClass, form, Args, ArgCount);
+ #endif
  
      /* get the font and width of above label widget */
+ #ifdef KANJI
+     FirstArg(XtNfontSet, &fontset);
+ #else
      FirstArg(XtNfont, &temp_font);
+ #endif
      NextArg(XtNwidth, &pwidth);
      GetValues(beside);
      /* make panel as wide as image pane above less the label widget's width */
***************
*** 2534,2539 ****
--- 2556,2564 ----
      }
      if (nlines > 4)	/* limit to displaying 4 lines and show scrollbars */
  	nlines = 4;
+ #ifdef KANJI
+     fontsetext = XExtentsOfFontSet(fontset);
+ #endif
      FirstArg(XtNfromVert, below);
      NextArg(XtNstring, string);
      NextArg(XtNinsertPosition, strlen(string));
***************
*** 2541,2557 ****
--- 2566,2592 ----
      NextArg(XtNeditType, XawtextEdit);
      NextArg(XtNwidth, width);
      /* allow enough height for scrollbar */
+ #ifdef KANJI
+     NextArg(XtNheight, (fontsetext->max_logical_extent.height) * nlines + 20);
+ #else
      NextArg(XtNheight, max_char_height(temp_font) * nlines + 20);
+ #endif
      NextArg(XtNscrollHorizontal, XawtextScrollWhenNeeded);
      NextArg(XtNscrollVertical, XawtextScrollWhenNeeded);
  
+ #ifdef KANJI_R5
+     *pi_x = XtCreateManagedWidget(textname, multiTextWidgetClass, form, Args, ArgCount);
+ #else
      *pi_x = XtCreateManagedWidget(textname, asciiTextWidgetClass, form, Args, ArgCount);
+ #endif
  
      /* make CR do nothing for now */
      text_transl(*pi_x);
  
+ #ifndef KANJI
      /* read personal key configuration */
      XtOverrideTranslations(*pi_x, XtParseTranslationTable(local_translations));
+ #endif
  
      below = *pi_x;
  
*** e_update.c.orig	Wed May 24 07:56:36 1995
--- e_update.c	Tue Sep  3 10:14:09 1996
***************
*** 32,37 ****
--- 32,40 ----
  
  extern		update_current_settings();
  extern PIX_FONT lookfont();
+ #ifdef KANJI	/* H.Goto */
+ extern PIX_FONT lookkfont();
+ #endif
  static int	init_update_object();
  static int	init_update_settings();
  
***************
*** 340,347 ****
--- 343,356 ----
      up_part(text->angle, cur_elltextangle*M_PI/180.0, I_ELLTEXTANGLE);
      up_part(text->color, cur_pencolor, I_PEN_COLOR);
      up_part(text->depth, cur_depth, I_DEPTH);
+ #ifdef KANJI
+     size = textsize(lookfont(x_fontnum(psfont_text(text), text->font),text->size), 
+ 		lookkfont(x_fontnum(psfont_text(text), text->font),text->size),
+ 		strlen(text->cstring), text->cstring);
+ #else
      size = textsize(lookfont(x_fontnum(psfont_text(text), text->font),
  			text->size), strlen(text->cstring), text->cstring);
+ #endif
      text->ascent = size.ascent;
      text->descent = size.descent;
      text->length = size.length;
*** f_read.c.orig	Tue Aug  8 09:52:31 1995
--- f_read.c	Tue Sep  3 10:05:47 1996
***************
*** 961,966 ****
--- 961,969 ----
      char	    s[BUF_SIZE], s_temp[BUF_SIZE], junk[2];
      float	    tx_size;
      extern PIX_FONT lookfont();
+ #ifdef KANJI
+     extern PIX_FONT lookkfont();
+ #endif
      Boolean	    more;
      PR_SIZE	    tx_dim;
  
***************
*** 1077,1082 ****
--- 1080,1088 ----
  
      /* get the UNZOOMED font struct */
      t->fontstruct = lookfont(x_fontnum(psfont_text(t), t->font), t->size);
+ #ifdef KANJI
+     t->kfontstruct = lookkfont(x_fontnum(psfont_text(t), t->font), t->size);
+ #endif
  
      fix_depth(&t->depth);
      check_color(&t->color);
***************
*** 1182,1188 ****
--- 1188,1198 ----
      (void) strcpy(t->cstring, &s[1]);
  
      /* now calculate the actual length and height of the string in fig units */
+ #ifdef KANJI	/* H.Goto */
+     tx_dim = textsize(t->fontstruct, t->kfontstruct, strlen(t->cstring), t->cstring);
+ #else
      tx_dim = textsize(t->fontstruct, strlen(t->cstring), t->cstring);
+ #endif
      t->length = round(tx_dim.length);
      t->ascent = round(tx_dim.ascent);
      t->descent = round(tx_dim.descent);
*** fig.h.orig	Fri Aug 11 09:02:48 1995
--- fig.h	Thu Oct 10 16:21:50 1996
***************
*** 327,332 ****
--- 327,365 ----
  extern char *strstr();
  #endif
  
+ #ifdef KANJI
+ 
+ #include <X11/Xlocale.h>
+ 
+ #include <X11/cursorfont.h>
+ #include <X11/StringDefs.h>
+ #include <X11/Shell.h>
+ #include <X11/Xatom.h>
+ 
+ #ifdef KANJI_R5
+ #include <X11/Xaw/LabelLc.h>
+ #include <X11/Xaw/MultiText.h>
+ #endif
+ 
+ #include <X11/Xaw/Command.h>
+ #include <X11/Xaw/Label.h>
+ #include <X11/Xaw/Dialog.h>
+ #include <X11/Xaw/Box.h>
+ #include <X11/Xaw/Form.h>
+ #include <X11/Xaw/Cardinals.h>
+ #include <X11/Xaw/Text.h>
+ #include <X11/Xaw/AsciiText.h>
+ #include <X11/Xaw/MenuButton.h>
+ #include <X11/Xaw/SimpleMenu.h>
+ #include <X11/Xaw/Sme.h>
+ #include <X11/Xaw/SmeBSB.h>
+ #include <X11/Xaw/Toggle.h>
+ #include <X11/Xaw/Paned.h>
+ #include <X11/Xaw/Viewport.h>
+ #include <X11/Xaw/List.h>
+ 
+ #endif
+ 
  #if defined(SYSV) || defined(SVR4)
  extern	void		srand48();
  extern	long		lrand48();
*** main.c.orig	Tue Aug  8 06:57:59 1995
--- main.c	Thu Oct 10 16:11:43 1996
***************
*** 116,121 ****
--- 116,127 ----
      XtOffset(appresPtr, normalFont), XtRString, (caddr_t) NULL},
      {"buttonFont", "Font", XtRString, sizeof(char *),
      XtOffset(appresPtr, buttonFont), XtRString, (caddr_t) NULL},
+ #ifdef KANJI
+     {"kanjiFont", "KanjiFont", XtRString, sizeof(char *),
+     XtOffset(appresPtr, kanjiFont), XtRString, (caddr_t)NULL},
+     {"kanjiscalablefonts", "KanjiScalableFonts", XtRBoolean, sizeof(Boolean),
+     XtOffset(appresPtr, KANJISCALABLEFONTS), XtRBoolean, (caddr_t) & true},
+ #endif
      {"startlatexFont", "StartlatexFont", XtRString, sizeof(char *),
      XtOffset(appresPtr, startlatexFont), XtRString, (caddr_t) NULL},
      {"startpsFont", "StartpsFont", XtRString, sizeof(char *),
***************
*** 191,196 ****
--- 197,207 ----
      {"-boldFont", ".boldFont", XrmoptionSepArg, 0},
      {"-normalFont", ".normalFont", XrmoptionSepArg, 0},
      {"-buttonFont", ".buttonFont", XrmoptionSepArg, 0},
+ #ifdef KANJI
+     {"-kanjiFont", ".kanjiFont", XrmoptionSepArg, 0},
+     {"-kanjiscalablefonts", ".kanjiscalablefonts", XrmoptionNoArg, "True"},
+     {"-kanjinoscalablefonts", ".kanjiscalablefonts", XrmoptionNoArg, "False"},
+ #endif
      {"-startpsFont", ".startpsFont", XrmoptionSepArg, 0},
      {"-startlatexFont", ".startlatexFont", XrmoptionSepArg, 0},
      {"-startFontSize", ".startfontsize", XrmoptionSepArg, 0},
***************
*** 329,334 ****
--- 340,349 ----
  	exit(0);
      }
  
+ #ifdef KANJI
+     XtSetLanguageProc(NULL, NULL, NULL);
+ #endif
+ 
      /* we are not writing the figure to the bitmap */
      writing_bitmap = False;
  
***************
*** 707,712 ****
--- 722,728 ----
  	XSetIOErrorHandler((XIOErrorHandler) X_error_handler);
      }
  
+     if (!appres.DEBUG) {
      (void) signal(SIGHUP, error_handler);
      (void) signal(SIGFPE, error_handler);
  #ifdef SIGBUS
***************
*** 714,719 ****
--- 730,737 ----
  #endif
      (void) signal(SIGSEGV, error_handler);
      (void) signal(SIGINT, SIG_IGN);	/* in case user accidentally types ctrl-c */
+ 
+     }
  
      put_msg("READY, please select a mode or load a file");
  
*** object.h.orig	Fri Aug 18 09:22:17 1995
--- object.h	Wed Aug 28 14:01:18 1996
***************
*** 212,217 ****
--- 212,220 ----
  #define					T_RIGHT_JUSTIFIED	2
      int		    font;
      PIX_FONT	    fontstruct;
+ #ifdef KANJI
+     PIX_FONT	    kfontstruct;	/* kanji fontstruct */
+ #endif
      float	    zoom;	/* to keep track of when it needs rescaling */
      int		    size;	/* point size */
      Color	    color;
*** patchlevel.h.orig	Thu Aug 17 06:54:50 1995
--- patchlevel.h	Wed Aug 28 14:30:39 1996
***************
*** 16,19 ****
--- 16,23 ----
   * the party supplying this software to the X Consortium.
   */
  
+ #ifdef KANJI
+ #define PATCHLEVEL "4-J2"
+ #else
  #define PATCHLEVEL "4"
+ #endif
*** resources.h.orig	Wed Aug  9 05:41:17 1995
--- resources.h	Tue Aug 13 12:02:22 1996
***************
*** 89,94 ****
--- 89,98 ----
      char	   *normalFont;
      char	   *boldFont;
      char	   *buttonFont;
+ #ifdef KANJI
+     char           *kanjiFont;
+     Boolean	    KANJISCALABLEFONTS;
+ #endif
      char	   *startpsFont;	/* bab 11 Jan 92 */
      char	   *startlatexFont;	/* bab 11 Jan 92 */
      float	    tmp_width;
*** u_drag.c.orig	Sat Aug 12 08:07:01 1995
--- u_drag.c	Wed Aug 28 14:02:38 1996
***************
*** 367,373 ****
--- 367,377 ----
      x1off = new_t->base_x - x;
      y1off = new_t->base_y - y;
      if (t->type == T_CENTER_JUSTIFIED || t->type == T_RIGHT_JUSTIFIED) {
+ #ifdef KANJI
+ 	txsize = textsize(t->fontstruct, t->kfontstruct, strlen(t->cstring), t->cstring);
+ #else
  	txsize = textsize(t->fontstruct, strlen(t->cstring), t->cstring);
+ #endif
  	if (t->type == T_CENTER_JUSTIFIED) {
  	    cw2 = txsize.length/2.0/display_zoomscale;
  	    x1off = round(x1off - cos((double)t->angle)*cw2);
*** u_draw.c.orig	Tue Aug 15 06:56:49 1995
--- u_draw.c	Tue Sep  3 16:44:32 1996
***************
*** 30,35 ****
--- 30,38 ----
  #include "w_zoom.h"
  
  extern PIX_FONT lookfont();
+ #ifdef KANJI
+ extern PIX_FONT lookkfont();
+ #endif
  
  /************** POLYGON/CURVE DRAWING FACILITIES ****************/
  
***************
*** 504,513 ****
--- 507,525 ----
  	    xmax = max3(p0->x, p1->x, p2->x);
  	    ymax = max3(p0->y, p1->y, p2->y);
  	    canvas_font = lookfont(0, 12);	/* get a size 12 font */
+ #ifdef KANJI
+ 	    canvas_kfont = lookkfont(0, 12);	/* get a size 12 kfont */
+ 	    txt = textsize(canvas_font, canvas_kfont, strlen(string), string);
+ #else
  	    txt = textsize(canvas_font, strlen(string), string);
+ #endif
  	    x = (xmin + xmax) / 2 - txt.length/display_zoomscale / 2;
  	    y = (ymin + ymax) / 2;
+ #ifdef KANJI
+ 	    pw_text(canvas_win, x, y, op, canvas_font, canvas_kfont, 0.0, string, DEFAULT);
+ #else
  	    pw_text(canvas_win, x, y, op, canvas_font, 0.0, string, DEFAULT);
+ #endif
  	}
      }
      /* get first point and coordinates */
***************
*** 1086,1093 ****
--- 1098,1110 ----
      x = text->base_x;
      y = text->base_y;
      if (text->type == T_CENTER_JUSTIFIED || text->type == T_RIGHT_JUSTIFIED) {
+ #ifdef KANJI
+ 	size = textsize(text->fontstruct, text->kfontstruct, strlen(text->cstring),
+ 			    text->cstring);
+ #else
  	size = textsize(text->fontstruct, strlen(text->cstring),
  			    text->cstring);
+ #endif
  	size.length = size.length/display_zoomscale;
  	if (text->type == T_CENTER_JUSTIFIED) {
  	    x = round(x-cos(text->angle)*size.length/2);
***************
*** 1098,1108 ****
--- 1115,1133 ----
  	}
      }
      if (hidden_text(text))
+ #ifdef KANJI
+ 	pw_text(canvas_win, x, y, op, lookfont(0,12), lookkfont(0,12),
+ 		text->angle, hidden_text_string, DEFAULT);
+     else
+ 	pw_text(canvas_win, x, y, op, text->fontstruct, text->kfontstruct,
+ 		text->angle, text->cstring, text->color);
+ #else
  	pw_text(canvas_win, x, y, op, lookfont(0,12),
  		text->angle, hidden_text_string, DEFAULT);
      else
  	pw_text(canvas_win, x, y, op, text->fontstruct,
  		text->angle, text->cstring, text->color);
+ #endif
  }
  
  /*********************** COMPOUND ***************************/
*** u_elastic.c.orig	Sat Jul  8 06:49:41 1995
--- u_elastic.c	Tue Aug 13 12:02:25 1996
***************
*** 771,779 ****
  
  elastic_movetext()
  {
      pw_text(canvas_win, cur_x + x1off, cur_y + y1off, INV_PAINT,
! 	    new_t->fontstruct, new_t->angle, 
  	    new_t->cstring, new_t->color);
  }
  
  
--- 771,785 ----
  
  elastic_movetext()
  {
+ #ifdef KANJI
      pw_text(canvas_win, cur_x + x1off, cur_y + y1off, INV_PAINT,
! 	    new_t->fontstruct, new_t->kfontstruct, new_t->angle, 
  	    new_t->cstring, new_t->color);
+ #else
+     pw_text(canvas_win, cur_x + x1off, cur_y + y1off, INV_PAINT,
+ 	    new_t->fontstruct, new_t->angle,
+ 	    new_t->cstring, new_t->color);
+ #endif
  }
  
  
*** u_fonts.h.orig	Thu Jun  2 06:35:25 1994
--- u_fonts.h	Tue Aug 13 12:02:25 1996
***************
*** 50,55 ****
--- 50,60 ----
      char	   *template;	/* template for locating X fonts */
      struct xfont   *xfontlist;	/* linked list of X fonts for different point
  				 * sizes */
+ #ifdef KANJI
+     char	   *ktemplate;	/* template for locating X kanji fonts */
+     struct xfont   *xkfontlist; /* linked list of X kanji fonts for different
+ 				 * point sizes */
+ #endif
  };
  
  int		x_fontnum();
*** w_canvas.c.orig	Tue Jul 18 07:13:39 1995
--- w_canvas.c	Thu Oct 10 16:18:48 1996
***************
*** 64,69 ****
--- 64,72 ----
  int		clip_xmin, clip_ymin, clip_xmax, clip_ymax;
  int		clip_width, clip_height;
  int		cur_x, cur_y;
+ #ifdef KANJI
+ void            BeginConversion();
+ #endif KANJI
  
  String		local_translations = "";
  
***************
*** 123,134 ****
      {"PasteCanv", (XtActionProc) canvas_paste},
      {"LeaveCanv", (XtActionProc) clear_mousefun},
      {"EraseRulerMark", (XtActionProc) erase_rulermark},
  };
  
  /* need the ~Meta for the EventCanv action so that the accelerators still work 
     during text input */
  static String	canvas_translations =
! "<Motion>:EventCanv()\n\
      Any<BtnDown>:EventCanv()\n\
      <Key>F18: PasteCanv()\n\
      <EnterWindow>:EnterCanv()\n\
--- 126,142 ----
      {"PasteCanv", (XtActionProc) canvas_paste},
      {"LeaveCanv", (XtActionProc) clear_mousefun},
      {"EraseRulerMark", (XtActionProc) erase_rulermark},
+ #ifdef KANJI
+     { "begin-conversion", BeginConversion },
+ #endif
  };
  
  /* need the ~Meta for the EventCanv action so that the accelerators still work 
     during text input */
+ #ifdef KANJI
  static String	canvas_translations =
! "Shift<Key>space:begin-conversion(_JAPANESE_CONVERSION) \n\
!     <Motion>:EventCanv()\n\
      Any<BtnDown>:EventCanv()\n\
      <Key>F18: PasteCanv()\n\
      <EnterWindow>:EnterCanv()\n\
***************
*** 136,141 ****
--- 144,159 ----
      <KeyUp>:EventCanv()\n\
      ~Meta<Key>:EventCanv()\n\
      <Expose>:ExposeCanv()\n";
+ #else
+ static String	canvas_translations =
+ "<Motion>:EventCanv()\n\
+     Any<BtnDown>:EventCanv()\n\
+     <Key>F18: PasteCanv()\n\
+     <EnterWindow>:EnterCanv()\n\
+     <LeaveWindow>:LeaveCanv()EraseRulerMark()\n\
+     <Key>:EventCanv()\n\
+     <Expose>:ExposeCanv()\n";
+ #endif
  
  init_canvas(tool)
      Widget	   tool;
***************
*** 211,217 ****
--- 229,239 ----
      register int    x, y;
      KeySym	    key;
      static int	    sx = -10000, sy = -10000;
+ #ifdef KANJI
+     unsigned char   buf[1];
+ #else
      char	    buf[1];
+ #endif
      XButtonPressedEvent *be = (XButtonPressedEvent *) event;
      XKeyPressedEvent *ke = (XKeyPressedEvent *) event;
  
*** w_drawprim.c.orig	Tue Aug  1 09:26:45 1995
--- w_drawprim.c	Tue Sep  3 17:12:13 1996
***************
*** 56,61 ****
--- 56,66 ----
  PIX_FONT	button_font;
  PIX_FONT	canvas_font;
  
+ #ifdef KANJI
+ PIX_FONT        kanji_font;
+ PIX_FONT        canvas_kfont;
+ #endif
+ 
  /* LOCAL */
  
  static Pixel	gc_color[NUMOPS];
***************
*** 63,70 ****
--- 68,97 ----
  static int	parsesize();
  static Boolean	openwinfonts;
  
+ #ifdef KANJI
+ static int      gc_font[NUMOPS], gc_fontsize[NUMOPS];
+ #endif
+ 
  #define MAXNAMES 35
  
+ #ifdef KANJI
+ struct xfont kfontlist[] = {
+         { 8,  0, "k14.8",  NULL, NULL },
+         { 10, 0, "k14.10", NULL, NULL },
+         { 12, 0, "k14.12", NULL, NULL },
+         { 14, 0, "k14.14", NULL, NULL },
+         { 16, 0, "k14.16", NULL, NULL },
+         { 18, 0, "k14.18", NULL, NULL },
+         { 20, 0, "k14.20", NULL, NULL },
+         { 24, 0, "k14.24", NULL, NULL },
+         { 26, 0, "k14.26", NULL, NULL },
+         { 32, 0, "k14.32", NULL, NULL },
+         { 48, 0, "k14.48", NULL, NULL },
+         { 72, 0, "k14.72", NULL, NULL },
+         { 96, 0, "k14.96", NULL, NULL }
+ };
+ #endif
+ 
  static struct {
      char	   *fn;
      int		    s;
***************
*** 79,84 ****
--- 106,115 ----
  
      if (appres.boldFont == NULL || *appres.boldFont == '\0')
  	appres.boldFont = BOLD_FONT;
+ #ifdef KANJI
+     if( appres.kanjiFont == NULL || *appres.kanjiFont == '\0')
+         appres.kanjiFont = KANJI_FONT;
+ #endif
      if (appres.normalFont == NULL || *appres.normalFont == '\0')
  	appres.normalFont = NORMAL_FONT;
      if (appres.buttonFont == NULL || *appres.buttonFont == '\0')
***************
*** 105,110 ****
--- 136,147 ----
  		appres.buttonFont, appres.normalFont);
  	button_font = XLoadQueryFont(tool_d, appres.normalFont);
      }
+ #ifdef KANJI
+     if ((kanji_font = XLoadQueryFont(tool_d, appres.kanjiFont)) == 0) {
+ 	fprintf(stderr, "Can't load font: %s\n",appres.kanjiFont);
+ 	exit(1);
+     }
+ #endif
      /*
       * Now initialize the font structure for the X fonts corresponding to the
       * Postscript fonts for the canvas.	 OpenWindows can use any LaserWriter
***************
*** 125,131 ****
--- 162,174 ----
  	    strcpy(template,x_fontinfo[0].template);  /* nope, check for font size 0 */
  	    strcat(template,"0-0-*-*-*-*-*-*");
  	    if ((fontlist = XListFonts(tool_d, template, 1, &count))==0)
+ #ifdef KANJI
+ 		appres.KANJISCALABLEFONTS = appres.SCALABLEFONTS = False;
+ 		/* 欧文スケーラブルフォントが見つからなければ、
+ 		   ついでに漢字スケーラブルフォントも OFF にしておこう	*/
+ #else
  		appres.SCALABLEFONTS = False;	/* none, turn off request for them */
+ #endif
  	}
      }
  
***************
*** 179,184 ****
--- 222,248 ----
  	    } /* next size */
  	} /* next font, f */
      } /* !appres.SCALABLEFONTS */
+ #ifdef KANJI
+     {
+       int             j, max, found;
+       struct xfont    *first = NULL, *prev = NULL;
+     
+       max = sizeof(kfontlist)/sizeof(struct xfont);
+       for (j=0; j < max; j++)
+         {
+             (void) XListFonts(tool_d, kfontlist[j].fname, 1, &found);
+             if (found > 0)
+               {
+                   if (!first) first = &kfontlist[j];
+                   if (prev)   prev->next = &kfontlist[j];
+                   prev = &kfontlist[j];
+               }
+         }
+       for (j=0; j < NUM_FONTS; j++) {
+           x_fontinfo[j].xkfontlist = first;
+       }
+     }
+ #endif /* KANJI */
      XFreeFontNames(fontlist); 
  }
  
***************
*** 320,332 ****
  	return (nf->fstruct);
  }
  
! /* print "string" in window "w" using font specified in fstruct at angle
! 	"angle" (radians) at (x,y) */
  
  pw_text(w, x, y, op, fstruct, angle, string, color)
      Window	    w;
      int		    x, y, op;
      PIX_FONT	    fstruct;
      float	    angle;
      char	   *string;
      Color	    color;
--- 384,489 ----
  	return (nf->fstruct);
  }
  
! #ifdef KANJI
  
+ /*
+  * Lookup an X kanji font
+  */
+ 
+ PIX_FONT
+   lookkfont(f,s)
+      int	f, s;
+ {
+   struct xfont	*xf;
+   XFontStruct	*fontst;
+   int		fuzz;
+ 
+   if (f<0)	f=0;			/* use font 0 for default font (-1) */
+ 
+   if (s<0)	s=DEF_FONTSIZE;		/* default font size		*/
+ 
+   if (s <= 26)		fuzz = 1;	/* fuzz number for look size	*/
+   else if (s <= 32)	fuzz = 2;
+   else if (s <= 48)	fuzz = 3;
+   else			fuzz = 4;
+ 
+   xf = x_fontinfo[f].xkfontlist;	/* go through the linked list
+ 					   looking for match		*/
+   if (xf == NULL)			/* kfontlist does not appear	*/
+       fontst = kanji_font;		/*   use default kanji font	*/
+   else
+     {
+     while (1)				/* kfontlist apeared		*/
+       {
+ 	if (s-fuzz <= xf->size)		/* -fuzz, exact or larger point size */
+ 	  break;
+ 	if (xf->next != NULL)		/* keep ptr to last if not found */
+ 	  xf = xf->next;
+ 	else
+ 	  break;			/* not found, use largest point size
+ 					   in the list */
+       }
+     fontst = xf->fstruct;
+ 
+     if (xf->fid == 0)			/* if the font is not yet loaded,
+ 					   load it */
+       {
+ 	if (appres.DEBUG)
+ 	    fprintf(stderr,"Loading font %s\n",xf->fname);
+ 	if (fontst = XLoadQueryFont(tool_d, xf->fname))	/* load it */
+ 	    {
+ 	      xf->fid = fontst->fid;		/* save the id */
+ 	      xf->fstruct = fontst;		/* and the XFontStruct ptr */
+ 	    }
+ 	else
+ 	    fprintf(stderr,"What!!?!?! Can't find font %s\n",xf->fname);
+ 	}
+     if ( abs(s - xf->size) <= fuzz )   return(fontst);
+ 						/* use font in kfontlist
+ 						   or default kanji_font */
+   }
+ 
+     if (!appres.KANJISCALABLEFONTS)
+ 	return(fontst);				/* use font in kfontlist
+ 						   or default kanji_font */
+     else
+       {						/* scalable fonts! */
+ 	char            fn[128];
+ 	char            template[128];
+ 
+ 	put_msg("Please wait for loading scalable kanji font %dpt", s);
+ 	strcpy(template,
+ /*	       "-*-fixed-medium-r-normal--%d-*-*-*-*-*-jisx0208.1983-0");	*/
+ 	       "-*-minchou-medium-r-normal--%d-*-*-*-*-*-jisx0208.1983-0");
+ 	sprintf(fn, template, s);
+ 	if (appres.DEBUG)
+ 	  fprintf(stderr, "Loading font %s\n", fn);
+ 	fontst = XLoadQueryFont(tool_d, fn);
+ 	if (fontst == NULL) {
+ 	  fprintf(stderr, "xfig: Can't load font %s ?!, using %s\n",
+ 		  fn, appres.kanjiFont);
+ 	  fontst = XLoadQueryFont(tool_d, appres.kanjiFont);
+ 	}
+ 	return (fontst);
+       }	
+ }
+ 
+ #endif
+ 
+ /* print "string" in window "w" using font specified in fstruct/kfstruct
+    at angle "angle" (radians) at (x,y) */
+ 
+ #ifdef KANJI
+ pw_text(w, x, y, op, fstruct, kfstruct, angle, string, color)
+ #else
  pw_text(w, x, y, op, fstruct, angle, string, color)
+ #endif
      Window	    w;
      int		    x, y, op;
      PIX_FONT	    fstruct;
+ #ifdef KANJI
+     PIX_FONT	    kfstruct;
+ #endif
      float	    angle;
      char	   *string;
      Color	    color;
***************
*** 333,341 ****
--- 490,506 ----
  {
      if (fstruct == NULL)
  	fprintf(stderr,"Error, in pw_text, fstruct==NULL\n");
+ #ifdef KANJI
+     if (kfstruct == NULL)
+ 	fprintf(stderr,"Error, in pw_text, kfstruct==NULL\n");
+     pwx_text(w, x, y, op, fstruct, kfstruct, angle, string, color);
+ #else
      pwx_text(w, x, y, op, fstruct, angle, string, color);
+ #endif
  }
  
+ #ifndef KANJI
+ 
  pwx_text(w, x, y, op, fstruct, angle, string, color)
      Window	    w;
      int		    x, y, op;
***************
*** 344,349 ****
--- 509,516 ----
      char	   *string;
      Color	    color;
  {
+     int  i;
+ 
      /* if we're drawing to the bitmap instead of the canvas
         map colors white => white, all others => black */
      if (writing_bitmap)
***************
*** 366,385 ****
--- 533,711 ----
  		    x, y, string);
  }
  
+ #else /* KANJI */
+ 
+ pwx_text(w, x, y, op, fstruct, kfstruct, angle, string, color)
+      Window	    w;
+      int	    x, y, op;
+      PIX_FONT	    fstruct, kfstruct;
+      float	    angle;
+      unsigned char  *string;
+      Color	    color;
+ {
+     int  i;
+ 
+     /* if we're drawing to the bitmap instead of the canvas
+        map colors white => white, all others => black */
+     if (writing_bitmap)
+ 	{
+ 	if (color == WHITE)
+ 		color = 0;
+ 	else
+ 		color = 1;
+ 	}
+     if (writing_bitmap? color != gc_color[op] : x_color(color) != gc_color[op]) {
+ 	    if (op == PAINT) {
+ 		if (writing_bitmap)
+ 		    XSetForeground(tool_d,gccache[op],color);
+ 		else
+ 		    set_x_color(gccache[op], color);
+ 		gc_color[op] = writing_bitmap? color : x_color(color);
+ 	    }
+     }
+ 
+   for(i=0;string[i] != '\0' && string[i] != '\n';)
+   {
+     if(string[i] < 0x80)
+       i = pw_asc_text(w, fstruct, &x, &y, op, string, i, angle);
+     else
+       i = pw_kanji_text(w, kfstruct, &x, &y, op, string, i, angle);
+   }
+ }
+ 
+ pw_asc_text(w, fstruct, x, y, op, string, i, angle)
+      Window   		w;
+      int      		*x, *y;
+      int      		op;
+      PIX_FONT		fstruct;
+      unsigned char	string[];
+      int		i;
+      float		angle;
+ {
+     unsigned char buf[1024];
+     int		j;
+     float	len = 0;
+ 
+     for(j=0;string[i] != '\0' && string[i] != '\n' && string[i] < 0x80;i++,j++)
+         buf[j] = string[i];
+     buf[j] = '\0';
+ 
+     zXRotDrawString(tool_d, fstruct, angle, w, gccache[op], *x, *y, buf);
+ 
+     for(--j;j >= 0;j--)
+         len += char_advance(fstruct,buf[j]) / zoomscale ;
+     *x += cos(angle) * len;
+     *y -= sin(angle) * len;
+ 
+     return(i);
+ }
+ 
+ pw_kanji_text(w, kfstruct, x, y, op, string, i, angle)
+      Window		w;
+      int      		*x, *y;
+      int      	 	op;
+      PIX_FONT   	kfstruct;
+      unsigned char     	string[];
+      int       		i;
+      float		angle;
+ {
+   unsigned char buf[3];
+   int 	     	j = 0;
+   float		len  = 0, cos_angle, sin_angle;
+   int		xd, yd, width, height;
+ 
+ /* もし zXRotDrawString16 が出来たら、こうしよう。********************
+ 
+   for(j=0;string[i] >= 0x80 && string[i] != 0x8e;)
+      {
+      buf[j++] = string[i++] & 0x7f;
+      buf[j++] = string[i++] & 0x7f;
+      }
+   buf[j] = '\0';
+   zXRotDrawString16(tool_d, kfstruct, angle, w, gccache[op], *x, *y, buf);
+   len = strlen(buf)/2 * char_width(kfstruct) / zoomscale;
+   *x += cos(angle) * len;
+   *y -= sin(angle) * len;
+ 
+ ******************************************************************* */
+ 
+   /* 漢字の描画位置補正の為の準備 */
+   width = char_width(kfstruct);
+   height = max_char_height(kfstruct);
+   cos_angle = cos(angle);
+   sin_angle = sin(angle);
+ 
+   /* 次に描く漢字の中心座標を求め、それを元に始点を決める。 */
+   xd = *x + width/2 * (cos_angle - sin_angle - 1.0)/zoomscale;
+   yd = *y - height/2 * (sin_angle + cos_angle - 1.0)/zoomscale;
+ 
+   /* buf[]に漢字１文字をコピー */
+   buf[j++] = string[i++] & 0x7f;
+   buf[j++] = string[i++] & 0x7f;
+   buf[j] = '\0';
+ 
+   change_gc(gccache[op], kfstruct);
+   zXDrawString16(tool_d, w, gccache[op], xd, yd, (XChar2b *)buf, 1);
+   len = width / zoomscale;
+   *y -= round(sin_angle * len);		/* 次の描画座標を求める。*/
+   *x += round(cos_angle * len);
+ 
+   return(i);
+ }
+ #endif /* KANJI */
+ 
  PR_SIZE
+ #ifdef KANJI
+ textsize(fstruct, kfstruct, n, s)
+     PIX_FONT	    fstruct;
+     PIX_FONT	    kfstruct;
+     int		    n;
+     unsigned char   *s;
+ #else
  textsize(fstruct, n, s)
      PIX_FONT	    fstruct;
      int		    n;
      char	   *s;
+ #endif
  {
      PR_SIZE	    ret;
      int		    dir, asc, desc;
      XCharStruct	    overall;
  
+ #ifndef KANJI 
      ret.length = ZOOM_FACTOR * XTextWidth(fstruct, s, n);
      XTextExtents(fstruct, s, n, &dir, &asc, &desc, &overall);
      ret.ascent = ZOOM_FACTOR * overall.ascent;
      ret.descent = ZOOM_FACTOR * overall.descent;
+ #else
+     {
+ 	unsigned char *c;
+ 	XChar2b	buf;
+ 	c = s;
+ 	ret.length = ret.ascent = ret.descent = 0;
+ 
+ 	while (c <= s + n - 1)
+ 	{
+ 	    if ((*c) < 0x7f)
+ 	    {
+ 		XTextExtents(fstruct, c, 1, &dir, &asc, &desc, &overall);
+ 		c ++;
+ 	    } else {
+ 		buf.byte1 = *(c ++) & 0x7f;
+ 		buf.byte2 = *(c ++) & 0x7f;
+ 		XTextExtents16(kfstruct, &buf, 1, &dir, &asc, &desc, &overall);
+ 	    }
+ 	    ret.length += overall.width;
+ 	    if (ret.ascent  < overall.ascent ) ret.ascent  = overall.ascent ;
+ 	    if (ret.descent < overall.descent) ret.descent = overall.descent;
+ 	}
+ 	ret.length  *= ZOOM_FACTOR;
+ 	ret.ascent  *= ZOOM_FACTOR;
+ 	ret.descent *= ZOOM_FACTOR;
+     }
+ #endif
+     if (appres.DEBUG)
+          printf("%d %d %d \n",ret.length,ret.ascent,ret.descent);
      return (ret);
  }
  
***************
*** 1295,1300 ****
--- 1621,1640 ----
      gc_cap_style[op] = cap_style;
      gc_color[op] = writing_bitmap? color : x_color(color);
  }
+ 
+ #ifdef KANJI
+ change_gc(ngc,font)      
+ GC        ngc;            
+ PIX_FONT  font;
+ {
+     XGCValues       gcv;
+     int             gcmask;
+                             
+     gcv.font = font->fid;
+     gcmask = GCFont;
+     XChangeGC(tool_d, ngc, gcmask, &gcv);
+ }
+ #endif
  
  int
  x_color(col)
*** w_drawprim.h.orig	Tue Dec  6 02:08:10 1994
--- w_drawprim.h	Tue Aug 13 12:02:27 1996
***************
*** 23,28 ****
--- 23,34 ----
  extern PIX_FONT button_font;
  extern PIX_FONT canvas_font;
  
+ #ifdef KANJI
+ extern PIX_FONT kanji_font;
+ extern PIX_FONT canvas_kfont;
+ extern PIX_FONT canvas_zoomed_kfont;
+ #endif
+ 
  /* Maximum number of points for polygons etc */
  /* This may be overridden by adding -DMAXNUMPTS=xxxx in the Imakefile/Makefile */
  #ifndef MAXNUMPTS
***************
*** 34,39 ****
--- 40,49 ----
  #define		NORMAL_FONT	"fixed"
  #define		BOLD_FONT	"8x13bold"
  #define		BUTTON_FONT	"6x13"
+ 
+ #ifdef KANJI
+ #  define       KANJI_FONT      "k14"
+ #endif
  
  #define		max_char_height(font) \
  		((font)->max_bounds.ascent + (font)->max_bounds.descent)
*** w_zoom.h.orig	Fri Jan  6 10:28:43 1995
--- w_zoom.h	Wed Aug 28 12:20:36 1996
***************
*** 43,48 ****
--- 43,55 ----
  	      (short)ZOOMX(x2),(short)ZOOMY(y2))
  #define zXRotDrawString(d,font,ang,w,gc,x,y,s)\
      XRotDrawString(d,font,ang,w,gc,(short)ZOOMX(x),(short)ZOOMY(y),s)
+ #ifdef KANJI
+ #define zXDrawString(d,w,gc,x,y,s,l)\
+     XDrawString(d,w,gc,(short)ZOOMX(x),(short)ZOOMY(y),s,l)
+ 
+ #define zXDrawString16(d,w,gc,x,y,s,l)\
+     XDrawString16(d,w,gc,(short)ZOOMX(x),(short)ZOOMY(y),s,l)
+ #endif
  #define zXFillRectangle(d,w,gc,x1,y1,x2,y2)\
      XFillRectangle(d,w,gc,(short)ZOOMX(x1),(short)ZOOMY(y1),\
  		(short)round(zoomscale*(x2)),(short)round(zoomscale*(y2)))
*** f_readold.c.orig	Tue Aug  8 09:54:36 1995
--- f_readold.c	Tue Sep  3 10:12:33 1996
***************
*** 468,473 ****
--- 468,476 ----
      int		    dum;
      char	    buf[128];
      extern PIX_FONT lookfont();
+ #ifdef KANJI	/* H.Goto */
+     extern PIX_FONT lookkfont();
+ #endif
      PR_SIZE	    tx_dim;
  
      if ((t = create_text()) == NULL)
***************
*** 502,507 ****
--- 505,514 ----
      t->zoom = zoomscale;
      t->fontstruct = lookfont(x_fontnum(psfont_text(t), t->font),
  			round(t->size*display_zoomscale));
+ #ifdef KANJI	/* H.Goto */
+     t->kfontstruct = lookkfont(x_fontnum(psfont_text(t), t->font),
+ 			round(t->size*display_zoomscale));
+ #endif
  
      if (t->font >= MAXFONT(t)) {
  	file_msg("Invalid text font (%d) at line %d, setting to DEFAULT.",
***************
*** 509,515 ****
--- 516,526 ----
  	t->font = DEFAULT;
      }
      /* now calculate the actual length and height of the string in fig units */
+ #ifdef KANJI	/* H.Goto */
+     tx_dim = textsize(t->fontstruct, t->kfontstruct, strlen(t->cstring), t->cstring);
+ #else
      tx_dim = textsize(t->fontstruct, strlen(t->cstring), t->cstring);
+ #endif
      t->length = round(tx_dim.length);
      t->ascent = round(tx_dim.ascent);
      t->descent = round(tx_dim.descent);
*** f_save.c.orig	Tue Jun 27 01:14:04 1995
--- f_save.c	Thu Oct 10 16:36:22 1996
***************
*** 306,311 ****
--- 306,314 ----
  	c = t->cstring[l];
  	if (c == '\\')
  	    fprintf(fp,"\\\\");		/* escape a '\' with another one */
+ #ifdef KANJIFIGFILE
+ 	else putc(c,fp);		/* 8-bit */
+ #else
  	else if ((unsigned int) c <= 255)
  	    putc(c,fp);			/* normal 7-bit ASCII */
  	else {
***************
*** 317,322 ****
--- 320,326 ----
  	    }
  	    fprintf(fp,"\\%s",buf);
  	}
+ #endif
      }
      fprintf(fp,"\\001\n");		/* finish off with '\001' string */
  }
