diff --git a/src/font.c b/src/font.c index f882441..04c7f2e 100644 --- a/src/font.c +++ b/src/font.c @@ -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, diff --git a/src/font.h b/src/font.h index a64d91f..eca773d 100644 --- a/src/font.h +++ b/src/font.h @@ -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); diff --git a/src/message.c b/src/message.c index 2e128d9..6e076e1 100644 --- a/src/message.c +++ b/src/message.c @@ -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; diff --git a/src/misc/defines.h b/src/misc/defines.h index f03dac4..d87026e 100644 --- a/src/misc/defines.h +++ b/src/misc/defines.h @@ -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"