[coretext] Fix fallback detection

Fixes http://github.com/behdad/harfbuzz/pull/36
This commit is contained in:
Behdad Esfahbod 2014-08-10 19:05:25 -04:00
parent 77a7a53ace
commit 25f4fb9b56
1 changed files with 20 additions and 9 deletions

View File

@ -661,10 +661,6 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
if (start != chars_len && last_range->font) if (start != chars_len && last_range->font)
CFAttributedStringSetAttribute (attr_string, CFRangeMake (start, chars_len - start), CFAttributedStringSetAttribute (attr_string, CFRangeMake (start, chars_len - start),
kCTFontAttributeName, last_range->font); kCTFontAttributeName, last_range->font);
for (unsigned int i = 0; i < range_records.len; i++)
if (range_records[i].font)
CFRelease (range_records[i].font);
} }
CTLineRef line = CTLineCreateWithAttributedString (attr_string); CTLineRef line = CTLineCreateWithAttributedString (attr_string);
@ -689,11 +685,22 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
*/ */
CFDictionaryRef attributes = CTRunGetAttributes (run); CFDictionaryRef attributes = CTRunGetAttributes (run);
CTFontRef run_ct_font = static_cast<CTFontRef>(CFDictionaryGetValue (attributes, kCTFontAttributeName)); CTFontRef run_ct_font = static_cast<CTFontRef>(CFDictionaryGetValue (attributes, kCTFontAttributeName));
CGFontRef run_cg_font = CTFontCopyGraphicsFont (run_ct_font, 0); if (!CFEqual (run_ct_font, font_data->ct_font))
if (!CFEqual (run_cg_font, face_data)) {
/* The run doesn't use our main font. See if it uses any of our subfonts
* created to set font features... Only if the font didn't match any of
* those, consider reject the font. What we really want is to check the
* underlying CGFont, but apparently there's no safe way to do that.
* See: http://github.com/behdad/harfbuzz/pull/36 */
bool matched = false;
for (unsigned int i = 0; i < range_records.len; i++)
if (range_records[i].font && CFEqual (run_ct_font, range_records[i].font))
{
matched = true;
break;
}
if (!matched)
{ {
CFRelease (run_cg_font);
CFRange range = CTRunGetStringRange (run); CFRange range = CTRunGetStringRange (run);
buffer->ensure (buffer->len + range.length); buffer->ensure (buffer->len + range.length);
if (unlikely (buffer->in_error)) if (unlikely (buffer->in_error))
@ -729,7 +736,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
} }
continue; continue;
} }
CFRelease (run_cg_font); }
unsigned int num_glyphs = CTRunGetGlyphCount (run); unsigned int num_glyphs = CTRunGetGlyphCount (run);
if (num_glyphs == 0) if (num_glyphs == 0)
@ -788,6 +795,10 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
} }
} }
for (unsigned int i = 0; i < range_records.len; i++)
if (range_records[i].font)
CFRelease (range_records[i].font);
buffer->clear_positions (); buffer->clear_positions ();
unsigned int count = buffer->len; unsigned int count = buffer->len;