summaryrefslogtreecommitdiffstats
path: root/libass/ass_fontselect.c
diff options
context:
space:
mode:
authorRodger Combs <rodger.combs@gmail.com>2019-01-15 18:17:57 -0600
committerOleg Oshmyan <chortos@inbox.lv>2019-09-26 16:51:09 +0300
commit47e9e994358f17c776f20084d7b9750d3de79068 (patch)
tree44aa43c2fd18b44f54b0f8ec588bbf44d9ff9d9d /libass/ass_fontselect.c
parentd0852911b7a91ee7e6653958419009912a7ad3e8 (diff)
downloadlibass-47e9e994358f17c776f20084d7b9750d3de79068.tar.bz2
libass-47e9e994358f17c776f20084d7b9750d3de79068.tar.xz
fontselect: provide a way to use freetype to get font info
Diffstat (limited to 'libass/ass_fontselect.c')
-rw-r--r--libass/ass_fontselect.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c
index 85ff0dc..651fc7a 100644
--- a/libass/ass_fontselect.c
+++ b/libass/ass_fontselect.c
@@ -848,6 +848,47 @@ error:
return false;
}
+bool ass_get_font_info(ASS_Library *lib, FT_Library ftlib, const char *path,
+ const char *postscript_name, int index,
+ 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);
+ 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, info);
+ if (ret)
+ info->postscript_name = strdup(info->postscript_name);
+ FT_Done_Face(face);
+ }
+
+ return ret;
+}
+
/**
* \brief Free the dynamically allocated fields of metadata
* created by get_font_info.