summaryrefslogtreecommitdiff
path: root/src/fontpack.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-11-12 07:12:48 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-11-12 07:12:48 +0200
commitdc4185b6cb5a5e12604d2910830061b5a4a0fd9a (patch)
treea2e1c5a1b4dc6c59d34fb0ab6f26a451475fefdd /src/fontpack.c
parenteed83717b6125ba655be9ffd618f301ef97948b2 (diff)
FontPack: Font dropdown includes IDs if ambiguous
If some fonts have the same human-readable name, the unique font ID will be added to show which font it actually is.
Diffstat (limited to 'src/fontpack.c')
-rw-r--r--src/fontpack.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/fontpack.c b/src/fontpack.c
index c12b2ddc..bbf1833e 100644
--- a/src/fontpack.c
+++ b/src/fontpack.c
@@ -550,6 +550,21 @@ static void sortSpecs_Fonts_(iFonts *d) {
550 sort_Array(&d->specOrder, cmpPriority_FontSpecPtr_); 550 sort_Array(&d->specOrder, cmpPriority_FontSpecPtr_);
551} 551}
552 552
553static void disambiguateSpecs_Fonts_(iFonts *d) {
554 /* Names of specs with the same human-readable label are augmented with the font ID. */
555 const size_t numSpecs = size_PtrArray(&d->specOrder);
556 for (size_t i = 0; i < numSpecs; i++) {
557 iFontSpec *spec1 = at_PtrArray(&d->specOrder, i);
558 for (size_t j = i + 1; j < numSpecs; j++) {
559 iFontSpec *spec2 = at_PtrArray(&d->specOrder, j);
560 if (equalCase_String(&spec1->name, &spec2->name)) {
561 appendFormat_String(&spec1->name, " [%s]", cstr_String(&spec1->id));
562 appendFormat_String(&spec2->name, " [%s]", cstr_String(&spec2->id));
563 }
564 }
565 }
566}
567
553static const iString *userFontsDirectory_Fonts_(const iFonts *d) { 568static const iString *userFontsDirectory_Fonts_(const iFonts *d) {
554 return collect_String(concatCStr_Path(&d->userDir, "fonts")); 569 return collect_String(concatCStr_Path(&d->userDir, "fonts"));
555} 570}
@@ -677,8 +692,12 @@ void init_Fonts(const char *userDir) {
677 pushBack_PtrArray(&d->packs, pack); 692 pushBack_PtrArray(&d->packs, pack);
678 } 693 }
679 } 694 }
680 } 695 }
681 sortSpecs_Fonts_(d); 696 sortSpecs_Fonts_(d);
697 disambiguateSpecs_Fonts_(d);
698#if !defined (NDEBUG)
699 printf("[FontPack] %zu fonts available\n", size_Array(&d->specOrder));
700#endif
682} 701}
683 702
684void deinit_Fonts(void) { 703void deinit_Fonts(void) {