summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2021-09-24 23:06:50 +0300
committerOleg Oshmyan <chortos@inbox.lv>2021-09-24 23:06:50 +0300
commit2b30c69ca3a0c0767dac4f3486c9182d2a79cb38 (patch)
tree3a7563f0142c48a980def777f20b956066f56703
parentb6240cdaef1b51a9add42a4bdfa72064297dbc7d (diff)
downloadlibass-2b30c69ca3a0c0767dac4f3486c9182d2a79cb38.tar.bz2
libass-2b30c69ca3a0c0767dac4f3486c9182d2a79cb38.tar.xz
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.
-rw-r--r--libass/ass_font.c14
1 files 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)