diff options
| author | Jan Djärv | 2014-10-05 13:34:59 +0200 |
|---|---|---|
| committer | Jan Djärv | 2014-10-05 13:34:59 +0200 |
| commit | 6a4b1b17293ed0e4c7f7f3a33e058f63ccd290eb (patch) | |
| tree | ffe90cfa2f8c36f2aec7014e76604a65716c4a89 /src | |
| parent | 21c1abcae174704033a7f5b164081503501b921e (diff) | |
| download | emacs-6a4b1b17293ed0e4c7f7f3a33e058f63ccd290eb.tar.gz emacs-6a4b1b17293ed0e4c7f7f3a33e058f63ccd290eb.zip | |
Import from macoport 24.3.94.
* macfont.m: Fix indentation and import changes from macport
24.3.94.
(macfont_closest_traits_index): New function.
(macfont_closest_traits_index_p): Renamed from
macfont_closest_traits_index.
(macfont_list): Use macfont_closest_traits_index_p.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/macfont.m | 3186 |
2 files changed, 1612 insertions, 1583 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c8779d37841..59d28aad8bc 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2014-10-05 Jan Djärv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | * macfont.m: Fix indentation and import changes from macport | ||
| 4 | 24.3.94. | ||
| 5 | (macfont_closest_traits_index): New function. | ||
| 6 | (macfont_closest_traits_index_p): Renamed from | ||
| 7 | macfont_closest_traits_index. | ||
| 8 | (macfont_list): Use macfont_closest_traits_index_p. | ||
| 9 | |||
| 1 | 2014-10-05 K. Handa <handa@gnu.org> | 10 | 2014-10-05 K. Handa <handa@gnu.org> |
| 2 | 11 | ||
| 3 | * coding.c (detect_coding_iso_2022): Set coding->rejected | 12 | * coding.c (detect_coding_iso_2022): Set coding->rejected |
diff --git a/src/macfont.m b/src/macfont.m index f1895d1b0a5..b1fa5a1a41b 100644 --- a/src/macfont.m +++ b/src/macfont.m | |||
| @@ -50,25 +50,25 @@ static CGRect mac_ctfont_get_bounding_rect_for_glyph (CTFontRef, CGGlyph); | |||
| 50 | static CFArrayRef mac_ctfont_create_available_families (void); | 50 | static CFArrayRef mac_ctfont_create_available_families (void); |
| 51 | static Boolean mac_ctfont_equal_in_postscript_name (CTFontRef, CTFontRef); | 51 | static Boolean mac_ctfont_equal_in_postscript_name (CTFontRef, CTFontRef); |
| 52 | static CTLineRef mac_ctfont_create_line_with_string_and_font (CFStringRef, | 52 | static CTLineRef mac_ctfont_create_line_with_string_and_font (CFStringRef, |
| 53 | CTFontRef); | 53 | CTFontRef); |
| 54 | static CFComparisonResult mac_font_family_compare (const void *, | 54 | static CFComparisonResult mac_font_family_compare (const void *, |
| 55 | const void *, void *); | 55 | const void *, void *); |
| 56 | static Boolean mac_ctfont_descriptor_supports_languages (CTFontDescriptorRef, | 56 | static Boolean mac_ctfont_descriptor_supports_languages (CTFontDescriptorRef, |
| 57 | CFArrayRef); | 57 | CFArrayRef); |
| 58 | static CFStringRef mac_ctfont_create_preferred_family_for_attributes (CFDictionaryRef); | 58 | static CFStringRef mac_ctfont_create_preferred_family_for_attributes (CFDictionaryRef); |
| 59 | static CFIndex mac_ctfont_shape (CTFontRef, CFStringRef, | 59 | static CFIndex mac_ctfont_shape (CTFontRef, CFStringRef, |
| 60 | struct mac_glyph_layout *, CFIndex); | 60 | struct mac_glyph_layout *, CFIndex); |
| 61 | static CFArrayRef | 61 | static CFArrayRef |
| 62 | mac_font_copy_default_descriptors_for_language (CFStringRef language); | 62 | mac_font_copy_default_descriptors_for_language (CFStringRef language); |
| 63 | 63 | ||
| 64 | static CFStringRef | 64 | static CFStringRef |
| 65 | mac_font_copy_default_name_for_charset_and_languages (CFCharacterSetRef charset, | 65 | mac_font_copy_default_name_for_charset_and_languages (CFCharacterSetRef charset, |
| 66 | CFArrayRef languages); | 66 | CFArrayRef languages); |
| 67 | 67 | ||
| 68 | #if USE_CT_GLYPH_INFO | 68 | #if USE_CT_GLYPH_INFO |
| 69 | static CGGlyph mac_ctfont_get_glyph_for_cid (CTFontRef, | 69 | static CGGlyph mac_ctfont_get_glyph_for_cid (CTFontRef, |
| 70 | CTCharacterCollection, | 70 | CTCharacterCollection, |
| 71 | CGFontIndex); | 71 | CGFontIndex); |
| 72 | #endif | 72 | #endif |
| 73 | 73 | ||
| 74 | /* The font property key specifying the font design destination. The | 74 | /* The font property key specifying the font design destination. The |
| @@ -129,26 +129,26 @@ static const CGAffineTransform synthetic_italic_atfm = {1, 0, 0.25, 1, 0, 0}; | |||
| 129 | static const CGFloat synthetic_bold_factor = 0.024; | 129 | static const CGFloat synthetic_bold_factor = 0.024; |
| 130 | 130 | ||
| 131 | static Boolean cfnumber_get_font_symbolic_traits_value (CFNumberRef, | 131 | static Boolean cfnumber_get_font_symbolic_traits_value (CFNumberRef, |
| 132 | FontSymbolicTraits *); | 132 | FontSymbolicTraits *); |
| 133 | static void macfont_store_descriptor_attributes (FontDescriptorRef, | 133 | static void macfont_store_descriptor_attributes (FontDescriptorRef, |
| 134 | Lisp_Object); | 134 | Lisp_Object); |
| 135 | static Lisp_Object macfont_descriptor_entity (FontDescriptorRef, | 135 | static Lisp_Object macfont_descriptor_entity (FontDescriptorRef, |
| 136 | Lisp_Object, | 136 | Lisp_Object, |
| 137 | FontSymbolicTraits); | 137 | FontSymbolicTraits); |
| 138 | static CFStringRef macfont_create_family_with_symbol (Lisp_Object); | 138 | static CFStringRef macfont_create_family_with_symbol (Lisp_Object); |
| 139 | static int macfont_glyph_extents (struct font *, CGGlyph, | 139 | static int macfont_glyph_extents (struct font *, CGGlyph, |
| 140 | struct font_metrics *, CGFloat *, int); | 140 | struct font_metrics *, CGFloat *, int); |
| 141 | static CFMutableDictionaryRef macfont_create_attributes_with_spec (Lisp_Object); | 141 | static CFMutableDictionaryRef macfont_create_attributes_with_spec (Lisp_Object); |
| 142 | static Boolean macfont_supports_charset_and_languages_p (FontDescriptorRef, | 142 | static Boolean macfont_supports_charset_and_languages_p (FontDescriptorRef, |
| 143 | CFCharacterSetRef, | 143 | CFCharacterSetRef, |
| 144 | Lisp_Object, | 144 | Lisp_Object, |
| 145 | CFArrayRef); | 145 | CFArrayRef); |
| 146 | static CFIndex macfont_closest_traits_index (CFArrayRef, | 146 | static Boolean macfont_closest_traits_index_p (CFArrayRef, FontSymbolicTraits, |
| 147 | FontSymbolicTraits); | 147 | CFIndex); |
| 148 | static CFDataRef mac_font_copy_uvs_table (FontRef); | 148 | static CFDataRef mac_font_copy_uvs_table (FontRef); |
| 149 | static void mac_font_get_glyphs_for_variants (CFDataRef, UTF32Char, | 149 | static void mac_font_get_glyphs_for_variants (CFDataRef, UTF32Char, |
| 150 | const UTF32Char [], | 150 | const UTF32Char [], |
| 151 | CGGlyph [], CFIndex); | 151 | CGGlyph [], CFIndex); |
| 152 | 152 | ||
| 153 | /* From CFData to a lisp string. Always returns a unibyte string. */ | 153 | /* From CFData to a lisp string. Always returns a unibyte string. */ |
| 154 | 154 | ||
| @@ -180,15 +180,15 @@ cfstring_to_lisp_nodecode (CFStringRef string) | |||
| 180 | CFIndex i, length = CFStringGetLength (string); | 180 | CFIndex i, length = CFStringGetLength (string); |
| 181 | 181 | ||
| 182 | for (i = 0; i < length; i++) | 182 | for (i = 0; i < length; i++) |
| 183 | if (CFStringGetCharacterAtIndex (string, i) == 0) | 183 | if (CFStringGetCharacterAtIndex (string, i) == 0) |
| 184 | break; | 184 | break; |
| 185 | 185 | ||
| 186 | if (i == length) | 186 | if (i == length) |
| 187 | return make_unibyte_string (s, strlen (s)); | 187 | return make_unibyte_string (s, strlen (s)); |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | data = CFStringCreateExternalRepresentation (NULL, string, | 190 | data = CFStringCreateExternalRepresentation (NULL, string, |
| 191 | kCFStringEncodingUTF8, '?'); | 191 | kCFStringEncodingUTF8, '?'); |
| 192 | if (data) | 192 | if (data) |
| 193 | { | 193 | { |
| 194 | result = cfdata_to_lisp (data); | 194 | result = cfdata_to_lisp (data); |
| @@ -206,12 +206,12 @@ static CFStringRef | |||
| 206 | cfstring_create_with_string_noencode (Lisp_Object s) | 206 | cfstring_create_with_string_noencode (Lisp_Object s) |
| 207 | { | 207 | { |
| 208 | CFStringRef string = CFStringCreateWithBytes (NULL, SDATA (s), SBYTES (s), | 208 | CFStringRef string = CFStringCreateWithBytes (NULL, SDATA (s), SBYTES (s), |
| 209 | kCFStringEncodingUTF8, false); | 209 | kCFStringEncodingUTF8, false); |
| 210 | 210 | ||
| 211 | if (string == NULL) | 211 | if (string == NULL) |
| 212 | /* Failed to interpret as UTF 8. Fall back on Mac Roman. */ | 212 | /* Failed to interpret as UTF 8. Fall back on Mac Roman. */ |
| 213 | string = CFStringCreateWithBytes (NULL, SDATA (s), SBYTES (s), | 213 | string = CFStringCreateWithBytes (NULL, SDATA (s), SBYTES (s), |
| 214 | kCFStringEncodingMacRoman, false); | 214 | kCFStringEncodingMacRoman, false); |
| 215 | 215 | ||
| 216 | return string; | 216 | return string; |
| 217 | } | 217 | } |
| @@ -226,7 +226,7 @@ mac_screen_font_get_advance_width_for_glyph (ScreenFontRef font, CGGlyph glyph) | |||
| 226 | 226 | ||
| 227 | static CGGlyph | 227 | static CGGlyph |
| 228 | mac_font_get_glyph_for_cid (FontRef font, CharacterCollection collection, | 228 | mac_font_get_glyph_for_cid (FontRef font, CharacterCollection collection, |
| 229 | CGFontIndex cid) | 229 | CGFontIndex cid) |
| 230 | { | 230 | { |
| 231 | #if USE_CT_GLYPH_INFO | 231 | #if USE_CT_GLYPH_INFO |
| 232 | return mac_ctfont_get_glyph_for_cid ((CTFontRef) font, collection, cid); | 232 | return mac_ctfont_get_glyph_for_cid ((CTFontRef) font, collection, cid); |
| @@ -237,17 +237,17 @@ mac_font_get_glyph_for_cid (FontRef font, CharacterCollection collection, | |||
| 237 | unichar characters[] = {0xfffd}; | 237 | unichar characters[] = {0xfffd}; |
| 238 | NSString *string = | 238 | NSString *string = |
| 239 | [NSString stringWithCharacters:characters | 239 | [NSString stringWithCharacters:characters |
| 240 | length:ARRAYELTS (characters)]; | 240 | length:ARRAYELTS (characters)]; |
| 241 | NSGlyphInfo *glyphInfo = | 241 | NSGlyphInfo *glyphInfo = |
| 242 | [NSGlyphInfo glyphInfoWithCharacterIdentifier:cid | 242 | [NSGlyphInfo glyphInfoWithCharacterIdentifier:cid |
| 243 | collection:collection | 243 | collection:collection |
| 244 | baseString:string]; | 244 | baseString:string]; |
| 245 | NSDictionary *attributes = | 245 | NSDictionary *attributes = |
| 246 | [NSDictionary dictionaryWithObjectsAndKeys:nsFont,NSFontAttributeName, | 246 | [NSDictionary dictionaryWithObjectsAndKeys:nsFont,NSFontAttributeName, |
| 247 | glyphInfo,NSGlyphInfoAttributeName,nil]; | 247 | glyphInfo,NSGlyphInfoAttributeName,nil]; |
| 248 | NSTextStorage *textStorage = | 248 | NSTextStorage *textStorage = |
| 249 | [[NSTextStorage alloc] initWithString:string | 249 | [[NSTextStorage alloc] initWithString:string |
| 250 | attributes:attributes]; | 250 | attributes:attributes]; |
| 251 | NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init]; | 251 | NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init]; |
| 252 | NSTextContainer *textContainer = [[NSTextContainer alloc] init]; | 252 | NSTextContainer *textContainer = [[NSTextContainer alloc] init]; |
| 253 | NSFont *fontInTextStorage; | 253 | NSFont *fontInTextStorage; |
| @@ -261,14 +261,14 @@ mac_font_get_glyph_for_cid (FontRef font, CharacterCollection collection, | |||
| 261 | (void) [layoutManager glyphRangeForTextContainer:textContainer]; | 261 | (void) [layoutManager glyphRangeForTextContainer:textContainer]; |
| 262 | 262 | ||
| 263 | fontInTextStorage = [textStorage attribute:NSFontAttributeName atIndex:0 | 263 | fontInTextStorage = [textStorage attribute:NSFontAttributeName atIndex:0 |
| 264 | effectiveRange:NULL]; | 264 | effectiveRange:NULL]; |
| 265 | if (fontInTextStorage == nsFont | 265 | if (fontInTextStorage == nsFont |
| 266 | || [[fontInTextStorage fontName] isEqualToString:[nsFont fontName]]) | 266 | || [[fontInTextStorage fontName] isEqualToString:[nsFont fontName]]) |
| 267 | { | 267 | { |
| 268 | NSGlyph glyph = [layoutManager glyphAtIndex:0]; | 268 | NSGlyph glyph = [layoutManager glyphAtIndex:0]; |
| 269 | 269 | ||
| 270 | if (glyph < [nsFont numberOfGlyphs]) | 270 | if (glyph < [nsFont numberOfGlyphs]) |
| 271 | result = glyph; | 271 | result = glyph; |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | [textStorage release]; | 274 | [textStorage release]; |
| @@ -292,7 +292,7 @@ mac_screen_font_create_with_name (CFStringRef name, CGFloat size) | |||
| 292 | 292 | ||
| 293 | static Boolean | 293 | static Boolean |
| 294 | mac_screen_font_get_metrics (ScreenFontRef font, CGFloat *ascent, | 294 | mac_screen_font_get_metrics (ScreenFontRef font, CGFloat *ascent, |
| 295 | CGFloat *descent, CGFloat *leading) | 295 | CGFloat *descent, CGFloat *leading) |
| 296 | { | 296 | { |
| 297 | NSFont *nsFont = [(NSFont *)font printerFont]; | 297 | NSFont *nsFont = [(NSFont *)font printerFont]; |
| 298 | NSTextStorage *textStorage; | 298 | NSTextStorage *textStorage; |
| @@ -323,7 +323,7 @@ mac_screen_font_get_metrics (ScreenFontRef font, CGFloat *ascent, | |||
| 323 | } | 323 | } |
| 324 | 324 | ||
| 325 | usedRect = [layoutManager lineFragmentUsedRectForGlyphAtIndex:0 | 325 | usedRect = [layoutManager lineFragmentUsedRectForGlyphAtIndex:0 |
| 326 | effectiveRange:NULL]; | 326 | effectiveRange:NULL]; |
| 327 | spaceLocation = [layoutManager locationForGlyphAtIndex:0]; | 327 | spaceLocation = [layoutManager locationForGlyphAtIndex:0]; |
| 328 | [textStorage release]; | 328 | [textStorage release]; |
| 329 | 329 | ||
| @@ -342,8 +342,8 @@ mac_screen_font_get_metrics (ScreenFontRef font, CGFloat *ascent, | |||
| 342 | 342 | ||
| 343 | static CFIndex | 343 | static CFIndex |
| 344 | mac_font_shape_1 (NSFont *font, NSString *string, | 344 | mac_font_shape_1 (NSFont *font, NSString *string, |
| 345 | struct mac_glyph_layout *glyph_layouts, CFIndex glyph_len, | 345 | struct mac_glyph_layout *glyph_layouts, CFIndex glyph_len, |
| 346 | BOOL screen_font_p) | 346 | BOOL screen_font_p) |
| 347 | { | 347 | { |
| 348 | NSUInteger i; | 348 | NSUInteger i; |
| 349 | CFIndex result = 0; | 349 | CFIndex result = 0; |
| @@ -360,7 +360,7 @@ mac_font_shape_1 (NSFont *font, NSString *string, | |||
| 360 | 360 | ||
| 361 | /* Append a trailing space to measure baseline position. */ | 361 | /* Append a trailing space to measure baseline position. */ |
| 362 | [textStorage appendAttributedString:([[[NSAttributedString alloc] | 362 | [textStorage appendAttributedString:([[[NSAttributedString alloc] |
| 363 | initWithString:@" "] autorelease])]; | 363 | initWithString:@" "] autorelease])]; |
| 364 | [textStorage setFont:font]; | 364 | [textStorage setFont:font]; |
| 365 | [textContainer setLineFragmentPadding:0]; | 365 | [textContainer setLineFragmentPadding:0]; |
| 366 | [layoutManager setUsesScreenFonts:screen_font_p]; | 366 | [layoutManager setUsesScreenFonts:screen_font_p]; |
| @@ -396,13 +396,13 @@ mac_font_shape_1 (NSFont *font, NSString *string, | |||
| 396 | { | 396 | { |
| 397 | NSRange range; | 397 | NSRange range; |
| 398 | NSFont *fontInTextStorage = | 398 | NSFont *fontInTextStorage = |
| 399 | [textStorage attribute:NSFontAttributeName atIndex:i | 399 | [textStorage attribute:NSFontAttributeName atIndex:i |
| 400 | longestEffectiveRange:&range | 400 | longestEffectiveRange:&range |
| 401 | inRange:(NSMakeRange (0, stringLength))]; | 401 | inRange:(NSMakeRange (0, stringLength))]; |
| 402 | 402 | ||
| 403 | if (!(fontInTextStorage == font | 403 | if (!(fontInTextStorage == font |
| 404 | || [[fontInTextStorage fontName] isEqualToString:[font fontName]])) | 404 | || [[fontInTextStorage fontName] isEqualToString:[font fontName]])) |
| 405 | break; | 405 | break; |
| 406 | i = NSMaxRange (range); | 406 | i = NSMaxRange (range); |
| 407 | } | 407 | } |
| 408 | if (i < stringLength) | 408 | if (i < stringLength) |
| @@ -414,12 +414,12 @@ mac_font_shape_1 (NSFont *font, NSString *string, | |||
| 414 | NSRange range = NSMakeRange (0, stringLength); | 414 | NSRange range = NSMakeRange (0, stringLength); |
| 415 | 415 | ||
| 416 | range = [layoutManager glyphRangeForCharacterRange:range | 416 | range = [layoutManager glyphRangeForCharacterRange:range |
| 417 | actualCharacterRange:NULL]; | 417 | actualCharacterRange:NULL]; |
| 418 | numberOfGlyphs = NSMaxRange (range); | 418 | numberOfGlyphs = NSMaxRange (range); |
| 419 | used = numberOfGlyphs; | 419 | used = numberOfGlyphs; |
| 420 | for (i = 0; i < numberOfGlyphs; i++) | 420 | for (i = 0; i < numberOfGlyphs; i++) |
| 421 | if ([layoutManager notShownAttributeForGlyphAtIndex:i]) | 421 | if ([layoutManager notShownAttributeForGlyphAtIndex:i]) |
| 422 | used--; | 422 | used--; |
| 423 | } | 423 | } |
| 424 | 424 | ||
| 425 | if (0 < used && used <= glyph_len) | 425 | if (0 < used && used <= glyph_len) |
| @@ -432,186 +432,186 @@ mac_font_shape_1 (NSFont *font, NSString *string, | |||
| 432 | 432 | ||
| 433 | glyphIndex = 0; | 433 | glyphIndex = 0; |
| 434 | while ([layoutManager notShownAttributeForGlyphAtIndex:glyphIndex]) | 434 | while ([layoutManager notShownAttributeForGlyphAtIndex:glyphIndex]) |
| 435 | glyphIndex++; | 435 | glyphIndex++; |
| 436 | 436 | ||
| 437 | /* For now we assume the direction is not changed within the | 437 | /* For now we assume the direction is not changed within the |
| 438 | string. */ | 438 | string. */ |
| 439 | [layoutManager getGlyphsInRange:(NSMakeRange (glyphIndex, 1)) | 439 | [layoutManager getGlyphsInRange:(NSMakeRange (glyphIndex, 1)) |
| 440 | glyphs:NULL characterIndexes:NULL | 440 | glyphs:NULL characterIndexes:NULL |
| 441 | glyphInscriptions:NULL elasticBits:NULL | 441 | glyphInscriptions:NULL elasticBits:NULL |
| 442 | bidiLevels:&bidiLevel]; | 442 | bidiLevels:&bidiLevel]; |
| 443 | if (bidiLevel & 1) | 443 | if (bidiLevel & 1) |
| 444 | permutation = xmalloc (sizeof (NSUInteger) * used); | 444 | permutation = xmalloc (sizeof (NSUInteger) * used); |
| 445 | else | 445 | else |
| 446 | permutation = NULL; | 446 | permutation = NULL; |
| 447 | 447 | ||
| 448 | #define RIGHT_TO_LEFT_P permutation | 448 | #define RIGHT_TO_LEFT_P permutation |
| 449 | 449 | ||
| 450 | /* Fill the `comp_range' member of struct mac_glyph_layout, and | 450 | /* Fill the `comp_range' member of struct mac_glyph_layout, and |
| 451 | setup a permutation for right-to-left text. */ | 451 | setup a permutation for right-to-left text. */ |
| 452 | compRange = NSMakeRange (0, 0); | 452 | compRange = NSMakeRange (0, 0); |
| 453 | for (range = NSMakeRange (0, 0); NSMaxRange (range) < used; | 453 | for (range = NSMakeRange (0, 0); NSMaxRange (range) < used; |
| 454 | range.length++) | 454 | range.length++) |
| 455 | { | 455 | { |
| 456 | struct mac_glyph_layout *gl = glyph_layouts + NSMaxRange (range); | 456 | struct mac_glyph_layout *gl = glyph_layouts + NSMaxRange (range); |
| 457 | NSUInteger characterIndex = | 457 | NSUInteger characterIndex = |
| 458 | [layoutManager characterIndexForGlyphAtIndex:glyphIndex]; | 458 | [layoutManager characterIndexForGlyphAtIndex:glyphIndex]; |
| 459 | 459 | ||
| 460 | gl->string_index = characterIndex; | 460 | gl->string_index = characterIndex; |
| 461 | 461 | ||
| 462 | if (characterIndex >= NSMaxRange (compRange)) | 462 | if (characterIndex >= NSMaxRange (compRange)) |
| 463 | { | 463 | { |
| 464 | compRange.location = NSMaxRange (compRange); | 464 | compRange.location = NSMaxRange (compRange); |
| 465 | do | 465 | do |
| 466 | { | 466 | { |
| 467 | NSRange characterRange = | 467 | NSRange characterRange = |
| 468 | [string | 468 | [string |
| 469 | rangeOfComposedCharacterSequenceAtIndex:characterIndex]; | 469 | rangeOfComposedCharacterSequenceAtIndex:characterIndex]; |
| 470 | 470 | ||
| 471 | compRange.length = | 471 | compRange.length = |
| 472 | NSMaxRange (characterRange) - compRange.location; | 472 | NSMaxRange (characterRange) - compRange.location; |
| 473 | [layoutManager glyphRangeForCharacterRange:compRange | 473 | [layoutManager glyphRangeForCharacterRange:compRange |
| 474 | actualCharacterRange:&characterRange]; | 474 | actualCharacterRange:&characterRange]; |
| 475 | characterIndex = NSMaxRange (characterRange) - 1; | 475 | characterIndex = NSMaxRange (characterRange) - 1; |
| 476 | } | 476 | } |
| 477 | while (characterIndex >= NSMaxRange (compRange)); | 477 | while (characterIndex >= NSMaxRange (compRange)); |
| 478 | 478 | ||
| 479 | if (RIGHT_TO_LEFT_P) | 479 | if (RIGHT_TO_LEFT_P) |
| 480 | for (i = 0; i < range.length; i++) | 480 | for (i = 0; i < range.length; i++) |
| 481 | permutation[range.location + i] = NSMaxRange (range) - i - 1; | 481 | permutation[range.location + i] = NSMaxRange (range) - i - 1; |
| 482 | 482 | ||
| 483 | range = NSMakeRange (NSMaxRange (range), 0); | 483 | range = NSMakeRange (NSMaxRange (range), 0); |
| 484 | } | 484 | } |
| 485 | 485 | ||
| 486 | gl->comp_range.location = compRange.location; | 486 | gl->comp_range.location = compRange.location; |
| 487 | gl->comp_range.length = compRange.length; | 487 | gl->comp_range.length = compRange.length; |
| 488 | 488 | ||
| 489 | while (++glyphIndex < numberOfGlyphs) | 489 | while (++glyphIndex < numberOfGlyphs) |
| 490 | if (![layoutManager notShownAttributeForGlyphAtIndex:glyphIndex]) | 490 | if (![layoutManager notShownAttributeForGlyphAtIndex:glyphIndex]) |
| 491 | break; | 491 | break; |
| 492 | } | 492 | } |
| 493 | if (RIGHT_TO_LEFT_P) | 493 | if (RIGHT_TO_LEFT_P) |
| 494 | for (i = 0; i < range.length; i++) | 494 | for (i = 0; i < range.length; i++) |
| 495 | permutation[range.location + i] = NSMaxRange (range) - i - 1; | 495 | permutation[range.location + i] = NSMaxRange (range) - i - 1; |
| 496 | 496 | ||
| 497 | /* Then fill the remaining members. */ | 497 | /* Then fill the remaining members. */ |
| 498 | glyphIndex = prevGlyphIndex = 0; | 498 | glyphIndex = prevGlyphIndex = 0; |
| 499 | while ([layoutManager notShownAttributeForGlyphAtIndex:glyphIndex]) | 499 | while ([layoutManager notShownAttributeForGlyphAtIndex:glyphIndex]) |
| 500 | glyphIndex++; | 500 | glyphIndex++; |
| 501 | 501 | ||
| 502 | if (!RIGHT_TO_LEFT_P) | 502 | if (!RIGHT_TO_LEFT_P) |
| 503 | totalAdvance = 0; | 503 | totalAdvance = 0; |
| 504 | else | 504 | else |
| 505 | { | 505 | { |
| 506 | NSUInteger nrects; | 506 | NSUInteger nrects; |
| 507 | NSRect *glyphRects = | 507 | NSRect *glyphRects = |
| 508 | [layoutManager | 508 | [layoutManager |
| 509 | rectArrayForGlyphRange:(NSMakeRange (0, numberOfGlyphs)) | 509 | rectArrayForGlyphRange:(NSMakeRange (0, numberOfGlyphs)) |
| 510 | withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0)) | 510 | withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0)) |
| 511 | inTextContainer:textContainer rectCount:&nrects]; | 511 | inTextContainer:textContainer rectCount:&nrects]; |
| 512 | 512 | ||
| 513 | totalAdvance = NSMaxX (glyphRects[0]); | 513 | totalAdvance = NSMaxX (glyphRects[0]); |
| 514 | } | 514 | } |
| 515 | 515 | ||
| 516 | for (i = 0; i < used; i++) | 516 | for (i = 0; i < used; i++) |
| 517 | { | 517 | { |
| 518 | struct mac_glyph_layout *gl; | 518 | struct mac_glyph_layout *gl; |
| 519 | NSPoint location; | 519 | NSPoint location; |
| 520 | NSUInteger nextGlyphIndex; | 520 | NSUInteger nextGlyphIndex; |
| 521 | NSRange glyphRange; | 521 | NSRange glyphRange; |
| 522 | NSRect *glyphRects; | 522 | NSRect *glyphRects; |
| 523 | NSUInteger nrects; | 523 | NSUInteger nrects; |
| 524 | 524 | ||
| 525 | if (!RIGHT_TO_LEFT_P) | 525 | if (!RIGHT_TO_LEFT_P) |
| 526 | gl = glyph_layouts + i; | 526 | gl = glyph_layouts + i; |
| 527 | else | 527 | else |
| 528 | { | 528 | { |
| 529 | NSUInteger dest = permutation[i]; | 529 | NSUInteger dest = permutation[i]; |
| 530 | 530 | ||
| 531 | gl = glyph_layouts + dest; | 531 | gl = glyph_layouts + dest; |
| 532 | if (i < dest) | 532 | if (i < dest) |
| 533 | { | 533 | { |
| 534 | CFIndex tmp = gl->string_index; | 534 | CFIndex tmp = gl->string_index; |
| 535 | 535 | ||
| 536 | gl->string_index = glyph_layouts[i].string_index; | 536 | gl->string_index = glyph_layouts[i].string_index; |
| 537 | glyph_layouts[i].string_index = tmp; | 537 | glyph_layouts[i].string_index = tmp; |
| 538 | } | 538 | } |
| 539 | } | 539 | } |
| 540 | gl->glyph_id = [layoutManager glyphAtIndex:glyphIndex]; | 540 | gl->glyph_id = [layoutManager glyphAtIndex:glyphIndex]; |
| 541 | 541 | ||
| 542 | location = [layoutManager locationForGlyphAtIndex:glyphIndex]; | 542 | location = [layoutManager locationForGlyphAtIndex:glyphIndex]; |
| 543 | gl->baseline_delta = spaceLocation.y - location.y; | 543 | gl->baseline_delta = spaceLocation.y - location.y; |
| 544 | 544 | ||
| 545 | for (nextGlyphIndex = glyphIndex + 1; nextGlyphIndex < numberOfGlyphs; | 545 | for (nextGlyphIndex = glyphIndex + 1; nextGlyphIndex < numberOfGlyphs; |
| 546 | nextGlyphIndex++) | 546 | nextGlyphIndex++) |
| 547 | if (![layoutManager | 547 | if (![layoutManager |
| 548 | notShownAttributeForGlyphAtIndex:nextGlyphIndex]) | 548 | notShownAttributeForGlyphAtIndex:nextGlyphIndex]) |
| 549 | break; | 549 | break; |
| 550 | 550 | ||
| 551 | if (!RIGHT_TO_LEFT_P) | 551 | if (!RIGHT_TO_LEFT_P) |
| 552 | { | 552 | { |
| 553 | CGFloat maxX; | 553 | CGFloat maxX; |
| 554 | 554 | ||
| 555 | if (prevGlyphIndex == 0) | 555 | if (prevGlyphIndex == 0) |
| 556 | glyphRange = NSMakeRange (0, nextGlyphIndex); | 556 | glyphRange = NSMakeRange (0, nextGlyphIndex); |
| 557 | else | 557 | else |
| 558 | glyphRange = NSMakeRange (glyphIndex, | 558 | glyphRange = NSMakeRange (glyphIndex, |
| 559 | nextGlyphIndex - glyphIndex); | 559 | nextGlyphIndex - glyphIndex); |
| 560 | glyphRects = | 560 | glyphRects = |
| 561 | [layoutManager | 561 | [layoutManager |
| 562 | rectArrayForGlyphRange:glyphRange | 562 | rectArrayForGlyphRange:glyphRange |
| 563 | withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0)) | 563 | withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0)) |
| 564 | inTextContainer:textContainer rectCount:&nrects]; | 564 | inTextContainer:textContainer rectCount:&nrects]; |
| 565 | maxX = max (NSMaxX (glyphRects[0]), totalAdvance); | 565 | maxX = max (NSMaxX (glyphRects[0]), totalAdvance); |
| 566 | gl->advance_delta = location.x - totalAdvance; | 566 | gl->advance_delta = location.x - totalAdvance; |
| 567 | gl->advance = maxX - totalAdvance; | 567 | gl->advance = maxX - totalAdvance; |
| 568 | totalAdvance = maxX; | 568 | totalAdvance = maxX; |
| 569 | } | 569 | } |
| 570 | else | 570 | else |
| 571 | { | 571 | { |
| 572 | CGFloat minX; | 572 | CGFloat minX; |
| 573 | 573 | ||
| 574 | if (nextGlyphIndex == numberOfGlyphs) | 574 | if (nextGlyphIndex == numberOfGlyphs) |
| 575 | glyphRange = NSMakeRange (prevGlyphIndex, | 575 | glyphRange = NSMakeRange (prevGlyphIndex, |
| 576 | numberOfGlyphs - prevGlyphIndex); | 576 | numberOfGlyphs - prevGlyphIndex); |
| 577 | else | 577 | else |
| 578 | glyphRange = NSMakeRange (prevGlyphIndex, | 578 | glyphRange = NSMakeRange (prevGlyphIndex, |
| 579 | glyphIndex + 1 - prevGlyphIndex); | 579 | glyphIndex + 1 - prevGlyphIndex); |
| 580 | glyphRects = | 580 | glyphRects = |
| 581 | [layoutManager | 581 | [layoutManager |
| 582 | rectArrayForGlyphRange:glyphRange | 582 | rectArrayForGlyphRange:glyphRange |
| 583 | withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0)) | 583 | withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0)) |
| 584 | inTextContainer:textContainer rectCount:&nrects]; | 584 | inTextContainer:textContainer rectCount:&nrects]; |
| 585 | minX = min (NSMinX (glyphRects[0]), totalAdvance); | 585 | minX = min (NSMinX (glyphRects[0]), totalAdvance); |
| 586 | gl->advance = totalAdvance - minX; | 586 | gl->advance = totalAdvance - minX; |
| 587 | totalAdvance = minX; | 587 | totalAdvance = minX; |
| 588 | gl->advance_delta = location.x - totalAdvance; | 588 | gl->advance_delta = location.x - totalAdvance; |
| 589 | } | 589 | } |
| 590 | 590 | ||
| 591 | prevGlyphIndex = glyphIndex + 1; | 591 | prevGlyphIndex = glyphIndex + 1; |
| 592 | glyphIndex = nextGlyphIndex; | 592 | glyphIndex = nextGlyphIndex; |
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | if (RIGHT_TO_LEFT_P) | 595 | if (RIGHT_TO_LEFT_P) |
| 596 | xfree (permutation); | 596 | xfree (permutation); |
| 597 | 597 | ||
| 598 | #undef RIGHT_TO_LEFT_P | 598 | #undef RIGHT_TO_LEFT_P |
| 599 | 599 | ||
| 600 | result = used; | 600 | result = used; |
| 601 | } | 601 | } |
| 602 | [textStorage release]; | 602 | [textStorage release]; |
| 603 | 603 | ||
| 604 | return result; | 604 | return result; |
| 605 | } | 605 | } |
| 606 | 606 | ||
| 607 | static CFIndex | 607 | static CFIndex |
| 608 | mac_screen_font_shape (ScreenFontRef font, CFStringRef string, | 608 | mac_screen_font_shape (ScreenFontRef font, CFStringRef string, |
| 609 | struct mac_glyph_layout *glyph_layouts, | 609 | struct mac_glyph_layout *glyph_layouts, |
| 610 | CFIndex glyph_len) | 610 | CFIndex glyph_len) |
| 611 | { | 611 | { |
| 612 | return mac_font_shape_1 ([(NSFont *)font printerFont], | 612 | return mac_font_shape_1 ([(NSFont *)font printerFont], |
| 613 | (NSString *) string, | 613 | (NSString *) string, |
| 614 | glyph_layouts, glyph_len, YES); | 614 | glyph_layouts, glyph_len, YES); |
| 615 | } | 615 | } |
| 616 | 616 | ||
| 617 | static CGColorRef | 617 | static CGColorRef |
| @@ -649,6 +649,7 @@ get_cgcolor(unsigned long idx, struct frame *f) | |||
| 649 | CGColorRelease (refcol_); \ | 649 | CGColorRelease (refcol_); \ |
| 650 | } while (0) | 650 | } while (0) |
| 651 | 651 | ||
| 652 | |||
| 652 | 653 | ||
| 653 | /* Mac font driver. */ | 654 | /* Mac font driver. */ |
| 654 | 655 | ||
| @@ -711,17 +712,17 @@ static const struct | |||
| 711 | CFStringRef font_names[3]; | 712 | CFStringRef font_names[3]; |
| 712 | } macfont_language_default_font_names[] = { | 713 | } macfont_language_default_font_names[] = { |
| 713 | { CFSTR ("ja"), { CFSTR ("HiraKakuProN-W3"), /* 10.5 - 10.9 */ | 714 | { CFSTR ("ja"), { CFSTR ("HiraKakuProN-W3"), /* 10.5 - 10.9 */ |
| 714 | CFSTR ("HiraKakuPro-W3"), /* 10.4 */ | 715 | CFSTR ("HiraKakuPro-W3"), /* 10.4 */ |
| 715 | NULL }}, | 716 | NULL }}, |
| 716 | { CFSTR ("ko"), { CFSTR ("AppleSDGothicNeo-Regular"), /* 10.8 - 10.9 */ | 717 | { CFSTR ("ko"), { CFSTR ("AppleSDGothicNeo-Regular"), /* 10.8 - 10.9 */ |
| 717 | CFSTR ("AppleGothic"), /* 10.4 - 10.7 */ | 718 | CFSTR ("AppleGothic"), /* 10.4 - 10.7 */ |
| 718 | NULL }}, | 719 | NULL }}, |
| 719 | { CFSTR ("zh-Hans"), { CFSTR ("STHeitiSC-Light"), /* 10.6 - 10.9 */ | 720 | { CFSTR ("zh-Hans"), { CFSTR ("STHeitiSC-Light"), /* 10.6 - 10.9 */ |
| 720 | CFSTR ("STXihei"), /* 10.4 - 10.5 */ | 721 | CFSTR ("STXihei"), /* 10.4 - 10.5 */ |
| 721 | NULL }}, | 722 | NULL }}, |
| 722 | { CFSTR ("zh-Hant"), { CFSTR ("STHeitiTC-Light"), /* 10.6 - 10.9 */ | 723 | { CFSTR ("zh-Hant"), { CFSTR ("STHeitiTC-Light"), /* 10.6 - 10.9 */ |
| 723 | CFSTR ("LiHeiPro"), /* 10.4 - 10.5 */ | 724 | CFSTR ("LiHeiPro"), /* 10.4 - 10.5 */ |
| 724 | NULL }}, | 725 | NULL }}, |
| 725 | { NULL } | 726 | { NULL } |
| 726 | }; | 727 | }; |
| 727 | #endif | 728 | #endif |
| @@ -736,8 +737,8 @@ macfont_update_antialias_threshold (void) | |||
| 736 | 737 | ||
| 737 | threshold = | 738 | threshold = |
| 738 | CFPreferencesGetAppIntegerValue (CFSTR ("AppleAntiAliasingThreshold"), | 739 | CFPreferencesGetAppIntegerValue (CFSTR ("AppleAntiAliasingThreshold"), |
| 739 | kCFPreferencesCurrentApplication, | 740 | kCFPreferencesCurrentApplication, |
| 740 | &valid_p); | 741 | &valid_p); |
| 741 | if (valid_p) | 742 | if (valid_p) |
| 742 | macfont_antialias_threshold = threshold; | 743 | macfont_antialias_threshold = threshold; |
| 743 | } | 744 | } |
| @@ -771,7 +772,7 @@ macfont_store_utf32char_to_unichars (UTF32Char c, UniChar *unichars) | |||
| 771 | 772 | ||
| 772 | static Boolean | 773 | static Boolean |
| 773 | cfnumber_get_font_symbolic_traits_value (CFNumberRef number, | 774 | cfnumber_get_font_symbolic_traits_value (CFNumberRef number, |
| 774 | FontSymbolicTraits *sym_traits) | 775 | FontSymbolicTraits *sym_traits) |
| 775 | { | 776 | { |
| 776 | SInt64 sint64_value; | 777 | SInt64 sint64_value; |
| 777 | 778 | ||
| @@ -789,7 +790,7 @@ cfnumber_get_font_symbolic_traits_value (CFNumberRef number, | |||
| 789 | 790 | ||
| 790 | static void | 791 | static void |
| 791 | macfont_store_descriptor_attributes (FontDescriptorRef desc, | 792 | macfont_store_descriptor_attributes (FontDescriptorRef desc, |
| 792 | Lisp_Object spec_or_entity) | 793 | Lisp_Object spec_or_entity) |
| 793 | { | 794 | { |
| 794 | CFStringRef str; | 795 | CFStringRef str; |
| 795 | CFDictionaryRef dict; | 796 | CFDictionaryRef dict; |
| @@ -797,66 +798,66 @@ macfont_store_descriptor_attributes (FontDescriptorRef desc, | |||
| 797 | CGFloat floatval; | 798 | CGFloat floatval; |
| 798 | 799 | ||
| 799 | str = mac_font_descriptor_copy_attribute (desc, | 800 | str = mac_font_descriptor_copy_attribute (desc, |
| 800 | MAC_FONT_FAMILY_NAME_ATTRIBUTE); | 801 | MAC_FONT_FAMILY_NAME_ATTRIBUTE); |
| 801 | if (str) | 802 | if (str) |
| 802 | { | 803 | { |
| 803 | ASET (spec_or_entity, FONT_FAMILY_INDEX, | 804 | ASET (spec_or_entity, FONT_FAMILY_INDEX, |
| 804 | macfont_intern_prop_cfstring (str)); | 805 | macfont_intern_prop_cfstring (str)); |
| 805 | CFRelease (str); | 806 | CFRelease (str); |
| 806 | } | 807 | } |
| 807 | dict = mac_font_descriptor_copy_attribute (desc, MAC_FONT_TRAITS_ATTRIBUTE); | 808 | dict = mac_font_descriptor_copy_attribute (desc, MAC_FONT_TRAITS_ATTRIBUTE); |
| 808 | if (dict) | 809 | if (dict) |
| 809 | { | 810 | { |
| 810 | struct { | 811 | struct { |
| 811 | enum font_property_index index; | 812 | enum font_property_index index; |
| 812 | CFStringRef trait; | 813 | CFStringRef trait; |
| 813 | CGPoint points[6]; | 814 | CGPoint points[6]; |
| 814 | } numeric_traits[] = | 815 | } numeric_traits[] = |
| 815 | {{FONT_WEIGHT_INDEX, MAC_FONT_WEIGHT_TRAIT, | 816 | {{FONT_WEIGHT_INDEX, MAC_FONT_WEIGHT_TRAIT, |
| 816 | {{-0.4, 50}, /* light */ | 817 | {{-0.4, 50}, /* light */ |
| 817 | {-0.24, 87.5}, /* (semi-light + normal) / 2 */ | 818 | {-0.24, 87.5}, /* (semi-light + normal) / 2 */ |
| 818 | {0, 100}, /* normal */ | 819 | {0, 100}, /* normal */ |
| 819 | {0.24, 140}, /* (semi-bold + normal) / 2 */ | 820 | {0.24, 140}, /* (semi-bold + normal) / 2 */ |
| 820 | {0.4, 200}, /* bold */ | 821 | {0.4, 200}, /* bold */ |
| 821 | {CGFLOAT_MAX, CGFLOAT_MAX}}}, | 822 | {CGFLOAT_MAX, CGFLOAT_MAX}}}, |
| 822 | {FONT_SLANT_INDEX, MAC_FONT_SLANT_TRAIT, | 823 | {FONT_SLANT_INDEX, MAC_FONT_SLANT_TRAIT, |
| 823 | {{0, 100}, {0.1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}, | 824 | {{0, 100}, {0.1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}, |
| 824 | {FONT_WIDTH_INDEX, MAC_FONT_WIDTH_TRAIT, | 825 | {FONT_WIDTH_INDEX, MAC_FONT_WIDTH_TRAIT, |
| 825 | {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}}; | 826 | {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}}; |
| 826 | int i; | 827 | int i; |
| 827 | 828 | ||
| 828 | for (i = 0; i < ARRAYELTS (numeric_traits); i++) | 829 | for (i = 0; i < ARRAYELTS (numeric_traits); i++) |
| 829 | { | 830 | { |
| 830 | num = CFDictionaryGetValue (dict, numeric_traits[i].trait); | 831 | num = CFDictionaryGetValue (dict, numeric_traits[i].trait); |
| 831 | if (num && CFNumberGetValue (num, kCFNumberCGFloatType, &floatval)) | 832 | if (num && CFNumberGetValue (num, kCFNumberCGFloatType, &floatval)) |
| 832 | { | 833 | { |
| 833 | CGPoint *point = numeric_traits[i].points; | 834 | CGPoint *point = numeric_traits[i].points; |
| 834 | 835 | ||
| 835 | while (point->x < floatval) | 836 | while (point->x < floatval) |
| 836 | point++; | 837 | point++; |
| 837 | if (point == numeric_traits[i].points) | 838 | if (point == numeric_traits[i].points) |
| 838 | point++; | 839 | point++; |
| 839 | else if (point->x == CGFLOAT_MAX) | 840 | else if (point->x == CGFLOAT_MAX) |
| 840 | point--; | 841 | point--; |
| 841 | floatval = (point - 1)->y + ((floatval - (point - 1)->x) | 842 | floatval = (point - 1)->y + ((floatval - (point - 1)->x) |
| 842 | * ((point->y - (point - 1)->y) | 843 | * ((point->y - (point - 1)->y) |
| 843 | / (point->x - (point - 1)->x))); | 844 | / (point->x - (point - 1)->x))); |
| 844 | FONT_SET_STYLE (spec_or_entity, numeric_traits[i].index, | 845 | FONT_SET_STYLE (spec_or_entity, numeric_traits[i].index, |
| 845 | make_number (lround (floatval))); | 846 | make_number (lround (floatval))); |
| 846 | } | 847 | } |
| 847 | } | 848 | } |
| 848 | 849 | ||
| 849 | num = CFDictionaryGetValue (dict, MAC_FONT_SYMBOLIC_TRAIT); | 850 | num = CFDictionaryGetValue (dict, MAC_FONT_SYMBOLIC_TRAIT); |
| 850 | if (num) | 851 | if (num) |
| 851 | { | 852 | { |
| 852 | FontSymbolicTraits sym_traits; | 853 | FontSymbolicTraits sym_traits; |
| 853 | int spacing; | 854 | int spacing; |
| 854 | 855 | ||
| 855 | cfnumber_get_font_symbolic_traits_value (num, &sym_traits); | 856 | cfnumber_get_font_symbolic_traits_value (num, &sym_traits); |
| 856 | spacing = (sym_traits & MAC_FONT_TRAIT_MONO_SPACE | 857 | spacing = (sym_traits & MAC_FONT_TRAIT_MONO_SPACE |
| 857 | ? FONT_SPACING_MONO : FONT_SPACING_PROPORTIONAL); | 858 | ? FONT_SPACING_MONO : FONT_SPACING_PROPORTIONAL); |
| 858 | ASET (spec_or_entity, FONT_SPACING_INDEX, make_number (spacing)); | 859 | ASET (spec_or_entity, FONT_SPACING_INDEX, make_number (spacing)); |
| 859 | } | 860 | } |
| 860 | 861 | ||
| 861 | CFRelease (dict); | 862 | CFRelease (dict); |
| 862 | } | 863 | } |
| @@ -871,7 +872,7 @@ macfont_store_descriptor_attributes (FontDescriptorRef desc, | |||
| 871 | 872 | ||
| 872 | static Lisp_Object | 873 | static Lisp_Object |
| 873 | macfont_descriptor_entity (FontDescriptorRef desc, Lisp_Object extra, | 874 | macfont_descriptor_entity (FontDescriptorRef desc, Lisp_Object extra, |
| 874 | FontSymbolicTraits synth_sym_traits) | 875 | FontSymbolicTraits synth_sym_traits) |
| 875 | { | 876 | { |
| 876 | Lisp_Object entity; | 877 | Lisp_Object entity; |
| 877 | CFDictionaryRef dict; | 878 | CFDictionaryRef dict; |
| @@ -891,7 +892,7 @@ macfont_descriptor_entity (FontDescriptorRef desc, Lisp_Object extra, | |||
| 891 | CFNumberRef num = CFDictionaryGetValue (dict, MAC_FONT_SYMBOLIC_TRAIT); | 892 | CFNumberRef num = CFDictionaryGetValue (dict, MAC_FONT_SYMBOLIC_TRAIT); |
| 892 | 893 | ||
| 893 | if (num) | 894 | if (num) |
| 894 | cfnumber_get_font_symbolic_traits_value (num, &sym_traits); | 895 | cfnumber_get_font_symbolic_traits_value (num, &sym_traits); |
| 895 | CFRelease (dict); | 896 | CFRelease (dict); |
| 896 | } | 897 | } |
| 897 | if (EQ (AREF (entity, FONT_SIZE_INDEX), make_number (0))) | 898 | if (EQ (AREF (entity, FONT_SIZE_INDEX), make_number (0))) |
| @@ -899,16 +900,16 @@ macfont_descriptor_entity (FontDescriptorRef desc, Lisp_Object extra, | |||
| 899 | ASET (entity, FONT_EXTRA_INDEX, Fcopy_sequence (extra)); | 900 | ASET (entity, FONT_EXTRA_INDEX, Fcopy_sequence (extra)); |
| 900 | name = mac_font_descriptor_copy_attribute (desc, MAC_FONT_NAME_ATTRIBUTE); | 901 | name = mac_font_descriptor_copy_attribute (desc, MAC_FONT_NAME_ATTRIBUTE); |
| 901 | font_put_extra (entity, QCfont_entity, | 902 | font_put_extra (entity, QCfont_entity, |
| 902 | make_save_ptr_int ((void *) name, sym_traits)); | 903 | make_save_ptr_int ((void *) name, sym_traits)); |
| 903 | if (synth_sym_traits & MAC_FONT_TRAIT_ITALIC) | 904 | if (synth_sym_traits & MAC_FONT_TRAIT_ITALIC) |
| 904 | FONT_SET_STYLE (entity, FONT_SLANT_INDEX, | 905 | FONT_SET_STYLE (entity, FONT_SLANT_INDEX, |
| 905 | make_number (FONT_SLANT_SYNTHETIC_ITALIC)); | 906 | make_number (FONT_SLANT_SYNTHETIC_ITALIC)); |
| 906 | if (synth_sym_traits & MAC_FONT_TRAIT_BOLD) | 907 | if (synth_sym_traits & MAC_FONT_TRAIT_BOLD) |
| 907 | FONT_SET_STYLE (entity, FONT_WEIGHT_INDEX, | 908 | FONT_SET_STYLE (entity, FONT_WEIGHT_INDEX, |
| 908 | make_number (FONT_WEIGHT_SYNTHETIC_BOLD)); | 909 | make_number (FONT_WEIGHT_SYNTHETIC_BOLD)); |
| 909 | if (synth_sym_traits & MAC_FONT_TRAIT_MONO_SPACE) | 910 | if (synth_sym_traits & MAC_FONT_TRAIT_MONO_SPACE) |
| 910 | ASET (entity, FONT_SPACING_INDEX, | 911 | ASET (entity, FONT_SPACING_INDEX, |
| 911 | make_number (FONT_SPACING_SYNTHETIC_MONO)); | 912 | make_number (FONT_SPACING_SYNTHETIC_MONO)); |
| 912 | 913 | ||
| 913 | return entity; | 914 | return entity; |
| 914 | } | 915 | } |
| @@ -948,36 +949,36 @@ macfont_create_family_with_symbol (Lisp_Object symbol) | |||
| 948 | else | 949 | else |
| 949 | while (1) | 950 | while (1) |
| 950 | { | 951 | { |
| 951 | CFIndex i, count; | 952 | CFIndex i, count; |
| 952 | 953 | ||
| 953 | if (families == NULL) | 954 | if (families == NULL) |
| 954 | { | 955 | { |
| 955 | families = mac_font_create_available_families (); | 956 | families = mac_font_create_available_families (); |
| 956 | using_cache_p = 0; | 957 | using_cache_p = 0; |
| 957 | if (families == NULL) | 958 | if (families == NULL) |
| 958 | break; | 959 | break; |
| 959 | } | 960 | } |
| 960 | 961 | ||
| 961 | count = CFArrayGetCount (families); | 962 | count = CFArrayGetCount (families); |
| 962 | i = CFArrayBSearchValues (families, CFRangeMake (0, count), | 963 | i = CFArrayBSearchValues (families, CFRangeMake (0, count), |
| 963 | (const void *) family_name, | 964 | (const void *) family_name, |
| 964 | family_name_comparator, NULL); | 965 | family_name_comparator, NULL); |
| 965 | if (i < count) | 966 | if (i < count) |
| 966 | { | 967 | { |
| 967 | CFStringRef name = CFArrayGetValueAtIndex (families, i); | 968 | CFStringRef name = CFArrayGetValueAtIndex (families, i); |
| 968 | 969 | ||
| 969 | if ((*family_name_comparator) (name, family_name, NULL) | 970 | if ((*family_name_comparator) (name, family_name, NULL) |
| 970 | == kCFCompareEqualTo) | 971 | == kCFCompareEqualTo) |
| 971 | result = CFRetain (name); | 972 | result = CFRetain (name); |
| 972 | } | 973 | } |
| 973 | 974 | ||
| 974 | if (result || !using_cache_p) | 975 | if (result || !using_cache_p) |
| 975 | break; | 976 | break; |
| 976 | else | 977 | else |
| 977 | { | 978 | { |
| 978 | CFRelease (families); | 979 | CFRelease (families); |
| 979 | families = NULL; | 980 | families = NULL; |
| 980 | } | 981 | } |
| 981 | } | 982 | } |
| 982 | 983 | ||
| 983 | CFRelease (family_name); | 984 | CFRelease (family_name); |
| @@ -1004,23 +1005,23 @@ struct macfont_metrics | |||
| 1004 | signed width_frac : WIDTH_FRAC_BITS, width_int : 16 - WIDTH_FRAC_BITS; | 1005 | signed width_frac : WIDTH_FRAC_BITS, width_int : 16 - WIDTH_FRAC_BITS; |
| 1005 | }; | 1006 | }; |
| 1006 | 1007 | ||
| 1007 | #define METRICS_VALUE(metrics, member) \ | 1008 | #define METRICS_VALUE(metrics, member) \ |
| 1008 | (((metrics)->member##_high << 8) | (metrics)->member##_low) | 1009 | (((metrics)->member##_high << 8) | (metrics)->member##_low) |
| 1009 | #define METRICS_SET_VALUE(metrics, member, value) \ | 1010 | #define METRICS_SET_VALUE(metrics, member, value) \ |
| 1010 | do {short tmp = (value); (metrics)->member##_low = tmp & 0xff; \ | 1011 | do {short tmp = (value); (metrics)->member##_low = tmp & 0xff; \ |
| 1011 | (metrics)->member##_high = tmp >> 8;} while (0) | 1012 | (metrics)->member##_high = tmp >> 8;} while (0) |
| 1012 | 1013 | ||
| 1013 | enum metrics_status | 1014 | enum metrics_status |
| 1014 | { | 1015 | { |
| 1015 | METRICS_INVALID = -1, /* metrics entry is invalid */ | 1016 | METRICS_INVALID = -1, /* metrics entry is invalid */ |
| 1016 | METRICS_WIDTH_VALID = -2 /* width is valid but others are invalid */ | 1017 | METRICS_WIDTH_VALID = -2 /* width is valid but others are invalid */ |
| 1017 | }; | 1018 | }; |
| 1018 | 1019 | ||
| 1019 | #define METRICS_STATUS(metrics) \ | 1020 | #define METRICS_STATUS(metrics) \ |
| 1020 | (METRICS_VALUE (metrics, ascent) + METRICS_VALUE (metrics, descent)) | 1021 | (METRICS_VALUE (metrics, ascent) + METRICS_VALUE (metrics, descent)) |
| 1021 | #define METRICS_SET_STATUS(metrics, status) \ | 1022 | #define METRICS_SET_STATUS(metrics, status) \ |
| 1022 | do {METRICS_SET_VALUE (metrics, ascent, 0); \ | 1023 | do {METRICS_SET_VALUE (metrics, ascent, 0); \ |
| 1023 | METRICS_SET_VALUE (metrics, descent, status);} while (0) | 1024 | METRICS_SET_VALUE (metrics, descent, status);} while (0) |
| 1024 | 1025 | ||
| 1025 | #define METRICS_NCOLS_PER_ROW (128) | 1026 | #define METRICS_NCOLS_PER_ROW (128) |
| 1026 | #define LCD_FONT_SMOOTHING_LEFT_MARGIN (0.396f) | 1027 | #define LCD_FONT_SMOOTHING_LEFT_MARGIN (0.396f) |
| @@ -1028,8 +1029,8 @@ enum metrics_status | |||
| 1028 | 1029 | ||
| 1029 | static int | 1030 | static int |
| 1030 | macfont_glyph_extents (struct font *font, CGGlyph glyph, | 1031 | macfont_glyph_extents (struct font *font, CGGlyph glyph, |
| 1031 | struct font_metrics *metrics, CGFloat *advance_delta, | 1032 | struct font_metrics *metrics, CGFloat *advance_delta, |
| 1032 | int force_integral_p) | 1033 | int force_integral_p) |
| 1033 | { | 1034 | { |
| 1034 | struct macfont_info *macfont_info = (struct macfont_info *) font; | 1035 | struct macfont_info *macfont_info = (struct macfont_info *) font; |
| 1035 | FontRef macfont = macfont_info->macfont; | 1036 | FontRef macfont = macfont_info->macfont; |
| @@ -1042,11 +1043,11 @@ macfont_glyph_extents (struct font *font, CGGlyph glyph, | |||
| 1042 | if (row >= macfont_info->metrics_nrows) | 1043 | if (row >= macfont_info->metrics_nrows) |
| 1043 | { | 1044 | { |
| 1044 | macfont_info->metrics = | 1045 | macfont_info->metrics = |
| 1045 | xrealloc (macfont_info->metrics, | 1046 | xrealloc (macfont_info->metrics, |
| 1046 | sizeof (struct macfont_metrics *) * (row + 1)); | 1047 | sizeof (struct macfont_metrics *) * (row + 1)); |
| 1047 | memset (macfont_info->metrics + macfont_info->metrics_nrows, 0, | 1048 | memset (macfont_info->metrics + macfont_info->metrics_nrows, 0, |
| 1048 | (sizeof (struct macfont_metrics *) | 1049 | (sizeof (struct macfont_metrics *) |
| 1049 | * (row + 1 - macfont_info->metrics_nrows))); | 1050 | * (row + 1 - macfont_info->metrics_nrows))); |
| 1050 | macfont_info->metrics_nrows = row + 1; | 1051 | macfont_info->metrics_nrows = row + 1; |
| 1051 | } | 1052 | } |
| 1052 | if (macfont_info->metrics[row] == NULL) | 1053 | if (macfont_info->metrics[row] == NULL) |
| @@ -1056,7 +1057,7 @@ macfont_glyph_extents (struct font *font, CGGlyph glyph, | |||
| 1056 | 1057 | ||
| 1057 | new = xmalloc (sizeof (struct macfont_metrics) * METRICS_NCOLS_PER_ROW); | 1058 | new = xmalloc (sizeof (struct macfont_metrics) * METRICS_NCOLS_PER_ROW); |
| 1058 | for (i = 0; i < METRICS_NCOLS_PER_ROW; i++) | 1059 | for (i = 0; i < METRICS_NCOLS_PER_ROW; i++) |
| 1059 | METRICS_SET_STATUS (new + i, METRICS_INVALID); | 1060 | METRICS_SET_STATUS (new + i, METRICS_INVALID); |
| 1060 | macfont_info->metrics[row] = new; | 1061 | macfont_info->metrics[row] = new; |
| 1061 | } | 1062 | } |
| 1062 | cache = macfont_info->metrics[row] + col; | 1063 | cache = macfont_info->metrics[row] + col; |
| @@ -1066,17 +1067,17 @@ macfont_glyph_extents (struct font *font, CGGlyph glyph, | |||
| 1066 | CGFloat fwidth; | 1067 | CGFloat fwidth; |
| 1067 | 1068 | ||
| 1068 | if (macfont_info->screen_font) | 1069 | if (macfont_info->screen_font) |
| 1069 | fwidth = mac_screen_font_get_advance_width_for_glyph (macfont_info->screen_font, glyph); | 1070 | fwidth = mac_screen_font_get_advance_width_for_glyph (macfont_info->screen_font, glyph); |
| 1070 | else | 1071 | else |
| 1071 | fwidth = mac_font_get_advance_width_for_glyph (macfont, glyph); | 1072 | fwidth = mac_font_get_advance_width_for_glyph (macfont, glyph); |
| 1072 | 1073 | ||
| 1073 | /* For synthetic mono fonts, cache->width_{int,frac} holds the | 1074 | /* For synthetic mono fonts, cache->width_{int,frac} holds the |
| 1074 | advance delta value. */ | 1075 | advance delta value. */ |
| 1075 | if (macfont_info->spacing == MACFONT_SPACING_SYNTHETIC_MONO) | 1076 | if (macfont_info->spacing == MACFONT_SPACING_SYNTHETIC_MONO) |
| 1076 | fwidth = (font->pixel_size - fwidth) / 2; | 1077 | fwidth = (font->pixel_size - fwidth) / 2; |
| 1077 | cache->width_int = lround (fwidth); | 1078 | cache->width_int = lround (fwidth); |
| 1078 | cache->width_frac = lround ((fwidth - cache->width_int) | 1079 | cache->width_frac = lround ((fwidth - cache->width_int) |
| 1079 | * WIDTH_FRAC_SCALE); | 1080 | * WIDTH_FRAC_SCALE); |
| 1080 | METRICS_SET_STATUS (cache, METRICS_WIDTH_VALID); | 1081 | METRICS_SET_STATUS (cache, METRICS_WIDTH_VALID); |
| 1081 | } | 1082 | } |
| 1082 | if (macfont_info->spacing == MACFONT_SPACING_SYNTHETIC_MONO) | 1083 | if (macfont_info->spacing == MACFONT_SPACING_SYNTHETIC_MONO) |
| @@ -1087,52 +1088,52 @@ macfont_glyph_extents (struct font *font, CGGlyph glyph, | |||
| 1087 | if (metrics) | 1088 | if (metrics) |
| 1088 | { | 1089 | { |
| 1089 | if (METRICS_STATUS (cache) == METRICS_WIDTH_VALID) | 1090 | if (METRICS_STATUS (cache) == METRICS_WIDTH_VALID) |
| 1090 | { | 1091 | { |
| 1091 | CGRect bounds = mac_font_get_bounding_rect_for_glyph (macfont, glyph); | 1092 | CGRect bounds = mac_font_get_bounding_rect_for_glyph (macfont, glyph); |
| 1092 | 1093 | ||
| 1093 | if (macfont_info->synthetic_italic_p) | 1094 | if (macfont_info->synthetic_italic_p) |
| 1094 | { | 1095 | { |
| 1095 | /* We assume the members a, b, c, and d in | 1096 | /* We assume the members a, b, c, and d in |
| 1096 | synthetic_italic_atfm are non-negative. */ | 1097 | synthetic_italic_atfm are non-negative. */ |
| 1097 | bounds.origin = | 1098 | bounds.origin = |
| 1098 | CGPointApplyAffineTransform (bounds.origin, | 1099 | CGPointApplyAffineTransform (bounds.origin, |
| 1099 | synthetic_italic_atfm); | 1100 | synthetic_italic_atfm); |
| 1100 | bounds.size = | 1101 | bounds.size = |
| 1101 | CGSizeApplyAffineTransform (bounds.size, synthetic_italic_atfm); | 1102 | CGSizeApplyAffineTransform (bounds.size, synthetic_italic_atfm); |
| 1102 | } | 1103 | } |
| 1103 | if (macfont_info->synthetic_bold_p) | 1104 | if (macfont_info->synthetic_bold_p) |
| 1104 | { | 1105 | { |
| 1105 | CGFloat d = | 1106 | CGFloat d = |
| 1106 | - synthetic_bold_factor * mac_font_get_size (macfont) / 2; | 1107 | - synthetic_bold_factor * mac_font_get_size (macfont) / 2; |
| 1107 | 1108 | ||
| 1108 | bounds = CGRectInset (bounds, d, d); | 1109 | bounds = CGRectInset (bounds, d, d); |
| 1109 | } | 1110 | } |
| 1110 | switch (macfont_info->spacing) | 1111 | switch (macfont_info->spacing) |
| 1111 | { | 1112 | { |
| 1112 | case MACFONT_SPACING_PROPORTIONAL: | 1113 | case MACFONT_SPACING_PROPORTIONAL: |
| 1113 | bounds.origin.x += - (cache->width_frac | 1114 | bounds.origin.x += - (cache->width_frac |
| 1114 | / (CGFloat) (WIDTH_FRAC_SCALE * 2)); | 1115 | / (CGFloat) (WIDTH_FRAC_SCALE * 2)); |
| 1115 | break; | 1116 | break; |
| 1116 | case MACFONT_SPACING_MONO: | 1117 | case MACFONT_SPACING_MONO: |
| 1117 | break; | 1118 | break; |
| 1118 | case MACFONT_SPACING_SYNTHETIC_MONO: | 1119 | case MACFONT_SPACING_SYNTHETIC_MONO: |
| 1119 | bounds.origin.x += (cache->width_int | 1120 | bounds.origin.x += (cache->width_int |
| 1120 | + (cache->width_frac | 1121 | + (cache->width_frac |
| 1121 | / (CGFloat) WIDTH_FRAC_SCALE)); | 1122 | / (CGFloat) WIDTH_FRAC_SCALE)); |
| 1122 | break; | 1123 | break; |
| 1123 | } | 1124 | } |
| 1124 | if (bounds.size.width > 0) | 1125 | if (bounds.size.width > 0) |
| 1125 | { | 1126 | { |
| 1126 | bounds.origin.x -= LCD_FONT_SMOOTHING_LEFT_MARGIN; | 1127 | bounds.origin.x -= LCD_FONT_SMOOTHING_LEFT_MARGIN; |
| 1127 | bounds.size.width += (LCD_FONT_SMOOTHING_LEFT_MARGIN | 1128 | bounds.size.width += (LCD_FONT_SMOOTHING_LEFT_MARGIN |
| 1128 | + LCD_FONT_SMOOTHING_RIGHT_MARGIN); | 1129 | + LCD_FONT_SMOOTHING_RIGHT_MARGIN); |
| 1129 | } | 1130 | } |
| 1130 | bounds = CGRectIntegral (bounds); | 1131 | bounds = CGRectIntegral (bounds); |
| 1131 | METRICS_SET_VALUE (cache, lbearing, CGRectGetMinX (bounds)); | 1132 | METRICS_SET_VALUE (cache, lbearing, CGRectGetMinX (bounds)); |
| 1132 | METRICS_SET_VALUE (cache, rbearing, CGRectGetMaxX (bounds)); | 1133 | METRICS_SET_VALUE (cache, rbearing, CGRectGetMaxX (bounds)); |
| 1133 | METRICS_SET_VALUE (cache, ascent, CGRectGetMaxY (bounds)); | 1134 | METRICS_SET_VALUE (cache, ascent, CGRectGetMaxY (bounds)); |
| 1134 | METRICS_SET_VALUE (cache, descent, -CGRectGetMinY (bounds)); | 1135 | METRICS_SET_VALUE (cache, descent, -CGRectGetMinY (bounds)); |
| 1135 | } | 1136 | } |
| 1136 | metrics->lbearing = METRICS_VALUE (cache, lbearing); | 1137 | metrics->lbearing = METRICS_VALUE (cache, lbearing); |
| 1137 | metrics->rbearing = METRICS_VALUE (cache, rbearing); | 1138 | metrics->rbearing = METRICS_VALUE (cache, rbearing); |
| 1138 | metrics->width = width; | 1139 | metrics->width = width; |
| @@ -1143,22 +1144,22 @@ macfont_glyph_extents (struct font *font, CGGlyph glyph, | |||
| 1143 | if (advance_delta) | 1144 | if (advance_delta) |
| 1144 | { | 1145 | { |
| 1145 | switch (macfont_info->spacing) | 1146 | switch (macfont_info->spacing) |
| 1146 | { | 1147 | { |
| 1147 | case MACFONT_SPACING_PROPORTIONAL: | 1148 | case MACFONT_SPACING_PROPORTIONAL: |
| 1148 | *advance_delta = (force_integral_p ? 0 | 1149 | *advance_delta = (force_integral_p ? 0 |
| 1149 | : - (cache->width_frac | 1150 | : - (cache->width_frac |
| 1150 | / (CGFloat) (WIDTH_FRAC_SCALE * 2))); | 1151 | / (CGFloat) (WIDTH_FRAC_SCALE * 2))); |
| 1151 | break; | 1152 | break; |
| 1152 | case MACFONT_SPACING_MONO: | 1153 | case MACFONT_SPACING_MONO: |
| 1153 | *advance_delta = 0; | 1154 | *advance_delta = 0; |
| 1154 | break; | 1155 | break; |
| 1155 | case MACFONT_SPACING_SYNTHETIC_MONO: | 1156 | case MACFONT_SPACING_SYNTHETIC_MONO: |
| 1156 | *advance_delta = (force_integral_p ? cache->width_int | 1157 | *advance_delta = (force_integral_p ? cache->width_int |
| 1157 | : (cache->width_int | 1158 | : (cache->width_int |
| 1158 | + (cache->width_frac | 1159 | + (cache->width_frac |
| 1159 | / (CGFloat) WIDTH_FRAC_SCALE))); | 1160 | / (CGFloat) WIDTH_FRAC_SCALE))); |
| 1160 | break; | 1161 | break; |
| 1161 | } | 1162 | } |
| 1162 | } | 1163 | } |
| 1163 | 1164 | ||
| 1164 | return width; | 1165 | return width; |
| @@ -1220,7 +1221,7 @@ static CFCharacterSetRef macfont_get_cf_charset (struct font *); | |||
| 1220 | static CFCharacterSetRef macfont_get_cf_charset_for_name (CFStringRef); | 1221 | static CFCharacterSetRef macfont_get_cf_charset_for_name (CFStringRef); |
| 1221 | static CGGlyph macfont_get_glyph_for_character (struct font *, UTF32Char); | 1222 | static CGGlyph macfont_get_glyph_for_character (struct font *, UTF32Char); |
| 1222 | static CGGlyph macfont_get_glyph_for_cid (struct font *font, | 1223 | static CGGlyph macfont_get_glyph_for_cid (struct font *font, |
| 1223 | CharacterCollection, CGFontIndex); | 1224 | CharacterCollection, CGFontIndex); |
| 1224 | static CFDataRef macfont_get_uvs_table (struct font *, CharacterCollection *); | 1225 | static CFDataRef macfont_get_uvs_table (struct font *, CharacterCollection *); |
| 1225 | 1226 | ||
| 1226 | static struct macfont_cache * | 1227 | static struct macfont_cache * |
| @@ -1231,39 +1232,39 @@ macfont_lookup_cache (CFStringRef key) | |||
| 1231 | if (macfont_cache_dictionary == NULL) | 1232 | if (macfont_cache_dictionary == NULL) |
| 1232 | { | 1233 | { |
| 1233 | macfont_cache_dictionary = | 1234 | macfont_cache_dictionary = |
| 1234 | CFDictionaryCreateMutable (NULL, 0, | 1235 | CFDictionaryCreateMutable (NULL, 0, |
| 1235 | &kCFTypeDictionaryKeyCallBacks, NULL); | 1236 | &kCFTypeDictionaryKeyCallBacks, NULL); |
| 1236 | cache = NULL; | 1237 | cache = NULL; |
| 1237 | } | 1238 | } |
| 1238 | else | 1239 | else |
| 1239 | cache = ((struct macfont_cache *) | 1240 | cache = ((struct macfont_cache *) |
| 1240 | CFDictionaryGetValue (macfont_cache_dictionary, key)); | 1241 | CFDictionaryGetValue (macfont_cache_dictionary, key)); |
| 1241 | 1242 | ||
| 1242 | if (cache == NULL) | 1243 | if (cache == NULL) |
| 1243 | { | 1244 | { |
| 1244 | FontRef macfont = mac_font_create_with_name (key, 0); | 1245 | FontRef macfont = mac_font_create_with_name (key, 0); |
| 1245 | 1246 | ||
| 1246 | if (macfont) | 1247 | if (macfont) |
| 1247 | { | 1248 | { |
| 1248 | cache = xzalloc (sizeof (struct macfont_cache)); | 1249 | cache = xzalloc (sizeof (struct macfont_cache)); |
| 1249 | /* Treat the LastResort font as if it contained glyphs for | 1250 | /* Treat the LastResort font as if it contained glyphs for |
| 1250 | all characters. This may look too rough, but neither | 1251 | all characters. This may look too rough, but neither |
| 1251 | CTFontCopyCharacterSet nor -[NSFont coveredCharacterSet] | 1252 | CTFontCopyCharacterSet nor -[NSFont coveredCharacterSet] |
| 1252 | for this font is correct for non-BMP characters on Mac OS | 1253 | for this font is correct for non-BMP characters on Mac OS |
| 1253 | X 10.5, anyway. */ | 1254 | X 10.5, anyway. */ |
| 1254 | if (CFEqual (key, CFSTR ("LastResort"))) | 1255 | if (CFEqual (key, CFSTR ("LastResort"))) |
| 1255 | { | 1256 | { |
| 1256 | CFRange range = CFRangeMake (0, MAX_UNICODE_CHAR + 1); | 1257 | CFRange range = CFRangeMake (0, MAX_UNICODE_CHAR + 1); |
| 1257 | 1258 | ||
| 1258 | cache->cf_charset = | 1259 | cache->cf_charset = |
| 1259 | CFCharacterSetCreateWithCharactersInRange (NULL, range); | 1260 | CFCharacterSetCreateWithCharactersInRange (NULL, range); |
| 1260 | } | 1261 | } |
| 1261 | if (cache->cf_charset == NULL) | 1262 | if (cache->cf_charset == NULL) |
| 1262 | cache->cf_charset = mac_font_copy_character_set (macfont); | 1263 | cache->cf_charset = mac_font_copy_character_set (macfont); |
| 1263 | CFDictionaryAddValue (macfont_cache_dictionary, key, | 1264 | CFDictionaryAddValue (macfont_cache_dictionary, key, |
| 1264 | (const void *) cache); | 1265 | (const void *) cache); |
| 1265 | CFRelease (macfont); | 1266 | CFRelease (macfont); |
| 1266 | } | 1267 | } |
| 1267 | } | 1268 | } |
| 1268 | 1269 | ||
| 1269 | return cache; | 1270 | return cache; |
| @@ -1285,13 +1286,13 @@ macfont_release_cache (struct macfont_cache *cache) | |||
| 1285 | int i; | 1286 | int i; |
| 1286 | 1287 | ||
| 1287 | for (i = 0; i < cache->glyph.nrows; i++) | 1288 | for (i = 0; i < cache->glyph.nrows; i++) |
| 1288 | xfree (cache->glyph.matrix[i]); | 1289 | xfree (cache->glyph.matrix[i]); |
| 1289 | xfree (cache->glyph.matrix); | 1290 | xfree (cache->glyph.matrix); |
| 1290 | if (cache->glyph.dictionary) | 1291 | if (cache->glyph.dictionary) |
| 1291 | CFRelease (cache->glyph.dictionary); | 1292 | CFRelease (cache->glyph.dictionary); |
| 1292 | memset (&cache->glyph, 0, sizeof (cache->glyph)); | 1293 | memset (&cache->glyph, 0, sizeof (cache->glyph)); |
| 1293 | if (cache->uvs.table) | 1294 | if (cache->uvs.table) |
| 1294 | CFRelease (cache->uvs.table); | 1295 | CFRelease (cache->uvs.table); |
| 1295 | memset (&cache->uvs, 0, sizeof (cache->uvs)); | 1296 | memset (&cache->uvs, 0, sizeof (cache->uvs)); |
| 1296 | } | 1297 | } |
| 1297 | } | 1298 | } |
| @@ -1325,124 +1326,124 @@ macfont_get_glyph_for_character (struct font *font, UTF32Char c) | |||
| 1325 | int nkeys_or_perm = cache->glyph.row_nkeys_or_perm[row]; | 1326 | int nkeys_or_perm = cache->glyph.row_nkeys_or_perm[row]; |
| 1326 | 1327 | ||
| 1327 | if (nkeys_or_perm < ROW_PERM_OFFSET) | 1328 | if (nkeys_or_perm < ROW_PERM_OFFSET) |
| 1328 | { | 1329 | { |
| 1329 | UniChar unichars[256], ch; | 1330 | UniChar unichars[256], ch; |
| 1330 | CGGlyph *glyphs; | 1331 | CGGlyph *glyphs; |
| 1331 | int i, len; | 1332 | int i, len; |
| 1332 | int nrows; | 1333 | int nrows; |
| 1333 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 | 1334 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 |
| 1334 | dispatch_queue_t queue; | 1335 | dispatch_queue_t queue; |
| 1335 | dispatch_group_t group = NULL; | 1336 | dispatch_group_t group = NULL; |
| 1336 | #else | 1337 | #else |
| 1337 | int nkeys; | 1338 | int nkeys; |
| 1338 | #endif | 1339 | #endif |
| 1339 | 1340 | ||
| 1340 | if (row != 0) | 1341 | if (row != 0) |
| 1341 | { | 1342 | { |
| 1342 | CFMutableDictionaryRef dictionary; | 1343 | CFMutableDictionaryRef dictionary; |
| 1343 | uintptr_t key, value; | 1344 | uintptr_t key, value; |
| 1344 | int nshifts; | 1345 | int nshifts; |
| 1345 | CGGlyph glyph; | 1346 | CGGlyph glyph; |
| 1346 | 1347 | ||
| 1347 | if (cache->glyph.dictionary == NULL) | 1348 | if (cache->glyph.dictionary == NULL) |
| 1348 | cache->glyph.dictionary = | 1349 | cache->glyph.dictionary = |
| 1349 | CFDictionaryCreateMutable (NULL, 0, NULL, NULL); | 1350 | CFDictionaryCreateMutable (NULL, 0, NULL, NULL); |
| 1350 | dictionary = cache->glyph.dictionary; | 1351 | dictionary = cache->glyph.dictionary; |
| 1351 | key = c / NGLYPHS_IN_VALUE; | 1352 | key = c / NGLYPHS_IN_VALUE; |
| 1352 | nshifts = ((c % NGLYPHS_IN_VALUE) * sizeof (CGGlyph) * 8); | 1353 | nshifts = ((c % NGLYPHS_IN_VALUE) * sizeof (CGGlyph) * 8); |
| 1353 | value = ((uintptr_t) | 1354 | value = ((uintptr_t) |
| 1354 | CFDictionaryGetValue (dictionary, (const void *) key)); | 1355 | CFDictionaryGetValue (dictionary, (const void *) key)); |
| 1355 | glyph = (value >> nshifts); | 1356 | glyph = (value >> nshifts); |
| 1356 | if (glyph) | 1357 | if (glyph) |
| 1357 | return glyph; | 1358 | return glyph; |
| 1358 | 1359 | ||
| 1359 | if (nkeys_or_perm + 1 != ROW_PERM_OFFSET) | 1360 | if (nkeys_or_perm + 1 != ROW_PERM_OFFSET) |
| 1360 | { | 1361 | { |
| 1361 | ch = c; | 1362 | ch = c; |
| 1362 | if (!mac_font_get_glyphs_for_characters (macfont, &ch, | 1363 | if (!mac_font_get_glyphs_for_characters (macfont, &ch, |
| 1363 | &glyph, 1) | 1364 | &glyph, 1) |
| 1364 | || glyph == 0) | 1365 | || glyph == 0) |
| 1365 | glyph = kCGFontIndexInvalid; | 1366 | glyph = kCGFontIndexInvalid; |
| 1366 | 1367 | ||
| 1367 | if (value == 0) | 1368 | if (value == 0) |
| 1368 | cache->glyph.row_nkeys_or_perm[row] = nkeys_or_perm + 1; | 1369 | cache->glyph.row_nkeys_or_perm[row] = nkeys_or_perm + 1; |
| 1369 | value |= ((uintptr_t) glyph << nshifts); | 1370 | value |= ((uintptr_t) glyph << nshifts); |
| 1370 | CFDictionarySetValue (dictionary, (const void *) key, | 1371 | CFDictionarySetValue (dictionary, (const void *) key, |
| 1371 | (const void *) value); | 1372 | (const void *) value); |
| 1372 | 1373 | ||
| 1373 | return glyph; | 1374 | return glyph; |
| 1374 | } | 1375 | } |
| 1375 | 1376 | ||
| 1376 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 | 1377 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 |
| 1377 | queue = | 1378 | queue = |
| 1378 | dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | 1379 | dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); |
| 1379 | group = dispatch_group_create (); | 1380 | group = dispatch_group_create (); |
| 1380 | dispatch_group_async (group, queue, ^{ | 1381 | dispatch_group_async (group, queue, ^{ |
| 1381 | int nkeys; | 1382 | int nkeys; |
| 1382 | uintptr_t key; | 1383 | uintptr_t key; |
| 1383 | #endif | 1384 | #endif |
| 1384 | nkeys = nkeys_or_perm; | 1385 | nkeys = nkeys_or_perm; |
| 1385 | for (key = row * (256 / NGLYPHS_IN_VALUE); ; key++) | 1386 | for (key = row * (256 / NGLYPHS_IN_VALUE); ; key++) |
| 1386 | if (CFDictionaryContainsKey (dictionary, | 1387 | if (CFDictionaryContainsKey (dictionary, |
| 1387 | (const void *) key)) | 1388 | (const void *) key)) |
| 1388 | { | 1389 | { |
| 1389 | CFDictionaryRemoveValue (dictionary, | 1390 | CFDictionaryRemoveValue (dictionary, |
| 1390 | (const void *) key); | 1391 | (const void *) key); |
| 1391 | if (--nkeys == 0) | 1392 | if (--nkeys == 0) |
| 1392 | break; | 1393 | break; |
| 1393 | } | 1394 | } |
| 1394 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 | 1395 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 |
| 1395 | }); | 1396 | }); |
| 1396 | #endif | 1397 | #endif |
| 1397 | } | 1398 | } |
| 1398 | 1399 | ||
| 1399 | len = 0; | 1400 | len = 0; |
| 1400 | for (i = 0; i < 256; i++) | 1401 | for (i = 0; i < 256; i++) |
| 1401 | { | 1402 | { |
| 1402 | ch = row * 256 + i; | 1403 | ch = row * 256 + i; |
| 1403 | if (CFCharacterSetIsLongCharacterMember (cache->cf_charset, ch)) | 1404 | if (CFCharacterSetIsLongCharacterMember (cache->cf_charset, ch)) |
| 1404 | unichars[len++] = ch; | 1405 | unichars[len++] = ch; |
| 1405 | } | 1406 | } |
| 1406 | 1407 | ||
| 1407 | glyphs = xmalloc (sizeof (CGGlyph) * 256); | 1408 | glyphs = xmalloc (sizeof (CGGlyph) * 256); |
| 1408 | if (len > 0) | 1409 | if (len > 0) |
| 1409 | { | 1410 | { |
| 1410 | mac_font_get_glyphs_for_characters (macfont, unichars, | 1411 | mac_font_get_glyphs_for_characters (macfont, unichars, |
| 1411 | glyphs, len); | 1412 | glyphs, len); |
| 1412 | while (i > len) | 1413 | while (i > len) |
| 1413 | { | 1414 | { |
| 1414 | int next = unichars[len - 1] % 256; | 1415 | int next = unichars[len - 1] % 256; |
| 1415 | 1416 | ||
| 1416 | while (--i > next) | 1417 | while (--i > next) |
| 1417 | glyphs[i] = kCGFontIndexInvalid; | 1418 | glyphs[i] = kCGFontIndexInvalid; |
| 1418 | 1419 | ||
| 1419 | len--; | 1420 | len--; |
| 1420 | glyphs[i] = glyphs[len]; | 1421 | glyphs[i] = glyphs[len]; |
| 1421 | if (len == 0) | 1422 | if (len == 0) |
| 1422 | break; | 1423 | break; |
| 1423 | } | 1424 | } |
| 1424 | } | 1425 | } |
| 1425 | if (i > len) | 1426 | if (i > len) |
| 1426 | while (i-- > 0) | 1427 | while (i-- > 0) |
| 1427 | glyphs[i] = kCGFontIndexInvalid; | 1428 | glyphs[i] = kCGFontIndexInvalid; |
| 1428 | 1429 | ||
| 1429 | nrows = cache->glyph.nrows; | 1430 | nrows = cache->glyph.nrows; |
| 1430 | nkeys_or_perm = nrows + ROW_PERM_OFFSET; | 1431 | nkeys_or_perm = nrows + ROW_PERM_OFFSET; |
| 1431 | cache->glyph.row_nkeys_or_perm[row] = nkeys_or_perm; | 1432 | cache->glyph.row_nkeys_or_perm[row] = nkeys_or_perm; |
| 1432 | nrows++; | 1433 | nrows++; |
| 1433 | cache->glyph.matrix = xrealloc (cache->glyph.matrix, | 1434 | cache->glyph.matrix = xrealloc (cache->glyph.matrix, |
| 1434 | sizeof (CGGlyph *) * nrows); | 1435 | sizeof (CGGlyph *) * nrows); |
| 1435 | cache->glyph.matrix[nrows - 1] = glyphs; | 1436 | cache->glyph.matrix[nrows - 1] = glyphs; |
| 1436 | cache->glyph.nrows = nrows; | 1437 | cache->glyph.nrows = nrows; |
| 1437 | 1438 | ||
| 1438 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 | 1439 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 |
| 1439 | if (group) | 1440 | if (group) |
| 1440 | { | 1441 | { |
| 1441 | dispatch_group_wait (group, DISPATCH_TIME_FOREVER); | 1442 | dispatch_group_wait (group, DISPATCH_TIME_FOREVER); |
| 1442 | dispatch_release (group); | 1443 | dispatch_release (group); |
| 1443 | } | 1444 | } |
| 1444 | #endif | 1445 | #endif |
| 1445 | } | 1446 | } |
| 1446 | 1447 | ||
| 1447 | return cache->glyph.matrix[nkeys_or_perm - ROW_PERM_OFFSET][c % 256]; | 1448 | return cache->glyph.matrix[nkeys_or_perm - ROW_PERM_OFFSET][c % 256]; |
| 1448 | } | 1449 | } |
| @@ -1453,29 +1454,29 @@ macfont_get_glyph_for_character (struct font *font, UTF32Char c) | |||
| 1453 | CGGlyph glyph; | 1454 | CGGlyph glyph; |
| 1454 | 1455 | ||
| 1455 | if (cache->glyph.dictionary == NULL) | 1456 | if (cache->glyph.dictionary == NULL) |
| 1456 | cache->glyph.dictionary = | 1457 | cache->glyph.dictionary = |
| 1457 | CFDictionaryCreateMutable (NULL, 0, NULL, NULL); | 1458 | CFDictionaryCreateMutable (NULL, 0, NULL, NULL); |
| 1458 | key = c / NGLYPHS_IN_VALUE; | 1459 | key = c / NGLYPHS_IN_VALUE; |
| 1459 | nshifts = ((c % NGLYPHS_IN_VALUE) * sizeof (CGGlyph) * 8); | 1460 | nshifts = ((c % NGLYPHS_IN_VALUE) * sizeof (CGGlyph) * 8); |
| 1460 | value = (uintptr_t) CFDictionaryGetValue (cache->glyph.dictionary, | 1461 | value = (uintptr_t) CFDictionaryGetValue (cache->glyph.dictionary, |
| 1461 | (const void *) key); | 1462 | (const void *) key); |
| 1462 | glyph = (value >> nshifts); | 1463 | glyph = (value >> nshifts); |
| 1463 | if (glyph == 0) | 1464 | if (glyph == 0) |
| 1464 | { | 1465 | { |
| 1465 | UniChar unichars[2]; | 1466 | UniChar unichars[2]; |
| 1466 | CGGlyph glyphs[2]; | 1467 | CGGlyph glyphs[2]; |
| 1467 | CFIndex count = macfont_store_utf32char_to_unichars (c, unichars); | 1468 | CFIndex count = macfont_store_utf32char_to_unichars (c, unichars); |
| 1468 | 1469 | ||
| 1469 | if (mac_font_get_glyphs_for_characters (macfont, unichars, glyphs, | 1470 | if (mac_font_get_glyphs_for_characters (macfont, unichars, glyphs, |
| 1470 | count)) | 1471 | count)) |
| 1471 | glyph = glyphs[0]; | 1472 | glyph = glyphs[0]; |
| 1472 | if (glyph == 0) | 1473 | if (glyph == 0) |
| 1473 | glyph = kCGFontIndexInvalid; | 1474 | glyph = kCGFontIndexInvalid; |
| 1474 | 1475 | ||
| 1475 | value |= ((uintptr_t) glyph << nshifts); | 1476 | value |= ((uintptr_t) glyph << nshifts); |
| 1476 | CFDictionarySetValue (cache->glyph.dictionary, | 1477 | CFDictionarySetValue (cache->glyph.dictionary, |
| 1477 | (const void *) key, (const void *) value); | 1478 | (const void *) key, (const void *) value); |
| 1478 | } | 1479 | } |
| 1479 | 1480 | ||
| 1480 | return glyph; | 1481 | return glyph; |
| 1481 | } | 1482 | } |
| @@ -1483,7 +1484,7 @@ macfont_get_glyph_for_character (struct font *font, UTF32Char c) | |||
| 1483 | 1484 | ||
| 1484 | static CGGlyph | 1485 | static CGGlyph |
| 1485 | macfont_get_glyph_for_cid (struct font *font, CharacterCollection collection, | 1486 | macfont_get_glyph_for_cid (struct font *font, CharacterCollection collection, |
| 1486 | CGFontIndex cid) | 1487 | CGFontIndex cid) |
| 1487 | { | 1488 | { |
| 1488 | struct macfont_info *macfont_info = (struct macfont_info *) font; | 1489 | struct macfont_info *macfont_info = (struct macfont_info *) font; |
| 1489 | FontRef macfont = macfont_info->macfont; | 1490 | FontRef macfont = macfont_info->macfont; |
| @@ -1504,34 +1505,34 @@ macfont_get_uvs_table (struct font *font, CharacterCollection *collection) | |||
| 1504 | { | 1505 | { |
| 1505 | CFDataRef uvs_table = mac_font_copy_uvs_table (macfont); | 1506 | CFDataRef uvs_table = mac_font_copy_uvs_table (macfont); |
| 1506 | CharacterCollection uvs_collection = | 1507 | CharacterCollection uvs_collection = |
| 1507 | MAC_CHARACTER_COLLECTION_IDENTITY_MAPPING; | 1508 | MAC_CHARACTER_COLLECTION_IDENTITY_MAPPING; |
| 1508 | 1509 | ||
| 1509 | if (uvs_table == NULL | 1510 | if (uvs_table == NULL |
| 1510 | && mac_font_get_glyph_for_cid (macfont, | 1511 | && mac_font_get_glyph_for_cid (macfont, |
| 1511 | MAC_CHARACTER_COLLECTION_ADOBE_JAPAN1, | 1512 | MAC_CHARACTER_COLLECTION_ADOBE_JAPAN1, |
| 1512 | 6480) != kCGFontIndexInvalid) | 1513 | 6480) != kCGFontIndexInvalid) |
| 1513 | { | 1514 | { |
| 1514 | /* If the glyph for U+4E55 is accessible via its CID 6480, | 1515 | /* If the glyph for U+4E55 is accessible via its CID 6480, |
| 1515 | then we use the Adobe-Japan1 UVS table, which maps a | 1516 | then we use the Adobe-Japan1 UVS table, which maps a |
| 1516 | variation sequence to a CID, as a fallback. */ | 1517 | variation sequence to a CID, as a fallback. */ |
| 1517 | static CFDataRef mac_uvs_table_adobe_japan1 = NULL; | 1518 | static CFDataRef mac_uvs_table_adobe_japan1 = NULL; |
| 1518 | 1519 | ||
| 1519 | if (mac_uvs_table_adobe_japan1 == NULL) | 1520 | if (mac_uvs_table_adobe_japan1 == NULL) |
| 1520 | mac_uvs_table_adobe_japan1 = | 1521 | mac_uvs_table_adobe_japan1 = |
| 1521 | CFDataCreateWithBytesNoCopy (NULL, | 1522 | CFDataCreateWithBytesNoCopy (NULL, |
| 1522 | mac_uvs_table_adobe_japan1_bytes, | 1523 | mac_uvs_table_adobe_japan1_bytes, |
| 1523 | sizeof (mac_uvs_table_adobe_japan1_bytes), | 1524 | sizeof (mac_uvs_table_adobe_japan1_bytes), |
| 1524 | kCFAllocatorNull); | 1525 | kCFAllocatorNull); |
| 1525 | if (mac_uvs_table_adobe_japan1) | 1526 | if (mac_uvs_table_adobe_japan1) |
| 1526 | { | 1527 | { |
| 1527 | uvs_table = CFRetain (mac_uvs_table_adobe_japan1); | 1528 | uvs_table = CFRetain (mac_uvs_table_adobe_japan1); |
| 1528 | uvs_collection = MAC_CHARACTER_COLLECTION_ADOBE_JAPAN1; | 1529 | uvs_collection = MAC_CHARACTER_COLLECTION_ADOBE_JAPAN1; |
| 1529 | } | 1530 | } |
| 1530 | } | 1531 | } |
| 1531 | if (uvs_table == NULL) | 1532 | if (uvs_table == NULL) |
| 1532 | cache->uvs.table = kCFNull; | 1533 | cache->uvs.table = kCFNull; |
| 1533 | else | 1534 | else |
| 1534 | cache->uvs.table = uvs_table; | 1535 | cache->uvs.table = uvs_table; |
| 1535 | cache->uvs.collection = uvs_collection; | 1536 | cache->uvs.collection = uvs_collection; |
| 1536 | } | 1537 | } |
| 1537 | 1538 | ||
| @@ -1554,11 +1555,11 @@ static void macfont_close (struct font *); | |||
| 1554 | static int macfont_has_char (Lisp_Object, int); | 1555 | static int macfont_has_char (Lisp_Object, int); |
| 1555 | static unsigned macfont_encode_char (struct font *, int); | 1556 | static unsigned macfont_encode_char (struct font *, int); |
| 1556 | static void macfont_text_extents (struct font *, unsigned int *, int, | 1557 | static void macfont_text_extents (struct font *, unsigned int *, int, |
| 1557 | struct font_metrics *); | 1558 | struct font_metrics *); |
| 1558 | static int macfont_draw (struct glyph_string *, int, int, int, int, bool); | 1559 | static int macfont_draw (struct glyph_string *, int, int, int, int, bool); |
| 1559 | static Lisp_Object macfont_shape (Lisp_Object); | 1560 | static Lisp_Object macfont_shape (Lisp_Object); |
| 1560 | static int macfont_variation_glyphs (struct font *, int c, | 1561 | static int macfont_variation_glyphs (struct font *, int c, |
| 1561 | unsigned variations[256]); | 1562 | unsigned variations[256]); |
| 1562 | static void macfont_filter_properties (Lisp_Object, Lisp_Object); | 1563 | static void macfont_filter_properties (Lisp_Object, Lisp_Object); |
| 1563 | 1564 | ||
| 1564 | static struct font_driver macfont_driver = | 1565 | static struct font_driver macfont_driver = |
| @@ -1610,19 +1611,19 @@ macfont_get_charset (Lisp_Object registry) | |||
| 1610 | for (i = j = 0; i < SBYTES (SYMBOL_NAME (registry)); i++, j++) | 1611 | for (i = j = 0; i < SBYTES (SYMBOL_NAME (registry)); i++, j++) |
| 1611 | { | 1612 | { |
| 1612 | if (str[i] == '.') | 1613 | if (str[i] == '.') |
| 1613 | re[j++] = '\\'; | 1614 | re[j++] = '\\'; |
| 1614 | else if (str[i] == '*') | 1615 | else if (str[i] == '*') |
| 1615 | re[j++] = '.'; | 1616 | re[j++] = '.'; |
| 1616 | re[j] = str[i]; | 1617 | re[j] = str[i]; |
| 1617 | if (re[j] == '?') | 1618 | if (re[j] == '?') |
| 1618 | re[j] = '.'; | 1619 | re[j] = '.'; |
| 1619 | } | 1620 | } |
| 1620 | re[j] = '\0'; | 1621 | re[j] = '\0'; |
| 1621 | regexp = make_unibyte_string (re, j); | 1622 | regexp = make_unibyte_string (re, j); |
| 1622 | for (i = 0; cf_charset_table[i].name; i++) | 1623 | for (i = 0; cf_charset_table[i].name; i++) |
| 1623 | if (fast_c_string_match_ignore_case | 1624 | if (fast_c_string_match_ignore_case |
| 1624 | (regexp, cf_charset_table[i].name, | 1625 | (regexp, cf_charset_table[i].name, |
| 1625 | strlen (cf_charset_table[i].name)) >= 0) | 1626 | strlen (cf_charset_table[i].name)) >= 0) |
| 1626 | break; | 1627 | break; |
| 1627 | if (! cf_charset_table[i].name) | 1628 | if (! cf_charset_table[i].name) |
| 1628 | return -1; | 1629 | return -1; |
| @@ -1635,27 +1636,27 @@ macfont_get_charset (Lisp_Object registry) | |||
| 1635 | CFMutableCharacterSetRef charset = CFCharacterSetCreateMutable (NULL); | 1636 | CFMutableCharacterSetRef charset = CFCharacterSetCreateMutable (NULL); |
| 1636 | 1637 | ||
| 1637 | if (! charset) | 1638 | if (! charset) |
| 1638 | return -1; | 1639 | return -1; |
| 1639 | for (j = 0; uniquifier[j]; j++) | 1640 | for (j = 0; uniquifier[j]; j++) |
| 1640 | { | 1641 | { |
| 1641 | count += macfont_store_utf32char_to_unichars (uniquifier[j], | 1642 | count += macfont_store_utf32char_to_unichars (uniquifier[j], |
| 1642 | unichars + count); | 1643 | unichars + count); |
| 1643 | CFCharacterSetAddCharactersInRange (charset, | 1644 | CFCharacterSetAddCharactersInRange (charset, |
| 1644 | CFRangeMake (uniquifier[j], 1)); | 1645 | CFRangeMake (uniquifier[j], 1)); |
| 1645 | } | 1646 | } |
| 1646 | 1647 | ||
| 1647 | string = CFStringCreateWithCharacters (NULL, unichars, count); | 1648 | string = CFStringCreateWithCharacters (NULL, unichars, count); |
| 1648 | if (! string) | 1649 | if (! string) |
| 1649 | { | 1650 | { |
| 1650 | CFRelease (charset); | 1651 | CFRelease (charset); |
| 1651 | return -1; | 1652 | return -1; |
| 1652 | } | 1653 | } |
| 1653 | cf_charset_table[i].cf_charset = CFCharacterSetCreateCopy (NULL, | 1654 | cf_charset_table[i].cf_charset = CFCharacterSetCreateCopy (NULL, |
| 1654 | charset); | 1655 | charset); |
| 1655 | CFRelease (charset); | 1656 | CFRelease (charset); |
| 1656 | /* CFCharacterSetCreateWithCharactersInString does not handle | 1657 | /* CFCharacterSetCreateWithCharactersInString does not handle |
| 1657 | surrogate pairs properly as of Mac OS X 10.5. */ | 1658 | surrogate pairs properly as of Mac OS X 10.5. */ |
| 1658 | cf_charset_table[i].cf_charset_string = string; | 1659 | cf_charset_table[i].cf_charset_string = string; |
| 1659 | } | 1660 | } |
| 1660 | return i; | 1661 | return i; |
| 1661 | } | 1662 | } |
| @@ -1668,19 +1669,19 @@ struct OpenTypeSpec | |||
| 1668 | unsigned int *features[2]; | 1669 | unsigned int *features[2]; |
| 1669 | }; | 1670 | }; |
| 1670 | 1671 | ||
| 1671 | #define OTF_SYM_TAG(SYM, TAG) \ | 1672 | #define OTF_SYM_TAG(SYM, TAG) \ |
| 1672 | do { \ | 1673 | do { \ |
| 1673 | unsigned char *p = SDATA (SYMBOL_NAME (SYM)); \ | 1674 | unsigned char *p = SDATA (SYMBOL_NAME (SYM)); \ |
| 1674 | TAG = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; \ | 1675 | TAG = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; \ |
| 1675 | } while (0) | 1676 | } while (0) |
| 1676 | 1677 | ||
| 1677 | #define OTF_TAG_STR(TAG, P) \ | 1678 | #define OTF_TAG_STR(TAG, P) \ |
| 1678 | do { \ | 1679 | do { \ |
| 1679 | (P)[0] = (char) (TAG >> 24); \ | 1680 | (P)[0] = (char) (TAG >> 24); \ |
| 1680 | (P)[1] = (char) ((TAG >> 16) & 0xFF); \ | 1681 | (P)[1] = (char) ((TAG >> 16) & 0xFF); \ |
| 1681 | (P)[2] = (char) ((TAG >> 8) & 0xFF); \ | 1682 | (P)[2] = (char) ((TAG >> 8) & 0xFF); \ |
| 1682 | (P)[3] = (char) (TAG & 0xFF); \ | 1683 | (P)[3] = (char) (TAG & 0xFF); \ |
| 1683 | (P)[4] = '\0'; \ | 1684 | (P)[4] = '\0'; \ |
| 1684 | } while (0) | 1685 | } while (0) |
| 1685 | 1686 | ||
| 1686 | static struct OpenTypeSpec * | 1687 | static struct OpenTypeSpec * |
| @@ -1699,9 +1700,9 @@ macfont_get_open_type_spec (Lisp_Object otf_spec) | |||
| 1699 | OTF_SYM_TAG (spec->script, spec->script_tag); | 1700 | OTF_SYM_TAG (spec->script, spec->script_tag); |
| 1700 | val = assq_no_quit (spec->script, Votf_script_alist); | 1701 | val = assq_no_quit (spec->script, Votf_script_alist); |
| 1701 | if (CONSP (val) && SYMBOLP (XCDR (val))) | 1702 | if (CONSP (val) && SYMBOLP (XCDR (val))) |
| 1702 | spec->script = XCDR (val); | 1703 | spec->script = XCDR (val); |
| 1703 | else | 1704 | else |
| 1704 | spec->script = Qnil; | 1705 | spec->script = Qnil; |
| 1705 | } | 1706 | } |
| 1706 | else | 1707 | else |
| 1707 | spec->script_tag = 0x44464C54; /* "DFLT" */ | 1708 | spec->script_tag = 0x44464C54; /* "DFLT" */ |
| @@ -1711,7 +1712,7 @@ macfont_get_open_type_spec (Lisp_Object otf_spec) | |||
| 1711 | { | 1712 | { |
| 1712 | val = XCAR (otf_spec); | 1713 | val = XCAR (otf_spec); |
| 1713 | if (! NILP (val)) | 1714 | if (! NILP (val)) |
| 1714 | OTF_SYM_TAG (val, spec->langsys_tag); | 1715 | OTF_SYM_TAG (val, spec->langsys_tag); |
| 1715 | otf_spec = XCDR (otf_spec); | 1716 | otf_spec = XCDR (otf_spec); |
| 1716 | } | 1717 | } |
| 1717 | spec->nfeatures[0] = spec->nfeatures[1] = 0; | 1718 | spec->nfeatures[0] = spec->nfeatures[1] = 0; |
| @@ -1721,31 +1722,31 @@ macfont_get_open_type_spec (Lisp_Object otf_spec) | |||
| 1721 | 1722 | ||
| 1722 | val = XCAR (otf_spec); | 1723 | val = XCAR (otf_spec); |
| 1723 | if (NILP (val)) | 1724 | if (NILP (val)) |
| 1724 | continue; | 1725 | continue; |
| 1725 | len = Flength (val); | 1726 | len = Flength (val); |
| 1726 | spec->features[i] = | 1727 | spec->features[i] = |
| 1727 | (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < XINT (len) | 1728 | (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < XINT (len) |
| 1728 | ? 0 | 1729 | ? 0 |
| 1729 | : malloc (XINT (len) * sizeof *spec->features[i])); | 1730 | : malloc (XINT (len) * sizeof *spec->features[i])); |
| 1730 | if (! spec->features[i]) | 1731 | if (! spec->features[i]) |
| 1731 | { | 1732 | { |
| 1732 | if (i > 0 && spec->features[0]) | 1733 | if (i > 0 && spec->features[0]) |
| 1733 | free (spec->features[0]); | 1734 | free (spec->features[0]); |
| 1734 | free (spec); | 1735 | free (spec); |
| 1735 | return NULL; | 1736 | return NULL; |
| 1736 | } | 1737 | } |
| 1737 | for (j = 0, negative = 0; CONSP (val); val = XCDR (val)) | 1738 | for (j = 0, negative = 0; CONSP (val); val = XCDR (val)) |
| 1738 | { | 1739 | { |
| 1739 | if (NILP (XCAR (val))) | 1740 | if (NILP (XCAR (val))) |
| 1740 | negative = 1; | 1741 | negative = 1; |
| 1741 | else | 1742 | else |
| 1742 | { | 1743 | { |
| 1743 | unsigned int tag; | 1744 | unsigned int tag; |
| 1744 | 1745 | ||
| 1745 | OTF_SYM_TAG (XCAR (val), tag); | 1746 | OTF_SYM_TAG (XCAR (val), tag); |
| 1746 | spec->features[i][j++] = negative ? tag & 0x80000000 : tag; | 1747 | spec->features[i][j++] = negative ? tag & 0x80000000 : tag; |
| 1747 | } | 1748 | } |
| 1748 | } | 1749 | } |
| 1749 | spec->nfeatures[i] = j; | 1750 | spec->nfeatures[i] = j; |
| 1750 | } | 1751 | } |
| 1751 | return spec; | 1752 | return spec; |
| @@ -1769,16 +1770,16 @@ macfont_create_attributes_with_spec (Lisp_Object spec) | |||
| 1769 | CGPoint points[6]; | 1770 | CGPoint points[6]; |
| 1770 | } numeric_traits[] = | 1771 | } numeric_traits[] = |
| 1771 | {{FONT_WEIGHT_INDEX, MAC_FONT_WEIGHT_TRAIT, | 1772 | {{FONT_WEIGHT_INDEX, MAC_FONT_WEIGHT_TRAIT, |
| 1772 | {{-0.4, 50}, /* light */ | 1773 | {{-0.4, 50}, /* light */ |
| 1773 | {-0.24, 87.5}, /* (semi-light + normal) / 2 */ | 1774 | {-0.24, 87.5}, /* (semi-light + normal) / 2 */ |
| 1774 | {0, 100}, /* normal */ | 1775 | {0, 100}, /* normal */ |
| 1775 | {0.24, 140}, /* (semi-bold + normal) / 2 */ | 1776 | {0.24, 140}, /* (semi-bold + normal) / 2 */ |
| 1776 | {0.4, 200}, /* bold */ | 1777 | {0.4, 200}, /* bold */ |
| 1777 | {CGFLOAT_MAX, CGFLOAT_MAX}}}, | 1778 | {CGFLOAT_MAX, CGFLOAT_MAX}}}, |
| 1778 | {FONT_SLANT_INDEX, MAC_FONT_SLANT_TRAIT, | 1779 | {FONT_SLANT_INDEX, MAC_FONT_SLANT_TRAIT, |
| 1779 | {{0, 100}, {0.1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}, | 1780 | {{0, 100}, {0.1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}, |
| 1780 | {FONT_WIDTH_INDEX, MAC_FONT_WIDTH_TRAIT, | 1781 | {FONT_WIDTH_INDEX, MAC_FONT_WIDTH_TRAIT, |
| 1781 | {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}}; | 1782 | {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}}; |
| 1782 | 1783 | ||
| 1783 | registry = AREF (spec, FONT_REGISTRY_INDEX); | 1784 | registry = AREF (spec, FONT_REGISTRY_INDEX); |
| 1784 | if (NILP (registry) | 1785 | if (NILP (registry) |
| @@ -1792,17 +1793,17 @@ macfont_create_attributes_with_spec (Lisp_Object spec) | |||
| 1792 | 1793 | ||
| 1793 | cf_charset_idx = macfont_get_charset (registry); | 1794 | cf_charset_idx = macfont_get_charset (registry); |
| 1794 | if (cf_charset_idx < 0) | 1795 | if (cf_charset_idx < 0) |
| 1795 | goto err; | 1796 | goto err; |
| 1796 | charset = cf_charset_table[cf_charset_idx].cf_charset; | 1797 | charset = cf_charset_table[cf_charset_idx].cf_charset; |
| 1797 | charset_string = cf_charset_table[cf_charset_idx].cf_charset_string; | 1798 | charset_string = cf_charset_table[cf_charset_idx].cf_charset_string; |
| 1798 | lang = cf_charset_table[cf_charset_idx].lang; | 1799 | lang = cf_charset_table[cf_charset_idx].lang; |
| 1799 | if (lang) | 1800 | if (lang) |
| 1800 | { | 1801 | { |
| 1801 | langarray = CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks); | 1802 | langarray = CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks); |
| 1802 | if (! langarray) | 1803 | if (! langarray) |
| 1803 | goto err; | 1804 | goto err; |
| 1804 | CFArrayAppendValue (langarray, lang); | 1805 | CFArrayAppendValue (langarray, lang); |
| 1805 | } | 1806 | } |
| 1806 | } | 1807 | } |
| 1807 | 1808 | ||
| 1808 | for (extra = AREF (spec, FONT_EXTRA_INDEX); | 1809 | for (extra = AREF (spec, FONT_EXTRA_INDEX); |
| @@ -1813,35 +1814,35 @@ macfont_create_attributes_with_spec (Lisp_Object spec) | |||
| 1813 | tmp = XCAR (extra); | 1814 | tmp = XCAR (extra); |
| 1814 | key = XCAR (tmp), val = XCDR (tmp); | 1815 | key = XCAR (tmp), val = XCDR (tmp); |
| 1815 | if (EQ (key, QClang)) | 1816 | if (EQ (key, QClang)) |
| 1816 | { | 1817 | { |
| 1817 | if (! langarray) | 1818 | if (! langarray) |
| 1818 | langarray = CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks); | 1819 | langarray = CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks); |
| 1819 | if (! langarray) | 1820 | if (! langarray) |
| 1820 | goto err; | 1821 | goto err; |
| 1821 | if (SYMBOLP (val)) | 1822 | if (SYMBOLP (val)) |
| 1822 | val = list1 (val); | 1823 | val = list1 (val); |
| 1823 | for (; CONSP (val); val = XCDR (val)) | 1824 | for (; CONSP (val); val = XCDR (val)) |
| 1824 | if (SYMBOLP (XCAR (val))) | 1825 | if (SYMBOLP (XCAR (val))) |
| 1825 | { | 1826 | { |
| 1826 | CFStringRef lang = | 1827 | CFStringRef lang = |
| 1827 | cfstring_create_with_string_noencode (SYMBOL_NAME | 1828 | cfstring_create_with_string_noencode (SYMBOL_NAME |
| 1828 | (XCAR (val))); | 1829 | (XCAR (val))); |
| 1829 | 1830 | ||
| 1830 | if (lang == NULL) | 1831 | if (lang == NULL) |
| 1831 | goto err; | 1832 | goto err; |
| 1832 | CFArrayAppendValue (langarray, lang); | 1833 | CFArrayAppendValue (langarray, lang); |
| 1833 | CFRelease (lang); | 1834 | CFRelease (lang); |
| 1834 | } | 1835 | } |
| 1835 | } | 1836 | } |
| 1836 | else if (EQ (key, QCotf)) | 1837 | else if (EQ (key, QCotf)) |
| 1837 | { | 1838 | { |
| 1838 | otspec = macfont_get_open_type_spec (val); | 1839 | otspec = macfont_get_open_type_spec (val); |
| 1839 | if (! otspec) | 1840 | if (! otspec) |
| 1840 | goto err; | 1841 | goto err; |
| 1841 | script = otspec->script; | 1842 | script = otspec->script; |
| 1842 | } | 1843 | } |
| 1843 | else if (EQ (key, QCscript)) | 1844 | else if (EQ (key, QCscript)) |
| 1844 | script = val; | 1845 | script = val; |
| 1845 | } | 1846 | } |
| 1846 | 1847 | ||
| 1847 | if (! NILP (script) && ! charset) | 1848 | if (! NILP (script) && ! charset) |
| @@ -1849,40 +1850,40 @@ macfont_create_attributes_with_spec (Lisp_Object spec) | |||
| 1849 | Lisp_Object chars = assq_no_quit (script, Vscript_representative_chars); | 1850 | Lisp_Object chars = assq_no_quit (script, Vscript_representative_chars); |
| 1850 | 1851 | ||
| 1851 | if (CONSP (chars) && CONSP (CDR (chars))) | 1852 | if (CONSP (chars) && CONSP (CDR (chars))) |
| 1852 | { | 1853 | { |
| 1853 | CFMutableStringRef string = CFStringCreateMutable (NULL, 0); | 1854 | CFMutableStringRef string = CFStringCreateMutable (NULL, 0); |
| 1854 | CFMutableCharacterSetRef cs = CFCharacterSetCreateMutable (NULL); | 1855 | CFMutableCharacterSetRef cs = CFCharacterSetCreateMutable (NULL); |
| 1855 | 1856 | ||
| 1856 | if (! string || !cs) | 1857 | if (! string || !cs) |
| 1857 | { | 1858 | { |
| 1858 | if (string) | 1859 | if (string) |
| 1859 | CFRelease (string); | 1860 | CFRelease (string); |
| 1860 | else if (cs) | 1861 | else if (cs) |
| 1861 | CFRelease (cs); | 1862 | CFRelease (cs); |
| 1862 | goto err; | 1863 | goto err; |
| 1863 | } | 1864 | } |
| 1864 | for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars)) | 1865 | for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars)) |
| 1865 | if (CHARACTERP (XCAR (chars))) | 1866 | if (CHARACTERP (XCAR (chars))) |
| 1866 | { | 1867 | { |
| 1867 | UniChar unichars[2]; | 1868 | UniChar unichars[2]; |
| 1868 | CFIndex count = | 1869 | CFIndex count = |
| 1869 | macfont_store_utf32char_to_unichars (XFASTINT (XCAR (chars)), | 1870 | macfont_store_utf32char_to_unichars (XFASTINT (XCAR (chars)), |
| 1870 | unichars); | 1871 | unichars); |
| 1871 | CFRange range = CFRangeMake (XFASTINT (XCAR (chars)), 1); | 1872 | CFRange range = CFRangeMake (XFASTINT (XCAR (chars)), 1); |
| 1872 | 1873 | ||
| 1873 | CFStringAppendCharacters (string, unichars, count); | 1874 | CFStringAppendCharacters (string, unichars, count); |
| 1874 | CFCharacterSetAddCharactersInRange (cs, range); | 1875 | CFCharacterSetAddCharactersInRange (cs, range); |
| 1875 | } | 1876 | } |
| 1876 | charset = cs; | 1877 | charset = cs; |
| 1877 | /* CFCharacterSetCreateWithCharactersInString does not | 1878 | /* CFCharacterSetCreateWithCharactersInString does not |
| 1878 | handle surrogate pairs properly as of Mac OS X 10.5. */ | 1879 | handle surrogate pairs properly as of Mac OS X 10.5. */ |
| 1879 | charset_string = string; | 1880 | charset_string = string; |
| 1880 | } | 1881 | } |
| 1881 | } | 1882 | } |
| 1882 | 1883 | ||
| 1883 | attributes = CFDictionaryCreateMutable (NULL, 0, | 1884 | attributes = CFDictionaryCreateMutable (NULL, 0, |
| 1884 | &kCFTypeDictionaryKeyCallBacks, | 1885 | &kCFTypeDictionaryKeyCallBacks, |
| 1885 | &kCFTypeDictionaryValueCallBacks); | 1886 | &kCFTypeDictionaryValueCallBacks); |
| 1886 | if (! attributes) | 1887 | if (! attributes) |
| 1887 | goto err; | 1888 | goto err; |
| 1888 | 1889 | ||
| @@ -1892,15 +1893,15 @@ macfont_create_attributes_with_spec (Lisp_Object spec) | |||
| 1892 | CFStringRef family = macfont_create_family_with_symbol (tmp); | 1893 | CFStringRef family = macfont_create_family_with_symbol (tmp); |
| 1893 | 1894 | ||
| 1894 | if (! family) | 1895 | if (! family) |
| 1895 | goto err; | 1896 | goto err; |
| 1896 | CFDictionaryAddValue (attributes, MAC_FONT_FAMILY_NAME_ATTRIBUTE, | 1897 | CFDictionaryAddValue (attributes, MAC_FONT_FAMILY_NAME_ATTRIBUTE, |
| 1897 | family); | 1898 | family); |
| 1898 | CFRelease (family); | 1899 | CFRelease (family); |
| 1899 | } | 1900 | } |
| 1900 | 1901 | ||
| 1901 | traits = CFDictionaryCreateMutable (NULL, 4, | 1902 | traits = CFDictionaryCreateMutable (NULL, 4, |
| 1902 | &kCFTypeDictionaryKeyCallBacks, | 1903 | &kCFTypeDictionaryKeyCallBacks, |
| 1903 | &kCFTypeDictionaryValueCallBacks); | 1904 | &kCFTypeDictionaryValueCallBacks); |
| 1904 | if (! traits) | 1905 | if (! traits) |
| 1905 | goto err; | 1906 | goto err; |
| 1906 | 1907 | ||
| @@ -1908,40 +1909,40 @@ macfont_create_attributes_with_spec (Lisp_Object spec) | |||
| 1908 | { | 1909 | { |
| 1909 | tmp = AREF (spec, numeric_traits[i].index); | 1910 | tmp = AREF (spec, numeric_traits[i].index); |
| 1910 | if (INTEGERP (tmp)) | 1911 | if (INTEGERP (tmp)) |
| 1911 | { | 1912 | { |
| 1912 | CGPoint *point = numeric_traits[i].points; | 1913 | CGPoint *point = numeric_traits[i].points; |
| 1913 | CGFloat floatval = (XINT (tmp) >> 8); // XXX | 1914 | CGFloat floatval = (XINT (tmp) >> 8); // XXX |
| 1914 | CFNumberRef num; | 1915 | CFNumberRef num; |
| 1915 | 1916 | ||
| 1916 | while (point->y < floatval) | 1917 | while (point->y < floatval) |
| 1917 | point++; | 1918 | point++; |
| 1918 | if (point == numeric_traits[i].points) | 1919 | if (point == numeric_traits[i].points) |
| 1919 | point++; | 1920 | point++; |
| 1920 | else if (point->y == CGFLOAT_MAX) | 1921 | else if (point->y == CGFLOAT_MAX) |
| 1921 | point--; | 1922 | point--; |
| 1922 | floatval = (point - 1)->x + ((floatval - (point - 1)->y) | 1923 | floatval = (point - 1)->x + ((floatval - (point - 1)->y) |
| 1923 | * ((point->x - (point - 1)->x) | 1924 | * ((point->x - (point - 1)->x) |
| 1924 | / (point->y - (point - 1)->y))); | 1925 | / (point->y - (point - 1)->y))); |
| 1925 | if (floatval > 1.0) | 1926 | if (floatval > 1.0) |
| 1926 | floatval = 1.0; | 1927 | floatval = 1.0; |
| 1927 | else if (floatval < -1.0) | 1928 | else if (floatval < -1.0) |
| 1928 | floatval = -1.0; | 1929 | floatval = -1.0; |
| 1929 | num = CFNumberCreate (NULL, kCFNumberCGFloatType, &floatval); | 1930 | num = CFNumberCreate (NULL, kCFNumberCGFloatType, &floatval); |
| 1930 | if (! num) | 1931 | if (! num) |
| 1931 | goto err; | 1932 | goto err; |
| 1932 | CFDictionaryAddValue (traits, numeric_traits[i].trait, num); | 1933 | CFDictionaryAddValue (traits, numeric_traits[i].trait, num); |
| 1933 | CFRelease (num); | 1934 | CFRelease (num); |
| 1934 | } | 1935 | } |
| 1935 | } | 1936 | } |
| 1936 | if (CFDictionaryGetCount (traits)) | 1937 | if (CFDictionaryGetCount (traits)) |
| 1937 | CFDictionaryAddValue (attributes, MAC_FONT_TRAITS_ATTRIBUTE, traits); | 1938 | CFDictionaryAddValue (attributes, MAC_FONT_TRAITS_ATTRIBUTE, traits); |
| 1938 | 1939 | ||
| 1939 | if (charset) | 1940 | if (charset) |
| 1940 | CFDictionaryAddValue (attributes, MAC_FONT_CHARACTER_SET_ATTRIBUTE, | 1941 | CFDictionaryAddValue (attributes, MAC_FONT_CHARACTER_SET_ATTRIBUTE, |
| 1941 | charset); | 1942 | charset); |
| 1942 | if (charset_string) | 1943 | if (charset_string) |
| 1943 | CFDictionaryAddValue (attributes, MAC_FONT_CHARACTER_SET_STRING_ATTRIBUTE, | 1944 | CFDictionaryAddValue (attributes, MAC_FONT_CHARACTER_SET_STRING_ATTRIBUTE, |
| 1944 | charset_string); | 1945 | charset_string); |
| 1945 | if (langarray) | 1946 | if (langarray) |
| 1946 | CFDictionaryAddValue (attributes, MAC_FONT_LANGUAGES_ATTRIBUTE, langarray); | 1947 | CFDictionaryAddValue (attributes, MAC_FONT_LANGUAGES_ATTRIBUTE, langarray); |
| 1947 | 1948 | ||
| @@ -1962,9 +1963,9 @@ macfont_create_attributes_with_spec (Lisp_Object spec) | |||
| 1962 | if (otspec) | 1963 | if (otspec) |
| 1963 | { | 1964 | { |
| 1964 | if (otspec->nfeatures[0] > 0) | 1965 | if (otspec->nfeatures[0] > 0) |
| 1965 | free (otspec->features[0]); | 1966 | free (otspec->features[0]); |
| 1966 | if (otspec->nfeatures[1] > 0) | 1967 | if (otspec->nfeatures[1] > 0) |
| 1967 | free (otspec->features[1]); | 1968 | free (otspec->features[1]); |
| 1968 | free (otspec); | 1969 | free (otspec); |
| 1969 | } | 1970 | } |
| 1970 | 1971 | ||
| @@ -1973,38 +1974,38 @@ macfont_create_attributes_with_spec (Lisp_Object spec) | |||
| 1973 | 1974 | ||
| 1974 | static Boolean | 1975 | static Boolean |
| 1975 | macfont_supports_charset_and_languages_p (FontDescriptorRef desc, | 1976 | macfont_supports_charset_and_languages_p (FontDescriptorRef desc, |
| 1976 | CFCharacterSetRef charset, | 1977 | CFCharacterSetRef charset, |
| 1977 | Lisp_Object chars, | 1978 | Lisp_Object chars, |
| 1978 | CFArrayRef languages) | 1979 | CFArrayRef languages) |
| 1979 | { | 1980 | { |
| 1980 | Boolean result = true; | 1981 | Boolean result = true; |
| 1981 | 1982 | ||
| 1982 | if (charset || VECTORP (chars)) | 1983 | if (charset || VECTORP (chars)) |
| 1983 | { | 1984 | { |
| 1984 | CFCharacterSetRef desc_charset = | 1985 | CFCharacterSetRef desc_charset = |
| 1985 | mac_font_descriptor_copy_attribute (desc, | 1986 | mac_font_descriptor_copy_attribute (desc, |
| 1986 | MAC_FONT_CHARACTER_SET_ATTRIBUTE); | 1987 | MAC_FONT_CHARACTER_SET_ATTRIBUTE); |
| 1987 | 1988 | ||
| 1988 | if (desc_charset == NULL) | 1989 | if (desc_charset == NULL) |
| 1989 | result = false; | 1990 | result = false; |
| 1990 | else | 1991 | else |
| 1991 | { | 1992 | { |
| 1992 | if (charset) | 1993 | if (charset) |
| 1993 | result = CFCharacterSetIsSupersetOfSet (desc_charset, charset); | 1994 | result = CFCharacterSetIsSupersetOfSet (desc_charset, charset); |
| 1994 | else /* VECTORP (chars) */ | 1995 | else /* VECTORP (chars) */ |
| 1995 | { | 1996 | { |
| 1996 | ptrdiff_t j; | 1997 | ptrdiff_t j; |
| 1997 | 1998 | ||
| 1998 | for (j = 0; j < ASIZE (chars); j++) | 1999 | for (j = 0; j < ASIZE (chars); j++) |
| 1999 | if (TYPE_RANGED_INTEGERP (UTF32Char, AREF (chars, j)) | 2000 | if (TYPE_RANGED_INTEGERP (UTF32Char, AREF (chars, j)) |
| 2000 | && CFCharacterSetIsLongCharacterMember (desc_charset, | 2001 | && CFCharacterSetIsLongCharacterMember (desc_charset, |
| 2001 | XFASTINT (AREF (chars, j)))) | 2002 | XFASTINT (AREF (chars, j)))) |
| 2002 | break; | 2003 | break; |
| 2003 | if (j == ASIZE (chars)) | 2004 | if (j == ASIZE (chars)) |
| 2004 | result = false; | 2005 | result = false; |
| 2005 | } | 2006 | } |
| 2006 | CFRelease (desc_charset); | 2007 | CFRelease (desc_charset); |
| 2007 | } | 2008 | } |
| 2008 | } | 2009 | } |
| 2009 | if (result && languages) | 2010 | if (result && languages) |
| 2010 | result = mac_font_descriptor_supports_languages (desc, languages); | 2011 | result = mac_font_descriptor_supports_languages (desc, languages); |
| @@ -2012,38 +2013,49 @@ macfont_supports_charset_and_languages_p (FontDescriptorRef desc, | |||
| 2012 | return result; | 2013 | return result; |
| 2013 | } | 2014 | } |
| 2014 | 2015 | ||
| 2015 | static CFIndex | 2016 | static int |
| 2016 | macfont_closest_traits_index (CFArrayRef traits_array, | 2017 | macfont_traits_distance (FontSymbolicTraits sym_traits1, |
| 2017 | FontSymbolicTraits target) | 2018 | FontSymbolicTraits sym_traits2) |
| 2019 | { | ||
| 2020 | FontSymbolicTraits diff = (sym_traits1 ^ sym_traits2); | ||
| 2021 | int distance = 0; | ||
| 2022 | |||
| 2023 | /* We prefer synthetic bold of italic to synthetic italic of bold | ||
| 2024 | when both bold and italic are available but bold-italic is not | ||
| 2025 | available. */ | ||
| 2026 | if (diff & MAC_FONT_TRAIT_BOLD) | ||
| 2027 | distance |= (1 << 0); | ||
| 2028 | if (diff & MAC_FONT_TRAIT_ITALIC) | ||
| 2029 | distance |= (1 << 1); | ||
| 2030 | if (diff & MAC_FONT_TRAIT_MONO_SPACE) | ||
| 2031 | distance |= (1 << 2); | ||
| 2032 | |||
| 2033 | return distance; | ||
| 2034 | } | ||
| 2035 | |||
| 2036 | static Boolean | ||
| 2037 | macfont_closest_traits_index_p (CFArrayRef traits_array, | ||
| 2038 | FontSymbolicTraits target, | ||
| 2039 | CFIndex index) | ||
| 2018 | { | 2040 | { |
| 2019 | CFIndex i, result = -1, count = CFArrayGetCount (traits_array); | 2041 | CFIndex i, count = CFArrayGetCount (traits_array); |
| 2020 | int min_distance = (1 << 3); | 2042 | FontSymbolicTraits traits; |
| 2043 | int my_distance; | ||
| 2044 | |||
| 2045 | traits = ((FontSymbolicTraits) (uintptr_t) | ||
| 2046 | CFArrayGetValueAtIndex (traits_array, index)); | ||
| 2047 | my_distance = macfont_traits_distance (target, traits); | ||
| 2021 | 2048 | ||
| 2022 | for (i = 0; i < count; i++) | 2049 | for (i = 0; i < count; i++) |
| 2023 | { | 2050 | if (i != index) |
| 2024 | FontSymbolicTraits traits, diff; | 2051 | { |
| 2025 | int distance = 0; | 2052 | traits = ((FontSymbolicTraits) (uintptr_t) |
| 2026 | 2053 | CFArrayGetValueAtIndex (traits_array, i)); | |
| 2027 | traits = ((FontSymbolicTraits) (uintptr_t) | 2054 | if (macfont_traits_distance (target, traits) < my_distance) |
| 2028 | CFArrayGetValueAtIndex (traits_array, i)); | 2055 | return false; |
| 2029 | diff = (target ^ traits); | 2056 | } |
| 2030 | /* We prefer synthetic bold of italic to synthetic italic of | ||
| 2031 | bold when both bold and italic are available but bold-italic | ||
| 2032 | is not available. */ | ||
| 2033 | if (diff & MAC_FONT_TRAIT_BOLD) | ||
| 2034 | distance |= (1 << 0); | ||
| 2035 | if (diff & MAC_FONT_TRAIT_ITALIC) | ||
| 2036 | distance |= (1 << 1); | ||
| 2037 | if (diff & MAC_FONT_TRAIT_MONO_SPACE) | ||
| 2038 | distance |= (1 << 2); | ||
| 2039 | if (distance < min_distance) | ||
| 2040 | { | ||
| 2041 | min_distance = distance; | ||
| 2042 | result = i; | ||
| 2043 | } | ||
| 2044 | } | ||
| 2045 | 2057 | ||
| 2046 | return result; | 2058 | return true; |
| 2047 | } | 2059 | } |
| 2048 | 2060 | ||
| 2049 | static Lisp_Object | 2061 | static Lisp_Object |
| @@ -2068,7 +2080,7 @@ macfont_list (struct frame *f, Lisp_Object spec) | |||
| 2068 | { | 2080 | { |
| 2069 | family_name = macfont_create_family_with_symbol (family); | 2081 | family_name = macfont_create_family_with_symbol (family); |
| 2070 | if (family_name == NULL) | 2082 | if (family_name == NULL) |
| 2071 | goto finish; | 2083 | goto finish; |
| 2072 | } | 2084 | } |
| 2073 | 2085 | ||
| 2074 | attributes = macfont_create_attributes_with_spec (spec); | 2086 | attributes = macfont_create_attributes_with_spec (spec); |
| @@ -2081,14 +2093,14 @@ macfont_list (struct frame *f, Lisp_Object spec) | |||
| 2081 | spacing = XINT (AREF (spec, FONT_SPACING_INDEX)); | 2093 | spacing = XINT (AREF (spec, FONT_SPACING_INDEX)); |
| 2082 | 2094 | ||
| 2083 | traits = ((CFMutableDictionaryRef) | 2095 | traits = ((CFMutableDictionaryRef) |
| 2084 | CFDictionaryGetValue (attributes, MAC_FONT_TRAITS_ATTRIBUTE)); | 2096 | CFDictionaryGetValue (attributes, MAC_FONT_TRAITS_ATTRIBUTE)); |
| 2085 | 2097 | ||
| 2086 | n = FONT_SLANT_NUMERIC (spec); | 2098 | n = FONT_SLANT_NUMERIC (spec); |
| 2087 | if (n < 0 || n == FONT_SLANT_SYNTHETIC_ITALIC) | 2099 | if (n < 0 || n == FONT_SLANT_SYNTHETIC_ITALIC) |
| 2088 | { | 2100 | { |
| 2089 | synth_sym_traits |= MAC_FONT_TRAIT_ITALIC; | 2101 | synth_sym_traits |= MAC_FONT_TRAIT_ITALIC; |
| 2090 | if (traits) | 2102 | if (traits) |
| 2091 | CFDictionaryRemoveValue (traits, MAC_FONT_SLANT_TRAIT); | 2103 | CFDictionaryRemoveValue (traits, MAC_FONT_SLANT_TRAIT); |
| 2092 | } | 2104 | } |
| 2093 | 2105 | ||
| 2094 | n = FONT_WEIGHT_NUMERIC (spec); | 2106 | n = FONT_WEIGHT_NUMERIC (spec); |
| @@ -2096,7 +2108,7 @@ macfont_list (struct frame *f, Lisp_Object spec) | |||
| 2096 | { | 2108 | { |
| 2097 | synth_sym_traits |= MAC_FONT_TRAIT_BOLD; | 2109 | synth_sym_traits |= MAC_FONT_TRAIT_BOLD; |
| 2098 | if (traits) | 2110 | if (traits) |
| 2099 | CFDictionaryRemoveValue (traits, MAC_FONT_WEIGHT_TRAIT); | 2111 | CFDictionaryRemoveValue (traits, MAC_FONT_WEIGHT_TRAIT); |
| 2100 | } | 2112 | } |
| 2101 | 2113 | ||
| 2102 | if (languages | 2114 | if (languages |
| @@ -2105,15 +2117,15 @@ macfont_list (struct frame *f, Lisp_Object spec) | |||
| 2105 | CFStringRef language = CFArrayGetValueAtIndex (languages, 0); | 2117 | CFStringRef language = CFArrayGetValueAtIndex (languages, 0); |
| 2106 | 2118 | ||
| 2107 | if (CFStringHasPrefix (language, CFSTR ("ja")) | 2119 | if (CFStringHasPrefix (language, CFSTR ("ja")) |
| 2108 | || CFStringHasPrefix (language, CFSTR ("ko")) | 2120 | || CFStringHasPrefix (language, CFSTR ("ko")) |
| 2109 | || CFStringHasPrefix (language, CFSTR ("zh"))) | 2121 | || CFStringHasPrefix (language, CFSTR ("zh"))) |
| 2110 | synth_sym_traits |= MAC_FONT_TRAIT_MONO_SPACE; | 2122 | synth_sym_traits |= MAC_FONT_TRAIT_MONO_SPACE; |
| 2111 | } | 2123 | } |
| 2112 | 2124 | ||
| 2113 | /* Create array of families. */ | 2125 | /* Create array of families. */ |
| 2114 | if (family_name) | 2126 | if (family_name) |
| 2115 | families = CFArrayCreate (NULL, (const void **) &family_name, | 2127 | families = CFArrayCreate (NULL, (const void **) &family_name, |
| 2116 | 1, &kCFTypeArrayCallBacks); | 2128 | 1, &kCFTypeArrayCallBacks); |
| 2117 | else | 2129 | else |
| 2118 | { | 2130 | { |
| 2119 | CFStringRef pref_family; | 2131 | CFStringRef pref_family; |
| @@ -2121,46 +2133,46 @@ macfont_list (struct frame *f, Lisp_Object spec) | |||
| 2121 | 2133 | ||
| 2122 | families = mac_font_create_available_families (); | 2134 | families = mac_font_create_available_families (); |
| 2123 | if (families == NULL) | 2135 | if (families == NULL) |
| 2124 | goto err; | 2136 | goto err; |
| 2125 | 2137 | ||
| 2126 | families_count = CFArrayGetCount (families); | 2138 | families_count = CFArrayGetCount (families); |
| 2127 | 2139 | ||
| 2128 | /* Move preferred family to the front if exists. */ | 2140 | /* Move preferred family to the front if exists. */ |
| 2129 | pref_family = | 2141 | pref_family = |
| 2130 | mac_font_create_preferred_family_for_attributes (attributes); | 2142 | mac_font_create_preferred_family_for_attributes (attributes); |
| 2131 | if (pref_family) | 2143 | if (pref_family) |
| 2132 | { | 2144 | { |
| 2133 | pref_family_index = | 2145 | pref_family_index = |
| 2134 | CFArrayGetFirstIndexOfValue (families, | 2146 | CFArrayGetFirstIndexOfValue (families, |
| 2135 | CFRangeMake (0, families_count), | 2147 | CFRangeMake (0, families_count), |
| 2136 | pref_family); | 2148 | pref_family); |
| 2137 | CFRelease (pref_family); | 2149 | CFRelease (pref_family); |
| 2138 | } | 2150 | } |
| 2139 | if (pref_family_index > 0) | 2151 | if (pref_family_index > 0) |
| 2140 | { | 2152 | { |
| 2141 | CFMutableArrayRef mutable_families = | 2153 | CFMutableArrayRef mutable_families = |
| 2142 | CFArrayCreateMutable (NULL, families_count, &kCFTypeArrayCallBacks); | 2154 | CFArrayCreateMutable (NULL, families_count, &kCFTypeArrayCallBacks); |
| 2143 | 2155 | ||
| 2144 | if (mutable_families) | 2156 | if (mutable_families) |
| 2145 | { | 2157 | { |
| 2146 | CFArrayAppendValue (mutable_families, | 2158 | CFArrayAppendValue (mutable_families, |
| 2147 | CFArrayGetValueAtIndex (families, | 2159 | CFArrayGetValueAtIndex (families, |
| 2148 | pref_family_index)); | 2160 | pref_family_index)); |
| 2149 | CFArrayAppendArray (mutable_families, families, | 2161 | CFArrayAppendArray (mutable_families, families, |
| 2150 | CFRangeMake (0, pref_family_index)); | 2162 | CFRangeMake (0, pref_family_index)); |
| 2151 | if (pref_family_index + 1 < families_count) | 2163 | if (pref_family_index + 1 < families_count) |
| 2152 | CFArrayAppendArray (mutable_families, families, | 2164 | CFArrayAppendArray (mutable_families, families, |
| 2153 | CFRangeMake (pref_family_index + 1, | 2165 | CFRangeMake (pref_family_index + 1, |
| 2154 | families_count | 2166 | families_count |
| 2155 | - (pref_family_index + 1))); | 2167 | - (pref_family_index + 1))); |
| 2156 | CFRelease (families); | 2168 | CFRelease (families); |
| 2157 | families = mutable_families; | 2169 | families = mutable_families; |
| 2158 | } | 2170 | } |
| 2159 | } | 2171 | } |
| 2160 | } | 2172 | } |
| 2161 | 2173 | ||
| 2162 | charset = CFDictionaryGetValue (attributes, | 2174 | charset = CFDictionaryGetValue (attributes, |
| 2163 | MAC_FONT_CHARACTER_SET_ATTRIBUTE); | 2175 | MAC_FONT_CHARACTER_SET_ATTRIBUTE); |
| 2164 | if (charset) | 2176 | if (charset) |
| 2165 | { | 2177 | { |
| 2166 | CFRetain (charset); | 2178 | CFRetain (charset); |
| @@ -2170,11 +2182,11 @@ macfont_list (struct frame *f, Lisp_Object spec) | |||
| 2170 | { | 2182 | { |
| 2171 | val = assq_no_quit (QCscript, AREF (spec, FONT_EXTRA_INDEX)); | 2183 | val = assq_no_quit (QCscript, AREF (spec, FONT_EXTRA_INDEX)); |
| 2172 | if (! NILP (val)) | 2184 | if (! NILP (val)) |
| 2173 | { | 2185 | { |
| 2174 | val = assq_no_quit (XCDR (val), Vscript_representative_chars); | 2186 | val = assq_no_quit (XCDR (val), Vscript_representative_chars); |
| 2175 | if (CONSP (val) && VECTORP (XCDR (val))) | 2187 | if (CONSP (val) && VECTORP (XCDR (val))) |
| 2176 | chars = XCDR (val); | 2188 | chars = XCDR (val); |
| 2177 | } | 2189 | } |
| 2178 | val = Qnil; | 2190 | val = Qnil; |
| 2179 | } | 2191 | } |
| 2180 | 2192 | ||
| @@ -2198,151 +2210,152 @@ macfont_list (struct frame *f, Lisp_Object spec) | |||
| 2198 | int j; | 2210 | int j; |
| 2199 | 2211 | ||
| 2200 | CFDictionarySetValue (attributes, MAC_FONT_FAMILY_NAME_ATTRIBUTE, | 2212 | CFDictionarySetValue (attributes, MAC_FONT_FAMILY_NAME_ATTRIBUTE, |
| 2201 | family_name); | 2213 | family_name); |
| 2202 | pat_desc = mac_font_descriptor_create_with_attributes (attributes); | 2214 | pat_desc = mac_font_descriptor_create_with_attributes (attributes); |
| 2203 | if (! pat_desc) | 2215 | if (! pat_desc) |
| 2204 | goto err; | 2216 | goto err; |
| 2205 | 2217 | ||
| 2206 | /* CTFontDescriptorCreateMatchingFontDescriptors on Mac OS X | 2218 | /* CTFontDescriptorCreateMatchingFontDescriptors on Mac OS X |
| 2207 | 10.7 returns NULL if pat_desc represents the LastResort font. | 2219 | 10.7 returns NULL if pat_desc represents the LastResort font. |
| 2208 | So we use CTFontDescriptorCreateMatchingFontDescriptor (no | 2220 | So we use CTFontDescriptorCreateMatchingFontDescriptor (no |
| 2209 | trailing "s") for such a font. */ | 2221 | trailing "s") for such a font. */ |
| 2210 | if (!CFEqual (family_name, CFSTR ("LastResort"))) | 2222 | if (!CFEqual (family_name, CFSTR ("LastResort"))) |
| 2211 | descs = mac_font_descriptor_create_matching_font_descriptors (pat_desc, | 2223 | descs = mac_font_descriptor_create_matching_font_descriptors (pat_desc, |
| 2212 | NULL); | 2224 | NULL); |
| 2213 | else | 2225 | else |
| 2214 | { | 2226 | { |
| 2215 | FontDescriptorRef lr_desc = | 2227 | FontDescriptorRef lr_desc = |
| 2216 | mac_font_descriptor_create_matching_font_descriptor (pat_desc, | 2228 | mac_font_descriptor_create_matching_font_descriptor (pat_desc, |
| 2217 | NULL); | 2229 | NULL); |
| 2218 | if (lr_desc) | 2230 | if (lr_desc) |
| 2219 | { | 2231 | { |
| 2220 | descs = CFArrayCreate (NULL, (const void **) &lr_desc, 1, | 2232 | descs = CFArrayCreate (NULL, (const void **) &lr_desc, 1, |
| 2221 | &kCFTypeArrayCallBacks); | 2233 | &kCFTypeArrayCallBacks); |
| 2222 | CFRelease (lr_desc); | 2234 | CFRelease (lr_desc); |
| 2223 | } | 2235 | } |
| 2224 | else | 2236 | else |
| 2225 | descs = NULL; | 2237 | descs = NULL; |
| 2226 | } | 2238 | } |
| 2227 | CFRelease (pat_desc); | 2239 | CFRelease (pat_desc); |
| 2228 | if (! descs) | 2240 | if (! descs) |
| 2229 | goto err; | 2241 | goto err; |
| 2230 | 2242 | ||
| 2231 | descs_count = CFArrayGetCount (descs); | 2243 | descs_count = CFArrayGetCount (descs); |
| 2232 | if (descs_count == 0 | 2244 | if (descs_count == 0 |
| 2233 | || !macfont_supports_charset_and_languages_p (CFArrayGetValueAtIndex (descs, 0), | 2245 | || !macfont_supports_charset_and_languages_p (CFArrayGetValueAtIndex (descs, 0), |
| 2234 | charset, chars, | 2246 | charset, chars, |
| 2235 | languages)) | 2247 | languages)) |
| 2236 | { | 2248 | { |
| 2237 | CFRelease (descs); | 2249 | CFRelease (descs); |
| 2238 | continue; | 2250 | continue; |
| 2239 | } | 2251 | } |
| 2240 | 2252 | ||
| 2241 | filtered_descs = | 2253 | filtered_descs = |
| 2242 | CFArrayCreateMutable (NULL, descs_count, &kCFTypeArrayCallBacks); | 2254 | CFArrayCreateMutable (NULL, descs_count, &kCFTypeArrayCallBacks); |
| 2243 | traits_array = CFArrayCreateMutable (NULL, descs_count, NULL); | 2255 | traits_array = CFArrayCreateMutable (NULL, descs_count, NULL); |
| 2244 | for (j = 0; j < descs_count; j++) | 2256 | for (j = 0; j < descs_count; j++) |
| 2245 | { | 2257 | { |
| 2246 | FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, j); | 2258 | FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, j); |
| 2247 | CFDictionaryRef dict; | 2259 | CFDictionaryRef dict; |
| 2248 | CFNumberRef num; | 2260 | CFNumberRef num; |
| 2249 | FontSymbolicTraits sym_traits; | 2261 | FontSymbolicTraits sym_traits; |
| 2250 | 2262 | ||
| 2251 | dict = mac_font_descriptor_copy_attribute (desc, | 2263 | dict = mac_font_descriptor_copy_attribute (desc, |
| 2252 | MAC_FONT_TRAITS_ATTRIBUTE); | 2264 | MAC_FONT_TRAITS_ATTRIBUTE); |
| 2253 | if (dict == NULL) | 2265 | if (dict == NULL) |
| 2254 | continue; | 2266 | continue; |
| 2255 | 2267 | ||
| 2256 | num = CFDictionaryGetValue (dict, MAC_FONT_SYMBOLIC_TRAIT); | 2268 | num = CFDictionaryGetValue (dict, MAC_FONT_SYMBOLIC_TRAIT); |
| 2257 | CFRelease (dict); | 2269 | CFRelease (dict); |
| 2258 | if (num == NULL | 2270 | if (num == NULL |
| 2259 | || !cfnumber_get_font_symbolic_traits_value (num, &sym_traits)) | 2271 | || !cfnumber_get_font_symbolic_traits_value (num, &sym_traits)) |
| 2260 | continue; | 2272 | continue; |
| 2261 | 2273 | ||
| 2262 | if (spacing >= 0 | 2274 | if (spacing >= 0 |
| 2263 | && !(synth_sym_traits & MAC_FONT_TRAIT_MONO_SPACE) | 2275 | && !(synth_sym_traits & MAC_FONT_TRAIT_MONO_SPACE) |
| 2264 | && (((sym_traits & MAC_FONT_TRAIT_MONO_SPACE) != 0) | 2276 | && (((sym_traits & MAC_FONT_TRAIT_MONO_SPACE) != 0) |
| 2265 | != (spacing >= FONT_SPACING_MONO))) | 2277 | != (spacing >= FONT_SPACING_MONO))) |
| 2266 | continue; | 2278 | continue; |
| 2267 | 2279 | ||
| 2268 | /* Don't use a color bitmap font unless its family is | 2280 | /* Don't use a color bitmap font unless its family is |
| 2269 | explicitly specified. */ | 2281 | explicitly specified. */ |
| 2270 | if ((sym_traits & MAC_FONT_TRAIT_COLOR_GLYPHS) && NILP (family)) | 2282 | if ((sym_traits & MAC_FONT_TRAIT_COLOR_GLYPHS) && NILP (family)) |
| 2271 | continue; | 2283 | continue; |
| 2272 | 2284 | ||
| 2273 | if (j > 0 | 2285 | if (j > 0 |
| 2274 | && !macfont_supports_charset_and_languages_p (desc, charset, | 2286 | && !macfont_supports_charset_and_languages_p (desc, charset, |
| 2275 | chars, languages)) | 2287 | chars, languages)) |
| 2276 | continue; | 2288 | continue; |
| 2277 | 2289 | ||
| 2278 | CFArrayAppendValue (filtered_descs, desc); | 2290 | CFArrayAppendValue (filtered_descs, desc); |
| 2279 | CFArrayAppendValue (traits_array, | 2291 | CFArrayAppendValue (traits_array, |
| 2280 | (const void *) (uintptr_t) sym_traits); | 2292 | (const void *) (uintptr_t) sym_traits); |
| 2281 | } | 2293 | } |
| 2282 | 2294 | ||
| 2283 | CFRelease (descs); | 2295 | CFRelease (descs); |
| 2284 | descs = filtered_descs; | 2296 | descs = filtered_descs; |
| 2285 | descs_count = CFArrayGetCount (descs); | 2297 | descs_count = CFArrayGetCount (descs); |
| 2286 | 2298 | ||
| 2287 | for (j = 0; j < descs_count; j++) | 2299 | for (j = 0; j < descs_count; j++) |
| 2288 | { | 2300 | { |
| 2289 | FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, j); | 2301 | FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, j); |
| 2290 | FontSymbolicTraits sym_traits = | 2302 | FontSymbolicTraits sym_traits = |
| 2291 | ((FontSymbolicTraits) (uintptr_t) | 2303 | ((FontSymbolicTraits) (uintptr_t) |
| 2292 | CFArrayGetValueAtIndex (traits_array, j)); | 2304 | CFArrayGetValueAtIndex (traits_array, j)); |
| 2293 | FontSymbolicTraits mask_min, mask_max, imask, bmask, mmask; | 2305 | FontSymbolicTraits mask_min, mask_max, imask, bmask, mmask; |
| 2294 | 2306 | ||
| 2295 | mask_min = ((synth_sym_traits ^ sym_traits) | 2307 | mask_min = ((synth_sym_traits ^ sym_traits) |
| 2296 | & (MAC_FONT_TRAIT_ITALIC | MAC_FONT_TRAIT_BOLD)); | 2308 | & (MAC_FONT_TRAIT_ITALIC | MAC_FONT_TRAIT_BOLD)); |
| 2297 | if (FONT_SLANT_NUMERIC (spec) < 0) | 2309 | if (FONT_SLANT_NUMERIC (spec) < 0) |
| 2298 | mask_min &= ~MAC_FONT_TRAIT_ITALIC; | 2310 | mask_min &= ~MAC_FONT_TRAIT_ITALIC; |
| 2299 | if (FONT_WEIGHT_NUMERIC (spec) < 0) | 2311 | if (FONT_WEIGHT_NUMERIC (spec) < 0) |
| 2300 | mask_min &= ~MAC_FONT_TRAIT_BOLD; | 2312 | mask_min &= ~MAC_FONT_TRAIT_BOLD; |
| 2301 | 2313 | ||
| 2302 | mask_max = (synth_sym_traits & ~sym_traits); | 2314 | mask_max = (synth_sym_traits & ~sym_traits); |
| 2303 | /* Synthetic bold does not work for bitmap-only fonts on Mac | 2315 | /* Synthetic bold does not work for bitmap-only fonts on Mac |
| 2304 | OS X 10.6. */ | 2316 | OS X 10.6. */ |
| 2305 | if ((mask_min ^ mask_max) & MAC_FONT_TRAIT_BOLD) | 2317 | if ((mask_min ^ mask_max) & MAC_FONT_TRAIT_BOLD) |
| 2306 | { | 2318 | { |
| 2307 | CFNumberRef format = | 2319 | CFNumberRef format = |
| 2308 | mac_font_descriptor_copy_attribute (desc, | 2320 | mac_font_descriptor_copy_attribute (desc, |
| 2309 | MAC_FONT_FORMAT_ATTRIBUTE); | 2321 | MAC_FONT_FORMAT_ATTRIBUTE); |
| 2310 | 2322 | ||
| 2311 | if (format) | 2323 | if (format) |
| 2312 | { | 2324 | { |
| 2313 | uint32_t format_val; | 2325 | uint32_t format_val; |
| 2314 | 2326 | ||
| 2315 | if (CFNumberGetValue (format, kCFNumberSInt32Type, | 2327 | if (CFNumberGetValue (format, kCFNumberSInt32Type, |
| 2316 | &format_val) | 2328 | &format_val) |
| 2317 | && format_val == MAC_FONT_FORMAT_BITMAP) | 2329 | && format_val == MAC_FONT_FORMAT_BITMAP) |
| 2318 | mask_max &= ~MAC_FONT_TRAIT_BOLD; | 2330 | mask_max &= ~MAC_FONT_TRAIT_BOLD; |
| 2319 | } | 2331 | } |
| 2320 | } | 2332 | } |
| 2321 | if (spacing >= 0) | 2333 | if (spacing >= 0) |
| 2322 | mask_min |= (mask_max & MAC_FONT_TRAIT_MONO_SPACE); | 2334 | mask_min |= (mask_max & MAC_FONT_TRAIT_MONO_SPACE); |
| 2323 | 2335 | ||
| 2324 | for (mmask = (mask_min & MAC_FONT_TRAIT_MONO_SPACE); | 2336 | for (mmask = (mask_min & MAC_FONT_TRAIT_MONO_SPACE); |
| 2325 | mmask <= (mask_max & MAC_FONT_TRAIT_MONO_SPACE); | 2337 | mmask <= (mask_max & MAC_FONT_TRAIT_MONO_SPACE); |
| 2326 | mmask += MAC_FONT_TRAIT_MONO_SPACE) | 2338 | mmask += MAC_FONT_TRAIT_MONO_SPACE) |
| 2327 | for (bmask = (mask_min & MAC_FONT_TRAIT_BOLD); | 2339 | for (bmask = (mask_min & MAC_FONT_TRAIT_BOLD); |
| 2328 | bmask <= (mask_max & MAC_FONT_TRAIT_BOLD); | 2340 | bmask <= (mask_max & MAC_FONT_TRAIT_BOLD); |
| 2329 | bmask += MAC_FONT_TRAIT_BOLD) | 2341 | bmask += MAC_FONT_TRAIT_BOLD) |
| 2330 | for (imask = (mask_min & MAC_FONT_TRAIT_ITALIC); | 2342 | for (imask = (mask_min & MAC_FONT_TRAIT_ITALIC); |
| 2331 | imask <= (mask_max & MAC_FONT_TRAIT_ITALIC); | 2343 | imask <= (mask_max & MAC_FONT_TRAIT_ITALIC); |
| 2332 | imask += MAC_FONT_TRAIT_ITALIC) | 2344 | imask += MAC_FONT_TRAIT_ITALIC) |
| 2333 | { | 2345 | { |
| 2334 | FontSymbolicTraits synth = (imask | bmask | mmask); | 2346 | FontSymbolicTraits synth = (imask | bmask | mmask); |
| 2335 | 2347 | ||
| 2336 | if (synth == 0 | 2348 | if (synth == 0 |
| 2337 | || j == macfont_closest_traits_index (traits_array, | 2349 | || macfont_closest_traits_index_p (traits_array, |
| 2338 | (sym_traits | synth))) | 2350 | (sym_traits | synth), |
| 2339 | { | 2351 | j)) |
| 2340 | entity = macfont_descriptor_entity (desc, extra, synth); | 2352 | { |
| 2341 | if (! NILP (entity)) | 2353 | entity = macfont_descriptor_entity (desc, extra, synth); |
| 2342 | val = Fcons (entity, val); | 2354 | if (! NILP (entity)) |
| 2343 | } | 2355 | val = Fcons (entity, val); |
| 2344 | } | 2356 | } |
| 2345 | } | 2357 | } |
| 2358 | } | ||
| 2346 | 2359 | ||
| 2347 | CFRelease (traits_array); | 2360 | CFRelease (traits_array); |
| 2348 | CFRelease (descs); | 2361 | CFRelease (descs); |
| @@ -2384,13 +2397,13 @@ macfont_match (struct frame * frame, Lisp_Object spec) | |||
| 2384 | if (pat_desc) | 2397 | if (pat_desc) |
| 2385 | { | 2398 | { |
| 2386 | desc = mac_font_descriptor_create_matching_font_descriptor (pat_desc, | 2399 | desc = mac_font_descriptor_create_matching_font_descriptor (pat_desc, |
| 2387 | NULL); | 2400 | NULL); |
| 2388 | CFRelease (pat_desc); | 2401 | CFRelease (pat_desc); |
| 2389 | } | 2402 | } |
| 2390 | if (desc) | 2403 | if (desc) |
| 2391 | { | 2404 | { |
| 2392 | entity = macfont_descriptor_entity (desc, AREF (spec, FONT_EXTRA_INDEX), | 2405 | entity = macfont_descriptor_entity (desc, AREF (spec, FONT_EXTRA_INDEX), |
| 2393 | 0); | 2406 | 0); |
| 2394 | CFRelease (desc); | 2407 | CFRelease (desc); |
| 2395 | } | 2408 | } |
| 2396 | unblock_input (); | 2409 | unblock_input (); |
| @@ -2413,7 +2426,7 @@ macfont_list_family (struct frame *frame) | |||
| 2413 | CFIndex i, count = CFArrayGetCount (families); | 2426 | CFIndex i, count = CFArrayGetCount (families); |
| 2414 | 2427 | ||
| 2415 | for (i = 0; i < count; i++) | 2428 | for (i = 0; i < count; i++) |
| 2416 | list = Fcons (macfont_intern_prop_cfstring (CFArrayGetValueAtIndex (families, i)), list); | 2429 | list = Fcons (macfont_intern_prop_cfstring (CFArrayGetValueAtIndex (families, i)), list); |
| 2417 | CFRelease (families); | 2430 | CFRelease (families); |
| 2418 | } | 2431 | } |
| 2419 | 2432 | ||
| @@ -2426,7 +2439,7 @@ static void | |||
| 2426 | macfont_free_entity (Lisp_Object entity) | 2439 | macfont_free_entity (Lisp_Object entity) |
| 2427 | { | 2440 | { |
| 2428 | Lisp_Object val = assq_no_quit (QCfont_entity, | 2441 | Lisp_Object val = assq_no_quit (QCfont_entity, |
| 2429 | AREF (entity, FONT_EXTRA_INDEX)); | 2442 | AREF (entity, FONT_EXTRA_INDEX)); |
| 2430 | CFStringRef name = XSAVE_POINTER (XCDR (val), 0); | 2443 | CFStringRef name = XSAVE_POINTER (XCDR (val), 0); |
| 2431 | 2444 | ||
| 2432 | block_input (); | 2445 | block_input (); |
| @@ -2444,7 +2457,8 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2444 | int size; | 2457 | int size; |
| 2445 | FontRef macfont; | 2458 | FontRef macfont; |
| 2446 | FontSymbolicTraits sym_traits; | 2459 | FontSymbolicTraits sym_traits; |
| 2447 | int i, total_width; | 2460 | char name[256]; |
| 2461 | int len, i, total_width; | ||
| 2448 | CGGlyph glyph; | 2462 | CGGlyph glyph; |
| 2449 | CGFloat ascent, descent, leading; | 2463 | CGFloat ascent, descent, leading; |
| 2450 | 2464 | ||
| @@ -2472,7 +2486,7 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2472 | return Qnil; | 2486 | return Qnil; |
| 2473 | 2487 | ||
| 2474 | font_object = font_build_object (VECSIZE (struct macfont_info), | 2488 | font_object = font_build_object (VECSIZE (struct macfont_info), |
| 2475 | Qmac_ct, entity, size); | 2489 | Qmac_ct, entity, size); |
| 2476 | font = XFONT_OBJECT (font_object); | 2490 | font = XFONT_OBJECT (font_object); |
| 2477 | font->pixel_size = size; | 2491 | font->pixel_size = size; |
| 2478 | font->driver = &macfont_driver; | 2492 | font->driver = &macfont_driver; |
| @@ -2487,7 +2501,7 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2487 | val = assq_no_quit (QCdestination, AREF (entity, FONT_EXTRA_INDEX)); | 2501 | val = assq_no_quit (QCdestination, AREF (entity, FONT_EXTRA_INDEX)); |
| 2488 | if (CONSP (val) && EQ (XCDR (val), make_number (1))) | 2502 | if (CONSP (val) && EQ (XCDR (val), make_number (1))) |
| 2489 | macfont_info->screen_font = mac_screen_font_create_with_name (font_name, | 2503 | macfont_info->screen_font = mac_screen_font_create_with_name (font_name, |
| 2490 | size); | 2504 | size); |
| 2491 | else | 2505 | else |
| 2492 | macfont_info->screen_font = NULL; | 2506 | macfont_info->screen_font = NULL; |
| 2493 | macfont_info->cache = macfont_lookup_cache (font_name); | 2507 | macfont_info->cache = macfont_lookup_cache (font_name); |
| @@ -2507,8 +2521,8 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2507 | if (sym_traits & MAC_FONT_TRAIT_MONO_SPACE) | 2521 | if (sym_traits & MAC_FONT_TRAIT_MONO_SPACE) |
| 2508 | macfont_info->spacing = MACFONT_SPACING_MONO; | 2522 | macfont_info->spacing = MACFONT_SPACING_MONO; |
| 2509 | else if (INTEGERP (AREF (entity, FONT_SPACING_INDEX)) | 2523 | else if (INTEGERP (AREF (entity, FONT_SPACING_INDEX)) |
| 2510 | && (XINT (AREF (entity, FONT_SPACING_INDEX)) | 2524 | && (XINT (AREF (entity, FONT_SPACING_INDEX)) |
| 2511 | == FONT_SPACING_SYNTHETIC_MONO)) | 2525 | == FONT_SPACING_SYNTHETIC_MONO)) |
| 2512 | macfont_info->spacing = MACFONT_SPACING_SYNTHETIC_MONO; | 2526 | macfont_info->spacing = MACFONT_SPACING_SYNTHETIC_MONO; |
| 2513 | if (macfont_info->synthetic_italic_p || macfont_info->synthetic_bold_p) | 2527 | if (macfont_info->synthetic_italic_p || macfont_info->synthetic_bold_p) |
| 2514 | macfont_info->antialias = MACFONT_ANTIALIAS_ON; | 2528 | macfont_info->antialias = MACFONT_ANTIALIAS_ON; |
| @@ -2516,8 +2530,8 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2516 | { | 2530 | { |
| 2517 | val = assq_no_quit (QCantialias, AREF (entity, FONT_EXTRA_INDEX)); | 2531 | val = assq_no_quit (QCantialias, AREF (entity, FONT_EXTRA_INDEX)); |
| 2518 | if (CONSP (val)) | 2532 | if (CONSP (val)) |
| 2519 | macfont_info->antialias = | 2533 | macfont_info->antialias = |
| 2520 | NILP (XCDR (val)) ? MACFONT_ANTIALIAS_OFF : MACFONT_ANTIALIAS_ON; | 2534 | NILP (XCDR (val)) ? MACFONT_ANTIALIAS_OFF : MACFONT_ANTIALIAS_ON; |
| 2521 | } | 2535 | } |
| 2522 | macfont_info->color_bitmap_p = 0; | 2536 | macfont_info->color_bitmap_p = 0; |
| 2523 | if (sym_traits & MAC_FONT_TRAIT_COLOR_GLYPHS) | 2537 | if (sym_traits & MAC_FONT_TRAIT_COLOR_GLYPHS) |
| @@ -2535,7 +2549,7 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2535 | { | 2549 | { |
| 2536 | glyph = macfont_get_glyph_for_character (font, ' ' + i); | 2550 | glyph = macfont_get_glyph_for_character (font, ' ' + i); |
| 2537 | if (glyph == kCGFontIndexInvalid) | 2551 | if (glyph == kCGFontIndexInvalid) |
| 2538 | break; | 2552 | break; |
| 2539 | total_width += macfont_glyph_extents (font, glyph, NULL, NULL, 0); | 2553 | total_width += macfont_glyph_extents (font, glyph, NULL, NULL, 0); |
| 2540 | } | 2554 | } |
| 2541 | if (i == 95) | 2555 | if (i == 95) |
| @@ -2544,8 +2558,8 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2544 | font->average_width = font->space_width; /* XXX */ | 2558 | font->average_width = font->space_width; /* XXX */ |
| 2545 | 2559 | ||
| 2546 | if (!(macfont_info->screen_font | 2560 | if (!(macfont_info->screen_font |
| 2547 | && mac_screen_font_get_metrics (macfont_info->screen_font, | 2561 | && mac_screen_font_get_metrics (macfont_info->screen_font, |
| 2548 | &ascent, &descent, &leading))) | 2562 | &ascent, &descent, &leading))) |
| 2549 | { | 2563 | { |
| 2550 | CFStringRef family_name; | 2564 | CFStringRef family_name; |
| 2551 | 2565 | ||
| @@ -2553,21 +2567,21 @@ macfont_open (struct frame * f, Lisp_Object entity, int pixel_size) | |||
| 2553 | descent = mac_font_get_descent (macfont); | 2567 | descent = mac_font_get_descent (macfont); |
| 2554 | leading = mac_font_get_leading (macfont); | 2568 | leading = mac_font_get_leading (macfont); |
| 2555 | /* AppKit and WebKit do some adjustment to the heights of | 2569 | /* AppKit and WebKit do some adjustment to the heights of |
| 2556 | Courier, Helvetica, and Times. */ | 2570 | Courier, Helvetica, and Times. */ |
| 2557 | family_name = mac_font_copy_family_name (macfont); | 2571 | family_name = mac_font_copy_family_name (macfont); |
| 2558 | if (family_name) | 2572 | if (family_name) |
| 2559 | { | 2573 | { |
| 2560 | if (CFEqual (family_name, CFSTR ("Courier")) | 2574 | if (CFEqual (family_name, CFSTR ("Courier")) |
| 2561 | || CFEqual (family_name, CFSTR ("Helvetica")) | 2575 | || CFEqual (family_name, CFSTR ("Helvetica")) |
| 2562 | || CFEqual (family_name, CFSTR ("Times"))) | 2576 | || CFEqual (family_name, CFSTR ("Times"))) |
| 2563 | ascent += (ascent + descent) * .15f; | 2577 | ascent += (ascent + descent) * .15f; |
| 2564 | else if (CFStringHasPrefix (family_name, CFSTR ("Hiragino"))) | 2578 | else if (CFStringHasPrefix (family_name, CFSTR ("Hiragino"))) |
| 2565 | { | 2579 | { |
| 2566 | leading *= .25f; | 2580 | leading *= .25f; |
| 2567 | ascent += leading; | 2581 | ascent += leading; |
| 2568 | } | 2582 | } |
| 2569 | CFRelease (family_name); | 2583 | CFRelease (family_name); |
| 2570 | } | 2584 | } |
| 2571 | } | 2585 | } |
| 2572 | font->ascent = ascent + 0.5f; | 2586 | font->ascent = ascent + 0.5f; |
| 2573 | val = assq_no_quit (QCminspace, AREF (entity, FONT_EXTRA_INDEX)); | 2587 | val = assq_no_quit (QCminspace, AREF (entity, FONT_EXTRA_INDEX)); |
| @@ -2607,13 +2621,13 @@ macfont_close (struct font *font) | |||
| 2607 | CFRelease (macfont_info->macfont); | 2621 | CFRelease (macfont_info->macfont); |
| 2608 | CGFontRelease (macfont_info->cgfont); | 2622 | CGFontRelease (macfont_info->cgfont); |
| 2609 | if (macfont_info->screen_font) | 2623 | if (macfont_info->screen_font) |
| 2610 | CFRelease (macfont_info->screen_font); | 2624 | CFRelease (macfont_info->screen_font); |
| 2611 | macfont_release_cache (macfont_info->cache); | 2625 | macfont_release_cache (macfont_info->cache); |
| 2612 | for (i = 0; i < macfont_info->metrics_nrows; i++) | 2626 | for (i = 0; i < macfont_info->metrics_nrows; i++) |
| 2613 | if (macfont_info->metrics[i]) | 2627 | if (macfont_info->metrics[i]) |
| 2614 | xfree (macfont_info->metrics[i]); | 2628 | xfree (macfont_info->metrics[i]); |
| 2615 | if (macfont_info->metrics) | 2629 | if (macfont_info->metrics) |
| 2616 | xfree (macfont_info->metrics); | 2630 | xfree (macfont_info->metrics); |
| 2617 | macfont_info->cache = NULL; | 2631 | macfont_info->cache = NULL; |
| 2618 | unblock_input (); | 2632 | unblock_input (); |
| 2619 | } | 2633 | } |
| @@ -2659,8 +2673,8 @@ macfont_encode_char (struct font *font, int c) | |||
| 2659 | } | 2673 | } |
| 2660 | 2674 | ||
| 2661 | static void | 2675 | static void |
| 2662 | macfont_text_extents (struct font *font, unsigned int *code, | 2676 | macfont_text_extents (struct font *font, unsigned int *code, int nglyphs, |
| 2663 | int nglyphs, struct font_metrics *metrics) | 2677 | struct font_metrics *metrics) |
| 2664 | { | 2678 | { |
| 2665 | int width, i; | 2679 | int width, i; |
| 2666 | 2680 | ||
| @@ -2669,26 +2683,31 @@ macfont_text_extents (struct font *font, unsigned int *code, | |||
| 2669 | for (i = 1; i < nglyphs; i++) | 2683 | for (i = 1; i < nglyphs; i++) |
| 2670 | { | 2684 | { |
| 2671 | struct font_metrics m; | 2685 | struct font_metrics m; |
| 2672 | int w = macfont_glyph_extents (font, code[i], &m, NULL, 0); | 2686 | int w = macfont_glyph_extents (font, code[i], metrics ? &m : NULL, |
| 2673 | 2687 | NULL, 0); | |
| 2674 | if (width + m.lbearing < metrics->lbearing) | 2688 | |
| 2675 | metrics->lbearing = width + m.lbearing; | 2689 | if (metrics) |
| 2676 | if (width + m.rbearing > metrics->rbearing) | 2690 | { |
| 2677 | metrics->rbearing = width + m.rbearing; | 2691 | if (width + m.lbearing < metrics->lbearing) |
| 2678 | if (m.ascent > metrics->ascent) | 2692 | metrics->lbearing = width + m.lbearing; |
| 2679 | metrics->ascent = m.ascent; | 2693 | if (width + m.rbearing > metrics->rbearing) |
| 2680 | if (m.descent > metrics->descent) | 2694 | metrics->rbearing = width + m.rbearing; |
| 2681 | metrics->descent = m.descent; | 2695 | if (m.ascent > metrics->ascent) |
| 2696 | metrics->ascent = m.ascent; | ||
| 2697 | if (m.descent > metrics->descent) | ||
| 2698 | metrics->descent = m.descent; | ||
| 2699 | } | ||
| 2682 | width += w; | 2700 | width += w; |
| 2683 | } | 2701 | } |
| 2684 | unblock_input (); | 2702 | unblock_input (); |
| 2685 | 2703 | ||
| 2686 | metrics->width = width; | 2704 | if (metrics) |
| 2705 | metrics->width = width; | ||
| 2687 | } | 2706 | } |
| 2688 | 2707 | ||
| 2689 | static int | 2708 | static int |
| 2690 | macfont_draw (struct glyph_string *s, int from, int to, int x, int y, | 2709 | macfont_draw (struct glyph_string *s, int from, int to, int x, int y, |
| 2691 | bool with_background) | 2710 | bool with_background) |
| 2692 | { | 2711 | { |
| 2693 | struct frame * f = s->f; | 2712 | struct frame * f = s->f; |
| 2694 | struct macfont_info *macfont_info = (struct macfont_info *) s->font; | 2713 | struct macfont_info *macfont_info = (struct macfont_info *) s->font; |
| @@ -2700,7 +2719,7 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 2700 | bool no_antialias_p = | 2719 | bool no_antialias_p = |
| 2701 | (macfont_info->antialias == MACFONT_ANTIALIAS_OFF | 2720 | (macfont_info->antialias == MACFONT_ANTIALIAS_OFF |
| 2702 | || (macfont_info->antialias == MACFONT_ANTIALIAS_DEFAULT | 2721 | || (macfont_info->antialias == MACFONT_ANTIALIAS_DEFAULT |
| 2703 | && font_size <= macfont_antialias_threshold)); | 2722 | && font_size <= macfont_antialias_threshold)); |
| 2704 | int len = to - from; | 2723 | int len = to - from; |
| 2705 | struct face *face = s->face; | 2724 | struct face *face = s->face; |
| 2706 | CGContextRef context; | 2725 | CGContextRef context; |
| @@ -2710,29 +2729,29 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 2710 | if (with_background) | 2729 | if (with_background) |
| 2711 | background_rect = CGRectMake (x, y - FONT_BASE (s->font), | 2730 | background_rect = CGRectMake (x, y - FONT_BASE (s->font), |
| 2712 | s->width, FONT_HEIGHT (s->font)); | 2731 | s->width, FONT_HEIGHT (s->font)); |
| 2713 | else | 2732 | else |
| 2714 | background_rect = CGRectNull; | 2733 | background_rect = CGRectNull; |
| 2715 | 2734 | ||
| 2716 | text_position = CGPointMake (x, -y); | 2735 | text_position = CGPointMake (x, -y); |
| 2717 | glyphs = xmalloc (sizeof (CGGlyph) * len); | 2736 | glyphs = xmalloc (sizeof (CGGlyph) * len); |
| 2718 | { | 2737 | { |
| 2719 | CGFloat advance_delta; | 2738 | CGFloat advance_delta = 0; |
| 2720 | int i; | 2739 | int i; |
| 2721 | CGFloat total_width = 0; | 2740 | CGFloat total_width = 0; |
| 2722 | 2741 | ||
| 2723 | positions = xmalloc (sizeof (CGPoint) * len); | 2742 | positions = xmalloc (sizeof (CGPoint) * len); |
| 2724 | for (i = 0; i < len; i++) | 2743 | for (i = 0; i < len; i++) |
| 2725 | { | 2744 | { |
| 2726 | int width; | 2745 | int width; |
| 2727 | 2746 | ||
| 2728 | glyphs[i] = s->char2b[from + i]; | 2747 | glyphs[i] = s->char2b[from + i]; |
| 2729 | width = (s->padding_p ? 1 | 2748 | width = (s->padding_p ? 1 |
| 2730 | : macfont_glyph_extents (s->font, glyphs[i], | 2749 | : macfont_glyph_extents (s->font, glyphs[i], |
| 2731 | NULL, &advance_delta, | 2750 | NULL, &advance_delta, |
| 2732 | no_antialias_p)); | 2751 | no_antialias_p)); |
| 2733 | positions[i].x = total_width + advance_delta; | 2752 | positions[i].x = total_width + advance_delta; |
| 2734 | positions[i].y = 0; | 2753 | positions[i].y = 0; |
| 2735 | total_width += width; | 2754 | total_width += width; |
| 2736 | } | 2755 | } |
| 2737 | } | 2756 | } |
| 2738 | 2757 | ||
| @@ -2750,24 +2769,25 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 2750 | CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face, f); | 2769 | CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face, f); |
| 2751 | CGContextFillRects (context, &background_rect, 1); | 2770 | CGContextFillRects (context, &background_rect, 1); |
| 2752 | } | 2771 | } |
| 2753 | 2772 | ||
| 2754 | if (macfont_info->cgfont) | 2773 | if (macfont_info->cgfont) |
| 2755 | { | 2774 | { |
| 2756 | CGAffineTransform atfm; | 2775 | CGAffineTransform atfm; |
| 2776 | |||
| 2757 | CGContextScaleCTM (context, 1, -1); | 2777 | CGContextScaleCTM (context, 1, -1); |
| 2758 | CG_SET_FILL_COLOR_WITH_FACE_FOREGROUND (context, face, s->f); | 2778 | CG_SET_FILL_COLOR_WITH_FACE_FOREGROUND (context, face, s->f); |
| 2759 | if (macfont_info->synthetic_italic_p) | 2779 | if (macfont_info->synthetic_italic_p) |
| 2760 | atfm = synthetic_italic_atfm; | 2780 | atfm = synthetic_italic_atfm; |
| 2761 | else | 2781 | else |
| 2762 | atfm = CGAffineTransformIdentity; | 2782 | atfm = CGAffineTransformIdentity; |
| 2763 | if (macfont_info->synthetic_bold_p) | 2783 | if (macfont_info->synthetic_bold_p) |
| 2764 | { | 2784 | { |
| 2765 | CGContextSetTextDrawingMode (context, kCGTextFillStroke); | 2785 | CGContextSetTextDrawingMode (context, kCGTextFillStroke); |
| 2766 | CGContextSetLineWidth (context, synthetic_bold_factor * font_size); | 2786 | CGContextSetLineWidth (context, synthetic_bold_factor * font_size); |
| 2767 | CG_SET_STROKE_COLOR_WITH_FACE_FOREGROUND (context, face, f); | 2787 | CG_SET_STROKE_COLOR_WITH_FACE_FOREGROUND (context, face, f); |
| 2768 | } | 2788 | } |
| 2769 | if (no_antialias_p) | 2789 | if (no_antialias_p) |
| 2770 | CGContextSetShouldAntialias (context, false); | 2790 | CGContextSetShouldAntialias (context, false); |
| 2771 | 2791 | ||
| 2772 | CGContextSetTextMatrix (context, atfm); | 2792 | CGContextSetTextMatrix (context, atfm); |
| 2773 | CGContextSetTextPosition (context, text_position.x, text_position.y); | 2793 | CGContextSetTextPosition (context, text_position.x, text_position.y); |
| @@ -2775,23 +2795,23 @@ macfont_draw (struct glyph_string *s, int from, int to, int x, int y, | |||
| 2775 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 | 2795 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 |
| 2776 | if (macfont_info->color_bitmap_p | 2796 | if (macfont_info->color_bitmap_p |
| 2777 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 | 2797 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 |
| 2778 | && CTFontDrawGlyphs != NULL | 2798 | && CTFontDrawGlyphs != NULL |
| 2779 | #endif | 2799 | #endif |
| 2780 | ) | 2800 | ) |
| 2781 | { | 2801 | { |
| 2782 | if (len > 0) | 2802 | if (len > 0) |
| 2783 | { | 2803 | { |
| 2784 | CTFontDrawGlyphs (macfont_info->macfont, glyphs, positions, len, | 2804 | CTFontDrawGlyphs (macfont_info->macfont, glyphs, positions, len, |
| 2785 | context); | 2805 | context); |
| 2786 | } | 2806 | } |
| 2787 | } | 2807 | } |
| 2788 | else | 2808 | else |
| 2789 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */ | 2809 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */ |
| 2790 | { | 2810 | { |
| 2791 | CGContextSetFont (context, macfont_info->cgfont); | 2811 | CGContextSetFont (context, macfont_info->cgfont); |
| 2792 | CGContextSetFontSize (context, font_size); | 2812 | CGContextSetFontSize (context, font_size); |
| 2793 | CGContextShowGlyphsAtPositions (context, glyphs, positions, len); | 2813 | CGContextShowGlyphsAtPositions (context, glyphs, positions, len); |
| 2794 | } | 2814 | } |
| 2795 | } | 2815 | } |
| 2796 | 2816 | ||
| 2797 | 2817 | ||
| @@ -2829,9 +2849,9 @@ macfont_shape (Lisp_Object lgstring) | |||
| 2829 | Lisp_Object lglyph = LGSTRING_GLYPH (lgstring, i); | 2849 | Lisp_Object lglyph = LGSTRING_GLYPH (lgstring, i); |
| 2830 | 2850 | ||
| 2831 | if (NILP (lglyph)) | 2851 | if (NILP (lglyph)) |
| 2832 | break; | 2852 | break; |
| 2833 | if (LGLYPH_CHAR (lglyph) >= 0x10000) | 2853 | if (LGLYPH_CHAR (lglyph) >= 0x10000) |
| 2834 | nonbmp_len++; | 2854 | nonbmp_len++; |
| 2835 | } | 2855 | } |
| 2836 | 2856 | ||
| 2837 | len = i; | 2857 | len = i; |
| @@ -2846,25 +2866,25 @@ macfont_shape (Lisp_Object lgstring) | |||
| 2846 | UTF32Char c = LGLYPH_CHAR (LGSTRING_GLYPH (lgstring, i)); | 2866 | UTF32Char c = LGLYPH_CHAR (LGSTRING_GLYPH (lgstring, i)); |
| 2847 | 2867 | ||
| 2848 | if (macfont_store_utf32char_to_unichars (c, unichars + i + j) > 1) | 2868 | if (macfont_store_utf32char_to_unichars (c, unichars + i + j) > 1) |
| 2849 | { | 2869 | { |
| 2850 | nonbmp_indices[j] = i + j; | 2870 | nonbmp_indices[j] = i + j; |
| 2851 | j++; | 2871 | j++; |
| 2852 | } | 2872 | } |
| 2853 | } | 2873 | } |
| 2854 | nonbmp_indices[j] = len + j; /* sentinel */ | 2874 | nonbmp_indices[j] = len + j; /* sentinel */ |
| 2855 | 2875 | ||
| 2856 | block_input (); | 2876 | block_input (); |
| 2857 | 2877 | ||
| 2858 | string = CFStringCreateWithCharactersNoCopy (NULL, unichars, len + nonbmp_len, | 2878 | string = CFStringCreateWithCharactersNoCopy (NULL, unichars, len + nonbmp_len, |
| 2859 | kCFAllocatorNull); | 2879 | kCFAllocatorNull); |
| 2860 | if (string) | 2880 | if (string) |
| 2861 | { | 2881 | { |
| 2862 | glyph_layouts = alloca (sizeof (struct mac_glyph_layout) * glyph_len); | 2882 | glyph_layouts = alloca (sizeof (struct mac_glyph_layout) * glyph_len); |
| 2863 | if (macfont_info->screen_font) | 2883 | if (macfont_info->screen_font) |
| 2864 | used = mac_screen_font_shape (macfont_info->screen_font, string, | 2884 | used = mac_screen_font_shape (macfont_info->screen_font, string, |
| 2865 | glyph_layouts, glyph_len); | 2885 | glyph_layouts, glyph_len); |
| 2866 | else | 2886 | else |
| 2867 | used = mac_font_shape (macfont, string, glyph_layouts, glyph_len); | 2887 | used = mac_font_shape (macfont, string, glyph_layouts, glyph_len); |
| 2868 | CFRelease (string); | 2888 | CFRelease (string); |
| 2869 | } | 2889 | } |
| 2870 | 2890 | ||
| @@ -2884,40 +2904,40 @@ macfont_shape (Lisp_Object lgstring) | |||
| 2884 | int xoff, yoff, wadjust; | 2904 | int xoff, yoff, wadjust; |
| 2885 | 2905 | ||
| 2886 | if (NILP (lglyph)) | 2906 | if (NILP (lglyph)) |
| 2887 | { | 2907 | { |
| 2888 | lglyph = Fmake_vector (make_number (LGLYPH_SIZE), Qnil); | 2908 | lglyph = Fmake_vector (make_number (LGLYPH_SIZE), Qnil); |
| 2889 | LGSTRING_SET_GLYPH (lgstring, i, lglyph); | 2909 | LGSTRING_SET_GLYPH (lgstring, i, lglyph); |
| 2890 | } | 2910 | } |
| 2891 | 2911 | ||
| 2892 | from = gl->comp_range.location; | 2912 | from = gl->comp_range.location; |
| 2893 | /* Convert UTF-16 index to UTF-32. */ | 2913 | /* Convert UTF-16 index to UTF-32. */ |
| 2894 | j = 0; | 2914 | j = 0; |
| 2895 | while (nonbmp_indices[j] < from) | 2915 | while (nonbmp_indices[j] < from) |
| 2896 | j++; | 2916 | j++; |
| 2897 | from -= j; | 2917 | from -= j; |
| 2898 | LGLYPH_SET_FROM (lglyph, from); | 2918 | LGLYPH_SET_FROM (lglyph, from); |
| 2899 | 2919 | ||
| 2900 | to = gl->comp_range.location + gl->comp_range.length; | 2920 | to = gl->comp_range.location + gl->comp_range.length; |
| 2901 | /* Convert UTF-16 index to UTF-32. */ | 2921 | /* Convert UTF-16 index to UTF-32. */ |
| 2902 | while (nonbmp_indices[j] < to) | 2922 | while (nonbmp_indices[j] < to) |
| 2903 | j++; | 2923 | j++; |
| 2904 | to -= j; | 2924 | to -= j; |
| 2905 | LGLYPH_SET_TO (lglyph, to - 1); | 2925 | LGLYPH_SET_TO (lglyph, to - 1); |
| 2906 | 2926 | ||
| 2907 | /* LGLYPH_CHAR is used in `describe-char' for checking whether | 2927 | /* LGLYPH_CHAR is used in `describe-char' for checking whether |
| 2908 | the composition is trivial. */ | 2928 | the composition is trivial. */ |
| 2909 | { | 2929 | { |
| 2910 | UTF32Char c; | 2930 | UTF32Char c; |
| 2911 | 2931 | ||
| 2912 | if (unichars[gl->string_index] >= 0xD800 | 2932 | if (unichars[gl->string_index] >= 0xD800 |
| 2913 | && unichars[gl->string_index] < 0xDC00) | 2933 | && unichars[gl->string_index] < 0xDC00) |
| 2914 | c = (((unichars[gl->string_index] - 0xD800) << 10) | 2934 | c = (((unichars[gl->string_index] - 0xD800) << 10) |
| 2915 | + (unichars[gl->string_index + 1] - 0xDC00) + 0x10000); | 2935 | + (unichars[gl->string_index + 1] - 0xDC00) + 0x10000); |
| 2916 | else | 2936 | else |
| 2917 | c = unichars[gl->string_index]; | 2937 | c = unichars[gl->string_index]; |
| 2918 | if (macfont_get_glyph_for_character (font, c) != gl->glyph_id) | 2938 | if (macfont_get_glyph_for_character (font, c) != gl->glyph_id) |
| 2919 | c = 0; | 2939 | c = 0; |
| 2920 | LGLYPH_SET_CHAR (lglyph, c); | 2940 | LGLYPH_SET_CHAR (lglyph, c); |
| 2921 | } | 2941 | } |
| 2922 | 2942 | ||
| 2923 | { | 2943 | { |
| @@ -2936,15 +2956,15 @@ macfont_shape (Lisp_Object lgstring) | |||
| 2936 | yoff = lround (- gl->baseline_delta); | 2956 | yoff = lround (- gl->baseline_delta); |
| 2937 | wadjust = lround (gl->advance); | 2957 | wadjust = lround (gl->advance); |
| 2938 | if (xoff != 0 || yoff != 0 || wadjust != metrics.width) | 2958 | if (xoff != 0 || yoff != 0 || wadjust != metrics.width) |
| 2939 | { | 2959 | { |
| 2940 | Lisp_Object vec; | 2960 | Lisp_Object vec; |
| 2941 | 2961 | ||
| 2942 | vec = Fmake_vector (make_number (3), Qnil); | 2962 | vec = Fmake_vector (make_number (3), Qnil); |
| 2943 | ASET (vec, 0, make_number (xoff)); | 2963 | ASET (vec, 0, make_number (xoff)); |
| 2944 | ASET (vec, 1, make_number (yoff)); | 2964 | ASET (vec, 1, make_number (yoff)); |
| 2945 | ASET (vec, 2, make_number (wadjust)); | 2965 | ASET (vec, 2, make_number (wadjust)); |
| 2946 | LGLYPH_SET_ADJUSTMENT (lglyph, vec); | 2966 | LGLYPH_SET_ADJUSTMENT (lglyph, vec); |
| 2947 | } | 2967 | } |
| 2948 | } | 2968 | } |
| 2949 | 2969 | ||
| 2950 | unblock_input (); | 2970 | unblock_input (); |
| @@ -2967,7 +2987,7 @@ struct uvs_table | |||
| 2967 | UInt32 length, num_var_selector_records; | 2987 | UInt32 length, num_var_selector_records; |
| 2968 | struct variation_selector_record variation_selector_records[1]; | 2988 | struct variation_selector_record variation_selector_records[1]; |
| 2969 | }; | 2989 | }; |
| 2970 | #define SIZEOF_UVS_TABLE_HEADER \ | 2990 | #define SIZEOF_UVS_TABLE_HEADER \ |
| 2971 | (sizeof (struct uvs_table) - sizeof (struct variation_selector_record)) | 2991 | (sizeof (struct uvs_table) - sizeof (struct variation_selector_record)) |
| 2972 | 2992 | ||
| 2973 | struct unicode_value_range | 2993 | struct unicode_value_range |
| @@ -2979,7 +2999,7 @@ struct default_uvs_table { | |||
| 2979 | UInt32 num_unicode_value_ranges; | 2999 | UInt32 num_unicode_value_ranges; |
| 2980 | struct unicode_value_range unicode_value_ranges[1]; | 3000 | struct unicode_value_range unicode_value_ranges[1]; |
| 2981 | }; | 3001 | }; |
| 2982 | #define SIZEOF_DEFAULT_UVS_TABLE_HEADER \ | 3002 | #define SIZEOF_DEFAULT_UVS_TABLE_HEADER \ |
| 2983 | (sizeof (struct default_uvs_table) - sizeof (struct unicode_value_range)) | 3003 | (sizeof (struct default_uvs_table) - sizeof (struct unicode_value_range)) |
| 2984 | 3004 | ||
| 2985 | struct uvs_mapping | 3005 | struct uvs_mapping |
| @@ -2992,7 +3012,7 @@ struct non_default_uvs_table | |||
| 2992 | UInt32 num_uvs_mappings; | 3012 | UInt32 num_uvs_mappings; |
| 2993 | struct uvs_mapping uvs_mappings[1]; | 3013 | struct uvs_mapping uvs_mappings[1]; |
| 2994 | }; | 3014 | }; |
| 2995 | #define SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER \ | 3015 | #define SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER \ |
| 2996 | (sizeof (struct non_default_uvs_table) - sizeof (struct uvs_mapping)) | 3016 | (sizeof (struct non_default_uvs_table) - sizeof (struct uvs_mapping)) |
| 2997 | #pragma pack(pop) | 3017 | #pragma pack(pop) |
| 2998 | 3018 | ||
| @@ -3024,98 +3044,98 @@ mac_font_copy_uvs_table (FontRef font) | |||
| 3024 | 3044 | ||
| 3025 | #if __LP64__ | 3045 | #if __LP64__ |
| 3026 | if (CFDataGetLength (cmap_table) > UINT32_MAX) | 3046 | if (CFDataGetLength (cmap_table) > UINT32_MAX) |
| 3027 | goto finish; | 3047 | goto finish; |
| 3028 | #endif | 3048 | #endif |
| 3029 | 3049 | ||
| 3030 | cmap_len = CFDataGetLength (cmap_table); | 3050 | cmap_len = CFDataGetLength (cmap_table); |
| 3031 | if (sizeof_sfntCMapHeader > cmap_len) | 3051 | if (sizeof_sfntCMapHeader > cmap_len) |
| 3032 | goto finish; | 3052 | goto finish; |
| 3033 | 3053 | ||
| 3034 | ntables = BUINT16_VALUE (cmap->numTables); | 3054 | ntables = BUINT16_VALUE (cmap->numTables); |
| 3035 | if (ntables > ((cmap_len - sizeof_sfntCMapHeader) | 3055 | if (ntables > ((cmap_len - sizeof_sfntCMapHeader) |
| 3036 | / sizeof_sfntCMapEncoding)) | 3056 | / sizeof_sfntCMapEncoding)) |
| 3037 | goto finish; | 3057 | goto finish; |
| 3038 | 3058 | ||
| 3039 | for (i = 0; i < ntables; i++) | 3059 | for (i = 0; i < ntables; i++) |
| 3040 | if ((BUINT16_VALUE (cmap->encoding[i].platformID) | 3060 | if ((BUINT16_VALUE (cmap->encoding[i].platformID) |
| 3041 | == kFontUnicodePlatform) | 3061 | == kFontUnicodePlatform) |
| 3042 | && (BUINT16_VALUE (cmap->encoding[i].scriptID) | 3062 | && (BUINT16_VALUE (cmap->encoding[i].scriptID) |
| 3043 | == 5)) /* kFontUnicodeV4_0VariationSequenceSemantics */ | 3063 | == 5)) /* kFontUnicodeV4_0VariationSequenceSemantics */ |
| 3044 | { | 3064 | { |
| 3045 | uvs_offset = BUINT32_VALUE (cmap->encoding[i].offset); | 3065 | uvs_offset = BUINT32_VALUE (cmap->encoding[i].offset); |
| 3046 | break; | 3066 | break; |
| 3047 | } | 3067 | } |
| 3048 | if (i == ntables | 3068 | if (i == ntables |
| 3049 | || uvs_offset > cmap_len | 3069 | || uvs_offset > cmap_len |
| 3050 | || SIZEOF_UVS_TABLE_HEADER > cmap_len - uvs_offset) | 3070 | || SIZEOF_UVS_TABLE_HEADER > cmap_len - uvs_offset) |
| 3051 | goto finish; | 3071 | goto finish; |
| 3052 | 3072 | ||
| 3053 | uvs = (struct uvs_table *) ((UInt8 *) cmap + uvs_offset); | 3073 | uvs = (struct uvs_table *) ((UInt8 *) cmap + uvs_offset); |
| 3054 | uvs_len = BUINT32_VALUE (uvs->length); | 3074 | uvs_len = BUINT32_VALUE (uvs->length); |
| 3055 | if (uvs_len > cmap_len - uvs_offset | 3075 | if (uvs_len > cmap_len - uvs_offset |
| 3056 | || SIZEOF_UVS_TABLE_HEADER > uvs_len) | 3076 | || SIZEOF_UVS_TABLE_HEADER > uvs_len) |
| 3057 | goto finish; | 3077 | goto finish; |
| 3058 | 3078 | ||
| 3059 | if (BUINT16_VALUE (uvs->format) != 14) | 3079 | if (BUINT16_VALUE (uvs->format) != 14) |
| 3060 | goto finish; | 3080 | goto finish; |
| 3061 | 3081 | ||
| 3062 | nrecords = BUINT32_VALUE (uvs->num_var_selector_records); | 3082 | nrecords = BUINT32_VALUE (uvs->num_var_selector_records); |
| 3063 | if (nrecords > ((uvs_len - SIZEOF_UVS_TABLE_HEADER) | 3083 | if (nrecords > ((uvs_len - SIZEOF_UVS_TABLE_HEADER) |
| 3064 | / sizeof (struct variation_selector_record))) | 3084 | / sizeof (struct variation_selector_record))) |
| 3065 | goto finish; | 3085 | goto finish; |
| 3066 | 3086 | ||
| 3067 | records = uvs->variation_selector_records; | 3087 | records = uvs->variation_selector_records; |
| 3068 | for (i = 0; i < nrecords; i++) | 3088 | for (i = 0; i < nrecords; i++) |
| 3069 | { | 3089 | { |
| 3070 | UInt32 default_uvs_offset, non_default_uvs_offset; | 3090 | UInt32 default_uvs_offset, non_default_uvs_offset; |
| 3071 | 3091 | ||
| 3072 | default_uvs_offset = BUINT32_VALUE (records[i].default_uvs_offset); | 3092 | default_uvs_offset = BUINT32_VALUE (records[i].default_uvs_offset); |
| 3073 | if (default_uvs_offset) | 3093 | if (default_uvs_offset) |
| 3074 | { | 3094 | { |
| 3075 | struct default_uvs_table *default_uvs; | 3095 | struct default_uvs_table *default_uvs; |
| 3076 | UInt32 nranges; | 3096 | UInt32 nranges; |
| 3077 | 3097 | ||
| 3078 | if (default_uvs_offset > uvs_len | 3098 | if (default_uvs_offset > uvs_len |
| 3079 | || (SIZEOF_DEFAULT_UVS_TABLE_HEADER | 3099 | || (SIZEOF_DEFAULT_UVS_TABLE_HEADER |
| 3080 | > uvs_len - default_uvs_offset)) | 3100 | > uvs_len - default_uvs_offset)) |
| 3081 | goto finish; | 3101 | goto finish; |
| 3082 | 3102 | ||
| 3083 | default_uvs = ((struct default_uvs_table *) | 3103 | default_uvs = ((struct default_uvs_table *) |
| 3084 | ((UInt8 *) uvs + default_uvs_offset)); | 3104 | ((UInt8 *) uvs + default_uvs_offset)); |
| 3085 | nranges = BUINT32_VALUE (default_uvs->num_unicode_value_ranges); | 3105 | nranges = BUINT32_VALUE (default_uvs->num_unicode_value_ranges); |
| 3086 | if (nranges > ((uvs_len - default_uvs_offset | 3106 | if (nranges > ((uvs_len - default_uvs_offset |
| 3087 | - SIZEOF_DEFAULT_UVS_TABLE_HEADER) | 3107 | - SIZEOF_DEFAULT_UVS_TABLE_HEADER) |
| 3088 | / sizeof (struct unicode_value_range))) | 3108 | / sizeof (struct unicode_value_range))) |
| 3089 | goto finish; | 3109 | goto finish; |
| 3090 | /* Now 2 * nranges can't overflow, so we can safely use | 3110 | /* Now 2 * nranges can't overflow, so we can safely use |
| 3091 | `(lo + hi) / 2' instead of `lo + (hi - lo) / 2' in | 3111 | `(lo + hi) / 2' instead of `lo + (hi - lo) / 2' in |
| 3092 | mac_font_get_glyphs_for_variants. */ | 3112 | mac_font_get_glyphs_for_variants. */ |
| 3093 | } | 3113 | } |
| 3094 | 3114 | ||
| 3095 | non_default_uvs_offset = | 3115 | non_default_uvs_offset = |
| 3096 | BUINT32_VALUE (records[i].non_default_uvs_offset); | 3116 | BUINT32_VALUE (records[i].non_default_uvs_offset); |
| 3097 | if (non_default_uvs_offset) | 3117 | if (non_default_uvs_offset) |
| 3098 | { | 3118 | { |
| 3099 | struct non_default_uvs_table *non_default_uvs; | 3119 | struct non_default_uvs_table *non_default_uvs; |
| 3100 | UInt32 nmappings; | 3120 | UInt32 nmappings; |
| 3101 | 3121 | ||
| 3102 | if (non_default_uvs_offset > uvs_len | 3122 | if (non_default_uvs_offset > uvs_len |
| 3103 | || (SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER | 3123 | || (SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER |
| 3104 | > uvs_len - non_default_uvs_offset)) | 3124 | > uvs_len - non_default_uvs_offset)) |
| 3105 | goto finish; | 3125 | goto finish; |
| 3106 | 3126 | ||
| 3107 | non_default_uvs = ((struct non_default_uvs_table *) | 3127 | non_default_uvs = ((struct non_default_uvs_table *) |
| 3108 | ((UInt8 *) uvs + non_default_uvs_offset)); | 3128 | ((UInt8 *) uvs + non_default_uvs_offset)); |
| 3109 | nmappings = BUINT32_VALUE (non_default_uvs->num_uvs_mappings); | 3129 | nmappings = BUINT32_VALUE (non_default_uvs->num_uvs_mappings); |
| 3110 | if (nmappings > ((uvs_len - non_default_uvs_offset | 3130 | if (nmappings > ((uvs_len - non_default_uvs_offset |
| 3111 | - SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER) | 3131 | - SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER) |
| 3112 | / sizeof (struct uvs_mapping))) | 3132 | / sizeof (struct uvs_mapping))) |
| 3113 | goto finish; | 3133 | goto finish; |
| 3114 | /* Now 2 * nmappings can't overflow, so we can safely | 3134 | /* Now 2 * nmappings can't overflow, so we can safely |
| 3115 | use `(lo + hi) / 2' instead of `lo + (hi - lo) / 2' | 3135 | use `(lo + hi) / 2' instead of `lo + (hi - lo) / 2' |
| 3116 | in mac_font_get_glyphs_for_variants. */ | 3136 | in mac_font_get_glyphs_for_variants. */ |
| 3117 | } | 3137 | } |
| 3118 | } | 3138 | } |
| 3119 | 3139 | ||
| 3120 | uvs_table = CFDataCreate (NULL, (UInt8 *) uvs, uvs_len); | 3140 | uvs_table = CFDataCreate (NULL, (UInt8 *) uvs, uvs_len); |
| 3121 | 3141 | ||
| @@ -3138,8 +3158,8 @@ mac_font_copy_uvs_table (FontRef font) | |||
| 3138 | 3158 | ||
| 3139 | static void | 3159 | static void |
| 3140 | mac_font_get_glyphs_for_variants (CFDataRef uvs_table, UTF32Char c, | 3160 | mac_font_get_glyphs_for_variants (CFDataRef uvs_table, UTF32Char c, |
| 3141 | const UTF32Char selectors[], CGGlyph glyphs[], | 3161 | const UTF32Char selectors[], CGGlyph glyphs[], |
| 3142 | CFIndex count) | 3162 | CFIndex count) |
| 3143 | { | 3163 | { |
| 3144 | struct uvs_table *uvs = (struct uvs_table *) CFDataGetBytePtr (uvs_table); | 3164 | struct uvs_table *uvs = (struct uvs_table *) CFDataGetBytePtr (uvs_table); |
| 3145 | struct variation_selector_record *records = uvs->variation_selector_records; | 3165 | struct variation_selector_record *records = uvs->variation_selector_records; |
| @@ -3159,76 +3179,76 @@ mac_font_get_glyphs_for_variants (CFDataRef uvs_table, UTF32Char c, | |||
| 3159 | UInt32 default_uvs_offset, non_default_uvs_offset; | 3179 | UInt32 default_uvs_offset, non_default_uvs_offset; |
| 3160 | 3180 | ||
| 3161 | if (selectors[i] < BUINT24_VALUE (records[ir].var_selector)) | 3181 | if (selectors[i] < BUINT24_VALUE (records[ir].var_selector)) |
| 3162 | { | 3182 | { |
| 3163 | glyphs[i++] = kCGFontIndexInvalid; | 3183 | glyphs[i++] = kCGFontIndexInvalid; |
| 3164 | continue; | 3184 | continue; |
| 3165 | } | 3185 | } |
| 3166 | else if (selectors[i] > BUINT24_VALUE (records[ir].var_selector)) | 3186 | else if (selectors[i] > BUINT24_VALUE (records[ir].var_selector)) |
| 3167 | { | 3187 | { |
| 3168 | ir++; | 3188 | ir++; |
| 3169 | continue; | 3189 | continue; |
| 3170 | } | 3190 | } |
| 3171 | 3191 | ||
| 3172 | /* selectors[i] == BUINT24_VALUE (records[ir].var_selector) */ | 3192 | /* selectors[i] == BUINT24_VALUE (records[ir].var_selector) */ |
| 3173 | default_uvs_offset = BUINT32_VALUE (records[ir].default_uvs_offset); | 3193 | default_uvs_offset = BUINT32_VALUE (records[ir].default_uvs_offset); |
| 3174 | non_default_uvs_offset = | 3194 | non_default_uvs_offset = |
| 3175 | BUINT32_VALUE (records[ir].non_default_uvs_offset); | 3195 | BUINT32_VALUE (records[ir].non_default_uvs_offset); |
| 3176 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 | 3196 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 |
| 3177 | dispatch_group_async (group, queue, ^{ | 3197 | dispatch_group_async (group, queue, ^{ |
| 3178 | #endif | 3198 | #endif |
| 3179 | glyphs[i] = kCGFontIndexInvalid; | 3199 | glyphs[i] = kCGFontIndexInvalid; |
| 3180 | 3200 | ||
| 3181 | if (default_uvs_offset) | 3201 | if (default_uvs_offset) |
| 3182 | { | 3202 | { |
| 3183 | struct default_uvs_table *default_uvs = | 3203 | struct default_uvs_table *default_uvs = |
| 3184 | (struct default_uvs_table *) ((UInt8 *) uvs | 3204 | (struct default_uvs_table *) ((UInt8 *) uvs |
| 3185 | + default_uvs_offset); | 3205 | + default_uvs_offset); |
| 3186 | struct unicode_value_range *ranges = | 3206 | struct unicode_value_range *ranges = |
| 3187 | default_uvs->unicode_value_ranges; | 3207 | default_uvs->unicode_value_ranges; |
| 3188 | UInt32 lo, hi; | 3208 | UInt32 lo, hi; |
| 3189 | 3209 | ||
| 3190 | lo = 0; | 3210 | lo = 0; |
| 3191 | hi = BUINT32_VALUE (default_uvs->num_unicode_value_ranges); | 3211 | hi = BUINT32_VALUE (default_uvs->num_unicode_value_ranges); |
| 3192 | while (lo < hi) | 3212 | while (lo < hi) |
| 3193 | { | 3213 | { |
| 3194 | UInt32 mid = (lo + hi) / 2; | 3214 | UInt32 mid = (lo + hi) / 2; |
| 3195 | 3215 | ||
| 3196 | if (c < BUINT24_VALUE (ranges[mid].start_unicode_value)) | 3216 | if (c < BUINT24_VALUE (ranges[mid].start_unicode_value)) |
| 3197 | hi = mid; | 3217 | hi = mid; |
| 3198 | else | 3218 | else |
| 3199 | lo = mid + 1; | 3219 | lo = mid + 1; |
| 3200 | } | 3220 | } |
| 3201 | if (hi > 0 | 3221 | if (hi > 0 |
| 3202 | && (c <= (BUINT24_VALUE (ranges[hi - 1].start_unicode_value) | 3222 | && (c <= (BUINT24_VALUE (ranges[hi - 1].start_unicode_value) |
| 3203 | + BUINT8_VALUE (ranges[hi - 1].additional_count)))) | 3223 | + BUINT8_VALUE (ranges[hi - 1].additional_count)))) |
| 3204 | glyphs[i] = 0; | 3224 | glyphs[i] = 0; |
| 3205 | } | 3225 | } |
| 3206 | 3226 | ||
| 3207 | if (glyphs[i] == kCGFontIndexInvalid && non_default_uvs_offset) | 3227 | if (glyphs[i] == kCGFontIndexInvalid && non_default_uvs_offset) |
| 3208 | { | 3228 | { |
| 3209 | struct non_default_uvs_table *non_default_uvs = | 3229 | struct non_default_uvs_table *non_default_uvs = |
| 3210 | (struct non_default_uvs_table *) ((UInt8 *) uvs | 3230 | (struct non_default_uvs_table *) ((UInt8 *) uvs |
| 3211 | + non_default_uvs_offset); | 3231 | + non_default_uvs_offset); |
| 3212 | struct uvs_mapping *mappings = non_default_uvs->uvs_mappings; | 3232 | struct uvs_mapping *mappings = non_default_uvs->uvs_mappings; |
| 3213 | UInt32 lo, hi; | 3233 | UInt32 lo, hi; |
| 3214 | 3234 | ||
| 3215 | lo = 0; | 3235 | lo = 0; |
| 3216 | hi = BUINT32_VALUE (non_default_uvs->num_uvs_mappings); | 3236 | hi = BUINT32_VALUE (non_default_uvs->num_uvs_mappings); |
| 3217 | while (lo < hi) | 3237 | while (lo < hi) |
| 3218 | { | 3238 | { |
| 3219 | UInt32 mid = (lo + hi) / 2; | 3239 | UInt32 mid = (lo + hi) / 2; |
| 3220 | 3240 | ||
| 3221 | if (c < BUINT24_VALUE (mappings[mid].unicode_value)) | 3241 | if (c < BUINT24_VALUE (mappings[mid].unicode_value)) |
| 3222 | hi = mid; | 3242 | hi = mid; |
| 3223 | else | 3243 | else |
| 3224 | lo = mid + 1; | 3244 | lo = mid + 1; |
| 3225 | } | 3245 | } |
| 3226 | if (hi > 0 && | 3246 | if (hi > 0 && |
| 3227 | BUINT24_VALUE (mappings[hi - 1].unicode_value) == c) | 3247 | BUINT24_VALUE (mappings[hi - 1].unicode_value) == c) |
| 3228 | glyphs[i] = BUINT16_VALUE (mappings[hi - 1].glyph_id); | 3248 | glyphs[i] = BUINT16_VALUE (mappings[hi - 1].glyph_id); |
| 3229 | } | 3249 | } |
| 3230 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 | 3250 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 |
| 3231 | }); | 3251 | }); |
| 3232 | #endif | 3252 | #endif |
| 3233 | i++; | 3253 | i++; |
| 3234 | ir++; | 3254 | ir++; |
| @@ -3257,26 +3277,26 @@ macfont_variation_glyphs (struct font *font, int c, unsigned variations[256]) | |||
| 3257 | CGGlyph glyphs[256]; | 3277 | CGGlyph glyphs[256]; |
| 3258 | 3278 | ||
| 3259 | for (i = 0; i < 16; i++) | 3279 | for (i = 0; i < 16; i++) |
| 3260 | selectors[i] = 0xFE00 + i; | 3280 | selectors[i] = 0xFE00 + i; |
| 3261 | for (; i < 256; i++) | 3281 | for (; i < 256; i++) |
| 3262 | selectors[i] = 0xE0100 + (i - 16); | 3282 | selectors[i] = 0xE0100 + (i - 16); |
| 3263 | mac_font_get_glyphs_for_variants (uvs_table, c, selectors, glyphs, 256); | 3283 | mac_font_get_glyphs_for_variants (uvs_table, c, selectors, glyphs, 256); |
| 3264 | for (i = 0; i < 256; i++) | 3284 | for (i = 0; i < 256; i++) |
| 3265 | { | 3285 | { |
| 3266 | CGGlyph glyph = glyphs[i]; | 3286 | CGGlyph glyph = glyphs[i]; |
| 3267 | 3287 | ||
| 3268 | if (uvs_collection != MAC_CHARACTER_COLLECTION_IDENTITY_MAPPING | 3288 | if (uvs_collection != MAC_CHARACTER_COLLECTION_IDENTITY_MAPPING |
| 3269 | && glyph != kCGFontIndexInvalid) | 3289 | && glyph != kCGFontIndexInvalid) |
| 3270 | glyph = macfont_get_glyph_for_cid (font, uvs_collection, glyph); | 3290 | glyph = macfont_get_glyph_for_cid (font, uvs_collection, glyph); |
| 3271 | if (glyph == kCGFontIndexInvalid) | 3291 | if (glyph == kCGFontIndexInvalid) |
| 3272 | variations[i] = 0; | 3292 | variations[i] = 0; |
| 3273 | else | 3293 | else |
| 3274 | { | 3294 | { |
| 3275 | variations[i] = (glyph ? glyph | 3295 | variations[i] = (glyph ? glyph |
| 3276 | : macfont_get_glyph_for_character (font, c)); | 3296 | : macfont_get_glyph_for_character (font, c)); |
| 3277 | n++; | 3297 | n++; |
| 3278 | } | 3298 | } |
| 3279 | } | 3299 | } |
| 3280 | } | 3300 | } |
| 3281 | unblock_input (); | 3301 | unblock_input (); |
| 3282 | 3302 | ||
| @@ -3304,7 +3324,7 @@ macfont_filter_properties (Lisp_Object font, Lisp_Object alist) | |||
| 3304 | 3324 | ||
| 3305 | static Boolean | 3325 | static Boolean |
| 3306 | mac_ctfont_descriptor_supports_languages (CTFontDescriptorRef descriptor, | 3326 | mac_ctfont_descriptor_supports_languages (CTFontDescriptorRef descriptor, |
| 3307 | CFArrayRef languages) | 3327 | CFArrayRef languages) |
| 3308 | { | 3328 | { |
| 3309 | Boolean result = true; | 3329 | Boolean result = true; |
| 3310 | CFArrayRef desc_languages = | 3330 | CFArrayRef desc_languages = |
| @@ -3319,13 +3339,13 @@ mac_ctfont_descriptor_supports_languages (CTFontDescriptorRef descriptor, | |||
| 3319 | desc_languages_count = CFArrayGetCount (desc_languages); | 3339 | desc_languages_count = CFArrayGetCount (desc_languages); |
| 3320 | languages_count = CFArrayGetCount (languages); | 3340 | languages_count = CFArrayGetCount (languages); |
| 3321 | for (i = 0; i < languages_count; i++) | 3341 | for (i = 0; i < languages_count; i++) |
| 3322 | if (!CFArrayContainsValue (desc_languages, | 3342 | if (!CFArrayContainsValue (desc_languages, |
| 3323 | CFRangeMake (0, desc_languages_count), | 3343 | CFRangeMake (0, desc_languages_count), |
| 3324 | CFArrayGetValueAtIndex (languages, i))) | 3344 | CFArrayGetValueAtIndex (languages, i))) |
| 3325 | { | 3345 | { |
| 3326 | result = false; | 3346 | result = false; |
| 3327 | break; | 3347 | break; |
| 3328 | } | 3348 | } |
| 3329 | CFRelease (desc_languages); | 3349 | CFRelease (desc_languages); |
| 3330 | } | 3350 | } |
| 3331 | 3351 | ||
| @@ -3343,79 +3363,79 @@ mac_ctfont_create_preferred_family_for_attributes (CFDictionaryRef attributes) | |||
| 3343 | { | 3363 | { |
| 3344 | CFStringRef keys[] = { | 3364 | CFStringRef keys[] = { |
| 3345 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 | 3365 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 |
| 3346 | kCTLanguageAttributeName | 3366 | kCTLanguageAttributeName |
| 3347 | #else | 3367 | #else |
| 3348 | CFSTR ("NSLanguage") | 3368 | CFSTR ("NSLanguage") |
| 3349 | #endif | 3369 | #endif |
| 3350 | }; | 3370 | }; |
| 3351 | CFTypeRef values[] = {NULL}; | 3371 | CFTypeRef values[] = {NULL}; |
| 3352 | CFIndex num_values = 0; | 3372 | CFIndex num_values = 0; |
| 3353 | CFArrayRef languages | 3373 | CFArrayRef languages |
| 3354 | = CFDictionaryGetValue (attributes, MAC_FONT_LANGUAGES_ATTRIBUTE); | 3374 | = CFDictionaryGetValue (attributes, MAC_FONT_LANGUAGES_ATTRIBUTE); |
| 3355 | 3375 | ||
| 3356 | if (languages && CFArrayGetCount (languages) > 0) | 3376 | if (languages && CFArrayGetCount (languages) > 0) |
| 3357 | { | 3377 | { |
| 3358 | if (CTGetCoreTextVersion () >= kCTVersionNumber10_9) | 3378 | if (CTGetCoreTextVersion () >= kCTVersionNumber10_9) |
| 3359 | values[num_values++] = CFArrayGetValueAtIndex (languages, 0); | 3379 | values[num_values++] = CFArrayGetValueAtIndex (languages, 0); |
| 3360 | else | 3380 | else |
| 3361 | { | 3381 | { |
| 3362 | CFCharacterSetRef charset = | 3382 | CFCharacterSetRef charset = |
| 3363 | CFDictionaryGetValue (attributes, | 3383 | CFDictionaryGetValue (attributes, |
| 3364 | MAC_FONT_CHARACTER_SET_ATTRIBUTE); | 3384 | MAC_FONT_CHARACTER_SET_ATTRIBUTE); |
| 3365 | 3385 | ||
| 3366 | result = mac_font_copy_default_name_for_charset_and_languages (charset, languages); | 3386 | result = mac_font_copy_default_name_for_charset_and_languages (charset, languages); |
| 3367 | } | 3387 | } |
| 3368 | } | 3388 | } |
| 3369 | if (result == NULL) | 3389 | if (result == NULL) |
| 3370 | { | 3390 | { |
| 3371 | CFAttributedStringRef attr_string = NULL; | 3391 | CFAttributedStringRef attr_string = NULL; |
| 3372 | CTLineRef ctline = NULL; | 3392 | CTLineRef ctline = NULL; |
| 3373 | CFDictionaryRef attrs | 3393 | CFDictionaryRef attrs |
| 3374 | = CFDictionaryCreate (NULL, (const void **) keys, | 3394 | = CFDictionaryCreate (NULL, (const void **) keys, |
| 3375 | (const void **) values, num_values, | 3395 | (const void **) values, num_values, |
| 3376 | &kCFTypeDictionaryKeyCallBacks, | 3396 | &kCFTypeDictionaryKeyCallBacks, |
| 3377 | &kCFTypeDictionaryValueCallBacks); | 3397 | &kCFTypeDictionaryValueCallBacks); |
| 3378 | 3398 | ||
| 3379 | if (attrs) | 3399 | if (attrs) |
| 3380 | { | 3400 | { |
| 3381 | attr_string = CFAttributedStringCreate (NULL, charset_string, | 3401 | attr_string = CFAttributedStringCreate (NULL, charset_string, |
| 3382 | attrs); | 3402 | attrs); |
| 3383 | CFRelease (attrs); | 3403 | CFRelease (attrs); |
| 3384 | } | 3404 | } |
| 3385 | if (attr_string) | 3405 | if (attr_string) |
| 3386 | { | 3406 | { |
| 3387 | ctline = CTLineCreateWithAttributedString (attr_string); | 3407 | ctline = CTLineCreateWithAttributedString (attr_string); |
| 3388 | CFRelease (attr_string); | 3408 | CFRelease (attr_string); |
| 3389 | } | 3409 | } |
| 3390 | if (ctline) | 3410 | if (ctline) |
| 3391 | { | 3411 | { |
| 3392 | CFArrayRef runs = CTLineGetGlyphRuns (ctline); | 3412 | CFArrayRef runs = CTLineGetGlyphRuns (ctline); |
| 3393 | CFIndex i, nruns = CFArrayGetCount (runs); | 3413 | CFIndex i, nruns = CFArrayGetCount (runs); |
| 3394 | CTFontRef font; | 3414 | CTFontRef font; |
| 3395 | 3415 | ||
| 3396 | for (i = 0; i < nruns; i++) | 3416 | for (i = 0; i < nruns; i++) |
| 3397 | { | 3417 | { |
| 3398 | CTRunRef run = CFArrayGetValueAtIndex (runs, i); | 3418 | CTRunRef run = CFArrayGetValueAtIndex (runs, i); |
| 3399 | CFDictionaryRef attributes = CTRunGetAttributes (run); | 3419 | CFDictionaryRef attributes = CTRunGetAttributes (run); |
| 3400 | CTFontRef font_in_run; | 3420 | CTFontRef font_in_run; |
| 3401 | 3421 | ||
| 3402 | if (attributes == NULL) | 3422 | if (attributes == NULL) |
| 3403 | break; | 3423 | break; |
| 3404 | font_in_run = | 3424 | font_in_run = |
| 3405 | CFDictionaryGetValue (attributes, kCTFontAttributeName); | 3425 | CFDictionaryGetValue (attributes, kCTFontAttributeName); |
| 3406 | if (font_in_run == NULL) | 3426 | if (font_in_run == NULL) |
| 3407 | break; | 3427 | break; |
| 3408 | if (i == 0) | 3428 | if (i == 0) |
| 3409 | font = font_in_run; | 3429 | font = font_in_run; |
| 3410 | else if (!mac_ctfont_equal_in_postscript_name (font, | 3430 | else if (!mac_ctfont_equal_in_postscript_name (font, |
| 3411 | font_in_run)) | 3431 | font_in_run)) |
| 3412 | break; | 3432 | break; |
| 3413 | } | 3433 | } |
| 3414 | if (nruns > 0 && i == nruns) | 3434 | if (nruns > 0 && i == nruns) |
| 3415 | result = CTFontCopyAttribute (font, kCTFontFamilyNameAttribute); | 3435 | result = CTFontCopyAttribute (font, kCTFontFamilyNameAttribute); |
| 3416 | CFRelease (ctline); | 3436 | CFRelease (ctline); |
| 3417 | } | 3437 | } |
| 3418 | } | 3438 | } |
| 3419 | } | 3439 | } |
| 3420 | 3440 | ||
| 3421 | return result; | 3441 | return result; |
| @@ -3425,14 +3445,14 @@ static inline double | |||
| 3425 | mac_ctfont_get_advance_width_for_glyph (CTFontRef font, CGGlyph glyph) | 3445 | mac_ctfont_get_advance_width_for_glyph (CTFontRef font, CGGlyph glyph) |
| 3426 | { | 3446 | { |
| 3427 | return CTFontGetAdvancesForGlyphs (font, kCTFontDefaultOrientation, | 3447 | return CTFontGetAdvancesForGlyphs (font, kCTFontDefaultOrientation, |
| 3428 | &glyph, NULL, 1); | 3448 | &glyph, NULL, 1); |
| 3429 | } | 3449 | } |
| 3430 | 3450 | ||
| 3431 | static inline CGRect | 3451 | static inline CGRect |
| 3432 | mac_ctfont_get_bounding_rect_for_glyph (CTFontRef font, CGGlyph glyph) | 3452 | mac_ctfont_get_bounding_rect_for_glyph (CTFontRef font, CGGlyph glyph) |
| 3433 | { | 3453 | { |
| 3434 | return CTFontGetBoundingRectsForGlyphs (font, kCTFontDefaultOrientation, | 3454 | return CTFontGetBoundingRectsForGlyphs (font, kCTFontDefaultOrientation, |
| 3435 | &glyph, NULL, 1); | 3455 | &glyph, NULL, 1); |
| 3436 | } | 3456 | } |
| 3437 | 3457 | ||
| 3438 | static CFArrayRef | 3458 | static CFArrayRef |
| @@ -3448,24 +3468,24 @@ mac_ctfont_create_available_families (void) | |||
| 3448 | CFArrayRef orig_families = CTFontManagerCopyAvailableFontFamilyNames (); | 3468 | CFArrayRef orig_families = CTFontManagerCopyAvailableFontFamilyNames (); |
| 3449 | 3469 | ||
| 3450 | if (orig_families) | 3470 | if (orig_families) |
| 3451 | { | 3471 | { |
| 3452 | CFIndex i, count = CFArrayGetCount (orig_families); | 3472 | CFIndex i, count = CFArrayGetCount (orig_families); |
| 3453 | 3473 | ||
| 3454 | families = CFArrayCreateMutable (NULL, count, &kCFTypeArrayCallBacks); | 3474 | families = CFArrayCreateMutable (NULL, count, &kCFTypeArrayCallBacks); |
| 3455 | if (families) | 3475 | if (families) |
| 3456 | for (i = 0; i < count; i++) | 3476 | for (i = 0; i < count; i++) |
| 3457 | { | 3477 | { |
| 3458 | CFStringRef family = CFArrayGetValueAtIndex (orig_families, i); | 3478 | CFStringRef family = CFArrayGetValueAtIndex (orig_families, i); |
| 3459 | 3479 | ||
| 3460 | if (!CFStringHasPrefix (family, CFSTR (".")) | 3480 | if (!CFStringHasPrefix (family, CFSTR (".")) |
| 3461 | && (CTFontManagerCompareFontFamilyNames (family, | 3481 | && (CTFontManagerCompareFontFamilyNames (family, |
| 3462 | CFSTR ("LastResort"), | 3482 | CFSTR ("LastResort"), |
| 3463 | NULL) | 3483 | NULL) |
| 3464 | != kCFCompareEqualTo)) | 3484 | != kCFCompareEqualTo)) |
| 3465 | CFArrayAppendValue (families, family); | 3485 | CFArrayAppendValue (families, family); |
| 3466 | } | 3486 | } |
| 3467 | CFRelease (orig_families); | 3487 | CFRelease (orig_families); |
| 3468 | } | 3488 | } |
| 3469 | } | 3489 | } |
| 3470 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 | 3490 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 |
| 3471 | else /* CTFontManagerCopyAvailableFontFamilyNames == NULL */ | 3491 | else /* CTFontManagerCopyAvailableFontFamilyNames == NULL */ |
| @@ -3478,41 +3498,41 @@ mac_ctfont_create_available_families (void) | |||
| 3478 | 3498 | ||
| 3479 | collection = CTFontCollectionCreateFromAvailableFonts (NULL); | 3499 | collection = CTFontCollectionCreateFromAvailableFonts (NULL); |
| 3480 | if (collection) | 3500 | if (collection) |
| 3481 | { | 3501 | { |
| 3482 | descs = CTFontCollectionCreateMatchingFontDescriptors (collection); | 3502 | descs = CTFontCollectionCreateMatchingFontDescriptors (collection); |
| 3483 | CFRelease (collection); | 3503 | CFRelease (collection); |
| 3484 | } | 3504 | } |
| 3485 | if (descs) | 3505 | if (descs) |
| 3486 | { | 3506 | { |
| 3487 | CFIndex i, count = CFArrayGetCount (descs); | 3507 | CFIndex i, count = CFArrayGetCount (descs); |
| 3488 | 3508 | ||
| 3489 | families = CFArrayCreateMutable (NULL, count, &kCFTypeArrayCallBacks); | 3509 | families = CFArrayCreateMutable (NULL, count, &kCFTypeArrayCallBacks); |
| 3490 | if (families) | 3510 | if (families) |
| 3491 | for (i = 0; i < count; i++) | 3511 | for (i = 0; i < count; i++) |
| 3492 | { | 3512 | { |
| 3493 | FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, i); | 3513 | FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, i); |
| 3494 | CFStringRef name = | 3514 | CFStringRef name = |
| 3495 | mac_font_descriptor_copy_attribute (desc, | 3515 | mac_font_descriptor_copy_attribute (desc, |
| 3496 | MAC_FONT_FAMILY_NAME_ATTRIBUTE); | 3516 | MAC_FONT_FAMILY_NAME_ATTRIBUTE); |
| 3497 | 3517 | ||
| 3498 | if (name) | 3518 | if (name) |
| 3499 | { | 3519 | { |
| 3500 | CFIndex p, limit = CFArrayGetCount (families); | 3520 | CFIndex p, limit = CFArrayGetCount (families); |
| 3501 | 3521 | ||
| 3502 | p = CFArrayBSearchValues (families, CFRangeMake (0, limit), | 3522 | p = CFArrayBSearchValues (families, CFRangeMake (0, limit), |
| 3503 | (const void *) name, | 3523 | (const void *) name, |
| 3504 | mac_font_family_compare, NULL); | 3524 | mac_font_family_compare, NULL); |
| 3505 | if (p >= limit) | 3525 | if (p >= limit) |
| 3506 | CFArrayAppendValue (families, name); | 3526 | CFArrayAppendValue (families, name); |
| 3507 | else if (mac_font_family_compare | 3527 | else if (mac_font_family_compare |
| 3508 | (CFArrayGetValueAtIndex (families, p), | 3528 | (CFArrayGetValueAtIndex (families, p), |
| 3509 | name, NULL) != kCFCompareEqualTo) | 3529 | name, NULL) != kCFCompareEqualTo) |
| 3510 | CFArrayInsertValueAtIndex (families, p, name); | 3530 | CFArrayInsertValueAtIndex (families, p, name); |
| 3511 | CFRelease (name); | 3531 | CFRelease (name); |
| 3512 | } | 3532 | } |
| 3513 | } | 3533 | } |
| 3514 | CFRelease (descs); | 3534 | CFRelease (descs); |
| 3515 | } | 3535 | } |
| 3516 | } | 3536 | } |
| 3517 | #endif | 3537 | #endif |
| 3518 | 3538 | ||
| @@ -3534,10 +3554,10 @@ mac_ctfont_equal_in_postscript_name (CTFontRef font1, CTFontRef font2) | |||
| 3534 | { | 3554 | { |
| 3535 | name2 = CTFontCopyPostScriptName (font2); | 3555 | name2 = CTFontCopyPostScriptName (font2); |
| 3536 | if (name2) | 3556 | if (name2) |
| 3537 | { | 3557 | { |
| 3538 | result = CFEqual (name1, name2); | 3558 | result = CFEqual (name1, name2); |
| 3539 | CFRelease (name2); | 3559 | CFRelease (name2); |
| 3540 | } | 3560 | } |
| 3541 | CFRelease (name1); | 3561 | CFRelease (name1); |
| 3542 | } | 3562 | } |
| 3543 | 3563 | ||
| @@ -3546,7 +3566,7 @@ mac_ctfont_equal_in_postscript_name (CTFontRef font1, CTFontRef font2) | |||
| 3546 | 3566 | ||
| 3547 | static CTLineRef | 3567 | static CTLineRef |
| 3548 | mac_ctfont_create_line_with_string_and_font (CFStringRef string, | 3568 | mac_ctfont_create_line_with_string_and_font (CFStringRef string, |
| 3549 | CTFontRef macfont) | 3569 | CTFontRef macfont) |
| 3550 | { | 3570 | { |
| 3551 | CFStringRef keys[] = {kCTFontAttributeName, kCTKernAttributeName}; | 3571 | CFStringRef keys[] = {kCTFontAttributeName, kCTKernAttributeName}; |
| 3552 | CFTypeRef values[] = {NULL, NULL}; | 3572 | CFTypeRef values[] = {NULL, NULL}; |
| @@ -3560,10 +3580,10 @@ mac_ctfont_create_line_with_string_and_font (CFStringRef string, | |||
| 3560 | if (values[1]) | 3580 | if (values[1]) |
| 3561 | { | 3581 | { |
| 3562 | attributes = CFDictionaryCreate (NULL, (const void **) keys, | 3582 | attributes = CFDictionaryCreate (NULL, (const void **) keys, |
| 3563 | (const void **) values, | 3583 | (const void **) values, |
| 3564 | ARRAYELTS (keys), | 3584 | ARRAYELTS (keys), |
| 3565 | &kCFTypeDictionaryKeyCallBacks, | 3585 | &kCFTypeDictionaryKeyCallBacks, |
| 3566 | &kCFTypeDictionaryValueCallBacks); | 3586 | &kCFTypeDictionaryValueCallBacks); |
| 3567 | CFRelease (values[1]); | 3587 | CFRelease (values[1]); |
| 3568 | } | 3588 | } |
| 3569 | if (attributes) | 3589 | if (attributes) |
| @@ -3579,30 +3599,30 @@ mac_ctfont_create_line_with_string_and_font (CFStringRef string, | |||
| 3579 | if (ctline) | 3599 | if (ctline) |
| 3580 | { | 3600 | { |
| 3581 | /* Abandon if ctline contains some fonts other than the | 3601 | /* Abandon if ctline contains some fonts other than the |
| 3582 | specified one. */ | 3602 | specified one. */ |
| 3583 | CFArrayRef runs = CTLineGetGlyphRuns (ctline); | 3603 | CFArrayRef runs = CTLineGetGlyphRuns (ctline); |
| 3584 | CFIndex i, nruns = CFArrayGetCount (runs); | 3604 | CFIndex i, nruns = CFArrayGetCount (runs); |
| 3585 | 3605 | ||
| 3586 | for (i = 0; i < nruns; i++) | 3606 | for (i = 0; i < nruns; i++) |
| 3587 | { | 3607 | { |
| 3588 | CTRunRef run = CFArrayGetValueAtIndex (runs, i); | 3608 | CTRunRef run = CFArrayGetValueAtIndex (runs, i); |
| 3589 | CFDictionaryRef attributes = CTRunGetAttributes (run); | 3609 | CFDictionaryRef attributes = CTRunGetAttributes (run); |
| 3590 | CTFontRef font_in_run; | 3610 | CTFontRef font_in_run; |
| 3591 | 3611 | ||
| 3592 | if (attributes == NULL) | 3612 | if (attributes == NULL) |
| 3593 | break; | 3613 | break; |
| 3594 | font_in_run = | 3614 | font_in_run = |
| 3595 | CFDictionaryGetValue (attributes, kCTFontAttributeName); | 3615 | CFDictionaryGetValue (attributes, kCTFontAttributeName); |
| 3596 | if (font_in_run == NULL) | 3616 | if (font_in_run == NULL) |
| 3597 | break; | 3617 | break; |
| 3598 | if (!mac_ctfont_equal_in_postscript_name (macfont, font_in_run)) | 3618 | if (!mac_ctfont_equal_in_postscript_name (macfont, font_in_run)) |
| 3599 | break; | 3619 | break; |
| 3600 | } | 3620 | } |
| 3601 | if (i < nruns) | 3621 | if (i < nruns) |
| 3602 | { | 3622 | { |
| 3603 | CFRelease (ctline); | 3623 | CFRelease (ctline); |
| 3604 | ctline = NULL; | 3624 | ctline = NULL; |
| 3605 | } | 3625 | } |
| 3606 | } | 3626 | } |
| 3607 | 3627 | ||
| 3608 | return ctline; | 3628 | return ctline; |
| @@ -3610,7 +3630,7 @@ mac_ctfont_create_line_with_string_and_font (CFStringRef string, | |||
| 3610 | 3630 | ||
| 3611 | static CFIndex | 3631 | static CFIndex |
| 3612 | mac_ctfont_shape (CTFontRef font, CFStringRef string, | 3632 | mac_ctfont_shape (CTFontRef font, CFStringRef string, |
| 3613 | struct mac_glyph_layout *glyph_layouts, CFIndex glyph_len) | 3633 | struct mac_glyph_layout *glyph_layouts, CFIndex glyph_len) |
| 3614 | { | 3634 | { |
| 3615 | CFIndex used, result = 0; | 3635 | CFIndex used, result = 0; |
| 3616 | CTLineRef ctline = mac_ctfont_create_line_with_string_and_font (string, font); | 3636 | CTLineRef ctline = mac_ctfont_create_line_with_string_and_font (string, font); |
| @@ -3627,128 +3647,128 @@ mac_ctfont_shape (CTFontRef font, CFStringRef string, | |||
| 3627 | CFIndex total_glyph_count = 0; | 3647 | CFIndex total_glyph_count = 0; |
| 3628 | 3648 | ||
| 3629 | for (k = 0; k < ctrun_count; k++) | 3649 | for (k = 0; k < ctrun_count; k++) |
| 3630 | { | 3650 | { |
| 3631 | CTRunRef ctrun = CFArrayGetValueAtIndex (ctruns, k); | 3651 | CTRunRef ctrun = CFArrayGetValueAtIndex (ctruns, k); |
| 3632 | CFIndex i, min_location, glyph_count = CTRunGetGlyphCount (ctrun); | 3652 | CFIndex i, min_location, glyph_count = CTRunGetGlyphCount (ctrun); |
| 3633 | struct mac_glyph_layout *glbuf = glyph_layouts + total_glyph_count; | 3653 | struct mac_glyph_layout *glbuf = glyph_layouts + total_glyph_count; |
| 3634 | CFRange string_range, comp_range, range; | 3654 | CFRange string_range, comp_range, range; |
| 3635 | CFIndex *permutation; | 3655 | CFIndex *permutation; |
| 3636 | 3656 | ||
| 3637 | if (CTRunGetStatus (ctrun) & kCTRunStatusRightToLeft) | 3657 | if (CTRunGetStatus (ctrun) & kCTRunStatusRightToLeft) |
| 3638 | permutation = xmalloc (sizeof (CFIndex) * glyph_count); | 3658 | permutation = xmalloc (sizeof (CFIndex) * glyph_count); |
| 3639 | else | 3659 | else |
| 3640 | permutation = NULL; | 3660 | permutation = NULL; |
| 3641 | 3661 | ||
| 3642 | #define RIGHT_TO_LEFT_P permutation | 3662 | #define RIGHT_TO_LEFT_P permutation |
| 3643 | 3663 | ||
| 3644 | /* Now the `comp_range' member of struct mac_glyph_layout is | 3664 | /* Now the `comp_range' member of struct mac_glyph_layout is |
| 3645 | temporarily used as a work area such that: | 3665 | temporarily used as a work area such that: |
| 3646 | glbuf[i].comp_range.location = | 3666 | glbuf[i].comp_range.location = |
| 3647 | min {compRange[i + 1].location, ..., | 3667 | min {compRange[i + 1].location, ..., |
| 3648 | compRange[glyph_count - 1].location, | 3668 | compRange[glyph_count - 1].location, |
| 3649 | maxRange (stringRangeForCTRun)} | 3669 | maxRange (stringRangeForCTRun)} |
| 3650 | glbuf[i].comp_range.length = maxRange (compRange[i]) | 3670 | glbuf[i].comp_range.length = maxRange (compRange[i]) |
| 3651 | where compRange[i] is the range of composed characters | 3671 | where compRange[i] is the range of composed characters |
| 3652 | containing i-th glyph. */ | 3672 | containing i-th glyph. */ |
| 3653 | string_range = CTRunGetStringRange (ctrun); | 3673 | string_range = CTRunGetStringRange (ctrun); |
| 3654 | min_location = string_range.location + string_range.length; | 3674 | min_location = string_range.location + string_range.length; |
| 3655 | for (i = 0; i < glyph_count; i++) | 3675 | for (i = 0; i < glyph_count; i++) |
| 3656 | { | 3676 | { |
| 3657 | struct mac_glyph_layout *gl = glbuf + glyph_count - i - 1; | 3677 | struct mac_glyph_layout *gl = glbuf + glyph_count - i - 1; |
| 3658 | CFIndex glyph_index; | 3678 | CFIndex glyph_index; |
| 3659 | CFRange rng; | 3679 | CFRange rng; |
| 3660 | 3680 | ||
| 3661 | if (!RIGHT_TO_LEFT_P) | 3681 | if (!RIGHT_TO_LEFT_P) |
| 3662 | glyph_index = glyph_count - i - 1; | 3682 | glyph_index = glyph_count - i - 1; |
| 3663 | else | 3683 | else |
| 3664 | glyph_index = i; | 3684 | glyph_index = i; |
| 3665 | CTRunGetStringIndices (ctrun, CFRangeMake (glyph_index, 1), | 3685 | CTRunGetStringIndices (ctrun, CFRangeMake (glyph_index, 1), |
| 3666 | &gl->string_index); | 3686 | &gl->string_index); |
| 3667 | rng = | 3687 | rng = |
| 3668 | CFStringGetRangeOfComposedCharactersAtIndex (string, | 3688 | CFStringGetRangeOfComposedCharactersAtIndex (string, |
| 3669 | gl->string_index); | 3689 | gl->string_index); |
| 3670 | gl->comp_range.location = min_location; | 3690 | gl->comp_range.location = min_location; |
| 3671 | gl->comp_range.length = rng.location + rng.length; | 3691 | gl->comp_range.length = rng.location + rng.length; |
| 3672 | if (rng.location < min_location) | 3692 | if (rng.location < min_location) |
| 3673 | min_location = rng.location; | 3693 | min_location = rng.location; |
| 3674 | } | 3694 | } |
| 3675 | 3695 | ||
| 3676 | /* Fill the `comp_range' member of struct mac_glyph_layout, | 3696 | /* Fill the `comp_range' member of struct mac_glyph_layout, |
| 3677 | and setup a permutation for right-to-left text. */ | 3697 | and setup a permutation for right-to-left text. */ |
| 3678 | comp_range = CFRangeMake (string_range.location, 0); | 3698 | comp_range = CFRangeMake (string_range.location, 0); |
| 3679 | range = CFRangeMake (0, 0); | 3699 | range = CFRangeMake (0, 0); |
| 3680 | while (1) | 3700 | while (1) |
| 3681 | { | 3701 | { |
| 3682 | struct mac_glyph_layout *gl = | 3702 | struct mac_glyph_layout *gl = |
| 3683 | glbuf + range.location + range.length; | 3703 | glbuf + range.location + range.length; |
| 3684 | 3704 | ||
| 3685 | if (gl->comp_range.length | 3705 | if (gl->comp_range.length |
| 3686 | > comp_range.location + comp_range.length) | 3706 | > comp_range.location + comp_range.length) |
| 3687 | comp_range.length = gl->comp_range.length - comp_range.location; | 3707 | comp_range.length = gl->comp_range.length - comp_range.location; |
| 3688 | min_location = gl->comp_range.location; | 3708 | min_location = gl->comp_range.location; |
| 3689 | range.length++; | 3709 | range.length++; |
| 3690 | 3710 | ||
| 3691 | if (min_location >= comp_range.location + comp_range.length) | 3711 | if (min_location >= comp_range.location + comp_range.length) |
| 3692 | { | 3712 | { |
| 3693 | comp_range.length = min_location - comp_range.location; | 3713 | comp_range.length = min_location - comp_range.location; |
| 3694 | for (i = 0; i < range.length; i++) | 3714 | for (i = 0; i < range.length; i++) |
| 3695 | { | 3715 | { |
| 3696 | glbuf[range.location + i].comp_range = comp_range; | 3716 | glbuf[range.location + i].comp_range = comp_range; |
| 3697 | if (RIGHT_TO_LEFT_P) | 3717 | if (RIGHT_TO_LEFT_P) |
| 3698 | permutation[range.location + i] = | 3718 | permutation[range.location + i] = |
| 3699 | range.location + range.length - i - 1; | 3719 | range.location + range.length - i - 1; |
| 3700 | } | 3720 | } |
| 3701 | 3721 | ||
| 3702 | comp_range = CFRangeMake (min_location, 0); | 3722 | comp_range = CFRangeMake (min_location, 0); |
| 3703 | range.location += range.length; | 3723 | range.location += range.length; |
| 3704 | range.length = 0; | 3724 | range.length = 0; |
| 3705 | if (range.location == glyph_count) | 3725 | if (range.location == glyph_count) |
| 3706 | break; | 3726 | break; |
| 3707 | } | 3727 | } |
| 3708 | } | 3728 | } |
| 3709 | 3729 | ||
| 3710 | /* Then fill the remaining members. */ | 3730 | /* Then fill the remaining members. */ |
| 3711 | for (range = CFRangeMake (0, 1); range.location < glyph_count; | 3731 | for (range = CFRangeMake (0, 1); range.location < glyph_count; |
| 3712 | range.location++) | 3732 | range.location++) |
| 3713 | { | 3733 | { |
| 3714 | struct mac_glyph_layout *gl; | 3734 | struct mac_glyph_layout *gl; |
| 3715 | CGPoint position; | 3735 | CGPoint position; |
| 3716 | 3736 | ||
| 3717 | if (!RIGHT_TO_LEFT_P) | 3737 | if (!RIGHT_TO_LEFT_P) |
| 3718 | gl = glbuf + range.location; | 3738 | gl = glbuf + range.location; |
| 3719 | else | 3739 | else |
| 3720 | { | 3740 | { |
| 3721 | CFIndex src, dest; | 3741 | CFIndex src, dest; |
| 3722 | 3742 | ||
| 3723 | src = glyph_count - 1 - range.location; | 3743 | src = glyph_count - 1 - range.location; |
| 3724 | dest = permutation[src]; | 3744 | dest = permutation[src]; |
| 3725 | gl = glbuf + dest; | 3745 | gl = glbuf + dest; |
| 3726 | if (src < dest) | 3746 | if (src < dest) |
| 3727 | { | 3747 | { |
| 3728 | CFIndex tmp = gl->string_index; | 3748 | CFIndex tmp = gl->string_index; |
| 3729 | 3749 | ||
| 3730 | gl->string_index = glbuf[src].string_index; | 3750 | gl->string_index = glbuf[src].string_index; |
| 3731 | glbuf[src].string_index = tmp; | 3751 | glbuf[src].string_index = tmp; |
| 3732 | } | 3752 | } |
| 3733 | } | 3753 | } |
| 3734 | CTRunGetGlyphs (ctrun, range, &gl->glyph_id); | 3754 | CTRunGetGlyphs (ctrun, range, &gl->glyph_id); |
| 3735 | 3755 | ||
| 3736 | CTRunGetPositions (ctrun, range, &position); | 3756 | CTRunGetPositions (ctrun, range, &position); |
| 3737 | gl->advance_delta = position.x - total_advance; | 3757 | gl->advance_delta = position.x - total_advance; |
| 3738 | gl->baseline_delta = position.y; | 3758 | gl->baseline_delta = position.y; |
| 3739 | gl->advance = (gl->advance_delta | 3759 | gl->advance = (gl->advance_delta |
| 3740 | + CTRunGetTypographicBounds (ctrun, range, | 3760 | + CTRunGetTypographicBounds (ctrun, range, |
| 3741 | NULL, NULL, NULL)); | 3761 | NULL, NULL, NULL)); |
| 3742 | total_advance += gl->advance; | 3762 | total_advance += gl->advance; |
| 3743 | } | 3763 | } |
| 3744 | 3764 | ||
| 3745 | if (RIGHT_TO_LEFT_P) | 3765 | if (RIGHT_TO_LEFT_P) |
| 3746 | xfree (permutation); | 3766 | xfree (permutation); |
| 3747 | 3767 | ||
| 3748 | #undef RIGHT_TO_LEFT_P | 3768 | #undef RIGHT_TO_LEFT_P |
| 3749 | 3769 | ||
| 3750 | total_glyph_count += glyph_count; | 3770 | total_glyph_count += glyph_count; |
| 3751 | } | 3771 | } |
| 3752 | 3772 | ||
| 3753 | result = used; | 3773 | result = used; |
| 3754 | } | 3774 | } |
| @@ -3763,7 +3783,7 @@ mac_ctfont_shape (CTFontRef font, CFStringRef string, | |||
| 3763 | #if USE_CT_GLYPH_INFO | 3783 | #if USE_CT_GLYPH_INFO |
| 3764 | static CGGlyph | 3784 | static CGGlyph |
| 3765 | mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection, | 3785 | mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection, |
| 3766 | CGFontIndex cid) | 3786 | CGFontIndex cid) |
| 3767 | { | 3787 | { |
| 3768 | CGGlyph result = kCGFontIndexInvalid; | 3788 | CGGlyph result = kCGFontIndexInvalid; |
| 3769 | UniChar characters[] = {0xfffd}; | 3789 | UniChar characters[] = {0xfffd}; |
| @@ -3777,27 +3797,27 @@ mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection, | |||
| 3777 | if (string) | 3797 | if (string) |
| 3778 | { | 3798 | { |
| 3779 | CTGlyphInfoRef glyph_info = | 3799 | CTGlyphInfoRef glyph_info = |
| 3780 | CTGlyphInfoCreateWithCharacterIdentifier (cid, collection, string); | 3800 | CTGlyphInfoCreateWithCharacterIdentifier (cid, collection, string); |
| 3781 | CFDictionaryRef attributes = NULL; | 3801 | CFDictionaryRef attributes = NULL; |
| 3782 | 3802 | ||
| 3783 | if (glyph_info) | 3803 | if (glyph_info) |
| 3784 | { | 3804 | { |
| 3785 | CFStringRef keys[] = {kCTFontAttributeName, | 3805 | CFStringRef keys[] = {kCTFontAttributeName, |
| 3786 | kCTGlyphInfoAttributeName}; | 3806 | kCTGlyphInfoAttributeName}; |
| 3787 | CFTypeRef values[] = {font, glyph_info}; | 3807 | CFTypeRef values[] = {font, glyph_info}; |
| 3788 | 3808 | ||
| 3789 | attributes = CFDictionaryCreate (NULL, (const void **) keys, | 3809 | attributes = CFDictionaryCreate (NULL, (const void **) keys, |
| 3790 | (const void **) values, | 3810 | (const void **) values, |
| 3791 | ARRAYELTS (keys), | 3811 | ARRAYELTS (keys), |
| 3792 | &kCFTypeDictionaryKeyCallBacks, | 3812 | &kCFTypeDictionaryKeyCallBacks, |
| 3793 | &kCFTypeDictionaryValueCallBacks); | 3813 | &kCFTypeDictionaryValueCallBacks); |
| 3794 | CFRelease (glyph_info); | 3814 | CFRelease (glyph_info); |
| 3795 | } | 3815 | } |
| 3796 | if (attributes) | 3816 | if (attributes) |
| 3797 | { | 3817 | { |
| 3798 | attr_string = CFAttributedStringCreate (NULL, string, attributes); | 3818 | attr_string = CFAttributedStringCreate (NULL, string, attributes); |
| 3799 | CFRelease (attributes); | 3819 | CFRelease (attributes); |
| 3800 | } | 3820 | } |
| 3801 | CFRelease (string); | 3821 | CFRelease (string); |
| 3802 | } | 3822 | } |
| 3803 | if (attr_string) | 3823 | if (attr_string) |
| @@ -3810,24 +3830,24 @@ mac_ctfont_get_glyph_for_cid (CTFontRef font, CTCharacterCollection collection, | |||
| 3810 | CFArrayRef runs = CTLineGetGlyphRuns (ctline); | 3830 | CFArrayRef runs = CTLineGetGlyphRuns (ctline); |
| 3811 | 3831 | ||
| 3812 | if (CFArrayGetCount (runs) > 0) | 3832 | if (CFArrayGetCount (runs) > 0) |
| 3813 | { | 3833 | { |
| 3814 | CTRunRef run = CFArrayGetValueAtIndex (runs, 0); | 3834 | CTRunRef run = CFArrayGetValueAtIndex (runs, 0); |
| 3815 | CFDictionaryRef attributes = CTRunGetAttributes (run); | 3835 | CFDictionaryRef attributes = CTRunGetAttributes (run); |
| 3816 | 3836 | ||
| 3817 | if (attributes) | 3837 | if (attributes) |
| 3818 | { | 3838 | { |
| 3819 | CTFontRef font_in_run = | 3839 | CTFontRef font_in_run = |
| 3820 | CFDictionaryGetValue (attributes, kCTFontAttributeName); | 3840 | CFDictionaryGetValue (attributes, kCTFontAttributeName); |
| 3821 | 3841 | ||
| 3822 | if (font_in_run | 3842 | if (font_in_run |
| 3823 | && mac_ctfont_equal_in_postscript_name (font_in_run, font)) | 3843 | && mac_ctfont_equal_in_postscript_name (font_in_run, font)) |
| 3824 | { | 3844 | { |
| 3825 | CTRunGetGlyphs (run, CFRangeMake (0, 1), &result); | 3845 | CTRunGetGlyphs (run, CFRangeMake (0, 1), &result); |
| 3826 | if (result >= CTFontGetGlyphCount (font)) | 3846 | if (result >= CTFontGetGlyphCount (font)) |
| 3827 | result = kCGFontIndexInvalid; | 3847 | result = kCGFontIndexInvalid; |
| 3828 | } | 3848 | } |
| 3829 | } | 3849 | } |
| 3830 | } | 3850 | } |
| 3831 | CFRelease (ctline); | 3851 | CFRelease (ctline); |
| 3832 | } | 3852 | } |
| 3833 | 3853 | ||
| @@ -3846,9 +3866,9 @@ mac_font_family_group (CFStringRef family) | |||
| 3846 | CFRange range; | 3866 | CFRange range; |
| 3847 | 3867 | ||
| 3848 | range = CFStringFind (family, CFSTR ("Apple"), | 3868 | range = CFStringFind (family, CFSTR ("Apple"), |
| 3849 | kCFCompareCaseInsensitive | kCFCompareAnchored); | 3869 | kCFCompareCaseInsensitive | kCFCompareAnchored); |
| 3850 | if (range.location != kCFNotFound) | 3870 | if (range.location != kCFNotFound) |
| 3851 | return 1; | 3871 | return 1; |
| 3852 | 3872 | ||
| 3853 | return 0; | 3873 | return 0; |
| 3854 | } | 3874 | } |
| @@ -3881,22 +3901,22 @@ mac_font_copy_default_descriptors_for_language (CFStringRef language) | |||
| 3881 | #endif | 3901 | #endif |
| 3882 | { | 3902 | { |
| 3883 | CTFontRef user_font = | 3903 | CTFontRef user_font = |
| 3884 | CTFontCreateUIFontForLanguage (kCTFontUserFontType, 0, language); | 3904 | CTFontCreateUIFontForLanguage (kCTFontUserFontType, 0, language); |
| 3885 | 3905 | ||
| 3886 | if (user_font) | 3906 | if (user_font) |
| 3887 | { | 3907 | { |
| 3888 | CFArrayRef languages = | 3908 | CFArrayRef languages = |
| 3889 | CFArrayCreate (NULL, (const void **) &language, 1, | 3909 | CFArrayCreate (NULL, (const void **) &language, 1, |
| 3890 | &kCFTypeArrayCallBacks); | 3910 | &kCFTypeArrayCallBacks); |
| 3891 | 3911 | ||
| 3892 | if (languages) | 3912 | if (languages) |
| 3893 | { | 3913 | { |
| 3894 | result = CTFontCopyDefaultCascadeListForLanguages (user_font, | 3914 | result = CTFontCopyDefaultCascadeListForLanguages (user_font, |
| 3895 | languages); | 3915 | languages); |
| 3896 | CFRelease (languages); | 3916 | CFRelease (languages); |
| 3897 | } | 3917 | } |
| 3898 | CFRelease (user_font); | 3918 | CFRelease (user_font); |
| 3899 | } | 3919 | } |
| 3900 | } | 3920 | } |
| 3901 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 | 3921 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 |
| 3902 | else /* CTFontCopyDefaultCascadeListForLanguages == NULL */ | 3922 | else /* CTFontCopyDefaultCascadeListForLanguages == NULL */ |
| @@ -3907,55 +3927,55 @@ mac_font_copy_default_descriptors_for_language (CFStringRef language) | |||
| 3907 | CFIndex i; | 3927 | CFIndex i; |
| 3908 | 3928 | ||
| 3909 | for (i = 0; macfont_language_default_font_names[i].language; i++) | 3929 | for (i = 0; macfont_language_default_font_names[i].language; i++) |
| 3910 | { | 3930 | { |
| 3911 | if (CFEqual (macfont_language_default_font_names[i].language, | 3931 | if (CFEqual (macfont_language_default_font_names[i].language, |
| 3912 | language)) | 3932 | language)) |
| 3913 | { | 3933 | { |
| 3914 | CFMutableArrayRef descriptors = | 3934 | CFMutableArrayRef descriptors = |
| 3915 | CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks); | 3935 | CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks); |
| 3916 | 3936 | ||
| 3917 | if (descriptors) | 3937 | if (descriptors) |
| 3918 | { | 3938 | { |
| 3919 | CFIndex j; | 3939 | CFIndex j; |
| 3920 | 3940 | ||
| 3921 | for (j = 0; | 3941 | for (j = 0; |
| 3922 | macfont_language_default_font_names[i].font_names[j]; | 3942 | macfont_language_default_font_names[i].font_names[j]; |
| 3923 | j++) | 3943 | j++) |
| 3924 | { | 3944 | { |
| 3925 | CFDictionaryRef attributes = | 3945 | CFDictionaryRef attributes = |
| 3926 | CFDictionaryCreate (NULL, | 3946 | CFDictionaryCreate (NULL, |
| 3927 | ((const void **) | 3947 | ((const void **) |
| 3928 | &MAC_FONT_NAME_ATTRIBUTE), | 3948 | &MAC_FONT_NAME_ATTRIBUTE), |
| 3929 | ((const void **) | 3949 | ((const void **) |
| 3930 | &macfont_language_default_font_names[i].font_names[j]), | 3950 | &macfont_language_default_font_names[i].font_names[j]), |
| 3931 | 1, &kCFTypeDictionaryKeyCallBacks, | 3951 | 1, &kCFTypeDictionaryKeyCallBacks, |
| 3932 | &kCFTypeDictionaryValueCallBacks); | 3952 | &kCFTypeDictionaryValueCallBacks); |
| 3933 | 3953 | ||
| 3934 | if (attributes) | 3954 | if (attributes) |
| 3935 | { | 3955 | { |
| 3936 | FontDescriptorRef pat_desc = | 3956 | FontDescriptorRef pat_desc = |
| 3937 | mac_font_descriptor_create_with_attributes (attributes); | 3957 | mac_font_descriptor_create_with_attributes (attributes); |
| 3938 | 3958 | ||
| 3939 | if (pat_desc) | 3959 | if (pat_desc) |
| 3940 | { | 3960 | { |
| 3941 | FontDescriptorRef descriptor = | 3961 | FontDescriptorRef descriptor = |
| 3942 | mac_font_descriptor_create_matching_font_descriptor (pat_desc, NULL); | 3962 | mac_font_descriptor_create_matching_font_descriptor (pat_desc, NULL); |
| 3943 | 3963 | ||
| 3944 | if (descriptor) | 3964 | if (descriptor) |
| 3945 | { | 3965 | { |
| 3946 | CFArrayAppendValue (descriptors, descriptor); | 3966 | CFArrayAppendValue (descriptors, descriptor); |
| 3947 | CFRelease (descriptor); | 3967 | CFRelease (descriptor); |
| 3948 | } | 3968 | } |
| 3949 | CFRelease (pat_desc); | 3969 | CFRelease (pat_desc); |
| 3950 | } | 3970 | } |
| 3951 | CFRelease (attributes); | 3971 | CFRelease (attributes); |
| 3952 | } | 3972 | } |
| 3953 | } | 3973 | } |
| 3954 | result = descriptors; | 3974 | result = descriptors; |
| 3955 | } | 3975 | } |
| 3956 | break; | 3976 | break; |
| 3957 | } | 3977 | } |
| 3958 | } | 3978 | } |
| 3959 | } | 3979 | } |
| 3960 | #endif | 3980 | #endif |
| 3961 | 3981 | ||
| @@ -3964,7 +3984,7 @@ mac_font_copy_default_descriptors_for_language (CFStringRef language) | |||
| 3964 | 3984 | ||
| 3965 | static CFStringRef | 3985 | static CFStringRef |
| 3966 | mac_font_copy_default_name_for_charset_and_languages (CFCharacterSetRef charset, | 3986 | mac_font_copy_default_name_for_charset_and_languages (CFCharacterSetRef charset, |
| 3967 | CFArrayRef languages) | 3987 | CFArrayRef languages) |
| 3968 | { | 3988 | { |
| 3969 | CFStringRef result = NULL; | 3989 | CFStringRef result = NULL; |
| 3970 | CFStringRef language = CFArrayGetValueAtIndex (languages, 0); | 3990 | CFStringRef language = CFArrayGetValueAtIndex (languages, 0); |
| @@ -3976,29 +3996,29 @@ mac_font_copy_default_name_for_charset_and_languages (CFCharacterSetRef charset, | |||
| 3976 | CFIndex i, count = CFArrayGetCount (descriptors); | 3996 | CFIndex i, count = CFArrayGetCount (descriptors); |
| 3977 | 3997 | ||
| 3978 | for (i = 0; i < count; i++) | 3998 | for (i = 0; i < count; i++) |
| 3979 | { | 3999 | { |
| 3980 | FontDescriptorRef descriptor = | 4000 | FontDescriptorRef descriptor = |
| 3981 | CFArrayGetValueAtIndex (descriptors, i); | 4001 | CFArrayGetValueAtIndex (descriptors, i); |
| 3982 | 4002 | ||
| 3983 | if (macfont_supports_charset_and_languages_p (descriptor, charset, | 4003 | if (macfont_supports_charset_and_languages_p (descriptor, charset, |
| 3984 | Qnil, languages)) | 4004 | Qnil, languages)) |
| 3985 | { | 4005 | { |
| 3986 | CFStringRef family = | 4006 | CFStringRef family = |
| 3987 | mac_font_descriptor_copy_attribute (descriptor, | 4007 | mac_font_descriptor_copy_attribute (descriptor, |
| 3988 | MAC_FONT_FAMILY_NAME_ATTRIBUTE); | 4008 | MAC_FONT_FAMILY_NAME_ATTRIBUTE); |
| 3989 | if (family) | 4009 | if (family) |
| 3990 | { | 4010 | { |
| 3991 | if (!CFStringHasPrefix (family, CFSTR (".")) | 4011 | if (!CFStringHasPrefix (family, CFSTR (".")) |
| 3992 | && !CFEqual (family, CFSTR ("LastResort"))) | 4012 | && !CFEqual (family, CFSTR ("LastResort"))) |
| 3993 | { | 4013 | { |
| 3994 | result = family; | 4014 | result = family; |
| 3995 | break; | 4015 | break; |
| 3996 | } | 4016 | } |
| 3997 | else | 4017 | else |
| 3998 | CFRelease (family); | 4018 | CFRelease (family); |
| 3999 | } | 4019 | } |
| 4000 | } | 4020 | } |
| 4001 | } | 4021 | } |
| 4002 | CFRelease (descriptors); | 4022 | CFRelease (descriptors); |
| 4003 | } | 4023 | } |
| 4004 | 4024 | ||