From 6c8348a598cd79874007e233b6f0f409185093b1 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Tue, 1 Sep 2015 15:47:40 +0200 Subject: directwrite, coretext: implement substitutions This adds simple and sensible substitutions for generic font family names. A helper function is introduced to reduce code duplication. --- libass/ass_coretext.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libass/ass_coretext.c') diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c index 35533248..877018d5 100644 --- a/libass/ass_coretext.c +++ b/libass/ass_coretext.c @@ -25,6 +25,12 @@ #define SAFE_CFRelease(x) do { if (x) CFRelease(x); } while(0) +static const ASS_FontMapping font_substitutions[] = { + {"sans-serif", "Helvetica"}, + {"serif", "Times"}, + {"monospace", "Courier"} +}; + static char *cfstr2buf(CFStringRef string) { const int encoding = kCFStringEncodingUTF8; @@ -266,10 +272,18 @@ static char *get_fallback(void *priv, const char *family, uint32_t codepoint) return res_family; } +static void get_substitutions(void *priv, const char *name, + ASS_FontProviderMetaData *meta) +{ + const int n = sizeof(font_substitutions) / sizeof(font_substitutions[0]); + ass_map_font(font_substitutions, n, name, meta); +} + static ASS_FontProviderFuncs coretext_callbacks = { .check_glyph = check_glyph, .destroy_font = destroy_font, .match_fonts = match_fonts, + .get_substitutions = get_substitutions, .get_fallback = get_fallback, }; -- cgit v1.2.3