]> code.delx.au - gnu-emacs/blobdiff - src/xftfont.c
(math-read-token): Read complement signed numbers.
[gnu-emacs] / src / xftfont.c
index aecf64974286f85df4118683414c7c830081a2a7..e66b538fa157231f50afd3dbc757a9a81252b0d6 100644 (file)
@@ -21,6 +21,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #include <stdio.h>
+#include <setjmp.h>
 #include <X11/Xlib.h>
 #include <X11/Xft/Xft.h>
 
@@ -159,7 +160,7 @@ xftfont_list (frame, spec)
      Lisp_Object spec;
 {
   Lisp_Object list = ftfont_driver.list (frame, spec), tail;
-  
+
   for (tail = list; CONSP (tail); tail = XCDR (tail))
     ASET (XCAR (tail), FONT_TYPE_INDEX, Qxft);
   return list;
@@ -256,7 +257,7 @@ xftfont_open (f, entity, pixel_size)
       else if (EQ (key, QChintstyle))
        {
          if (INTEGERP (val))
-           FcPatternAddInteger (pat, FC_RGBA, XINT (val));
+           FcPatternAddInteger (pat, FC_HINT_STYLE, XINT (val));
        }
       else if (EQ (key, QCrgba))
        {
@@ -271,20 +272,31 @@ xftfont_open (f, entity, pixel_size)
 
   FcPatternAddString (pat, FC_FILE, (FcChar8 *) SDATA (filename));
   FcPatternAddInteger (pat, FC_INDEX, XINT (index));
-                      
+
 
   BLOCK_INPUT;
+  /* Make sure that the Xrender extension is added before the Xft one.
+     Otherwise, the close-display hook set by Xft is called after the
+     one for Xrender, and the former tries to re-add the latter.  This
+     results in inconsistency of internal states and leads to X
+     protocol error when one reconnects to the same X server.
+     (Bug#1696)  */
+  {
+    int event_base, error_base;
+    XRenderQueryExtension (display, &event_base, &error_base);
+  }
   match = XftFontMatch (display, FRAME_X_SCREEN_NUMBER (f), pat, &result);
   FcPatternDestroy (pat);
   xftfont = XftFontOpenPattern (display, match);
-  ft_face = XftLockFace (xftfont);
-  UNBLOCK_INPUT;
-
-  if (! xftfont)
+  if (!xftfont)
     {
+      UNBLOCK_INPUT;
       XftPatternDestroy (match);
       return Qnil;
     }
+  ft_face = XftLockFace (xftfont);
+  UNBLOCK_INPUT;
+
   /* We should not destroy PAT here because it is kept in XFTFONT and
      destroyed automatically when XFTFONT is closed.  */
   font_object = font_make_object (VECSIZE (struct xftfont_info), entity, size);
@@ -335,7 +347,7 @@ xftfont_open (f, entity, pixel_size)
       font->space_width = extents.xOff;
       if (font->space_width <= 0)
        /* dirty workaround */
-       font->space_width = pixel_size; 
+       font->space_width = pixel_size;
       XftTextExtents8 (display, xftfont, ascii_printable + 1, 94, &extents);
       font->average_width = (font->space_width + extents.xOff) / 95;
     }
@@ -360,7 +372,7 @@ xftfont_open (f, entity, pixel_size)
       int upEM = ft_face->units_per_EM;
 
       font->underline_position = -ft_face->underline_position * size / upEM;
-      font->underline_thickness = -ft_face->underline_thickness * size / upEM;
+      font->underline_thickness = ft_face->underline_thickness * size / upEM;
       if (font->underline_thickness > 2)
        font->underline_position -= font->underline_thickness / 2;
     }
@@ -451,7 +463,7 @@ xftfont_done_face (f, face)
      struct face *face;
 {
   struct xftface_info *xftface_info;
-  
+
 #if 0
   /* This doesn't work if face->ascii_face doesn't use an Xft font. */
   if (face != face->ascii_face
@@ -467,16 +479,27 @@ xftfont_done_face (f, face)
     }
 }
 
+extern Lisp_Object Qja, Qko;
+
 static int
 xftfont_has_char (font, c)
      Lisp_Object font;
      int c;
 {
   struct xftfont_info *xftfont_info;
+  struct charset *cs = NULL;
+
+  if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qja)
+      && charset_jisx0208 >= 0)
+    cs = CHARSET_FROM_ID (charset_jisx0208);
+  else if (EQ (AREF (font, FONT_ADSTYLE_INDEX), Qko)
+      && charset_ksc5601 >= 0)
+    cs = CHARSET_FROM_ID (charset_ksc5601);
+  if (cs)
+    return (ENCODE_CHAR (cs, c) != CHARSET_INVALID_CODE (cs));
 
   if (FONT_ENTITY_P (font))
     return ftfont_driver.has_char (font, c);
-
   xftfont_info = (struct xftfont_info *) XFONT_OBJECT (font);
   return (XftCharExists (xftfont_info->display, xftfont_info->xftfont,
                         (FcChar32) c) == FcTrue);
@@ -490,7 +513,7 @@ xftfont_encode_char (font, c)
   struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
   unsigned code = XftCharIndex (xftfont_info->display, xftfont_info->xftfont,
                                (FcChar32) c);
-  
+
   return (code ? code : FONT_INVALID_CODE);
 }
 
@@ -523,7 +546,7 @@ static XftDraw *
 xftfont_get_xft_draw (f)
      FRAME_PTR f;
 {
-  XftDraw *xft_draw = font_get_frame_data (f, &xftfont_driver);;
+  XftDraw *xft_draw = font_get_frame_data (f, &xftfont_driver);
 
   if (! xft_draw)
     {