summaryrefslogtreecommitdiffstats
path: root/src/detection/font
diff options
context:
space:
mode:
Diffstat (limited to 'src/detection/font')
-rw-r--r--src/detection/font/font.c19
-rw-r--r--src/detection/font/font.h20
-rw-r--r--src/detection/font/font_apple.m37
-rw-r--r--src/detection/font/font_haiku.cpp54
-rw-r--r--src/detection/font/font_linux.c53
-rw-r--r--src/detection/font/font_nosupport.c7
-rw-r--r--src/detection/font/font_windows.c63
7 files changed, 253 insertions, 0 deletions
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 <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]");
+ }
+}
+
+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 <Application.h>
+#include <Font.h>
+#include <Menu.h>
+
+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(&gtk2, ffDetectGTK2()->font.chars);
+ ffStrbufAppend(&result->fonts[1], &gtk2.pretty);
+ ffFontDestroy(&gtk2);
+
+ FFfont gtk3;
+ ffFontInitPango(&gtk3, ffDetectGTK3()->font.chars);
+ ffStrbufAppend(&result->fonts[2], &gtk3.pretty);
+ ffFontDestroy(&gtk3);
+
+ FFfont gtk4;
+ ffFontInitPango(&gtk4, ffDetectGTK4()->font.chars);
+ ffStrbufAppend(&result->fonts[3], &gtk4.pretty);
+ ffFontDestroy(&gtk4);
+
+ 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 <windows.h>
+
+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;
+}