From b700a4e77b8ce9c3e3005e008c6a1f10e58adcd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Mon, 20 Feb 2017 23:11:40 +0100 Subject: [PATCH] (CoreText) Fix loading fonts from a path --- gfx/drivers_font_renderer/coretext.c | 29 ++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/gfx/drivers_font_renderer/coretext.c b/gfx/drivers_font_renderer/coretext.c index bd94b54a9c..d48b144a36 100644 --- a/gfx/drivers_font_renderer/coretext.c +++ b/gfx/drivers_font_renderer/coretext.c @@ -253,9 +253,12 @@ static bool coretext_font_renderer_create_atlas(CTFontRef face, ct_font_renderer static void *font_renderer_ct_init(const char *font_path, float font_size) { - char err = 0; - CFStringRef cf_font_path = NULL; - CTFontRef face = NULL; + char err = 0; + CFStringRef cf_font_path = NULL; + CTFontRef face = NULL; + CFURLRef url = NULL; + CGDataProviderRef dataProvider = NULL; + CGFontRef theCGFont = NULL; ct_font_renderer_t *handle = (ct_font_renderer_t*) calloc(1, sizeof(*handle)); @@ -273,7 +276,10 @@ static void *font_renderer_ct_init(const char *font_path, float font_size) goto error; } - face = CTFontCreateWithName(cf_font_path, font_size, NULL); + url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cf_font_path, kCFURLPOSIXPathStyle, false); + dataProvider = CGDataProviderCreateWithURL(url); + theCGFont = CGFontCreateWithDataProvider(dataProvider); + face = CTFontCreateWithGraphicsFont(theCGFont, font_size, NULL, NULL); if (!face) { @@ -304,6 +310,21 @@ error: CFRelease(face); face = NULL; } + if (url) + { + CFRelease(url); + url = NULL; + } + if (dataProvider) + { + CFRelease(dataProvider); + dataProvider = NULL; + } + if (theCGFont) + { + CFRelease(theCGFont); + theCGFont = NULL; + } return handle; }