changeset 91909:a549624ad4bc

Include xterm.h. [HAVE_NTGUI]: Include w32term.h. [MAC_OS]: Include macterm.ch. (font_otf_ValueRecord): Use make_number. (font_finish_cache): Fix handling of reference count. (font_clear_cache): Update num_fonts. (font_open_entity): Update smallest_char_width and smallest_font_height of the frame. (font_close_object): Update num_fonts. (Fclear_font_cache): Fix finding the target cache data.
author Kenichi Handa <handa@m17n.org>
date Sun, 17 Feb 2008 02:03:58 +0000
parents 6916adc8df33
children 27249878ef44
files src/font.c
diffstat 1 files changed, 62 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/font.c	Sun Feb 17 02:03:44 2008 +0000
+++ b/src/font.c	Sun Feb 17 02:03:58 2008 +0000
@@ -40,6 +40,18 @@
 #include "fontset.h"
 #include "font.h"
 
+#ifdef HAVE_X_WINDOWS
+#include "xterm.h"
+#endif /* HAVE_X_WINDOWS */
+
+#ifdef HAVE_NTGUI
+#include "w32term.h"
+#endif /* HAVE_NTGUI */
+
+#ifdef MAC_OS
+#include "macterm.h"
+#endif /* MAC_OS */
+
 #ifndef FONT_DEBUG
 #define FONT_DEBUG
 #endif
@@ -1815,13 +1827,13 @@
   Lisp_Object val = Fmake_vector (make_number (8), Qnil);
 
   if (value_format & OTF_XPlacement)
-    ASET (val, 0, value_record->XPlacement);
+    ASET (val, 0, make_number (value_record->XPlacement));
   if (value_format & OTF_YPlacement)
-    ASET (val, 1, value_record->YPlacement);
+    ASET (val, 1, make_number (value_record->YPlacement));
   if (value_format & OTF_XAdvance)
-    ASET (val, 2, value_record->XAdvance);
+    ASET (val, 2, make_number (value_record->XAdvance));
   if (value_format & OTF_YAdvance)
-    ASET (val, 3, value_record->YAdvance);
+    ASET (val, 3, make_number (value_record->YAdvance));
   if (value_format & OTF_XPlaDevice)
     ASET (val, 4, font_otf_DeviceTable (&value_record->XPlaDevice));
   if (value_format & OTF_YPlaDevice)
@@ -2197,6 +2209,7 @@
     }
 }
 
+
 static void
 font_finish_cache (f, driver)
      FRAME_PTR f;
@@ -2211,17 +2224,15 @@
     cache = val, val = XCDR (val);
   xassert (! NILP (val));
   tmp = XCDR (XCAR (val));
+  XSETCAR (tmp, make_number (XINT (XCAR (tmp)) - 1));
   if (XINT (XCAR (tmp)) == 0)
     {
       font_clear_cache (f, XCAR (val), driver);
       XSETCDR (cache, XCDR (val));
     }
-  else
-    {
-      XSETCAR (tmp, make_number (XINT (XCAR (tmp)) - 1));
-    }
 }
 
+
 static Lisp_Object
 font_get_cache (f, driver)
      FRAME_PTR f;
@@ -2238,6 +2249,8 @@
   return val;
 }
 
+static int num_fonts;
+
 static void
 font_clear_cache (f, cache, driver)
      FRAME_PTR f;
@@ -2273,6 +2286,7 @@
 		      driver->close (f, font);
 		      p->pointer = NULL;
 		      p->integer = 0;
+		      num_fonts--;
 		    }
 		  if (driver->free_entity)
 		    driver->free_entity (entity);
@@ -2406,8 +2420,6 @@
   return entity;
 }
 
-static int num_fonts;
-
 
 /* Open a font of ENTITY and PIXEL_SIZE on frame F, and return the
    opened font object.  */
@@ -2419,7 +2431,7 @@
      int pixel_size;
 {
   struct font_driver_list *driver_list;
-  Lisp_Object objlist, size, val;
+  Lisp_Object objlist, size, val, font_object;
   struct font *font;
 
   size = AREF (entity, FONT_SIZE_INDEX);
@@ -2427,35 +2439,49 @@
   if (XINT (size) != 0)
     pixel_size = XINT (size);
 
+  font_object = Qnil;
   for (objlist = AREF (entity, FONT_OBJLIST_INDEX); CONSP (objlist);
        objlist = XCDR (objlist))
     {
       font = XSAVE_VALUE (XCAR (objlist))->pointer;
       if (font->pixel_size == pixel_size)
 	{
-	  XSAVE_VALUE (XCAR (objlist))->integer++;
-	  return XCAR (objlist);
+	  font_object = XCAR (objlist);
+	  XSAVE_VALUE (font_object)->integer++;
+	  break;
 	}
     }
 
-  xassert (FONT_ENTITY_P (entity));
-  val = AREF (entity, FONT_TYPE_INDEX);
-  for (driver_list = f->font_driver_list;
-       driver_list && ! EQ (driver_list->driver->type, val);
-       driver_list = driver_list->next);
-  if (! driver_list)
-    return Qnil;
-
-  font = driver_list->driver->open (f, entity, pixel_size);
-  if (! font)
-    return Qnil;
-  font->scalable = XINT (size) == 0;
-
-  val = make_save_value (font, 1);
-  ASET (entity, FONT_OBJLIST_INDEX,
-	Fcons (val, AREF (entity, FONT_OBJLIST_INDEX)));
-  num_fonts++;
-  return val;
+  if (NILP (font_object))
+    {
+      val = AREF (entity, FONT_TYPE_INDEX);
+      for (driver_list = f->font_driver_list;
+	   driver_list && ! EQ (driver_list->driver->type, val);
+	   driver_list = driver_list->next);
+      if (! driver_list)
+	return Qnil;
+
+      font = driver_list->driver->open (f, entity, pixel_size);
+      if (! font)
+	return Qnil;
+      font->scalable = XINT (size) == 0;
+
+      font_object = make_save_value (font, 1);
+      ASET (entity, FONT_OBJLIST_INDEX,
+	    Fcons (font_object, AREF (entity, FONT_OBJLIST_INDEX)));
+      num_fonts++;
+    }
+
+  if (FRAME_SMALLEST_CHAR_WIDTH (f) > font->min_width)
+    FRAME_SMALLEST_CHAR_WIDTH (f) = font->min_width;
+  if (FRAME_SMALLEST_CHAR_WIDTH (f) <= 0)
+    FRAME_SMALLEST_CHAR_WIDTH (f) = 1;
+  if (FRAME_SMALLEST_FONT_HEIGHT (f) > font->font.height)
+    FRAME_SMALLEST_FONT_HEIGHT (f) = font->font.height;
+  if (FRAME_SMALLEST_FONT_HEIGHT (f) <= 0)
+    FRAME_SMALLEST_FONT_HEIGHT (f) = 1;
+
+  return font_object;
 }
 
 
@@ -2470,8 +2496,8 @@
   Lisp_Object objlist;
   Lisp_Object tail, prev = Qnil;
 
+  xassert (XSAVE_VALUE (font_object)->integer > 0);
   XSAVE_VALUE (font_object)->integer--;
-  xassert (XSAVE_VALUE (font_object)->integer >= 0);
   if (XSAVE_VALUE (font_object)->integer > 0)
     return;
 
@@ -2487,6 +2513,7 @@
 	  ASET (font->entity, FONT_OBJLIST_INDEX, XCDR (objlist));
 	else
 	  XSETCDR (prev, XCDR (objlist));
+	num_fonts--;
 	return;
       }
   abort ();
@@ -3364,8 +3391,10 @@
 	    Lisp_Object val;
 	    
 	    val = XCDR (cache);
-	    while (! EQ (XCAR (val), driver_list->driver->type))
+	    while (! NILP (val)
+		   && ! EQ (XCAR (XCAR (val)), driver_list->driver->type))
 	      val = XCDR (val);
+	    xassert (! NILP (val));
 	    val = XCDR (XCAR (val));
 	    if (XINT (XCAR (val)) == 0)
 	      {