From faa5203fe181e50ce1377f09e451e90906ffe9e3 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Tue, 9 Jun 2015 01:20:28 +0200 Subject: fontselect: add fallback and substitution callbacks Add callbacks to introduce more sane fallback handling and font alias substitutions. --- libass/ass_coretext.c | 6 ++++-- libass/ass_fontconfig.c | 2 ++ libass/ass_fontselect.c | 2 ++ libass/ass_types.h | 56 ++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 57 insertions(+), 9 deletions(-) (limited to 'libass') diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c index 5347541..66277a5 100644 --- a/libass/ass_coretext.c +++ b/libass/ass_coretext.c @@ -270,10 +270,12 @@ static ASS_FontProviderFuncs coretext_callbacks = { destroy_font, NULL, #if CT_FONTS_EAGER_LOAD - NULL + NULL, #else - match_fonts + match_fonts, #endif + NULL, + NULL }; ASS_FontProvider * diff --git a/libass/ass_fontconfig.c b/libass/ass_fontconfig.c index 2d3ea3f..c91c074 100644 --- a/libass/ass_fontconfig.c +++ b/libass/ass_fontconfig.c @@ -131,6 +131,8 @@ static ASS_FontProviderFuncs fontconfig_callbacks = { NULL, destroy, NULL, + NULL, + NULL }; ASS_FontProvider * diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c index 174fe1d..38a1a89 100644 --- a/libass/ass_fontselect.c +++ b/libass/ass_fontselect.c @@ -195,6 +195,8 @@ static ASS_FontProviderFuncs ft_funcs = { destroy_font_ft, NULL, NULL, + NULL, + NULL }; /** diff --git a/libass/ass_types.h b/libass/ass_types.h index c1a14b4..545724d 100644 --- a/libass/ass_types.h +++ b/libass/ass_types.h @@ -47,8 +47,8 @@ typedef struct parser_priv ASS_ParserPriv; typedef struct ass_library ASS_Library; typedef struct font_provider ASS_FontProvider; - /* Font Provider */ +typedef struct font_provider_meta_data ASS_FontProviderMetaData; /** * Get font data. This is a stream interface which can be used as an @@ -104,13 +104,55 @@ typedef void (*MatchFontsFunc)(ASS_Library *lib, ASS_FontProvider *provider, char *name); +/** + * Substitute font name by another. This implements generic font family + * substitutions (e.g. sans-serif, serif, monospace) as well as font aliases. + * + * The generic families should map to sensible platform-specific font families. + * Aliases are sometimes used to map from common fonts that don't exist on + * a particular platform to similar alternatives. For example, a Linux + * system with fontconfig may map "Arial" to "Liberation Sans" and Windows + * maps "Helvetica" to "Arial". + * + * This is called by fontselect when a new logical font is created. The font + * provider set as default is used. + * + * \param priv font provider private data + * \param name input string for substitution, as specified in the script + * \return output string for substitution, allocated with malloc(), must be + * freed by caller, can be NULL if no substitution was done. + */ +typedef char *(*SubstituteFontFunc)(void *priv, const char *name); + +/** + * Get an appropriate fallback font for a given codepoint. + * + * This is called by fontselect whenever a glyph is not found in the + * physical font list of a logical font. fontselect will try to add the + * font family with match_fonts if it does not exist in the font list + * add match_fonts is not NULL. Note that the returned font family should + * contain the requested codepoint. + * + * Note that fontselect uses the font provider set as default to determine + * fallbacks. + * + * \param font_priv font private data + * \param codepoint Unicode codepoint (UTF-32) + * \return output font family, allocated with malloc(), must be freed + * by caller. + */ +typedef char *(*GetFallbackFunc)(void *font_priv, + ASS_FontProviderMetaData *meta, + uint32_t codepoint); + typedef struct font_provider_funcs { - GetDataFunc get_data; - CheckGlyphFunc check_glyph; - DestroyFontFunc destroy_font; - DestroyProviderFunc destroy_provider; - MatchFontsFunc match_fonts; - // XXX: add function for alias handling + GetDataFunc get_data; /* optional/mandatory */ + CheckGlyphFunc check_glyph; /* mandatory */ + DestroyFontFunc destroy_font; /* optional */ + DestroyProviderFunc destroy_provider; /* optional */ + MatchFontsFunc match_fonts; /* optional */ + SubstituteFontFunc subst_font; /* optional */ + GetFallbackFunc fallback_font; /* optional */ } ASS_FontProviderFuncs; /* -- cgit v1.2.3