mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Font: support macOS
The original result format was too Linux specific to make it portable, so I simplified it.
This commit is contained in:
@@ -280,6 +280,7 @@ if(LINUX OR BSD)
|
||||
src/detection/terminalfont/terminalfont_linux.c
|
||||
src/detection/media/media_linux.c
|
||||
src/detection/wmtheme/wmtheme_linux.c
|
||||
src/detection/font/font_linux.c
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -301,6 +302,7 @@ if(APPLE)
|
||||
src/detection/disk/disk_apple.m
|
||||
src/detection/wmtheme/wmtheme_apple.c
|
||||
src/detection/temps/temps_apple.c
|
||||
src/detection/font/font_apple.m
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -321,6 +323,7 @@ if(ANDROID)
|
||||
src/detection/terminalfont/terminalfont_android.c
|
||||
src/detection/media/media_android.c
|
||||
src/detection/wmtheme/wmtheme_android.c
|
||||
src/detection/font/font_android.c
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
--wm-theme-format Name: {}
|
||||
--theme-format Plasma: {}; Plasma colors: {}; Plasma colors pretty: {}; GTK2: {}; GTK3: {}; GTK4: {}; GTK: {}
|
||||
--icons-format Plasma: {}; GTK2: {}; GTK3: {}; GTK4: {}; GTK: {}
|
||||
--font-format Plasma raw: {}; Plasma name: {}; Plasma size: {}; Plasma styles: {}; Plasma pretty: {}; GTK2 raw: {}; GTK2 name: {}; GTK2 size: {}; GTK2 styles: {}; GTK2 pretty: {}; GTK3 raw: {}; GTK3 name: {}; GTK3 size: {}; GTK3 styles: {}; GTK3 pretty: {}; GTK4 raw: {}; GTK4 name: {}; GTK4 size: {}; GTK4 styles: {}; GTK4 pretty: {}; GTK: {}
|
||||
--font-format Type: {}; Font: {}
|
||||
--cursor-format Theme: {}; Size: {}
|
||||
--terminal-format Process: {}; Path: {}; Exe: {}
|
||||
--terminal-font-format Pretty: {}; Name: {}; Size: {}; Styles: {}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_font_font
|
||||
#define FF_INCLUDED_detection_font_font
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include "util/FFstrbuf.h"
|
||||
#include "util/FFlist.h"
|
||||
|
||||
typedef struct FFFontResult
|
||||
{
|
||||
const char* type;
|
||||
FFstrbuf fontPretty;
|
||||
} FFFontResult;
|
||||
|
||||
const char* ffDetectFontImpl(FFinstance* instance, FFlist* result);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "common/font.h"
|
||||
|
||||
const char* ffDetectFontImpl(FFinstance* instance, FFlist* result)
|
||||
{
|
||||
FF_UNUSED(instance, result);
|
||||
return "Font detection is not supported on Android";
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "common/font.h"
|
||||
#include "util/apple/cf_helpers.h"
|
||||
#include "font.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#define FF_FONT_MODULE_NAME "Font"
|
||||
|
||||
static void detectFontForType(CTFontUIFontType uiType, FFFontResult* result)
|
||||
{
|
||||
CTFontRef ctFont = CTFontCreateUIFontForLanguage(uiType, 12, NULL);
|
||||
|
||||
ffStrbufInit(&result->fontPretty);
|
||||
ffCfStrGetString(CTFontCopyFullName(ctFont), &result->fontPretty);
|
||||
|
||||
FFstrbuf familyName;
|
||||
ffStrbufInit(&familyName);
|
||||
ffCfStrGetString(CTFontCopyFamilyName(ctFont), &familyName);
|
||||
|
||||
if (ffStrbufComp(&familyName, &result->fontPretty) != 0)
|
||||
{
|
||||
ffStrbufAppendF(&result->fontPretty, " (%*s)", familyName.length, familyName.chars);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&familyName);
|
||||
}
|
||||
|
||||
const char* ffDetectFontImpl(FFinstance* instance, FFlist* 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;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#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)
|
||||
{
|
||||
const FFstrbuf* qtRaw = &ffDetectQt(instance)->font;
|
||||
const FFstrbuf* gtk2Raw = &ffDetectGTK2(instance)->font;
|
||||
const FFstrbuf* gtk3Raw = &ffDetectGTK3(instance)->font;
|
||||
const FFstrbuf* gtk4Raw = &ffDetectGTK4(instance)->font;
|
||||
|
||||
if(qtRaw->length > 0)
|
||||
{
|
||||
FFfont qt;
|
||||
ffFontInitQt(&qt, qtRaw->chars);
|
||||
|
||||
FFFontResult* resultQt = (FFFontResult *)ffListAdd(result);
|
||||
resultQt->type = "QT";
|
||||
ffStrbufInitCopy(&resultQt->fontPretty, &qt.pretty);
|
||||
|
||||
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;
|
||||
}
|
||||
+24
-73
@@ -1,21 +1,13 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/font.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/parsing.h"
|
||||
#include "detection/qt.h"
|
||||
#include "detection/gtk.h"
|
||||
#include "detection/font/font.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
|
||||
#define FF_FONT_MODULE_NAME "Font"
|
||||
#define FF_FONT_NUM_FORMAT_ARGS 21
|
||||
#define FF_FONT_NUM_FORMAT_ARGS 2
|
||||
|
||||
void ffPrintFont(FFinstance* instance)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "Font detection is not supported on Android");
|
||||
return;
|
||||
#endif
|
||||
|
||||
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
|
||||
@@ -24,76 +16,35 @@ void ffPrintFont(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
const FFstrbuf* plasmaRaw = &ffDetectQt(instance)->font;
|
||||
const FFstrbuf* gtk2Raw = &ffDetectGTK2(instance)->font;
|
||||
const FFstrbuf* gtk3Raw = &ffDetectGTK3(instance)->font;
|
||||
const FFstrbuf* gtk4Raw = &ffDetectGTK4(instance)->font;
|
||||
|
||||
if(plasmaRaw->length == 0 && gtk2Raw->length == 0 && gtk3Raw->length == 0 && gtk4Raw->length == 0)
|
||||
FFlist list;
|
||||
ffListInit(&list, sizeof(FFFontResult));
|
||||
const char* error = ffDetectFontImpl(instance, &list);
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "No fonts found");
|
||||
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "%s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
FFfont plasma;
|
||||
ffFontInitQt(&plasma, plasmaRaw->chars);
|
||||
|
||||
FFfont gtk2;
|
||||
ffFontInitPango(>k2, gtk2Raw->chars);
|
||||
|
||||
FFfont gtk3;
|
||||
ffFontInitPango(>k3, gtk3Raw->chars);
|
||||
|
||||
FFfont gtk4;
|
||||
ffFontInitPango(>k4, gtk4Raw->chars);
|
||||
|
||||
FFstrbuf gtk;
|
||||
ffStrbufInitA(>k, 64);
|
||||
ffParseGTK(>k, >k2.pretty, >k3.pretty, >k4.pretty);
|
||||
|
||||
if(instance->config.font.outputFormat.length == 0)
|
||||
for(uint32_t i = 0; i < list.length; ++i)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font.key);
|
||||
if(plasma.pretty.length > 0)
|
||||
FFFontResult* font = (FFFontResult*)ffListGet(&list, i);
|
||||
if(instance->config.font.outputFormat.length == 0)
|
||||
{
|
||||
ffStrbufWriteTo(&plasma.pretty, stdout);
|
||||
fputs(" [QT]", stdout);
|
||||
|
||||
if(gtk.length > 0)
|
||||
fputs(", ", stdout);
|
||||
FFstrbuf key;
|
||||
ffStrbufInitF(&key, "%s (%s)", FF_FONT_MODULE_NAME, font->type);
|
||||
ffPrintLogoAndKey(instance, key.chars, 0, &instance->config.font.key);
|
||||
puts(font->fontPretty.chars);
|
||||
ffStrbufDestroy(&key);
|
||||
}
|
||||
ffStrbufPutTo(>k, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, plasmaRaw},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma.name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma.size},
|
||||
{FF_FORMAT_ARG_TYPE_LIST, &plasma.styles},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma.pretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, gtk2Raw},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k2.name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k2.size},
|
||||
{FF_FORMAT_ARG_TYPE_LIST, >k2.styles},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k2.pretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, gtk3Raw},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k3.name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k3.size},
|
||||
{FF_FORMAT_ARG_TYPE_LIST, >k3.styles},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k3.pretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, gtk4Raw},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k4.name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k4.size},
|
||||
{FF_FORMAT_ARG_TYPE_LIST, >k4.styles},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k4.pretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, >k}
|
||||
});
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRING, font->type},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fontPretty}
|
||||
});
|
||||
}
|
||||
ffStrbufDestroy(&font->fontPretty);
|
||||
}
|
||||
|
||||
ffFontDestroy(&plasma);
|
||||
ffFontDestroy(>k2);
|
||||
ffFontDestroy(>k3);
|
||||
ffFontDestroy(>k4);
|
||||
ffStrbufDestroy(>k);
|
||||
ffListDestroy(&list);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user