Commit 481ae085 authored by Jan Djärv's avatar Jan Djärv

Handle floating point errors in ns-fonts (Bug#7887).

* nsfont.m (nsfont_open): Ensure that fonts with inexact
descenders would not become one pixel too tall (Bug#7887).
parent e52f87a1
2011-01-29 Anders Lindgren <andlind@gmail.com> (tiny change)
* nsfont.m (nsfont_open): Ensure that fonts with inexact
descenders would not become one pixel too tall (Bug#7887).
2011-01-28 Chong Yidong <cyd@stupidchicken.com> 2011-01-28 Chong Yidong <cyd@stupidchicken.com>
* keyboard.c (make_lispy_position): For clicks on right fringe or * keyboard.c (make_lispy_position): For clicks on right fringe or
...@@ -809,6 +809,14 @@ when setting family in ns_spec_to_descriptor(). */ ...@@ -809,6 +809,14 @@ when setting family in ns_spec_to_descriptor(). */
const char *fontName = [[nsfont fontName] UTF8String]; const char *fontName = [[nsfont fontName] UTF8String];
int len = strlen (fontName); int len = strlen (fontName);
/* The values specified by fonts are not always exact. For
* example, a 6x8 font could specify that the descender is
* -2.00000405... (represented by 0xc000000220000000). Without
* adjustment, the code below would round the descender to -3,
* resulting in a font that would be one pixel higher than
* intended. */
CGFloat adjusted_descender = [sfont descender] + 0.0001;
#ifdef NS_IMPL_GNUSTEP #ifdef NS_IMPL_GNUSTEP
font_info->nsfont = sfont; font_info->nsfont = sfont;
#else #else
...@@ -830,7 +838,7 @@ when setting family in ns_spec_to_descriptor(). */ ...@@ -830,7 +838,7 @@ when setting family in ns_spec_to_descriptor(). */
brect = [sfont boundingRectForFont]; brect = [sfont boundingRectForFont];
full_height = brect.size.height; full_height = brect.size.height;
min_height = [sfont ascender] - [sfont descender]; min_height = [sfont ascender] - adjusted_descender;
hd = full_height - min_height; hd = full_height - min_height;
/* standard height, similar to Carbon. Emacs.app: was 0.5 by default. */ /* standard height, similar to Carbon. Emacs.app: was 0.5 by default. */
...@@ -845,10 +853,10 @@ when setting family in ns_spec_to_descriptor(). */ ...@@ -845,10 +853,10 @@ when setting family in ns_spec_to_descriptor(). */
/* max bounds */ /* max bounds */
font_info->max_bounds.ascent = font_info->max_bounds.ascent =
lrint (hshrink * [sfont ascender] + expand * hd/2); lrint (hshrink * [sfont ascender] + expand * hd/2);
/* [sfont descender] is usually negative. Use floor to avoid /* Descender is usually negative. Use floor to avoid
clipping descenders. */ clipping descenders. */
font_info->max_bounds.descent = font_info->max_bounds.descent =
-lrint (floor(hshrink* [sfont descender] - expand*hd/2)); -lrint (floor(hshrink* adjusted_descender - expand*hd/2));
font_info->height = font_info->height =
font_info->max_bounds.ascent + font_info->max_bounds.descent; font_info->max_bounds.ascent + font_info->max_bounds.descent;
font_info->max_bounds.width = lrint (font_info->width); font_info->max_bounds.width = lrint (font_info->width);
...@@ -884,7 +892,7 @@ when setting family in ns_spec_to_descriptor(). */ ...@@ -884,7 +892,7 @@ when setting family in ns_spec_to_descriptor(). */
/* set up metrics portion of font struct */ /* set up metrics portion of font struct */
font->ascent = lrint([sfont ascender]); font->ascent = lrint([sfont ascender]);
font->descent = -lrint(floor([sfont descender])); font->descent = -lrint(floor(adjusted_descender));
font->min_width = ns_char_width(sfont, '|'); font->min_width = ns_char_width(sfont, '|');
font->space_width = lrint (ns_char_width (sfont, ' ')); font->space_width = lrint (ns_char_width (sfont, ' '));
font->average_width = lrint (font_info->width); font->average_width = lrint (font_info->width);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment