changeset 90460:86449661f321

(xftfont_open): Change coding style of error handling. Generate fontconfig's fontname pattern.
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Jun 2006 12:12:49 +0000
parents 81011b9fc603
children 2457d1153a8b
files src/xftfont.c
diffstat 1 files changed, 30 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/xftfont.c	Fri Jun 16 12:11:19 2006 +0000
+++ b/src/xftfont.c	Fri Jun 16 12:12:49 2006 +0000
@@ -196,14 +196,15 @@
   Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
   Display *display = FRAME_X_DISPLAY (f);
   Lisp_Object val;
-  FcPattern *pattern, *pat;
-  FcChar8 *file, *name;
-  XFontStruct *xfont;
-  struct xftfont_info *xftfont_info;
+  FcPattern *pattern, *pat = NULL;
+  FcChar8 *file;
+  struct xftfont_info *xftfont_info = NULL;
+  XFontStruct *xfont = NULL;
   struct font *font;
   double size = 0;
-  XftFont *xftfont;
+  XftFont *xftfont = NULL;
   int spacing;
+  char *name;
   int len;
 
   val = AREF (entity, FONT_EXTRA_INDEX);
@@ -217,15 +218,6 @@
   size = XINT (AREF (entity, FONT_SIZE_INDEX));
   if (size == 0)
     size = pixel_size;
-  if (FcPatternGetString (pattern, FC_FILE, 1, &name) != FcResultMatch)
-    {
-      int isize = size;
-
-      name = malloc (strlen ((char *) file) + 30);
-      if (! name)
-	return NULL;
-      sprintf (name, ":file=%s:pixelsize=%d", (char *) file, isize);
-    }
 
   pat = FcPatternCreate ();
   FcPatternAddString (pat, FC_FILE, file);
@@ -237,26 +229,14 @@
   /* We should not destroy PAT here because it is kept in XFTFONT and
      destroyed automatically when XFTFONT is closed.  */
   if (! xftfont)
-    {
-      UNBLOCK_INPUT;
-      return NULL;
-    }
+    goto err;
 
   xftfont_info = malloc (sizeof (struct xftfont_info));
   if (! xftfont_info)
-    {
-      XftFontClose (display, xftfont);
-      UNBLOCK_INPUT;
-      return NULL;
-    }
+    goto err;
   xfont = malloc (sizeof (XFontStruct));
-  if (! xftfont_info)
-    {
-      XftFontClose (display, xftfont);
-      free (xftfont_info);
-      UNBLOCK_INPUT;
-      return NULL;
-    }
+  if (! xfont)
+    goto err;
   xftfont_info->display = display;
   xftfont_info->screen = FRAME_X_SCREEN_NUMBER (f);
   xftfont_info->xftfont = xftfont;
@@ -266,7 +246,19 @@
   font->entity = entity;
   font->pixel_size = size;
   font->driver = &xftfont_driver;
-  font->font.full_name = font->font.name = (char *) name;
+  len = 64;
+  name = malloc (len);
+  while (name && font_unparse_fcname (entity, pixel_size, name, len) < 0)
+    {
+      char *new = realloc (name, len += 32);
+
+      if (! new)
+	free (name);
+      name = new;
+    }
+  if (! name)
+    goto err;
+  font->font.full_name = font->font.name = name;
   font->file_name = (char *) file;
   font->font.size = xftfont->max_advance_width;
   font->ascent = xftfont->ascent;
@@ -341,6 +333,13 @@
     }
 
   return font;
+
+ err:
+  if (xftfont) XftFontClose (display, xftfont);
+  UNBLOCK_INPUT;
+  if (xftfont_info) free (xftfont_info);
+  if (xfont) free (xfont);
+  return NULL;
 }
 
 static void