Subject: Re: bug#3975: 23.1; [PATCH] Line height too small with Monaco font on Mac OS X

From: Francis Devereux <[email-masked]>
Date: Thu, 30 Jul 2009 23:57:49 +0100

I have done some investigating into this bug and found a fix.  The  
problem was being caused by [sfont descender] returning -2.5, which  
was being rounded to -2 by the lrint on line 807 of nsfont.c:
       -lrint (hshrink* [sfont descender] - expand*hd/2);

The following patch fixes the problem:
--- src/nsfont.m~	2009-07-30 00:39:40.000000000 +0100
+++ src/nsfont.m	2009-07-30 23:41:56.000000000 +0100
@@ -803,8 +803,11 @@
      /* max bounds */
      font_info->max_bounds.ascent =
        lrint (hshrink * [sfont ascender] + expand * hd/2);
+    /* [sfont descender] is usually negative, so we use floor to round
+       towards the integer with the greater magnitude so that we  
don't clip
+       any 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);
@@ -839,8 +842,8 @@
  #endif

      /* set up metrics portion of font struct */
-    font->ascent = [sfont ascender];
-    font->descent = -[sfont descender];
+    font->ascent = lrint([sfont ascender]);
+    font->descent = -lrint(floor([sfont descender]));
      font->min_width = [sfont widthOfString: @"|"]; /* FIXME */
      font->space_width = lrint (ns_char_width (sfont, ' '));
      font->average_width = lrint (font_info->width);

The second hunk does not actually seem to be necessary, but I added it  
for consistency.

I think that this patch may also fix bug 3961 (Incorrect font height  
on Mac OS X).

Francis