2018-05-28 18:14:26 +00:00
|
|
|
/*
|
|
|
|
4coder_font_helper.cpp - Procedures for font setting operations
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
// TODO(allen): transition wrappers
|
2018-05-28 18:14:26 +00:00
|
|
|
static Face_Description
|
2019-04-05 02:03:36 +00:00
|
|
|
get_buffer_face_description(Application_Links *app, Buffer_ID buffer){
|
2019-06-20 04:45:58 +00:00
|
|
|
Face_ID current_id = get_face_id(app, buffer);
|
2018-11-20 08:18:54 +00:00
|
|
|
Face_Description description = {};
|
2018-05-28 18:14:26 +00:00
|
|
|
if (current_id != 0){
|
|
|
|
description = get_face_description(app, current_id);
|
|
|
|
}
|
|
|
|
return(description);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Face_Description
|
|
|
|
get_global_face_description(Application_Links *app){
|
2019-06-20 04:45:58 +00:00
|
|
|
Face_ID current_id = get_face_id(app, 0);
|
2018-05-28 18:14:26 +00:00
|
|
|
Face_Description description = get_face_description(app, current_id);
|
|
|
|
return(description);
|
|
|
|
}
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
static b32
|
2018-05-28 18:14:26 +00:00
|
|
|
descriptions_match(Face_Description *a, Face_Description *b){
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 result = false;
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(SCchar(a->font.name), SCchar(b->font.name)) && a->font.in_local_font_folder == b->font.in_local_font_folder){
|
2018-05-28 18:14:26 +00:00
|
|
|
if (memcmp((&a->pt_size), (&b->pt_size), sizeof(*a) - sizeof(a->font)) == 0){
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Face_ID
|
2019-06-01 23:58:28 +00:00
|
|
|
get_existing_face_id_matching_name(Application_Links *app, String_Const_u8 name){
|
2018-05-28 18:14:26 +00:00
|
|
|
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);
|
2019-06-01 23:58:28 +00:00
|
|
|
if (string_match(SCu8(compare.font.name), name)){
|
2018-05-28 18:14:26 +00:00
|
|
|
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
|
2019-06-01 23:58:28 +00:00
|
|
|
get_face_id_by_name(Application_Links *app, String_Const_u8 name, Face_Description *base_description){
|
2018-05-28 18:14:26 +00:00
|
|
|
Face_ID new_id = 0;
|
2019-06-01 23:58:28 +00:00
|
|
|
name.size = clamp_top(name.size, sizeof(base_description->font.name) - 1);
|
|
|
|
if (!string_match(name, SCu8(base_description->font.name))){
|
|
|
|
new_id = get_existing_face_id_matching_name(app, name);
|
2018-05-28 18:14:26 +00:00
|
|
|
if (new_id == 0){
|
|
|
|
Face_Description description = *base_description;
|
2019-06-01 23:58:28 +00:00
|
|
|
block_copy(description.font.name, name.str, name.size);
|
|
|
|
description.font.name[name.size] = 0;
|
2018-05-28 18:14:26 +00:00
|
|
|
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
|
2019-06-01 23:58:28 +00:00
|
|
|
set_global_face_by_name(Application_Links *app, String_Const_u8 name, b32 apply_to_all_buffers){
|
2019-06-20 04:45:58 +00:00
|
|
|
Face_ID global_face_id = get_face_id(app, 0);
|
2018-05-28 18:14:26 +00:00
|
|
|
Face_Description description = get_face_description(app, global_face_id);
|
2019-06-01 23:58:28 +00:00
|
|
|
Face_ID new_id = get_face_id_by_name(app, name, &description);
|
2018-05-28 18:14:26 +00:00
|
|
|
if (new_id != 0){
|
|
|
|
set_global_face(app, new_id, apply_to_all_buffers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-26 23:08:42 +00:00
|
|
|
change_global_face_by_description(Application_Links *app, Face_Description description, b32 apply_to_all_buffers){
|
2019-06-20 04:45:58 +00:00
|
|
|
Face_ID face_id = get_face_id(app, 0);
|
2018-05-28 18:14:26 +00:00
|
|
|
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
|
2019-06-01 23:58:28 +00:00
|
|
|
set_buffer_face_by_name(Application_Links *app, Buffer_ID buffer, String_Const_u8 name){
|
2019-06-20 04:45:58 +00:00
|
|
|
Face_ID current_id = get_face_id(app, buffer);
|
2018-05-28 18:14:26 +00:00
|
|
|
if (current_id != 0){
|
|
|
|
Face_Description description = get_face_description(app, current_id);
|
2019-06-01 23:58:28 +00:00
|
|
|
Face_ID new_id = get_face_id_by_name(app, name, &description);
|
2018-05-28 18:14:26 +00:00
|
|
|
if (new_id != 0){
|
|
|
|
buffer_set_face(app, buffer, new_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|