diff -u gplt_x11.c.ORG gplt_x11.c
--- gplt_x11.c.ORG	Sun Jan  9 15:24:29 2005
+++ gplt_x11.c	Mon Jan 24 15:30:23 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,15 @@
 #endif
 
 static char *FallbackFont = "fixed";
+#ifdef USEXMULTIBYTE
+# define FallbackFontMB "mbfont:*-medium-r-normal--14-*;*-medium-r-normal--16-*"
+# define FontSetSep ';'
+static XFontSet gpXCreateFontSet __PROTO((Display *,char *));
+static int fontset_transsep __PROTO((char *,char *,int));
+static int fontset_ascent __PROTO((XFontSet));
+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 +533,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 +679,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 +1751,12 @@
     int x, y;
     double src_x, src_y;
     double dest_x, dest_y;
+#ifndef USEXMULTIBYTE
     int width = XTextWidth(font, str, len);
+#else
+    int width = (!usemultibyte)? 
+	XTextWidth(font, str, len) : XmbTextEscapement(mbfont, str, len);
+#endif
     int height = vchar;
     double src_cen_x = (double)width * 0.5;
     double src_cen_y = (double)height * 0.5;
@@ -1775,11 +1801,21 @@
 	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
+    if (!usemultibyte) {
+        XSetFont(dpy, bitmapGC, font->fid);
+        XDrawImageString(dpy, pixmap_src, bitmapGC, 0, font->ascent, str, len);
+    } else {
+	XmbDrawImageString(dpy, pixmap_src, mbfont, bitmapGC, 0, 
+			   fontset_ascent(mbfont), str, len);
+    }
+#endif
 
     /* create XImage's of depth 1 */
     /* source from pixmap */
@@ -1938,7 +1974,12 @@
 		c = &(buffer[strlen(buffer)-1]);
 		while (*c <= ' ') *c-- = '\0';
 	    	pr_font(&buffer[2]);
+#ifndef USEXMULTIBYTE
 		XSetFont(dpy,gc,font->fid);
+#else
+		if (!usemultibyte)
+		  XSetFont(dpy,gc,font->fid);
+#endif
 		break;
 	case 'E':
 		/* Save the requested font encoding */
@@ -2012,7 +2053,14 @@
 	}
 
 	sl = strlen(str) - 1;
+#ifndef USEXMULTIBYTE
 	sw = XTextWidth(font, str, sl);
+#else
+	if (!usemultibyte)
+	  sw = XTextWidth(font, str, sl);
+	else
+	  sw = XmbTextEscapement(mbfont, str, sl);
+#endif
 
 /*	EAM - May 2002 	Modify to allow colored text.
  *	1) do not force foreground of gc to be black
@@ -2042,8 +2090,17 @@
 	    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
+	    if (!usemultibyte)
+	      XDrawString(dpy, plot->pixmap, *current_gc,
+			  X(x) + sj, Y(y) + v_offset, str, sl);
+	    else
+	      XmbDrawString(dpy, plot->pixmap, mbfont, *current_gc,
+			    X(x) + sj, Y(y) + v_offset, str, sl);
+#endif
 	}
 
 	/* Update current text position */
@@ -3089,7 +3146,12 @@
 
     gc = XCreateGC(dpy, plot->pixmap, 0, (XGCValues *) 0);
 
+#ifndef USEXMULTIBYTE
     XSetFont(dpy, gc, font->fid);
+#else
+    if (!usemultibyte)
+      XSetFont(dpy, gc, font->fid);
+#endif
 #if USE_ULIG_FILLEDBOXES
     XSetFillStyle(dpy, gc, FillSolid);
 
@@ -3169,7 +3231,12 @@
 	if (gc)
 	    XFreeGC(dpy, gc);
 	gc = XCreateGC(dpy, plot->pixmap, 0, (XGCValues *) 0);
+#ifndef USEXMULTIBYTE
 	XSetFont(dpy, gc, font->fid);
+#else
+	if (!usemultibyte)
+	  XSetFont(dpy, gc, font->fid);
+#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 +3715,42 @@
     int xwidth, ywidth;
 
     xlen = strlen(xstr);
+#ifndef USEXMULTIBYTE
     xwidth = XTextWidth(font, xstr, xlen);
+#else
+    if (!usemultibyte)
+      xwidth = XTextWidth(font, xstr, xlen);
+    else
+      xwidth = XmbTextEscapement(mbfont, xstr, xlen);
+#endif
 
     ylen = strlen(ystr);
+#ifndef USEXMULTIBYTE
     ywidth = XTextWidth(font, ystr, ylen);
+#else
+    if (!usemultibyte)
+      ywidth = XTextWidth(font, ystr, ylen);
+    else
+      xwidth = XmbTextEscapement(mbfont, 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
+    if (!usemultibyte) { 
+	XDrawString(dpy, plot->window, gc_xor, x, y - 3, xstr, xlen);
+	XDrawString(dpy, plot->window, gc_xor, x, y + vchar, ystr, ylen);
+    } else {
+	XmbDrawString(dpy, plot->window, mbfont, gc_xor, x, y - 3, xstr, xlen);
+	XmbDrawString(dpy, plot->window, mbfont, gc_xor, x, y + vchar, ystr, ylen);
+    }
+#endif
 }
 
 /* returns the time difference to the last click in milliseconds */
@@ -3719,9 +3810,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 +3935,16 @@
     }
 
     if (str[0] != 0)
+#ifndef USEXMULTIBYTE
 	XDrawString(dpy, plot->window, gc_xor, 1, plot->gheight + vchar - 1, str, strlen(str));
+#else
+    if (!usemultibyte)
+      XDrawString(dpy, plot->window, gc_xor, 
+		  1, plot->gheight + vchar - 1, str, strlen(str));
+    else
+      XmbDrawString(dpy, plot->window, mbfont, gc_xor, 
+		    1, plot->gheight + vchar - 1, str, strlen(str));
+#endif
 }
 
 
@@ -5091,6 +5202,58 @@
  *   pr_font - determine font
  *---------------------------------------------------------------------------*/
 
+#ifdef USEXMULTIBYTE
+
+XFontSet gpXCreateFontSet (Display *disp,char *fontname)
+{
+    static char **miss, *def;
+    int n_miss;
+    char tmpfname[512];
+    
+    if (!usemultibyte) return NULL;
+    fontset_transsep(tmpfname,fontname,512-1);
+    mbfont = XCreateFontSet(disp, tmpfname, &miss, &n_miss, &def);
+    if (n_miss>0) {
+	if (mbfont) {
+	    XFreeFontSet(disp, mbfont);
+	    mbfont=NULL;
+	}
+	XFreeStringList(miss);
+    }
+    return mbfont;
+}
+
+int fontset_transsep(char *nfname,char *ofname,int n)
+{
+    char *s;
+
+    strncpy(nfname,ofname,n);
+    if(nfname[n-1]!='\0') nfname[n]='\0';
+    if (strchr(nfname,',')) return 1;
+    s = nfname;
+    while (s = strchr(nfname,FontSetSep)){
+	*s = ',';
+	nfname = s;
+    }
+    return 0;
+}
+
+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;
+}
+#endif
+
 static void
 pr_font( fontname )
 char *fontname;
@@ -5098,6 +5261,10 @@
     static char previous_font_name[128];
     char fontspec[128];
     int  fontsize = 0;
+#ifdef USEXMULTIBYTE
+    static XFontSetExtents *extents;
+    char *orgfontname = NULL;
+#endif
 
     if (!fontname || !(*fontname))
 	fontname = default_font;
@@ -5109,22 +5276,67 @@
 		    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) {
+	if (!usemultibyte) 
+	  fontname = FallbackFont;
+	else
+	  fontname = FallbackFontMB;
+    }
+#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
+    if (font) {
+	XFreeFont(dpy, font);
+	font=NULL;
+    }
+    if (mbfont) {
+	XFreeFontSet(dpy, mbfont);
+	mbfont=NULL;
+    }
+#endif /* USEXMULTIBYTE */
+
+#ifndef USEXMULTIBYTE
     font = XLoadQueryFont(dpy, fontname);
+#else
+    if (!usemultibyte) 
+      font = XLoadQueryFont(dpy, fontname);
+    else 
+      mbfont = gpXCreateFontSet(dpy, fontname);
+#endif
 
+#ifndef USEXMULTIBYTE
     if (!font) {
+#else
+    if (!font && !mbfont && !strchr(fontname,FontSetSep)) {
+#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 +5344,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 +5383,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 +5401,20 @@
 	sprintf(fontspec, "-*-%s-%s-%c-*-*-%d-*-*-*-*-*-%s",
 		shortname, weight, slant, fontsize, fontencoding
 		);
+#ifndef USEXMULTIBYTE
 	font = XLoadQueryFont(dpy, fontspec);
+#else
+	if (!usemultibyte) 
+	  font = XLoadQueryFont(dpy, fontspec);
+	else 
+	  mbfont = gpXCreateFontSet(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 +5441,53 @@
 		sprintf(fontspec,
 			"-*-arial narrow-bold-r-*-*-%d-*-*-*-*-*-%s", fontsize, fontencoding);
 	    }
+#ifdef USEXMULTIBYTE
+	    /* Japanese standard PostScript font names */
+	    else if (usablemb 
+	      && (!strncmp("Ryumin-Light",shortname,strlen("Ryumin-Light")) 
+	       || !strncmp("ryumin-light",shortname,strlen("ryumin-light")))) {
+		if (!usemultibyte ) {
+		    usemultibyte = 1;
+		    orgfontname = fontname;
+		}
+		sprintf(fontspec,"-*-mincho-medium-%c-*--%d-*", slant,fontsize);
+	    } 
+	    else if (usablemb 
+	      && (!strncmp("GothicBBB-Medium",shortname,strlen("GothicBBB-Medium")) 
+	       || !strncmp("gothicbbb-medium",shortname,strlen("gothicbbb-medium")))) {
+		if (!usemultibyte) {
+		    usemultibyte = 1;
+		    orgfontname = fontname;
+		}
+		sprintf(fontspec,"-*-gothic-bold-%c-*--%d-*", slant,fontsize);
+	    }
+#endif
+#ifndef USEXMULTIBYTE
 	    font = XLoadQueryFont(dpy, fontspec);
+#else
+	    if (!usemultibyte) 
+	      font = XLoadQueryFont(dpy, fontspec);
+	    else 
+	      mbfont = gpXCreateFontSet(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);
+		mbfont = gpXCreateFontSet(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 +5495,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 +5521,35 @@
 	}
 	FPRINTF((stderr, "\ngnuplot_x11: requested font not found, using '%s' instead.\n", fontname));
     }
+#ifdef USEXMULTIBYTE
+    if (usemultibyte && !mbfont) { /* multibyte font setting */
+	mbfont = gpXCreateFontSet(dpy, FallbackFontMB);
+	if (!mbfont) {
+	    usemultibyte = 0; 
+	    font = XLoadQueryFont(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
+    if (!usemultibyte) {
+	vchar = font->ascent + font->descent;
+	hchar = XTextWidth(font, "0123456789", 10) / 10;
+    }
+    else {
+	extents = XExtentsOfFontSet(mbfont);
+	vchar = extents->max_logical_extent.height;
+	hchar = XmbTextEscapement(mbfont, "0123456789", 10) / 10;
+    }
+#endif
 
     FPRINTF((stderr,"gnuplot_x11: pr_font() set font %s, vchar %d hchar %d\n",
 		fontname,vchar,hchar));
