master ohmu/fastfetch-openbsd / src / detection / font / font_haiku.cpp
ohmu  ·  2026-10-15
 1extern "C" {
 2#include "font.h"
 3}
 4
 5#include <Application.h>
 6#include <Font.h>
 7#include <Menu.h>
 8
 9extern "C" {
10const char* ffDetectFontImpl(FFFontResult* result);
11}
12
13static void generateString(FFFontResult* font) {
14    const char* types[] = { "Plain", "Menu", "Bold", "Mono" };
15    for (uint32_t i = 0; i < ARRAY_SIZE(types); ++i) {
16        if (i == 0 || !ffStrbufEqual(&font->fonts[i - 1], &font->fonts[i])) {
17            if (i > 0) {
18                ffStrbufAppendS(&font->display, "], ");
19            }
20            ffStrbufAppendF(&font->display, "%s [%s", font->fonts[i].chars, types[i]);
21        } else {
22            ffStrbufAppendS(&font->display, " / ");
23            ffStrbufAppendS(&font->display, types[i]);
24        }
25    }
26    ffStrbufAppendC(&font->display, ']');
27}
28
29const char* ffDetectFontImpl(FFFontResult* result) {
30    struct menu_info menuInfo;
31    const BFont* f;
32    // We need a valid be_app to query the app_server here.
33    BApplication app("application/x-vnd.fastfetch-cli-fastfetch");
34
35    if ((f = be_plain_font) != nullptr) {
36        f->GetFamilyAndStyle(&menuInfo.f_family, &menuInfo.f_style);
37        ffStrbufAppendF(&result->fonts[0], "%s %s (%dpt)", menuInfo.f_family, menuInfo.f_style, (int) f->Size());
38    }
39    if (get_menu_info(&menuInfo) == B_OK) {
40        ffStrbufAppendF(&result->fonts[1], "%s %s (%dpt)", menuInfo.f_family, menuInfo.f_style, (int) menuInfo.font_size);
41    }
42    if ((f = be_bold_font) != nullptr) {
43        f->GetFamilyAndStyle(&menuInfo.f_family, &menuInfo.f_style);
44        ffStrbufAppendF(&result->fonts[2], "%s %s (%dpt)", menuInfo.f_family, menuInfo.f_style, (int) f->Size());
45    }
46    if ((f = be_fixed_font) != nullptr) {
47        f->GetFamilyAndStyle(&menuInfo.f_family, &menuInfo.f_style);
48        ffStrbufAppendF(&result->fonts[3], "%s %s (%dpt)", menuInfo.f_family, menuInfo.f_style, (int) f->Size());
49    }
50
51    generateString(result);
52
53    return nullptr;
54}