changeset 59206:77ba45776c58

(x_new_font): Set FRAME_COLUMN_WIDTH to fontp->average_width, not FONT_WIDTH. Set FRAME_SPACE_WIDTH to fontp-?space_width.. (x_load_font): Calculate fontp->space_width and fontp->average_width. (x_term_init): Initialize dpyinfo->Xatom_AVERAGE_WIDTH.
author Kenichi Handa <handa@m17n.org>
date Thu, 30 Dec 2004 12:26:31 +0000
parents d33c176effbf
children 3912575fcded
files src/xterm.c
diffstat 1 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/xterm.c	Thu Dec 30 12:25:28 2004 +0000
+++ b/src/xterm.c	Thu Dec 30 12:26:31 2004 +0000
@@ -7838,7 +7838,8 @@
   FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset;
   FRAME_FONTSET (f) = -1;
 
-  FRAME_COLUMN_WIDTH (f) = FONT_WIDTH (FRAME_FONT (f));
+  FRAME_COLUMN_WIDTH (f) = fontp->average_width;
+  FRAME_SPACE_WIDTH (f) = fontp->space_width;
   FRAME_LINE_HEIGHT (f) = FONT_HEIGHT (FRAME_FONT (f));
 
   compute_fringe_widths (f, 1);
@@ -9782,6 +9783,43 @@
     fontp->name = (char *) xmalloc (strlen (fontname) + 1);
     bcopy (fontname, fontp->name, strlen (fontname) + 1);
 
+    if (font->min_bounds.width == font->max_bounds.width)
+      {
+	/* Fixed width font.  */
+	fontp->average_width = fontp->space_width = font->min_bounds.width;
+      }
+    else
+      {
+	XChar2b char2b;
+	XCharStruct *pcm;
+
+	char2b.byte1 = 0x00, char2b.byte2 = 0x20;
+	pcm = x_per_char_metric (font, &char2b, 0);
+	if (pcm)
+	  fontp->space_width = pcm->width;
+	else
+	  fontp->space_width = FONT_WIDTH (font);
+
+	fontp->average_width
+	  = (XGetFontProperty (font, dpyinfo->Xatom_AVERAGE_WIDTH, &value)
+	     ? (long) value / 10 : 0);
+	if (fontp->average_width < 0)
+	  fontp->average_width = - fontp->average_width;
+	if (fontp->average_width == 0)
+	  {
+	    if (pcm)
+	      {
+		int width = pcm->width;
+		for (char2b.byte2 = 33; char2b.byte2 <= 126; char2b.byte2++)
+		  if ((pcm = x_per_char_metric (font, &char2b, 0)) != NULL)
+		    width += pcm->width;
+		fontp->average_width = width / 95;
+	      }
+	    else
+	      fontp->average_width = FONT_WIDTH (font);
+	  }
+      }
+
     /* Try to get the full name of FONT.  Put it in FULL_NAME.  */
     full_name = 0;
     if (XGetFontProperty (font, XA_FONT, &value))
@@ -10409,6 +10447,8 @@
   /* For properties of font.  */
   dpyinfo->Xatom_PIXEL_SIZE
     = XInternAtom (dpyinfo->display, "PIXEL_SIZE", False);
+  dpyinfo->Xatom_AVERAGE_WIDTH
+    = XInternAtom (dpyinfo->display, "AVERAGE_WIDTH", False);
   dpyinfo->Xatom_MULE_BASELINE_OFFSET
     = XInternAtom (dpyinfo->display, "_MULE_BASELINE_OFFSET", False);
   dpyinfo->Xatom_MULE_RELATIVE_COMPOSE