From: Adrian Robert Date: Wed, 1 Oct 2008 17:15:16 +0000 (+0000) Subject: * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfon... X-Git-Tag: emacs-pretest-23.0.90~2690 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8d0e382ee4161edb2a109fb14e3089a9169ca0ef;p=emacs.git * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal styles. (nsfont_open): Reenable the cache. --- diff --git a/src/ChangeLog b/src/ChangeLog index 8603222ea32..eb667c7a0ce 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2008-10-01 Adrian Robert + + * nsfont.m (nsfont_spec_to_traits): Use UnXX masks only for non-normal + styles. + (nsfont_open): Reenable the cache. + 2008-10-01 Adrian Robert * font.c (font_matching_entity): Reflect ATTRS in font selection. diff --git a/src/font.c b/src/font.c index 816ce9a674f..fa179d624b5 100644 --- a/src/font.c +++ b/src/font.c @@ -2770,9 +2770,9 @@ font_matching_entity (f, attrs, spec) 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))); + if (FLOATP (size)) + 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 @@ font_matching_entity (f, attrs, spec) if (! NILP (entity)) break; } - ASET (spec, FONT_TYPE_INDEX, ftype); - ASET (spec, FONT_SIZE_INDEX, size); font_add_log ("match", work, entity); return entity; } diff --git a/src/nsfont.m b/src/nsfont.m index 813b04be662..7adced73c12 100644 --- a/src/nsfont.m +++ b/src/nsfont.m @@ -121,20 +121,18 @@ nsfont_spec_to_traits (Lisp_Object font_spec) 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 @@ nsfont_match (Lisp_Object frame, Lisp_Object font_spec) 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 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) 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 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) } } -//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 @@ fprintf (stderr, "*** CACHE HIT!\n"); 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];