getting buffer font info

master
Allen Webster 2016-10-24 22:45:34 -04:00
parent ad5b203b57
commit 54bea311a2
9 changed files with 93 additions and 48 deletions

File diff suppressed because one or more lines are too long

View File

@ -49,6 +49,7 @@
#define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int32_t len) #define CHANGE_THEME_SIG(n) void n(Application_Links *app, char *name, int32_t len)
#define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files) #define CHANGE_FONT_SIG(n) void n(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files)
#define BUFFER_SET_FONT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len) #define BUFFER_SET_FONT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len)
#define BUFFER_GET_FONT_SIG(n) int32_t n(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max)
#define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count) #define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count)
#define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count) #define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, int32_t count)
#define DIRECTORY_GET_HOT_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity) #define DIRECTORY_GET_HOT_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity)
@ -115,6 +116,7 @@ typedef PRINT_MESSAGE_SIG(Print_Message_Function);
typedef CHANGE_THEME_SIG(Change_Theme_Function); typedef CHANGE_THEME_SIG(Change_Theme_Function);
typedef CHANGE_FONT_SIG(Change_Font_Function); typedef CHANGE_FONT_SIG(Change_Font_Function);
typedef BUFFER_SET_FONT_SIG(Buffer_Set_Font_Function); typedef BUFFER_SET_FONT_SIG(Buffer_Set_Font_Function);
typedef BUFFER_GET_FONT_SIG(Buffer_Get_Font_Function);
typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function); typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function);
typedef GET_THEME_COLORS_SIG(Get_Theme_Colors_Function); typedef GET_THEME_COLORS_SIG(Get_Theme_Colors_Function);
typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot_Function); typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot_Function);
@ -183,6 +185,7 @@ Print_Message_Function *print_message;
Change_Theme_Function *change_theme; Change_Theme_Function *change_theme;
Change_Font_Function *change_font; Change_Font_Function *change_font;
Buffer_Set_Font_Function *buffer_set_font; Buffer_Set_Font_Function *buffer_set_font;
Buffer_Get_Font_Function *buffer_get_font;
Set_Theme_Colors_Function *set_theme_colors; Set_Theme_Colors_Function *set_theme_colors;
Get_Theme_Colors_Function *get_theme_colors; Get_Theme_Colors_Function *get_theme_colors;
Directory_Get_Hot_Function *directory_get_hot; Directory_Get_Hot_Function *directory_get_hot;
@ -250,6 +253,7 @@ Print_Message_Function *print_message_;
Change_Theme_Function *change_theme_; Change_Theme_Function *change_theme_;
Change_Font_Function *change_font_; Change_Font_Function *change_font_;
Buffer_Set_Font_Function *buffer_set_font_; Buffer_Set_Font_Function *buffer_set_font_;
Buffer_Get_Font_Function *buffer_get_font_;
Set_Theme_Colors_Function *set_theme_colors_; Set_Theme_Colors_Function *set_theme_colors_;
Get_Theme_Colors_Function *get_theme_colors_; Get_Theme_Colors_Function *get_theme_colors_;
Directory_Get_Hot_Function *directory_get_hot_; Directory_Get_Hot_Function *directory_get_hot_;
@ -325,6 +329,7 @@ app_links->print_message_ = Print_Message;\
app_links->change_theme_ = Change_Theme;\ app_links->change_theme_ = Change_Theme;\
app_links->change_font_ = Change_Font;\ app_links->change_font_ = Change_Font;\
app_links->buffer_set_font_ = Buffer_Set_Font;\ app_links->buffer_set_font_ = Buffer_Set_Font;\
app_links->buffer_get_font_ = Buffer_Get_Font;\
app_links->set_theme_colors_ = Set_Theme_Colors;\ app_links->set_theme_colors_ = Set_Theme_Colors;\
app_links->get_theme_colors_ = Get_Theme_Colors;\ app_links->get_theme_colors_ = Get_Theme_Colors;\
app_links->directory_get_hot_ = Directory_Get_Hot;\ app_links->directory_get_hot_ = Directory_Get_Hot;\
@ -392,6 +397,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len)
static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme(app, name, len));} static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme(app, name, len));}
static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font(app, name, len, apply_to_all_files));} static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font(app, name, len, apply_to_all_files));}
static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font(app, buffer, name, len));} static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font(app, buffer, name, len));}
static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font(app, buffer, name_out, name_max));}
static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors(app, colors, count));} static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors(app, colors, count));}
static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors(app, colors, count));} static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors(app, colors, count));}
static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot(app, out, capacity));} static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot(app, out, capacity));}
@ -459,6 +465,7 @@ static inline void print_message(Application_Links *app, char *str, int32_t len)
static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme_(app, name, len));} static inline void change_theme(Application_Links *app, char *name, int32_t len){(app->change_theme_(app, name, len));}
static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font_(app, name, len, apply_to_all_files));} static inline void change_font(Application_Links *app, char *name, int32_t len, bool32 apply_to_all_files){(app->change_font_(app, name, len, apply_to_all_files));}
static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font_(app, buffer, name, len));} static inline void buffer_set_font(Application_Links *app, Buffer_Summary *buffer, char *name, int32_t len){(app->buffer_set_font_(app, buffer, name, len));}
static inline int32_t buffer_get_font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max){return(app->buffer_get_font_(app, buffer, name_out, name_max));}
static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors_(app, colors, count));} static inline void set_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->set_theme_colors_(app, colors, count));}
static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors_(app, colors, count));} static inline void get_theme_colors(Application_Links *app, Theme_Color *colors, int32_t count){(app->get_theme_colors_(app, colors, count));}
static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot_(app, out, capacity));} static inline int32_t directory_get_hot(Application_Links *app, char *out, int32_t capacity){return(app->directory_get_hot_(app, out, capacity));}

View File

@ -158,6 +158,22 @@ HOOK_SIG(my_exit){
return(1); return(1);
} }
// NOTE(allen|a4.0.12): This is for testing it may be removed and replaced with a better test for the buffer_get_font when you eventally read this and wonder what it's about.
CUSTOM_COMMAND_SIG(write_name_of_font){
View_Summary view = get_active_view(app, AccessOpen);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen);
char font_name[256];
int32_t font_max = 256;
int32_t font_len = buffer_get_font(app, &buffer, font_name, font_max);
if (font_len != 0){
write_string(app, &view, &buffer, make_string(font_name, font_len));
}
print_message(app, literal("TRIED WRITING FONT NAME"));
}
CUSTOM_COMMAND_SIG(newline_or_goto_position){ CUSTOM_COMMAND_SIG(newline_or_goto_position){
View_Summary view = get_active_view(app, AccessProtected); View_Summary view = get_active_view(app, AccessProtected);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
@ -176,7 +192,7 @@ OPEN_FILE_HOOK_SIG(my_file_settings){
// NOTE(allen|a4.0.8): The get_parameter_buffer was eliminated // NOTE(allen|a4.0.8): The get_parameter_buffer was eliminated
// and instead the buffer is passed as an explicit parameter through // and instead the buffer is passed as an explicit parameter through
// the function call. That is where buffer_id comes from here. // the function call. That is where buffer_id comes from here.
uint32_t access = AccessProtected|AccessHidden; uint32_t access = AccessAll;
Buffer_Summary buffer = get_buffer(app, buffer_id, access); Buffer_Summary buffer = get_buffer(app, buffer_id, access);
assert(buffer.exists); assert(buffer.exists);
@ -412,6 +428,8 @@ default_keys(Bind_Helper *context){
bind(context, '\n', MDFR_SHIFT, newline_or_goto_position); bind(context, '\n', MDFR_SHIFT, newline_or_goto_position);
bind(context, ' ', MDFR_SHIFT, write_character); bind(context, ' ', MDFR_SHIFT, write_character);
bind(context, ';', MDFR_ALT, write_name_of_font);
end_map(context); end_map(context);
} }

View File

@ -1965,15 +1965,18 @@ seek_command(alphanumeric_or_camel, left, BoundaryAlphanumeric | BoundaryCamelC
// special string writing commands // special string writing commands
// //
static void
write_string(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, String string){
buffer_replace_range(app, buffer, view->cursor.pos, view->cursor.pos, string.str, string.size);
view_set_cursor(app, view, seek_pos(view->cursor.pos + string.size), 1);
}
static void static void
write_string(Application_Links *app, String string){ write_string(Application_Links *app, String string){
uint32_t access = AccessOpen; uint32_t access = AccessOpen;
View_Summary view = get_active_view(app, access); View_Summary view = get_active_view(app, access);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, access); Buffer_Summary buffer = get_buffer(app, view.buffer_id, access);
buffer_replace_range(app, &buffer, write_string(app, &view, &buffer, string);
view.cursor.pos, view.cursor.pos,
string.str, string.size);
view_set_cursor(app, &view, seek_pos(view.cursor.pos + string.size), true);
} }
CUSTOM_COMMAND_SIG(write_increment){ CUSTOM_COMMAND_SIG(write_increment){

View File

@ -2071,6 +2071,26 @@ DOC(This call sets the display font of a particular buffer.)
} }
} }
API_EXPORT int32_t
Buffer_Get_Font(Application_Links *app, Buffer_Summary *buffer, char *name_out, int32_t name_max)
{
Command_Data *cmd = (Command_Data*)app->cmd_context;
System_Functions *system = cmd->system;
Models *models = cmd->models;
Editing_File *file = imp_get_file(cmd, buffer);
int32_t result = 0;
if (file){
Font_Set *set = models->font_set;
String name = make_string_cap(name_out, 0, name_max);
if (font_set_get_name(set, file->settings.font_id, &name)){
result = name.size;
}
}
return(result);
}
API_EXPORT void API_EXPORT void
Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int32_t count) Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int32_t count)
/* /*

View File

@ -4558,7 +4558,6 @@ 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;
i16 i = 1, count = (i16)models->font_set->count + 1; i16 i = 1, count = (i16)models->font_set->count + 1;
@ -4577,7 +4576,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
i16 new_font_id = font_id; i16 new_font_id = font_id;
for (i = 1; i < count; ++i){ for (i = 1; i < count; ++i){
info = get_font_info(font_set, i); Font_Info *info = get_font_info(font_set, i);
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, info->name)){

View File

@ -204,18 +204,20 @@ font_set_add(Partition *partition, Font_Set *set,
internal b32 internal b32
font_set_find_pos(Font_Set *set, String name, u32 *position){ font_set_find_pos(Font_Set *set, String name, u32 *position){
b32 result; u32 hash = font_hash(name);
u32 hash, i, j; u32 i = hash % set->max;
hash = font_hash(name); u32 j = i - 1;
i = hash % set->max; if (j <= 1){
j = i - 1; j += set->max;
if (j <= 1) j += set->max; }
result = 0; b32 result = 0;
Font_Table_Entry *entry;
for (; i != j; ++i){ for (; i != j; ++i){
if (i == set->max) i = 0; if (i == set->max){
entry = set->entries + i; i = 0;
}
Font_Table_Entry *entry = set->entries + i;
if (entry->hash == hash){ if (entry->hash == hash){
if (match_ss(name, entry->name)){ if (match_ss(name, entry->name)){
result = 1; result = 1;
@ -228,16 +230,20 @@ font_set_find_pos(Font_Set *set, String name, u32 *position){
return(result); return(result);
} }
internal b32
font_set_get_name(Font_Set *set, i16 font_id, String *name){
Font_Info *info = get_font_info(set, font_id);
b32 result = copy_checked_ss(name, info->name);
return(result);
}
internal b32 internal b32
font_set_extract(Font_Set *set, String name, i16 *font_id){ font_set_extract(Font_Set *set, String name, i16 *font_id){
b32 result;
u32 position; u32 position;
b32 result = font_set_find_pos(set, name, &position);
result = font_set_find_pos(set, name, &position);
if (result){ if (result){
*font_id = set->entries[position].font_id; *font_id = set->entries[position].font_id;
} }
return(result); return(result);
} }

View File

@ -102,17 +102,9 @@ typedef Draw_Pop_Clip_Sig(Draw_Pop_Clip);
#define Draw_Push_Piece_Sig(name) void name(Render_Target *target, Render_Piece_Combined piece) #define Draw_Push_Piece_Sig(name) void name(Render_Target *target, Render_Piece_Combined piece)
typedef Draw_Push_Piece_Sig(Draw_Push_Piece); typedef Draw_Push_Piece_Sig(Draw_Push_Piece);
#define Font_Load_Sig(name) i32 name( \ #define Font_Load_Sig(name) i32 name(Render_Font *font_out, char *filename, char *fontname, i32 pt_size, i32 tab_width, b32 store_texture)
Render_Font *font_out, \
char *filename, \
char *fontname, \
i32 pt_size, \
i32 tab_width, \
b32 store_texture)
typedef Font_Load_Sig(Font_Load); typedef Font_Load_Sig(Font_Load);
#define Release_Font_Sig(name) void name(Render_Font *font) #define Release_Font_Sig(name) void name(Render_Font *font)
typedef Release_Font_Sig(Release_Font); typedef Release_Font_Sig(Release_Font);
@ -140,15 +132,15 @@ struct Font_Set{
Font_Info *info; Font_Info *info;
Font_Table_Entry *entries; Font_Table_Entry *entries;
u32 count, max; u32 count, max;
void *font_block; void *font_block;
Font_Slot free_slots; Font_Slot free_slots;
Font_Slot used_slots; Font_Slot used_slots;
//Font_Info_Load *font_info_load; //Font_Info_Load *font_info_load;
Font_Load *font_load; Font_Load *font_load;
Release_Font *release_font; Release_Font *release_font;
b8 *font_used_flags; b8 *font_used_flags;
i16 used_this_frame; i16 used_this_frame;
i16 live_max; i16 live_max;
@ -159,7 +151,7 @@ struct Render_Target{
void *context; void *context;
i32_Rect clip_boxes[5]; i32_Rect clip_boxes[5];
i32 clip_top; i32 clip_top;
i32 width, height; i32 width, height;
i32 bound_texture; i32 bound_texture;
u32 color; u32 color;

View File

@ -177,9 +177,9 @@
; [X] handle unclosed statements ; [X] handle unclosed statements
; [X] wrapped line indication ; [X] wrapped line indication
; [X] additional width for nesting? ; [X] additional width for nesting?
; [X] special indent rules in preprocessor body
; [X] handle comments ; [X] handle comments
; [] solve the comment lead whitespace problem ; [] solve the comment lead whitespace problem
; [] special indent rules in preprocessor body
; [] fix issues when relexing happens in parallel ; [] fix issues when relexing happens in parallel
; [] remeasure version of measure_wraps ; [] remeasure version of measure_wraps