finished torching the old font system

master
Allen Webster 2017-03-11 13:35:12 -05:00
parent 4a5bfa59b7
commit e62da80982
7 changed files with 120 additions and 88 deletions

12
4ed.cpp
View File

@ -634,7 +634,7 @@ app_hardcode_styles(Models *models){
Style *style = styles + 1; Style *style = styles + 1;
i16 fonts = 1; i16 fonts = 1;
models->global_font.font_id = fonts + 0; models->global_font_id = fonts + 0;
///////////////// /////////////////
style_set_name(style, make_lit_string("4coder")); style_set_name(style, make_lit_string("4coder"));
@ -1215,11 +1215,8 @@ App_Init_Sig(app_init){
models->app_links.cmd_context = &vars->command_data; models->app_links.cmd_context = &vars->command_data;
partition = &models->mem.part; partition = &models->mem.part;
target->partition = partition;
{ {
i32 i;
panel_max_count = models->layout.panel_max_count = MAX_VIEWS; panel_max_count = models->layout.panel_max_count = MAX_VIEWS;
divider_max_count = panel_max_count - 1; divider_max_count = panel_max_count - 1;
models->layout.panel_count = 0; models->layout.panel_count = 0;
@ -1231,7 +1228,7 @@ App_Init_Sig(app_init){
dll_init_sentinel(&models->layout.used_sentinel); dll_init_sentinel(&models->layout.used_sentinel);
panel = panels; panel = panels;
for (i = 0; i < panel_max_count; ++i, ++panel){ for (i32 i = 0; i < panel_max_count; ++i, ++panel){
dll_insert(&models->layout.free_sentinel, panel); dll_insert(&models->layout.free_sentinel, panel);
} }
@ -1239,7 +1236,7 @@ App_Init_Sig(app_init){
models->layout.dividers = dividers; models->layout.dividers = dividers;
div = dividers; div = dividers;
for (i = 0; i < divider_max_count-1; ++i, ++div){ for (i32 i = 0; i < divider_max_count-1; ++i, ++div){
div->next = (div + 1); div->next = (div + 1);
} }
div->next = 0; div->next = 0;
@ -1460,6 +1457,7 @@ App_Init_Sig(app_init){
setup_ui_commands(&models->map_ui, &models->mem.part, global_map); setup_ui_commands(&models->map_ui, &models->mem.part, global_map);
} }
#if 0
// NOTE(allen): font setup // NOTE(allen): font setup
{ {
models->font_set = &target->font_set; models->font_set = &target->font_set;
@ -1510,6 +1508,7 @@ App_Init_Sig(app_init){
font_set_add(models->font_set, file_name, name, pt_size); font_set_add(models->font_set, file_name, name, pt_size);
} }
} }
#endif
// NOTE(allen): file setup // NOTE(allen): file setup
working_set_init(&models->working_set, partition, &vars->models.mem.general); working_set_init(&models->working_set, partition, &vars->models.mem.general);
@ -1659,7 +1658,6 @@ App_Step_Sig(app_step){
App_Vars *vars = (App_Vars*)memory->vars_memory; App_Vars *vars = (App_Vars*)memory->vars_memory;
Models *models = &vars->models; Models *models = &vars->models;
target->partition = &models->mem.part;
// NOTE(allen): OS clipboard event handling // NOTE(allen): OS clipboard event handling
String clipboard = input->clipboard; String clipboard = input->clipboard;

View File

@ -877,9 +877,10 @@ DOC_SEE(Buffer_Setting_ID)
new_value = 48; new_value = 48;
} }
if (new_value != file->settings.display_width){ if (new_value != file->settings.display_width){
i16 font_id = file->settings.font_id; //i16 font_id = file->settings.font_id;
Font_Info *font_info = get_font_info(models->font_set, font_id); //Font_Info *font_info = get_font_info(models->font_set, font_id);
Render_Font *font = font_info->font; //Render_Font *font = font_info->font;
Render_Font *font = 0;
file_set_width(models, file, new_value, font); file_set_width(models, file, new_value, font);
} }
}break; }break;
@ -891,8 +892,9 @@ DOC_SEE(Buffer_Setting_ID)
new_value = 0; new_value = 0;
} }
if (new_value != file->settings.minimum_base_display_width){ if (new_value != file->settings.minimum_base_display_width){
i16 font_id = file->settings.font_id; //i16 font_id = file->settings.font_id;
Render_Font *font = get_font_info(models->font_set, font_id)->font; //Render_Font *font = get_font_info(models->font_set, font_id)->font;
Render_Font *font = 0;
file_set_min_base_width(models, file, new_value, font); file_set_min_base_width(models, file, new_value, font);
} }
}break; }break;
@ -977,8 +979,9 @@ DOC_SEE(Buffer_Setting_ID)
} }
if (full_remeasure){ if (full_remeasure){
i16 font_id = file->settings.font_id; //i16 font_id = file->settings.font_id;
Render_Font *font = get_font_info(models->font_set, font_id)->font; //Render_Font *font = get_font_info(models->font_set, font_id)->font;
Render_Font *font = 0;
file_allocate_character_starts_as_needed(&models->mem.general, file); file_allocate_character_starts_as_needed(&models->mem.general, file);
buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white); buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
@ -2095,6 +2098,8 @@ DOC_PARAM(apply_to_all_files, If this is set all open files change to this font.
durring the start hook because several files already exist at that time.) durring the start hook because several files already exist at that time.)
DOC(This call changes 4coder's default font to one of the built in fonts.) DOC(This call changes 4coder's default font to one of the built in fonts.)
*/{ */{
#if 0
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Font_Set *set = cmd->models->font_set; Font_Set *set = cmd->models->font_set;
@ -2110,6 +2115,8 @@ DOC(This call changes 4coder's default font to one of the built in fonts.)
global_font->font_id = font_id; global_font->font_id = font_id;
} }
} }
#endif
} }
API_EXPORT void API_EXPORT void
@ -2120,6 +2127,8 @@ DOC_PARAM(name, The name parameter specifies the name of the font to begin using
DOC_PARAM(len, The len parameter specifies the length of the name string.) DOC_PARAM(len, The len parameter specifies the length of the name string.)
DOC(This call sets the display font of a particular buffer.) DOC(This call sets the display font of a particular buffer.)
*/{ */{
#if 0
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models; Models *models = cmd->models;
Editing_File *file = imp_get_file(cmd, buffer); Editing_File *file = imp_get_file(cmd, buffer);
@ -2133,6 +2142,8 @@ DOC(This call sets the display font of a particular buffer.)
file_set_font(models, file, font_id); file_set_font(models, file, font_id);
} }
} }
#endif
} }
API_EXPORT bool32 API_EXPORT bool32
@ -2144,18 +2155,21 @@ DOC_PARAM(name_max, the capacity of name_out)
DOC_RETURN(returns non-zero on success) DOC_RETURN(returns non-zero on success)
*/ */
{ {
bool32 result = false;
#if 0
Command_Data *cmd = (Command_Data*)app->cmd_context; Command_Data *cmd = (Command_Data*)app->cmd_context;
Models *models = cmd->models; Models *models = cmd->models;
Editing_File *file = imp_get_file(cmd, buffer); Editing_File *file = imp_get_file(cmd, buffer);
bool32 result = 0;
if (file){ if (file){
Font_Set *set = models->font_set; Font_Set *set = models->font_set;
String name = make_string_cap(name_out, 0, name_max); String name = make_string_cap(name_out, 0, name_max);
if (font_set_get_name(set, file->settings.font_id, &name)){ if (font_set_get_name(set, file->settings.font_id, &name)){
result = name.size; result = (name.size > 0);
} }
} }
#endif
return(result); return(result);
} }

View File

@ -50,6 +50,8 @@ struct Models{
Mem_Options mem; Mem_Options mem;
App_Settings settings; App_Settings settings;
i16 global_font_id;
Command_Map map_top; Command_Map map_top;
Command_Map map_file; Command_Map map_file;
Command_Map map_ui; Command_Map map_ui;

View File

@ -1951,7 +1951,7 @@ file_set_min_base_width(Models *models, Editing_File *file, i32 minimum_base_dis
internal void internal void
file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, b8 read_only = 0){ file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, b8 read_only = 0){
Font_Set *font_set = models->font_set; //Font_Set *font_set = models->font_set;
General_Memory *general = &models->mem.general; General_Memory *general = &models->mem.general;
Partition *part = &models->mem.part; Partition *part = &models->mem.part;
Open_File_Hook_Function *hook_open_file = models->hook_open_file; Open_File_Hook_Function *hook_open_file = models->hook_open_file;
@ -1986,9 +1986,10 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
file_allocate_character_starts_as_needed(general, file); file_allocate_character_starts_as_needed(general, file);
buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white); buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
i16 font_id = models->global_font.font_id; i16 font_id = models->global_font_id;
file->settings.font_id = font_id; file->settings.font_id = font_id;
Render_Font *font = get_font_info(font_set, font_id)->font; //Render_Font *font = get_font_info(font_set, font_id)->font;
Render_Font *font = 0;
file_measure_wraps(models, file, font); file_measure_wraps(models, file, font);
@ -2799,7 +2800,8 @@ file_view_nullify_file(View *view){
internal void internal void
update_view_line_height(Models *models, View *view, i16 font_id){ update_view_line_height(Models *models, View *view, i16 font_id){
Render_Font *font = get_font_info(models->font_set, font_id)->font; //Render_Font *font = get_font_info(models->font_set, font_id)->font;
Render_Font *font = 0;
view->line_height = font->height; view->line_height = font->height;
} }
@ -3278,7 +3280,8 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file
i32 new_line_count = buffer_count_newlines(&file->state.buffer, start, start+str_len); i32 new_line_count = buffer_count_newlines(&file->state.buffer, start, start+str_len);
i32 line_shift = new_line_count - replaced_line_count; i32 line_shift = new_line_count - replaced_line_count;
Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; //Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font;
Render_Font *font = 0;
file_grow_starts_as_needed(general, buffer, line_shift); file_grow_starts_as_needed(general, buffer, line_shift);
buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount); buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount);
@ -3404,7 +3407,8 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file,
file_allocate_character_starts_as_needed(&models->mem.general, file); file_allocate_character_starts_as_needed(&models->mem.general, file);
buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white); buffer_measure_character_starts(&file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; //Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font;
Render_Font *font = 0;
file_measure_wraps(models, file, font); file_measure_wraps(models, file, font);
// NOTE(allen): cursor fixing // NOTE(allen): cursor fixing
@ -3684,8 +3688,9 @@ style_get_color(Style *style, Cpp_Token token){
internal void internal void
file_set_font(Models *models, Editing_File *file, i16 font_id){ file_set_font(Models *models, Editing_File *file, i16 font_id){
file->settings.font_id = font_id; file->settings.font_id = font_id;
Font_Info *font_info = get_font_info(models->font_set, file->settings.font_id); //Font_Info *font_info = get_font_info(models->font_set, file->settings.font_id);
Render_Font *font = font_info->font; //Render_Font *font = font_info->font;
Render_Font *font = 0;
file_measure_wraps_and_fix_cursor(models, file, font); file_measure_wraps_and_fix_cursor(models, file, font);
Editing_Layout *layout = &models->layout; Editing_Layout *layout = &models->layout;
@ -3704,8 +3709,7 @@ global_set_font(Models *models, i16 font_id){
Editing_File *file = (Editing_File*)node; Editing_File *file = (Editing_File*)node;
file_set_font(models, file, font_id); file_set_font(models, file, font_id);
} }
models->global_font_id = font_id;
models->global_font.font_id = font_id;
} }
inline void inline void
@ -4738,7 +4742,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
message = make_lit_string("Set Global Font"); message = make_lit_string("Set Global Font");
id.id[0] = (u64)(&models->global_font); id.id[0] = (u64)(&models->global_font_id);
if (gui_do_button(target, id, message)){ if (gui_do_button(target, id, message)){
view->color_mode = CV_Mode_Global_Font; view->color_mode = CV_Mode_Global_Font;
@ -4774,10 +4778,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
{ {
Assert(view->file_data.file); Assert(view->file_data.file);
Font_Set *font_set = models->font_set; //Font_Set *font_set = models->font_set;
Font_Info *info = 0; //Font_Info *info = 0;
i16 i = 1, count = (i16)models->font_set->count + 1;
String message = make_lit_string("Back"); String message = make_lit_string("Back");
@ -4786,18 +4788,18 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
view->color_mode = CV_Mode_Library; view->color_mode = CV_Mode_Library;
} }
i16 font_id = models->global_font.font_id; i16 font_id = models->global_font_id;
if (view->color_mode == CV_Mode_Font){ if (view->color_mode == CV_Mode_Font){
font_id = view->file_data.file->settings.font_id; font_id = view->file_data.file->settings.font_id;
} }
i16 new_font_id = font_id; i16 new_font_id = font_id;
i16 count = 2;
for (i = 1; i < count; ++i){ for (i16 i = 1; i < count; ++i){
info = get_font_info(font_set, i); String font_name = {0};
id.id[0] = (u64)i; id.id[0] = (u64)i;
if (i != font_id){ if (i != font_id){
if (gui_do_font_button(target, id, i, info->name)){ if (gui_do_font_button(target, id, i, font_name)){
new_font_id = i; new_font_id = i;
} }
} }
@ -4805,7 +4807,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
char message_space[256]; char message_space[256];
message = make_fixed_width_string(message_space); message = make_fixed_width_string(message_space);
copy_ss(&message, make_lit_string("currently selected: ")); copy_ss(&message, make_lit_string("currently selected: "));
append_ss(&message, info->name); append_ss(&message, font_name);
gui_do_font_button(target, id, i, message); gui_do_font_button(target, id, i, message);
} }
} }
@ -5939,7 +5941,8 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max); Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max);
i16 font_id = file->settings.font_id; i16 font_id = file->settings.font_id;
Render_Font *font = get_font_info(models->font_set, font_id)->font; //Render_Font *font = get_font_info(models->font_set, font_id)->font;
Render_Font *font = 0;
f32 scroll_x = view->edit_pos->scroll.scroll_x; f32 scroll_x = view->edit_pos->scroll.scroll_x;
f32 scroll_y = view->edit_pos->scroll.scroll_y; f32 scroll_y = view->edit_pos->scroll.scroll_y;
@ -6181,18 +6184,20 @@ draw_text_with_cursor(Render_Target *target, View *view, i16 font_id, i32_Rect r
draw_rectangle(target, rect, back_color); draw_rectangle(target, rect, back_color);
if (pos >= 0 && pos < s.size){ if (pos >= 0 && pos < s.size){
String part1, part2, part3; //Render_Font *font = get_font_info(models->font_set, font_id)->font;
i32_Rect cursor_rect; Render_Font *font = 0; AllowLocal(font);
Render_Font *font = get_font_info(models->font_set, font_id)->font;
part1 = substr(s, 0, pos); String part1 = substr(s, 0, pos);
part2 = substr(s, pos, 1); String part2 = substr(s, pos, 1);
part3 = substr(s, pos+1, s.size-pos-1); String part3 = substr(s, pos+1, s.size-pos-1);
x = draw_string(target, font_id, part1, floor32(x), y, text_color); x = draw_string(target, font_id, part1, floor32(x), y, text_color);
//f32 adv = get_codepoint_advance(font, s.str[pos]);
f32 adv = 2.f;
i32_Rect cursor_rect;
cursor_rect.x0 = floor32(x); cursor_rect.x0 = floor32(x);
cursor_rect.x1 = floor32(x) + ceil32(get_codepoint_advance(font, s.str[pos])); cursor_rect.x1 = floor32(x) + ceil32(adv);
cursor_rect.y0 = y; cursor_rect.y0 = y;
cursor_rect.y1 = y + view->line_height; cursor_rect.y1 = y + view->line_height;
draw_rectangle(target, cursor_rect, cursor_color); draw_rectangle(target, cursor_rect, cursor_color);
@ -6400,10 +6405,12 @@ draw_button(GUI_Target *gui_target, Render_Target *target, View *view, i16 font_
internal void internal void
draw_style_preview(GUI_Target *gui_target, Render_Target *target, View *view, i16 font_id, i32_Rect rect, GUI_id id, Style *style){ draw_style_preview(GUI_Target *gui_target, Render_Target *target, View *view, i16 font_id, i32_Rect rect, GUI_id id, Style *style){
Models *models = view->persistent.models; Models *models = view->persistent.models; AllowLocal(models);
i32 active_level = gui_active_level(gui_target, id); i32 active_level = gui_active_level(gui_target, id);
Font_Info *info = get_font_info(models->font_set, font_id); //Font_Info *info = get_font_info(models->font_set, font_id);
String font_name = {0};
Render_Font *font = 0;
i32_Rect inner = get_inner_rect(rect, 3); i32_Rect inner = get_inner_rect(rect, 3);
@ -6420,12 +6427,12 @@ draw_style_preview(GUI_Target *gui_target, Render_Target *target, View *view, i1
i32 y = inner.y0; i32 y = inner.y0;
i32 x = inner.x0; i32 x = inner.x0;
x = ceil32(draw_string(target, font_id, style->name.str, x, y, text_color)); x = ceil32(draw_string(target, font_id, style->name.str, x, y, text_color));
i32 font_x = (i32)(inner.x1 - font_string_width(target, font_id, info->name.str)); i32 font_x = (i32)(inner.x1 - font_string_width(target, font_id, font_name));
if (font_x > x + 10){ if (font_x > x + 10){
draw_string(target, font_id, info->name.str, font_x, y, text_color); draw_string(target, font_id, font_name, font_x, y, text_color);
} }
i32 height = info->font->height; i32 height = font->height;
x = inner.x0; x = inner.x0;
y += height; y += height;
x = ceil32(draw_string(target, font_id, "if", x, y, keyword_color)); x = ceil32(draw_string(target, font_id, "if", x, y, keyword_color));

View File

@ -21,21 +21,14 @@ handle_equal(Plat_Handle a, Plat_Handle b){
return(result); return(result);
} }
// files
#define Sys_Set_File_List_Sig(name) void name(File_List *file_list, char *directory, char *canon_directory_out, u32 *canon_directory_size_out, u32 canon_directory_max) #define Sys_Set_File_List_Sig(name) void name(File_List *file_list, char *directory, char *canon_directory_out, u32 *canon_directory_size_out, u32 canon_directory_max)
typedef Sys_Set_File_List_Sig(System_Set_File_List); typedef Sys_Set_File_List_Sig(System_Set_File_List);
#define Sys_Get_Canonical_Sig(name) u32 name(char *filename, u32 len, char *buffer, u32 max) #define Sys_Get_Canonical_Sig(name) u32 name(char *filename, u32 len, char *buffer, u32 max)
typedef Sys_Get_Canonical_Sig(System_Get_Canonical); typedef Sys_Get_Canonical_Sig(System_Get_Canonical);
#define Sys_Add_Listener_Sig(name) b32 name(char *filename) // file load/save
typedef Sys_Add_Listener_Sig(System_Add_Listener);
#define Sys_Remove_Listener_Sig(name) b32 name(char *filename)
typedef Sys_Remove_Listener_Sig(System_Remove_Listener);
#define Sys_Get_File_Change_Sig(name) i32 name(char *buffer, i32 max, b32 *mem_too_small, i32 *required_size)
typedef Sys_Get_File_Change_Sig(System_Get_File_Change);
#define Sys_Load_Handle_Sig(name) b32 name(char *filename, Plat_Handle *handle_out) #define Sys_Load_Handle_Sig(name) b32 name(char *filename, Plat_Handle *handle_out)
typedef Sys_Load_Handle_Sig(System_Load_Handle); typedef Sys_Load_Handle_Sig(System_Load_Handle);
@ -51,10 +44,21 @@ typedef Sys_Load_Close_Sig(System_Load_Close);
#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, u32 size) #define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, u32 size)
typedef Sys_Save_File_Sig(System_Save_File); typedef Sys_Save_File_Sig(System_Save_File);
// file changes
#define Sys_Add_Listener_Sig(name) b32 name(char *filename)
typedef Sys_Add_Listener_Sig(System_Add_Listener);
#define Sys_Remove_Listener_Sig(name) b32 name(char *filename)
typedef Sys_Remove_Listener_Sig(System_Remove_Listener);
#define Sys_Get_File_Change_Sig(name) i32 name(char *buffer, i32 max, b32 *mem_too_small, i32 *required_size)
typedef Sys_Get_File_Change_Sig(System_Get_File_Change);
// time
#define Sys_Now_Time_Sig(name) u64 name() #define Sys_Now_Time_Sig(name) u64 name()
typedef Sys_Now_Time_Sig(System_Now_Time); typedef Sys_Now_Time_Sig(System_Now_Time);
// clipboard
#define Sys_Post_Clipboard_Sig(name) void name(String str) #define Sys_Post_Clipboard_Sig(name) void name(String str)
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard); typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
@ -80,7 +84,6 @@ typedef Sys_CLI_Update_Step_Sig(System_CLI_Update_Step);
typedef Sys_CLI_End_Update_Sig(System_CLI_End_Update); typedef Sys_CLI_End_Update_Sig(System_CLI_End_Update);
// coroutine // coroutine
#define Coroutine_Function_Sig(name) void name(struct Coroutine *coroutine) #define Coroutine_Function_Sig(name) void name(struct Coroutine *coroutine)
typedef Coroutine_Function_Sig(Coroutine_Function); typedef Coroutine_Function_Sig(Coroutine_Function);

View File

@ -10,8 +10,7 @@
// TOP // TOP
// //
// Standard implementation of file system stuff // Standard implementation of file system stuff based on the file track layer.
// based on the file track layer.
// //
struct Shared_Vars{ struct Shared_Vars{
@ -422,6 +421,8 @@ get_exact_render_quad(Glyph_Bounds *b, i32 pw, i32 ph, float xpos, float ypos){
inline void inline void
private_draw_glyph(Render_Target *target, Render_Font *font, u32 character, f32 x, f32 y, u32 color){ private_draw_glyph(Render_Target *target, Render_Font *font, u32 character, f32 x, f32 y, u32 color){
#if 0
Glyph_Data glyph = {0}; Glyph_Data glyph = {0};
if (get_codepoint_glyph_data(font, character, &glyph)){ if (get_codepoint_glyph_data(font, character, &glyph)){
Render_Quad q = get_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y); Render_Quad q = get_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y);
@ -437,10 +438,14 @@ private_draw_glyph(Render_Target *target, Render_Font *font, u32 character, f32
} }
glEnd(); glEnd();
} }
#endif
} }
inline void inline void
private_draw_glyph_mono(Render_Target *target, Render_Font *font, u8 character, f32 x, f32 y, f32 advance, u32 color){ private_draw_glyph_mono(Render_Target *target, Render_Font *font, u8 character, f32 x, f32 y, f32 advance, u32 color){
#if 0
Glyph_Data glyph = {0}; Glyph_Data glyph = {0};
if (get_codepoint_glyph_data(font, character, &glyph)){ if (get_codepoint_glyph_data(font, character, &glyph)){
f32 left = glyph.bounds.x0; f32 left = glyph.bounds.x0;
@ -463,6 +468,8 @@ private_draw_glyph_mono(Render_Target *target, Render_Font *font, u8 character,
} }
glEnd(); glEnd();
} }
#endif
} }
inline void inline void
@ -500,32 +507,38 @@ launch_rendering(Render_Target *target){
case piece_type_glyph: case piece_type_glyph:
{ {
#if 0
Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph); Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph);
Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font;
if (font){ if (font){
private_draw_glyph(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color); private_draw_glyph(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color);
} }
#endif
}break; }break;
case piece_type_mono_glyph: case piece_type_mono_glyph:
{ {
#if 0
Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph); Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph);
Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font;
if (font){ if (font){
private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color); private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color);
} }
#endif
}break; }break;
case piece_type_mono_glyph_advance: case piece_type_mono_glyph_advance:
{ {
#if 0
Render_Piece_Glyph_Advance *glyph = ExtractStruct(Render_Piece_Glyph_Advance); Render_Piece_Glyph_Advance *glyph = ExtractStruct(Render_Piece_Glyph_Advance);
Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font;
if (font){ if (font){
private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color); private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color);
} }
#endif
}break; }break;
case piece_type_change_clip: case piece_type_change_clip:
@ -586,8 +599,11 @@ font_load_freetype_page_inner(Partition *part, Render_Font *font, FT_Library ft,
// fill the texture // fill the texture
u32 base_codepoint = (page_number << 8); u32 base_codepoint = (page_number << 8);
Glyph_Bounds *glyph_ptr = &page->glyphs[0]; Glyph_Bounds *glyphs = &page->glyphs[0];
f32 *advance_ptr = &page->advance[0]; Glyph_Bounds *glyph_ptr = glyphs;
f32 *advances = &page->advance[0];
f32 *advance_ptr = advances;
for(u32 i = 0; i < ITEM_PER_FONT_PAGE; ++i, ++glyph_ptr, ++advance_ptr){ for(u32 i = 0; i < ITEM_PER_FONT_PAGE; ++i, ++glyph_ptr, ++advance_ptr){
u32 codepoint = i + base_codepoint; u32 codepoint = i + base_codepoint;
@ -656,38 +672,22 @@ font_load_freetype_page_inner(Partition *part, Render_Font *font, FT_Library ft,
// whitespace spacing stuff // whitespace spacing stuff
if (page_number == 0){ if (page_number == 0){
f32 space_adv = get_codepoint_advance(font, ' '); f32 space_adv = advances[' '];
f32 backslash_adv = get_codepoint_advance(font, '\\'); f32 backslash_adv = advances['\\'];
f32 r_adv = get_codepoint_advance(font, 'r'); f32 r_adv = advances['r'];
set_codepoint_advance(font, '\n', space_adv); advances['\n'] = space_adv;
set_codepoint_advance(font, '\r', backslash_adv + r_adv); advances['\r'] = backslash_adv + r_adv;
set_codepoint_advance(font, '\t', space_adv*tab_width); advances['\t'] = space_adv*tab_width;
} }
} }
internal b32
font_load_freetype_page(Partition *part, Render_Font *font, char *filename, i32 pt_size, b32 use_hinting, u32 page_number, i32 tab_width){
// TODO(allen): Stop redoing all this init for each call.
FT_Library ft;
FT_Init_FreeType(&ft);
FT_Face face;
FT_New_Face(ft, filename, 0, &face);
Glyph_Page *page = font_get_or_make_page(font, page_number);
font_load_freetype_page_inner(part, font, ft, face, use_hinting, page_number, tab_width);
FT_Done_FreeType(ft);
return(true);
}
internal b32 internal b32
font_load_freetype(Partition *part, Render_Font *font, char *filename, i32 pt_size, i32 tab_width, b32 use_hinting){ font_load_freetype(Partition *part, Render_Font *font, char *filename, i32 pt_size, i32 tab_width, b32 use_hinting){
memset(font, 0, sizeof(*font)); memset(font, 0, sizeof(*font));
#if 0
// TODO(allen): Stop redoing all this init for each call. // TODO(allen): Stop redoing all this init for each call.
FT_Library ft; FT_Library ft;
FT_Init_FreeType(&ft); FT_Init_FreeType(&ft);
@ -734,10 +734,12 @@ font_load_freetype(Partition *part, Render_Font *font, char *filename, i32 pt_si
font->byte_advance = backslash_adv + max_hex_advance*2; font->byte_advance = backslash_adv + max_hex_advance*2;
FT_Done_FreeType(ft); FT_Done_FreeType(ft);
#endif
return(true); return(true);
} }
#if 0
internal internal
Release_Font_Sig(draw_release_font){ Release_Font_Sig(draw_release_font){
for (u32 i = 0; i < ArrayCount(font->pages); ++i){ for (u32 i = 0; i < ArrayCount(font->pages); ++i){
@ -749,6 +751,7 @@ Release_Font_Sig(draw_release_font){
FREE(font->pages); FREE(font->pages);
} }
} }
#endif
// BOTTOM // BOTTOM

View File

@ -64,6 +64,7 @@
#define GL_TEXTURE_MAX_LEVEL 0x813D #define GL_TEXTURE_MAX_LEVEL 0x813D
#include "filetrack/4tech_file_track_win32.c" #include "filetrack/4tech_file_track_win32.c"
#include "font/4coder_font_data.h"
#include "4ed_system_shared.h" #include "4ed_system_shared.h"
#define SUPPORT_DPI 1 #define SUPPORT_DPI 1
@ -1402,6 +1403,7 @@ size_change(i32 dpi_x, i32 dpi_y){
return(size_max); return(size_max);
} }
#if 0
internal internal
Font_Load_Sig(font_load){ Font_Load_Sig(font_load){
if (win32vars.font_part.base == 0){ if (win32vars.font_part.base == 0){
@ -1427,6 +1429,7 @@ Font_Load_Sig(font_load){
return(success); return(success);
} }
#endif
// //
// Linkage to Custom and Application // Linkage to Custom and Application
@ -1507,8 +1510,10 @@ Win32LoadRenderCode(){
win32vars.target.pop_clip = draw_pop_clip; win32vars.target.pop_clip = draw_pop_clip;
win32vars.target.push_piece = draw_push_piece; win32vars.target.push_piece = draw_push_piece;
#if 0
win32vars.target.font_set.font_load = font_load; win32vars.target.font_set.font_load = font_load;
win32vars.target.font_set.release_font = draw_release_font; win32vars.target.font_set.release_font = draw_release_font;
#endif
} }
// //