diff -u gplt_x11.c.ORG gplt_x11.c
--- gplt_x11.c.ORG	Sun Jan  9 15:24:29 2005
+++ gplt_x11.c	Sun Jan 23 00:55:54 2005
@@ -5,6 +5,8 @@
 #define X11_POLYLINE 1
 #define MOUSE_ALL_WINDOWS 1
 
+#define USEXMULTIBYTE
+
 /* GNUPLOT - gplt_x11.c */
 
 /*[
@@ -130,6 +132,9 @@
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
 #include <X11/keysym.h>
+#ifdef USEXMULTIBYTE
+# include <X11/Xlocale.h>
+#endif
 
 #ifdef PM3D
 # include <math.h>		/* pow() */
@@ -461,6 +466,19 @@
 #endif
 
 static char *FallbackFont = "fixed";
+#ifdef USEXMULTIBYTE
+# define FallbackFontMB "mbfont:*-medium-r-normal--14-*,*-medium-r-normal--16-*"
+static int gpXTextWidth __PROTO((const char *,int));
+static int gpXTextHeight __PROTO((void));
+static void gpXSetFont __PROTO((Display *,GC));
+static void gpXDrawImageString __PROTO((Display *,Drawable,GC,int,const char *,int));
+static void gpXDrawString __PROTO((Display *,Drawable,GC,int,int,const char *,int));
+static void gpXFreeFont __PROTO((Display *));
+static int gpXLoadQueryFont __PROTO((Display *,char *));
+static int fontset_ascent __PROTO((XFontSet font));
+static int usemultibyte = 0;
+static int usablemb=1;
+#endif /* USEXMULTIBYTE */
 enum set_encoding_id encoding = S_ENC_DEFAULT; /* EAM - mirrored from core code by 'QE' */
 static char default_font[64] = { '\0' };
 
@@ -519,7 +537,10 @@
 static GC gc_xor = (GC) 0;
 static GC gc_xor_dashed = (GC) 0;
 static GC fill_gc = (GC) 0;
-static XFontStruct *font;
+static XFontStruct *font = NULL;
+#ifdef USEXMULTIBYTE
+static XFontSet mbfont = NULL;
+#endif
 /* must match the definition in term/x11.trm: */
 /* FIXME HBB 20020225: that really should be ensured by sharing a common
  * header file between this file and term/x11.trm! */
@@ -662,6 +683,10 @@
     fcloseall();
 #endif
 
+#ifdef USEXMULTIBYTE
+    if (setlocale(LC_ALL, "")==NULL || XSupportsLocale()==False)
+      usablemb=0;
+#endif /* USEXMULTIBYTE */
     preset(argc, argv);
 
 /* set up the alternative cursor */
@@ -1730,7 +1755,11 @@
     int x, y;
     double src_x, src_y;
     double dest_x, dest_y;
+#ifndef USEXMULTIBYTE
     int width = XTextWidth(font, str, len);
+#else
+    int width = gpXTextWidth(str, len);
+#endif
     int height = vchar;
     double src_cen_x = (double)width * 0.5;
     double src_cen_y = (double)height * 0.5;
@@ -1775,11 +1804,16 @@
 	XSetBackground(dpy, bitmapGC, 0);
     }
 
+#ifndef USEXMULTIBYTE
     /* set font for the bitmap GC */
     XSetFont(dpy, bitmapGC, font->fid);
 
     /* draw string to the source bitmap */
     XDrawImageString(dpy, pixmap_src, bitmapGC, 0, font->ascent, str, len);
+#else
+    gpXSetFont(dpy, bitmapGC);
+    gpXDrawImageString(dpy, pixmap_src, bitmapGC, 0, str, len);
+#endif
 
     /* create XImage's of depth 1 */
     /* source from pixmap */
@@ -1938,7 +1972,11 @@
 		c = &(buffer[strlen(buffer)-1]);
 		while (*c <= ' ') *c-- = '\0';
 	    	pr_font(&buffer[2]);
+#ifndef USEXMULTIBYTE
 		XSetFont(dpy,gc,font->fid);
+#else
+		gpXSetFont(dpy,gc);
+#endif
 		break;
 	case 'E':
 		/* Save the requested font encoding */
@@ -2012,7 +2050,11 @@
 	}
 
 	sl = strlen(str) - 1;
+#ifndef USEXMULTIBYTE
 	sw = XTextWidth(font, str, sl);
+#else
+	sw = gpXTextWidth(str, sl);
+#endif
 
 /*	EAM - May 2002 	Modify to allow colored text.
  *	1) do not force foreground of gc to be black
@@ -2042,8 +2084,13 @@
 	    DrawRotated(plot, dpy, *current_gc, X(x), Y(y), str, sl);
 	} else {
 	    /* horizontal text */
+#ifndef USEXMULTIBYTE
 	    XDrawString(dpy, plot->pixmap, *current_gc,
 		    X(x) + sj, Y(y) + v_offset, str, sl);
+#else
+	    gpXDrawString(dpy, plot->pixmap, *current_gc,
+			  X(x) + sj, Y(y) + v_offset, str, sl);
+#endif
 	}
 
 	/* Update current text position */
@@ -3089,7 +3136,11 @@
 
     gc = XCreateGC(dpy, plot->pixmap, 0, (XGCValues *) 0);
 
+#ifndef USEXMULTIBYTE
     XSetFont(dpy, gc, font->fid);
+#else
+    gpXSetFont(dpy, gc);
+#endif
 #if USE_ULIG_FILLEDBOXES
     XSetFillStyle(dpy, gc, FillSolid);
 
@@ -3169,7 +3220,11 @@
 	if (gc)
 	    XFreeGC(dpy, gc);
 	gc = XCreateGC(dpy, plot->pixmap, 0, (XGCValues *) 0);
+#ifndef USEXMULTIBYTE
 	XSetFont(dpy, gc, font->fid);
+#else
+	gpXSetFont(dpy, gc);
+#endif
 	/* set pixmap background */
 	XSetForeground(dpy, gc, plot->cmap->colors[0]);
 	XFillRectangle(dpy, plot->pixmap, gc, 0, 0, plot->width, PIXMAP_HEIGHT(plot) + vchar);
@@ -3648,18 +3703,31 @@
     int xwidth, ywidth;
 
     xlen = strlen(xstr);
+#ifndef USEXMULTIBYTE
     xwidth = XTextWidth(font, xstr, xlen);
+#else
+    xwidth = gpXTextWidth(xstr, xlen);
+#endif
 
     ylen = strlen(ystr);
+#ifndef USEXMULTIBYTE
     ywidth = XTextWidth(font, ystr, ylen);
+#else
+    ywidth = gpXTextWidth(ystr, ylen);
+#endif
 
     /* horizontal centering disabled (joze) */
 
     if (!gc_xor) {
 	GetGCXor(plot, &gc_xor);
     }
+#ifndef USEXMULTIBYTE
     XDrawString(dpy, plot->window, gc_xor, x, y - 3, xstr, xlen);
     XDrawString(dpy, plot->window, gc_xor, x, y + vchar, ystr, ylen);
+#else
+    gpXDrawString(dpy, plot->window, gc_xor, x, y - 3, xstr, xlen);
+    gpXDrawString(dpy, plot->window, gc_xor, x, y + vchar, ystr, ylen);
+#endif
 }
 
 /* returns the time difference to the last click in milliseconds */
@@ -3719,9 +3787,20 @@
 
     values.foreground = AllocateXorPixel(plot->cmap);
 
+#ifndef USEXMULTIBYTE
     mask = GCForeground | GCFunction | GCFont;
     values.function = GXxor;
     values.font = font->fid;
+#else
+    if (!usemultibyte) { 
+	mask = GCForeground | GCFunction | GCFont;
+	values.function = GXxor;
+	values.font = font->fid;
+    } else {
+	mask = GCForeground | GCFunction;
+	values.function = GXxor;
+    }
+#endif
 
     *ret = XCreateGC(dpy, plot->window, mask, &values);
 }
@@ -3833,7 +3912,12 @@
     }
 
     if (str[0] != 0)
+#ifndef USEXMULTIBYTE
 	XDrawString(dpy, plot->window, gc_xor, 1, plot->gheight + vchar - 1, str, strlen(str));
+#else
+        gpXDrawString(dpy, plot->window, gc_xor, 1, 
+		      plot->gheight + vchar - 1, str, strlen(str));
+#endif
 }
 
 
@@ -5091,6 +5175,99 @@
  *   pr_font - determine font
  *---------------------------------------------------------------------------*/
 
+#ifdef USEXMULTIBYTE
+/* wrapper functions */
+int gpXTextWidth (const char *str,int count)
+{
+    if (!usemultibyte) return XTextWidth(font,str,count);
+    else return XmbTextEscapement(mbfont,str,count);
+}
+
+int gpXTextHeight (void)
+{
+    static XFontSetExtents *extents;
+
+    extents = XExtentsOfFontSet(mbfont);
+
+    if (!usemultibyte) return font->ascent + font->descent;
+    else return extents->max_logical_extent.height;
+}
+
+void gpXSetFont (Display *disp,GC gc)
+{
+    if (!usemultibyte) XSetFont(disp,gc,font->fid);
+}
+
+void gpXDrawImageString (Display *disp,Drawable d,GC gc,int x,
+			 const char *str,int len)
+{
+    if (!usemultibyte) XDrawImageString(disp,d,gc,x,font->ascent,str,len);
+    else XmbDrawImageString(disp,d,mbfont,gc,x,fontset_ascent(mbfont),str,len);
+}
+
+void gpXDrawString (Display *disp,Drawable d,GC gc,int x,int y,
+		    const char *str,int len)
+{
+    if (!usemultibyte) XDrawString(disp,d,gc,x,y,str,len);
+    else XmbDrawString(disp,d,mbfont,gc,x,y,str,len);
+}
+
+void gpXFreeFont(Display *disp)
+{
+    if (font) {
+	XFreeFont(disp, font);
+	font=NULL;
+    }
+    if (mbfont) {
+	XFreeFontSet(disp, mbfont);
+	mbfont=NULL;
+    }
+}
+
+int gpXLoadQueryFont (Display *disp,char *fontname)
+{
+    static char **miss, *def;
+    int n_miss;
+    
+    if (!usemultibyte)
+      return ((font=XLoadQueryFont(disp, fontname))!=NULL);
+    else {
+	mbfont = XCreateFontSet(disp, fontname, &miss, &n_miss, &def);
+	if (n_miss>0) {
+	    if (mbfont) {
+		XFreeFontSet(disp, mbfont);
+		mbfont=NULL;
+	    }
+	    XFreeStringList(miss);
+	}
+	return (mbfont!=NULL);
+    }
+}
+
+int fontset_ascent(XFontSet fontset)
+{
+    static XFontStruct **fonts;
+    char **fontnames;
+    int max_ascent = 0;
+    int i, n_fonts;
+
+    n_fonts = XFontsOfFontSet(fontset, &fonts, &fontnames);
+    for (i = 0; i < n_fonts; i++) {
+	if (fonts[i]->ascent > max_ascent)
+	  max_ascent = fonts[i]->ascent;
+    }
+    return max_ascent;
+}
+
+char *gpFallbackFont(void)
+{
+    if (!usemultibyte) 
+      return FallbackFont;
+    else
+      return FallbackFontMB;
+}
+#endif
+
 static void
 pr_font( fontname )
 char *fontname;
@@ -5098,6 +5275,9 @@
     static char previous_font_name[128];
     char fontspec[128];
     int  fontsize = 0;
+#ifdef USEXMULTIBYTE
+    char *orgfontname = NULL;
+#endif
 
     if (!fontname || !(*fontname))
 	fontname = default_font;
@@ -5109,22 +5289,53 @@
 		    fontname));
     }
 
+#ifndef USEXMULTIBYTE
     if (!fontname)
 	fontname = FallbackFont;
+#else
+    if (fontname && strncmp(fontname,"mbfont:",7) == 0) {
+	if (usablemb) {
+	    usemultibyte = 1;
+	    orgfontname = fontname;
+	    fontname = &fontname[7];
+	} else {
+	    usemultibyte=0;
+	    fontname=NULL;
+	}
+    } else usemultibyte=0;
+
+    if (!fontname)
+      fontname = gpFallbackFont();
+#endif
 
     /* EAM DEBUG - Free previous font before searching for a new one. */
     /* This doesn't seem right, since we will probably need it again  */
     /* very soon. But if we don't free it, we gradually leak memory.  */
+#ifndef USEXMULTIBYTE
     if (font)
 	XFreeFont(dpy, font);
-	
+#else
+    gpXFreeFont(dpy);
+#endif /* USEXMULTIBYTE */
+
+#ifndef USEXMULTIBYTE
     font = XLoadQueryFont(dpy, fontname);
+#else
+    gpXLoadQueryFont(dpy,fontname);
+#endif
 
+#ifndef USEXMULTIBYTE
     if (!font) {
+#else
+    if (!font && !mbfont) {
+#endif
 	/* EAM 19-Aug-2002 Try to construct a plausible X11 full font spec */
 	/* We are passed "font<,size><,slant>"                             */
 	char shortname[64], *fontencoding, slant, *weight;
 	int  sep;
+#ifdef USEXMULTIBYTE
+	int backfont = 0;
+#endif
 
 	/* Enhanced font processing wants a method of requesting a new size  */
 	/* for whatever the previously selected font was, so we have to save */
@@ -5132,10 +5343,24 @@
 	if (!strncmp(fontname,"DEFAULT",7)) {
 	    sscanf(&fontname[8],"%d",&fontsize);
 	    fontname = default_font;
+#ifdef USEXMULTIBYTE
+	    backfont = 1;
+#endif
 	} else if (*fontname == ',') {
 	    sscanf(&fontname[1],"%d",&fontsize);
 	    fontname = previous_font_name;
+#ifdef USEXMULTIBYTE
+	    backfont = 1;
+#endif
+	}
+#ifdef USEXMULTIBYTE
+	if (backfont && fontname && strncmp(fontname,"mbfont:",7) == 0
+	    && usablemb) {
+	    usemultibyte = 1;
+	    orgfontname = fontname;
+	    fontname = &fontname[7];
 	}
+#endif
 
 	sep = strcspn(fontname,",");
 	if (sep >= sizeof(shortname))
@@ -5157,6 +5382,10 @@
 
 	if (!strncmp("Symbol",shortname,6) || !strncmp("symbol",shortname,6))
 	    fontencoding = "*-*";
+#ifdef USEXMULTIBYTE
+	else if (usemultibyte)
+	    fontencoding = "*-*";
+#endif
 	else
 	    fontencoding = (
 		encoding == S_ENC_CP437     ? "dosencoding-cp437" :
@@ -5171,9 +5400,17 @@
 	sprintf(fontspec, "-*-%s-%s-%c-*-*-%d-*-*-*-*-*-%s",
 		shortname, weight, slant, fontsize, fontencoding
 		);
+#ifndef USEXMULTIBYTE
 	font = XLoadQueryFont(dpy, fontspec);
+#else
+	gpXLoadQueryFont(dpy,fontspec);
+#endif
 
+#ifndef USEXMULTIBYTE
 	if (!font) {
+#else
+	if (!font && !mbfont) {
+#endif
 	    /* Try to decode some common PostScript font names */
 	    if (!strcmp("Times-Bold",shortname) || !strcmp("times-bold",shortname)) {
 		sprintf(fontspec,
@@ -5200,12 +5437,42 @@
 		sprintf(fontspec,
 			"-*-arial narrow-bold-r-*-*-%d-*-*-*-*-*-%s", fontsize, fontencoding);
 	    }
+#ifdef USEXMULTIBYTE
+	    /* Japanese standard PostScript font names */
+	    else if (usablemb && (!strcmp("Ryumin-Light",shortname) || !strcmp("ryumin-light",shortname))) {
+		usemultibyte = 1;
+		orgfontname = fontname;
+		sprintf(fontspec,"-*-mincho-medium-%c-*--%d-*", slant,fontsize);
+	    } 
+	    else if (usablemb && (!strcmp("GothicBBB-Medium",shortname) || !strcmp("gothicbbb-medium",shortname))) {
+		usemultibyte = 1;
+		orgfontname = fontname;
+		sprintf(fontspec,"-*-gothic-bold-%c-*--%d-*", slant,fontsize);
+	    }
+#endif
+#ifndef USEXMULTIBYTE
 	    font = XLoadQueryFont(dpy, fontspec);
+#else
+	    gpXLoadQueryFont(dpy,fontspec);
+	    if (usemultibyte && !mbfont) {
+		/* But (mincho|gothic) X fonts are not provided 
+		 * on some X servers even in Japan
+		 */
+		sprintf(fontspec,"*-%s-%c-*--%d-*", weight,slant,fontsize);
+		gpXLoadQueryFont(dpy,fontspec);
+	    }
+#endif
 	}
 
     }
 
+#ifndef USEXMULTIBYTE
     if (font) {
+#else
+    if (font || mbfont) {
+	if (usemultibyte && orgfontname)
+	  fontname = orgfontname;
+#endif
         strncpy(previous_font_name, fontname, sizeof(previous_font_name)-1);
         FPRINTF((stderr,"gnuplot_x11:saving current font name \"%s\"\n",previous_font_name));
     }
@@ -5213,7 +5480,11 @@
     /* By now we have tried everything we can to honor the specific request. */
     /* Try some common scaleable fonts before falling back to a last resort  */
     /* fixed font.                                                           */
+#ifndef USEXMULTIBYTE
     if (!font) {
+#else
+    if (!usemultibyte && !font) {
+#endif
 	sprintf(fontspec, "-*-bitstream vera sans-bold-r-*-*-%d-*-*-*-*-*-*-*", fontsize);
 	font = XLoadQueryFont(dpy, fontspec);
 	fontname = fontspec;
@@ -5235,9 +5506,28 @@
 	}
 	FPRINTF((stderr, "\ngnuplot_x11: requested font not found, using '%s' instead.\n", fontname));
     }
+#ifdef USEXMULTIBYTE
+    if (usemultibyte && !mbfont) { /* multibyte font setting */
+	gpXLoadQueryFont(dpy, gpFallbackFont());
+	if (!mbfont) {
+	    usemultibyte=0;
+	    gpXLoadQueryFont(dpy, FallbackFont);
+	    fontname = FallbackFont;
+	}
+	if (!font) {
+	    fprintf(stderr, "\ngnuplot_x11: can't find usable font - X11 aborted.\n");
+	    EXIT(1);
+	}
+    }
+#endif /* USEXMULTIBYTE */
 
+#ifndef USEXMULTIBYTE
     vchar = font->ascent + font->descent;
     hchar = XTextWidth(font, "0123456789", 10) / 10;
+#else
+    vchar = gpXTextHeight();
+    hchar = gpXTextWidth("0123456789", 10) / 10;
+#endif
 
     FPRINTF((stderr,"gnuplot_x11: pr_font() set font %s, vchar %d hchar %d\n",
 		fontname,vchar,hchar));
