summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2024-03-31 02:43:20 +0200
committerOleg Oshmyan <chortos@inbox.lv>2024-04-08 00:44:36 +0300
commit6b895b478d83acc2ffa261c38d3b491b32d46a0b (patch)
tree2c72ba13f91ecd7f676ffae257a309d9b2c6555d
parentdb4b720172a426aef183c6912e5847d60250b947 (diff)
downloadlibass-6b895b478d83acc2ffa261c38d3b491b32d46a0b.tar.bz2
libass-6b895b478d83acc2ffa261c38d3b491b32d46a0b.tar.xz
directwrite: query GDI-enumerated fonts by full name, not family name
Fixes: https://github.com/libass/libass/issues/744
-rw-r--r--libass/ass_directwrite.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/libass/ass_directwrite.c b/libass/ass_directwrite.c
index 1c7a3f0..40a0591 100644
--- a/libass/ass_directwrite.c
+++ b/libass/ass_directwrite.c
@@ -726,7 +726,21 @@ static int CALLBACK font_enum_proc(const ENUMLOGFONTW *lpelf,
if (FontType & RASTER_FONTTYPE)
goto cleanup;
- hFont = CreateFontIndirectW(&lpelf->elfLogFont);
+ LOGFONTW lf = lpelf->elfLogFont;
+ // lf.lfFaceName currently holds the font family name.
+ // The family may contain several fonts with equal numerical parameters
+ // but distinct full names. If we pass lf to CreateFontIndirect as is,
+ // we will miss this variety and merely get the same one font multiple
+ // times. Try to increase our chances of seeing all the right fonts
+ // by replacing the family name by the full name. There's some chance
+ // that this in turn selects some *other* family's fonts and misses
+ // the requested family, but we would rather take this chance than
+ // add every font twice (via the family name and via the full name).
+ // lfFaceName can hold up to LF_FACESIZE wchars; truncate longer names.
+ wcsncpy(lf.lfFaceName, lpelf->elfFullName, LF_FACESIZE - 1);
+ lf.lfFaceName[LF_FACESIZE - 1] = L'\0';
+
+ hFont = CreateFontIndirectW(&lf);
if (!hFont)
goto cleanup;
@@ -737,7 +751,7 @@ static int CALLBACK font_enum_proc(const ENUMLOGFONTW *lpelf,
wchar_t selected_name[LF_FACESIZE];
if (!GetTextFaceW(hdc, LF_FACESIZE, selected_name))
goto cleanup;
- if (wcsncmp(selected_name, lpelf->elfLogFont.lfFaceName, LF_FACESIZE)) {
+ if (wcsncmp(selected_name, lf.lfFaceName, LF_FACESIZE)) {
// A different font was selected. This can happen if the requested
// name is subject to charset-specific font substitution while
// EnumFont... enumerates additional charsets contained in the font.