changeset 90561:73750c4e078a

(xfont_match): New function. (xfont_driver): Set xfont_driver.match to xfont_match. (xfont_draw): Set font in GC if necessary.
author Kenichi Handa <handa@m17n.org>
date Tue, 01 Aug 2006 01:21:08 +0000
parents c443c8a56b84
children 9d76594a90f0
files src/xfont.c
diffstat 1 files changed, 64 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/xfont.c	Tue Aug 01 01:19:31 2006 +0000
+++ b/src/xfont.c	Tue Aug 01 01:21:08 2006 +0000
@@ -239,6 +239,7 @@
 
 static Lisp_Object xfont_get_cache P_ ((Lisp_Object));
 static Lisp_Object xfont_list P_ ((Lisp_Object, Lisp_Object));
+static Lisp_Object xfont_match P_ ((Lisp_Object, Lisp_Object));
 static Lisp_Object xfont_list_family P_ ((Lisp_Object));
 static struct font *xfont_open P_ ((FRAME_PTR, Lisp_Object, int));
 static void xfont_close P_ ((FRAME_PTR, struct font *));
@@ -257,6 +258,7 @@
     (Lisp_Object) NULL,		/* Qx */
     xfont_get_cache,
     xfont_list,
+    xfont_match,
     xfont_list_family,
     NULL,
     xfont_open,
@@ -433,6 +435,53 @@
   return (NILP (list) ? null_vector : Fvconcat (1, &list));
 }
 
+static Lisp_Object
+xfont_match (frame, spec)
+     Lisp_Object frame, spec;
+{
+  FRAME_PTR f = XFRAME (frame);
+  Display *display = FRAME_X_DISPLAY_INFO (f)->display;
+  Lisp_Object extra, val, entity;
+  char *name;
+  XFontStruct *xfont;
+  unsigned long value;
+
+  extra = AREF (spec, FONT_EXTRA_INDEX);
+  val = assq_no_quit (QCname, extra);
+  if (! CONSP (val) || ! STRINGP (XCDR (val)))
+    return Qnil;
+
+  entity = Qnil;
+  name = (char *) SDATA (XCDR (val));
+  xfont = XLoadQueryFont (display, name);
+  if (xfont)
+    {
+      if (XGetFontProperty (xfont, XA_FONT, &value))
+	{
+	  int len;
+
+	  name = (char *) XGetAtomName (display, (Atom) value);
+	  len = strlen (name);
+
+	  /* If DXPC (a Differential X Protocol Compressor)
+	     Ver.3.7 is running, XGetAtomName will return null
+	     string.  We must avoid such a name.  */
+	  if (len > 0)
+	    {
+	      entity = Fmake_vector (make_number (FONT_ENTITY_MAX), Qnil);
+	      ASET (entity, FONT_TYPE_INDEX, Qx);
+	      ASET (entity, FONT_FRAME_INDEX, frame);
+	      if (font_parse_xlfd (name, entity) < 0)
+		entity = Qnil;
+	    }
+	  XFree (name);
+	}
+      XFreeFont (display, xfont);
+    }
+
+  return entity;
+}
+
 static int
 memq_no_quit (elt, list)
      Lisp_Object elt, list;
@@ -805,6 +854,17 @@
 {
   XFontStruct *xfont = s->face->font;
   int len = to - from;
+  GC gc = s->gc;
+
+  if (gc != s->face->gc)
+    {
+      XGCValues xgcv;
+      Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (s->f);
+
+      XGetGCValues (s->display, gc, GCFont, &xgcv);
+      if (xgcv.font != xfont->fid)
+	XSetFont (s->display, gc, xfont->fid);
+    }
 
   if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0)
     {
@@ -817,20 +877,20 @@
 	str[i] = XCHAR2B_BYTE2 (s->char2b + from + i);
       if (with_background > 0)
 	XDrawImageString (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
-			  s->gc, x, y, str, len);
+			  gc, x, y, str, len);
       else
 	XDrawString (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
-		     s->gc, x, y, str, len);
+		     gc, x, y, str, len);
       SAFE_FREE ();
       return s->nchars;
     }
 
   if (with_background > 0)
     XDrawImageString16 (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
-			s->gc, x, y, s->char2b + from, len);
+			gc, x, y, s->char2b + from, len);
   else
     XDrawString16 (FRAME_X_DISPLAY (s->f), FRAME_X_WINDOW (s->f),
-		   s->gc, x, y, s->char2b + from, len);
+		   gc, x, y, s->char2b + from, len);
 
   return len;
 }