From abb060ba17024759a7cfcc7b9256742e1c1e418b Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 21 Jan 2022 13:50:56 +0200 Subject: Fonts: Show abbreviated list of names on "about:fonts" A big set can be viewed separately to see all the individual fonts. --- src/fontpack.c | 19 ++++++++++++++----- src/fontpack.h | 2 +- src/ui/documentwidget.c | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/fontpack.c b/src/fontpack.c index 924d4781..96006226 100644 --- a/src/fontpack.c +++ b/src/fontpack.c @@ -749,7 +749,7 @@ const iPtrArray *listSpecsByPriority_Fonts(void) { return &fonts_.specOrder; } -iString *infoText_FontPack(const iFontPack *d) { +iString *infoText_FontPack(const iFontPack *d, iBool isFull) { const iFontPack *installed = pack_Fonts(cstr_String(&d->id)); const iBool isInstalled = (installed != NULL); const int installedVersion = installed ? installed->version : 0; @@ -758,9 +758,17 @@ iString *infoText_FontPack(const iFontPack *d) { size_t sizeInBytes = 0; iPtrSet *uniqueFiles = new_PtrSet(); iStringList *names = new_StringList(); + size_t numNames = 0; + iBool isAbbreviated = iFalse; iConstForEach(PtrArray, i, listSpecs_FontPack(d)) { const iFontSpec *spec = i.ptr; - pushBack_StringList(names, &spec->name); + numNames++; + if (isFull || size_StringList(names) < 20) { + pushBack_StringList(names, &spec->name); + } + else { + isAbbreviated = iTrue; + } iForIndices(j, spec->styles) { insert_PtrSet(uniqueFiles, spec->styles[j]->sourceData.i); } @@ -778,11 +786,12 @@ iString *infoText_FontPack(const iFontPack *d) { if (!endsWith_String(str, "(")) { appendCStr_String(str, ", "); } - appendCStr_String(str, formatCStrs_Lang("num.fonts.n", size_StringList(names))); + appendCStr_String(str, formatCStrs_Lang("num.fonts.n", numNames)); } appendFormat_String(str, ")"); } - appendFormat_String(str, " \u2014 %s\n", cstrCollect_String(joinCStr_StringList(names, ", "))); + appendFormat_String(str, " \u2014 %s%s\n", cstrCollect_String(joinCStr_StringList(names, ", ")), + isAbbreviated ? ", ..." : ""); if (isInstalled && installedVersion != d->version) { appendCStr_String(str, format_Lang("${fontpack.meta.version}\n", d->version)); } @@ -946,7 +955,7 @@ const iString *infoPage_Fonts(iRangecc query) { appendFormat_String(str, "### %s\n", isEmpty_String(packId) ? "fonts.ini" : cstr_String(packId)); - append_String(str, collect_String(infoText_FontPack(pack))); + append_String(str, collect_String(infoText_FontPack(pack, iFalse))); appendFormat_String(str, "=> %s ${fontpack.meta.viewfile}\n", cstrCollect_String(makeFileUrl_String(&spec->sourcePath))); if (pack->isStandalone) { diff --git a/src/fontpack.h b/src/fontpack.h index 27ecd087..f6d4d483 100644 --- a/src/fontpack.h +++ b/src/fontpack.h @@ -160,7 +160,7 @@ const iString * loadPath_FontPack (const iFontPack *); /* may return N iBool isDisabled_FontPack (const iFontPack *); iBool isReadOnly_FontPack (const iFontPack *); const iPtrArray * listSpecs_FontPack (const iFontPack *); -iString * infoText_FontPack (const iFontPack *); +iString * infoText_FontPack (const iFontPack *, iBool isFull); const iArray * actions_FontPack (const iFontPack *, iBool showInstalled); const iString * idFromUrl_FontPack (const iString *url); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index fdb55232..03119ca2 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -2659,7 +2659,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, if (loadArchive_FontPack(fp, zip)) { appendFormat_String(&str, "# " fontpack_Icon "%s\n%s", cstr_String(id_FontPack(fp).id), - cstrCollect_String(infoText_FontPack(fp))); + cstrCollect_String(infoText_FontPack(fp, iTrue))); } appendCStr_String(&str, "\n"); appendCStr_String(&str, cstr_Lang("fontpack.help")); -- cgit v1.2.3