Skip to content
This repository was archived by the owner on Jan 3, 2025. It is now read-only.

Commit c7b8761

Browse files
author
Michael Belyaev
committed
Fix loading font from data
1 parent d0343f3 commit c7b8761

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/font_renderer/ct_font_renderer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ class CtFontRenderer : public FontRenderer {
2626

2727
CtFontRenderer::CtFontRenderer(const FontRendererArgs& args)
2828
{
29-
CFStringRef fontName = CFStringCreateWithCString(NULL, (const char*)args.data, kCFStringEncodingUTF8);
30-
font = CTFontCreateWithName(fontName, args.pxSize, NULL);
31-
CFRelease(fontName);
29+
CTFontDescriptorRef descriptor = CTFontManagerCreateFontDescriptorFromData(CFDataCreate(nullptr, static_cast<const UInt8*>(args.data), args.dataSize));
30+
if (!descriptor)
31+
throw FontRendererError("CoreText can't create descriptor");
32+
font = CTFontCreateWithFontDescriptor(descriptor, static_cast<CGFloat>(args.pxSize), nullptr);
33+
CFRelease(descriptor);
3234
if (!font)
3335
throw FontRendererError("CoreText can't init font");
3436
}

0 commit comments

Comments
 (0)