diff options
| author | Jan Djärv | 2011-01-29 11:36:16 +0100 |
|---|---|---|
| committer | Jan Djärv | 2011-01-29 11:36:16 +0100 |
| commit | 481ae0855fbeadb5817ea3ffa7d5dbf3723000ac (patch) | |
| tree | 72de5f18e26f21eb1c7b0610cb35d74efcd8eace | |
| parent | e52f87a1c0ac9e6f04c1047d2b4828744e83f7ba (diff) | |
| download | emacs-481ae0855fbeadb5817ea3ffa7d5dbf3723000ac.tar.gz emacs-481ae0855fbeadb5817ea3ffa7d5dbf3723000ac.zip | |
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).
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/nsfont.m | 16 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index e4eb78f7f01..f8686529221 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2011-01-29 Anders Lindgren <andlind@gmail.com> (tiny change) | ||
| 2 | |||
| 3 | * nsfont.m (nsfont_open): Ensure that fonts with inexact | ||
| 4 | descenders would not become one pixel too tall (Bug#7887). | ||
| 5 | |||
| 1 | 2011-01-28 Chong Yidong <cyd@stupidchicken.com> | 6 | 2011-01-28 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 7 | ||
| 3 | * keyboard.c (make_lispy_position): For clicks on right fringe or | 8 | * keyboard.c (make_lispy_position): For clicks on right fringe or |
diff --git a/src/nsfont.m b/src/nsfont.m index b8848525f21..68cd19da70e 100644 --- a/src/nsfont.m +++ b/src/nsfont.m | |||
| @@ -809,6 +809,14 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) | |||
| 809 | const char *fontName = [[nsfont fontName] UTF8String]; | 809 | const char *fontName = [[nsfont fontName] UTF8String]; |
| 810 | int len = strlen (fontName); | 810 | int len = strlen (fontName); |
| 811 | 811 | ||
| 812 | /* The values specified by fonts are not always exact. For | ||
| 813 | * example, a 6x8 font could specify that the descender is | ||
| 814 | * -2.00000405... (represented by 0xc000000220000000). Without | ||
| 815 | * adjustment, the code below would round the descender to -3, | ||
| 816 | * resulting in a font that would be one pixel higher than | ||
| 817 | * intended. */ | ||
| 818 | CGFloat adjusted_descender = [sfont descender] + 0.0001; | ||
| 819 | |||
| 812 | #ifdef NS_IMPL_GNUSTEP | 820 | #ifdef NS_IMPL_GNUSTEP |
| 813 | font_info->nsfont = sfont; | 821 | font_info->nsfont = sfont; |
| 814 | #else | 822 | #else |
| @@ -830,7 +838,7 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) | |||
| 830 | 838 | ||
| 831 | brect = [sfont boundingRectForFont]; | 839 | brect = [sfont boundingRectForFont]; |
| 832 | full_height = brect.size.height; | 840 | full_height = brect.size.height; |
| 833 | min_height = [sfont ascender] - [sfont descender]; | 841 | min_height = [sfont ascender] - adjusted_descender; |
| 834 | hd = full_height - min_height; | 842 | hd = full_height - min_height; |
| 835 | 843 | ||
| 836 | /* standard height, similar to Carbon. Emacs.app: was 0.5 by default. */ | 844 | /* standard height, similar to Carbon. Emacs.app: was 0.5 by default. */ |
| @@ -845,10 +853,10 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) | |||
| 845 | /* max bounds */ | 853 | /* max bounds */ |
| 846 | font_info->max_bounds.ascent = | 854 | font_info->max_bounds.ascent = |
| 847 | lrint (hshrink * [sfont ascender] + expand * hd/2); | 855 | lrint (hshrink * [sfont ascender] + expand * hd/2); |
| 848 | /* [sfont descender] is usually negative. Use floor to avoid | 856 | /* Descender is usually negative. Use floor to avoid |
| 849 | clipping descenders. */ | 857 | clipping descenders. */ |
| 850 | font_info->max_bounds.descent = | 858 | font_info->max_bounds.descent = |
| 851 | -lrint (floor(hshrink* [sfont descender] - expand*hd/2)); | 859 | -lrint (floor(hshrink* adjusted_descender - expand*hd/2)); |
| 852 | font_info->height = | 860 | font_info->height = |
| 853 | font_info->max_bounds.ascent + font_info->max_bounds.descent; | 861 | font_info->max_bounds.ascent + font_info->max_bounds.descent; |
| 854 | font_info->max_bounds.width = lrint (font_info->width); | 862 | font_info->max_bounds.width = lrint (font_info->width); |
| @@ -884,7 +892,7 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) | |||
| 884 | 892 | ||
| 885 | /* set up metrics portion of font struct */ | 893 | /* set up metrics portion of font struct */ |
| 886 | font->ascent = lrint([sfont ascender]); | 894 | font->ascent = lrint([sfont ascender]); |
| 887 | font->descent = -lrint(floor([sfont descender])); | 895 | font->descent = -lrint(floor(adjusted_descender)); |
| 888 | font->min_width = ns_char_width(sfont, '|'); | 896 | font->min_width = ns_char_width(sfont, '|'); |
| 889 | font->space_width = lrint (ns_char_width (sfont, ' ')); | 897 | font->space_width = lrint (ns_char_width (sfont, ' ')); |
| 890 | font->average_width = lrint (font_info->width); | 898 | font->average_width = lrint (font_info->width); |