]> code.delx.au - gnu-emacs/blobdiff - src/xfont.c
Merge from emacs--devo--0
[gnu-emacs] / src / xfont.c
index ac60b96bb5fc29e5dea4743fc2a79ff2c79fb64b..59cc31d78e4aeba5f86064426a77c4ed59d91b60 100644 (file)
@@ -239,6 +239,7 @@ xfont_registry_charsets (registry, encoding, repertory)
 
 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 *));
@@ -254,9 +255,10 @@ static int xfont_draw P_ ((struct glyph_string *, int, int, int, int, int));
 
 struct font_driver xfont_driver =
   {
-    (Lisp_Object) NULL,                /* Qx */
+    0,                         /* Qx */
     xfont_get_cache,
     xfont_list,
+    xfont_match,
     xfont_list_family,
     NULL,
     xfont_open,
@@ -396,7 +398,8 @@ xfont_list (frame, spec)
        font_name = XCDR (val);
     }
 
-  if (STRINGP (font_name))
+  if (STRINGP (font_name)
+      && ! strchr ((char *) SDATA (font_name), ':'))
     list = xfont_list_pattern (frame, display, (char *) SDATA (font_name));
   else if ((len = font_unparse_xlfd (spec, 0, name, 256)) < 0)
     return null_vector;
@@ -410,8 +413,8 @@ xfont_list (frame, spec)
 
          if (! NILP (registry)
              && (alter = Fassoc (SYMBOL_NAME (registry),
-                                 Vface_alternative_font_registry_alist))
-             && CONSP (alter))
+                                 Vface_alternative_font_registry_alist),
+                 CONSP (alter)))
            {
              /* Pointer to REGISTRY-ENCODING field.  */
              char *r = name + len - SBYTES (SYMBOL_NAME (registry));
@@ -432,6 +435,55 @@ xfont_list (frame, spec)
   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;
+
+  BLOCK_INPUT;
+  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);
+    }
+  UNBLOCK_INPUT;
+
+  return entity;
+}
+
 static int
 memq_no_quit (elt, list)
      Lisp_Object elt, list;
@@ -540,6 +592,7 @@ xfont_open (f, entity, pixel_size)
   if (! xfont)
     return NULL;
   font = malloc (sizeof (struct font));
+  font->format = Qx;
   font->font.font = xfont;
   font->entity = entity;
   font->pixel_size = pixel_size;
@@ -804,6 +857,17 @@ xfont_draw (s, from, to, x, y, with_background)
 {
   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)
     {
@@ -816,20 +880,20 @@ xfont_draw (s, from, to, x, y, with_background)
        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;
 }