Index: src/vtedraw.h
===================================================================
RCS file: /cvs/gnome/vte/src/vtedraw.h,v
retrieving revision 1.8
diff -u -7 -p -r1.8 vtedraw.h
--- src/vtedraw.h	16 Jun 2003 21:15:10 -0000	1.8
+++ src/vtedraw.h	5 Sep 2003 02:54:52 -0000
@@ -28,15 +28,22 @@
 #include "vtebg.h"
 
 G_BEGIN_DECLS
 
 #define VTE_DRAW_SINGLE_WIDE_CHARACTERS	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
 					"abcdefgjijklmnopqrstuvwxyz" \
 					"0123456789./+@"
-#define VTE_DRAW_DOUBLE_WIDE_CHARACTERS	0x4e00, 0x4e8c, 0x4e09, 0x56db, 0x4e94
+/* Some Korean fonts don't have CJK ideographs at all. Add 5 Hangul syllables
+   for them */
+#define VTE_DRAW_DOUBLE_WIDE_CHARACTERS 0x4e00, 0x4e8c, 0x4e09, 0x56db, 0x4e94,\
+					0xac00, 0xac01, 0xac04, 0xac08, 0xac10
+/* For Pango, we have to use CJK Ideographs alone. Otherwise, 'width'
+   returned by pango_layout would be screwed up for Chinese and Japanese 
+   fonts without Hangul */
+#define VTE_DRAW_DOUBLE_WIDE_IDEOGRAPHS 0x4e00, 0x4e8c, 0x4e09, 0x56db, 0x4e94
 #define VTE_DRAW_OPAQUE 0xff
 #define VTE_DRAW_MAX_LENGTH 88
 
 /* The _vte_draw structure. */
 struct _vte_draw;
 
 /* A request to draw a particular character spanning a given number of columns
Index: src/vteglyph.c
===================================================================
RCS file: /cvs/gnome/vte/src/vteglyph.c,v
retrieving revision 1.13
diff -u -7 -p -r1.13 vteglyph.c
--- src/vteglyph.c	28 May 2003 21:53:59 -0000	1.13
+++ src/vteglyph.c	5 Sep 2003 02:54:54 -0000
@@ -143,15 +143,15 @@ _vte_glyph_cache_set_font_description(Gt
 {
 	FcChar8 *facefile;
 	int i, j, error, count, width, faceindex;
 	double dpi, size;
 	GList *iter;
 	FcPattern *pattern;
 	GArray *patterns;
-	FT_Face face;
+	FT_Face face, prev_face;
 	gunichar double_wide_characters[] = {VTE_DRAW_DOUBLE_WIDE_CHARACTERS};
 
 	g_return_if_fail(cache != NULL);
 	g_return_if_fail(fontdesc != NULL);
 
 	/* Convert the font description to a sorted set of patterns. */
 	patterns = g_array_new(TRUE, TRUE, sizeof(FcPattern*));
@@ -342,35 +342,42 @@ _vte_glyph_cache_set_font_description(Gt
 		cache->height = howmany((cache->height / 64), count);
 		cache->ascent = howmany((cache->ascent / 64), count);
 	} else {
 		cache->width = 1;
 		cache->height = 1;
 		cache->ascent = 1;
 	}
-	width = 0;
+	width = count = 0;
+	prev_face = NULL;
 	for (i = 0; i < G_N_ELEMENTS(double_wide_characters); i++) {
 		face = _vte_glyph_cache_face_for_char(cache,
 						      double_wide_characters[i]);
 		if (face == NULL) {
 			continue;
 		}
 		error = FT_Load_Char((FT_Face) face,
 				     double_wide_characters[i],
 				     cache->ft_load_flags);
 		if (error == 0) {
 			error = FT_Render_Glyph(face->glyph,
 						cache->ft_render_flags);
 		}
 		if (error == 0) {
+			if (count && prev_face != face) {
+				count = width = 0;
+			}
 			width += face->glyph->metrics.horiAdvance;
 			count++;
+			prev_face = face;
 		}
 	}
 	if (count > 0) {
 		if (cache->width == width / 64 / count) {
+			/* add 1 to round up when dividing by 2 */
+			cache->width++;
 			cache->width /= 2;
 		}
 	}
 }
 
 static FT_Face
 _vte_glyph_cache_face_for_char(struct _vte_glyph_cache *cache, gunichar c)
Index: src/vtepango.c
===================================================================
RCS file: /cvs/gnome/vte/src/vtepango.c,v
retrieving revision 1.15
diff -u -7 -p -r1.15 vtepango.c
--- src/vtepango.c	16 Jun 2003 21:15:10 -0000	1.15
+++ src/vtepango.c	5 Sep 2003 02:54:55 -0000
@@ -263,15 +263,15 @@ _vte_pango_set_text_font(struct _vte_dra
 #if GTK_CHECK_VERSION(2,2,0)
 	GdkScreen *screen;
 #endif
 	PangoContext *ctx;
 	PangoLayout *layout;
 	PangoLayoutIter *iter;
 	PangoRectangle ink, logical;
-	gunichar full_codepoints[] = {VTE_DRAW_DOUBLE_WIDE_CHARACTERS};
+	gunichar full_codepoints[] = {VTE_DRAW_DOUBLE_WIDE_IDEOGRAPHS};
 	GString *full_string;
 	gint full_width;
 	int i;
 	struct _vte_pango_data *data;
 
 	data = (struct _vte_pango_data*) draw->impl_data;
 
@@ -314,14 +314,16 @@ _vte_pango_set_text_font(struct _vte_dra
 	pango_layout_set_text(layout, full_string->str, full_string->len);
 	pango_layout_get_extents(layout, &ink, &logical);
 	full_width = howmany(logical.width, G_N_ELEMENTS(full_codepoints));
 	g_string_free(full_string, TRUE);
 
 	/* If they're the same, then we have a screwy font. */
 	if (full_width == draw->width) {
+		/* add 1 to round up when dividing by 2 */
+		draw->width++;
 		draw->width /= 2;
 	}
 
 	draw->width = PANGO_PIXELS(draw->width);
 	iter = pango_layout_get_iter(layout);
 	if (draw->height == 0) {
 		draw->height = PANGO_PIXELS(logical.height);
Index: src/vtepangox.c
===================================================================
RCS file: /cvs/gnome/vte/src/vtepangox.c,v
retrieving revision 1.13
diff -u -7 -p -r1.13 vtepangox.c
--- src/vtepangox.c	16 Jun 2003 21:15:10 -0000	1.13
+++ src/vtepangox.c	5 Sep 2003 02:54:56 -0000
@@ -274,15 +274,15 @@ _vte_pango_x_set_text_font(struct _vte_d
 			   const PangoFontDescription *fontdesc)
 {
 	PangoContext *ctx;
 	Display *display;
 	PangoLayout *layout;
 	PangoLayoutIter *iter;
 	PangoRectangle ink, logical;
-	gunichar full_codepoints[] = {VTE_DRAW_DOUBLE_WIDE_CHARACTERS};
+	gunichar full_codepoints[] = {VTE_DRAW_DOUBLE_WIDE_IDEOGRAPHS};
 	GString *full_string;
 	gint full_width;
 	int i;
 	struct _vte_pango_x_data *data;
 
 	data = (struct _vte_pango_x_data*) draw->impl_data;
 
@@ -324,14 +324,16 @@ _vte_pango_x_set_text_font(struct _vte_d
 	pango_layout_set_text(layout, full_string->str, full_string->len);
 	pango_layout_get_extents(layout, &ink, &logical);
 	full_width = howmany(logical.width, G_N_ELEMENTS(full_codepoints));
 	g_string_free(full_string, TRUE);
 
 	/* If they're the same, then we have a screwy font. */
 	if (full_width == draw->width) {
+                /* add 1 to round up when dividing by 2 */
+		draw->width++;
 		draw->width /= 2;
 	}
 
 	draw->width = PANGO_PIXELS(draw->width);
 	iter = pango_layout_get_iter(layout);
 	if (draw->height == 0) {
 		draw->height = PANGO_PIXELS(logical.height);
Index: src/vtexft.c
===================================================================
RCS file: /cvs/gnome/vte/src/vtexft.c,v
retrieving revision 1.18
diff -u -7 -p -r1.18 vtexft.c
--- src/vtexft.c	16 Jun 2003 21:15:10 -0000	1.18
+++ src/vtexft.c	5 Sep 2003 02:54:56 -0000
@@ -529,15 +529,15 @@ _vte_xft_clear(struct _vte_draw *draw,
 }
 
 static void
 _vte_xft_set_text_font(struct _vte_draw *draw,
 		       const PangoFontDescription *fontdesc)
 {
 	GString *string;
-	XftFont *font;
+	XftFont *font, *prev_font;
 	XGlyphInfo extents;
 	struct _vte_xft_data *data;
 	gunichar wide_chars[] = {VTE_DRAW_DOUBLE_WIDE_CHARACTERS};
 	int i, n, width, height;
 	FcChar32 c;
 
 	data = (struct _vte_xft_data*) draw->impl_data;
@@ -573,28 +573,42 @@ _vte_xft_set_text_font(struct _vte_draw 
 			       font->ascent + font->descent : height;
 		draw->ascent = (font != NULL) ?
 			       font->ascent : height;
 	}
 	/* Estimate a typical cell width by looking at double-width
 	 * characters, and if it's the same as the single width, assume the
 	 * single-width stuff is broken. */
-	n = 0;
+	n = width = 0;
+	prev_font = NULL;
 	for (i = 0; i < G_N_ELEMENTS(wide_chars); i++) {
 		c = wide_chars[i];
 		font = _vte_xft_font_for_char(data->font, c);
 		if ((font != NULL) &&
 		    (_vte_xft_char_exists(data->font, font, c))) {
+			if (n && prev_font != font) { /* font change */
+			    n = width = 0; 
+			}
 			memset(&extents, 0, sizeof(extents));
 			_vte_xft_text_extents(data->font, font, c, &extents);
 			n++;
 			width += extents.xOff;
+			prev_font = font;
 		}
 	}
+#ifdef VTE_DEBUG
+	if (_vte_debug_on(VTE_DEBUG_MISC)) {
+		fprintf(stderr, "VteXft font : single width=%d,"
+		        "double width=%d, # of doubld width chars=%d\n", 
+			draw->width, howmany(width,n), n);
+	}
+#endif
 	if (n > 0) {
 		if (howmany(width, n) == draw->width) {
+		        /* add 1 to round up when dividing by 2 */
+			draw->width++;
 			draw->width /= 2;
 		}
 	}
 	g_string_free(string, TRUE);
 
 #ifdef VTE_DEBUG
 	if (_vte_debug_on(VTE_DEBUG_MISC)) {
