[kaffe] i18n patches for X AWT backend

Atsushi Nemoto anemo at mba.ocn.ne.jp
Thu Feb 26 18:33:01 PST 2004


>>>>> On Thu, 26 Feb 2004 07:43:40 +0900, Ito Kazumitsu <kaz at maczuka.gcd.org> said:
kaz> :> I found that Kaffe might not support i18n well, which is
kaz> :> really bad for handling CJK. I did primitive patches on X AWT
kaz> :> backend for i18n improvements.

kaz> I also thought Kaffe's AWT not supporting i18n was a big problem.
kaz> Thank you for your patches, and I am testing them.

kaz> My test program still does not show Japanese texts and I think I
kaz> must do more dirty things about font setting.

Just for reference, I will post a patch I'm using for kaffe 1.1.3.
With this patch I can display japanese font on Debian 3.0.

The AWT i18n patch was posted to this ML a while ago.  I found a newer
version in http://yamaguch.sytes.net/~tora/java/diary/kaffe.html
(Japanese).  My patch is based on this one.  I think Jim Huang's patch
is better than this.

Note for my patch:

1. The patch includes changes for Defaults.java.  This change is for
   Japanese.  I choose kochi-mincho font.

2. The patch includes changes for include/files.h and include/nets.h.
   This hack is needed because strerror will return multibyte string
   if setlocale was called.

3. IIRC, "-Duser.language=ja -Duser.region=JP -Dfile.encoding=EUC_JP"
   is needed when compiling java source which contains native strings.

---
Atsushi Nemoto

-------------- next part --------------
diff -ur kaffe-1.1.3.org/include/files.h kaffe-1.1.3/include/files.h
--- kaffe-1.1.3.org/include/files.h	Fri Aug  1 07:46:43 2003
+++ kaffe-1.1.3/include/files.h	Wed Dec 10 18:25:26 2003
@@ -22,7 +22,22 @@
 #endif
 
 #if defined(HAVE_STRERROR)
-#define	SYS_ERROR(x)	(char*)strerror(x)
+#include <locale.h>
+static inline char *cstrerror(int x)
+{
+	/* use "C" locale temporarily */
+	char *org = setlocale(LC_MESSAGES, NULL);
+	char *err;
+	if (strcmp(org, "C") != 0)
+		setlocale(LC_MESSAGES, "C");
+	else
+		org = NULL;
+	err = strerror(x);
+	if (org)
+		setlocale(LC_MESSAGES, org);
+	return err;
+}
+#define	SYS_ERROR(x)	cstrerror(x)
 #else
 extern char* sys_errlist[];
 #define	SYS_ERROR(x)	sys_errlist[x]
diff -ur kaffe-1.1.3.org/include/nets.h kaffe-1.1.3/include/nets.h
--- kaffe-1.1.3.org/include/nets.h	Tue Jan  7 02:14:18 2003
+++ kaffe-1.1.3/include/nets.h	Wed Dec 10 18:25:42 2003
@@ -23,7 +23,22 @@
 #define	MAXHOSTNAME	128
 
 #if defined(HAVE_STRERROR)
-#define	SYS_ERROR(x)	strerror(x)
+#include <locale.h>
+static inline char *cstrerror(int x)
+{
+	/* use "C" locale temporarily */
+	char *org = setlocale(LC_MESSAGES, NULL);
+	char *err;
+	if (strcmp(org, "C") != 0)
+		setlocale(LC_MESSAGES, "C");
+	else
+		org = NULL;
+	err = strerror(x);
+	if (org)
+		setlocale(LC_MESSAGES, org);
+	return err;
+}
+#define	SYS_ERROR(x)	cstrerror(x)
 #else
 extern char* sys_errlist[];
 #define	SYS_ERROR(x)	sys_errlist[x]
diff -ur kaffe-1.1.3.org/libraries/clib/awt/X/fnt.c kaffe-1.1.3/libraries/clib/awt/X/fnt.c
--- kaffe-1.1.3.org/libraries/clib/awt/X/fnt.c	Fri Sep 26 02:26:16 2003
+++ kaffe-1.1.3/libraries/clib/awt/X/fnt.c	Thu Dec 11 10:49:22 2003
@@ -64,6 +64,8 @@
  * adapts the AWT to your X installation/preferences. Don't lament, modify it!
  */
 
+XOC create_xoc(Toolkit *X,char *font_name);
+
 void*
 Java_java_awt_Toolkit_fntInitFont ( JNIEnv* env, jclass clazz, jstring jSpec,
                                     jint style, jint size )
@@ -71,9 +73,9 @@
   int  i, j, k, i0, i1, j0, j1, di, dj;
   char buf[160];
   char *spec = java2CString( env, X, jSpec);
-  XFontStruct* fs = 0;
-
-	size *= 10;  /* convert into X pointsizes */
+  XOC xoc = NULL;
+  
+  size *= 10;  /* convert into X pointsizes */
 
   if ( style & 0x1 ) { /* we have a Font.BOLD request */
     i0 = NWEIGHT - 1; i1 = -1; di = -1;
@@ -89,35 +91,35 @@
     j0 = 0; j1 = NSLANT; dj = 1;
   }
 
-  for ( j=j0; !fs && (j != j1); j += dj ) {
-    for ( i=i0; !fs && (i != i1); i += di ) {
-      for ( k=0;  !fs && (k < NDSIZE); k++ ) {
+  for ( j=j0; (xoc == NULL) && (j != j1); j += dj ) {
+    for ( i=i0; (xoc == NULL) && (i != i1); i += di ) {
+      for ( k=0;  (xoc == NULL) && (k < NDSIZE); k++ ) {
         sprintf( buf, spec, weight[i], slant[j], size + dsize[k]);
         DBG( AWT_FNT, printf("look up font: %s\n", buf));
-        fs = XLoadQueryFont( X->dsp, buf);
+        xoc = create_xoc( X, buf);
       }
     }
   }
 
-  if ( ! fs ){
+  if ( ! xoc ){
     /* now we are getting desperate, try the spec directly (without vars) */
-    fs = XLoadQueryFont( X->dsp, spec);
+    xoc = create_xoc( X, spec);
   }
 
-  if ( ! fs ){
+  if ( ! xoc ){
 	DBG( AWT, printf("cannot load font: %s (backup to %s)\n", buf, backupFont));
-	if ( !(fs = XLoadQueryFont( X->dsp, backupFont)) ) {
+	if ( !(xoc = create_xoc( X, backupFont)) ) {
 	  fprintf( stderr, "font panic, no default font!\n");
 	}
   }
 
-  return (void*) fs;
+  return (void*) xoc;
 }
 
 void
-Java_java_awt_Toolkit_fntFreeFont ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntFreeFont ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  XFreeFont( X->dsp, fs);
+  XDestroyOC(xoc);
 }
 
 
@@ -126,92 +128,109 @@
  */
 
 void*
-Java_java_awt_Toolkit_fntInitFontMetrics ( JNIEnv* env, jclass clazz, void* fs )
+Java_java_awt_Toolkit_fntInitFontMetrics ( JNIEnv* env, jclass clazz, void* xoc )
 {
-  return fs;
+  return xoc;
 }
 
 void
-Java_java_awt_Toolkit_fntFreeFontMetrics ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntFreeFontMetrics ( JNIEnv* env, jclass clazz, XOC xoc )
 {
 }
 
 
 jint
-Java_java_awt_Toolkit_fntGetAscent ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntGetAscent ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  return fs->ascent;
+  DBG( AWT, printf("Java_java_awt_Toolkit_fntGetAscent=%d\n",-XExtentsOfFontSet(xoc)->max_logical_extent.y));
+  return -XExtentsOfFontSet(xoc)->max_logical_extent.y;
 }
 
 jint
-Java_java_awt_Toolkit_fntGetDescent ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntGetDescent ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  return fs->descent;
+  XFontSetExtents *xfse=XExtentsOfFontSet(xoc);
+  return xfse->max_logical_extent.height-(-xfse->max_logical_extent.y); 
+  //  return fs->descent;
 }
 
 jint
-Java_java_awt_Toolkit_fntGetFixedWidth ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntGetFixedWidth ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  return (fs->min_bounds.width == fs->max_bounds.width) ? fs->max_bounds.width : 0;
-}
+  return 0;
+  /*
+  XFontSetExtents *xfse=XExtentsOfFontSet(xoc);
+  return ( xfse->max_logical_extent.width == xfse->max_ink_extent.width ) ?
+    xfse->max_logical_extent.width : 
+    0;
+*/
+}  
 
 jint
-Java_java_awt_Toolkit_fntGetHeight ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntGetHeight ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  return fs->ascent + fs->descent +1;
+   DBG( AWT, printf("Java_java_awt_Toolkit_fntGetHeight=%d\n",XExtentsOfFontSet(xoc)->max_logical_extent.height));
+   return XExtentsOfFontSet(xoc)->max_logical_extent.height;
 }
 
 jint
-Java_java_awt_Toolkit_fntGetLeading ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntGetLeading ( JNIEnv* env, jclass clazz, XOC xoc )
 {
   return 0;  /* no leading (interline spacing) for X fonts */
 }
 
 jint
-Java_java_awt_Toolkit_fntGetMaxAdvance ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntGetMaxAdvance ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  return fs->max_bounds.width;
+  return XExtentsOfFontSet(xoc)->max_logical_extent.width;
 }
 
 jint
-Java_java_awt_Toolkit_fntGetMaxAscent ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntGetMaxAscent ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  return fs->max_bounds.ascent;
+  XFontSetExtents *xfse=XExtentsOfFontSet(xoc);
+  return -xfse->max_logical_extent.y;
 }
 
 jint
-Java_java_awt_Toolkit_fntGetMaxDescent ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntGetMaxDescent ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  return fs->max_bounds.descent;
+  XFontSetExtents *xfse=XExtentsOfFontSet(xoc);
+  return xfse->max_logical_extent.height-(-xfse->max_logical_extent.y); 
 }
 
 jboolean
-Java_java_awt_Toolkit_fntIsWideFont ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntIsWideFont ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  return (fs->min_byte1 | fs->max_byte1);
+  return 2;					     
 }
 
+
 jobject
-Java_java_awt_Toolkit_fntGetWidths ( JNIEnv* env, jclass clazz, XFontStruct* fs )
+Java_java_awt_Toolkit_fntGetWidths ( JNIEnv* env, jclass clazz, XOC xoc )
 {
-  int       n = 256;
   jintArray widths;
   jint      *jw;
   jboolean isCopy;
-  register  int i, j;
+  register  int i;
+  XRectangle ink_array, logical_array;
+  XRectangle overall_ink, overall_logical;
+  wchar_t wch;
+  int num;
+
+  DBG( AWT, printf("Java_java_awt_Toolkit_fntGetWidths\n"));
 
   widths = (*env)->NewIntArray( env, 256);
   jw = (*env)->GetIntArrayElements( env, widths, &isCopy);
 
-  if ( fs->max_char_or_byte2 < n ) n = fs->max_char_or_byte2;
-
-  if ( fs->min_bounds.width == fs->max_bounds.width ) {
-	for ( i=fs->min_char_or_byte2, j=0; i < n; i++, j++ )
-	  jw[i] = fs->max_bounds.width;
-  }
-  else {
-	for ( i=fs->min_char_or_byte2, j=0; i < n; i++, j++ )
-	  jw[i] = fs->per_char[j].width;
+  for( i = 0; i < 256; i++ ) {
+    wch = i;
+    if(!XwcTextPerCharExtents(xoc ,&wch ,1 ,&ink_array, &logical_array, 1,
+			  &num,&overall_ink, &overall_logical )){
+    fprintf(stderr, __FILE__ "(%d)"
+	    "):" "XwcTextPerCharExtents Error\n",__LINE__ );
+    }
+    jw[i] = overall_logical.width;
   }
 
   (*env)->ReleaseIntArrayElements( env, widths, jw, 0);
@@ -222,79 +241,147 @@
 
 jint
 Java_java_awt_Toolkit_fntBytesWidth ( JNIEnv* env, jclass clazz,
-	XFontStruct* fs, jbyteArray jBytes, jint off, jint len )
+	XOC xoc, jbyteArray jBytes, jint off, jint len )
 {
   jboolean  isCopy;
   jbyte    *jb = (*env)->GetByteArrayElements( env, jBytes, &isCopy);
   int       n = (*env)->GetArrayLength( env, jBytes);
-  int       w;
+  wchar_t   *wch;
+  XRectangle *ink_array, *logical_array;
+  XRectangle overall_ink, overall_logical;
+  int num;
+
+  DBG( AWT,printf("Java_java_awt_Toolkit_fntBytesWidth\n"));
 
   if ( off+len > n ) len = n - off;
 
-  w = XTextWidth( fs, jb+off, len);
+  wch = jbyte2wchar( jb + off, len );
+  ink_array = (XRectangle *)malloc(sizeof(XRectangle)*len);
+  logical_array = (XRectangle *)malloc(sizeof(XRectangle)*len);
+
+  if(!XwcTextPerCharExtents(xoc ,wch ,len ,ink_array,logical_array, len,
+			&num,&overall_ink ,&overall_logical)){
+    fprintf(stderr, __FILE__ "(%d)"
+	    "):" "XwcTextPerCharExtents Error\n",__LINE__ );
+  }
+
+  free( (void *)logical_array );
+  free( (void *)ink_array );
+  free( (void *)wch );
 
   (*env)->ReleaseByteArrayElements( env, jBytes, jb, JNI_ABORT);
-  return w;
+  
+  return overall_logical.width;
 }
 
 jint
-Java_java_awt_Toolkit_fntCharWidth ( JNIEnv* env, jclass clazz, XFontStruct* fs, jchar jChar )
+Java_java_awt_Toolkit_fntCharWidth ( JNIEnv* env, jclass clazz, XOC xoc, jchar jChar )
 {
-#ifndef WORDS_BIGENDIAN
-  jChar = (jChar << 8) | (jChar >> 8);
-#endif
+    wchar_t wch;
+    XRectangle ink_array, logical_array;
+    XRectangle overall_ink, overall_logical;
+    int num;
+    
+    wch = jChar;
+    if(!XwcTextPerCharExtents(xoc ,&wch ,1 ,&ink_array, &logical_array,
+			  1,
+			  &num, &overall_ink, &overall_logical)){
+    fprintf(stderr, __FILE__ "(%d)"
+	    "):" "XwcTextPerCharExtents Error\n",__LINE__ );
+    }
 
-  return XTextWidth16( fs, (XChar2b*)&jChar, 1);
+    return overall_logical.width;
 }
 
 jint
 Java_java_awt_Toolkit_fntCharsWidth ( JNIEnv* env, jclass clazz,
-	XFontStruct* fs, jcharArray jChars, jint off, jint len )
+	XOC xoc, jcharArray jChars, jint off, jint len )
 {
   jboolean  isCopy;
   jchar    *jc = (*env)->GetCharArrayElements( env, jChars, &isCopy);
   int      n = (*env)->GetArrayLength( env, jChars);
-  XChar2b  *b;
-  int      w;
+  wchar_t  *wch;
+  XRectangle *ink_array, *logical_array;
+  XRectangle overall_ink, overall_logical;
+  int num;
+
+  DBG( AWT, printf("Java_java_awt_Toolkit_fntCharsWidth\n"));
 
   if ( off+len > n ) len = n - off;
 
-#ifndef WORDS_BIGENDIAN
-  n = sizeof(XChar2b)*len;
-  b = (XChar2b*) getBuffer( X, n);
-  swab( (jc+off), b, n);
-#else
-  b = (XChar2b*) (jc + off);
-#endif
+  wch = jchar2wchar( jc + off, len );
+  ink_array = (XRectangle *)malloc(sizeof(XRectangle)*len);
+  logical_array = (XRectangle *)malloc(sizeof(XRectangle)*len);
+
+  if(!XwcTextPerCharExtents(xoc ,wch ,len ,ink_array,logical_array, len,
+			   &num,&overall_ink ,&overall_logical)){
+    fprintf(stderr, __FILE__ "(%d)"
+	    "):" "XwcTextPerCharExtents Error\n",__LINE__ );
+  }
 
-  w = XTextWidth16( fs, b, len);
+  free( (void *)logical_array );
+  free( (void *)ink_array );
+  free( (void *)wch );
 
   (*env)->ReleaseCharArrayElements( env, jChars, jc, JNI_ABORT);
-  return w;
+  return overall_logical.width;
 }
 
 jint
-Java_java_awt_Toolkit_fntStringWidth ( JNIEnv* env, jclass clazz, XFontStruct* fs, jstring jStr )
+Java_java_awt_Toolkit_fntStringWidth ( JNIEnv* env, jclass clazz, XOC xoc, jstring jStr )
 {
   jboolean isCopy;
   const jchar    *jc = (*env)->GetStringChars( env, jStr, &isCopy);
   int      len = (*env)->GetStringLength( env, jStr);
-  int      w;
-#ifndef WORDS_BIGENDIAN
-  int      n;
-#endif
-  XChar2b  *b;
-
-#ifndef WORDS_BIGENDIAN
-  n = sizeof(XChar2b)*len;
-  b = (XChar2b*) getBuffer( X, n);
-  swab( jc, b, n);
-#else
-  b = (XChar2b*) jc;
-#endif
-
-  w = XTextWidth16( fs, b, len);
+  wchar_t  *wch;  
+  XRectangle *ink_array, *logical_array;
+  XRectangle overall_ink, overall_logical;
+  int num=len;
+  
+  wch = jchar2wchar( jc, len );
+  ink_array = (XRectangle *)malloc(sizeof(XRectangle)*len);
+  logical_array = (XRectangle *)malloc(sizeof(XRectangle)*len);
+
+  if(!XwcTextPerCharExtents(xoc ,wch ,len ,ink_array,logical_array, len,
+			    &num,&overall_ink ,&overall_logical)){
+    fprintf(stderr, __FILE__ "(%d)"
+	    "):" "XwcTextPerCharExtents Error\n",__LINE__ );
+  }
 
+  free( (void *)logical_array );
+  free( (void *)ink_array );
+  free( (void *)wch );
+ 
   (*env)->ReleaseStringChars( env, jStr, jc);
-  return w;
+
+  return overall_logical.width;
+}
+
+
+XOC create_xoc(Toolkit *X,char *font_name){
+  XOC xoc;
+  int i;
+  char **missing_list;
+  int missing_count;
+  char *def_string;
+
+  xoc = XCreateOC(X->xom,
+		 XNBaseFontName, font_name,
+		 NULL);
+  if (xoc) {
+    XGetOCValues(xoc, 
+		 XNMissingCharSet, &missing_count,
+		 XNRequiredCharSet, &missing_list,
+		 XNDefaultString, &def_string,
+		 NULL);
+    if( missing_count!=0 ){
+      fprintf(stderr, "missing list exists at %s.\n" ,font_name);
+      for (i = 0; i < missing_count; i++) {
+	fprintf(stderr, "missing list[%d]: %s\n", i, missing_list[i]);
+      }
+    }
+  } else {
+    fprintf(stderr, "XCreateOC error at %s.\n" ,font_name);
+  }
+  return xoc;
 }
diff -ur kaffe-1.1.3.org/libraries/clib/awt/X/gra.c kaffe-1.1.3/libraries/clib/awt/X/gra.c
--- kaffe-1.1.3.org/libraries/clib/awt/X/gra.c	Fri Sep 26 02:26:16 2003
+++ kaffe-1.1.3/libraries/clib/awt/X/gra.c	Thu Dec 11 10:49:22 2003
@@ -13,6 +13,7 @@
 typedef struct {
   GC        gc;
   Drawable  drw;
+  XOC       oc;
   int       fg;
   int       bg;
   char      xor;
@@ -40,7 +41,7 @@
   Drawable       drw;
   XGCValues      values;
   XRectangle     rect;
-  unsigned long  valueMask = GCForeground | GCBackground | GCFont | GCFunction;
+  unsigned long  valueMask = GCForeground | GCBackground | GCFunction;
 
   DBG( AWT_GRA, printf("initGraphics: %p (%p, %d) %d,%d  %d,%d - %d,%d  %p %x %x\n",
 				 gr, tgt,tgtType, xOff,yOff, xClip,yClip,wClip,hClip, fnt,fg,bg));
@@ -65,9 +66,10 @@
 
   values.foreground = fg;
   values.background = bg;
-  values.font       = ((XFontStruct*)fnt)->fid;
+
+/*  values.font       = ((XFontStruct*)fnt)->fid;*/
   values.function   = GXcopy;
-  
+ 
   if ( gr ) {
 	XChangeGC( X->dsp, gr->gc, valueMask, &values);
   }
@@ -90,6 +92,7 @@
   gr->x0   = xOff;
   gr->y0   = yOff;
   gr->xor  = 0;
+  gr->oc   = fnt;
 
   if ( blank ) {
 	XSetForeground( X->dsp, gr->gc, gr->bg);
@@ -148,6 +151,7 @@
   jboolean isCopy;
   int      n;
   jbyte    *jb, *jbo;
+  wchar_t *wch;
 
   if ( !jBytes ) return;
 
@@ -161,7 +165,11 @@
   if ( offset+len > n )
 	len = n - offset;
 
-  XDrawString( X->dsp, gr->drw, gr->gc, x+gr->x0, y+gr->y0, jbo, len);
+  wch = jbyte2wchar( jbo, len );
+
+  XwcDrawString( X->dsp, gr->drw, gr->oc, gr->gc, x+gr->x0, y+gr->y0, wch,len);
+
+  free((void*) wch);
 
   (*env)->ReleaseByteArrayElements( env, jBytes, jb, JNI_ABORT);
   XFLUSH( X, False);
@@ -175,7 +183,7 @@
   jboolean isCopy;
   int      n;
   jchar    *jc, *jco;
-  XChar2b  *b;
+  wchar_t *wch;
 
   if ( !jChars ) return;
 
@@ -189,15 +197,11 @@
   if ( offset+len > n )
 	len = n - offset;
 
-#ifndef WORDS_BIGENDIAN
-  n = sizeof(XChar2b)*len;
-  b = (XChar2b*) getBuffer( X, n);
-  swab( (void*)jco, (void*)b, n);
-#else
-  b = (XChar2b*) jco;
-#endif
+  wch = jchar2wchar( jco, len );
 
-  XDrawString16( X->dsp, gr->drw, gr->gc, x+gr->x0, y+gr->y0, b, len);  
+  XwcDrawString( X->dsp, gr->drw, gr->oc, gr->gc, x+gr->x0, y+gr->y0, wch,len); 
+
+  free((void*) wch);
 
   (*env)->ReleaseCharArrayElements( env, jChars, jc, JNI_ABORT);
   XFLUSH( X, False);
@@ -210,11 +214,8 @@
 {
   jboolean     isCopy;
   int          len;
-#ifndef WORDS_BIGENDIAN
-  int n;
-#endif
   const jchar  *jc;
-  XChar2b      *b;
+  wchar_t *wch;
 
   DBG( AWT_GRA, printf("drawString: %p  \"%s\"  %d,%d\n", gr, java2CString(env,X,str), x,y));
 
@@ -223,15 +224,10 @@
   len = (*env)->GetStringLength( env, str);
   jc = (*env)->GetStringChars( env, str, &isCopy);
 
-#ifndef WORDS_BIGENDIAN
-  n = sizeof(XChar2b)*len;
-  b = (XChar2b*) getBuffer( X, n);
-  swab( jc, b, n);
-#else
-  b = (XChar2b*) jc;
-#endif
 
-  XDrawString16( X->dsp, gr->drw, gr->gc, x+gr->x0, y+gr->y0, b, len);  
+  wch = jchar2wchar( jc, len );
+  XwcDrawString( X->dsp, gr->drw, gr->oc, gr->gc, x+gr->x0, y+gr->y0, wch,len);
+  free( (void *)wch );
 
   (*env)->ReleaseStringChars( env, str, jc);
   XFLUSH( X, False);
@@ -590,8 +586,7 @@
 Java_java_awt_Toolkit_graSetFont ( JNIEnv* env, jclass clazz, Graphics* gr, jobject fnt )
 {
   DBG( AWT_GRA, printf("setFont: %p, %p\n", gr, fnt));
-
-  XSetFont( X->dsp, gr->gc, ((XFontStruct*)fnt)->fid);
+  gr->oc=(XOC)fnt;
 }
 
 void
diff -ur kaffe-1.1.3.org/libraries/clib/awt/X/tlk.c kaffe-1.1.3/libraries/clib/awt/X/tlk.c
--- kaffe-1.1.3.org/libraries/clib/awt/X/tlk.c	Tue Jan  7 02:14:25 2003
+++ kaffe-1.1.3/libraries/clib/awt/X/tlk.c	Thu Dec 11 10:49:22 2003
@@ -13,6 +13,7 @@
 
 #include "toolkit.h"
 #include "tlkprops.h"
+#include "locale.h"
 
 /********************************************************************************
  * auxiliary functions
@@ -80,6 +81,12 @@
 Java_java_awt_Toolkit_tlkInit ( JNIEnv* env, jclass clazz, jstring name )
 {
   char    *dspName;
+  /* for X Output Method */
+  int i;
+  Bool direction;
+  Bool contextdrawing;
+  XOMCharSetList cslist;
+  XOMOrientation orientation;
 
   getBuffer(X, 128);
 
@@ -139,6 +146,28 @@
   RETRY_FOCUS      = XInternAtom( X->dsp, "RETRY_FOCUS", False);
   FORWARD_FOCUS    = XInternAtom( X->dsp, "FORWARD_FOCUS", False);
 
+  /* Open  X Output Method */
+  setlocale(LC_ALL ,"");
+
+  X->xom = XOpenOM(X->dsp, NULL, NULL, NULL);
+  if (X->xom) {
+    DBG( AWT, printf("locale of XOM: %s\n", XLocaleOfOM(X->xom)));
+    XGetOMValues(X->xom,
+		 XNRequiredCharSet, &cslist,
+		 XNQueryOrientation, &orientation,
+		 XNDirectionalDependentDrawing, &direction
+		 ,
+		 XNContextualDrawing, &contextdrawing,
+		 NULL);
+    
+    /* We could create fontset list from these. */
+      for (i = 0; i < cslist.charset_count; i++) {
+	DBG( AWT, printf("needed charset[%d]: %s\n", i, cslist.charset_list[i]));
+      }
+  } else {
+    fprintf(stderr ,"XOpenOM error\n");
+  }
+
   return JNI_TRUE;
 }
 
diff -ur kaffe-1.1.3.org/libraries/clib/awt/X/toolkit.h kaffe-1.1.3/libraries/clib/awt/X/toolkit.h
--- kaffe-1.1.3.org/libraries/clib/awt/X/toolkit.h	Tue Jan 14 08:27:53 2003
+++ kaffe-1.1.3/libraries/clib/awt/X/toolkit.h	Fri Dec 12 19:49:50 2003
@@ -191,6 +191,7 @@
   Window         focus;     /* this is the real focus, if it is in our process */
   Window         focusFwd;  /* this might be a (owned) window we forward the focus to */
   int            fwdIdx;    /* cached index of the focus forward window */
+  XOM            xom;       /* X Output Method */
 } Toolkit;
 
 
@@ -330,6 +331,20 @@
   return X->buf;
 }
 
+static __inline__ wchar_t* jchar2wchar( const jchar *jc, int len ) {
+  int i;
+  wchar_t *wch = (wchar_t *)malloc(sizeof(wchar_t)*len);
+  for( i=0; i < len; i++ ) wch[i] = jc[i];
+  return wch;
+}
+
+static __inline__ wchar_t* jbyte2wchar( jbyte *jc, int len ) {
+  int i;
+  wchar_t *wch = (wchar_t *)malloc(sizeof(wchar_t)*(len));
+  for( i=0; i < len; i++ ) wch[i] = jc[i];
+  return wch;
+}
+
 
 /*****************************************************************************************
  * color functions & defines
diff -ur kaffe-1.1.3.org/libraries/javalib/java/awt/Defaults.java kaffe-1.1.3/libraries/javalib/java/awt/Defaults.java
--- kaffe-1.1.3.org/libraries/javalib/java/awt/Defaults.java	Fri Jan  4 14:12:19 2002
+++ kaffe-1.1.3/libraries/javalib/java/awt/Defaults.java	Wed Dec 10 18:51:29 2003
@@ -424,13 +424,13 @@
 		String fntCat = Integer.toString(res) + '-' + res + "-*-*-*-*";
 
 		//FsDefault = "-b&h-lucida-%s-%s-*-*-*-%d-" + fntCat;
-		FsDefault = "-adobe-helvetica-%s-%s-*-*-*-%d-"  + fntCat;
-		FsMonospaced = "-adobe-courier-%s-%s-*-*-*-%d-" + fntCat;
-		FsSansSerif = "-adobe-helvetica-%s-%s-*-*-*-%d-" + fntCat;
-		FsSerif = "-adobe-times-%s-%s-*-*-*-%d-" + fntCat;
-		FsDialog = "-misc-fixed-%s-%s-*-*-*-%d-" + fntCat;
-		FsDialogInput = "-b&h-lucidatypewriter-%s-%s-*-*-*-%d-" + fntCat;
-		FsZapfDingbats = "-adobe-new century schoolbook-%s-%s-*-*-*-%d-" + fntCat;
+		FsDefault = "-kochi-mincho-%s-%s-normal--*-%d-"  + fntCat;
+		FsMonospaced = "-kochi-mincho-%s-%s-normal--*-%d-" + fntCat;
+		FsSansSerif = "-kochi-mincho-%s-%s-normal--*-%d-" + fntCat;
+		FsSerif = "-kochi-mincho-%s-%s-normal--*-%d-" + fntCat;
+		FsDialog = "-kochi-mincho-%s-%s-normal--*-%d-" + fntCat;
+		FsDialogInput = "-kochi-mincho-%s-%s-normal--*-%d-" + fntCat;
+		FsZapfDingbats = "-kochi-mincho-%s-%s-normal--*-%d-" + fntCat;
 	}
 	else {
 		// no idea, we have to leave it for the native layer


More information about the kaffe mailing list