changeset 90555:45553626fa76

(ftfont_open): Set font->font.full_name and font->font.name properly. Fix calculation of font->font.height and font->min_width.
author Kenichi Handa <handa@m17n.org>
date Fri, 28 Jul 2006 12:45:58 +0000
parents d0351223b22a
children e56a86aa94cc
files src/ftfont.c
diffstat 1 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ftfont.c	Fri Jul 28 12:44:45 2006 +0000
+++ b/src/ftfont.c	Fri Jul 28 12:45:58 2006 +0000
@@ -629,6 +629,8 @@
   FcPattern *pattern;
   FcChar8 *file;
   int spacing;
+  char *name;
+  int len;
 
   val = AREF (entity, FONT_EXTRA_INDEX);
   if (XTYPE (val) != Lisp_Misc
@@ -681,15 +683,28 @@
   font->entity = entity;
   font->pixel_size = size;
   font->driver = &ftfont_driver;
-  font->font.name = font->font.full_name = NULL;
+  len = 96;
+  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;
+    }
+  font->font.full_name = font->font.name = name;
   font->file_name = (char *) file;
   font->font.size = ft_face->size->metrics.max_advance >> 6;
+  if (font->font.size <= 0)
+    font->font.size = size;
   font->font.charset = font->encoding_charset = font->repertory_charset = -1;
   font->ascent = ft_face->size->metrics.ascender >> 6;
   font->descent = - ft_face->size->metrics.descender >> 6;
-  font->font.height = ft_face->size->metrics.height >> 6;
-  if (FcPatternGetInteger (pattern, FC_SPACING, 0, &spacing) != FcResultMatch
-      || spacing != FC_PROPORTIONAL)
+  font->font.height = font->ascent + font->descent;
+  if (FcPatternGetInteger (pattern, FC_SPACING, 0, &spacing) != FcResultMatch)
+    spacing = FC_PROPORTIONAL;
+  if (spacing != FC_PROPORTIONAL)
     font->font.average_width = font->font.space_width = font->font.size;
   else
     {
@@ -716,6 +731,10 @@
 	}
     }
 
+  /* Unfortunately FreeType doesn't provide a way to get minimum char
+     width.  So, we use space_width instead.  */
+  font->min_width = font->font.space_width;
+
   font->font.baseline_offset = 0;
   font->font.relative_compose = 0;
   font->font.default_ascent = 0;