summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2021-06-17 16:57:44 +0300
committerOleg Oshmyan <chortos@inbox.lv>2021-07-10 02:36:31 +0300
commit2ff663a6f3f0a9209a75116ff549fc78cef2b75c (patch)
tree7cb8d5da7b0377fc45f2b7013efc81c1d5ed234e
parenta7f67df5f96f03fab6661d90d716c16e0fab4a21 (diff)
downloadlibass-2ff663a6f3f0a9209a75116ff549fc78cef2b75c.tar.bz2
libass-2ff663a6f3f0a9209a75116ff549fc78cef2b75c.tar.xz
Pass last-resort-fallback family name directly to get_font_info
-rw-r--r--libass/ass_coretext.c46
-rw-r--r--libass/ass_fontselect.c31
-rw-r--r--libass/ass_fontselect.h4
3 files changed, 32 insertions, 49 deletions
diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c
index 4041046..42259bb 100644
--- a/libass/ass_coretext.c
+++ b/libass/ass_coretext.c
@@ -126,36 +126,6 @@ static char *get_name(CTFontDescriptorRef fontd, CFStringRef attr)
return ret;
}
-static bool fill_family_name(CTFontDescriptorRef fontd,
- ASS_FontProviderMetaData *info)
-{
- char *family_name = get_name(fontd, kCTFontFamilyNameAttribute);
- if (!family_name)
- return false;
-
- info->extended_family = family_name;
-
- if (!info->n_family) {
- family_name = strdup(family_name);
- if (!family_name) {
- free(info->extended_family);
- return false;
- }
-
- info->families = malloc(sizeof(char *));
- if (!info->families) {
- free(family_name);
- free(info->extended_family);
- return false;
- }
-
- info->families[0] = family_name;
- info->n_family++;
- }
-
- return true;
-}
-
static bool get_font_info_ct(ASS_Library *lib, FT_Library ftlib,
CTFontDescriptorRef fontd,
char **path_out,
@@ -172,10 +142,22 @@ static bool get_font_info_ct(ASS_Library *lib, FT_Library ftlib,
if (!ps_name)
return false;
- bool got_info = ass_get_font_info(lib, ftlib, path, ps_name, -1, false, info);
+ char *family_name = get_name(fontd, kCTFontFamilyNameAttribute);
+ if (!family_name) {
+ free(ps_name);
+ return false;
+ }
+
+ bool got_info =
+ ass_get_font_info(lib, ftlib, path, ps_name, -1, family_name, info);
free(ps_name);
- return got_info && fill_family_name(fontd, info);
+ if (got_info)
+ info->extended_family = family_name;
+ else
+ free(family_name);
+
+ return got_info;
}
static void process_descriptors(ASS_Library *lib, FT_Library ftlib,
diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c
index 40daf85..90fe0dc 100644
--- a/libass/ass_fontselect.c
+++ b/libass/ass_fontselect.c
@@ -771,11 +771,12 @@ char *ass_font_select(ASS_FontSelector *priv, ASS_Library *library,
* as required for the FontSelector for matching and sorting.
* \param lib FreeType library
* \param face FreeType face
+ * \param fallback_family_name family name from outside source, used as last resort
* \param info metadata, returned here
* \return success
*/
static bool
-get_font_info(FT_Library lib, FT_Face face, bool require_family_name,
+get_font_info(FT_Library lib, FT_Face face, const char *fallback_family_name,
ASS_FontProviderMetaData *info)
{
int i;
@@ -820,20 +821,20 @@ get_font_info(FT_Library lib, FT_Face face, bool require_family_name,
}
- if (require_family_name) {
- // check if we got a valid family - if not use whatever FreeType gives us
- if (num_family == 0 && face->family_name) {
- families[0] = strdup(face->family_name);
- if (families[0] == NULL)
- goto error;
- num_family++;
- }
-
- // we absolutely need a name
- if (num_family == 0)
+ // check if we got a valid family - if not, use
+ // whatever the font provider or FreeType gives us
+ if (num_family == 0 && (fallback_family_name || face->family_name)) {
+ families[0] =
+ strdup(fallback_family_name ? fallback_family_name : face->family_name);
+ if (families[0] == NULL)
goto error;
+ num_family++;
}
+ // we absolutely need a name
+ if (num_family == 0)
+ goto error;
+
// calculate sensible slant and weight from style attributes
slant = 110 * !!(face->style_flags & FT_STYLE_FLAG_ITALIC);
weight = ass_face_get_weight(face);
@@ -881,14 +882,14 @@ error:
bool ass_get_font_info(ASS_Library *lib, FT_Library ftlib, const char *path,
const char *postscript_name, int index,
- bool require_family_name,
+ const char *fallback_family_name,
ASS_FontProviderMetaData *info)
{
FT_Face face = ass_face_open(lib, ftlib, path, postscript_name, index);
if (!face)
return false;
- bool ret = get_font_info(ftlib, face, require_family_name, info);
+ bool ret = get_font_info(ftlib, face, fallback_family_name, info);
if (ret)
info->postscript_name = strdup(info->postscript_name);
FT_Done_Face(face);
@@ -952,7 +953,7 @@ static void process_fontdata(ASS_FontProvider *priv, ASS_Library *library,
charmap_magic(library, face);
memset(&info, 0, sizeof(ASS_FontProviderMetaData));
- if (!get_font_info(ftlibrary, face, true, &info)) {
+ if (!get_font_info(ftlibrary, face, NULL, &info)) {
ass_msg(library, MSGL_WARN,
"Error getting metadata for embedded font '%s'", name);
FT_Done_Face(face);
diff --git a/libass/ass_fontselect.h b/libass/ass_fontselect.h
index 907a1b5..eb0d112 100644
--- a/libass/ass_fontselect.h
+++ b/libass/ass_fontselect.h
@@ -285,14 +285,14 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
* \param path the path to the font file to read
* \param postscript_name the PS name of the specific face to read (set either this or index)
* \param index the face index to read, or -1 if not applicable
- * \param require_family_name whether to try a fallback family name and fail if none found
+ * \param fallback_family_name family name from outside source, used as last resort
* \param info the struct to store results into
* \return success
*
*/
bool ass_get_font_info(ASS_Library *lib, FT_Library ftlib, const char *path,
const char *postscript_name, int index,
- bool require_family_name,
+ const char *fallback_family_name,
ASS_FontProviderMetaData *info);
/**