1-bit font anti-aliasing

This commit is contained in:
Allen Webster 2021-01-16 20:21:35 -08:00
parent 91ac59b3ec
commit 8f67525380
9 changed files with 45 additions and 11 deletions

View File

@ -2654,6 +2654,7 @@ get_face_description(Application_Links *app, Face_ID face_id)
}
}
else{
description.parameters.aa_mode = FaceAntialiasingMode_8BitMono;
description.parameters.pt_size = models->settings.font_size;
description.parameters.hinting = models->settings.use_hinting;
}

View File

@ -23,7 +23,7 @@ struct App_Settings{
b32 lctrl_lalt_is_altgr;
i32 font_size;
b32 use_hinting;
b8 use_hinting;
};
enum App_State{

View File

@ -246,6 +246,8 @@ ft__font_make_face(Arena *arena, Face_Description *description, f32 scale_factor
case FT_PIXEL_MODE_GRAY:
{
b32 aa_1bit_mono = (description->parameters.aa_mode == FaceAntialiasingMode_1BitMono);
u8 *src_line = ft_glyph->bitmap.buffer;
if (ft_glyph->bitmap.pitch < 0){
src_line = ft_glyph->bitmap.buffer + (-ft_glyph->bitmap.pitch)*(dim.y - 1);
@ -254,7 +256,16 @@ ft__font_make_face(Arena *arena, Face_Description *description, f32 scale_factor
for (i32 y = 0; y < dim.y; y += 1){
u8 *src_pixel = src_line;
for (i32 x = 0; x < dim.x; x += 1){
*dst = *src_pixel;
if (aa_1bit_mono){
u8 s = *src_pixel;
if (s > 0){
s = 255;
}
*dst = s;
}
else{
*dst = *src_pixel;
}
dst += 1;
src_pixel += 1;
}

View File

@ -150,9 +150,9 @@ get_or_open_build_panel(Application_Links *app){
function void
set_fancy_compilation_buffer_font(Application_Links *app){
Scratch_Block scratch(app);
Buffer_ID buffer = get_comp_buffer(app);
Font_Load_Location font = {};
Scratch_Block scratch(app);
font.file_name = def_search_normal_full_path(scratch, str8_lit("fonts/Inconsolata-Regular.ttf"));
set_buffer_face_by_font_load_location(app, buffer, &font);
}

View File

@ -1535,6 +1535,16 @@ load_config_and_apply(Application_Links *app, Arena *out_arena, i32 override_fon
b32 default_font_hinting = def_get_config_b32(vars_save_string_lit("default_font_hinting"));
description.parameters.hinting = default_font_hinting || override_hinting;
Face_Antialiasing_Mode aa_mode = FaceAntialiasingMode_8BitMono;
String8 aa_mode_string = def_get_config_string(scratch, vars_save_string_lit("default_font_aa_mode"));
if (string_match(aa_mode_string, str8_lit("8bit"))){
aa_mode = FaceAntialiasingMode_8BitMono;
}
else if (string_match(aa_mode_string, str8_lit("1bit"))){
aa_mode = FaceAntialiasingMode_1BitMono;
}
description.parameters.aa_mode = aa_mode;
description.font.file_name = default_font_name;
if (!modify_global_face_by_description(app, description)){
String8 name_in_fonts_folder = push_u8_stringf(scratch, "fonts/%.*s", string_expand(default_font_name));

View File

@ -662,8 +662,7 @@ default_4coder_initialize(Application_Links *app, String_Const_u8_Array file_nam
}
function void
default_4coder_initialize(Application_Links *app,
i32 override_font_size, b32 override_hinting){
default_4coder_initialize(Application_Links *app, i32 override_font_size, b32 override_hinting){
String_Const_u8_Array file_names = {};
default_4coder_initialize(app, file_names, override_font_size, override_hinting);
}

View File

@ -499,13 +499,21 @@ struct Font_Load_Location{
String_Const_u8 file_name;
};
api(custom)
typedef u32 Face_Antialiasing_Mode;
enum{
FaceAntialiasingMode_8BitMono,
FaceAntialiasingMode_1BitMono,
};
api(custom)
struct Face_Load_Parameters{
u32 pt_size;
b32 bold;
b32 italic;
b32 underline;
b32 hinting;
Face_Antialiasing_Mode aa_mode;
b8 bold;
b8 italic;
b8 underline;
b8 hinting;
};
api(custom)

View File

@ -326,7 +326,7 @@ static Command_Metadata fcoder_metacmd_table[252] = {
{ PROC_LINKS(execute_any_cli, 0), false, "execute_any_cli", 15, "Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer.", 133, "W:\\4ed\\code\\custom\\4coder_cli_command.cpp", 41, 22 },
{ PROC_LINKS(execute_previous_cli, 0), false, "execute_previous_cli", 20, "If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.", 126, "W:\\4ed\\code\\custom\\4coder_cli_command.cpp", 41, 7 },
{ PROC_LINKS(exit_4coder, 0), false, "exit_4coder", 11, "Attempts to close 4coder.", 25, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 846 },
{ PROC_LINKS(go_to_user_directory, 0), false, "go_to_user_directory", 20, "Go to the 4coder user directory", 31, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1638 },
{ PROC_LINKS(go_to_user_directory, 0), false, "go_to_user_directory", 20, "Go to the 4coder user directory", 31, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1648 },
{ PROC_LINKS(goto_beginning_of_file, 0), false, "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2247 },
{ PROC_LINKS(goto_end_of_file, 0), false, "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2255 },
{ PROC_LINKS(goto_first_jump, 0), false, "goto_first_jump", 15, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "W:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 525 },
@ -375,7 +375,7 @@ static Command_Metadata fcoder_metacmd_table[252] = {
{ PROC_LINKS(list_all_substring_locations, 0), false, "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 174 },
{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), false, "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 186 },
{ PROC_LINKS(load_project, 0), false, "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 823 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1594 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1604 },
{ PROC_LINKS(load_themes_default_folder, 0), false, "load_themes_default_folder", 26, "Loads all the theme files in the default theme folder.", 54, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 535 },
{ PROC_LINKS(load_themes_hot_directory, 0), false, "load_themes_hot_directory", 25, "Loads all the theme files in the current hot directory.", 55, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 554 },
{ PROC_LINKS(make_directory_query, 0), false, "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1495 },

View File

@ -68,6 +68,11 @@ default_font_name = "liberation-mono.ttf";
default_font_size = 16;
default_font_hinting = false;
// aa modes:
// 8bit - mono-chrome 0-255 opacity channel per pixel
// 1bit - mono-chrome 0/1 opacity channel per pixel
default_font_aa_mode = "1bit";
// User
user_name = "not-set";