From 9014b275e9e90d796bee95249a6059e4a55f3cf9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 2 Nov 2013 12:07:07 +0100 Subject: fontselect: coretext: allow selection based on PostScript name Up until now fontselect used the face index to identify which font to load from a font collection. While this pretty convenient when using something freetype based like fontconfig, it seems to be somewhat freetype specific. CoreText uses the PostScript name as the unique identifier of a font. This commit allows to use that instead of the index to decide which face to open with FT_New_Face. To use the PostScript name the provider must return a -1 index and the PostScript name. --- libass/ass_font.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'libass/ass_font.c') diff --git a/libass/ass_font.c b/libass/ass_font.c index 0b6d24b..9a81dca 100644 --- a/libass/ass_font.c +++ b/libass/ass_font.c @@ -135,6 +135,7 @@ close_stream_font(FT_Stream stream) static int add_face(ASS_FontSelector *fontsel, ASS_Font *font, uint32_t ch) { char *path; + char *postscript_name; int i, index, uid, error; ASS_FontStream stream = { NULL, NULL }; FT_Face face; @@ -142,8 +143,8 @@ static int add_face(ASS_FontSelector *fontsel, ASS_Font *font, uint32_t ch) if (font->n_faces == ASS_FONT_MAX_FACES) return -1; - path = ass_font_select(fontsel, font->library, font , &index, &uid, - &stream, ch); + path = ass_font_select(fontsel, font->library, font , &index, + &postscript_name, &uid, &stream, ch); if (!path) return -1; @@ -191,6 +192,25 @@ static int add_face(ASS_FontSelector *fontsel, ASS_Font *font, uint32_t ch) free(path); return -1; } + + if (postscript_name && index < 0 && face->num_faces > 0) { + // The font provider gave us a post_script name and is not sure + // about the face index.. so use the postscript name to find the + // correct face_index in the collection! + for (int i = 0; face->num_faces; i++) { + FT_Done_Face(face); + error = FT_New_Face(font->ftlibrary, path, i, &face); + if (error) { + ass_msg(font->library, MSGL_WARN, + "Error opening font: '%s', %d", path, i); + free(path); + return -1; + } + + if (strcmp(FT_Get_Postscript_Name(face), postscript_name) == 0) + break; + } + } } charmap_magic(font->library, face); -- cgit v1.2.3