diff options
author | Oleg Oshmyan <chortos@inbox.lv> | 2021-05-21 23:07:42 +0300 |
---|---|---|
committer | Oleg Oshmyan <chortos@inbox.lv> | 2021-06-07 13:42:02 +0200 |
commit | bfffc82c88b55071901f7d00ebe3e66168cd5a6d (patch) | |
tree | 11267ee2f148ed4d1d47e06be23d696223ef91f9 | |
parent | 11607d56bd64c54f5a7bbdc631d96b0bb29fc8a4 (diff) | |
download | libass-bfffc82c88b55071901f7d00ebe3e66168cd5a6d.tar.bz2 libass-bfffc82c88b55071901f7d00ebe3e66168cd5a6d.tar.xz |
coretext: deduplicate found fonts in match_fonts
We ask Core Text to match multiple name fields, and a single font may
match several at once. In this case, by default, Core Text duly returns
the font multiple times, and we add it to fontselect multiple times.
This does not break anything, but it is a waste, so ask Core Text
to deduplicate the returned list.
This is supposedly available since Mac OS X 10.5.
We support Core Text on 10.6+.
-rw-r--r-- | libass/ass_coretext.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libass/ass_coretext.c b/libass/ass_coretext.c index 64ec8ee..f331639 100644 --- a/libass/ass_coretext.c +++ b/libass/ass_coretext.c @@ -242,7 +242,21 @@ static void match_fonts(void *priv, ASS_Library *lib, ASS_FontProvider *provider if (!descriptors) goto cleanup; - ctcoll = CTFontCollectionCreateWithFontDescriptors(descriptors, 0); + const int nonzero = 1; + CFNumberRef cfnonzero = CFNumberCreate(NULL, kCFNumberIntType, &nonzero); + if (!cfnonzero) + goto cleanup; + CFDictionaryRef options = + CFDictionaryCreate(NULL, + (const void **)&kCTFontCollectionRemoveDuplicatesOption, + (const void **)&cfnonzero, + 1, NULL, NULL); + CFRelease(cfnonzero); + if (!options) + goto cleanup; + + ctcoll = CTFontCollectionCreateWithFontDescriptors(descriptors, options); + CFRelease(options); if (!ctcoll) goto cleanup; |