Skip to content

Commit 6c29365

Browse files
dskuzadskuza
andcommitted
fix(apple): use core text suggested fallback font if necessary (#11530) 147fe75b6b
Co-authored-by: David Skuza <david@rive.app>
1 parent 16f3637 commit 6c29365

File tree

2 files changed

+3
-41
lines changed

2 files changed

+3
-41
lines changed

.rive_head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
41002bf174cb409ba82c12b6803add48e969b6fb
1+
147fe75b6ba2592e3c8531b518433e87ab399b4c

src/text/font_hb_apple.mm

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -307,46 +307,8 @@ static void apply_element(void* ctx, const CGPathElement* element)
307307
if (CFIndex count = CTRunGetGlyphCount(run))
308308
{
309309
rive::GlyphRun gr(count);
310-
311-
// Because CoreText will automatically do its own font fallbacks
312-
// we need to detect that it's trying to use a different font.
313-
CFDictionaryRef attributes = CTRunGetAttributes(run);
314-
CTFontRef runCtFont = static_cast<CTFontRef>(
315-
CFDictionaryGetValue(attributes, kCTFontAttributeName));
316-
const float scale = textRun.size / (float)CTFontGetSize(runCtFont);
317-
if (!CFEqual(runCtFont, ctFont))
318-
{
319-
// Get the original font's traits and create a fallback font
320-
// with the same traits. In some cases, CoreText will use a
321-
// different font for the fallback, but the fallback font will
322-
// not have the same traits (e.g weight) as the original font.
323-
CTFontSymbolicTraits originalTraits =
324-
CTFontGetSymbolicTraits(ctFont);
325-
CTFontRef fallbackFont =
326-
CTFontCreateCopyWithSymbolicTraits(runCtFont,
327-
CTFontGetSize(runCtFont),
328-
nullptr,
329-
originalTraits,
330-
originalTraits);
331-
if (!fallbackFont)
332-
{
333-
fallbackFont = runCtFont;
334-
}
335-
336-
gr.font = HBFont::FromSystem(
337-
(void*)fallbackFont, true, m_weight, m_width);
338-
339-
// If the fallback font is not the same as the original run
340-
// font, we need to release it since we made a copy of it
341-
if ((void*)fallbackFont != (void*)runCtFont)
342-
{
343-
CFRelease(fallbackFont);
344-
}
345-
}
346-
else
347-
{
348-
gr.font = textRun.font;
349-
}
310+
const float scale = textRun.size / (float)CTFontGetSize(ctFont);
311+
gr.font = textRun.font;
350312
gr.size = textRun.size;
351313
gr.lineHeight = textRun.lineHeight;
352314
gr.letterSpacing = textRun.letterSpacing;

0 commit comments

Comments
 (0)