Finished font organization, began adding italics, bold, underline.

master
Allen Webster 2017-11-20 11:56:21 -05:00
parent 29b1488057
commit e7d8aae42e
3 changed files with 120 additions and 80 deletions

View File

@ -3569,7 +3569,7 @@ global_set_font(System_Functions *system, Models *models, Font_ID font_id){
internal void internal void
alter_font(System_Functions *system, Models *models, Font_ID font_id, Font_Settings *new_settings){ alter_font(System_Functions *system, Models *models, Font_ID font_id, Font_Settings *new_settings){
if (system->font.change_settings(font_id, new_settings)){ if (system->font.face_change_settings(font_id, new_settings)){
File_Node *node = 0; File_Node *node = 0;
File_Node *sentinel = &models->working_set.used_sentinel; File_Node *sentinel = &models->working_set.used_sentinel;
for (dll_items(node, sentinel)){ for (dll_items(node, sentinel)){
@ -4541,9 +4541,6 @@ step_file_view(System_Functions *system, View *view, Models *models, View *activ
Font_ID font_id = file->settings.font_id; Font_ID font_id = file->settings.font_id;
Font_ID new_font_id = 0; Font_ID new_font_id = 0;
#if 1
// NEW
Font_ID largest_id = system->font.get_largest_id(); Font_ID largest_id = system->font.get_largest_id();
for (Font_ID i = 1; i <= largest_id; ++i){ for (Font_ID i = 1; i <= largest_id; ++i){
Font_Pointers font = system->font.get_pointers_by_id(i); Font_Pointers font = system->font.get_pointers_by_id(i);
@ -4557,12 +4554,15 @@ step_file_view(System_Functions *system, View *view, Models *models, View *activ
append(&m, "*"); append(&m, "*");
} }
append(&m, "family:\""); append(&m, " \"");
append(&m, make_string(metrics->name, metrics->name_len)); append(&m, make_string(metrics->name, metrics->name_len));
append(&m, "\" size:"); append(&m, "\" ");
append_int_to_str(&m, settings->pt_size); append_int_to_str(&m, settings->parameters.pt_size);
append(&m, " hint:"); append(&m, " ");
append(&m, (char*)(settings->use_hinting?"ON ":"OFF")); append(&m, (char*)(settings->parameters.italics?"italics ":""));
append(&m, (char*)(settings->parameters.bold?"bold ":""));
append(&m, (char*)(settings->parameters.underline?"underline ":""));
append(&m, (char*)(settings->parameters.use_hinting?"hinting ":""));
if (i == font_id){ if (i == font_id){
append(&m, "*"); append(&m, "*");
@ -4592,7 +4592,7 @@ step_file_view(System_Functions *system, View *view, Models *models, View *activ
if (gui_do_button(target, id, make_lit_string("new face"))){ if (gui_do_button(target, id, make_lit_string("new face"))){
if (new_font_id == 0){ if (new_font_id == 0){
Font_Pointers font = system->font.get_pointers_by_id(font_id); Font_Pointers font = system->font.get_pointers_by_id(font_id);
view->font_edit_id = system->font.load_new_font(&font.settings->stub); view->font_edit_id = system->font.face_allocate_and_init(font.settings);
if (view->color_mode == CV_Mode_Font){ if (view->color_mode == CV_Mode_Font){
view->color_mode = CV_Mode_Font_Editing; view->color_mode = CV_Mode_Font_Editing;
} }
@ -4602,30 +4602,6 @@ step_file_view(System_Functions *system, View *view, Models *models, View *activ
} }
} }
#else
// OLD
i32 total_count = system->font.get_loadable_count();
for (i32 i = 0; i < total_count; ++i){
Font_Loadable_Description loadable = {0};
system->font.get_loadable(i, &loadable);
id.id[0] = (u64)i + 1;
if (loadable.valid){
String name = make_string(loadable.display_name, loadable.display_len);
if (gui_do_button(target, id, name)){
if (new_font_id == 0){
new_font_id = font_get_id_by_name(system, name);
if (new_font_id == 0){
new_font_id = system->font.load_new_font(&loadable.stub);
}
}
}
}
}
#endif
if (new_font_id != 0){ if (new_font_id != 0){
if (view->color_mode == CV_Mode_Font && new_font_id != font_id){ if (view->color_mode == CV_Mode_Font && new_font_id != font_id){
file_set_font(system, models, file, new_font_id); file_set_font(system, models, file, new_font_id);
@ -4663,37 +4639,68 @@ step_file_view(System_Functions *system, View *view, Models *models, View *activ
char space[128]; char space[128];
String m = make_fixed_width_string(space); String m = make_fixed_width_string(space);
copy(&m, "Size Up ("); copy(&m, "Size Up (");
append_int_to_str(&m, settings->pt_size); append_int_to_str(&m, settings->parameters.pt_size);
append(&m, ")"); append(&m, ")");
++id.id[0]; ++id.id[0];
if (gui_do_button(target, id, m)){ if (gui_do_button(target, id, m)){
if (!has_new_settings){ if (!has_new_settings){
has_new_settings = true; has_new_settings = true;
++new_settings.pt_size; ++new_settings.parameters.pt_size;
} }
} }
copy(&m, "Size Down ("); copy(&m, "Size Down (");
append_int_to_str(&m, settings->pt_size); append_int_to_str(&m, settings->parameters.pt_size);
append(&m, ")"); append(&m, ")");
++id.id[0]; ++id.id[0];
if (gui_do_button(target, id, m)){ if (gui_do_button(target, id, m)){
if (!has_new_settings){ if (!has_new_settings){
has_new_settings = true; has_new_settings = true;
--new_settings.pt_size; --new_settings.parameters.pt_size;
} }
} }
copy(&m, "Turn Hinting "); copy(&m, "Italics [");
append(&m, (char*)(settings->use_hinting?"Off":"On")); append(&m, (char*)(settings->parameters.italics?"+":" "));
append(&m, " (it is currently "); append(&m, "]");
append(&m, (char*)(settings->use_hinting?"On":"Off"));
append(&m, ")");
++id.id[0]; ++id.id[0];
if (gui_do_button(target, id, m)){ if (gui_do_button(target, id, m)){
if (!has_new_settings){ if (!has_new_settings){
has_new_settings = true; has_new_settings = true;
new_settings.use_hinting = !new_settings.use_hinting; new_settings.parameters.italics = !new_settings.parameters.italics;
}
}
copy(&m, "Bold [");
append(&m, (char*)(settings->parameters.bold?"+":" "));
append(&m, "]");
++id.id[0];
if (gui_do_button(target, id, m)){
if (!has_new_settings){
has_new_settings = true;
new_settings.parameters.bold = !new_settings.parameters.bold;
}
}
copy(&m, "Underline [");
append(&m, (char*)(settings->parameters.underline?"+":" "));
append(&m, "]");
++id.id[0];
if (gui_do_button(target, id, m)){
if (!has_new_settings){
has_new_settings = true;
new_settings.parameters.underline = !new_settings.parameters.underline;
}
}
copy(&m, "Hinting [");
append(&m, (char*)(settings->parameters.use_hinting?"+":" "));
append(&m, "]");
++id.id[0];
if (gui_do_button(target, id, m)){
if (!has_new_settings){
has_new_settings = true;
new_settings.parameters.use_hinting = !new_settings.parameters.use_hinting;
} }
} }

View File

@ -27,10 +27,17 @@ struct Font_Loadable_Description{
}; };
// NOTE(allen): Settings that the are specified that determine how a font should be loaded and rendered. // NOTE(allen): Settings that the are specified that determine how a font should be loaded and rendered.
struct Font_Parameters{
i32 pt_size;
b32 italics;
b32 bold;
b32 underline;
b32 use_hinting;
};
struct Font_Settings{ struct Font_Settings{
Font_Loadable_Stub stub; Font_Loadable_Stub stub;
i32 pt_size; Font_Parameters parameters;
b32 use_hinting;
}; };
// NOTE(allen): Results about the font true for the entire font as a whole. // NOTE(allen): Results about the font true for the entire font as a whole.
@ -106,11 +113,14 @@ typedef Sys_Font_Get_Loadable_Count_Sig(Font_Get_Loadable_Count_Function);
#define Sys_Font_Get_Loadable_Sig(n,i,o) void (n)(i32 i, Font_Loadable_Description *o) #define Sys_Font_Get_Loadable_Sig(n,i,o) void (n)(i32 i, Font_Loadable_Description *o)
typedef Sys_Font_Get_Loadable_Sig(Font_Get_Loadable_Function, index, out); typedef Sys_Font_Get_Loadable_Sig(Font_Get_Loadable_Function, index, out);
#define Sys_Font_Load_New_Font_Sig(n,s) Font_ID (n)(Font_Loadable_Stub *s) #define Sys_Font_Face_Allocate_And_Init_Sig(n,s) Font_ID (n)(Font_Settings *s)
typedef Sys_Font_Load_New_Font_Sig(Font_Load_New_Font_Function, stub); typedef Sys_Font_Face_Allocate_And_Init_Sig(Font_Face_Allocate_And_Init_Function, settings);
#define Sys_Font_Change_Settings_Sig(n,id,s) b32 (n)(Font_ID id, Font_Settings *s) #define Sys_Font_Face_Change_Settings_Sig(n,id,s) b32 (n)(Font_ID id, Font_Settings *s)
typedef Sys_Font_Change_Settings_Sig(Font_Change_Settings_Function, font_id, new_settings); typedef Sys_Font_Face_Change_Settings_Sig(Font_Face_Change_Settings_Function, font_id, new_settings);
#define Sys_Font_Face_Release_Sig(n,id) b32 (n)(Font_ID id)
typedef Sys_Font_Face_Release_Sig(Font_Face_Release_Function, font_id);
#define Sys_Font_Get_Largest_ID_Sig(n) Font_ID (n)(void) #define Sys_Font_Get_Largest_ID_Sig(n) Font_ID (n)(void)
typedef Sys_Font_Get_Largest_ID_Sig(Font_Get_Largest_ID_Function); typedef Sys_Font_Get_Largest_ID_Sig(Font_Get_Largest_ID_Function);
@ -136,8 +146,9 @@ typedef Sys_Font_Free_Sig(Font_Free_Function,ptr);
struct Font_Functions{ struct Font_Functions{
Font_Get_Loadable_Count_Function *get_loadable_count; Font_Get_Loadable_Count_Function *get_loadable_count;
Font_Get_Loadable_Function *get_loadable; Font_Get_Loadable_Function *get_loadable;
Font_Load_New_Font_Function *load_new_font; Font_Face_Allocate_And_Init_Function *face_allocate_and_init;
Font_Change_Settings_Function *change_settings; Font_Face_Change_Settings_Function *face_change_settings;
Font_Face_Release_Function *face_release;
Font_Get_Largest_ID_Function *get_largest_id; Font_Get_Largest_ID_Function *get_largest_id;
Font_Get_Count_Function *get_count; Font_Get_Count_Function *get_count;
Font_Get_Name_By_ID_Function *get_name_by_id; Font_Get_Name_By_ID_Function *get_name_by_id;

View File

@ -83,8 +83,8 @@ font_load_page_layout(Font_Settings *settings, Font_Metrics *metrics, Glyph_Page
page->page_number = page_number; page->page_number = page_number;
page->has_layout = true; page->has_layout = true;
u32 pt_size = settings->pt_size; u32 pt_size = settings->parameters.pt_size;
b32 use_hinting = settings->use_hinting; b32 use_hinting = settings->parameters.use_hinting;
// 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;
@ -176,8 +176,8 @@ font_load_page_pixels(Partition *part, Font_Settings *settings, Glyph_Page *page
Assert(page->has_layout); Assert(page->has_layout);
Assert(page->page_number == page_number); Assert(page->page_number == page_number);
i32 pt_size = settings->pt_size; i32 pt_size = settings->parameters.pt_size;
b32 use_hinting = settings->use_hinting; b32 use_hinting = settings->parameters.use_hinting;
// 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;
@ -285,7 +285,7 @@ font_release_pages(System_Functions *system, Font_Page_Storage *storage){
internal b32 internal b32
font_load(System_Functions *system, Font_Settings *settings, Font_Metrics *metrics, Font_Page_Storage *pages){ font_load(System_Functions *system, Font_Settings *settings, Font_Metrics *metrics, Font_Page_Storage *pages){
i32 pt_size = settings->pt_size; i32 pt_size = settings->parameters.pt_size;
// 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;
@ -405,7 +405,7 @@ Sys_Font_Get_Loadable_Sig(system_font_get_loadable, i, out){
} }
internal internal
Sys_Font_Load_New_Font_Sig(system_font_load_new_font, stub){ Sys_Font_Face_Allocate_And_Init_Sig(system_font_face_allocate_and_init, new_settings){
i32 slot_max = fontvars.max_slot_count; i32 slot_max = fontvars.max_slot_count;
Font_Slot_Page *page_with_slot = 0; Font_Slot_Page *page_with_slot = 0;
@ -515,16 +515,12 @@ Sys_Font_Load_New_Font_Sig(system_font_load_new_font, stub){
Assert(((*is_active_flags) & is_active_mask) == 0); Assert(((*is_active_flags) & is_active_mask) == 0);
char *filename = stub->name; char *filename = new_settings->stub.name;
i32 filename_len = 0; i32 filename_len = 0;
for (;filename[filename_len];++filename_len); for (;filename[filename_len];++filename_len);
// Initialize Font Parameters // Initialize font settings.
Assert(filename_len <= sizeof(settings->stub.name) - 1); memcpy(settings, new_settings, sizeof(*new_settings));
memset(settings, 0, sizeof(*settings));
memcpy(&settings->stub, stub, sizeof(*stub));
settings->pt_size = fontvars.pt_size;
settings->use_hinting = fontvars.use_hinting;
memset(metrics, 0, sizeof(*metrics)); memset(metrics, 0, sizeof(*metrics));
memset(pages, 0, sizeof(*pages)); memset(pages, 0, sizeof(*pages));
@ -580,7 +576,7 @@ system_font_get_active_location(Font_ID font_id){
} }
internal internal
Sys_Font_Change_Settings_Sig(system_font_change_settings, font_id, new_settings){ Sys_Font_Face_Change_Settings_Sig(system_font_face_change_settings, font_id, new_settings){
if (font_id == 0){ if (font_id == 0){
return(false); return(false);
} }
@ -613,6 +609,26 @@ Sys_Font_Change_Settings_Sig(system_font_change_settings, font_id, new_settings)
return(made_change); return(made_change);
} }
internal
Sys_Font_Face_Release_Sig(system_font_face_release, font_id){
if (font_id == 0){
return(false);
}
Font_Slot_Page_And_Index page_and_index = system_font_get_active_location(font_id);
if (page_and_index.page == 0){
return(false);
}
Font_Page_Storage *pages_ptr = &page_and_index.page->pages[page_and_index.index];
font_release_pages(&sysfunc, pages_ptr);
u64 *is_active_ptr = &page_and_index.page->is_active[page_and_index.index/64];
(*is_active_ptr) &= (~(1 << (page_and_index.index%64)));
return(true);
}
internal internal
Sys_Font_Get_Name_By_ID_Sig(system_font_get_name_by_id, font_id, str_out, capacity){ Sys_Font_Get_Name_By_ID_Sig(system_font_get_name_by_id, font_id, str_out, capacity){
i32 length = 0; i32 length = 0;
@ -707,8 +723,8 @@ system_font_init(Font_Functions *font_links, u32 pt_size, b32 use_hinting, Font_
// Linking // Linking
font_links->get_loadable_count = system_font_get_loadable_count; font_links->get_loadable_count = system_font_get_loadable_count;
font_links->get_loadable = system_font_get_loadable; font_links->get_loadable = system_font_get_loadable;
font_links->load_new_font = system_font_load_new_font; font_links->face_allocate_and_init = system_font_face_allocate_and_init;
font_links->change_settings = system_font_change_settings; font_links->face_change_settings = system_font_face_change_settings;
font_links->get_largest_id = system_font_get_largest_id; font_links->get_largest_id = system_font_get_largest_id;
font_links->get_count = system_font_get_count; font_links->get_count = system_font_get_count;
font_links->get_name_by_id = system_font_get_name_by_id; font_links->get_name_by_id = system_font_get_name_by_id;
@ -720,6 +736,8 @@ system_font_init(Font_Functions *font_links, u32 pt_size, b32 use_hinting, Font_
// Initialize fontvars // Initialize fontvars
memset(&fontvars, 0, sizeof(fontvars)); memset(&fontvars, 0, sizeof(fontvars));
dll_init_sentinel(&fontvars.slot_pages_sentinel); dll_init_sentinel(&fontvars.slot_pages_sentinel);
// TODO(allen): Eliminate from fontvars.
fontvars.pt_size = pt_size; fontvars.pt_size = pt_size;
fontvars.use_hinting = use_hinting; fontvars.use_hinting = use_hinting;
@ -766,7 +784,11 @@ system_font_init(Font_Functions *font_links, u32 pt_size, b32 use_hinting, Font_
// Force load one font. // Force load one font.
Font_Setup *first_setup = list.first; Font_Setup *first_setup = list.first;
system_font_load_new_font(&first_setup->stub); Font_Settings first_settings = {0};
memcpy(&first_settings.stub, &first_setup->stub, sizeof(first_setup->stub));
first_settings.parameters.pt_size = pt_size;
first_settings.parameters.use_hinting = use_hinting;
system_font_face_allocate_and_init(&first_settings);
} }
// BOTTOM // BOTTOM