mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Font: code refactor
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#ifndef FF_INCLUDED_parsing_h
|
||||
#define FF_INCLUDED_parsing_h
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct FFVersion
|
||||
|
||||
@@ -9,6 +9,7 @@ static void detectFont(const FFinstance* instance, FFFontResult* font)
|
||||
|
||||
for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
|
||||
ffStrbufInit(&font->fonts[i]);
|
||||
ffStrbufInit(&font->display);
|
||||
|
||||
ffDetectFontImpl(instance, font);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ typedef struct FFFontResult
|
||||
* Other: Unset, Unset, Unset, Unset
|
||||
*/
|
||||
FFstrbuf fonts[FF_DETECT_FONT_NUM_FONTS];
|
||||
FFstrbuf display;
|
||||
} FFFontResult;
|
||||
|
||||
const FFFontResult* ffDetectFont(const FFinstance* instance);
|
||||
|
||||
@@ -4,6 +4,23 @@
|
||||
|
||||
#import <AppKit/NSFont.h>
|
||||
|
||||
static void generateString(FFFontResult* font)
|
||||
{
|
||||
if(font->fonts[0].length > 0)
|
||||
{
|
||||
ffStrbufAppend(&font->display, &font->fonts[0]);
|
||||
ffStrbufAppendS(&font->display, " [System]");
|
||||
if(font->fonts[1].length > 0)
|
||||
ffStrbufAppendS(&font->display, ", ");
|
||||
}
|
||||
|
||||
if(font->fonts[1].length > 0)
|
||||
{
|
||||
ffStrbufAppend(&font->display, &font->fonts[1]);
|
||||
ffStrbufAppendS(&font->display, " [User]");
|
||||
}
|
||||
}
|
||||
|
||||
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
@@ -11,4 +28,5 @@ void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
ffStrbufAppendS(&result->fonts[1], [NSFont userFontOfSize:12].familyName.UTF8String);
|
||||
ffStrbufAppendS(&result->fonts[2], [NSFont monospacedSystemFontOfSize:12 weight:400].familyName.UTF8String);
|
||||
ffStrbufAppendS(&result->fonts[3], [NSFont userFixedPitchFontOfSize:12].familyName.UTF8String);
|
||||
generateString(result);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,23 @@
|
||||
#include "common/font.h"
|
||||
#include "common/parsing.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
#include "detection/gtk_qt/gtk_qt.h"
|
||||
#include "font.h"
|
||||
|
||||
static void generateString(FFFontResult* font)
|
||||
{
|
||||
ffParseGTK(&font->display, &font->fonts[1], &font->fonts[2], &font->fonts[3]);
|
||||
|
||||
if(font->fonts[0].length > 0)
|
||||
{
|
||||
if(font->display.length > 0)
|
||||
ffStrbufAppendS(&font->display, ", ");
|
||||
|
||||
ffStrbufAppend(&font->display, &font->fonts[0]);
|
||||
ffStrbufAppendS(&font->display, " [QT]");
|
||||
}
|
||||
}
|
||||
|
||||
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
{
|
||||
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
|
||||
@@ -32,4 +47,6 @@ void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
ffFontInitPango(>k4, ffDetectGTK4(instance)->font.chars);
|
||||
ffStrbufAppend(&result->fonts[3], >k4.pretty);
|
||||
ffFontDestroy(>k4);
|
||||
|
||||
generateString(result);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
static void generateString(FFFontResult* font)
|
||||
{
|
||||
const char* types[] = { "Caption", "Menu", "Message", "Status" };
|
||||
for(uint32_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i)
|
||||
{
|
||||
if(i == 0 || !ffStrbufEqual(&font->fonts[i - 1], &font->fonts[i]))
|
||||
{
|
||||
if(i > 0)
|
||||
ffStrbufAppendS(&font->display, "], ");
|
||||
ffStrbufAppendF(&font->display, "%s [%s", font->fonts[i].chars, types[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffStrbufAppendS(&font->display, " / ");
|
||||
ffStrbufAppendS(&font->display, types[i]);
|
||||
}
|
||||
}
|
||||
ffStrbufAppendC(&font->display, ']');
|
||||
}
|
||||
|
||||
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
@@ -19,4 +39,6 @@ void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
|
||||
if(fonts[i]->lfHeight < 0)
|
||||
ffStrbufAppendF(&result->fonts[i], " (%dpt)", (int)-fonts[i]->lfHeight);
|
||||
}
|
||||
|
||||
generateString(result);
|
||||
}
|
||||
|
||||
+4
-71
@@ -4,77 +4,10 @@
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
|
||||
#define FF_FONT_MODULE_NAME "Font"
|
||||
#define FF_FONT_NUM_FORMAT_ARGS 4
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
#include "common/parsing.h"
|
||||
|
||||
static void printFont(const FFFontResult* font)
|
||||
{
|
||||
FFstrbuf gtk;
|
||||
ffStrbufInit(>k);
|
||||
ffParseGTK(>k, &font->fonts[1], &font->fonts[2], &font->fonts[3]);
|
||||
|
||||
if(font->fonts[0].length > 0)
|
||||
{
|
||||
printf("%s [QT]", font->fonts[0].chars);
|
||||
if(gtk.length > 0)
|
||||
fputs(", ", stdout);
|
||||
}
|
||||
|
||||
ffStrbufWriteTo(>k, stdout);
|
||||
ffStrbufDestroy(>k);
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
static void printFont(const FFFontResult* font)
|
||||
{
|
||||
if(font->fonts[0].length > 0)
|
||||
{
|
||||
printf("%s [System]", font->fonts[0].chars);
|
||||
if(font->fonts[1].length > 0)
|
||||
fputs(", ", stdout);
|
||||
}
|
||||
|
||||
if(font->fonts[1].length > 0)
|
||||
printf("%s [User]", font->fonts[1].chars);
|
||||
}
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
static void printFont(const FFFontResult* font)
|
||||
{
|
||||
const char* types[] = { "Caption", "Menu", "Message", "Status" };
|
||||
for(uint32_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i)
|
||||
{
|
||||
if(i == 0 || !ffStrbufEqual(&font->fonts[i - 1], &font->fonts[i]))
|
||||
{
|
||||
if(i > 0)
|
||||
fputs("], ", stdout);
|
||||
printf("%s [%s", font->fonts[i].chars, types[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" / %s", types[i]);
|
||||
}
|
||||
}
|
||||
putchar(']');
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void printFont(const FFFontResult* font)
|
||||
{
|
||||
FF_UNUSED(font);
|
||||
}
|
||||
|
||||
#endif
|
||||
#define FF_FONT_NUM_FORMAT_ARGS (FF_DETECT_FONT_NUM_FONTS + 1)
|
||||
|
||||
void ffPrintFont(FFinstance* instance)
|
||||
{
|
||||
assert(FF_DETECT_FONT_NUM_FONTS == FF_FONT_NUM_FORMAT_ARGS);
|
||||
|
||||
const FFFontResult* font = ffDetectFont(instance);
|
||||
|
||||
if(font->error.length > 0)
|
||||
@@ -86,8 +19,7 @@ void ffPrintFont(FFinstance* instance)
|
||||
if(instance->config.font.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font.key);
|
||||
printFont(font);
|
||||
putchar('\n');
|
||||
ffStrbufPutTo(&font->display, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -95,7 +27,8 @@ void ffPrintFont(FFinstance* instance)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[0]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[1]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[2]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[3]}
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[3]},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->display},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user