summaryrefslogtreecommitdiffstats
path: root/src/modules/font
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/modules/font
Add the files
Diffstat (limited to 'src/modules/font')
-rw-r--r--src/modules/font/font.c113
-rw-r--r--src/modules/font/font.h11
-rw-r--r--src/modules/font/option.h9
3 files changed, 133 insertions, 0 deletions
diff --git a/src/modules/font/font.c b/src/modules/font/font.c
new file mode 100644
index 0000000..a32a7e8
--- /dev/null
+++ b/src/modules/font/font.c
@@ -0,0 +1,113 @@
+#include "common/printing.h"
+#include "common/jsonconfig.h"
+#include "common/strutil.h"
+#include "detection/font/font.h"
+#include "modules/font/font.h"
+
+bool ffPrintFont(FFFontOptions* options) {
+ bool success = false;
+ FFFontResult font;
+ for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i) {
+ ffStrbufInit(&font.fonts[i]);
+ }
+ ffStrbufInit(&font.display);
+
+ const char* error = ffDetectFont(&font);
+
+ if (error) {
+ ffPrintError(FF_FONT_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
+ } else {
+ if (options->moduleArgs.outputFormat.length == 0) {
+ ffPrintLogoAndKey(FF_FONT_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
+ ffStrbufPutTo(&font.display, stdout);
+ } else {
+ FF_PRINT_FORMAT_CHECKED(FF_FONT_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
+ FF_ARG(font.fonts[0], "font1"),
+ FF_ARG(font.fonts[1], "font2"),
+ FF_ARG(font.fonts[2], "font3"),
+ FF_ARG(font.fonts[3], "font4"),
+ FF_ARG(font.display, "combined"),
+ }));
+ }
+
+ success = true;
+ }
+
+ ffStrbufDestroy(&font.display);
+ for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i) {
+ ffStrbufDestroy(&font.fonts[i]);
+ }
+
+ return success;
+}
+
+void ffParseFontJsonObject(FFFontOptions* options, yyjson_val* module) {
+ yyjson_val *key, *val;
+ size_t idx, max;
+ yyjson_obj_foreach (module, idx, max, key, val) {
+ if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
+ continue;
+ }
+
+ ffPrintError(FF_FONT_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
+ }
+}
+
+void ffGenerateFontJsonConfig(FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
+ ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
+}
+
+bool ffGenerateFontJsonResult(FF_A_UNUSED FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
+ bool success = false;
+ FFFontResult font;
+ for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i) {
+ ffStrbufInit(&font.fonts[i]);
+ }
+ ffStrbufInit(&font.display);
+
+ const char* error = ffDetectFont(&font);
+ if (error) {
+ yyjson_mut_obj_add_str(doc, module, "error", error);
+ } else {
+ yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
+ yyjson_mut_obj_add_strbuf(doc, obj, "display", &font.display);
+ yyjson_mut_val* fontsArr = yyjson_mut_obj_add_arr(doc, obj, "fonts");
+ for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i) {
+ yyjson_mut_arr_add_strbuf(doc, fontsArr, &font.fonts[i]);
+ }
+ success = true;
+ }
+
+ ffStrbufDestroy(&font.display);
+ for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i) {
+ ffStrbufDestroy(&font.fonts[i]);
+ }
+
+ return success;
+}
+
+void ffInitFontOptions(FFFontOptions* options) {
+ ffOptionInitModuleArg(&options->moduleArgs, "");
+}
+
+void ffDestroyFontOptions(FFFontOptions* options) {
+ ffOptionDestroyModuleArg(&options->moduleArgs);
+}
+
+FFModuleBaseInfo ffFontModuleInfo = {
+ .name = FF_FONT_MODULE_NAME,
+ .description = "Print system font names",
+ .initOptions = (void*) ffInitFontOptions,
+ .destroyOptions = (void*) ffDestroyFontOptions,
+ .parseJsonObject = (void*) ffParseFontJsonObject,
+ .printModule = (void*) ffPrintFont,
+ .generateJsonResult = (void*) ffGenerateFontJsonResult,
+ .generateJsonConfig = (void*) ffGenerateFontJsonConfig,
+ .formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
+ { "Font 1", "font1" },
+ { "Font 2", "font2" },
+ { "Font 3", "font3" },
+ { "Font 4", "font4" },
+ { "Combined fonts for display", "combined" },
+ }))
+};
diff --git a/src/modules/font/font.h b/src/modules/font/font.h
new file mode 100644
index 0000000..b793b9f
--- /dev/null
+++ b/src/modules/font/font.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "option.h"
+
+#define FF_FONT_MODULE_NAME "Font"
+
+bool ffPrintFont(FFFontOptions* options);
+void ffInitFontOptions(FFFontOptions* options);
+void ffDestroyFontOptions(FFFontOptions* options);
+
+extern FFModuleBaseInfo ffFontModuleInfo;
diff --git a/src/modules/font/option.h b/src/modules/font/option.h
new file mode 100644
index 0000000..b2e2753
--- /dev/null
+++ b/src/modules/font/option.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "common/option.h"
+
+typedef struct FFFontOptions {
+ FFModuleArgs moduleArgs;
+} FFFontOptions;
+
+static_assert(sizeof(FFFontOptions) <= FF_OPTION_MAX_SIZE, "FFFontOptions size exceeds maximum allowed size");