Generalize and cleanup font subsystem checks.
[bpt/emacs.git] / src / xftfont.c
index dc82c28..2f81253 100644 (file)
@@ -1,6 +1,6 @@
 /* xftfont.c -- XFT font driver.
-   Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
-   Copyright (C) 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2006-2012 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H13PRO009
 
@@ -32,6 +32,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "blockinput.h"
 #include "character.h"
 #include "charset.h"
+#include "composite.h"
 #include "fontset.h"
 #include "font.h"
 #include "ftfont.h"
@@ -186,17 +187,20 @@ xftfont_fix_match (FcPattern *pat, FcPattern *match)
   double dpi;
 
   FcPatternGetBool (pat, FC_ANTIALIAS, 0, &b);
-  if (! b) 
+  if (! b)
     {
       FcPatternDel (match, FC_ANTIALIAS);
       FcPatternAddBool (match, FC_ANTIALIAS, FcFalse);
     }
   FcPatternGetBool (pat, FC_HINTING, 0, &b);
-  if (! b) 
+  if (! b)
     {
       FcPatternDel (match, FC_HINTING);
       FcPatternAddBool (match, FC_HINTING, FcFalse);
     }
+#ifndef FC_HINT_STYLE
+# define FC_HINT_STYLE "hintstyle"
+#endif
   if (FcResultMatch == FcPatternGetInteger (pat, FC_HINT_STYLE, 0, &i))
     {
       FcPatternDel (match, FC_HINT_STYLE);
@@ -276,7 +280,7 @@ xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
 {
   FcResult result;
   Display *display = FRAME_X_DISPLAY (f);
-  Lisp_Object val, filename, index, font_object;
+  Lisp_Object val, filename, idx, font_object;
   FcPattern *pat = NULL, *match;
   struct xftfont_info *xftfont_info = NULL;
   struct font *font;
@@ -294,7 +298,7 @@ xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
     return Qnil;
   val = XCDR (val);
   filename = XCAR (val);
-  index = XCDR (val);
+  idx = XCDR (val);
   size = XINT (AREF (entity, FONT_SIZE_INDEX));
   if (size == 0)
     size = pixel_size;
@@ -331,7 +335,7 @@ xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
   xftfont_add_rendering_parameters (pat, entity);
 
   FcPatternAddString (pat, FC_FILE, (FcChar8 *) SDATA (filename));
-  FcPatternAddInteger (pat, FC_INDEX, XINT (index));
+  FcPatternAddInteger (pat, FC_INDEX, XINT (idx));
 
 
   BLOCK_INPUT;
@@ -405,12 +409,16 @@ xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
     spacing = FC_PROPORTIONAL;
   if (! ascii_printable[0])
     {
-      int i;
-      for (i = 0; i < 95; i++)
-       ascii_printable[i] = ' ' + i;
+      int ch;
+      for (ch = 0; ch < 95; ch++)
+       ascii_printable[ch] = ' ' + ch;
     }
   BLOCK_INPUT;
-  if (spacing != FC_PROPORTIONAL && spacing != FC_DUAL)
+  if (spacing != FC_PROPORTIONAL
+#ifdef FC_DUAL
+      && spacing != FC_DUAL
+#endif /* FC_DUAL */
+      )
     {
       font->min_width = font->average_width = font->space_width
        = xftfont->max_advance_width;
@@ -519,7 +527,7 @@ xftfont_prepare_face (FRAME_PTR f, struct face *face)
     }
 #endif
 
-  xftface_info = malloc (sizeof (struct xftface_info));
+  xftface_info = malloc (sizeof *xftface_info);
   if (! xftface_info)
     return -1;
   xftfont_get_colors (f, face, face->gc, NULL,
@@ -614,8 +622,7 @@ xftfont_get_xft_draw (FRAME_PTR f)
                               FRAME_X_VISUAL (f),
                               FRAME_X_COLORMAP (f));
       UNBLOCK_INPUT;
-      if (! xft_draw)
-       abort ();
+      eassert (xft_draw != NULL);
       font_put_frame_data (f, &xftfont_driver, xft_draw);
     }
   return xft_draw;
@@ -646,7 +653,7 @@ xftfont_draw (struct glyph_string *s, int from, int to, int x, int y, int with_b
 
   if (with_background)
     XftDrawRect (xft_draw, &bg,
-                x, y - face->font->ascent, s->width, face->font->height);
+                x, y - s->font->ascent, s->width, s->font->height);
   code = alloca (sizeof (FT_UInt) * len);
   for (i = 0; i < len; i++)
     code[i] = ((XCHAR2B_BYTE1 (s->char2b + from + i) << 8)
@@ -664,6 +671,25 @@ xftfont_draw (struct glyph_string *s, int from, int to, int x, int y, int with_b
   return len;
 }
 
+#if defined HAVE_M17N_FLT && defined HAVE_LIBOTF
+static Lisp_Object
+xftfont_shape (Lisp_Object lgstring)
+{
+  struct font *font;
+  struct xftfont_info *xftfont_info;
+  FT_Face ft_face;
+  Lisp_Object val;
+
+  CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring), font);
+  xftfont_info = (struct xftfont_info *) font;
+  ft_face = XftLockFace (xftfont_info->xftfont);
+  xftfont_info->ft_size = ft_face->size;
+  val = ftfont_driver.shape (lgstring);
+  XftUnlockFace (xftfont_info->xftfont);
+  return val;
+}
+#endif
+
 static int
 xftfont_end_for_frame (FRAME_PTR f)
 {
@@ -753,9 +779,9 @@ syms_of_xftfont (void)
   xftfont_driver.draw = xftfont_draw;
   xftfont_driver.end_for_frame = xftfont_end_for_frame;
   xftfont_driver.cached_font_ok = xftfont_cached_font_ok;
+#if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF)
+  xftfont_driver.shape = xftfont_shape;
+#endif
 
   register_font_driver (&xftfont_driver, NULL);
 }
-
-/* arch-tag: 64ec61bf-7c8e-4fe6-b953-c6a85d5e1605
-   (do not change this comment) */