add new domain --load-font <path> which makes a font from a custom path available

This commit is contained in:
Felix Kratz 2024-02-22 17:18:46 +01:00
parent 97743969fe
commit b5c2c65447
4 changed files with 25 additions and 0 deletions

View file

@ -2,6 +2,25 @@
#include "animation.h"
#include "bar_manager.h"
void font_register(char* font_path) {
CFStringRef url_string = CFStringCreateWithCString(kCFAllocatorDefault,
font_path,
kCFStringEncodingUTF8);
if (url_string) {
CFURLRef url_ref = CFURLCreateWithString(kCFAllocatorDefault,
url_string,
NULL );
if (url_ref) {
CTFontManagerRegisterFontsForURL(url_ref,
kCTFontManagerScopeProcess,
NULL );
CFRelease(url_ref);
}
CFRelease(url_string);
}
free(font_path);
}
void font_create_ctfont(struct font* font) {
CFStringRef family_ref = CFStringCreateWithCString(NULL,

View file

@ -11,6 +11,8 @@ struct font {
char* style;
};
void font_register(char* font_path);
void font_init(struct font* font);
void font_destroy(struct font* font);
bool font_set(struct font* font, char* font_string, bool forced);

View file

@ -713,6 +713,9 @@ void handle_message_mach(struct mach_buffer* buffer) {
} else if (token_equals(command, DOMAIN_HOTLOAD)) {
struct token token = get_token(&message);
hotload_set_state(evaluate_boolean_state(token, hotload_get_state()));
} else if (token_equals(command, DOMAIN_ADD_FONT)) {
struct token token = get_token(&message);
font_register(token_to_string(token));
} else if (token_equals(command, DOMAIN_RELOAD)) {
char* rbr_msg = get_batch_line(&message);
char* cur = rbr_msg;

View file

@ -32,6 +32,7 @@
#define DOMAIN_HOTLOAD "--hotload"
#define DOMAIN_RELOAD "--reload"
#define DOMAIN_ADD_FONT "--load-font"
#define SUB_DOMAIN_ICON "icon"
#define SUB_DOMAIN_LABEL "label"