emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs antialiasing in X


From: Jan D.
Subject: Re: Emacs antialiasing in X
Date: Tue, 17 Jan 2006 09:34:51 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050923 Fedora/1.7.12-1.5.1



Miles Bader wrote:
2006/1/17, David Abrahams <address@hidden>:

No tag, but you can use the date specifier, the cvs log message gives
the date.

Thanks, I'll do that.  FWIW, if you do use such tags you can
substantially reduce the number of conflicts you see upon merging.


This whole conversation is making me very nervous ....

I also merge into the emacs-unicode-2 branch (using arch), and this is
normally pretty easy.  I'm afraid that a botched merge (all too easy
with CVS) into that same branch will make things very painful for me.

Jan, how many changes are there in the XFT branch, compared to the trunk?

I've attached a diff from HEAD 2006-01-12 10:24 to the XFT branch (the latest sync with head occurred then). It is not that much.


If it's not many, how about instead I update my XFT branch in arch
(it's out of date because it got merged into from the trunk, which
caused lots of problems for my syncing scripts, but I can just
probably just recreate it from scratch), then merge that into the
unicode branch (using arch), and make a new combined branch, and then
make a new CVS branch from that...?

Sounds like a bit of work, but if it is easy for you, please do, that would help a lot.

        Jan D.
--- emacs-060112-102400/configure.in    2006-01-17 08:53:17.000000000 +0100
+++ emacs.xft/configure.in      2006-01-17 08:59:18.000000000 +0100
@@ -109,10 +109,12 @@
 [  --with-gif              use -lungif for displaying GIF images])
 AC_ARG_WITH(png,
 [  --with-png              use -lpng for displaying PNG images])
+AC_ARG_WITH(xft,
+[  --with-xft              use -lXft for anti aliased fonts])
 AC_ARG_WITH(gtk,
 [  --with-gtk              use GTK (same as --with-x-toolkit=gtk)])
 AC_ARG_WITH(pkg-config-prog,
-[  --with-pkg-config-prog  Path to pkg-config to use for finding GTK])
+[  --with-pkg-config-prog  Path to pkg-config to use for finding GTK and Xft])
 AC_ARG_WITH(toolkit-scroll-bars,
 [  --without-toolkit-scroll-bars
                           don't use Motif or Xaw3d scroll bars])
@@ -2267,6 +2269,42 @@
   CFLAGS=$late_CFLAGS
 fi
 
+
+### Use -lXft if available, unless `--with-xft=no'.
+HAVE_XFT=maybe
+if test "${HAVE_X11}" = "yes"; then
+  if test "${with_xft}" != "no"; then
+
+    dnl Check if --with-pkg-config-prog has been given.
+    if test "X${with_pkg_config_prog}" != X; then
+      PKG_CONFIG="${with_pkg_config_prog}"
+    fi
+
+    PKG_CHECK_MODULES(XFT, xft >= 0.13.0, , HAVE_XFT=no)
+    if test "$HAVE_XFT" != no; then
+      OLD_CFLAGS="$CPPFLAGS"
+      OLD_CFLAGS="$CFLAGS"
+      OLD_LIBS="$LIBS"
+      CPPFLAGS="$CPPFLAGS $XFT_CFLAGS"
+      CFLAGS="$CFLAGS $XFT_CFLAGS"
+      LIBS="$XFT_LIBS $LIBS"
+      AC_CHECK_HEADER(X11/Xft/Xft.h,
+        AC_CHECK_LIB(Xft, XftFontOpen, HAVE_XFT=yes, , $XFT_LIBS))
+
+      if test "${HAVE_XFT}" = "yes"; then
+        AC_DEFINE(HAVE_XFT, 1, [Define to 1 if you have the Xft library.])
+       AC_SUBST(XFT_LIBS)
+        C_SWITCH_X_SITE="$C_SWITCH_X_SITE $XFT_CFLAGS"
+      else
+        CFLAGS="$OLD_CPPFLAGS"
+        CFLAGS="$OLD_CFLAGS"
+        LIBS="$OLD_LIBS"
+      fi
+    fi
+  fi
+fi
+
+
 ### Use -lXpm if available, unless `--with-xpm=no'.
 HAVE_XPM=no
 if test "${HAVE_X11}" = "yes"; then
@@ -2291,7 +2329,7 @@
   fi
 
   if test "${HAVE_XPM}" = "yes"; then
-    AC_DEFINE(HAVE_XPM, 1, [Define to 1 if you have the Xpm libary (-lXpm).])
+    AC_DEFINE(HAVE_XPM, 1, [Define to 1 if you have the Xpm library (-lXpm).])
   fi
 fi
 
--- emacs-060112-102400/src/Makefile.in 2005-12-26 23:10:18.000000000 +0100
+++ emacs.xft/src/Makefile.in   2006-01-12 11:25:42.000000000 +0100
@@ -401,6 +401,11 @@
 #endif
 #endif /* not USE_X_TOOLKIT */
 
+#if HAVE_XFT
+#undef LIB_X11_LIB
+#define LIB_X11_LIB @XFT_LIBS@
+#endif /* HAVE_XFT */
+
 #if HAVE_XPM
 #ifndef LIBXPM
 #define LIBXPM -lXpm
--- emacs-060112-102400/src/config.in   2005-09-10 13:36:24.000000000 +0200
+++ emacs.xft/src/config.in     2006-01-12 11:25:42.000000000 +0100
@@ -700,13 +700,16 @@
 /* Define to 1 if you're using XFree386. */
 #undef HAVE_XFREE386
 
+/* Define to 1 if you have the Xft library. */
+#undef HAVE_XFT
+
 /* Define to 1 if XIM is available */
 #undef HAVE_XIM
 
 /* Define to 1 if you have the XkbGetKeyboard function. */
 #undef HAVE_XKBGETKEYBOARD
 
-/* Define to 1 if you have the Xpm libary (-lXpm). */
+/* Define to 1 if you have the Xpm library (-lXpm). */
 #undef HAVE_XPM
 
 /* Define to 1 if you have the `XrmSetDatabase' function. */
--- emacs-060112-102400/src/dispextern.h        2005-11-11 16:33:34.000000000 
+0100
+++ emacs.xft/src/dispextern.h  2006-01-12 11:25:42.000000000 +0100
@@ -27,6 +27,17 @@
 #ifdef HAVE_X_WINDOWS
 
 #include <X11/Xlib.h>
+
+#ifndef X_FONT_TYPE_DECL
+#define X_FONT_TYPE_DECL
+#ifdef HAVE_XFT
+#include <X11/Xft/Xft.h>
+typedef XftFont x_font_type;
+#else
+typedef XFontStruct x_font_type;
+#endif
+#endif /* not X_FONT_TYPE_DECL */
+
 #ifdef USE_X_TOOLKIT
 #include <X11/Intrinsic.h>
 #endif /* USE_X_TOOLKIT */
@@ -1149,7 +1160,7 @@
   struct face *face;
 
   /* Font in which this string is to be drawn.  */
-  XFontStruct *font;
+  x_font_type *font;
 
   /* Font info for this string.  */
   struct font_info *font_info;
@@ -1428,6 +1439,11 @@
 
 #ifdef HAVE_WINDOW_SYSTEM
 
+#ifdef HAVE_XFT
+  XftColor xft_fg;
+  XftColor xft_bg;
+  XftDraw *xft_draw;
+#endif
   /* If non-zero, this is a GC that we can use without modification for
      drawing the characters in this face.  */
   GC gc;
@@ -1436,7 +1452,7 @@
      for some reason.  This points to a `font' slot of a struct
      font_info, and we should not call XFreeFont on it because the
      font may still be used somewhere else.  */
-  XFontStruct *font;
+  x_font_type *font;
 
   /* Background stipple or bitmap used for this face.  This is
      an id as returned from load_pixmap.  */
@@ -1633,11 +1649,19 @@
 /* Prepare face FACE for use on frame F.  This must be called before
    using X resources of FACE.  */
 
+#ifdef HAVE_XFT
+#define PREPARE_FACE_FOR_DISPLAY(F, FACE)               \
+     if ((FACE)->xft_draw == 0 || (FACE)->gc == 0)      \
+       prepare_face_for_display ((F), (FACE));          \
+     else                                               \
+       (void) 0
+#else
 #define PREPARE_FACE_FOR_DISPLAY(F, FACE)      \
      if ((FACE)->gc == 0)                      \
        prepare_face_for_display ((F), (FACE)); \
      else                                      \
        (void) 0
+#endif /* not HAVE_XFT */
 
 /* Return a pointer to the face with ID on frame F, or null if such a
    face doesn't exist.  */
@@ -2293,7 +2317,9 @@
 
 /* Get metrics of character CHAR2B in FONT of type FONT_TYPE.
    Value is null if CHAR2B is not contained in the font.  */
-  XCharStruct * (*per_char_metric) P_ ((XFontStruct *font, XChar2b *char2b,
+  XCharStruct * (*per_char_metric) P_ ((struct frame *f,
+                                        x_font_type *font,
+                                        XChar2b *char2b,
                                        int font_type));
 
 /* Encode CHAR2B using encoding information from FONT_INFO.  CHAR2B is
@@ -2658,7 +2684,7 @@
 extern void reseat_at_previous_visible_line_start P_ ((struct it *));
 
 extern int calc_pixel_width_or_height P_ ((double *, struct it *, Lisp_Object,
-                                          /* XFontStruct */ void *, int, int 
*));
+                                          /* x_font_type */ void *, int, int 
*));
 
 #ifdef HAVE_WINDOW_SYSTEM
 
--- emacs-060112-102400/src/fontset.h   2005-12-19 07:59:10.000000000 +0100
+++ emacs.xft/src/fontset.h     2006-01-12 11:25:43.000000000 +0100
@@ -30,7 +30,7 @@
 struct font_info
 {
   /* Pointer to window system dependent font structure.  On X window,
-     this value should be coerced to (XFontStruct *).  */
+     this value should be coerced to (x_font_type *).  */
   void *font;
 
   /* Index number of the font.  */
--- emacs-060112-102400/src/image.c     2005-12-24 03:50:00.000000000 +0100
+++ emacs.xft/src/image.c       2006-01-12 11:25:43.000000000 +0100
@@ -28,6 +28,15 @@
 #include <unistd.h>
 #endif
 
+#ifdef HAVE_PNG
+
+#if defined HAVE_LIBPNG_PNG_H
+# include <libpng/png.h>
+#else
+# include <png.h>
+#endif
+#endif
+
 /* This makes the fields of a Display accessible, in Xlib header files.  */
 
 #define XLIB_ILLEGAL_ACCESS
--- emacs-060112-102400/src/macterm.c   2006-01-12 09:14:58.000000000 +0100
+++ emacs.xft/src/macterm.c     2006-01-12 11:25:44.000000000 +0100
@@ -258,7 +258,8 @@
                                            unsigned long *));
 
 static int is_emacs_window P_ ((WindowPtr));
-static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int));
+static XCharStruct *mac_per_char_metric P_ ((FRAME_PTR,
+                                             XFontStruct *, XChar2b *, int));
 static void XSetFont P_ ((Display *, GC, XFontStruct *));
 
 /* Defined in macmenu.h.  */
@@ -1000,7 +1001,7 @@
 
   for (i = 0; i < nchars; i++)
     {
-      pcm = mac_per_char_metric (font_struct, string, 0);
+      pcm = mac_per_char_metric (0, font_struct, string, 0);
       if (pcm == NULL)
        width += FONT_WIDTH (font_struct);
       else
@@ -1060,7 +1061,7 @@
   advances = xmalloc (sizeof (CGSize) * nchars);
   for (i = 0; i < nchars; i++)
     {
-      XCharStruct *pcm = mac_per_char_metric (GC_FONT (gc), buf, 0);
+      XCharStruct *pcm = mac_per_char_metric (f, GC_FONT (gc), buf, 0);
 
       advances[i].width = pcm->width;
       advances[i].height = 0;
@@ -1966,7 +1967,8 @@
  */
 
 static XCharStruct *
-mac_per_char_metric (font, char2b, font_type)
+mac_per_char_metric (f, font, char2b, font_type)
+     FRAME_PTR f;
      XFontStruct *font;
      XChar2b *char2b;
      int font_type;
@@ -7964,7 +7966,7 @@
        XCharStruct *pcm;
 
        char2b.byte1 = 0x00, char2b.byte2 = 0x20;
-       pcm = mac_per_char_metric (font, &char2b, 0);
+       pcm = mac_per_char_metric (0, font, &char2b, 0);
        if (pcm)
          fontp->space_width = pcm->width;
        else
@@ -7974,7 +7976,7 @@
          {
            int width = pcm->width;
            for (char2b.byte2 = 33; char2b.byte2 <= 126; char2b.byte2++)
-             if ((pcm = mac_per_char_metric (font, &char2b, 0)) != NULL)
+             if ((pcm = mac_per_char_metric (0, font, &char2b, 0)) != NULL)
                width += pcm->width;
            fontp->average_width = width / 95;
          }
--- emacs-060112-102400/src/w32fns.c    2005-12-14 21:58:33.000000000 +0100
+++ emacs.xft/src/w32fns.c      2006-01-12 11:25:46.000000000 +0100
@@ -64,7 +64,8 @@
 extern int w32_console_toggle_lock_key P_ ((int, Lisp_Object));
 extern void w32_menu_display_help P_ ((HWND, HMENU, UINT, UINT));
 extern void w32_free_menu_strings P_ ((HWND));
-extern XCharStruct *w32_per_char_metric P_ ((XFontStruct *, wchar_t *, int));
+extern XCharStruct *w32_per_char_metric P_ ((FRAME_PTR f,
+                                             XFontStruct *, wchar_t *, int));
 
 extern int quit_char;
 
@@ -4602,7 +4603,7 @@
       {
        wchar_t space = 32;
        XCharStruct* pcm;
-       pcm = w32_per_char_metric (font, &space, ANSI_FONT);
+       pcm = w32_per_char_metric (f, font, &space, ANSI_FONT);
        if (pcm)
          fontp->space_width = pcm->width;
        else
--- emacs-060112-102400/src/w32term.c   2005-12-19 09:31:23.000000000 +0100
+++ emacs.xft/src/w32term.c     2006-01-12 11:25:46.000000000 +0100
@@ -841,7 +841,8 @@
 
 /* Function prototypes of this page.  */
 
-XCharStruct *w32_per_char_metric P_ ((XFontStruct *, wchar_t *, int));
+XCharStruct *w32_per_char_metric P_ ((FRAME_PTR f,
+                                      XFontStruct *, wchar_t *, int));
 static int w32_encode_char P_ ((int, wchar_t *, struct font_info *, int *));
 
 
@@ -989,7 +990,8 @@
 
 
 XCharStruct *
-w32_per_char_metric (font, char2b, font_type)
+w32_per_char_metric (f, font, char2b, font_type)
+     FRAME_PTR f;
      XFontStruct *font;
      wchar_t *char2b;
      int /* enum w32_char_font_type */ font_type;
--- emacs-060112-102400/src/xdisp.c     2005-12-11 16:37:00.000000000 +0100
+++ emacs.xft/src/xdisp.c       2006-01-12 11:25:47.000000000 +0100
@@ -18038,9 +18038,9 @@
 
 #ifdef HAVE_WINDOW_SYSTEM
       if (EQ (prop, Qheight))
-       return OK_PIXELS (font ? FONT_HEIGHT ((XFontStruct *)font) : 
FRAME_LINE_HEIGHT (it->f));
+       return OK_PIXELS (font ? FONT_HEIGHT ((x_font_type *)font) : 
FRAME_LINE_HEIGHT (it->f));
       if (EQ (prop, Qwidth))
-       return OK_PIXELS (font ? FONT_WIDTH ((XFontStruct *)font) : 
FRAME_COLUMN_WIDTH (it->f));
+       return OK_PIXELS (font ? FONT_WIDTH ((x_font_type *)font) : 
FRAME_COLUMN_WIDTH (it->f));
 #else
       if (EQ (prop, Qheight) || EQ (prop, Qwidth))
        return OK_PIXELS (1);
@@ -18578,7 +18578,7 @@
 
   if (glyph->type == CHAR_GLYPH)
     {
-      XFontStruct *font;
+      x_font_type *font;
       struct face *face;
       struct font_info *font_info;
       XChar2b char2b;
@@ -18588,7 +18588,7 @@
       font = face->font;
       font_info = FONT_INFO_FROM_ID (f, face->font_info_id);
       if (font  /* ++KFS: Should this be font_info ?  */
-         && (pcm = rif->per_char_metric (font, &char2b, glyph->font_type)))
+         && (pcm = rif->per_char_metric (f, font, &char2b, glyph->font_type)))
        {
          if (pcm->rbearing > pcm->width)
            *right = pcm->rbearing - pcm->width;
@@ -19584,7 +19584,7 @@
   int ascent = 0;
   double tem;
   struct face *face = FACE_FROM_ID (it->f, it->face_id);
-  XFontStruct *font = face->font ? face->font : FRAME_FONT (it->f);
+  x_font_type *font = face->font ? face->font : FRAME_FONT (it->f);
 
   PREPARE_FACE_FOR_DISPLAY (it->f, face);
 
@@ -19735,7 +19735,7 @@
 calc_line_height_property (it, val, font, boff, override)
      struct it *it;
      Lisp_Object val;
-     XFontStruct *font;
+     x_font_type *font;
      int boff, override;
 {
   Lisp_Object face_name = Qnil;
@@ -19825,7 +19825,7 @@
   if (it->what == IT_CHARACTER)
     {
       XChar2b char2b;
-      XFontStruct *font;
+      x_font_type *font;
       struct face *face = FACE_FROM_ID (it->f, it->face_id);
       XCharStruct *pcm;
       int font_not_found_p;
@@ -19895,8 +19895,9 @@
 
          it->nglyphs = 1;
 
-         pcm = rif->per_char_metric (font, &char2b,
-                                     FONT_TYPE_FOR_UNIBYTE (font, 
it->char_to_display));
+         pcm = rif->per_char_metric (it->f, font, &char2b,
+                                     FONT_TYPE_FOR_UNIBYTE (font,
+                                                             
it->char_to_display));
 
          if (it->override_ascent >= 0)
            {
@@ -20126,7 +20127,7 @@
             from the charset width; this is what old redisplay code
             did.  */
 
-         pcm = rif->per_char_metric (font, &char2b,
+         pcm = rif->per_char_metric (it->f, font, &char2b,
                                      FONT_TYPE_FOR_MULTIBYTE (font, it->c));
 
          if (font_not_found_p || !pcm)
@@ -20187,7 +20188,7 @@
       /* Note: A composition is represented as one glyph in the
         glyph matrix.  There are no padding glyphs.  */
       XChar2b char2b;
-      XFontStruct *font;
+      x_font_type *font;
       struct face *face = FACE_FROM_ID (it->f, it->face_id);
       XCharStruct *pcm;
       int font_not_found_p;
@@ -20258,8 +20259,9 @@
 
          /* Initialize the bounding box.  */
          if (font_info
-             && (pcm = rif->per_char_metric (font, &char2b,
-                                             FONT_TYPE_FOR_MULTIBYTE (font, 
it->c))))
+             && (pcm = rif->per_char_metric (it->f, font, &char2b,
+                                             FONT_TYPE_FOR_MULTIBYTE (font,
+                                                                       
it->c))))
            {
              width = pcm->width;
              ascent = pcm->ascent;
@@ -20317,7 +20319,7 @@
                }
 
              if (font_info
-                 && (pcm = rif->per_char_metric (font, &char2b,
+                 && (pcm = rif->per_char_metric (it->f, font, &char2b,
                                                  FONT_TYPE_FOR_MULTIBYTE 
(font, ch))))
                {
                  width = pcm->width;
--- emacs-060112-102400/src/xfaces.c    2005-11-26 12:06:53.000000000 +0100
+++ emacs.xft/src/xfaces.c      2006-01-12 11:25:47.000000000 +0100
@@ -5246,7 +5246,6 @@
              x_free_gc (f, face->gc);
              face->gc = 0;
            }
-
          free_face_colors (f, face);
          x_destroy_bitmap (f, face->stipple);
        }
@@ -5269,6 +5268,30 @@
 #ifdef HAVE_WINDOW_SYSTEM
   xassert (FRAME_WINDOW_P (f));
 
+#ifdef HAVE_XFT
+  if (face->xft_draw == 0)
+    {
+      BLOCK_INPUT;
+      XColor colors[2];
+      face->xft_draw = XftDrawCreate (FRAME_X_DISPLAY (f),
+                                      FRAME_X_WINDOW (f),
+                                      FRAME_X_DISPLAY_INFO (f)->visual,
+                                      FRAME_X_DISPLAY_INFO (f)->cmap);
+      colors[0].pixel = face->xft_fg.pixel = face->foreground;
+      colors[1].pixel = face->xft_bg.pixel = face->background;
+      
+      XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->cmap,
+                    colors, 2);
+      face->xft_fg.color.alpha = face->xft_fg.color.alpha = 0xffff;
+      face->xft_fg.color.red = colors[0].red;
+      face->xft_fg.color.green = colors[0].green;
+      face->xft_fg.color.blue = colors[0].blue;
+      face->xft_bg.color.red = colors[1].red;
+      face->xft_bg.color.green = colors[1].green;
+      face->xft_bg.color.blue = colors[1].blue;
+      UNBLOCK_INPUT;
+    }
+#endif
   if (face->gc == 0)
     {
       XGCValues xgcv;
@@ -5280,18 +5303,24 @@
       xgcv.graphics_exposures = False;
 #endif
       /* The font of FACE may be null if we couldn't load it.  */
+      if (!face->font)
+        fprintf (stderr, "%s: font is NULL\n", __func__);
       if (face->font)
        {
 #ifdef HAVE_X_WINDOWS
+#ifndef HAVE_XFT
          xgcv.font = face->font->fid;
 #endif
+#endif
 #ifdef WINDOWSNT
          xgcv.font = face->font;
 #endif
 #ifdef MAC_OS
          xgcv.font = face->font;
 #endif
+#ifndef HAVE_XFT
          mask |= GCFont;
+#endif
        }
 
       BLOCK_INPUT;
@@ -5408,6 +5437,15 @@
       for (i = BASIC_FACE_ID_SENTINEL; i < c->used; ++i)
        {
          struct face *face = c->faces_by_id[i];
+#ifdef HAVE_XFT
+          if (face && face->xft_draw)
+            {
+              BLOCK_INPUT;
+              XftDrawDestroy (face->xft_draw);
+              UNBLOCK_INPUT;
+              face->xft_draw = 0;
+            }
+#endif
          if (face && face->gc)
            {
              x_free_gc (c->f, face->gc);
@@ -6681,6 +6719,9 @@
              }
          }
 
+#ifndef HAVE_XFT
+      /* KOKO: overstrike only works with non-aliased fonts.  How to figure
+         out if a font is aliased?  It is in the XFT properties.  */
       if (needs_overstrike)
        {
          enum xlfd_weight want_weight = specified[XLFD_WEIGHT];
@@ -6698,6 +6739,7 @@
                *needs_overstrike = 1;
            }
        }
+#endif
     }
 
   if (font_scalable_p (best))
@@ -6978,6 +7020,7 @@
   Lisp_Object attrs[LFACE_VECTOR_SIZE];
   Lisp_Object frame_font;
   struct face *face;
+  int do_font = 0;
 
   /* If the `default' face is not yet known, create it.  */
   lface = lface_from_face_name (f, Qdefault, 0);
@@ -6999,6 +7042,7 @@
       set_lface_from_font_name (f, lface, frame_font,
                                 f->default_face_done_p, 1);
       f->default_face_done_p = 1;
+      do_font = 1;
     }
 #endif /* HAVE_WINDOW_SYSTEM */
 
@@ -7068,6 +7112,11 @@
   check_lface (lface);
   bcopy (XVECTOR (lface)->contents, attrs, sizeof attrs);
   face = realize_face (c, attrs, 0, NULL, DEFAULT_FACE_ID);
+#ifdef HAVE_WINDOW_SYSTEM
+#warning "Must get face parameters and font cache right"
+  if (do_font)
+    face->font = FRAME_FONT (f);
+#endif
   return 1;
 }
 
--- emacs-060112-102400/src/xfns.c      2005-12-27 11:39:51.000000000 +0100
+++ emacs.xft/src/xfns.c        2006-01-12 11:25:47.000000000 +0100
@@ -2851,21 +2851,25 @@
      struct frame *f;
 {
   XGCValues gc_values;
-
+  unsigned mask;
   BLOCK_INPUT;
 
   /* Create the GCs of this frame.
      Note that many default values are used.  */
 
   /* Normal video */
+  mask = GCLineWidth | GCForeground | GCBackground;
+#ifndef HAVE_XFT
   gc_values.font = FRAME_FONT (f)->fid;
+  mask |= GCFont;
+#endif
   gc_values.foreground = f->output_data.x->foreground_pixel;
   gc_values.background = f->output_data.x->background_pixel;
   gc_values.line_width = 0;    /* Means 1 using fast algorithm.  */
   f->output_data.x->normal_gc
     = XCreateGC (FRAME_X_DISPLAY (f),
                 FRAME_X_WINDOW (f),
-                GCLineWidth | GCFont | GCForeground | GCBackground,
+                mask,
                 &gc_values);
 
   /* Reverse video style.  */
@@ -2874,7 +2878,7 @@
   f->output_data.x->reverse_gc
     = XCreateGC (FRAME_X_DISPLAY (f),
                 FRAME_X_WINDOW (f),
-                GCFont | GCForeground | GCBackground | GCLineWidth,
+                mask,
                 &gc_values);
 
   /* Cursor has cursor-color background, background-color foreground.  */
@@ -2885,10 +2889,14 @@
     = XCreateBitmapFromData (FRAME_X_DISPLAY (f),
                             FRAME_X_DISPLAY_INFO (f)->root_window,
                             cursor_bits, 16, 16);
+  mask = GCForeground | GCBackground
+    | GCFillStyle /* | GCStipple */ | GCLineWidth;
+#ifndef HAVE_XFT
+    mask |= GCFont;
+#endif
   f->output_data.x->cursor_gc
     = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-                (GCFont | GCForeground | GCBackground
-                 | GCFillStyle /* | GCStipple */ | GCLineWidth),
+                mask,
                 &gc_values);
 
   /* Reliefs.  */
@@ -3194,8 +3202,11 @@
 #ifdef USE_LUCID
   /* Prevent lwlib/xlwmenu.c from crashing because of a bug
      whereby it fails to get any font.  */
+#warning "xlwmenu_default_font??"
+#if 0
   xlwmenu_default_font = FRAME_FONT (f);
 #endif
+#endif
 
   x_default_parameter (f, parms, Qborder_width, make_number (2),
                       "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
--- emacs-060112-102400/src/xmenu.c     2005-12-23 00:30:36.000000000 +0100
+++ emacs.xft/src/xmenu.c       2006-01-12 11:25:47.000000000 +0100
@@ -1238,6 +1238,10 @@
       if (event.type == ButtonRelease
           && dpyinfo->display == event.xbutton.display)
         {
+         /* If the click is not on the menu, deactivate the menu.  */
+         if (x_any_window_to_frame (dpyinfo, event.xexpose.window))
+           popup_activated_flag = 0;
+           
           dpyinfo->grabbed &= ~(1 << event.xbutton.button);
 #ifdef USE_MOTIF /* Pretending that the event came from a
                     Btn1Down seems the only way to convince Motif to
--- emacs-060112-102400/src/xterm.c     2005-11-16 17:38:48.000000000 +0100
+++ emacs.xft/src/xterm.c       2006-01-12 11:25:47.000000000 +0100
@@ -336,7 +336,7 @@
 void x_wm_set_window_state P_ ((struct frame *, int));
 void x_wm_set_icon_pixmap P_ ((struct frame *, int));
 void x_initialize P_ ((void));
-static void x_font_min_bounds P_ ((XFontStruct *, int *, int *));
+static void x_font_min_bounds P_ ((x_font_type *, int *, int *));
 static int x_compute_min_glyph_bounds P_ ((struct frame *));
 static void x_update_end P_ ((struct frame *));
 static void XTframe_up_to_date P_ ((struct frame *));
@@ -822,8 +822,9 @@
    is not contained in the font.  */
 
 static XCharStruct *
-x_per_char_metric (font, char2b, font_type)
-     XFontStruct *font;
+x_per_char_metric (f, font, char2b, font_type)
+     FRAME_PTR f;
+     x_font_type *font;
      XChar2b *char2b;
      int font_type;  /* unused on X */
 {
@@ -832,6 +833,7 @@
 
   xassert (font && char2b);
 
+#ifndef HAVE_XFT
   if (font->per_char != NULL)
     {
       if (font->min_byte1 == 0 && font->max_byte1 == 0)
@@ -883,6 +885,23 @@
          && char2b->byte2 <= font->max_char_or_byte2)
        pcm = &font->max_bounds;
     }
+#else /* HAVE_XFT */
+  {
+    static XCharStruct xch;
+    XGlyphInfo xgl;
+    XftChar16 ch = char2b->byte2 | (char2b->byte1 << 8);
+    BLOCK_INPUT;
+    XftTextExtents16 (FRAME_X_DISPLAY (f), font, &ch, 1, &xgl);
+    UNBLOCK_INPUT;
+    xch.lbearing = -xgl.x;
+    xch.rbearing = xgl.width - xgl.x;
+    xch.width = xgl.xOff;
+    xch.ascent = xgl.y;
+    xch.descent = xgl.height - xgl.y;
+
+    pcm = &xch;
+  }
+#endif /* HAVE_XFT */
 
   return ((pcm == NULL
           || (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0))
@@ -901,7 +920,7 @@
      int *two_byte_p;
 {
   int charset = CHAR_CHARSET (c);
-  XFontStruct *font = font_info->font;
+  x_font_type *font = font_info->font;
 
   /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
      This may be either a program in a special encoder language or a
@@ -927,12 +946,16 @@
 
       ccl_driver (ccl, NULL, NULL, 0, 0, NULL);
 
+#ifdef HAVE_XFT
+      char2b->byte1 = ccl->reg[1], char2b->byte2 = ccl->reg[2];
+#else
       /* We assume that MSBs are appropriately set/reset by CCL
         program.  */
       if (font->max_byte1 == 0)        /* 1-byte font */
        char2b->byte1 = 0, char2b->byte2 = ccl->reg[1];
       else
        char2b->byte1 = ccl->reg[1], char2b->byte2 = ccl->reg[2];
+#endif
     }
   else if (font_info->encoding[charset])
     {
@@ -949,8 +972,12 @@
     }
 
   if (two_byte_p)
-    *two_byte_p = ((XFontStruct *) (font_info->font))->max_byte1 > 0;
-
+#ifdef HAVE_XFT
+    *two_byte_p = FcCharSetCount
+      (((x_font_type *) font_info->font)->charset) > 256;
+#else
+    *two_byte_p = ((x_font_type *) (font_info->font))->max_byte1 > 0;
+#endif
   return FONT_TYPE_UNKNOWN;
 }
 
@@ -992,7 +1019,7 @@
                                 int, int, int, XRectangle *));
 
 #if GLYPH_DEBUG
-static void x_check_font P_ ((struct frame *, XFontStruct *));
+static void x_check_font P_ ((struct frame *, x_font_type *));
 #endif
 
 
@@ -1034,9 +1061,12 @@
        }
 
       IF_DEBUG (x_check_font (s->f, s->font));
+      mask = GCForeground | GCBackground | GCGraphicsExposures;
+#ifndef HAVE_XFT
+      mask |= GCFont;
       xgcv.font = s->font->fid;
+#endif
       xgcv.graphics_exposures = False;
-      mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures;
 
       if (FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc)
        XChangeGC (s->display, FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc,
@@ -1085,9 +1115,12 @@
       xgcv.background = s->face->background;
       xgcv.foreground = s->face->foreground;
       IF_DEBUG (x_check_font (s->f, s->font));
+      mask = GCForeground | GCBackground | GCGraphicsExposures;
+#ifndef HAVE_XFT
+      mask |= GCFont;
       xgcv.font = s->font->fid;
+#endif
       xgcv.graphics_exposures = False;
-      mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures;
 
       if (FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc)
        XChangeGC (s->display, FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc,
@@ -1175,6 +1208,208 @@
 }
 
 
+#if HAVE_XFT
+/* XXX kludge - use the same font everywhere */
+static char *
+xft_pattern_name (char *pattern)
+{
+  static char *xft_pattern;
+
+  if (!xft_pattern)
+    {
+      if (*pattern == '-') return pattern;
+      xft_pattern = malloc (strlen (pattern) + 1);
+      strcpy (xft_pattern, pattern);
+    }
+  return xft_pattern;
+}
+
+static x_font_type *
+xft_font_open_name (Display *dpy, int screen, char *name)
+{
+    x_font_type *font;
+
+    /* name = xft_pattern_name (name); */
+    if (*name == '-') {
+       font = XftFontOpenXlfd (dpy, screen, name);
+       if (font)
+           return font;
+    }
+    return XftFontOpenName (dpy, screen, name);
+}
+
+static int
+xft_ndashes (char *pattern)
+{
+  int ndashes = 0;
+  while (*pattern)
+    if (*pattern++ == '-')
+      ++ndashes;
+  return ndashes;
+}
+
+static char *
+xft_pad_fields (char *pattern)
+{
+  int ndashes = xft_ndashes (pattern);
+  int add = 14 - ndashes;
+  char *new, *ret;
+
+  ret = new = malloc (strlen (pattern) + add * 2 + 1);
+  if (!new)
+    return NULL;
+  if (*pattern != '-') {
+    *new++ = '-';
+    add--;
+    ndashes++;
+  }
+  if (ndashes < 4) 
+    {
+      strcpy (new, pattern);
+      while (add--)
+       strcat (new, "-*");
+    }
+  else
+    {
+      char *third = pattern;
+      int n;
+
+      for (n = 0; n < 3; n++)
+       third = index (third, '-') + 1;
+
+      bcopy (pattern, new, third - pattern);
+      new[third - pattern] = '\0';
+      while (add--)
+       strcat (new, "*-");
+      strcat (new, third);
+    }
+  return new;
+}
+
+static char *
+xft_fillout_xlfd (char *pattern)
+{
+  char *fourteen = xft_pad_fields (pattern);
+  char *dash = fourteen;
+  int n;
+  static char numeric[14] = {
+    0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0
+  };
+
+
+  for (n = 0; n < 14; n++) {
+    dash = index (dash, '-') + 1;
+    if (numeric[n] && *dash == '*')
+      *dash = '0';
+  }
+  return fourteen;
+}
+
+static FcPattern *
+xft_name_parse (char *name)
+{
+    FcPattern  *pattern;
+    
+    if (*name == '-') {
+       char *full_xlfd = xft_fillout_xlfd (name);
+       pattern = XftXlfdParse (full_xlfd, FcFalse, FcFalse);
+       free (full_xlfd);
+       if (pattern)
+           return pattern;
+    }
+    return FcNameParse (name);
+}
+
+static char *
+xft_xlfd_weight_name (int weight)
+{
+    if (weight < (FC_WEIGHT_LIGHT + FC_WEIGHT_MEDIUM) / 2)
+       return "light";
+    if (weight < (FC_WEIGHT_MEDIUM + FC_WEIGHT_DEMIBOLD) / 2)
+       return "regular";
+    if (weight < (FC_WEIGHT_DEMIBOLD + FC_WEIGHT_BOLD) / 2)
+       return "demibold";
+    if (weight < (FC_WEIGHT_BOLD + FC_WEIGHT_BLACK) / 2)
+       return "demibold";
+    return "black";
+}
+
+static char *
+xft_xlfd_slant_name (int slant)
+{
+    if (slant < (FC_SLANT_ROMAN + FC_SLANT_ITALIC) / 2)
+       return "r";
+    if (slant < (FC_SLANT_ITALIC + FC_SLANT_OBLIQUE) / 2)
+       return "i";
+    return "o";
+}
+
+static char *
+xft_xlfd_unparse (FcPattern *pattern)
+{
+    char    *foundry;
+    char    *family;
+    int            weight;
+    char    *weight_name;
+    int            slant;
+    char    *slant_name;
+    double  pixel;
+    int            len;
+    char    *xlfd;
+
+    if (FcPatternGetString (pattern, FC_FOUNDRY, 0, (FcChar8 *) &foundry)
+        != FcResultMatch)
+       foundry = "*";
+    if (FcPatternGetString (pattern, FC_FAMILY, 0, (FcChar8 *) &family)
+        != FcResultMatch)
+       family = "*";
+    if (FcPatternGetInteger (pattern, FC_WEIGHT, 0, &weight) != FcResultMatch)
+       weight_name = "*";
+    else
+       weight_name = xft_xlfd_weight_name (weight);
+    if (FcPatternGetInteger (pattern, FC_SLANT, 0, &slant) != FcResultMatch)
+       slant_name = "*";
+    else
+       slant_name = xft_xlfd_slant_name (slant);
+    if (FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &pixel) != 
FcResultMatch)
+       pixel = 0.0;
+    if (pixel < 0.0)
+       pixel = 0;
+    if (pixel >= 10000)
+       pixel = 9999;
+    len = (strlen (foundry) + 
+          strlen (family) + 
+          strlen (weight_name) +
+          strlen (slant_name) + 
+          5 +                      /* pixel */
+          9 +                      /* stars */
+          14 +                     /* dashes */
+          1);                      /* null */
+    xlfd = malloc (len);
+    sprintf(xlfd, "-%s-%s-%s-%s-*-*-%d-*-*-*-*-0-*-*",
+           foundry, family, weight_name, slant_name,
+           (int) (pixel + 0.5));
+    return xlfd;
+}
+
+static char *
+xft_match_font (Display *dpy, int screen, char *name)
+{
+    FcPattern *pattern;
+    FcResult result;
+    FcPattern *match;
+    char      *xlfd;
+
+    pattern = xft_name_parse (name);
+    match = XftFontMatch (dpy, screen, pattern, &result);
+    FcPatternDestroy (pattern);
+    xlfd = xft_xlfd_unparse (match);
+    FcPatternDestroy (match);
+    return xlfd;
+}
+
+#endif
+
 /* RIF:
    Compute left and right overhang of glyph string S.  If S is a glyph
    string for a composition, assume overhangs don't exist.  */
@@ -1188,8 +1423,23 @@
     {
       XCharStruct cs;
       int direction, font_ascent, font_descent;
+#ifdef HAVE_XFT
+      XGlyphInfo xgl;
+      XftChar16 ch = s->char2b->byte2 | (s->char2b->byte1 << 8);
+      Display *dpy = s->display;
+      BLOCK_INPUT;
+      XftTextExtents16 (dpy, s->font, &ch, 1, &xgl);
+      UNBLOCK_INPUT;
+      cs.lbearing = -xgl.x;
+      cs.rbearing = xgl.width - xgl.x;
+      cs.width = xgl.xOff;
+      cs.ascent = xgl.y;
+      cs.descent = xgl.height - xgl.y;
+      
+#else
       XTextExtents16 (s->font, s->char2b, s->nchars, &direction,
                      &font_ascent, &font_descent, &cs);
+#endif
       s->right_overhang = cs.rbearing > cs.width ? cs.rbearing - cs.width : 0;
       s->left_overhang = cs.lbearing < 0 ? -cs.lbearing : 0;
     }
@@ -1300,6 +1550,41 @@
         XDrawImageString is usually faster than XDrawString.)  Always
         use XDrawImageString when drawing the cursor so that there is
         no chance that characters under a box cursor are invisible.  */
+#ifdef HAVE_XFT
+      /* KOKO: Always clear background for now, there are some redraw problems
+         otherwise.  */
+      if (1 || ! (s->for_overlaps
+                  || (s->background_filled_p && s->hl != DRAW_CURSOR)))
+        XftDrawRect (s->face->xft_draw,
+                     s->hl == DRAW_CURSOR ? &s->face->xft_fg : 
&s->face->xft_bg,
+                     s->x,
+                     s->y,
+                     s->width + s->right_overhang,
+                     s->height);
+
+      if (s->two_byte_p)
+        {
+          XftChar16 ch[s->nchars];
+          int i;
+          for (i = 0; i < s->nchars; ++i)
+            ch[i] = s->char2b[i].byte2 | (s->char2b[i].byte1 << 8);
+          XftDrawString16 (s->face->xft_draw,
+                           &s->face->xft_fg,
+                           s->face->font,
+                           x,
+                           s->ybase - boff,
+                           ch,
+                           s->nchars);
+        }
+      else
+        XftDrawString8 (s->face->xft_draw,
+                        &s->face->xft_fg,
+                        s->face->font,
+                        x,
+                        s->ybase - boff,
+                        char1b,
+                        s->nchars);
+#else
       if (s->for_overlaps
          || (s->background_filled_p && s->hl != DRAW_CURSOR))
        {
@@ -1320,7 +1605,9 @@
            XDrawImageString (s->display, s->window, s->gc, x,
                              s->ybase - boff, char1b, s->nchars);
        }
+#endif
 
+#ifndef HAVE_XFT
       if (s->face->overstrike)
        {
          /* For overstriking (to simulate bold-face), draw the
@@ -1332,6 +1619,7 @@
            XDrawString (s->display, s->window, s->gc, x + 1,
                         s->ybase - boff, char1b, s->nchars);
        }
+#endif
     }
 }
 
@@ -1368,6 +1656,7 @@
     {
       for (i = 0; i < s->nchars; i++, ++s->gidx)
        {
+#ifndef HAVE_XFT
          XDrawString16 (s->display, s->window, s->gc,
                         x + s->cmp->offsets[s->gidx * 2],
                         s->ybase - s->cmp->offsets[s->gidx * 2 + 1],
@@ -1377,6 +1666,7 @@
                           x + s->cmp->offsets[s->gidx * 2] + 1,
                           s->ybase - s->cmp->offsets[s->gidx * 2 + 1],
                           s->char2b + i, 1);
+#endif
        }
     }
 }
@@ -2672,7 +2962,9 @@
          int y;
 
          /* Get the underline thickness.  Default is 1 pixel.  */
+#ifndef HAVE_XFT
          if (!XGetFontProperty (s->font, XA_UNDERLINE_THICKNESS, &h))
+#endif
            h = 1;
 
          /* Get the underline position.  This is the recommended
@@ -2683,11 +2975,23 @@
             ROUND ((maximum descent) / 2), with
             ROUND(x) = floor (x + 0.5)  */
 
+#ifndef HAVE_XFT
          if (x_use_underline_position_properties
              && XGetFontProperty (s->font, XA_UNDERLINE_POSITION, &tem))
            y = s->ybase + (long) tem;
+#else
+          if (x_use_underline_position_properties)
+            {
+              tem = (float)s->font->descent/2.0+0.5;
+              y = s->ybase + (long) tem;
+            }
+#endif
          else if (s->face->font)
+#ifdef HAVE_XFT
+           y = s->ybase + (s->face->font->descent + 1) / 2;
+#else
            y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2;
+#endif
          else
            y = s->y + s->height - h;
 
@@ -7809,7 +8113,7 @@
   if (!fontp)
     return Qnil;
 
-  FRAME_FONT (f) = (XFontStruct *) (fontp->font);
+  FRAME_FONT (f) = (x_font_type *) (fontp->font);
   FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset;
   FRAME_FONTSET (f) = -1;
 
@@ -7835,13 +8139,14 @@
   /* Now make the frame display the given font.  */
   if (FRAME_X_WINDOW (f) != 0)
     {
+#ifndef HAVE_XFT
       XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->normal_gc,
                FRAME_FONT (f)->fid);
       XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->reverse_gc,
                FRAME_FONT (f)->fid);
       XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->cursor_gc,
                FRAME_FONT (f)->fid);
-
+#endif
       /* Don't change the size of a tip frame; there's no point in
         doing it because it's done in Fx_show_tip, and it leads to
         problems because the tip frame has no widget.  */
@@ -9307,6 +9612,10 @@
   int try_XLoadQueryFont = 0;
   int count;
   int allow_auto_scaled_font = 0;
+  int font_scalable_p = 0;
+#ifdef HAVE_XFT
+  int font_width = 0;
+#endif
 
   if (size < 0)
     {
@@ -9318,14 +9627,17 @@
   if (NILP (patterns))
     patterns = Fcons (pattern, Qnil);
 
+#ifndef HAVE_XFT
   if (maxnames == 1 && !size)
     /* We can return any single font matching PATTERN.  */
     try_XLoadQueryFont = 1;
+#endif
 
   for (; CONSP (patterns); patterns = XCDR (patterns))
     {
       int num_fonts;
       char **names = NULL;
+      char *name = NULL;
 
       pattern = XCAR (patterns);
       /* See if we cached the result for this particular query.
@@ -9347,10 +9659,12 @@
       BLOCK_INPUT;
       count = x_catch_errors (dpy);
 
+#ifndef HAVE_XFT
       if (try_XLoadQueryFont)
        {
-         XFontStruct *font;
+         x_font_type *font;
          unsigned long value;
+         int len;
 
          font = XLoadQueryFont (dpy, SDATA (pattern));
          if (x_had_errors_p (dpy))
@@ -9365,16 +9679,21 @@
              && XGetFontProperty (font, XA_FONT, &value))
            {
              char *name = (char *) XGetAtomName (dpy, (Atom) value);
-             int len = strlen (name);
-             char *tmp;
 
              /* 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)
                try_XLoadQueryFont = 0;
+           }
              else
+           try_XLoadQueryFont = 0;
+         if (font)
+            XFreeFont (dpy, font);
+          if (name)
                {
+             int len = strlen (name);
+             char *tmp;
                  num_fonts = 1;
                  names = (char **) alloca (sizeof (char *));
                  /* Some systems only allow alloca assigned to a
@@ -9384,15 +9703,22 @@
                  XFree (name);
                }
            }
-         else
-           try_XLoadQueryFont = 0;
-
-         if (font)
-           XFreeFont (dpy, font);
-       }
+#endif
 
       if (!try_XLoadQueryFont)
        {
+#if HAVE_XFT
+         char *full = xft_match_font (dpy, DefaultScreen (dpy), 
SDATA(pattern));
+         int len = strlen (full);
+         char *tmp;
+         num_fonts = 1;
+         names = (char **) alloca (sizeof (char *));
+         /* Some systems only allow alloca assigned to a
+            simple var.  */
+         tmp = (char *) alloca (len + 1);  names[0] = tmp;
+         bcopy (full, names[0], len + 1);
+         free (full);
+#else
          /* We try at least 10 fonts because XListFonts will return
             auto-scaled fonts at the head.  */
           if (maxnames < 0)
@@ -9424,6 +9750,7 @@
              names = NULL;
              x_clear_errors (dpy);
            }
+#endif
        }
 
       x_uncatch_errors (dpy, count);
@@ -9458,9 +9785,15 @@
                    else if (dashes == 12) /* AVERAGE_WIDTH field */
                      average_width = atoi (p);
                  }
+              font_scalable_p = dashes == 14 && average_width == 0 && resx != 
0;
 
-             if (allow_auto_scaled_font
-                 || dashes < 14 || average_width != 0 || resx == 0)
+#ifdef HAVE_XFT
+              if (width == 0)
+                width = font_width;
+              if (dashes != 14)
+                allow_auto_scaled_font = 1;
+#endif
+             if (allow_auto_scaled_font || ! font_scalable_p)                
                {
                  tem = build_string (names[i]);
                  if (NILP (Fassoc (tem, list)))
@@ -9479,12 +9812,14 @@
                }
            }
 
+#ifndef HAVE_XFT
          if (!try_XLoadQueryFont)
            {
              BLOCK_INPUT;
              XFreeFontNames (names);
              UNBLOCK_INPUT;
            }
+#endif
        }
 
       /* Now store the result in the cache.  */
@@ -9514,12 +9849,17 @@
            {
              /* Since we have not yet known the size of this font, we
                 must try slow function call XLoadQueryFont.  */
-             XFontStruct *thisinfo;
+             x_font_type *thisinfo;
 
              BLOCK_INPUT;
              count = x_catch_errors (dpy);
+#ifdef HAVE_XFT
+              thisinfo = xft_font_open_name (dpy, DefaultScreen (dpy),
+                                            SDATA (XCAR (tem)));
+#else
              thisinfo = XLoadQueryFont (dpy,
                                         SDATA (XCAR (tem)));
+#endif
              if (x_had_errors_p (dpy))
                {
                  /* This error is perhaps due to insufficient memory on X
@@ -9532,12 +9872,21 @@
 
              if (thisinfo)
                {
+#ifdef HAVE_XFT
+                 XSETCDR (tem,
+                           make_number (thisinfo->max_advance_width));
+#else
                  XSETCDR (tem,
                           (thisinfo->min_bounds.width == 0
                            ? make_number (0)
                            : make_number (thisinfo->max_bounds.width)));
+#endif
                  BLOCK_INPUT;
+#ifdef HAVE_XFT
+                  XftFontClose (dpy, thisinfo);
+#else
                  XFreeFont (dpy, thisinfo);
+#endif
                  UNBLOCK_INPUT;
                }
              else
@@ -9589,7 +9938,7 @@
 static void
 x_check_font (f, font)
      struct frame *f;
-     XFontStruct *font;
+     x_font_type *font;
 {
   int i;
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
@@ -9614,17 +9963,20 @@
 
 static INLINE void
 x_font_min_bounds (font, w, h)
-     XFontStruct *font;
+     x_font_type *font;
      int *w, *h;
 {
   *h = FONT_HEIGHT (font);
+#ifdef HAVE_XFT
+  *w = 0;
+#else
   *w = font->min_bounds.width;
-
+#endif
   /* Try to handle the case where FONT->min_bounds has invalid
      contents.  Since the only font known to have invalid min_bounds
      is fixed-width, use max_bounds if min_bounds seems to be invalid.  */
   if (*w <= 0)
-    *w = font->max_bounds.width;
+    *w = FONT_WIDTH(font);
 }
 
 
@@ -9640,7 +9992,7 @@
 {
   int i;
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
-  XFontStruct *font;
+  x_font_type *font;
   int old_width = dpyinfo->smallest_char_width;
   int old_height = dpyinfo->smallest_font_height;
 
@@ -9653,8 +10005,8 @@
        struct font_info *fontp = dpyinfo->font_table + i;
        int w, h;
 
-       font = (XFontStruct *) fontp->font;
-       xassert (font != (XFontStruct *) ~0);
+       font = (x_font_type *) fontp->font;
+       xassert (font != (x_font_type *) ~0);
        x_font_min_bounds (font, &w, &h);
 
        dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h);
@@ -9708,10 +10060,11 @@
   /* Load the font and add it to the table.  */
   {
     char *full_name;
-    XFontStruct *font;
+    x_font_type *font;
     struct font_info *fontp;
     unsigned long value;
     int i;
+    Display *dpy = FRAME_X_DISPLAY (f);
 
     /* If we have found fonts by x_list_font, load one of them.  If
        not, we still try to load a font by the name given as FONTNAME
@@ -9723,7 +10076,11 @@
 
     BLOCK_INPUT;
     count = x_catch_errors (FRAME_X_DISPLAY (f));
+#ifdef HAVE_XFT
+    font = xft_font_open_name (dpy, DefaultScreen (dpy), fontname);
+#else
     font = (XFontStruct *) XLoadQueryFont (FRAME_X_DISPLAY (f), fontname);
+#endif
     if (x_had_errors_p (FRAME_X_DISPLAY (f)))
       {
        /* This error is perhaps due to insufficient memory on X
@@ -9764,26 +10121,32 @@
     fontp->name = (char *) xmalloc (strlen (fontname) + 1);
     bcopy (fontname, fontp->name, strlen (fontname) + 1);
 
+#ifndef HAVE_XFT
     if (font->min_bounds.width == font->max_bounds.width)
       {
        /* Fixed width font.  */
        fontp->average_width = fontp->space_width = font->min_bounds.width;
       }
     else
+#endif
       {
        XChar2b char2b;
        XCharStruct *pcm;
 
        char2b.byte1 = 0x00, char2b.byte2 = 0x20;
-       pcm = x_per_char_metric (font, &char2b, 0);
+       pcm = x_per_char_metric (f, font, &char2b, 0);
        if (pcm)
          fontp->space_width = pcm->width;
        else
          fontp->space_width = FONT_WIDTH (font);
 
+#ifdef HAVE_XFT
+        fontp->average_width = 0;
+#else
        fontp->average_width
          = (XGetFontProperty (font, dpyinfo->Xatom_AVERAGE_WIDTH, &value)
             ? (long) value / 10 : 0);
+#endif
        if (fontp->average_width < 0)
          fontp->average_width = - fontp->average_width;
        if (fontp->average_width == 0)
@@ -9792,7 +10155,7 @@
              {
                int width = pcm->width;
                for (char2b.byte2 = 33; char2b.byte2 <= 126; char2b.byte2++)
-                 if ((pcm = x_per_char_metric (font, &char2b, 0)) != NULL)
+                 if ((pcm = x_per_char_metric (f, font, &char2b, 0)) != NULL)
                    width += pcm->width;
                fontp->average_width = width / 95;
              }
@@ -9803,6 +10166,7 @@
 
     /* Try to get the full name of FONT.  Put it in FULL_NAME.  */
     full_name = 0;
+#ifndef HAVE_XFT
     if (XGetFontProperty (font, XA_FONT, &value))
       {
        char *name = (char *) XGetAtomName (FRAME_X_DISPLAY (f), (Atom) value);
@@ -9829,13 +10193,13 @@
 
        XFree (name);
       }
-
+#endif
     if (full_name != 0)
       fontp->full_name = full_name;
     else
       fontp->full_name = fontp->name;
 
-    fontp->size = font->max_bounds.width;
+    fontp->size = FONT_WIDTH (font);
     fontp->height = FONT_HEIGHT (font);
 
     if (NILP (font_names))
@@ -9875,6 +10239,12 @@
        uses this font.  So, we set information in fontp->encoding[1]
        which is never used by any charset.  If mapping can't be
        decided, set FONT_ENCODING_NOT_DECIDED.  */
+#ifdef HAVE_XFT
+    fontp->encoding[1] = FONT_ENCODING_NOT_DECIDED;
+    fontp->baseline_offset = 0;
+    fontp->relative_compose = 0;
+    fontp->default_ascent = font->ascent;
+#else
     fontp->encoding[1]
       = (font->max_byte1 == 0
         /* 1-byte font */
@@ -9907,7 +10277,7 @@
     fontp->default_ascent
       = (XGetFontProperty (font, dpyinfo->Xatom_MULE_DEFAULT_ASCENT, &value)
         ? (long) value : 0);
-
+#endif
     /* Set global flag fonts_changed_p to non-zero if the font loaded
        has a character with a smaller width than any other character
        before, or if the font loaded has a smaller height than any
--- emacs-060112-102400/src/xterm.h     2005-12-02 15:57:10.000000000 +0100
+++ emacs.xft/src/xterm.h       2006-01-12 11:25:47.000000000 +0100
@@ -31,6 +31,16 @@
 #include <X11/Xatom.h>
 #include <X11/Xresource.h>
 
+#ifndef X_FONT_TYPE_DECL
+#define X_FONT_TYPE_DECL
+#ifdef HAVE_XFT
+#include <X11/Xft/Xft.h>
+typedef XftFont x_font_type;
+#else
+typedef XFontStruct x_font_type;
+#endif
+#endif /* not X_FONT_TYPE_DECL */
+
 #ifdef USE_X_TOOLKIT
 #include <X11/StringDefs.h>
 #include <X11/IntrinsicP.h>    /* CoreP.h needs this */
@@ -106,7 +116,11 @@
 #define WHITE_PIX_DEFAULT(f) WhitePixel (FRAME_X_DISPLAY (f), \
                                         XScreenNumberOfScreen (FRAME_X_SCREEN 
(f)))
 
+#ifdef HAVE_XFT
+#define FONT_WIDTH(f)  ((f)->max_advance_width)
+#else
 #define FONT_WIDTH(f)  ((f)->max_bounds.width)
+#endif
 #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
 #define FONT_BASE(f)    ((f)->ascent)
 #define FONT_DESCENT(f) ((f)->descent)
@@ -512,7 +526,7 @@
   int icon_bitmap;
 
   /* Default ASCII font of this frame.  */
-  XFontStruct *font;
+  x_font_type *font;
 
   /* The baseline offset of the default ASCII font.  */
   int baseline_offset;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]