From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/detection/font/font.c | 19 +++++++++++ src/detection/font/font.h | 20 ++++++++++++ src/detection/font/font_apple.m | 37 ++++++++++++++++++++++ src/detection/font/font_haiku.cpp | 54 +++++++++++++++++++++++++++++++ src/detection/font/font_linux.c | 53 +++++++++++++++++++++++++++++++ src/detection/font/font_nosupport.c | 7 +++++ src/detection/font/font_windows.c | 63 +++++++++++++++++++++++++++++++++++++ 7 files changed, 253 insertions(+) create mode 100644 src/detection/font/font.c create mode 100644 src/detection/font/font.h create mode 100644 src/detection/font/font_apple.m create mode 100644 src/detection/font/font_haiku.cpp create mode 100644 src/detection/font/font_linux.c create mode 100644 src/detection/font/font_nosupport.c create mode 100644 src/detection/font/font_windows.c (limited to 'src/detection/font') diff --git a/src/detection/font/font.c b/src/detection/font/font.c new file mode 100644 index 0000000..c651f29 --- /dev/null +++ b/src/detection/font/font.c @@ -0,0 +1,19 @@ +#include "font.h" + +const char* ffDetectFontImpl(FFFontResult* font); + +const char* ffDetectFont(FFFontResult* font) { + const char* error = ffDetectFontImpl(font); + + if (error) { + return error; + } + + for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i) { + if (font->fonts[i].length > 0) { + return NULL; + } + } + + return "No fonts found"; +} diff --git a/src/detection/font/font.h b/src/detection/font/font.h new file mode 100644 index 0000000..af04c6d --- /dev/null +++ b/src/detection/font/font.h @@ -0,0 +1,20 @@ +#pragma once + +#include "fastfetch.h" +#include "modules/font/option.h" + +enum { FF_DETECT_FONT_NUM_FONTS = 4 }; + +typedef struct FFFontResult { + /** + * Linux / BSD: Qt, GTK2, GTK3, GTK4 + * MacOS: System, User, System Mono, User Mono + * Windows: Caption, Menu, Message, Status + * Haiku: Plain, Menu, Bold, Mono + * Other: Unset, Unset, Unset, Unset + */ + FFstrbuf fonts[FF_DETECT_FONT_NUM_FONTS]; + FFstrbuf display; +} FFFontResult; + +const char* ffDetectFont(FFFontResult* font); diff --git a/src/detection/font/font_apple.m b/src/detection/font/font_apple.m new file mode 100644 index 0000000..e8aff3c --- /dev/null +++ b/src/detection/font/font_apple.m @@ -0,0 +1,37 @@ +#include "common/font.h" +#include "common/io.h" +#include "font.h" + +#import + +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]"); + } +} + +const char* ffDetectFontImpl(FFFontResult* result) +{ + ffStrbufAppendS(&result->fonts[0], [NSFont systemFontOfSize:12].familyName.UTF8String); + ffStrbufAppendS(&result->fonts[1], [NSFont userFontOfSize:12].familyName.UTF8String); + #ifdef MAC_OS_X_VERSION_10_15 + ffStrbufAppendS(&result->fonts[2], [NSFont monospacedSystemFontOfSize:12 weight:400].familyName.UTF8String); + #else + ffStrbufAppendS(&result->fonts[2], ""); + #endif + ffStrbufAppendS(&result->fonts[3], [NSFont userFixedPitchFontOfSize:12].familyName.UTF8String); + generateString(result); + + return NULL; +} diff --git a/src/detection/font/font_haiku.cpp b/src/detection/font/font_haiku.cpp new file mode 100644 index 0000000..dc29dd0 --- /dev/null +++ b/src/detection/font/font_haiku.cpp @@ -0,0 +1,54 @@ +extern "C" { +#include "font.h" +} + +#include +#include +#include + +extern "C" { +const char* ffDetectFontImpl(FFFontResult* result); +} + +static void generateString(FFFontResult* font) { + const char* types[] = { "Plain", "Menu", "Bold", "Mono" }; + for (uint32_t i = 0; i < ARRAY_SIZE(types); ++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, ']'); +} + +const char* ffDetectFontImpl(FFFontResult* result) { + struct menu_info menuInfo; + const BFont* f; + // We need a valid be_app to query the app_server here. + BApplication app("application/x-vnd.fastfetch-cli-fastfetch"); + + if ((f = be_plain_font) != NULL) { + f->GetFamilyAndStyle(&menuInfo.f_family, &menuInfo.f_style); + ffStrbufAppendF(&result->fonts[0], "%s %s (%dpt)", menuInfo.f_family, menuInfo.f_style, (int) f->Size()); + } + if (get_menu_info(&menuInfo) == B_OK) { + ffStrbufAppendF(&result->fonts[1], "%s %s (%dpt)", menuInfo.f_family, menuInfo.f_style, (int) menuInfo.font_size); + } + if ((f = be_bold_font) != NULL) { + f->GetFamilyAndStyle(&menuInfo.f_family, &menuInfo.f_style); + ffStrbufAppendF(&result->fonts[2], "%s %s (%dpt)", menuInfo.f_family, menuInfo.f_style, (int) f->Size()); + } + if ((f = be_fixed_font) != NULL) { + f->GetFamilyAndStyle(&menuInfo.f_family, &menuInfo.f_style); + ffStrbufAppendF(&result->fonts[3], "%s %s (%dpt)", menuInfo.f_family, menuInfo.f_style, (int) f->Size()); + } + + generateString(result); + + return NULL; +} diff --git a/src/detection/font/font_linux.c b/src/detection/font/font_linux.c new file mode 100644 index 0000000..5e82b68 --- /dev/null +++ b/src/detection/font/font_linux.c @@ -0,0 +1,53 @@ +#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) { + if (font->fonts[0].length > 0) { + ffStrbufAppend(&font->display, &font->fonts[0]); + ffStrbufAppendS(&font->display, " [Qt]"); + + for (uint8_t i = 1; i < ARRAY_SIZE(font->fonts); i++) { + if (font->fonts[i].length > 0) { + ffStrbufAppendS(&font->display, ", "); + break; + } + } + } + + ffParseGTK(&font->display, &font->fonts[1], &font->fonts[2], &font->fonts[3]); +} + +const char* ffDetectFontImpl(FFFontResult* result) { + const FFDisplayServerResult* wmde = ffConnectDisplayServer(); + + if (ffStrbufIgnCaseEqualS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY)) { + return "Font isn't supported in TTY"; + } + + FFfont qt; + ffFontInitQt(&qt, ffDetectQt()->font.chars); + ffStrbufAppend(&result->fonts[0], &qt.pretty); + ffFontDestroy(&qt); + + FFfont gtk2; + ffFontInitPango(>k2, ffDetectGTK2()->font.chars); + ffStrbufAppend(&result->fonts[1], >k2.pretty); + ffFontDestroy(>k2); + + FFfont gtk3; + ffFontInitPango(>k3, ffDetectGTK3()->font.chars); + ffStrbufAppend(&result->fonts[2], >k3.pretty); + ffFontDestroy(>k3); + + FFfont gtk4; + ffFontInitPango(>k4, ffDetectGTK4()->font.chars); + ffStrbufAppend(&result->fonts[3], >k4.pretty); + ffFontDestroy(>k4); + + generateString(result); + + return NULL; +} diff --git a/src/detection/font/font_nosupport.c b/src/detection/font/font_nosupport.c new file mode 100644 index 0000000..26f9ec6 --- /dev/null +++ b/src/detection/font/font_nosupport.c @@ -0,0 +1,7 @@ +#include "fastfetch.h" +#include "font.h" + +const char* ffDetectFontImpl(FF_A_UNUSED FFFontResult* result) { + FF_UNUSED(result); + return "Not supported on this platform"; +} diff --git a/src/detection/font/font_windows.c b/src/detection/font/font_windows.c new file mode 100644 index 0000000..4fc28d3 --- /dev/null +++ b/src/detection/font/font_windows.c @@ -0,0 +1,63 @@ +#include "font.h" +#include "common/windows/unicode.h" +#include "common/windows/registry.h" + +#include + +static void generateString(FFFontResult* font) { + const char* types[] = { "Caption", "Menu", "Message", "Status" }; + for (uint32_t i = 0; i < ARRAY_SIZE(types); ++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, ']'); +} + +const char* ffDetectFontImpl(FFFontResult* result) { + FF_AUTO_CLOSE_FD HANDLE hKey = NULL; + if (!ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Control Panel\\Desktop\\WindowMetrics", &hKey, NULL)) { + return "ffRegOpenKeyForRead(HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics) failed"; + } + + LOGFONTW fonts[4]; + FFArgBuffer fontBuffers[4] = { + { .data = &fonts[0], .length = sizeof(fonts[0]) }, + { .data = &fonts[1], .length = sizeof(fonts[1]) }, + { .data = &fonts[2], .length = sizeof(fonts[2]) }, + { .data = &fonts[3], .length = sizeof(fonts[3]) }, + }; + + if (!ffRegReadValues(hKey, 4, (FFRegValueArg[]) { + FF_ARG(fontBuffers[0], L"CaptionFont"), + FF_ARG(fontBuffers[1], L"MenuFont"), + FF_ARG(fontBuffers[2], L"MessageFont"), + FF_ARG(fontBuffers[3], L"StatusFont"), + }, + NULL)) { + return "ffRegReadValues(HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics) failed"; + } + + for (uint32_t i = 0; i < ARRAY_SIZE(fonts); ++i) { + if (fontBuffers[i].length != sizeof(LOGFONTW)) { + continue; // Invalid data, skip + } + + LOGFONTW* logFont = &fonts[i]; + + ffStrbufSetWS(&result->fonts[i], logFont->lfFaceName); + if (logFont->lfHeight < 0) { + ffStrbufAppendF(&result->fonts[i], " (%dpt)", (int) -logFont->lfHeight); + } + } + + generateString(result); + + return NULL; +} -- cgit v1.2.3