From ac052de8f7b6b6976ab89601388a1bd4d421e58b Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Thu, 1 Jun 2017 11:25:09 +0200 Subject: directwrite: fix font collections DirectWrite's FontFileStream does not actually use the data of a specific font in a collection, which was an expectation of the existing code. It simply returns a stream to the underlying file, collection or not. So we need to get the index of the font. This needs to be done lazily as this information is only available in a FontFace, which is expensive to initialize. Add a new optional font provider function for lazy initialization of the index and use it. This is similar to the check_postscript callback. Fixes libass#275. v2: fix type of returned value. --- libass/ass_directwrite.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libass/ass_directwrite.c') diff --git a/libass/ass_directwrite.c b/libass/ass_directwrite.c index 45d2a2e..d15cbcd 100644 --- a/libass/ass_directwrite.c +++ b/libass/ass_directwrite.c @@ -351,6 +351,19 @@ static bool check_postscript(void *data) type == DWRITE_FONT_FACE_TYPE_TYPE1; } +/* + * Lazily return index of font. It requires the FontFace to be present, which is expensive to initialize. + */ +static unsigned get_font_index(void *data) +{ + FontPrivate *priv = (FontPrivate *)data; + + if (!init_font_private_face(priv)) + return 0; + + return IDWriteFontFace_GetIndex(priv->face); +} + /* * Check if the passed font has a specific unicode character. */ @@ -719,6 +732,7 @@ static ASS_FontProviderFuncs directwrite_callbacks = { .destroy_provider = destroy_provider, .get_substitutions = get_substitutions, .get_fallback = get_fallback, + .get_font_index = get_font_index, }; typedef HRESULT (WINAPI *DWriteCreateFactoryFn)( -- cgit v1.2.3