changeset 98451:db015b441c0c

* nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache.
author Adrian Robert <Adrian.B.Robert@gmail.com>
date Wed, 01 Oct 2008 17:12:49 +0000
parents af59ad63b531
children 3984a4da51ca
files src/ChangeLog src/font.c src/nsfont.m
diffstat 3 files changed, 41 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Oct 01 16:23:28 2008 +0000
+++ b/src/ChangeLog	Wed Oct 01 17:12:49 2008 +0000
@@ -1,3 +1,7 @@
+2008-10-01  Adrian Robert  <Adrian.B.Robert@gmail.com>
+
+	* nsfont.m (nsfont_open): Reenable the cache.
+
 2008-10-01  Adrian Robert  <Adrian.B.Robert@gmail.com>
 
 	* font.c (font_matching_entity): Reflect ATTRS in font selection.
--- a/src/font.c	Wed Oct 01 16:23:28 2008 +0000
+++ b/src/font.c	Wed Oct 01 17:12:49 2008 +0000
@@ -2770,9 +2770,9 @@
   XSETFRAME (frame, f);
   ftype = AREF (spec, FONT_TYPE_INDEX);
   size = AREF (spec, FONT_SIZE_INDEX);
+
   if (FLOATP (size))
-    ASET (spec, FONT_SIZE_INDEX, make_number (font_pixel_size (f, spec)));
-
+    ASET (work, FONT_SIZE_INDEX, make_number (font_pixel_size (f, spec)));
   FONT_SET_STYLE (work, FONT_WEIGHT_INDEX, attrs[LFACE_WEIGHT_INDEX]);
   FONT_SET_STYLE (work, FONT_SLANT_INDEX, attrs[LFACE_SLANT_INDEX]);
   FONT_SET_STYLE (work, FONT_WIDTH_INDEX, attrs[LFACE_SWIDTH_INDEX]);
@@ -2799,8 +2799,6 @@
 	if (! NILP (entity))
 	  break;
       }
-  ASET (spec, FONT_TYPE_INDEX, ftype);
-  ASET (spec, FONT_SIZE_INDEX, size);
   font_add_log ("match", work, entity);
   return entity;
 }
--- a/src/nsfont.m	Wed Oct 01 16:23:28 2008 +0000
+++ b/src/nsfont.m	Wed Oct 01 17:12:49 2008 +0000
@@ -121,20 +121,18 @@
 
   n = FONT_WEIGHT_NUMERIC (font_spec);
   if (n != -1)
-      traits |= (n > STYLE_REF) ? NSBoldFontMask : NSUnboldFontMask;
+      traits |= (n > STYLE_REF) ? NSBoldFontMask
+        			: (n < STYLE_REF) ? NSUnboldFontMask : 0;
 
   n = FONT_SLANT_NUMERIC (font_spec);
   if (n != -1)
-      traits |= (n > STYLE_REF) ? NSItalicFontMask : NSUnitalicFontMask;
+      traits |= (n > STYLE_REF) ? NSItalicFontMask
+        			: (n < STYLE_REF) ? NSUnitalicFontMask : 0;
 
   n = FONT_WIDTH_NUMERIC (font_spec);
   if (n > -1)
-    {
-      if (n < STYLE_REF - 10)
-        traits |= NSCondensedFontMask;
-      else if (n > STYLE_REF + 10)
-        traits |= NSExpandedFontMask;
-    }
+      traits |= (n > STYLE_REF + 10) ? NSExpandedFontMask
+       			 	: (n < STYLE_REF - 10) ? NSExpandedFontMask : 0;
 
 /*fprintf (stderr, "  returning traits = %u\n", traits); */
   return traits;
@@ -377,7 +375,7 @@
     fprintf (stderr, "adstyle: '%s'\n", SDATA (tem));
 #endif
   tem = AREF (font_spec, FONT_REGISTRY_INDEX);
-  if (!EQ (tem, Qiso10646_1) && !EQ (tem, Qunicode_bmp))
+  if (!NILP (tem) && !EQ (tem, Qiso10646_1) && !EQ (tem, Qunicode_bmp))
     return nsfont_fallback_entity ();
 
   family = nsfont_get_family (font_spec);
@@ -500,26 +498,17 @@
   Lisp_Object font_object;
   int i;
   int fixLeopardBug;
-#if 0
   static NSMutableDictionary *fontCache = nil;
+  NSNumber *cached;
 
   /* 2008/03/08: The same font may end up being requested for different
      entities, due to small differences in numeric values or other issues,
      or for different copies of the same entity.  Therefore we cache to
      avoid creating multiple struct font objects (with metrics cache, etc.)
      for the same NSFont object.
-     2008/06/01: This is still an issue, but after font backend refactoring
-     caching will be more difficult, needs to be reworked before enabling. */
+     2008/06/01: This is still an issue after font backend refactoring. */
   if (fontCache == nil)
     fontCache = [[NSMutableDictionary alloc] init];
-#endif
-
-  font_object = font_make_object (VECSIZE (struct nsfont_info), font_entity,
-                                  pixel_size);
-  font_info = (struct nsfont_info *) XFONT_OBJECT (font_object);
-  font = (struct font *)font_info;
-  if (!font)
-    return Qnil; /* FIXME: this copies w32, but causes a segfault */
 
   if (NSFONT_TRACE)
     {
@@ -577,28 +566,32 @@
         }
     }
 
-//NSLog(@"%@\n",nsfont);
+  if (NSFONT_TRACE)
+    NSLog (@"%@\n", nsfont);
 
-#if 0
-  {
-    NSNumber *cached = [fontCache objectForKey: nsfont];
-    if (cached != nil && !synthItal)
-      {
-fprintf (stderr, "*** CACHE HIT!\n");
-        struct font_info *existing =
-          (struct nsfont_info *)[cached unsignedLongValue];
-        /* ... */
-      }
-    else
-      {
-        if (!synthItal)
-          [fontCache
-            setObject: [NSNumber numberWithUnsignedLong:
-                                   (unsigned long)font_info]
-               forKey: nsfont];
-      }
-  }
-#endif
+  /* Check the cache */
+  cached = [fontCache objectForKey: nsfont];
+  if (cached != nil && !synthItal)
+    {
+      if (NSFONT_TRACE)
+        fprintf(stderr, "*** nsfont_open CACHE HIT!\n");
+      return (Lisp_Object)[cached unsignedLongValue];
+    }
+  else
+    {
+      font_object = font_make_object (VECSIZE (struct nsfont_info),
+                                      font_entity, pixel_size);
+      if (!synthItal)
+        [fontCache
+          setObject: [NSNumber numberWithUnsignedLong:
+                                 (unsigned long)font_object]
+          forKey: nsfont];
+    }
+
+  font_info = (struct nsfont_info *) XFONT_OBJECT (font_object);
+  font = (struct font *)font_info;
+  if (!font)
+    return Qnil; /* FIXME: other terms do, but return Qnil causes segfault */
 
   font_info->glyphs = (unsigned short **)
     xmalloc (0x100 * sizeof (unsigned short *));
@@ -609,8 +602,7 @@
   bzero (font_info->glyphs, 0x100 * sizeof (unsigned short *));
   bzero (font_info->metrics, 0x100 * sizeof (struct font_metrics *));
 
-
-BLOCK_INPUT;
+  BLOCK_INPUT;
 
   /* for metrics */
   sfont = [nsfont screenFont];