*** TEST\text_tool.c	Sat Nov  7 02:15:14 1998
--- text_tool.c	Sat Nov  7 01:53:32 1998
***************
*** 15,20 ****
--- 15,49 ----
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   */
+ /* A patch for text_tool.c 
+  *  Purpose: To set KANJI and non-KANJI font independently
+  *    FAMILY_NAME which includes a string  "mincho", "gothic"
+  *  "gyosho", "fixed" is treated as KANJI font.  
+  *    Also FAMILY_NAMEs which have prefix "vf_" are treated as KANJI 
+  *  font. 
+  * 
+  *    If you prefer to apply this patch, define '__EMX__' in Makefile
+  *  or "../config.h".
+  * 
+  *   NOTE that you must add the line "-deferglyphs all" to your
+  *  startx script to scale NON-SCALABLE KANJI fonts. 
+  * 
+  * 
+  * RECOMMENDATION:
+  *   Use X-VFlib or X-truetype server to freely scale KANJI fonts. 
+  * 
+  * 
+  *  USAGE: See text_tool_jsawa.doc
+  * 
+  * 
+  * 1998.11.03
+  *           
+  *                JUN SAWATAISHI, YOKOHAMA, JAPAN
+  *                         E-mail address
+  *                            jsawa@ibm.net
+  *                         Web page
+  *                            http://www2s.biglobe.ne.jp/~vtgf3mpr/
+  */
  #include <stdlib.h>
  #include <stdio.h>
  #include <string.h>
***************
*** 99,104 ****
--- 128,171 ----
    void *gdisp_ptr;
  };
  
+ #ifdef __EMX__
+ #define		__NO_DEFAULT_FONT  0
+ #define		__ASCII            1
+ #define		__KANJI            2
+ #define		__NOT_FONTSET     -1
+ /*
+ * Definition of default properties
+ *
+ */
+ #define		KANJI_FAMILY_0	"mincho" /* this is default family */
+ #define		KANJI_FAMILY_1	"gothic"
+ #define		KANJI_FAMILY_2	"gyosho"
+ #define		KANJI_FAMILY_3	"fixed"
+ #define		KANJI_WEIGHT		"medium"
+ #define		KANJI_SLANT			"r"
+ #define		A_FAMILY				"times"
+ #define		A_WEIGHT				"medium"
+ #define		A_SLANT					"r"
+ #define		A_SET_WIDTH			"normal"
+ 
+ static int letter_type = 3; /*  1->KANJI, 0->NonKANJI */
+ static int kanji_defined = __NO_DEFAULT_FONT;
+ static int a_defined     = __NO_DEFAULT_FONT;
+ static int use_fontset_emx = TRUE;
+ char	vfkanji_prefix[]="vf_";
+ char		kanji_family[32];
+ char		kanji_weight[10];
+ char		kanji_slant[10];
+ char		a_family[32];
+ char		a_weight[10];
+ char		a_slant[2];
+ char		a_set_width[20];
+ /* istrstr returns 0 when 'const char *s1' includes 'char *s2' 
+ *    Note that istrstr searches a string case-insensitively
+ */
+ size_t	istrstr (const char *, char *);
+ #endif /* __EMX__ */
+ 
  typedef struct _FontInfo FontInfo;
  struct _FontInfo
  {
***************
*** 210,215 ****
--- 276,294 ----
  
  static void *text_options = NULL;
  
+ #ifdef __EMX__
+ /* istrstr returns 0 when 'const char *s' includes 'char *c' 
+ *    Note that istrstr searches a string case-insensitively
+ */
+ size_t	istrstr (const char *s, char *c)
+ {
+ 	size_t nc		= strlen(c);
+ 	size_t i, n	= strlen(s);
+ 	for ( i = 0; i < n; i++ )
+ 		if ( strnicmp(s+i, c, nc) == 0 ) return 0;
+ 	return -1;
+ }
+ #endif
  Tool*
  tools_new_text ()
  {
***************
*** 234,239 ****
--- 313,321 ----
        the_text_tool->size_type = PIXELS;
        the_text_tool->antialias = 1;
        the_text_tool->use_fontset = 1;
+ #ifdef __EMX__
+        use_fontset_emx = TRUE;
+ #endif
        the_text_tool->foundry = 0;
        the_text_tool->weight = 0;
        the_text_tool->slant = 0;
***************
*** 953,963 ****
  
    text_tool = (TextTool *) data;
  
    if (GTK_TOGGLE_BUTTON (w)->active)
      text_tool->use_fontset = TRUE;
    else
      text_tool->use_fontset = FALSE;
! 
    text_load_font (text_tool);
  }
  
--- 1035,1054 ----
  
    text_tool = (TextTool *) data;
  
+ #ifdef __EMX__
+   if (GTK_TOGGLE_BUTTON (w)->active) {
+     text_tool->use_fontset = TRUE;
+      use_fontset_emx = TRUE;
+   } else {
+     text_tool->use_fontset = FALSE;
+     use_fontset_emx = FALSE;
+   }
+ #else
    if (GTK_TOGGLE_BUTTON (w)->active)
      text_tool->use_fontset = TRUE;
    else
      text_tool->use_fontset = FALSE;
! #endif
    text_load_font (text_tool);
  }
  
***************
*** 1565,1576 ****
  	  sprintf (point_size, "%d", (int) (size * 10));
  	  break;
  	}
- 
        /* create the fontname */
        sprintf (fontname, "-%s-%s-%s-%s-%s-*-%s-%s-75-75-%s-*-%s-%s",
! 	       foundry,
! 	       family,
! 	       weight,
  	       foundry,
  	       family,
  	       weight,
--- 1655,1737 ----
  	  sprintf (point_size, "%d", (int) (size * 10));
  	  break;
  	}
        /* create the fontname */
+ #ifdef __EMX__
+ 	if (kanji_defined == __NO_DEFAULT_FONT) {
+ 		if ( getenv("GIMP_KANJI") == NULL ) 
+ 			strcpy (kanji_family, KANJI_FAMILY_0);
+ 		else
+ 			strcpy(kanji_family, getenv("GIMP_KANJI"));
+ 		strcpy(kanji_weight,KANJI_WEIGHT);
+ 		strcpy(kanji_slant, KANJI_SLANT);
+ 		kanji_defined++;
+ 	}
+ 	if (a_defined == __NO_DEFAULT_FONT) {
+ 		strcpy(a_family, A_FAMILY);
+ 		strcpy(a_weight, A_WEIGHT);
+ 		strcpy(a_slant,A_SLANT);
+ 		strcpy(a_set_width, A_SET_WIDTH);
+ 		a_defined++;
+ 	}
+ 
+ /* istrstr returns 0 if 'family' includes 'KANJI_FAMILY_[0-3]'
+ *  or 'vfkanji_prefix' 
+ *    Note that istrstr searches a string case-insensitively
+ */
+ 	if ( istrstr (family, KANJI_FAMILY_0)  == 0 || 
+ 				istrstr (family, KANJI_FAMILY_1) == 0 || 
+ 				istrstr (family, KANJI_FAMILY_2) == 0 || 
+ 				istrstr (family, KANJI_FAMILY_3)  == 0 ||
+ 				strnicmp (family, vfkanji_prefix, strlen(vfkanji_prefix))==0 ) {
+ 		letter_type = __KANJI;
+ 	} else {
+ 		letter_type = __ASCII;
+ 	}
+ 	
+ 	if (!use_fontset_emx)
+ 		letter_type = __NOT_FONTSET;
+ 
+ 	switch(letter_type)
+ 	{
+ 	case __KANJI:
+ 		strcpy(kanji_family, family);
+ 		strcpy(kanji_weight, weight);
+ 		strcpy(kanji_slant, slant);
+ 		break;
+ 	case __ASCII:
+ 		strcpy(a_family, family);
+ 		strcpy(a_weight, weight);
+ 		strcpy(a_slant, slant);
+ 		strcpy(a_set_width, set_width);
+ 		break;
+ 	}
+ 
+ 	switch(letter_type)
+ 	{
+ 	case __KANJI:
+ 		sprintf (fontname, "-%s-%s-%s-%s-normal-*-%s-%s-75-75-*-*-jisx0208.1983-0," "-*-%s-%s-%s-%s-*-%s-%s-75-75-%s-*-*-*,*",
+ 			foundry, kanji_family, kanji_weight, kanji_slant,
+ 			pixel_size, point_size,
+ 			a_family, a_weight, a_slant, a_set_width, 
+ 			pixel_size, point_size, spacing);
+ 		break;
+ 	case __ASCII:
+ 		sprintf (fontname, "-%s-%s-%s-%s-%s-*-%s-%s-75-75-%s-*-%s-%s," 
+ "-*-%s-%s-%s-normal-*-%s-%s-75-75-*-*-jisx0208.1983-0,*",
+ 			foundry, a_family, a_weight, a_slant, a_set_width,
+ 			pixel_size, point_size, spacing, registry, encoding,
+ 			kanji_family, kanji_weight, kanji_slant, pixel_size, point_size);
+ 		break;
+ 	case __NOT_FONTSET:
  		sprintf (fontname, "-%s-%s-%s-%s-%s-*-%s-%s-75-75-%s-*-%s-%s",
! 			foundry, family, weight, slant, set_width,
! 			pixel_size, point_size, spacing, registry, encoding);
! 		break;
! 	}
! 
! #else /* __EMX__ */
!       sprintf (fontname, "-%s-%s-%s-%s-%s-*-%s-%s-75-75-%s-*-%s-%s,"
!                          "-*-*-*-*-%s-*-%s-%s-75-75-%s-*-*-*,*",
      foundry,
  	       family,
  	       weight,
***************
*** 1578,1584 ****
  	       set_width,
  	       pixel_size, point_size,
  	       spacing,
! 	       registry, encoding);
        return TRUE;
      }
    else
--- 1739,1747 ----
  	       set_width,
  	       pixel_size, point_size,
  	       spacing,
! 	       registry, encoding,
! 	       set_width, pixel_size, point_size, spacing);
! #endif /* __EMX__ */
        return TRUE;
      }
    else
