summaryrefslogtreecommitdiffstats
path: root/libass/ass_fontselect.c
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2021-06-17 16:33:57 +0300
committerOleg Oshmyan <chortos@inbox.lv>2021-07-10 02:36:31 +0300
commita7f67df5f96f03fab6661d90d716c16e0fab4a21 (patch)
tree3329ce6a73bff4a352f04a621621e2fa71cf05ff /libass/ass_fontselect.c
parent677e8e3ca75e25163bfd5c217d9d4c1de09bd242 (diff)
downloadlibass-a7f67df5f96f03fab6661d90d716c16e0fab4a21.tar.bz2
libass-a7f67df5f96f03fab6661d90d716c16e0fab4a21.tar.xz
font, fontselect: factor out common code for creating FT_Face
Diffstat (limited to 'libass/ass_fontselect.c')
-rw-r--r--libass/ass_fontselect.c37
1 files changed, 6 insertions, 31 deletions
diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c
index ef79066..40daf85 100644
--- a/libass/ass_fontselect.c
+++ b/libass/ass_fontselect.c
@@ -884,39 +884,14 @@ bool ass_get_font_info(ASS_Library *lib, FT_Library ftlib, const char *path,
bool require_family_name,
ASS_FontProviderMetaData *info)
{
- bool ret = false;
- FT_Face face = NULL;
- int error = FT_New_Face(ftlib, path, index, &face);
- if (error) {
- ass_msg(lib, MSGL_WARN, "Error opening font: '%s', %d", path, index);
+ FT_Face face = ass_face_open(lib, ftlib, path, postscript_name, index);
+ if (!face)
return false;
- }
- if (postscript_name && index < 0 && face->num_faces > 0) {
- // The font provider gave us a postscript 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; i < face->num_faces; i++) {
- FT_Done_Face(face);
- error = FT_New_Face(ftlib, path, i, &face);
- if (error) {
- ass_msg(lib, MSGL_WARN, "Error opening font: '%s', %d", path, i);
- return false;
- }
-
- const char *face_psname = FT_Get_Postscript_Name(face);
- if (face_psname != NULL &&
- strcmp(face_psname, postscript_name) == 0)
- break;
- }
- }
-
- if (face) {
- ret = get_font_info(ftlib, face, require_family_name, info);
- if (ret)
- info->postscript_name = strdup(info->postscript_name);
- FT_Done_Face(face);
- }
+ bool ret = get_font_info(ftlib, face, require_family_name, info);
+ if (ret)
+ info->postscript_name = strdup(info->postscript_name);
+ FT_Done_Face(face);
return ret;
}