- range.length++)
- {
- struct mac_glyph_layout *gl = glyph_layouts + NSMaxRange (range);
- NSUInteger characterIndex =
- [layoutManager characterIndexForGlyphAtIndex:glyphIndex];
-
- gl->string_index = characterIndex;
-
- if (characterIndex >= NSMaxRange (compRange))
- {
- compRange.location = NSMaxRange (compRange);
- do
- {
- NSRange characterRange =
- [string
- rangeOfComposedCharacterSequenceAtIndex:characterIndex];
-
- compRange.length =
- NSMaxRange (characterRange) - compRange.location;
- [layoutManager glyphRangeForCharacterRange:compRange
- actualCharacterRange:&characterRange];
- characterIndex = NSMaxRange (characterRange) - 1;
- }
- while (characterIndex >= NSMaxRange (compRange));
-
- if (RIGHT_TO_LEFT_P)
- for (i = 0; i < range.length; i++)
- permutation[range.location + i] = NSMaxRange (range) - i - 1;
-
- range = NSMakeRange (NSMaxRange (range), 0);
- }
-
- gl->comp_range.location = compRange.location;
- gl->comp_range.length = compRange.length;
-
- while (++glyphIndex < numberOfGlyphs)
- if (![layoutManager notShownAttributeForGlyphAtIndex:glyphIndex])
- break;
- }
+ range.length++)
+ {
+ struct mac_glyph_layout *gl = glyph_layouts + NSMaxRange (range);
+ NSUInteger characterIndex =
+ [layoutManager characterIndexForGlyphAtIndex:glyphIndex];
+
+ gl->string_index = characterIndex;
+
+ if (characterIndex >= NSMaxRange (compRange))
+ {
+ compRange.location = NSMaxRange (compRange);
+ do
+ {
+ NSRange characterRange =
+ [string
+ rangeOfComposedCharacterSequenceAtIndex:characterIndex];
+
+ compRange.length =
+ NSMaxRange (characterRange) - compRange.location;
+ [layoutManager glyphRangeForCharacterRange:compRange
+ actualCharacterRange:&characterRange];
+ characterIndex = NSMaxRange (characterRange) - 1;
+ }
+ while (characterIndex >= NSMaxRange (compRange));
+
+ if (RIGHT_TO_LEFT_P)
+ for (i = 0; i < range.length; i++)
+ permutation[range.location + i] = NSMaxRange (range) - i - 1;
+
+ range = NSMakeRange (NSMaxRange (range), 0);
+ }
+
+ gl->comp_range.location = compRange.location;
+ gl->comp_range.length = compRange.length;
+
+ while (++glyphIndex < numberOfGlyphs)
+ if (![layoutManager notShownAttributeForGlyphAtIndex:glyphIndex])
+ break;
+ }
- {
- struct mac_glyph_layout *gl;
- NSPoint location;
- NSUInteger nextGlyphIndex;
- NSRange glyphRange;
- NSRect *glyphRects;
- NSUInteger nrects;
-
- if (!RIGHT_TO_LEFT_P)
- gl = glyph_layouts + i;
- else
- {
- NSUInteger dest = permutation[i];
-
- gl = glyph_layouts + dest;
- if (i < dest)
- {
- CFIndex tmp = gl->string_index;
-
- gl->string_index = glyph_layouts[i].string_index;
- glyph_layouts[i].string_index = tmp;
- }
- }
- gl->glyph_id = [layoutManager glyphAtIndex:glyphIndex];
-
- location = [layoutManager locationForGlyphAtIndex:glyphIndex];
- gl->baseline_delta = spaceLocation.y - location.y;
-
- for (nextGlyphIndex = glyphIndex + 1; nextGlyphIndex < numberOfGlyphs;
- nextGlyphIndex++)
- if (![layoutManager
- notShownAttributeForGlyphAtIndex:nextGlyphIndex])
- break;
-
- if (!RIGHT_TO_LEFT_P)
- {
- CGFloat maxX;
-
- if (prevGlyphIndex == 0)
- glyphRange = NSMakeRange (0, nextGlyphIndex);
- else
- glyphRange = NSMakeRange (glyphIndex,
- nextGlyphIndex - glyphIndex);
- glyphRects =
- [layoutManager
- rectArrayForGlyphRange:glyphRange
- withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0))
- inTextContainer:textContainer rectCount:&nrects];
- maxX = max (NSMaxX (glyphRects[0]), totalAdvance);
- gl->advance_delta = location.x - totalAdvance;
- gl->advance = maxX - totalAdvance;
- totalAdvance = maxX;
- }
- else
- {
- CGFloat minX;
-
- if (nextGlyphIndex == numberOfGlyphs)
- glyphRange = NSMakeRange (prevGlyphIndex,
- numberOfGlyphs - prevGlyphIndex);
- else
- glyphRange = NSMakeRange (prevGlyphIndex,
- glyphIndex + 1 - prevGlyphIndex);
- glyphRects =
- [layoutManager
- rectArrayForGlyphRange:glyphRange
- withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0))
- inTextContainer:textContainer rectCount:&nrects];
- minX = min (NSMinX (glyphRects[0]), totalAdvance);
- gl->advance = totalAdvance - minX;
- totalAdvance = minX;
- gl->advance_delta = location.x - totalAdvance;
- }
-
- prevGlyphIndex = glyphIndex + 1;
- glyphIndex = nextGlyphIndex;
- }
+ {
+ struct mac_glyph_layout *gl;
+ NSPoint location;
+ NSUInteger nextGlyphIndex;
+ NSRange glyphRange;
+ NSRect *glyphRects;
+ NSUInteger nrects;
+
+ if (!RIGHT_TO_LEFT_P)
+ gl = glyph_layouts + i;
+ else
+ {
+ NSUInteger dest = permutation[i];
+
+ gl = glyph_layouts + dest;
+ if (i < dest)
+ {
+ CFIndex tmp = gl->string_index;
+
+ gl->string_index = glyph_layouts[i].string_index;
+ glyph_layouts[i].string_index = tmp;
+ }
+ }
+ gl->glyph_id = [layoutManager glyphAtIndex:glyphIndex];
+
+ location = [layoutManager locationForGlyphAtIndex:glyphIndex];
+ gl->baseline_delta = spaceLocation.y - location.y;
+
+ for (nextGlyphIndex = glyphIndex + 1; nextGlyphIndex < numberOfGlyphs;
+ nextGlyphIndex++)
+ if (![layoutManager
+ notShownAttributeForGlyphAtIndex:nextGlyphIndex])
+ break;
+
+ if (!RIGHT_TO_LEFT_P)
+ {
+ CGFloat maxX;
+
+ if (prevGlyphIndex == 0)
+ glyphRange = NSMakeRange (0, nextGlyphIndex);
+ else
+ glyphRange = NSMakeRange (glyphIndex,
+ nextGlyphIndex - glyphIndex);
+ glyphRects =
+ [layoutManager
+ rectArrayForGlyphRange:glyphRange
+ withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0))
+ inTextContainer:textContainer rectCount:&nrects];
+ maxX = max (NSMaxX (glyphRects[0]), totalAdvance);
+ gl->advance_delta = location.x - totalAdvance;
+ gl->advance = maxX - totalAdvance;
+ totalAdvance = maxX;
+ }
+ else
+ {
+ CGFloat minX;
+
+ if (nextGlyphIndex == numberOfGlyphs)
+ glyphRange = NSMakeRange (prevGlyphIndex,
+ numberOfGlyphs - prevGlyphIndex);
+ else
+ glyphRange = NSMakeRange (prevGlyphIndex,
+ glyphIndex + 1 - prevGlyphIndex);
+ glyphRects =
+ [layoutManager
+ rectArrayForGlyphRange:glyphRange
+ withinSelectedGlyphRange:(NSMakeRange (NSNotFound, 0))
+ inTextContainer:textContainer rectCount:&nrects];
+ minX = min (NSMinX (glyphRects[0]), totalAdvance);
+ gl->advance = totalAdvance - minX;
+ totalAdvance = minX;
+ gl->advance_delta = location.x - totalAdvance;
+ }
+
+ prevGlyphIndex = glyphIndex + 1;
+ glyphIndex = nextGlyphIndex;
+ }
- {{FONT_WEIGHT_INDEX, MAC_FONT_WEIGHT_TRAIT,
- {{-0.4, 50}, /* light */
- {-0.24, 87.5}, /* (semi-light + normal) / 2 */
- {0, 100}, /* normal */
- {0.24, 140}, /* (semi-bold + normal) / 2 */
- {0.4, 200}, /* bold */
- {CGFLOAT_MAX, CGFLOAT_MAX}}},
- {FONT_SLANT_INDEX, MAC_FONT_SLANT_TRAIT,
- {{0, 100}, {0.1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}},
- {FONT_WIDTH_INDEX, MAC_FONT_WIDTH_TRAIT,
- {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}};
+ {{FONT_WEIGHT_INDEX, MAC_FONT_WEIGHT_TRAIT,
+ {{-0.4, 50}, /* light */
+ {-0.24, 87.5}, /* (semi-light + normal) / 2 */
+ {0, 100}, /* normal */
+ {0.24, 140}, /* (semi-bold + normal) / 2 */
+ {0.4, 200}, /* bold */
+ {CGFLOAT_MAX, CGFLOAT_MAX}}},
+ {FONT_SLANT_INDEX, MAC_FONT_SLANT_TRAIT,
+ {{0, 100}, {0.1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}},
+ {FONT_WIDTH_INDEX, MAC_FONT_WIDTH_TRAIT,
+ {{0, 100}, {1, 200}, {CGFLOAT_MAX, CGFLOAT_MAX}}}};
- {
- num = CFDictionaryGetValue (dict, numeric_traits[i].trait);
- if (num && CFNumberGetValue (num, kCFNumberCGFloatType, &floatval))
- {
- CGPoint *point = numeric_traits[i].points;
-
- while (point->x < floatval)
- point++;
- if (point == numeric_traits[i].points)
- point++;
- else if (point->x == CGFLOAT_MAX)
- point--;
- floatval = (point - 1)->y + ((floatval - (point - 1)->x)
- * ((point->y - (point - 1)->y)
- / (point->x - (point - 1)->x)));
- FONT_SET_STYLE (spec_or_entity, numeric_traits[i].index,
- make_number (lround (floatval)));
- }
- }
+ {
+ num = CFDictionaryGetValue (dict, numeric_traits[i].trait);
+ if (num && CFNumberGetValue (num, kCFNumberCGFloatType, &floatval))
+ {
+ CGPoint *point = numeric_traits[i].points;
+
+ while (point->x < floatval)
+ point++;
+ if (point == numeric_traits[i].points)
+ point++;
+ else if (point->x == CGFLOAT_MAX)
+ point--;
+ floatval = (point - 1)->y + ((floatval - (point - 1)->x)
+ * ((point->y - (point - 1)->y)
+ / (point->x - (point - 1)->x)));
+ FONT_SET_STYLE (spec_or_entity, numeric_traits[i].index,
+ make_number (lround (floatval)));
+ }
+ }
- CFIndex i, count;
-
- if (families == NULL)
- {
- families = mac_font_create_available_families ();
- using_cache_p = 0;
- if (families == NULL)
- break;
- }
-
- count = CFArrayGetCount (families);
- i = CFArrayBSearchValues (families, CFRangeMake (0, count),
- (const void *) family_name,
- family_name_comparator, NULL);
- if (i < count)
- {
- CFStringRef name = CFArrayGetValueAtIndex (families, i);
-
- if ((*family_name_comparator) (name, family_name, NULL)
- == kCFCompareEqualTo)
- result = CFRetain (name);
- }
-
- if (result || !using_cache_p)
- break;
- else
- {
- CFRelease (families);
- families = NULL;
- }
+ CFIndex i, count;
+
+ if (families == NULL)
+ {
+ families = mac_font_create_available_families ();
+ using_cache_p = 0;
+ if (families == NULL)
+ break;
+ }
+
+ count = CFArrayGetCount (families);
+ i = CFArrayBSearchValues (families, CFRangeMake (0, count),
+ (const void *) family_name,
+ family_name_comparator, NULL);
+ if (i < count)
+ {
+ CFStringRef name = CFArrayGetValueAtIndex (families, i);
+
+ if ((*family_name_comparator) (name, family_name, NULL)
+ == kCFCompareEqualTo)
+ result = CFRetain (name);
+ }
+
+ if (result || !using_cache_p)
+ break;
+ else
+ {
+ CFRelease (families);
+ families = NULL;
+ }
- {
- CGRect bounds = mac_font_get_bounding_rect_for_glyph (macfont, glyph);
-
- if (macfont_info->synthetic_italic_p)
- {
- /* We assume the members a, b, c, and d in
- synthetic_italic_atfm are non-negative. */
- bounds.origin =
- CGPointApplyAffineTransform (bounds.origin,
- synthetic_italic_atfm);
- bounds.size =
- CGSizeApplyAffineTransform (bounds.size, synthetic_italic_atfm);
- }
- if (macfont_info->synthetic_bold_p)
- {
- CGFloat d =
- - synthetic_bold_factor * mac_font_get_size (macfont) / 2;
-
- bounds = CGRectInset (bounds, d, d);
- }
- switch (macfont_info->spacing)
- {
- case MACFONT_SPACING_PROPORTIONAL:
- bounds.origin.x += - (cache->width_frac
- / (CGFloat) (WIDTH_FRAC_SCALE * 2));
- break;
- case MACFONT_SPACING_MONO:
- break;
- case MACFONT_SPACING_SYNTHETIC_MONO:
- bounds.origin.x += (cache->width_int
- + (cache->width_frac
- / (CGFloat) WIDTH_FRAC_SCALE));
- break;
- }
- if (bounds.size.width > 0)
- {
- bounds.origin.x -= LCD_FONT_SMOOTHING_LEFT_MARGIN;
- bounds.size.width += (LCD_FONT_SMOOTHING_LEFT_MARGIN
- + LCD_FONT_SMOOTHING_RIGHT_MARGIN);
- }
- bounds = CGRectIntegral (bounds);
- METRICS_SET_VALUE (cache, lbearing, CGRectGetMinX (bounds));
- METRICS_SET_VALUE (cache, rbearing, CGRectGetMaxX (bounds));
- METRICS_SET_VALUE (cache, ascent, CGRectGetMaxY (bounds));
- METRICS_SET_VALUE (cache, descent, -CGRectGetMinY (bounds));
- }
+ {
+ CGRect bounds = mac_font_get_bounding_rect_for_glyph (macfont, glyph);
+
+ if (macfont_info->synthetic_italic_p)
+ {
+ /* We assume the members a, b, c, and d in
+ synthetic_italic_atfm are non-negative. */
+ bounds.origin =
+ CGPointApplyAffineTransform (bounds.origin,
+ synthetic_italic_atfm);
+ bounds.size =
+ CGSizeApplyAffineTransform (bounds.size, synthetic_italic_atfm);
+ }
+ if (macfont_info->synthetic_bold_p && ! force_integral_p)
+ {
+ CGFloat d =
+ - synthetic_bold_factor * mac_font_get_size (macfont) / 2;
+
+ bounds = CGRectInset (bounds, d, d);
+ }
+ switch (macfont_info->spacing)
+ {
+ case MACFONT_SPACING_PROPORTIONAL:
+ bounds.origin.x += - (cache->width_frac
+ / (CGFloat) (WIDTH_FRAC_SCALE * 2));
+ break;
+ case MACFONT_SPACING_MONO:
+ break;
+ case MACFONT_SPACING_SYNTHETIC_MONO:
+ bounds.origin.x += (cache->width_int
+ + (cache->width_frac
+ / (CGFloat) WIDTH_FRAC_SCALE));
+ break;
+ }
+ if (bounds.size.width > 0)
+ {
+ bounds.origin.x -= LCD_FONT_SMOOTHING_LEFT_MARGIN;
+ bounds.size.width += (LCD_FONT_SMOOTHING_LEFT_MARGIN
+ + LCD_FONT_SMOOTHING_RIGHT_MARGIN);
+ }
+ bounds = CGRectIntegral (bounds);
+ METRICS_SET_VALUE (cache, lbearing, CGRectGetMinX (bounds));
+ METRICS_SET_VALUE (cache, rbearing, CGRectGetMaxX (bounds));
+ METRICS_SET_VALUE (cache, ascent, CGRectGetMaxY (bounds));
+ METRICS_SET_VALUE (cache, descent, -CGRectGetMinY (bounds));
+ }
- {
- cache = xzalloc (sizeof (struct macfont_cache));
- /* Treat the LastResort font as if it contained glyphs for
- all characters. This may look too rough, but neither
- CTFontCopyCharacterSet nor -[NSFont coveredCharacterSet]
- for this font is correct for non-BMP characters on Mac OS
- X 10.5, anyway. */
- if (CFEqual (key, CFSTR ("LastResort")))
- {
- CFRange range = CFRangeMake (0, MAX_UNICODE_CHAR + 1);
-
- cache->cf_charset =
- CFCharacterSetCreateWithCharactersInRange (NULL, range);
- }
- if (cache->cf_charset == NULL)
- cache->cf_charset = mac_font_copy_character_set (macfont);
- CFDictionaryAddValue (macfont_cache_dictionary, key,
- (const void *) cache);
- CFRelease (macfont);
- }
+ {
+ cache = xzalloc (sizeof (struct macfont_cache));
+ /* Treat the LastResort font as if it contained glyphs for
+ all characters. This may look too rough, but neither
+ CTFontCopyCharacterSet nor -[NSFont coveredCharacterSet]
+ for this font is correct for non-BMP characters on Mac OS
+ X 10.5, anyway. */
+ if (CFEqual (key, CFSTR ("LastResort")))
+ {
+ CFRange range = CFRangeMake (0, MAX_UNICODE_CHAR + 1);
+
+ cache->cf_charset =
+ CFCharacterSetCreateWithCharactersInRange (NULL, range);
+ }
+ if (cache->cf_charset == NULL)
+ cache->cf_charset = mac_font_copy_character_set (macfont);
+ CFDictionaryAddValue (macfont_cache_dictionary, key,
+ (const void *) cache);
+ CFRelease (macfont);
+ }
- {
- UniChar unichars[256], ch;
- CGGlyph *glyphs;
- int i, len;
- int nrows;
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
- dispatch_queue_t queue;
- dispatch_group_t group = NULL;
-#else
- int nkeys;
-#endif
-
- if (row != 0)
- {
- CFMutableDictionaryRef dictionary;
- uintptr_t key, value;
- int nshifts;
- CGGlyph glyph;
-
- if (cache->glyph.dictionary == NULL)
- cache->glyph.dictionary =
- CFDictionaryCreateMutable (NULL, 0, NULL, NULL);
- dictionary = cache->glyph.dictionary;
- key = c / NGLYPHS_IN_VALUE;
- nshifts = ((c % NGLYPHS_IN_VALUE) * sizeof (CGGlyph) * 8);
- value = ((uintptr_t)
- CFDictionaryGetValue (dictionary, (const void *) key));
- glyph = (value >> nshifts);
- if (glyph)
- return glyph;
-
- if (nkeys_or_perm + 1 != ROW_PERM_OFFSET)
- {
- ch = c;
- if (!mac_font_get_glyphs_for_characters (macfont, &ch,
- &glyph, 1)
- || glyph == 0)
- glyph = kCGFontIndexInvalid;
-
- if (value == 0)
- cache->glyph.row_nkeys_or_perm[row] = nkeys_or_perm + 1;
- value |= ((uintptr_t) glyph << nshifts);
- CFDictionarySetValue (dictionary, (const void *) key,
- (const void *) value);
-
- return glyph;
- }
-
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
- queue =
- dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- group = dispatch_group_create ();
- dispatch_group_async (group, queue, ^{
- int nkeys;
- uintptr_t key;
-#endif
- nkeys = nkeys_or_perm;
- for (key = row * (256 / NGLYPHS_IN_VALUE); ; key++)
- if (CFDictionaryContainsKey (dictionary,
- (const void *) key))
- {
- CFDictionaryRemoveValue (dictionary,
- (const void *) key);
- if (--nkeys == 0)
- break;
- }
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
- });
-#endif
- }
-
- len = 0;
- for (i = 0; i < 256; i++)
- {
- ch = row * 256 + i;
- if (CFCharacterSetIsLongCharacterMember (cache->cf_charset, ch))
- unichars[len++] = ch;
- }
-
- glyphs = xmalloc (sizeof (CGGlyph) * 256);
- if (len > 0)
- {
- mac_font_get_glyphs_for_characters (macfont, unichars,
- glyphs, len);
- while (i > len)
- {
- int next = unichars[len - 1] % 256;
-
- while (--i > next)
- glyphs[i] = kCGFontIndexInvalid;
-
- len--;
- glyphs[i] = glyphs[len];
- if (len == 0)
- break;
- }
- }
- if (i > len)
- while (i-- > 0)
- glyphs[i] = kCGFontIndexInvalid;
-
- nrows = cache->glyph.nrows;
- nkeys_or_perm = nrows + ROW_PERM_OFFSET;
- cache->glyph.row_nkeys_or_perm[row] = nkeys_or_perm;
- nrows++;
- cache->glyph.matrix = xrealloc (cache->glyph.matrix,
- sizeof (CGGlyph *) * nrows);
- cache->glyph.matrix[nrows - 1] = glyphs;
- cache->glyph.nrows = nrows;
-
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
- if (group)
- {
- dispatch_group_wait (group, DISPATCH_TIME_FOREVER);
- dispatch_release (group);
- }
-#endif
- }
+ {
+ UniChar unichars[256], ch;
+ CGGlyph *glyphs;
+ int i, len;
+ int nrows;
+ dispatch_queue_t queue;
+ dispatch_group_t group = NULL;
+
+ if (row != 0)
+ {
+ CFMutableDictionaryRef dictionary;
+ uintptr_t key, value;
+ int nshifts;
+ CGGlyph glyph;
+
+ if (cache->glyph.dictionary == NULL)
+ cache->glyph.dictionary =
+ CFDictionaryCreateMutable (NULL, 0, NULL, NULL);
+ dictionary = cache->glyph.dictionary;
+ key = c / NGLYPHS_IN_VALUE;
+ nshifts = ((c % NGLYPHS_IN_VALUE) * sizeof (CGGlyph) * 8);
+ value = ((uintptr_t)
+ CFDictionaryGetValue (dictionary, (const void *) key));
+ glyph = (value >> nshifts);
+ if (glyph)
+ return glyph;
+
+ if (nkeys_or_perm + 1 != ROW_PERM_OFFSET)
+ {
+ ch = c;
+ if (!mac_font_get_glyphs_for_characters (macfont, &ch,
+ &glyph, 1)
+ || glyph == 0)
+ glyph = kCGFontIndexInvalid;
+
+ if (value == 0)
+ cache->glyph.row_nkeys_or_perm[row] = nkeys_or_perm + 1;
+ value |= ((uintptr_t) glyph << nshifts);
+ CFDictionarySetValue (dictionary, (const void *) key,
+ (const void *) value);
+
+ return glyph;
+ }
+
+ queue =
+ dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+ group = dispatch_group_create ();
+ dispatch_group_async (group, queue, ^{
+ int nkeys;
+ uintptr_t key;
+ nkeys = nkeys_or_perm;
+ for (key = row * (256 / NGLYPHS_IN_VALUE); ; key++)
+ if (CFDictionaryContainsKey (dictionary,
+ (const void *) key))
+ {
+ CFDictionaryRemoveValue (dictionary,
+ (const void *) key);
+ if (--nkeys == 0)
+ break;
+ }
+ });
+ }
+
+ len = 0;
+ for (i = 0; i < 256; i++)
+ {
+ ch = row * 256 + i;
+ if (CFCharacterSetIsLongCharacterMember (cache->cf_charset, ch))
+ unichars[len++] = ch;
+ }
+
+ glyphs = xmalloc (sizeof (CGGlyph) * 256);
+ if (len > 0)
+ {
+ mac_font_get_glyphs_for_characters (macfont, unichars,
+ glyphs, len);
+ while (i > len)
+ {
+ int next = unichars[len - 1] % 256;
+
+ while (--i > next)
+ glyphs[i] = kCGFontIndexInvalid;
+
+ len--;
+ glyphs[i] = glyphs[len];
+ if (len == 0)
+ break;
+ }
+ }
+ if (i > len)
+ while (i-- > 0)
+ glyphs[i] = kCGFontIndexInvalid;
+
+ nrows = cache->glyph.nrows;
+ nkeys_or_perm = nrows + ROW_PERM_OFFSET;
+ cache->glyph.row_nkeys_or_perm[row] = nkeys_or_perm;
+ nrows++;
+ cache->glyph.matrix = xrealloc (cache->glyph.matrix,
+ sizeof (CGGlyph *) * nrows);
+ cache->glyph.matrix[nrows - 1] = glyphs;
+ cache->glyph.nrows = nrows;
+
+ if (group)
+ {
+ dispatch_group_wait (group, DISPATCH_TIME_FOREVER);
+ dispatch_release (group);
+ }
+ }
- && mac_font_get_glyph_for_cid (macfont,
- MAC_CHARACTER_COLLECTION_ADOBE_JAPAN1,
- 6480) != kCGFontIndexInvalid)
- {
- /* If the glyph for U+4E55 is accessible via its CID 6480,
- then we use the Adobe-Japan1 UVS table, which maps a
- variation sequence to a CID, as a fallback. */
- static CFDataRef mac_uvs_table_adobe_japan1 = NULL;
-
- if (mac_uvs_table_adobe_japan1 == NULL)
- mac_uvs_table_adobe_japan1 =
- CFDataCreateWithBytesNoCopy (NULL,
- mac_uvs_table_adobe_japan1_bytes,
- sizeof (mac_uvs_table_adobe_japan1_bytes),
- kCFAllocatorNull);
- if (mac_uvs_table_adobe_japan1)
- {
- uvs_table = CFRetain (mac_uvs_table_adobe_japan1);
- uvs_collection = MAC_CHARACTER_COLLECTION_ADOBE_JAPAN1;
- }
- }
+ && mac_font_get_glyph_for_cid (macfont,
+ MAC_CHARACTER_COLLECTION_ADOBE_JAPAN1,
+ 6480) != kCGFontIndexInvalid)
+ {
+ /* If the glyph for U+4E55 is accessible via its CID 6480,
+ then we use the Adobe-Japan1 UVS table, which maps a
+ variation sequence to a CID, as a fallback. */
+ static CFDataRef mac_uvs_table_adobe_japan1 = NULL;
+
+ if (mac_uvs_table_adobe_japan1 == NULL)
+ mac_uvs_table_adobe_japan1 =
+ CFDataCreateWithBytesNoCopy (NULL,
+ mac_uvs_table_adobe_japan1_bytes,
+ sizeof (mac_uvs_table_adobe_japan1_bytes),
+ kCFAllocatorNull);
+ if (mac_uvs_table_adobe_japan1)
+ {
+ uvs_table = CFRetain (mac_uvs_table_adobe_japan1);
+ uvs_collection = MAC_CHARACTER_COLLECTION_ADOBE_JAPAN1;
+ }
+ }
- {
- CFMutableStringRef string = CFStringCreateMutable (NULL, 0);
- CFMutableCharacterSetRef cs = CFCharacterSetCreateMutable (NULL);
-
- if (! string || !cs)
- {
- if (string)
- CFRelease (string);
- else if (cs)
- CFRelease (cs);
- goto err;
- }
- for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars))
- if (CHARACTERP (XCAR (chars)))
- {
- UniChar unichars[2];
- CFIndex count =
- macfont_store_utf32char_to_unichars (XFASTINT (XCAR (chars)),
- unichars);
- CFRange range = CFRangeMake (XFASTINT (XCAR (chars)), 1);
-
- CFStringAppendCharacters (string, unichars, count);
- CFCharacterSetAddCharactersInRange (cs, range);
- }
- charset = cs;
- /* CFCharacterSetCreateWithCharactersInString does not
- handle surrogate pairs properly as of Mac OS X 10.5. */
- charset_string = string;
- }
+ {
+ CFMutableStringRef string = CFStringCreateMutable (NULL, 0);
+ CFMutableCharacterSetRef cs = CFCharacterSetCreateMutable (NULL);
+
+ if (! string || !cs)
+ {
+ if (string)
+ CFRelease (string);
+ else if (cs)
+ CFRelease (cs);
+ goto err;
+ }
+ for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars))
+ if (CHARACTERP (XCAR (chars)))
+ {
+ UniChar unichars[2];
+ CFIndex count =
+ macfont_store_utf32char_to_unichars (XFASTINT (XCAR (chars)),
+ unichars);
+ CFRange range = CFRangeMake (XFASTINT (XCAR (chars)), 1);
+
+ CFStringAppendCharacters (string, unichars, count);
+ CFCharacterSetAddCharactersInRange (cs, range);
+ }
+ charset = cs;
+ /* CFCharacterSetCreateWithCharactersInString does not
+ handle surrogate pairs properly as of Mac OS X 10.5. */
+ charset_string = string;
+ }
- {
- CGPoint *point = numeric_traits[i].points;
- CGFloat floatval = (XINT (tmp) >> 8); // XXX
- CFNumberRef num;
-
- while (point->y < floatval)
- point++;
- if (point == numeric_traits[i].points)
- point++;
- else if (point->y == CGFLOAT_MAX)
- point--;
- floatval = (point - 1)->x + ((floatval - (point - 1)->y)
- * ((point->x - (point - 1)->x)
- / (point->y - (point - 1)->y)));
- if (floatval > 1.0)
- floatval = 1.0;
- else if (floatval < -1.0)
- floatval = -1.0;
- num = CFNumberCreate (NULL, kCFNumberCGFloatType, &floatval);
- if (! num)
- goto err;
- CFDictionaryAddValue (traits, numeric_traits[i].trait, num);
- CFRelease (num);
- }
+ {
+ CGPoint *point = numeric_traits[i].points;
+ CGFloat floatval = (XINT (tmp) >> 8); // XXX
+ CFNumberRef num;
+
+ while (point->y < floatval)
+ point++;
+ if (point == numeric_traits[i].points)
+ point++;
+ else if (point->y == CGFLOAT_MAX)
+ point--;
+ floatval = (point - 1)->x + ((floatval - (point - 1)->y)
+ * ((point->x - (point - 1)->x)
+ / (point->y - (point - 1)->y)));
+ if (floatval > 1.0)
+ floatval = 1.0;
+ else if (floatval < -1.0)
+ floatval = -1.0;
+ num = CFNumberCreate (NULL, kCFNumberCGFloatType, &floatval);
+ if (! num)
+ goto err;
+ CFDictionaryAddValue (traits, numeric_traits[i].trait, num);
+ CFRelease (num);
+ }
- {
- if (charset)
- result = CFCharacterSetIsSupersetOfSet (desc_charset, charset);
- else /* VECTORP (chars) */
- {
- ptrdiff_t j;
-
- for (j = 0; j < ASIZE (chars); j++)
- if (TYPE_RANGED_INTEGERP (UTF32Char, AREF (chars, j))
- && CFCharacterSetIsLongCharacterMember (desc_charset,
- XFASTINT (AREF (chars, j))))
- break;
- if (j == ASIZE (chars))
- result = false;
- }
- CFRelease (desc_charset);
- }
+ {
+ if (charset)
+ result = CFCharacterSetIsSupersetOfSet (desc_charset, charset);
+ else /* VECTORP (chars) */
+ {
+ ptrdiff_t j;
+
+ for (j = 0; j < ASIZE (chars); j++)
+ if (TYPE_RANGED_INTEGERP (UTF32Char, AREF (chars, j))
+ && CFCharacterSetIsLongCharacterMember (desc_charset,
+ XFASTINT (AREF (chars, j))))
+ break;
+ if (j == ASIZE (chars))
+ result = false;
+ }
+ CFRelease (desc_charset);
+ }
- {
- CFMutableArrayRef mutable_families =
- CFArrayCreateMutable (NULL, families_count, &kCFTypeArrayCallBacks);
-
- if (mutable_families)
- {
- CFArrayAppendValue (mutable_families,
- CFArrayGetValueAtIndex (families,
- pref_family_index));
- CFArrayAppendArray (mutable_families, families,
- CFRangeMake (0, pref_family_index));
- if (pref_family_index + 1 < families_count)
- CFArrayAppendArray (mutable_families, families,
- CFRangeMake (pref_family_index + 1,
- families_count
- - (pref_family_index + 1)));
- CFRelease (families);
- families = mutable_families;
- }
- }
+ {
+ CFMutableArrayRef mutable_families =
+ CFArrayCreateMutable (NULL, families_count, &kCFTypeArrayCallBacks);
+
+ if (mutable_families)
+ {
+ CFArrayAppendValue (mutable_families,
+ CFArrayGetValueAtIndex (families,
+ pref_family_index));
+ CFArrayAppendArray (mutable_families, families,
+ CFRangeMake (0, pref_family_index));
+ if (pref_family_index + 1 < families_count)
+ CFArrayAppendArray (mutable_families, families,
+ CFRangeMake (pref_family_index + 1,
+ families_count
+ - (pref_family_index + 1)));
+ CFRelease (families);
+ families = mutable_families;
+ }
+ }
- {
- FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, j);
- CFDictionaryRef dict;
- CFNumberRef num;
- FontSymbolicTraits sym_traits;
-
- dict = mac_font_descriptor_copy_attribute (desc,
- MAC_FONT_TRAITS_ATTRIBUTE);
- if (dict == NULL)
- continue;
-
- num = CFDictionaryGetValue (dict, MAC_FONT_SYMBOLIC_TRAIT);
- CFRelease (dict);
- if (num == NULL
- || !cfnumber_get_font_symbolic_traits_value (num, &sym_traits))
- continue;
-
- if (spacing >= 0
- && !(synth_sym_traits & MAC_FONT_TRAIT_MONO_SPACE)
- && (((sym_traits & MAC_FONT_TRAIT_MONO_SPACE) != 0)
- != (spacing >= FONT_SPACING_MONO)))
- continue;
-
- /* Don't use a color bitmap font unless its family is
- explicitly specified. */
- if ((sym_traits & MAC_FONT_TRAIT_COLOR_GLYPHS) && NILP (family))
- continue;
-
- if (j > 0
- && !macfont_supports_charset_and_languages_p (desc, charset,
- chars, languages))
- continue;
-
- CFArrayAppendValue (filtered_descs, desc);
- CFArrayAppendValue (traits_array,
- (const void *) (uintptr_t) sym_traits);
- }
+ {
+ FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, j);
+ CFDictionaryRef dict;
+ CFNumberRef num;
+ FontSymbolicTraits sym_traits;
+
+ dict = mac_font_descriptor_copy_attribute (desc,
+ MAC_FONT_TRAITS_ATTRIBUTE);
+ if (dict == NULL)
+ continue;
+
+ num = CFDictionaryGetValue (dict, MAC_FONT_SYMBOLIC_TRAIT);
+ CFRelease (dict);
+ if (num == NULL
+ || !cfnumber_get_font_symbolic_traits_value (num, &sym_traits))
+ continue;
+
+ if (spacing >= 0
+ && !(synth_sym_traits & MAC_FONT_TRAIT_MONO_SPACE)
+ && (((sym_traits & MAC_FONT_TRAIT_MONO_SPACE) != 0)
+ != (spacing >= FONT_SPACING_MONO)))
+ continue;
+
+ /* Don't use a color bitmap font unless its family is
+ explicitly specified. */
+ if ((sym_traits & MAC_FONT_TRAIT_COLOR_GLYPHS) && NILP (family))
+ continue;
+
+ if (j > 0
+ && !macfont_supports_charset_and_languages_p (desc, charset,
+ chars, languages))
+ continue;
+
+ CFArrayAppendValue (filtered_descs, desc);
+ CFArrayAppendValue (traits_array,
+ (const void *) (uintptr_t) sym_traits);
+ }
- {
- FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, j);
- FontSymbolicTraits sym_traits =
- ((FontSymbolicTraits) (uintptr_t)
- CFArrayGetValueAtIndex (traits_array, j));
- FontSymbolicTraits mask_min, mask_max, imask, bmask, mmask;
-
- mask_min = ((synth_sym_traits ^ sym_traits)
- & (MAC_FONT_TRAIT_ITALIC | MAC_FONT_TRAIT_BOLD));
- if (FONT_SLANT_NUMERIC (spec) < 0)
- mask_min &= ~MAC_FONT_TRAIT_ITALIC;
- if (FONT_WEIGHT_NUMERIC (spec) < 0)
- mask_min &= ~MAC_FONT_TRAIT_BOLD;
-
- mask_max = (synth_sym_traits & ~sym_traits);
- /* Synthetic bold does not work for bitmap-only fonts on Mac
- OS X 10.6. */
- if ((mask_min ^ mask_max) & MAC_FONT_TRAIT_BOLD)
- {
- CFNumberRef format =
- mac_font_descriptor_copy_attribute (desc,
- MAC_FONT_FORMAT_ATTRIBUTE);
-
- if (format)
- {
- uint32_t format_val;
-
- if (CFNumberGetValue (format, kCFNumberSInt32Type,
- &format_val)
- && format_val == MAC_FONT_FORMAT_BITMAP)
- mask_max &= ~MAC_FONT_TRAIT_BOLD;
- }
- }
- if (spacing >= 0)
- mask_min |= (mask_max & MAC_FONT_TRAIT_MONO_SPACE);
-
- for (mmask = (mask_min & MAC_FONT_TRAIT_MONO_SPACE);
- mmask <= (mask_max & MAC_FONT_TRAIT_MONO_SPACE);
- mmask += MAC_FONT_TRAIT_MONO_SPACE)
- for (bmask = (mask_min & MAC_FONT_TRAIT_BOLD);
- bmask <= (mask_max & MAC_FONT_TRAIT_BOLD);
- bmask += MAC_FONT_TRAIT_BOLD)
- for (imask = (mask_min & MAC_FONT_TRAIT_ITALIC);
- imask <= (mask_max & MAC_FONT_TRAIT_ITALIC);
- imask += MAC_FONT_TRAIT_ITALIC)
- {
- FontSymbolicTraits synth = (imask | bmask | mmask);
-
- if (synth == 0
- || j == macfont_closest_traits_index (traits_array,
- (sym_traits | synth)))
- {
- entity = macfont_descriptor_entity (desc, extra, synth);
- if (! NILP (entity))
- val = Fcons (entity, val);
- }
- }
- }
+ {
+ FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, j);
+ FontSymbolicTraits sym_traits =
+ ((FontSymbolicTraits) (uintptr_t)
+ CFArrayGetValueAtIndex (traits_array, j));
+ FontSymbolicTraits mask_min, mask_max, imask, bmask, mmask;
+
+ mask_min = ((synth_sym_traits ^ sym_traits)
+ & (MAC_FONT_TRAIT_ITALIC | MAC_FONT_TRAIT_BOLD));
+ if (FONT_SLANT_NUMERIC (spec) < 0)
+ mask_min &= ~MAC_FONT_TRAIT_ITALIC;
+ if (FONT_WEIGHT_NUMERIC (spec) < 0)
+ mask_min &= ~MAC_FONT_TRAIT_BOLD;
+
+ mask_max = (synth_sym_traits & ~sym_traits);
+ /* Synthetic bold does not work for bitmap-only fonts on Mac
+ OS X 10.6. */
+ if ((mask_min ^ mask_max) & MAC_FONT_TRAIT_BOLD)
+ {
+ CFNumberRef format =
+ mac_font_descriptor_copy_attribute (desc,
+ MAC_FONT_FORMAT_ATTRIBUTE);
+
+ if (format)
+ {
+ uint32_t format_val;
+
+ if (CFNumberGetValue (format, kCFNumberSInt32Type,
+ &format_val)
+ && format_val == MAC_FONT_FORMAT_BITMAP)
+ mask_max &= ~MAC_FONT_TRAIT_BOLD;
+ }
+ }
+ if (spacing >= 0)
+ mask_min |= (mask_max & MAC_FONT_TRAIT_MONO_SPACE);
+
+ for (mmask = (mask_min & MAC_FONT_TRAIT_MONO_SPACE);
+ mmask <= (mask_max & MAC_FONT_TRAIT_MONO_SPACE);
+ mmask += MAC_FONT_TRAIT_MONO_SPACE)
+ for (bmask = (mask_min & MAC_FONT_TRAIT_BOLD);
+ bmask <= (mask_max & MAC_FONT_TRAIT_BOLD);
+ bmask += MAC_FONT_TRAIT_BOLD)
+ for (imask = (mask_min & MAC_FONT_TRAIT_ITALIC);
+ imask <= (mask_max & MAC_FONT_TRAIT_ITALIC);
+ imask += MAC_FONT_TRAIT_ITALIC)
+ {
+ FontSymbolicTraits synth = (imask | bmask | mmask);
+
+ if (synth == 0
+ || macfont_closest_traits_index_p (traits_array,
+ (sym_traits | synth),
+ j))
+ {
+ entity = macfont_descriptor_entity (desc, extra, synth);
+ if (! NILP (entity))
+ val = Fcons (entity, val);
+ }
+ }
+ }
- font_object = font_make_object (VECSIZE (struct macfont_info), entity, size);
- ASET (font_object, FONT_TYPE_INDEX, macfont_driver.type);
- len = font_unparse_xlfd (entity, size, name, 256);
- if (len > 0)
- ASET (font_object, FONT_NAME_INDEX, make_string (name, len));
- len = font_unparse_fcname (entity, size, name, 256);
- if (len > 0)
- ASET (font_object, FONT_FULLNAME_INDEX, make_string (name, len));
- else
- ASET (font_object, FONT_FULLNAME_INDEX,
- AREF (font_object, FONT_NAME_INDEX));
+ font_object = font_build_object (VECSIZE (struct macfont_info),
+ Qmac_ct, entity, size);
- block_input ();
- CFRelease (macfont_info->macfont);
- CGFontRelease (macfont_info->cgfont);
- if (macfont_info->screen_font)
- CFRelease (macfont_info->screen_font);
- macfont_release_cache (macfont_info->cache);
- for (i = 0; i < macfont_info->metrics_nrows; i++)
- if (macfont_info->metrics[i])
- xfree (macfont_info->metrics[i]);
- if (macfont_info->metrics)
- xfree (macfont_info->metrics);
- unblock_input ();
+ if (macfont_info->cache)
+ {
+ int i;
+
+ block_input ();
+ CFRelease (macfont_info->macfont);
+ CGFontRelease (macfont_info->cgfont);
+ if (macfont_info->screen_font)
+ CFRelease (macfont_info->screen_font);
+ macfont_release_cache (macfont_info->cache);
+ for (i = 0; i < macfont_info->metrics_nrows; i++)
+ if (macfont_info->metrics[i])
+ xfree (macfont_info->metrics[i]);
+ if (macfont_info->metrics)
+ xfree (macfont_info->metrics);
+ macfont_info->cache = NULL;
+ unblock_input ();
+ }
- {
- UInt32 default_uvs_offset, non_default_uvs_offset;
-
- default_uvs_offset = BUINT32_VALUE (records[i].default_uvs_offset);
- if (default_uvs_offset)
- {
- struct default_uvs_table *default_uvs;
- UInt32 nranges;
-
- if (default_uvs_offset > uvs_len
- || (SIZEOF_DEFAULT_UVS_TABLE_HEADER
- > uvs_len - default_uvs_offset))
- goto finish;
-
- default_uvs = ((struct default_uvs_table *)
- ((UInt8 *) uvs + default_uvs_offset));
- nranges = BUINT32_VALUE (default_uvs->num_unicode_value_ranges);
- if (nranges > ((uvs_len - default_uvs_offset
- - SIZEOF_DEFAULT_UVS_TABLE_HEADER)
- / sizeof (struct unicode_value_range)))
- goto finish;
- /* Now 2 * nranges can't overflow, so we can safely use
- `(lo + hi) / 2' instead of `lo + (hi - lo) / 2' in
- mac_font_get_glyphs_for_variants. */
- }
-
- non_default_uvs_offset =
- BUINT32_VALUE (records[i].non_default_uvs_offset);
- if (non_default_uvs_offset)
- {
- struct non_default_uvs_table *non_default_uvs;
- UInt32 nmappings;
-
- if (non_default_uvs_offset > uvs_len
- || (SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER
- > uvs_len - non_default_uvs_offset))
- goto finish;
-
- non_default_uvs = ((struct non_default_uvs_table *)
- ((UInt8 *) uvs + non_default_uvs_offset));
- nmappings = BUINT32_VALUE (non_default_uvs->num_uvs_mappings);
- if (nmappings > ((uvs_len - non_default_uvs_offset
- - SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER)
- / sizeof (struct uvs_mapping)))
- goto finish;
- /* Now 2 * nmappings can't overflow, so we can safely
- use `(lo + hi) / 2' instead of `lo + (hi - lo) / 2'
- in mac_font_get_glyphs_for_variants. */
- }
- }
+ {
+ UInt32 default_uvs_offset, non_default_uvs_offset;
+
+ default_uvs_offset = BUINT32_VALUE (records[i].default_uvs_offset);
+ if (default_uvs_offset)
+ {
+ struct default_uvs_table *default_uvs;
+ UInt32 nranges;
+
+ if (default_uvs_offset > uvs_len
+ || (SIZEOF_DEFAULT_UVS_TABLE_HEADER
+ > uvs_len - default_uvs_offset))
+ goto finish;
+
+ default_uvs = ((struct default_uvs_table *)
+ ((UInt8 *) uvs + default_uvs_offset));
+ nranges = BUINT32_VALUE (default_uvs->num_unicode_value_ranges);
+ if (nranges > ((uvs_len - default_uvs_offset
+ - SIZEOF_DEFAULT_UVS_TABLE_HEADER)
+ / sizeof (struct unicode_value_range)))
+ goto finish;
+ /* Now 2 * nranges can't overflow, so we can safely use
+ `(lo + hi) / 2' instead of `lo + (hi - lo) / 2' in
+ mac_font_get_glyphs_for_variants. */
+ }
+
+ non_default_uvs_offset =
+ BUINT32_VALUE (records[i].non_default_uvs_offset);
+ if (non_default_uvs_offset)
+ {
+ struct non_default_uvs_table *non_default_uvs;
+ UInt32 nmappings;
+
+ if (non_default_uvs_offset > uvs_len
+ || (SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER
+ > uvs_len - non_default_uvs_offset))
+ goto finish;
+
+ non_default_uvs = ((struct non_default_uvs_table *)
+ ((UInt8 *) uvs + non_default_uvs_offset));
+ nmappings = BUINT32_VALUE (non_default_uvs->num_uvs_mappings);
+ if (nmappings > ((uvs_len - non_default_uvs_offset
+ - SIZEOF_NON_DEFAULT_UVS_TABLE_HEADER)
+ / sizeof (struct uvs_mapping)))
+ goto finish;
+ /* Now 2 * nmappings can't overflow, so we can safely
+ use `(lo + hi) / 2' instead of `lo + (hi - lo) / 2'
+ in mac_font_get_glyphs_for_variants. */
+ }
+ }
-#endif
- glyphs[i] = kCGFontIndexInvalid;
-
- if (default_uvs_offset)
- {
- struct default_uvs_table *default_uvs =
- (struct default_uvs_table *) ((UInt8 *) uvs
- + default_uvs_offset);
- struct unicode_value_range *ranges =
- default_uvs->unicode_value_ranges;
- UInt32 lo, hi;
-
- lo = 0;
- hi = BUINT32_VALUE (default_uvs->num_unicode_value_ranges);
- while (lo < hi)
- {
- UInt32 mid = (lo + hi) / 2;
-
- if (c < BUINT24_VALUE (ranges[mid].start_unicode_value))
- hi = mid;
- else
- lo = mid + 1;
- }
- if (hi > 0
- && (c <= (BUINT24_VALUE (ranges[hi - 1].start_unicode_value)
- + BUINT8_VALUE (ranges[hi - 1].additional_count))))
- glyphs[i] = 0;
- }
-
- if (glyphs[i] == kCGFontIndexInvalid && non_default_uvs_offset)
- {
- struct non_default_uvs_table *non_default_uvs =
- (struct non_default_uvs_table *) ((UInt8 *) uvs
- + non_default_uvs_offset);
- struct uvs_mapping *mappings = non_default_uvs->uvs_mappings;
- UInt32 lo, hi;
-
- lo = 0;
- hi = BUINT32_VALUE (non_default_uvs->num_uvs_mappings);
- while (lo < hi)
- {
- UInt32 mid = (lo + hi) / 2;
-
- if (c < BUINT24_VALUE (mappings[mid].unicode_value))
- hi = mid;
- else
- lo = mid + 1;
- }
- if (hi > 0 &&
- BUINT24_VALUE (mappings[hi - 1].unicode_value) == c)
- glyphs[i] = BUINT16_VALUE (mappings[hi - 1].glyph_id);
- }
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
- });
-#endif
+ glyphs[i] = kCGFontIndexInvalid;
+
+ if (default_uvs_offset)
+ {
+ struct default_uvs_table *default_uvs =
+ (struct default_uvs_table *) ((UInt8 *) uvs
+ + default_uvs_offset);
+ struct unicode_value_range *ranges =
+ default_uvs->unicode_value_ranges;
+ UInt32 lo, hi;
+
+ lo = 0;
+ hi = BUINT32_VALUE (default_uvs->num_unicode_value_ranges);
+ while (lo < hi)
+ {
+ UInt32 mid = (lo + hi) / 2;
+
+ if (c < BUINT24_VALUE (ranges[mid].start_unicode_value))
+ hi = mid;
+ else
+ lo = mid + 1;
+ }
+ if (hi > 0
+ && (c <= (BUINT24_VALUE (ranges[hi - 1].start_unicode_value)
+ + BUINT8_VALUE (ranges[hi - 1].additional_count))))
+ glyphs[i] = 0;
+ }
+
+ if (glyphs[i] == kCGFontIndexInvalid && non_default_uvs_offset)
+ {
+ struct non_default_uvs_table *non_default_uvs =
+ (struct non_default_uvs_table *) ((UInt8 *) uvs
+ + non_default_uvs_offset);
+ struct uvs_mapping *mappings = non_default_uvs->uvs_mappings;
+ UInt32 lo, hi;
+
+ lo = 0;
+ hi = BUINT32_VALUE (non_default_uvs->num_uvs_mappings);
+ while (lo < hi)
+ {
+ UInt32 mid = (lo + hi) / 2;
+
+ if (c < BUINT24_VALUE (mappings[mid].unicode_value))
+ hi = mid;
+ else
+ lo = mid + 1;
+ }
+ if (hi > 0 &&
+ BUINT24_VALUE (mappings[hi - 1].unicode_value) == c)
+ glyphs[i] = BUINT16_VALUE (mappings[hi - 1].glyph_id);
+ }
+ });
- {
- CFAttributedStringRef attr_string = NULL;
- CTLineRef ctline = NULL;
- CFDictionaryRef attrs
- = CFDictionaryCreate (NULL, (const void **) keys,
- (const void **) values, num_values,
- &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks);
-
- if (attrs)
- {
- attr_string = CFAttributedStringCreate (NULL, charset_string,
- attrs);
- CFRelease (attrs);
- }
- if (attr_string)
- {
- ctline = CTLineCreateWithAttributedString (attr_string);
- CFRelease (attr_string);
- }
- if (ctline)
- {
- CFArrayRef runs = CTLineGetGlyphRuns (ctline);
- CFIndex i, nruns = CFArrayGetCount (runs);
- CTFontRef font;
-
- for (i = 0; i < nruns; i++)
- {
- CTRunRef run = CFArrayGetValueAtIndex (runs, i);
- CFDictionaryRef attributes = CTRunGetAttributes (run);
- CTFontRef font_in_run;
-
- if (attributes == NULL)
- break;
- font_in_run =
- CFDictionaryGetValue (attributes, kCTFontAttributeName);
- if (font_in_run == NULL)
- break;
- if (i == 0)
- font = font_in_run;
- else if (!mac_ctfont_equal_in_postscript_name (font,
- font_in_run))
- break;
- }
- if (nruns > 0 && i == nruns)
- result = CTFontCopyAttribute (font, kCTFontFamilyNameAttribute);
- CFRelease (ctline);
- }
- }
+ {
+ CFAttributedStringRef attr_string = NULL;
+ CTLineRef ctline = NULL;
+ CFDictionaryRef attrs
+ = CFDictionaryCreate (NULL, (const void **) keys,
+ (const void **) values, num_values,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+
+ if (attrs)
+ {
+ attr_string = CFAttributedStringCreate (NULL, charset_string,
+ attrs);
+ CFRelease (attrs);
+ }
+ if (attr_string)
+ {
+ ctline = CTLineCreateWithAttributedString (attr_string);
+ CFRelease (attr_string);
+ }
+ if (ctline)
+ {
+ CFArrayRef runs = CTLineGetGlyphRuns (ctline);
+ CFIndex i, nruns = CFArrayGetCount (runs);
+ CTFontRef font;
+
+ for (i = 0; i < nruns; i++)
+ {
+ CTRunRef run = CFArrayGetValueAtIndex (runs, i);
+ CFDictionaryRef attributes = CTRunGetAttributes (run);
+ CTFontRef font_in_run;
+
+ if (attributes == NULL)
+ break;
+ font_in_run =
+ CFDictionaryGetValue (attributes, kCTFontAttributeName);
+ if (font_in_run == NULL)
+ break;
+ if (i == 0)
+ font = font_in_run;
+ else if (!mac_ctfont_equal_in_postscript_name (font,
+ font_in_run))
+ break;
+ }
+ if (nruns > 0 && i == nruns)
+ result = CTFontCopyAttribute (font, kCTFontFamilyNameAttribute);
+ CFRelease (ctline);
+ }
+ }
- {
- CFIndex i, count = CFArrayGetCount (orig_families);
-
- families = CFArrayCreateMutable (NULL, count, &kCFTypeArrayCallBacks);
- if (families)
- for (i = 0; i < count; i++)
- {
- CFStringRef family = CFArrayGetValueAtIndex (orig_families, i);
-
- if (!CFStringHasPrefix (family, CFSTR ("."))
- && (CTFontManagerCompareFontFamilyNames (family,
- CFSTR ("LastResort"),
- NULL)
- != kCFCompareEqualTo))
- CFArrayAppendValue (families, family);
- }
- CFRelease (orig_families);
- }
- }
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
- else /* CTFontManagerCopyAvailableFontFamilyNames == NULL */
-#endif
-#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 */
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
- {
- CTFontCollectionRef collection;
- CFArrayRef descs = NULL;
-
- collection = CTFontCollectionCreateFromAvailableFonts (NULL);
- if (collection)
- {
- descs = CTFontCollectionCreateMatchingFontDescriptors (collection);
- CFRelease (collection);
- }
- if (descs)
- {
- CFIndex i, count = CFArrayGetCount (descs);
-
- families = CFArrayCreateMutable (NULL, count, &kCFTypeArrayCallBacks);
- if (families)
- for (i = 0; i < count; i++)
- {
- FontDescriptorRef desc = CFArrayGetValueAtIndex (descs, i);
- CFStringRef name =
- mac_font_descriptor_copy_attribute (desc,
- MAC_FONT_FAMILY_NAME_ATTRIBUTE);
-
- if (name)
- {
- CFIndex p, limit = CFArrayGetCount (families);
-
- p = CFArrayBSearchValues (families, CFRangeMake (0, limit),
- (const void *) name,
- mac_font_family_compare, NULL);
- if (p >= limit)
- CFArrayAppendValue (families, name);
- else if (mac_font_family_compare
- (CFArrayGetValueAtIndex (families, p),
- name, NULL) != kCFCompareEqualTo)
- CFArrayInsertValueAtIndex (families, p, name);
- CFRelease (name);
- }
- }
- CFRelease (descs);
- }
+ {
+ CFIndex i, count = CFArrayGetCount (orig_families);
+
+ families = CFArrayCreateMutable (NULL, count, &kCFTypeArrayCallBacks);
+ if (families)
+ for (i = 0; i < count; i++)
+ {
+ CFStringRef family = CFArrayGetValueAtIndex (orig_families, i);
+
+ if (!CFStringHasPrefix (family, CFSTR ("."))
+ && (CTFontManagerCompareFontFamilyNames (family,
+ CFSTR ("LastResort"),
+ NULL)
+ != kCFCompareEqualTo))
+ CFArrayAppendValue (families, family);
+ }
+ CFRelease (orig_families);
+ }
- glbuf[i].comp_range.length = maxRange (compRange[i])
- where compRange[i] is the range of composed characters
- containing i-th glyph. */
- string_range = CTRunGetStringRange (ctrun);
- min_location = string_range.location + string_range.length;
- for (i = 0; i < glyph_count; i++)
- {
- struct mac_glyph_layout *gl = glbuf + glyph_count - i - 1;
- CFIndex glyph_index;
- CFRange rng;
-
- if (!RIGHT_TO_LEFT_P)
- glyph_index = glyph_count - i - 1;
- else
- glyph_index = i;
- CTRunGetStringIndices (ctrun, CFRangeMake (glyph_index, 1),
- &gl->string_index);
- rng =
- CFStringGetRangeOfComposedCharactersAtIndex (string,
- gl->string_index);
- gl->comp_range.location = min_location;
- gl->comp_range.length = rng.location + rng.length;
- if (rng.location < min_location)
- min_location = rng.location;
- }
-
- /* Fill the `comp_range' member of struct mac_glyph_layout,
- and setup a permutation for right-to-left text. */
- comp_range = CFRangeMake (string_range.location, 0);
- range = CFRangeMake (0, 0);
- while (1)
- {
- struct mac_glyph_layout *gl =
- glbuf + range.location + range.length;
-
- if (gl->comp_range.length
- > comp_range.location + comp_range.length)
- comp_range.length = gl->comp_range.length - comp_range.location;
- min_location = gl->comp_range.location;
- range.length++;
-
- if (min_location >= comp_range.location + comp_range.length)
- {
- comp_range.length = min_location - comp_range.location;
- for (i = 0; i < range.length; i++)
- {
- glbuf[range.location + i].comp_range = comp_range;
- if (RIGHT_TO_LEFT_P)
- permutation[range.location + i] =
- range.location + range.length - i - 1;
- }
-
- comp_range = CFRangeMake (min_location, 0);
- range.location += range.length;
- range.length = 0;
- if (range.location == glyph_count)
- break;
- }
- }
-
- /* Then fill the remaining members. */
- for (range = CFRangeMake (0, 1); range.location < glyph_count;
- range.location++)
- {
- struct mac_glyph_layout *gl;
- CGPoint position;
-
- if (!RIGHT_TO_LEFT_P)
- gl = glbuf + range.location;
- else
- {
- CFIndex src, dest;
-
- src = glyph_count - 1 - range.location;
- dest = permutation[src];
- gl = glbuf + dest;
- if (src < dest)
- {
- CFIndex tmp = gl->string_index;
-
- gl->string_index = glbuf[src].string_index;
- glbuf[src].string_index = tmp;
- }
- }
- CTRunGetGlyphs (ctrun, range, &gl->glyph_id);
-
- CTRunGetPositions (ctrun, range, &position);
- gl->advance_delta = position.x - total_advance;
- gl->baseline_delta = position.y;
- gl->advance = (gl->advance_delta
- + CTRunGetTypographicBounds (ctrun, range,
- NULL, NULL, NULL));
- total_advance += gl->advance;
- }
-
- if (RIGHT_TO_LEFT_P)
- xfree (permutation);
+ glbuf[i].comp_range.length = maxRange (compRange[i])
+ where compRange[i] is the range of composed characters
+ containing i-th glyph. */
+ string_range = CTRunGetStringRange (ctrun);
+ min_location = string_range.location + string_range.length;
+ for (i = 0; i < glyph_count; i++)
+ {
+ struct mac_glyph_layout *gl = glbuf + glyph_count - i - 1;
+ CFIndex glyph_index;
+ CFRange rng;
+
+ if (!RIGHT_TO_LEFT_P)
+ glyph_index = glyph_count - i - 1;
+ else
+ glyph_index = i;
+ CTRunGetStringIndices (ctrun, CFRangeMake (glyph_index, 1),
+ &gl->string_index);
+ rng =
+ CFStringGetRangeOfComposedCharactersAtIndex (string,
+ gl->string_index);
+ gl->comp_range.location = min_location;
+ gl->comp_range.length = rng.location + rng.length;
+ if (rng.location < min_location)
+ min_location = rng.location;
+ }
+
+ /* Fill the `comp_range' member of struct mac_glyph_layout,
+ and setup a permutation for right-to-left text. */
+ comp_range = CFRangeMake (string_range.location, 0);
+ range = CFRangeMake (0, 0);
+ while (1)
+ {
+ struct mac_glyph_layout *gl =
+ glbuf + range.location + range.length;
+
+ if (gl->comp_range.length
+ > comp_range.location + comp_range.length)
+ comp_range.length = gl->comp_range.length - comp_range.location;
+ min_location = gl->comp_range.location;
+ range.length++;
+
+ if (min_location >= comp_range.location + comp_range.length)
+ {
+ comp_range.length = min_location - comp_range.location;
+ for (i = 0; i < range.length; i++)
+ {
+ glbuf[range.location + i].comp_range = comp_range;
+ if (RIGHT_TO_LEFT_P)
+ permutation[range.location + i] =
+ range.location + range.length - i - 1;
+ }
+
+ comp_range = CFRangeMake (min_location, 0);
+ range.location += range.length;
+ range.length = 0;
+ if (range.location == glyph_count)
+ break;
+ }
+ }
+
+ /* Then fill the remaining members. */
+ for (range = CFRangeMake (0, 1); range.location < glyph_count;
+ range.location++)
+ {
+ struct mac_glyph_layout *gl;
+ CGPoint position;
+
+ if (!RIGHT_TO_LEFT_P)
+ gl = glbuf + range.location;
+ else
+ {
+ CFIndex src, dest;
+
+ src = glyph_count - 1 - range.location;
+ dest = permutation[src];
+ gl = glbuf + dest;
+ if (src < dest)
+ {
+ CFIndex tmp = gl->string_index;
+
+ gl->string_index = glbuf[src].string_index;
+ glbuf[src].string_index = tmp;
+ }
+ }
+ CTRunGetGlyphs (ctrun, range, &gl->glyph_id);
+
+ CTRunGetPositions (ctrun, range, &position);
+ gl->advance_delta = position.x - total_advance;
+ gl->baseline_delta = position.y;
+ gl->advance = (gl->advance_delta
+ + CTRunGetTypographicBounds (ctrun, range,
+ NULL, NULL, NULL));
+ total_advance += gl->advance;
+ }
+
+ if (RIGHT_TO_LEFT_P)
+ xfree (permutation);
- {
- CTRunRef run = CFArrayGetValueAtIndex (runs, 0);
- CFDictionaryRef attributes = CTRunGetAttributes (run);
-
- if (attributes)
- {
- CTFontRef font_in_run =
- CFDictionaryGetValue (attributes, kCTFontAttributeName);
-
- if (font_in_run
- && mac_ctfont_equal_in_postscript_name (font_in_run, font))
- {
- CTRunGetGlyphs (run, CFRangeMake (0, 1), &result);
- if (result >= CTFontGetGlyphCount (font))
- result = kCGFontIndexInvalid;
- }
- }
- }
+ {
+ CTRunRef run = CFArrayGetValueAtIndex (runs, 0);
+ CFDictionaryRef attributes = CTRunGetAttributes (run);
+
+ if (attributes)
+ {
+ CTFontRef font_in_run =
+ CFDictionaryGetValue (attributes, kCTFontAttributeName);
+
+ if (font_in_run
+ && mac_ctfont_equal_in_postscript_name (font_in_run, font))
+ {
+ CTRunGetGlyphs (run, CFRangeMake (0, 1), &result);
+ if (result >= CTFontGetGlyphCount (font))
+ result = kCGFontIndexInvalid;
+ }
+ }
+ }
- {
- CFMutableArrayRef descriptors =
- CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks);
-
- if (descriptors)
- {
- CFIndex j;
-
- for (j = 0;
- macfont_language_default_font_names[i].font_names[j];
- j++)
- {
- CFDictionaryRef attributes =
- CFDictionaryCreate (NULL,
- ((const void **)
- &MAC_FONT_NAME_ATTRIBUTE),
- ((const void **)
- &macfont_language_default_font_names[i].font_names[j]),
- 1, &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks);
-
- if (attributes)
- {
- FontDescriptorRef pat_desc =
- mac_font_descriptor_create_with_attributes (attributes);
-
- if (pat_desc)
- {
- FontDescriptorRef descriptor =
- mac_font_descriptor_create_matching_font_descriptor (pat_desc, NULL);
-
- if (descriptor)
- {
- CFArrayAppendValue (descriptors, descriptor);
- CFRelease (descriptor);
- }
- CFRelease (pat_desc);
- }
- CFRelease (attributes);
- }
- }
- result = descriptors;
- }
- break;
- }
- }
+ {
+ CFMutableArrayRef descriptors =
+ CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks);
+
+ if (descriptors)
+ {
+ CFIndex j;
+
+ for (j = 0;
+ macfont_language_default_font_names[i].font_names[j];
+ j++)
+ {
+ CFDictionaryRef attributes =
+ CFDictionaryCreate (NULL,
+ ((const void **)
+ &MAC_FONT_NAME_ATTRIBUTE),
+ ((const void **)
+ &macfont_language_default_font_names[i].font_names[j]),
+ 1, &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+
+ if (attributes)
+ {
+ FontDescriptorRef pat_desc =
+ mac_font_descriptor_create_with_attributes (attributes);
+
+ if (pat_desc)
+ {
+ FontDescriptorRef descriptor =
+ mac_font_descriptor_create_matching_font_descriptor (pat_desc, NULL);
+
+ if (descriptor)
+ {
+ CFArrayAppendValue (descriptors, descriptor);
+ CFRelease (descriptor);
+ }
+ CFRelease (pat_desc);
+ }
+ CFRelease (attributes);
+ }
+ }
+ result = descriptors;
+ }
+ break;
+ }
+ }
- {
- FontDescriptorRef descriptor =
- CFArrayGetValueAtIndex (descriptors, i);
-
- if (macfont_supports_charset_and_languages_p (descriptor, charset,
- Qnil, languages))
- {
- CFStringRef family =
- mac_font_descriptor_copy_attribute (descriptor,
- MAC_FONT_FAMILY_NAME_ATTRIBUTE);
- if (family)
- {
- if (!CFStringHasPrefix (family, CFSTR ("."))
- && !CFEqual (family, CFSTR ("LastResort")))
+ {
+ FontDescriptorRef descriptor =
+ CFArrayGetValueAtIndex (descriptors, i);
+
+ if (macfont_supports_charset_and_languages_p (descriptor, charset,
+ Qnil, languages))
+ {
+ CFStringRef family =
+ mac_font_descriptor_copy_attribute (descriptor,
+ MAC_FONT_FAMILY_NAME_ATTRIBUTE);
+ if (family)
+ {
+ if (!CFStringHasPrefix (family, CFSTR ("."))
+ && !CFEqual (family, CFSTR ("LastResort")))