(CoreText) Fix loading fonts from a path

This commit is contained in:
Jean-André Santoni 2017-02-20 23:11:40 +01:00
parent b42fdf3bdc
commit b700a4e77b

View File

@ -256,6 +256,9 @@ static void *font_renderer_ct_init(const char *font_path, float font_size)
char err = 0; char err = 0;
CFStringRef cf_font_path = NULL; CFStringRef cf_font_path = NULL;
CTFontRef face = NULL; CTFontRef face = NULL;
CFURLRef url = NULL;
CGDataProviderRef dataProvider = NULL;
CGFontRef theCGFont = NULL;
ct_font_renderer_t *handle = (ct_font_renderer_t*) ct_font_renderer_t *handle = (ct_font_renderer_t*)
calloc(1, sizeof(*handle)); calloc(1, sizeof(*handle));
@ -273,7 +276,10 @@ static void *font_renderer_ct_init(const char *font_path, float font_size)
goto error; 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) if (!face)
{ {
@ -304,6 +310,21 @@ error:
CFRelease(face); CFRelease(face);
face = NULL; face = NULL;
} }
if (url)
{
CFRelease(url);
url = NULL;
}
if (dataProvider)
{
CFRelease(dataProvider);
dataProvider = NULL;
}
if (theCGFont)
{
CFRelease(theCGFont);
theCGFont = NULL;
}
return handle; return handle;
} }