mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 20:24:19 +01:00
Refactor font output
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#include "font.h"
|
||||
#include "detection/internal.h"
|
||||
|
||||
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* font);
|
||||
|
||||
static void detectFont(const FFinstance* instance, FFFontResult* font)
|
||||
{
|
||||
ffStrbufInit(&font->error);
|
||||
|
||||
for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
|
||||
ffStrbufInit(&font->fonts[i]);
|
||||
|
||||
ffDetectFontImpl(instance, font);
|
||||
|
||||
if(font->error.length > 0)
|
||||
return;
|
||||
|
||||
for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
|
||||
{
|
||||
if(font->fonts[i].length > 0)
|
||||
return;
|
||||
}
|
||||
|
||||
ffStrbufAppendS(&font->error, "No fonts found");
|
||||
}
|
||||
|
||||
const FFFontResult* ffDetectFont(const FFinstance* instance)
|
||||
{
|
||||
FF_DETECTION_INTERNAL_GUARD(FFFontResult,
|
||||
detectFont(instance, &result);
|
||||
);
|
||||
}
|
||||
@@ -4,15 +4,21 @@
|
||||
#define FF_INCLUDED_detection_font_font
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include "util/FFstrbuf.h"
|
||||
#include "util/FFlist.h"
|
||||
|
||||
#define FF_DETECT_FONT_NUM_FONTS 4
|
||||
|
||||
typedef struct FFFontResult
|
||||
{
|
||||
const char* type;
|
||||
FFstrbuf fontPretty;
|
||||
FFstrbuf error;
|
||||
|
||||
/**
|
||||
* Linux / BSD: QT, GTK2, GTK3, GTK4
|
||||
* MacOS: System, User, Unset, Unset
|
||||
* Other: Unset, Unset, Unset, Unset
|
||||
*/
|
||||
FFstrbuf fonts[FF_DETECT_FONT_NUM_FONTS];
|
||||
} FFFontResult;
|
||||
|
||||
const char* ffDetectFontImpl(FFinstance* instance, FFlist* result);
|
||||
const FFFontResult* ffDetectFont(const FFinstance* instance);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/font.h"
|
||||
|
||||
const char* ffDetectFontImpl(FFinstance* instance, FFlist* result)
|
||||
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
{
|
||||
FF_UNUSED(instance, result);
|
||||
return "Font detection is not supported on Android";
|
||||
FF_UNUSED(instance);
|
||||
ffStrbufAppendS(&result->error, "Not implemented");
|
||||
}
|
||||
|
||||
@@ -4,38 +4,27 @@
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#define FF_FONT_MODULE_NAME "Font"
|
||||
|
||||
static void detectFontForType(CTFontUIFontType uiType, FFFontResult* result)
|
||||
static void detectFontForType(CTFontUIFontType uiType, FFstrbuf* font)
|
||||
{
|
||||
CTFontRef ctFont = CTFontCreateUIFontForLanguage(uiType, 12, NULL);
|
||||
ffCfStrGetString(CTFontCopyFullName(ctFont), font);
|
||||
|
||||
ffStrbufInit(&result->fontPretty);
|
||||
ffCfStrGetString(CTFontCopyFullName(ctFont), &result->fontPretty);
|
||||
if(font->length == 0)
|
||||
return;
|
||||
|
||||
FFstrbuf familyName;
|
||||
ffStrbufInit(&familyName);
|
||||
ffCfStrGetString(CTFontCopyFamilyName(ctFont), &familyName);
|
||||
|
||||
if (ffStrbufComp(&familyName, &result->fontPretty) != 0)
|
||||
{
|
||||
ffStrbufAppendF(&result->fontPretty, " (%*s)", familyName.length, familyName.chars);
|
||||
}
|
||||
if (ffStrbufComp(&familyName, font) != 0)
|
||||
ffStrbufAppendF(font, " (%*s)", familyName.length, familyName.chars);
|
||||
|
||||
ffStrbufDestroy(&familyName);
|
||||
}
|
||||
|
||||
const char* ffDetectFontImpl(FFinstance* instance, FFlist* result)
|
||||
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
|
||||
FFFontResult* resultSystem = (FFFontResult*)ffListAdd(result);
|
||||
resultSystem->type = "SYS";
|
||||
detectFontForType(kCTFontUIFontSystem, resultSystem);
|
||||
|
||||
FFFontResult* resultUser = (FFFontResult*)ffListAdd(result);
|
||||
resultUser->type = "USER";
|
||||
detectFontForType(kCTFontUIFontUser, resultUser);
|
||||
|
||||
return NULL;
|
||||
detectFontForType(kCTFontUIFontSystem, &result->fonts[0]);
|
||||
detectFontForType(kCTFontUIFontUser, &result->fonts[1]);
|
||||
}
|
||||
|
||||
@@ -1,51 +1,27 @@
|
||||
#include "detection/qt.h"
|
||||
#include "detection/gtk.h"
|
||||
#include "common/parsing.h"
|
||||
#include "common/font.h"
|
||||
#include "font.h"
|
||||
|
||||
const char* ffDetectFontImpl(FFinstance* instance, FFlist* result)
|
||||
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
{
|
||||
const FFstrbuf* qtRaw = &ffDetectQt(instance)->font;
|
||||
const FFstrbuf* gtk2Raw = &ffDetectGTK2(instance)->font;
|
||||
const FFstrbuf* gtk3Raw = &ffDetectGTK3(instance)->font;
|
||||
const FFstrbuf* gtk4Raw = &ffDetectGTK4(instance)->font;
|
||||
FFfont qt;
|
||||
ffFontInitQt(&qt, ffDetectQt(instance)->font.chars);
|
||||
ffStrbufAppend(&result->fonts[0], &qt.pretty);
|
||||
ffFontDestroy(&qt);
|
||||
|
||||
if(qtRaw->length > 0)
|
||||
{
|
||||
FFfont qt;
|
||||
ffFontInitQt(&qt, qtRaw->chars);
|
||||
FFfont gtk2;
|
||||
ffFontInitPango(>k2, ffDetectGTK2(instance)->font.chars);
|
||||
ffStrbufAppend(&result->fonts[1], >k2.pretty);
|
||||
ffFontDestroy(>k2);
|
||||
|
||||
FFFontResult* resultQt = (FFFontResult *)ffListAdd(result);
|
||||
resultQt->type = "QT";
|
||||
ffStrbufInitCopy(&resultQt->fontPretty, &qt.pretty);
|
||||
FFfont gtk3;
|
||||
ffFontInitPango(>k3, ffDetectGTK3(instance)->font.chars);
|
||||
ffStrbufAppend(&result->fonts[2], >k3.pretty);
|
||||
ffFontDestroy(>k3);
|
||||
|
||||
ffFontDestroy(&qt);
|
||||
}
|
||||
|
||||
if(gtk2Raw->length > 0 || gtk3Raw->length > 0 || gtk4Raw->length > 0)
|
||||
{
|
||||
FFfont gtk2;
|
||||
ffFontInitPango(>k2, gtk2Raw->chars);
|
||||
|
||||
FFfont gtk3;
|
||||
ffFontInitPango(>k3, gtk3Raw->chars);
|
||||
|
||||
FFfont gtk4;
|
||||
ffFontInitPango(>k4, gtk4Raw->chars);
|
||||
|
||||
FFFontResult* resultGtk = (FFFontResult *)ffListAdd(result);
|
||||
resultGtk->type = "GTK";
|
||||
ffStrbufInit(&resultGtk->fontPretty);
|
||||
ffParseGTK(&resultGtk->fontPretty, >k2.pretty, >k3.pretty, >k4.pretty);
|
||||
|
||||
ffFontDestroy(>k2);
|
||||
ffFontDestroy(>k3);
|
||||
ffFontDestroy(>k4);
|
||||
}
|
||||
|
||||
if(result->length == 0)
|
||||
return "No fonts found";
|
||||
|
||||
return NULL;
|
||||
FFfont gtk4;
|
||||
ffFontInitPango(>k4, ffDetectGTK4(instance)->font.chars);
|
||||
ffStrbufAppend(&result->fonts[3], >k4.pretty);
|
||||
ffFontDestroy(>k4);
|
||||
}
|
||||
|
||||
+5
-5
@@ -32,7 +32,7 @@ static inline void applyGTKSettings(FFGTKResult* result, const char* themeName,
|
||||
ffStrbufAppendF(&result->cursorSize, "%i", cursorSize);
|
||||
}
|
||||
|
||||
static void detectGTKFromSettings(FFinstance* instance, FFGTKResult* result)
|
||||
static void detectGTKFromSettings(const FFinstance* instance, FFGTKResult* result)
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
@@ -144,7 +144,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
|
||||
ffStrbufSubstrBefore(configDir, configDirLength);
|
||||
}
|
||||
|
||||
static void detectGTK(FFinstance* instance, const char* version, FFGTKResult* result)
|
||||
static void detectGTK(const FFinstance* instance, const char* version, FFGTKResult* result)
|
||||
{
|
||||
//Mate, Cinnamon and Gnome use dconf to save theme config
|
||||
//On other DEs, this will do nothing
|
||||
@@ -186,17 +186,17 @@ static void detectGTK(FFinstance* instance, const char* version, FFGTKResult* re
|
||||
pthread_mutex_unlock(&mutex); \
|
||||
return &result;
|
||||
|
||||
const FFGTKResult* ffDetectGTK2(FFinstance* instance)
|
||||
const FFGTKResult* ffDetectGTK2(const FFinstance* instance)
|
||||
{
|
||||
FF_DETECT_GTK_IMPL(2)
|
||||
}
|
||||
|
||||
const FFGTKResult* ffDetectGTK3(FFinstance* instance)
|
||||
const FFGTKResult* ffDetectGTK3(const FFinstance* instance)
|
||||
{
|
||||
FF_DETECT_GTK_IMPL(3)
|
||||
}
|
||||
|
||||
const FFGTKResult* ffDetectGTK4(FFinstance* instance)
|
||||
const FFGTKResult* ffDetectGTK4(const FFinstance* instance)
|
||||
{
|
||||
FF_DETECT_GTK_IMPL(4)
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,8 +14,8 @@ typedef struct FFGTKResult
|
||||
FFstrbuf cursorSize;
|
||||
} FFGTKResult;
|
||||
|
||||
const FFGTKResult* ffDetectGTK2(FFinstance* instance);
|
||||
const FFGTKResult* ffDetectGTK4(FFinstance* instance);
|
||||
const FFGTKResult* ffDetectGTK3(FFinstance* instance);
|
||||
const FFGTKResult* ffDetectGTK2(const FFinstance* instance);
|
||||
const FFGTKResult* ffDetectGTK4(const FFinstance* instance);
|
||||
const FFGTKResult* ffDetectGTK3(const FFinstance* instance);
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ static void detectLXQt(const FFinstance* instance, FFQtResult* result)
|
||||
});
|
||||
}
|
||||
|
||||
const FFQtResult* ffDetectQt(FFinstance* instance)
|
||||
const FFQtResult* ffDetectQt(const FFinstance* instance)
|
||||
{
|
||||
static FFQtResult result;
|
||||
|
||||
|
||||
+1
-1
@@ -13,6 +13,6 @@ typedef struct FFQtResult
|
||||
FFstrbuf font;
|
||||
} FFQtResult;
|
||||
|
||||
const FFQtResult* ffDetectQt(FFinstance* instance);
|
||||
const FFQtResult* ffDetectQt(const FFinstance* instance);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user