From 2b30c69ca3a0c0767dac4f3486c9182d2a79cb38 Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Fri, 24 Sep 2021 23:06:50 +0300 Subject: ass_face_open: if only one face exists, use it without name check At worst, even if this face isn't actually the desired one, this will just waste memory but won't break font selection. At best, this enables use of some broken TrueType fonts that lack valid PostScript names, as in https://github.com/libass/libass/issues/554. Core Text synthesizes a PostScript name, but FreeType doesn't, so every face has a NULL face_psname. Potentially, a font might also have a non-NULL face_psname that differs from Core Text's. --- libass/ass_font.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libass/ass_font.c b/libass/ass_font.c index 6f55840..68e5fe4 100644 --- a/libass/ass_font.c +++ b/libass/ass_font.c @@ -133,9 +133,6 @@ static void set_font_metrics(FT_Face face) FT_Face ass_face_open(ASS_Library *lib, FT_Library ftlib, const char *path, const char *postscript_name, int index) { - if (index < 0 && !postscript_name) - return NULL; - FT_Face face; int error = FT_New_Face(ftlib, path, index, &face); if (error) { @@ -157,6 +154,17 @@ FT_Face ass_face_open(ASS_Library *lib, FT_Library ftlib, const char *path, return NULL; } + // If there is only one face, don't bother checking the name. + // The font might not even *have* a valid PostScript name. + if (!i && face->num_faces == 1) + return face; + + // Otherwise, we really need a name to search for. + if (!postscript_name) { + FT_Done_Face(face); + return NULL; + } + const char *face_psname = FT_Get_Postscript_Name(face); if (face_psname != NULL && strcmp(face_psname, postscript_name) == 0) -- cgit v1.2.3