diff --git a/4coder_API/types.h b/4coder_API/types.h index e371fe04..adc54623 100644 --- a/4coder_API/types.h +++ b/4coder_API/types.h @@ -869,6 +869,11 @@ ENUM(int32_t, Special_Hook_ID){ special_hook_buffer_name_resolver, }; +STRUCT Startup_Parameters{ + int32_t override_font_size; + bool32 override_hinting; +}; + TYPEDEF_FUNC int32_t Command_Caller_Hook_Function(struct Application_Links *app, Generic_Command cmd); #define COMMAND_CALLER_HOOK(name) int32_t name(struct Application_Links *app, Generic_Command cmd) diff --git a/4coder_build_commands.cpp b/4coder_build_commands.cpp index c92e1164..1c17b1ea 100644 --- a/4coder_build_commands.cpp +++ b/4coder_build_commands.cpp @@ -183,7 +183,7 @@ get_or_open_build_panel(Application_Links *app){ static void set_fancy_compilation_buffer_font(Application_Links *app){ Buffer_Summary comp_buffer = get_buffer_by_name(app, literal("*compilation*"), AccessAll); - buffer_set_font(app, &comp_buffer, literal("Inconsolata")); + set_buffer_face_by_name(app, &comp_buffer, literal("Inconsolata")); } CUSTOM_COMMAND_SIG(build_in_build_panel) diff --git a/4coder_config.cpp b/4coder_config.cpp index 82888242..cde016b7 100644 --- a/4coder_config.cpp +++ b/4coder_config.cpp @@ -1024,6 +1024,8 @@ config_init_default(Config_Data *config){ config->default_font_name = make_fixed_width_string(config->default_font_name_space); copy(&config->default_font_name, ""); + config->default_font_size = 16; + config->default_font_hinting = false; config->default_compiler_bat = make_fixed_width_string(config->default_compiler_bat_space); copy(&config->default_compiler_bat, "cl"); @@ -1077,8 +1079,11 @@ config_parse__data(Partition *arena, String file_name, String data, Config_Data config_fixed_string_var(parsed, "default_theme_name", 0, &config->default_theme_name, config->default_theme_name_space); + config_fixed_string_var(parsed, "default_font_name", 0, &config->default_font_name, config->default_font_name_space); + config_int_var(parsed, "default_font_size", 0, &config->default_font_size); + config_bool_var(parsed, "default_font_hinting", 0, &config->default_font_hinting); config_fixed_string_var(parsed, "default_compiler_bat", 0, &config->default_compiler_bat, config->default_compiler_bat_space); @@ -1243,7 +1248,8 @@ config_feedback_int(String *space, char *name, int32_t val){ //////////////////////////////// static void -load_config_and_apply(Application_Links *app, Partition *scratch, Config_Data *config){ +load_config_and_apply(Application_Links *app, Partition *scratch, Config_Data *config, + int32_t override_font_size, bool32 override_hinting){ Temp_Memory temp = begin_temp_memory(scratch); Config *parsed = config_parse__file_name(app, scratch, "config.4coder", config); @@ -1281,7 +1287,10 @@ load_config_and_apply(Application_Links *app, Partition *scratch, Config_Data *c config_feedback_int(&space, "default_min_base_width", config->default_min_base_width); config_feedback_string(&space, "default_theme_name", config->default_theme_name); + config_feedback_string(&space, "default_font_name", config->default_font_name); + config_feedback_int(&space, "default_font_size", config->default_font_size); + config_feedback_bool(&space, "default_font_hinting", config->default_font_hinting); config_feedback_string(&space, "default_compiler_bat", config->default_compiler_bat); config_feedback_string(&space, "default_flags_bat", config->default_flags_bat); @@ -1299,6 +1308,25 @@ load_config_and_apply(Application_Links *app, Partition *scratch, Config_Data *c change_mapping(app, config->current_mapping); adjust_all_buffer_wrap_widths(app, config->default_wrap_width, config->default_min_base_width); global_set_setting(app, GlobalSetting_LAltLCtrlIsAltGr, config->lalt_lctrl_is_altgr); + + change_theme(app, config->default_theme_name.str, config->default_theme_name.size); + + Face_Description description = {0}; + int32_t len = config->default_font_name.size; + char *name_ptr = config->default_font_name.str; + if (len > sizeof(description.font.name) - 1){ + len = sizeof(description.font.name) - 1; + } + memcpy(description.font.name, name_ptr, len); + description.font.name[len] = 0; + if (override_font_size != 0){ + description.pt_size = override_font_size; + } + else{ + description.pt_size = config->default_font_size; + } + description.hinting = config->default_font_hinting || override_hinting; + change_global_face_by_description(app, description, true); } end_temp_memory(temp); diff --git a/4coder_config.h b/4coder_config.h index e2cc3767..bf38e596 100644 --- a/4coder_config.h +++ b/4coder_config.h @@ -173,6 +173,8 @@ struct Config_Data{ char default_font_name_space[256]; String default_font_name; + int32_t default_font_size; + bool32 default_font_hinting; char default_compiler_bat_space[256]; String default_compiler_bat; diff --git a/4coder_default_framework.cpp b/4coder_default_framework.cpp index 273fec2e..3924418f 100644 --- a/4coder_default_framework.cpp +++ b/4coder_default_framework.cpp @@ -229,179 +229,6 @@ CUSTOM_DOC("Switch to a named key binding map.") //////////////////////////////// -#if 0 -static bool32 -get_current_name(char **name_out, int32_t *len_out){ - bool32 result = false; - *name_out = 0; - if (user_name.str[0] != 0){ - *name_out = user_name.str; - *len_out = user_name.size; - result = true; - } - return(result); -} - -static String -get_default_theme_name(void){ - String str = default_theme_name; - if (str.size == 0){ - str = make_lit_string("4coder"); - } - return(str); -} - -static String -get_default_font_name(void){ - String str = default_font_name; - if (str.size == 0){ - str = make_lit_string("Liberation Mono"); - } - return(str); -} -#endif - -//////////////////////////////// - -static bool32 -descriptions_match(Face_Description *a, Face_Description *b){ - bool32 result = false; - if (match(a->font.name, b->font.name) && a->font.in_local_font_folder == b->font.in_local_font_folder){ - if (memcmp((&a->pt_size), (&b->pt_size), sizeof(*a) - sizeof(a->font)) == 0){ - result = true; - } - } - return(result); -} - -static Face_ID -get_existing_face_id_matching_name(Application_Links *app, char *name, int32_t len){ - String name_str = make_string(name, len); - Face_ID largest_id = get_largest_face_id(app); - Face_ID result = 0; - for (Face_ID id = 1; id <= largest_id; ++id){ - Face_Description compare = get_face_description(app, id); - if (match(compare.font.name, name_str)){ - result = id; - break; - } - } - return(result); -} - -static Face_ID -get_existing_face_id_matching_description(Application_Links *app, Face_Description *description){ - Face_ID largest_id = get_largest_face_id(app); - Face_ID result = 0; - for (Face_ID id = 1; id <= largest_id; ++id){ - Face_Description compare = get_face_description(app, id); - if (descriptions_match(&compare, description)){ - result = id; - break; - } - } - return(result); -} - -static Face_ID -get_face_id_by_name(Application_Links *app, char *name, int32_t len, Face_Description *base_description){ - Face_ID new_id = 0; - - String str = make_string(name, len); - if (!match(str, base_description->font.name)){ - new_id = get_existing_face_id_matching_name(app, name, len); - if (new_id == 0){ - Face_Description description = *base_description; - copy_fast_unsafe_cs(description.font.name, str); - description.font.name[str.size] = 0; - - description.font.in_local_font_folder = false; - new_id = try_create_new_face(app, &description); - if (new_id == 0){ - description.font.in_local_font_folder = true; - new_id = try_create_new_face(app, &description); - } - } - } - - return(new_id); -} - -static void -change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_buffers){ - Face_ID global_face_id = get_face_id(app, 0); - Face_Description description = get_face_description(app, global_face_id); - Face_ID new_id = get_face_id_by_name(app, name, len, &description); - if (new_id != 0){ - set_global_face(app, new_id, apply_to_all_buffers); - } -} - -static void -buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){ - Face_ID current_id = get_face_id(app, buffer); - if (current_id != 0){ - Face_Description description = get_face_description(app, current_id); - Face_ID new_id = get_face_id_by_name(app, name, len, &description); - if (new_id != 0){ - buffer_set_face(app, buffer, new_id); - } - } -} - -static Face_ID -get_face_id_by_description(Application_Links *app, Face_Description *description, Face_Description *base_description){ - Face_ID new_id = 0; - if (!descriptions_match(description, base_description)){ - new_id = get_existing_face_id_matching_description(app, description); - if (new_id == 0){ - new_id = try_create_new_face(app, description); - } - } - return(new_id); -} - -static void -change_face_description(Application_Links *app, Face_Description *new_description, bool32 apply_to_all_buffers){ - Face_ID global_face_id = get_face_id(app, 0); - Face_Description old_description = get_face_description(app, global_face_id); - Face_ID new_id = get_face_id_by_description(app, new_description, &old_description); - if (new_id != 0){ - set_global_face(app, new_id, apply_to_all_buffers); - } -} - -static void -buffer_set_face_description(Application_Links *app, Buffer_Summary *buffer, Face_Description *new_description){ - Face_ID current_id = get_face_id(app, buffer); - if (current_id != 0){ - Face_Description old_description = get_face_description(app, current_id); - Face_ID new_id = get_face_id_by_description(app, new_description, &old_description); - if (new_id != 0){ - buffer_set_face(app, buffer, new_id); - } - } -} - -static Face_Description -get_buffer_face_description(Application_Links *app, Buffer_Summary *buffer){ - Face_ID current_id = get_face_id(app, buffer); - Face_Description description = {0}; - if (current_id != 0){ - description = get_face_description(app, current_id); - } - return(description); -} - -static Face_Description -get_global_face_description(Application_Links *app){ - Face_ID current_id = get_face_id(app, 0); - Face_Description description = get_face_description(app, current_id); - return(description); -} - -//////////////////////////////// - static void init_memory(Application_Links *app){ int32_t part_size = (32 << 20); @@ -415,7 +242,7 @@ init_memory(Application_Links *app){ } static void -default_4coder_initialize(Application_Links *app){ +default_4coder_initialize(Application_Links *app, int32_t override_font_size, bool32 override_hinting){ init_memory(app); static const char message[] = "" @@ -428,19 +255,14 @@ default_4coder_initialize(Application_Links *app){ String msg = make_lit_string(message); print_message(app, msg.str, msg.size); - load_config_and_apply(app, &global_part, &global_config); + load_config_and_apply(app, &global_part, &global_config, override_font_size, override_hinting); load_folder_of_themes_into_live_set(app, &global_part, "themes"); - - String theme = global_config.default_theme_name; - String font = global_config.default_font_name; - - change_theme(app, theme.str, theme.size); - change_font(app, font.str, font.size, true); } static void -default_4coder_initialize(Application_Links *app, bool32 use_scroll_bars, bool32 use_file_bars){ - default_4coder_initialize(app); +default_4coder_initialize(Application_Links *app, int32_t override_font_size, bool32 override_hinting, + bool32 use_scroll_bars, bool32 use_file_bars){ + default_4coder_initialize(app, override_font_size, override_hinting); global_config.use_scroll_bars = use_scroll_bars; global_config.use_file_bars = use_file_bars; } diff --git a/4coder_default_hooks.cpp b/4coder_default_hooks.cpp index d2b84997..defca9be 100644 --- a/4coder_default_hooks.cpp +++ b/4coder_default_hooks.cpp @@ -23,7 +23,8 @@ START_HOOK_SIG(default_start){ named_maps = named_maps_values; named_map_count = ArrayCount(named_maps_values); - default_4coder_initialize(app); + Face_Description command_line_description = get_face_description(app, 0); + default_4coder_initialize(app, command_line_description.pt_size, command_line_description.hinting); default_4coder_side_by_side_panels(app, files, file_count); if (global_config.automatically_load_project){ diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 3ff3765c..57bb6c19 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -36,6 +36,7 @@ #include "4coder_default_framework_variables.cpp" #include "4coder_buffer_seek_constructors.cpp" #include "4coder_helper.cpp" +#include "4coder_font_helper.cpp" #include "4coder_config.cpp" #include "4coder_default_framework.cpp" #include "4coder_seek.cpp" diff --git a/4coder_font_helper.cpp b/4coder_font_helper.cpp new file mode 100644 index 00000000..fbe2c562 --- /dev/null +++ b/4coder_font_helper.cpp @@ -0,0 +1,129 @@ +/* +4coder_font_helper.cpp - Procedures for font setting operations +*/ + +// TOP + +static Face_Description +get_buffer_face_description(Application_Links *app, Buffer_Summary *buffer){ + Face_ID current_id = get_face_id(app, buffer); + Face_Description description = {0}; + if (current_id != 0){ + description = get_face_description(app, current_id); + } + return(description); +} + +static Face_Description +get_global_face_description(Application_Links *app){ + Face_ID current_id = get_face_id(app, 0); + Face_Description description = get_face_description(app, current_id); + return(description); +} + +static bool32 +descriptions_match(Face_Description *a, Face_Description *b){ + bool32 result = false; + if (match(a->font.name, b->font.name) && a->font.in_local_font_folder == b->font.in_local_font_folder){ + if (memcmp((&a->pt_size), (&b->pt_size), sizeof(*a) - sizeof(a->font)) == 0){ + result = true; + } + } + return(result); +} + +static Face_ID +get_existing_face_id_matching_name(Application_Links *app, char *name, int32_t len){ + String name_str = make_string(name, len); + Face_ID largest_id = get_largest_face_id(app); + Face_ID result = 0; + for (Face_ID id = 1; id <= largest_id; ++id){ + Face_Description compare = get_face_description(app, id); + if (match(compare.font.name, name_str)){ + result = id; + break; + } + } + return(result); +} + +static Face_ID +get_existing_face_id_matching_description(Application_Links *app, Face_Description *description){ + Face_ID largest_id = get_largest_face_id(app); + Face_ID result = 0; + for (Face_ID id = 1; id <= largest_id; ++id){ + Face_Description compare = get_face_description(app, id); + if (descriptions_match(&compare, description)){ + result = id; + break; + } + } + return(result); +} + +static Face_ID +get_face_id_by_name(Application_Links *app, char *name, int32_t len, Face_Description *base_description){ + Face_ID new_id = 0; + String str = make_string(name, len); + if (!match(str, base_description->font.name)){ + new_id = get_existing_face_id_matching_name(app, name, len); + if (new_id == 0){ + Face_Description description = *base_description; + copy_fast_unsafe_cs(description.font.name, str); + description.font.name[str.size] = 0; + description.font.in_local_font_folder = false; + new_id = try_create_new_face(app, &description); + if (new_id == 0){ + description.font.in_local_font_folder = true; + new_id = try_create_new_face(app, &description); + } + } + } + return(new_id); +} + +static Face_ID +get_face_id_by_description(Application_Links *app, Face_Description *description, Face_Description *base_description){ + Face_ID new_id = 0; + if (!descriptions_match(description, base_description)){ + new_id = get_existing_face_id_matching_description(app, description); + if (new_id == 0){ + new_id = try_create_new_face(app, description); + } + } + return(new_id); +} + +static void +set_global_face_by_name(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_buffers){ + Face_ID global_face_id = get_face_id(app, 0); + Face_Description description = get_face_description(app, global_face_id); + Face_ID new_id = get_face_id_by_name(app, name, len, &description); + if (new_id != 0){ + set_global_face(app, new_id, apply_to_all_buffers); + } +} + +static void +change_global_face_by_description(Application_Links *app, Face_Description description, bool32 apply_to_all_buffers){ + Face_ID face_id = get_face_id(app, 0); + if (!try_modify_face(app, face_id, &description)){ + description.font.in_local_font_folder = !description.font.in_local_font_folder; + try_modify_face(app, face_id, &description); + } +} + +static void +set_buffer_face_by_name(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){ + Face_ID current_id = get_face_id(app, buffer); + if (current_id != 0){ + Face_Description description = get_face_description(app, current_id); + Face_ID new_id = get_face_id_by_name(app, name, len, &description); + if (new_id != 0){ + buffer_set_face(app, buffer, new_id); + } + } +} + +// BOTTOM + diff --git a/4ed.cpp b/4ed.cpp index df238fc4..484c9b15 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1633,6 +1633,7 @@ App_Step_Sig(app_step){ char **flags = models->settings.custom_flags; i32 flags_count = models->settings.custom_flags_count; + models->hook_start(&models->app_links, files, files_count, flags, flags_count); } } diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index de767975..76b13f99 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -2463,7 +2463,9 @@ Get_Face_Description(Application_Links *app, Face_ID id) DOC_PARAM(id, The face slot from which to read a description. If zero gets default values.) DOC(Fills out the values of a Face_Description struct, which includes all the information that determines the appearance of the face. If the id does not specify a valid face the description will be invalid. An invalid description has a zero length string in it's font.name field (i.e. description.font.name[0] == 0), and a valid description always contains a non-zero length string in the font.name field (i.e. description.font.name[0] != 0) -If the input id is zero, the description returned will be invalid, but the pt_size and hinting fields will reflect the default values for those fields as specified on the command line. The default values, if unspecified, are pt_size=16 and hinting=false. Note that the id of zero is reserved and is never a valid face.) +If the input id is zero, the description returned will be invalid, but the pt_size and hinting fields will reflect the default values for those fields as specified on the command line. The default values, if unspecified, are pt_size=0 and hinting=false. These default values are overriden by config.4coder when instantiating fonts at startup, but the original values of pt_size=0 and hinting=false from the command line are preserved and returned here for the lifetime of the program. + +Note that the id of zero is reserved and is never a valid face.) DOC_RETURN(Returns a Face_Description that is valid if the id references a valid face slot and is filled with the description of the face. Otherwise returns an invalid Face_Description.) DOC_SEE(Face_Description) */ diff --git a/4ed_app_models.h b/4ed_app_models.h index cbdae491..ffc39936 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -33,9 +33,7 @@ global_const App_Settings null_app_settings = {0}; struct Debug_Input_Event{ Key_Code key; - char consumer[32]; - b8 is_hold; b8 is_ctrl; b8 is_alt;