commit e0eeaa3985a7d6eb15968a4969ac27a66e38ccb2
parent 6536b38812bb414f1304e00934feede28f0a922e
Author: nibo <nibo@relim.de>
Date: Wed, 22 Jan 2025 19:55:28 +0100
Load font file only if it contains one font
If a font file has multiple fonts in it and one of them
matched in lorid's search for a specified font then
pdfio doesn't extract the matched font but uses probably
the first.
I don't know what pdfio exactly does I only saw wrong
fonts being used after selecting a font file with
multiple fonts.
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/out_pdf.c b/out_pdf.c
@@ -230,6 +230,21 @@ fonts_get_all(struct ChoSong **songs, struct Config *config)
return fonts;
}
+static int
+fontpath_count_fonts(FcChar8 *path)
+{
+ int count;
+ FcFontSet *set;
+ set = FcFontSetCreate();
+ if (!FcFileScan(set, NULL, NULL, NULL, path, false)) {
+ LOG_DEBUG("fontpath_count_fonts failed.");
+ return -1;
+ }
+ count = set->nfont;
+ FcFontSetDestroy(set);
+ return count;
+}
+
static char *
fontpath_find(struct Font *font, enum FontType font_type)
{
@@ -289,7 +304,10 @@ fontpath_find(struct Font *font, enum FontType font_type)
FcChar8 *file;
for (int i=0; i<set->nfont; i++) {
if (FcPatternGetString(set->fonts[i], FC_FILE, 0, &file) == FcResultMatch) {
- if (!file_extension_equals((const char *)file, "ttc")) {
+ if (
+ !file_extension_equals((const char *)file, "ttc") &&
+ fontpath_count_fonts(file) == 1
+ ) {
filepath = strdup((const char *)file);
break;
}