Fix resizing for X and non-Gtk+ build. Bug #5848.
[bpt/emacs.git] / src / nsfont.m
index 60e217f..59d5ee7 100644 (file)
@@ -1,6 +1,6 @@
 /* Font back-end driver for the NeXT/Open/GNUstep and MacOSX window system.
    See font.h
-   Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -23,6 +23,7 @@ Author: Adrian Robert (arobert@cogsci.ucsd.edu)
 /* This should be the first include, as it may set up #defines affecting
    interpretation of even the system includes. */
 #include "config.h"
+#include <setjmp.h>
 
 #include "lisp.h"
 #include "dispextern.h"
@@ -49,7 +50,7 @@ extern Lisp_Object Qnormal, Qbold, Qitalic, Qcondensed, Qexpanded;
 static Lisp_Object Vns_reg_to_script;
 static Lisp_Object Qapple, Qroman, Qmedium;
 extern Lisp_Object Qappend;
-extern int ns_antialias_text;
+extern Lisp_Object ns_antialias_text;
 extern float ns_antialias_threshold;
 extern int ns_tmp_flags;
 extern struct nsfont_info *ns_tmp_font;
@@ -244,7 +245,11 @@ ns_char_width (NSFont *sfont, int c)
            return w;
       }
 #endif
-    w = [sfont widthOfString: cstr];
+    {
+      NSDictionary *attrsDictionary =
+        [NSDictionary dictionaryWithObject: sfont forKey: NSFontAttributeName];
+      w = [cstr sizeWithAttributes: attrsDictionary].width;
+    }
     return max (w, 2.0);
 }
 
@@ -543,7 +548,8 @@ ns_findfonts (Lisp_Object font_spec, BOOL isMatch)
       return ns_fallback_entity ();
 
     if (NSFONT_TRACE)
-       fprintf (stderr, "    Returning %d entities.\n", XINT (Flength (list)));
+       fprintf (stderr, "    Returning %ld entities.\n",
+                 (long) XINT (Flength (list)));
 
     return list;
 }
@@ -649,8 +655,8 @@ nsfont_list_family (Lisp_Object frame)
   /* FIXME: escape the name? */
 
   if (NSFONT_TRACE)
-    fprintf (stderr, "nsfont: list families returning %d entries\n",
-            XINT (Flength (list)));
+    fprintf (stderr, "nsfont: list families returning %ld entries\n",
+            (long) XINT (Flength (list)));
 
   return list;
 }
@@ -838,8 +844,10 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
     /* max bounds */
     font_info->max_bounds.ascent =
       lrint (hshrink * [sfont ascender] + expand * hd/2);
+    /* [sfont descender] is usually negative.  Use floor to avoid
+       clipping descenders. */
     font_info->max_bounds.descent =
-      -lrint (hshrink* [sfont descender] - expand*hd/2);
+      -lrint (floor(hshrink* [sfont descender] - expand*hd/2));
     font_info->height =
       font_info->max_bounds.ascent + font_info->max_bounds.descent;
     font_info->max_bounds.width = lrint (font_info->width);
@@ -874,9 +882,9 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
 #endif
 
     /* set up metrics portion of font struct */
-    font->ascent = [sfont ascender];
-    font->descent = -[sfont descender];
-    font->min_width = [sfont widthOfString: @"|"]; /* FIXME */
+    font->ascent = lrint([sfont ascender]);
+    font->descent = -lrint(floor([sfont descender]));
+    font->min_width = ns_char_width(sfont, '|');
     font->space_width = lrint (ns_char_width (sfont, ' '));
     font->average_width = lrint (font_info->width);
     font->max_width = lrint (font_info->max_bounds.width);
@@ -1223,7 +1231,7 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
 
     CGContextSetFont (gcontext, font->cgfont);
     CGContextSetFontSize (gcontext, font->size);
-    if (ns_antialias_text == Qnil || font->size <= ns_antialias_threshold)
+    if (NILP (ns_antialias_text) || font->size <= ns_antialias_threshold)
       CGContextSetShouldAntialias (gcontext, 0);
     else
       CGContextSetShouldAntialias (gcontext, 1);
@@ -1332,7 +1340,7 @@ ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
     NSGlyphGenerator *glyphGenerator = [NSGlyphGenerator sharedGlyphGenerator];
     /*NSCharacterSet *coveredChars = [nsfont coveredCharacterSet]; */
     unsigned int numGlyphs = [font_info->nsfont numberOfGlyphs];
-    unsigned int gInd =0, cInd =0;
+    NSUInteger gInd =0, cInd =0;
 
     [glyphStorage setString: allChars font: font_info->nsfont];
     [glyphGenerator generateGlyphsForGlyphStorage: glyphStorage
@@ -1454,7 +1462,7 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block)
 }
 
 /* NSGlyphStorage protocol */
-- (unsigned int)layoutOptions
+- (NSUInteger)layoutOptions
 {
   return 0;
 }
@@ -1464,9 +1472,9 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block)
   return attrStr;
 }
 
-- (void)insertGlyphs: (const NSGlyph *)glyphs length: (unsigned int)length
-        forStartingGlyphAtIndex: (unsigned int)glyphIndex
-        characterIndex: (unsigned int)charIndex
+- (void)insertGlyphs: (const NSGlyph *)glyphs length: (NSUInteger)length
+        forStartingGlyphAtIndex: (NSUInteger)glyphIndex
+        characterIndex: (NSUInteger)charIndex
 {
   len = glyphIndex+length;
   for (i =glyphIndex; i<len; i++)
@@ -1475,8 +1483,8 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block)
     maxGlyph = len;
 }
 
-- (void)setIntAttribute: (int)attributeTag value: (int)val
-        forGlyphAtIndex: (unsigned)glyphIndex
+- (void)setIntAttribute: (NSInteger)attributeTag value: (NSInteger)val
+        forGlyphAtIndex: (NSUInteger)glyphIndex
 {
   return;
 }