diff options
| author | YAMAMOTO Mitsuharu | 2015-09-30 18:56:30 +0900 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2015-09-30 18:56:30 +0900 |
| commit | d22634e518078a9a51c9a30b44a72e0c9e7c96cd (patch) | |
| tree | 6b33932911ed42cdcb865d7db32210255c958892 /src | |
| parent | 1c6a58705b653b62c71266497564b1880c5b1340 (diff) | |
| download | emacs-d22634e518078a9a51c9a30b44a72e0c9e7c96cd.tar.gz emacs-d22634e518078a9a51c9a30b44a72e0c9e7c96cd.zip | |
Work around crash when displaying etc/HELLO on OS X 10.11
* src/macfont.m (mac_font_get_weight)
(mac_font_descriptor_get_adjusted_weight): New functions.
(macfont_store_descriptor_attributes): Adjust weight.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macfont.m | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/src/macfont.m b/src/macfont.m index 69640766d4e..cfe0e0a2b92 100644 --- a/src/macfont.m +++ b/src/macfont.m | |||
| @@ -190,6 +190,14 @@ cfstring_create_with_string_noencode (Lisp_Object s) | |||
| 190 | return string; | 190 | return string; |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | static CFIndex | ||
| 194 | mac_font_get_weight (CTFontRef font) | ||
| 195 | { | ||
| 196 | NSFont *nsFont = (NSFont *) font; | ||
| 197 | |||
| 198 | return [[NSFontManager sharedFontManager] weightOfFont:nsFont]; | ||
| 199 | } | ||
| 200 | |||
| 193 | static CGFloat | 201 | static CGFloat |
| 194 | mac_screen_font_get_advance_width_for_glyph (ScreenFontRef font, CGGlyph glyph) | 202 | mac_screen_font_get_advance_width_for_glyph (ScreenFontRef font, CGGlyph glyph) |
| 195 | { | 203 | { |
| @@ -758,6 +766,46 @@ cfnumber_get_font_symbolic_traits_value (CFNumberRef number, | |||
| 758 | return false; | 766 | return false; |
| 759 | } | 767 | } |
| 760 | 768 | ||
| 769 | static CGFloat | ||
| 770 | mac_font_descriptor_get_adjusted_weight (CTFontDescriptorRef desc, CGFloat val) | ||
| 771 | { | ||
| 772 | long percent_val = lround (val * 100); | ||
| 773 | |||
| 774 | if (percent_val == -40 || percent_val == 56) | ||
| 775 | { | ||
| 776 | CTFontRef font = NULL; | ||
| 777 | CFStringRef name = | ||
| 778 | CTFontDescriptorCopyAttribute (desc, kCTFontNameAttribute); | ||
| 779 | |||
| 780 | if (name) | ||
| 781 | { | ||
| 782 | font = CTFontCreateWithName (name, 0, NULL); | ||
| 783 | CFRelease (name); | ||
| 784 | } | ||
| 785 | if (font) | ||
| 786 | { | ||
| 787 | CFIndex weight = mac_font_get_weight (font); | ||
| 788 | |||
| 789 | if (percent_val == -40) | ||
| 790 | { | ||
| 791 | /* Workaround for crash when displaying Oriya characters | ||
| 792 | with Arial Unicode MS on OS X 10.11. */ | ||
| 793 | if (weight == 5) | ||
| 794 | val = 0; | ||
| 795 | } | ||
| 796 | else /* percent_val == 56 */ | ||
| 797 | { | ||
| 798 | if (weight == 9) | ||
| 799 | /* Adjustment for HiraginoSans-W7 on OS X 10.11. */ | ||
| 800 | val = 0.4; | ||
| 801 | } | ||
| 802 | CFRelease (font); | ||
| 803 | } | ||
| 804 | } | ||
| 805 | |||
| 806 | return val; | ||
| 807 | } | ||
| 808 | |||
| 761 | static void | 809 | static void |
| 762 | macfont_store_descriptor_attributes (CTFontDescriptorRef desc, | 810 | macfont_store_descriptor_attributes (CTFontDescriptorRef desc, |
| 763 | Lisp_Object spec_or_entity) | 811 | Lisp_Object spec_or_entity) |
| @@ -781,6 +829,7 @@ macfont_store_descriptor_attributes (CTFontDescriptorRef desc, | |||
| 781 | enum font_property_index index; | 829 | enum font_property_index index; |
| 782 | CFStringRef trait; | 830 | CFStringRef trait; |
| 783 | CGPoint points[6]; | 831 | CGPoint points[6]; |
| 832 | CGFloat (*adjust_func) (CTFontDescriptorRef, CGFloat); | ||
| 784 | } numeric_traits[] = | 833 | } numeric_traits[] = |
| 785 | {{FONT_WEIGHT_INDEX, kCTFontWeightTrait, | 834 | {{FONT_WEIGHT_INDEX, kCTFontWeightTrait, |
| 786 | {{-0.4, 50}, /* light */ | 835 | {{-0.4, 50}, /* light */ |
| @@ -788,11 +837,12 @@ macfont_store_descriptor_attributes (CTFontDescriptorRef desc, | |||
| 788 | {0, 100}, /* normal */ | 837 | {0, 100}, /* normal */ |
| 789 | {0.24, 140}, /* (semi-bold + normal) / 2 */ | 838 | {0.24, 140}, /* (semi-bold + normal) / 2 */ |
| 790 | {0.4, 200}, /* bold */ | 839 | {0.4, 200}, /* bold */ |
| 791 | {CGFLOAT_MAX, CGFLOAT_MAX}}}, | 840 | {CGFLOAT_MAX, CGFLOAT_MAX}}, |
| 841 | mac_font_descriptor_get_adjusted_weight}, | ||
| 792 | {FONT_SLANT_INDEX, kCTFontSlantTrait, | 842 | {FONT_SLANT_INDEX, kCTFontSlantTrait, |
| 793 | {{0, 100}, {0.1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}, | 843 | {{0, 100}, {0.1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}, NULL}, |
| 794 | {FONT_WIDTH_INDEX, kCTFontWidthTrait, | 844 | {FONT_WIDTH_INDEX, kCTFontWidthTrait, |
| 795 | {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}}; | 845 | {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}, NULL}}; |
| 796 | int i; | 846 | int i; |
| 797 | 847 | ||
| 798 | for (i = 0; i < ARRAYELTS (numeric_traits); i++) | 848 | for (i = 0; i < ARRAYELTS (numeric_traits); i++) |
| @@ -802,6 +852,8 @@ macfont_store_descriptor_attributes (CTFontDescriptorRef desc, | |||
| 802 | { | 852 | { |
| 803 | CGPoint *point = numeric_traits[i].points; | 853 | CGPoint *point = numeric_traits[i].points; |
| 804 | 854 | ||
| 855 | if (numeric_traits[i].adjust_func) | ||
| 856 | floatval = (*numeric_traits[i].adjust_func) (desc, floatval); | ||
| 805 | while (point->x < floatval) | 857 | while (point->x < floatval) |
| 806 | point++; | 858 | point++; |
| 807 | if (point == numeric_traits[i].points) | 859 | if (point == numeric_traits[i].points) |