diff options
| author | Jan Djärv | 2013-11-07 23:21:08 +0100 |
|---|---|---|
| committer | Jan Djärv | 2013-11-07 23:21:08 +0100 |
| commit | 5ee2921081ec21d18b1a190bdacb3ebd3bfdc294 (patch) | |
| tree | 9fbf407c98c2c8bdd9657e631c2a68cf59ae33f4 /src | |
| parent | 3220d5279d488e51afb3a49cda5c48fa9ca4e36c (diff) | |
| download | emacs-5ee2921081ec21d18b1a190bdacb3ebd3bfdc294.tar.gz emacs-5ee2921081ec21d18b1a190bdacb3ebd3bfdc294.zip | |
Import macfont changes from mac-port 4.5.
* macfont.h (kCTVersionNumber10_9): Define if not defined.
* macfont.m (mac_font_copy_default_descriptors_for_language)
(mac_font_copy_default_name_for_charset_and_languages): Declare.
(cf_charset_table): big-5-0 has uniquifier 0x4EDC.
(macfont_language_default_font_names): New.
(macfont_list): Rearrange language/charset code.
(macfont_close): Don't check for macfont_info->cache.
(mac_ctfont_create_preferred_family_for_attributes): New font
selection code, call
mac_font_copy_default_name_for_charset_and_languages.
(mac_font_copy_default_descriptors_for_language)
(mac_font_copy_default_name_for_charset_and_languages): New functions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 17 | ||||
| -rw-r--r-- | src/macfont.h | 3 | ||||
| -rw-r--r-- | src/macfont.m | 364 |
3 files changed, 297 insertions, 87 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 2f774b87b13..2914c23ef0e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,20 @@ | |||
| 1 | 2013-11-07 Jan Djärv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | Import changes from mac-port 4.5. | ||
| 4 | * macfont.m (mac_font_copy_default_descriptors_for_language) | ||
| 5 | (mac_font_copy_default_name_for_charset_and_languages): Declare. | ||
| 6 | (cf_charset_table): big-5-0 has uniquifier 0x4EDC. | ||
| 7 | (macfont_language_default_font_names): New. | ||
| 8 | (macfont_list): Rearrange language/charset code. | ||
| 9 | (macfont_close): Don't check for macfont_info->cache. | ||
| 10 | (mac_ctfont_create_preferred_family_for_attributes): New font | ||
| 11 | selection code, call | ||
| 12 | mac_font_copy_default_name_for_charset_and_languages. | ||
| 13 | (mac_font_copy_default_descriptors_for_language) | ||
| 14 | (mac_font_copy_default_name_for_charset_and_languages): New functions. | ||
| 15 | |||
| 16 | * macfont.h (kCTVersionNumber10_9): Define if not defined. | ||
| 17 | |||
| 1 | 2013-11-07 Paul Eggert <eggert@cs.ucla.edu> | 18 | 2013-11-07 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 19 | ||
| 3 | Port to C11 aligned_alloc, and fix some integer overflows. | 20 | Port to C11 aligned_alloc, and fix some integer overflows. |
diff --git a/src/macfont.h b/src/macfont.h index 141d60bfb0a..4b57c18692e 100644 --- a/src/macfont.h +++ b/src/macfont.h | |||
| @@ -134,6 +134,9 @@ enum { | |||
| 134 | 134 | ||
| 135 | #define mac_nsctfont_copy_font_descriptor CTFontCopyFontDescriptor | 135 | #define mac_nsctfont_copy_font_descriptor CTFontCopyFontDescriptor |
| 136 | 136 | ||
| 137 | #ifndef kCTVersionNumber10_9 | ||
| 138 | #define kCTVersionNumber10_9 0x00060000 | ||
| 139 | #endif | ||
| 137 | #define MAC_FONT_CHARACTER_SET_STRING_ATTRIBUTE \ | 140 | #define MAC_FONT_CHARACTER_SET_STRING_ATTRIBUTE \ |
| 138 | (CFSTR ("MAC_FONT_CHARACTER_SET_STRING_ATTRIBUTE")) | 141 | (CFSTR ("MAC_FONT_CHARACTER_SET_STRING_ATTRIBUTE")) |
| 139 | 142 | ||
diff --git a/src/macfont.m b/src/macfont.m index c284b3086f8..10623eb12fe 100644 --- a/src/macfont.m +++ b/src/macfont.m | |||
| @@ -57,6 +57,13 @@ static Boolean mac_ctfont_descriptor_supports_languages (CTFontDescriptorRef, | |||
| 57 | static CFStringRef mac_ctfont_create_preferred_family_for_attributes (CFDictionaryRef); | 57 | static CFStringRef mac_ctfont_create_preferred_family_for_attributes (CFDictionaryRef); |
| 58 | static CFIndex mac_ctfont_shape (CTFontRef, CFStringRef, | 58 | static CFIndex mac_ctfont_shape (CTFontRef, CFStringRef, |
| 59 | struct mac_glyph_layout *, CFIndex); | 59 | struct mac_glyph_layout *, CFIndex); |
| 60 | static CFArrayRef | ||
| 61 | mac_font_copy_default_descriptors_for_language (CFStringRef language); | ||
| 62 | |||
| 63 | static CFStringRef | ||
| 64 | mac_font_copy_default_name_for_charset_and_languages (CFCharacterSetRef charset, | ||
| 65 | CFArrayRef languages); | ||
| 66 | |||
| 60 | #if USE_CT_GLYPH_INFO | 67 | #if USE_CT_GLYPH_INFO |
| 61 | static CGGlyph mac_ctfont_get_glyph_for_cid (CTFontRef, | 68 | static CGGlyph mac_ctfont_get_glyph_for_cid (CTFontRef, |
| 62 | CTCharacterCollection, | 69 | CTCharacterCollection, |
| @@ -676,7 +683,7 @@ static struct | |||
| 676 | { "iso8859-15", { 0x00A0, 0x00A1, 0x00D0, 0x0152 }}, | 683 | { "iso8859-15", { 0x00A0, 0x00A1, 0x00D0, 0x0152 }}, |
| 677 | { "iso8859-16", { 0x00A0, 0x0218}}, | 684 | { "iso8859-16", { 0x00A0, 0x0218}}, |
| 678 | { "gb2312.1980-0", { 0x4E13 }, CFSTR ("zh-Hans")}, | 685 | { "gb2312.1980-0", { 0x4E13 }, CFSTR ("zh-Hans")}, |
| 679 | { "big5-0", { /* 0xF6B1 in ftfont.c */ 0xF7E5 }, CFSTR ("zh-Hant") }, | 686 | { "big5-0", { /* 0xF6B1 in ftfont.c */ 0x4EDC }, CFSTR ("zh-Hant") }, |
| 680 | { "jisx0208.1983-0", { 0x4E55 }, CFSTR ("ja")}, | 687 | { "jisx0208.1983-0", { 0x4E55 }, CFSTR ("ja")}, |
| 681 | { "ksc5601.1987-0", { 0xAC00 }, CFSTR ("ko")}, | 688 | { "ksc5601.1987-0", { 0xAC00 }, CFSTR ("ko")}, |
| 682 | { "cns11643.1992-1", { 0xFE32 }, CFSTR ("zh-Hant")}, | 689 | { "cns11643.1992-1", { 0xFE32 }, CFSTR ("zh-Hant")}, |
| @@ -700,9 +707,31 @@ static struct | |||
| 700 | { NULL } | 707 | { NULL } |
| 701 | }; | 708 | }; |
| 702 | 709 | ||
| 710 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 | ||
| 711 | static const struct | ||
| 712 | { | ||
| 713 | CFStringRef language; | ||
| 714 | CFStringRef font_names[3]; | ||
| 715 | } macfont_language_default_font_names[] = { | ||
| 716 | { CFSTR ("ja"), { CFSTR ("HiraKakuProN-W3"), /* 10.5 - 10.9 */ | ||
| 717 | CFSTR ("HiraKakuPro-W3"), /* 10.4 */ | ||
| 718 | NULL }}, | ||
| 719 | { CFSTR ("ko"), { CFSTR ("AppleSDGothicNeo-Regular"), /* 10.8 - 10.9 */ | ||
| 720 | CFSTR ("AppleGothic"), /* 10.4 - 10.7 */ | ||
| 721 | NULL }}, | ||
| 722 | { CFSTR ("zh-Hans"), { CFSTR ("STHeitiSC-Light"), /* 10.6 - 10.9 */ | ||
| 723 | CFSTR ("STXihei"), /* 10.4 - 10.5 */ | ||
| 724 | NULL }}, | ||
| 725 | { CFSTR ("zh-Hant"), { CFSTR ("STHeitiTC-Light"), /* 10.6 - 10.9 */ | ||
| 726 | CFSTR ("LiHeiPro"), /* 10.4 - 10.5 */ | ||
| 727 | NULL }}, | ||
| 728 | { NULL } | ||
| 729 | }; | ||
| 730 | #endif | ||
| 731 | |||
| 703 | static CGFloat macfont_antialias_threshold; | 732 | static CGFloat macfont_antialias_threshold; |
| 704 | 733 | ||
| 705 | void | 734 | static void |
| 706 | macfont_update_antialias_threshold (void) | 735 | macfont_update_antialias_threshold (void) |
| 707 | { | 736 | { |
| 708 | int threshold; | 737 | int threshold; |
| @@ -2052,33 +2081,7 @@ macfont_list (struct frame *f, Lisp_Object spec) | |||
| 2052 | if (! attributes) | 2081 | if (! attributes) |
| 2053 | goto finish; | 2082 | goto finish; |
| 2054 | 2083 | ||
| 2055 | charset = ((CFCharacterSetRef) | 2084 | languages = CFDictionaryGetValue (attributes, MAC_FONT_LANGUAGES_ATTRIBUTE); |
| 2056 | CFDictionaryGetValue (attributes, | ||
| 2057 | MAC_FONT_CHARACTER_SET_ATTRIBUTE)); | ||
| 2058 | if (charset) | ||
| 2059 | { | ||
| 2060 | CFRetain (charset); | ||
| 2061 | CFDictionaryRemoveValue (attributes, MAC_FONT_CHARACTER_SET_ATTRIBUTE); | ||
| 2062 | } | ||
| 2063 | else | ||
| 2064 | { | ||
| 2065 | val = assq_no_quit (QCscript, AREF (spec, FONT_EXTRA_INDEX)); | ||
| 2066 | if (! NILP (val)) | ||
| 2067 | { | ||
| 2068 | val = assq_no_quit (XCDR (val), Vscript_representative_chars); | ||
| 2069 | if (CONSP (val) && VECTORP (XCDR (val))) | ||
| 2070 | chars = XCDR (val); | ||
| 2071 | } | ||
| 2072 | val = Qnil; | ||
| 2073 | } | ||
| 2074 | |||
| 2075 | languages = ((CFArrayRef) | ||
| 2076 | CFDictionaryGetValue (attributes, MAC_FONT_LANGUAGES_ATTRIBUTE)); | ||
| 2077 | if (languages) | ||
| 2078 | { | ||
| 2079 | CFRetain (languages); | ||
| 2080 | CFDictionaryRemoveValue (attributes, MAC_FONT_LANGUAGES_ATTRIBUTE); | ||
| 2081 | } | ||
| 2082 | 2085 | ||
| 2083 | if (INTEGERP (AREF (spec, FONT_SPACING_INDEX))) | 2086 | if (INTEGERP (AREF (spec, FONT_SPACING_INDEX))) |
| 2084 | spacing = XINT (AREF (spec, FONT_SPACING_INDEX)); | 2087 | spacing = XINT (AREF (spec, FONT_SPACING_INDEX)); |
| @@ -2162,6 +2165,31 @@ macfont_list (struct frame *f, Lisp_Object spec) | |||
| 2162 | } | 2165 | } |
| 2163 | } | 2166 | } |
| 2164 | 2167 | ||
| 2168 | charset = CFDictionaryGetValue (attributes, | ||
| 2169 | MAC_FONT_CHARACTER_SET_ATTRIBUTE); | ||
| 2170 | if (charset) | ||
| 2171 | { | ||
| 2172 | CFRetain (charset); | ||
| 2173 | CFDictionaryRemoveValue (attributes, MAC_FONT_CHARACTER_SET_ATTRIBUTE); | ||
| 2174 | } | ||
| 2175 | else | ||
| 2176 | { | ||
| 2177 | val = assq_no_quit (QCscript, AREF (spec, FONT_EXTRA_INDEX)); | ||
| 2178 | if (! NILP (val)) | ||
| 2179 | { | ||
| 2180 | val = assq_no_quit (XCDR (val), Vscript_representative_chars); | ||
| 2181 | if (CONSP (val) && VECTORP (XCDR (val))) | ||
| 2182 | chars = XCDR (val); | ||
| 2183 | } | ||
| 2184 | val = Qnil; | ||
| 2185 | } | ||
| 2186 | |||
| 2187 | if (languages) | ||
| 2188 | { | ||
| 2189 | CFRetain (languages); | ||
| 2190 | CFDictionaryRemoveValue (attributes, MAC_FONT_LANGUAGES_ATTRIBUTE); | ||
| 2191 | } | ||
| 2192 | |||
| 2165 | val = Qnil; | 2193 | val = Qnil; |
| 2166 | extra = AREF (spec, FONT_EXTRA_INDEX); | 2194 | extra = AREF (spec, FONT_EXTRA_INDEX); |
| 2167 | families_count = CFArrayGetCount (families); | 2195 | families_count = CFArrayGetCount (families); |
| @@ -2590,25 +2618,20 @@ static void | |||
| 2590 | macfont_close (struct font *font) | 2618 | macfont_close (struct font *font) |
| 2591 | { | 2619 | { |
| 2592 | struct macfont_info *macfont_info = (struct macfont_info *) font; | 2620 | struct macfont_info *macfont_info = (struct macfont_info *) font; |
| 2621 | int i; | ||
| 2593 | 2622 | ||
| 2594 | if (macfont_info->cache) | 2623 | block_input (); |
| 2595 | { | 2624 | CFRelease (macfont_info->macfont); |
| 2596 | int i; | 2625 | CGFontRelease (macfont_info->cgfont); |
| 2597 | 2626 | if (macfont_info->screen_font) | |
| 2598 | block_input (); | 2627 | CFRelease (macfont_info->screen_font); |
| 2599 | CFRelease (macfont_info->macfont); | 2628 | macfont_release_cache (macfont_info->cache); |
| 2600 | CGFontRelease (macfont_info->cgfont); | 2629 | for (i = 0; i < macfont_info->metrics_nrows; i++) |
| 2601 | if (macfont_info->screen_font) | 2630 | if (macfont_info->metrics[i]) |
| 2602 | CFRelease (macfont_info->screen_font); | 2631 | xfree (macfont_info->metrics[i]); |
| 2603 | macfont_release_cache (macfont_info->cache); | 2632 | if (macfont_info->metrics) |
| 2604 | macfont_info->cache = NULL; | 2633 | xfree (macfont_info->metrics); |
| 2605 | for (i = 0; i < macfont_info->metrics_nrows; i++) | 2634 | unblock_input (); |
| 2606 | if (macfont_info->metrics[i]) | ||
| 2607 | xfree (macfont_info->metrics[i]); | ||
| 2608 | if (macfont_info->metrics) | ||
| 2609 | xfree (macfont_info->metrics); | ||
| 2610 | unblock_input (); | ||
| 2611 | } | ||
| 2612 | } | 2635 | } |
| 2613 | 2636 | ||
| 2614 | static int | 2637 | static int |
| @@ -2798,7 +2821,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 2798 | return len; | 2821 | return len; |
| 2799 | } | 2822 | } |
| 2800 | 2823 | ||
| 2801 | Lisp_Object | 2824 | static Lisp_Object |
| 2802 | macfont_shape (Lisp_Object lgstring) | 2825 | macfont_shape (Lisp_Object lgstring) |
| 2803 | { | 2826 | { |
| 2804 | struct font *font; | 2827 | struct font *font; |
| @@ -3335,49 +3358,80 @@ mac_ctfont_create_preferred_family_for_attributes (CFDictionaryRef attributes) | |||
| 3335 | 3358 | ||
| 3336 | if (charset_string && CFStringGetLength (charset_string) > 0) | 3359 | if (charset_string && CFStringGetLength (charset_string) > 0) |
| 3337 | { | 3360 | { |
| 3338 | CFAttributedStringRef attr_string = NULL; | 3361 | CFStringRef keys[] = { |
| 3339 | CTLineRef ctline = NULL; | 3362 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 |
| 3340 | CFDictionaryRef attrs = | 3363 | kCTLanguageAttributeName |
| 3341 | CFDictionaryCreate (NULL, NULL, NULL, 0, | 3364 | #else |
| 3342 | &kCFTypeDictionaryKeyCallBacks, | 3365 | CFSTR ("NSLanguage") |
| 3343 | &kCFTypeDictionaryValueCallBacks); | 3366 | #endif |
| 3367 | }; | ||
| 3368 | CFTypeRef values[] = {NULL}; | ||
| 3369 | CFIndex num_values = 0; | ||
| 3370 | CFArrayRef languages | ||
| 3371 | = CFDictionaryGetValue (attributes, MAC_FONT_LANGUAGES_ATTRIBUTE); | ||
| 3344 | 3372 | ||
| 3345 | if (attrs) | 3373 | if (languages && CFArrayGetCount (languages) > 0) |
| 3346 | { | ||
| 3347 | attr_string = CFAttributedStringCreate (NULL, charset_string, attrs); | ||
| 3348 | CFRelease (attrs); | ||
| 3349 | } | ||
| 3350 | if (attr_string) | ||
| 3351 | { | 3374 | { |
| 3352 | ctline = CTLineCreateWithAttributedString (attr_string); | 3375 | if (CTGetCoreTextVersion () >= kCTVersionNumber10_9) |
| 3353 | CFRelease (attr_string); | 3376 | values[num_values++] = CFArrayGetValueAtIndex (languages, 0); |
| 3377 | else | ||
| 3378 | { | ||
| 3379 | CFCharacterSetRef charset = | ||
| 3380 | CFDictionaryGetValue (attributes, | ||
| 3381 | MAC_FONT_CHARACTER_SET_ATTRIBUTE); | ||
| 3382 | |||
| 3383 | result = mac_font_copy_default_name_for_charset_and_languages (charset, languages); | ||
| 3384 | } | ||
| 3354 | } | 3385 | } |
| 3355 | if (ctline) | 3386 | if (result == NULL) |
| 3356 | { | 3387 | { |
| 3357 | CFArrayRef runs = CTLineGetGlyphRuns (ctline); | 3388 | CFAttributedStringRef attr_string = NULL; |
| 3358 | CFIndex i, nruns = CFArrayGetCount (runs); | 3389 | CTLineRef ctline = NULL; |
| 3359 | CTFontRef font; | 3390 | CFDictionaryRef attrs |
| 3360 | 3391 | = CFDictionaryCreate (NULL, (const void **) keys, | |
| 3361 | for (i = 0; i < nruns; i++) | 3392 | (const void **) values, num_values, |
| 3393 | &kCFTypeDictionaryKeyCallBacks, | ||
| 3394 | &kCFTypeDictionaryValueCallBacks); | ||
| 3395 | |||
| 3396 | if (attrs) | ||
| 3362 | { | 3397 | { |
| 3363 | CTRunRef run = CFArrayGetValueAtIndex (runs, i); | 3398 | attr_string = CFAttributedStringCreate (NULL, charset_string, |
| 3364 | CFDictionaryRef attributes = CTRunGetAttributes (run); | 3399 | attrs); |
| 3365 | CTFontRef font_in_run; | 3400 | CFRelease (attrs); |
| 3401 | } | ||
| 3402 | if (attr_string) | ||
| 3403 | { | ||
| 3404 | ctline = CTLineCreateWithAttributedString (attr_string); | ||
| 3405 | CFRelease (attr_string); | ||
| 3406 | } | ||
| 3407 | if (ctline) | ||
| 3408 | { | ||
| 3409 | CFArrayRef runs = CTLineGetGlyphRuns (ctline); | ||
| 3410 | CFIndex i, nruns = CFArrayGetCount (runs); | ||
| 3411 | CTFontRef font; | ||
| 3366 | 3412 | ||
| 3367 | if (attributes == NULL) | 3413 | for (i = 0; i < nruns; i++) |
| 3368 | break; | 3414 | { |
| 3369 | font_in_run = | 3415 | CTRunRef run = CFArrayGetValueAtIndex (runs, i); |
| 3370 | CFDictionaryGetValue (attributes, kCTFontAttributeName); | 3416 | CFDictionaryRef attributes = CTRunGetAttributes (run); |
| 3371 | if (font_in_run == NULL) | 3417 | CTFontRef font_in_run; |
| 3372 | break; | 3418 | |
| 3373 | if (i == 0) | 3419 | if (attributes == NULL) |
| 3374 | font = font_in_run; | 3420 | break; |
| 3375 | else if (!mac_ctfont_equal_in_postscript_name (font, font_in_run)) | 3421 | font_in_run = |
| 3376 | break; | 3422 | CFDictionaryGetValue (attributes, kCTFontAttributeName); |
| 3423 | if (font_in_run == NULL) | ||
| 3424 | break; | ||
| 3425 | if (i == 0) | ||
| 3426 | font = font_in_run; | ||
| 3427 | else if (!mac_ctfont_equal_in_postscript_name (font, | ||
| 3428 | font_in_run)) | ||
| 3429 | break; | ||
| 3430 | } | ||
| 3431 | if (nruns > 0 && i == nruns) | ||
| 3432 | result = CTFontCopyAttribute (font, kCTFontFamilyNameAttribute); | ||
| 3433 | CFRelease (ctline); | ||
| 3377 | } | 3434 | } |
| 3378 | if (nruns > 0 && i == nruns) | ||
| 3379 | result = CTFontCopyAttribute (font, kCTFontFamilyNameAttribute); | ||
| 3380 | CFRelease (ctline); | ||
| 3381 | } | 3435 | } |
| 3382 | } | 3436 | } |
| 3383 | 3437 | ||
| @@ -3571,7 +3625,7 @@ mac_ctfont_create_line_with_string_and_font (CFStringRef string, | |||
| 3571 | return ctline; | 3625 | return ctline; |
| 3572 | } | 3626 | } |
| 3573 | 3627 | ||
| 3574 | CFIndex | 3628 | static CFIndex |
| 3575 | mac_ctfont_shape (CTFontRef font, CFStringRef string, | 3629 | mac_ctfont_shape (CTFontRef font, CFStringRef string, |
| 3576 | struct mac_glyph_layout *glyph_layouts, CFIndex glyph_len) | 3630 | struct mac_glyph_layout *glyph_layouts, CFIndex glyph_len) |
| 3577 | { | 3631 | { |
| @@ -3724,7 +3778,7 @@ mac_ctfont_shape (CTFontRef font, CFStringRef string, | |||
| 3724 | created by CFStringCreateWithCharacters as of Mac OS X 10.5.8 and | 3778 | created by CFStringCreateWithCharacters as of Mac OS X 10.5.8 and |
| 3725 | 10.6.3. For now, we use the NSGlyphInfo version instead. */ | 3779 | 10.6.3. For now, we use the NSGlyphInfo version instead. */ |
| 3726 | #if USE_CT_GLYPH_INFO | 3780 | #if USE_CT_GLYPH_INFO |
| 3727 | CGGlyph | 3781 | static CGGlyph |
| 3728 | mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection, | 3782 | mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection, |
| 3729 | CGFontIndex cid) | 3783 | CGFontIndex cid) |
| 3730 | { | 3784 | { |
| @@ -3817,7 +3871,7 @@ mac_font_family_group (CFStringRef family) | |||
| 3817 | } | 3871 | } |
| 3818 | } | 3872 | } |
| 3819 | 3873 | ||
| 3820 | CFComparisonResult | 3874 | static CFComparisonResult |
| 3821 | mac_font_family_compare (const void *val1, const void *val2, void *context) | 3875 | mac_font_family_compare (const void *val1, const void *val2, void *context) |
| 3822 | { | 3876 | { |
| 3823 | CFStringRef family1 = (CFStringRef) val1, family2 = (CFStringRef) val2; | 3877 | CFStringRef family1 = (CFStringRef) val1, family2 = (CFStringRef) val2; |
| @@ -3833,6 +3887,142 @@ mac_font_family_compare (const void *val1, const void *val2, void *context) | |||
| 3833 | } | 3887 | } |
| 3834 | #endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1060 */ | 3888 | #endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1060 */ |
| 3835 | 3889 | ||
| 3890 | static CFArrayRef | ||
| 3891 | mac_font_copy_default_descriptors_for_language (CFStringRef language) | ||
| 3892 | { | ||
| 3893 | CFArrayRef result = NULL; | ||
| 3894 | |||
| 3895 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 | ||
| 3896 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 | ||
| 3897 | if (CTFontCopyDefaultCascadeListForLanguages != NULL) | ||
| 3898 | #endif | ||
| 3899 | { | ||
| 3900 | CTFontRef user_font = | ||
| 3901 | CTFontCreateUIFontForLanguage (kCTFontUserFontType, 0, language); | ||
| 3902 | |||
| 3903 | if (user_font) | ||
| 3904 | { | ||
| 3905 | CFArrayRef languages = | ||
| 3906 | CFArrayCreate (NULL, (const void **) &language, 1, | ||
| 3907 | &kCFTypeArrayCallBacks); | ||
| 3908 | |||
| 3909 | if (languages) | ||
| 3910 | { | ||
| 3911 | result = CTFontCopyDefaultCascadeListForLanguages (user_font, | ||
| 3912 | languages); | ||
| 3913 | CFRelease (languages); | ||
| 3914 | } | ||
| 3915 | CFRelease (user_font); | ||
| 3916 | } | ||
| 3917 | } | ||
| 3918 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 | ||
| 3919 | else /* CTFontCopyDefaultCascadeListForLanguages == NULL */ | ||
| 3920 | #endif | ||
| 3921 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1080 */ | ||
| 3922 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 | ||
| 3923 | { | ||
| 3924 | CFIndex i; | ||
| 3925 | |||
| 3926 | for (i = 0; macfont_language_default_font_names[i].language; i++) | ||
| 3927 | { | ||
| 3928 | if (CFStringCompare (macfont_language_default_font_names[i].language, | ||
| 3929 | language, 0) == kCFCompareEqualTo) | ||
| 3930 | { | ||
| 3931 | CFMutableArrayRef descriptors = | ||
| 3932 | CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks); | ||
| 3933 | |||
| 3934 | if (descriptors) | ||
| 3935 | { | ||
| 3936 | CFIndex j; | ||
| 3937 | |||
| 3938 | for (j = 0; | ||
| 3939 | macfont_language_default_font_names[i].font_names[j]; | ||
| 3940 | j++) | ||
| 3941 | { | ||
| 3942 | CFDictionaryRef attributes = | ||
| 3943 | CFDictionaryCreate (NULL, | ||
| 3944 | ((const void **) | ||
| 3945 | &MAC_FONT_NAME_ATTRIBUTE), | ||
| 3946 | ((const void **) | ||
| 3947 | &macfont_language_default_font_names[i].font_names[j]), | ||
| 3948 | 1, &kCFTypeDictionaryKeyCallBacks, | ||
| 3949 | &kCFTypeDictionaryValueCallBacks); | ||
| 3950 | |||
| 3951 | if (attributes) | ||
| 3952 | { | ||
| 3953 | FontDescriptorRef pat_desc = | ||
| 3954 | mac_font_descriptor_create_with_attributes (attributes); | ||
| 3955 | |||
| 3956 | if (pat_desc) | ||
| 3957 | { | ||
| 3958 | FontDescriptorRef descriptor = | ||
| 3959 | mac_font_descriptor_create_matching_font_descriptor (pat_desc, NULL); | ||
| 3960 | |||
| 3961 | if (descriptor) | ||
| 3962 | { | ||
| 3963 | CFArrayAppendValue (descriptors, descriptor); | ||
| 3964 | CFRelease (descriptor); | ||
| 3965 | } | ||
| 3966 | CFRelease (pat_desc); | ||
| 3967 | } | ||
| 3968 | CFRelease (attributes); | ||
| 3969 | } | ||
| 3970 | } | ||
| 3971 | result = descriptors; | ||
| 3972 | } | ||
| 3973 | break; | ||
| 3974 | } | ||
| 3975 | } | ||
| 3976 | } | ||
| 3977 | #endif | ||
| 3978 | |||
| 3979 | return result; | ||
| 3980 | } | ||
| 3981 | |||
| 3982 | static CFStringRef | ||
| 3983 | mac_font_copy_default_name_for_charset_and_languages (CFCharacterSetRef charset, | ||
| 3984 | CFArrayRef languages) | ||
| 3985 | { | ||
| 3986 | CFStringRef result = NULL; | ||
| 3987 | CFStringRef language = CFArrayGetValueAtIndex (languages, 0); | ||
| 3988 | CFArrayRef descriptors = | ||
| 3989 | mac_font_copy_default_descriptors_for_language (language); | ||
| 3990 | |||
| 3991 | if (descriptors) | ||
| 3992 | { | ||
| 3993 | CFIndex i, count = CFArrayGetCount (descriptors); | ||
| 3994 | |||
| 3995 | for (i = 0; i < count; i++) | ||
| 3996 | { | ||
| 3997 | FontDescriptorRef descriptor = | ||
| 3998 | CFArrayGetValueAtIndex (descriptors, i); | ||
| 3999 | |||
| 4000 | if (macfont_supports_charset_and_languages_p (descriptor, charset, | ||
| 4001 | Qnil, languages)) | ||
| 4002 | { | ||
| 4003 | CFStringRef family = | ||
| 4004 | mac_font_descriptor_copy_attribute (descriptor, | ||
| 4005 | MAC_FONT_FAMILY_NAME_ATTRIBUTE); | ||
| 4006 | if (family) | ||
| 4007 | { | ||
| 4008 | if (!CFStringHasPrefix (family, CFSTR (".")) | ||
| 4009 | && (CFStringCompare (family, CFSTR ("LastResort"), 0) | ||
| 4010 | != kCFCompareEqualTo)) | ||
| 4011 | { | ||
| 4012 | result = family; | ||
| 4013 | break; | ||
| 4014 | } | ||
| 4015 | else | ||
| 4016 | CFRelease (family); | ||
| 4017 | } | ||
| 4018 | } | ||
| 4019 | } | ||
| 4020 | CFRelease (descriptors); | ||
| 4021 | } | ||
| 4022 | |||
| 4023 | return result; | ||
| 4024 | } | ||
| 4025 | |||
| 3836 | void * | 4026 | void * |
| 3837 | macfont_get_nsctfont (struct font *font) | 4027 | macfont_get_nsctfont (struct font *font) |
| 3838 | { | 4028 | { |