getting buffer font info
This commit is contained in:
parent
ad5b203b57
commit
54bea311a2
File diff suppressed because one or more lines are too long
|
@ -49,6 +49,7 @@
|
|||
#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 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 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)
|
||||
|
@ -115,6 +116,7 @@ typedef PRINT_MESSAGE_SIG(Print_Message_Function);
|
|||
typedef CHANGE_THEME_SIG(Change_Theme_Function);
|
||||
typedef CHANGE_FONT_SIG(Change_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 GET_THEME_COLORS_SIG(Get_Theme_Colors_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_Font_Function *change_font;
|
||||
Buffer_Set_Font_Function *buffer_set_font;
|
||||
Buffer_Get_Font_Function *buffer_get_font;
|
||||
Set_Theme_Colors_Function *set_theme_colors;
|
||||
Get_Theme_Colors_Function *get_theme_colors;
|
||||
Directory_Get_Hot_Function *directory_get_hot;
|
||||
|
@ -250,6 +253,7 @@ Print_Message_Function *print_message_;
|
|||
Change_Theme_Function *change_theme_;
|
||||
Change_Font_Function *change_font_;
|
||||
Buffer_Set_Font_Function *buffer_set_font_;
|
||||
Buffer_Get_Font_Function *buffer_get_font_;
|
||||
Set_Theme_Colors_Function *set_theme_colors_;
|
||||
Get_Theme_Colors_Function *get_theme_colors_;
|
||||
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_font_ = Change_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->get_theme_colors_ = Get_Theme_Colors;\
|
||||
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_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 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 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));}
|
||||
|
@ -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_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 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 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));}
|
||||
|
|
|
@ -158,6 +158,22 @@ HOOK_SIG(my_exit){
|
|||
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){
|
||||
View_Summary view = get_active_view(app, 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
|
||||
// and instead the buffer is passed as an explicit parameter through
|
||||
// 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);
|
||||
assert(buffer.exists);
|
||||
|
||||
|
@ -412,6 +428,8 @@ default_keys(Bind_Helper *context){
|
|||
bind(context, '\n', MDFR_SHIFT, newline_or_goto_position);
|
||||
bind(context, ' ', MDFR_SHIFT, write_character);
|
||||
|
||||
bind(context, ';', MDFR_ALT, write_name_of_font);
|
||||
|
||||
end_map(context);
|
||||
}
|
||||
|
||||
|
|
|
@ -1965,15 +1965,18 @@ seek_command(alphanumeric_or_camel, left, BoundaryAlphanumeric | BoundaryCamelC
|
|||
// 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
|
||||
write_string(Application_Links *app, String string){
|
||||
uint32_t access = AccessOpen;
|
||||
View_Summary view = get_active_view(app, access);
|
||||
Buffer_Summary buffer = get_buffer(app, view.buffer_id, access);
|
||||
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), true);
|
||||
write_string(app, &view, &buffer, string);
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(write_increment){
|
||||
|
|
|
@ -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
|
||||
Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int32_t count)
|
||||
/*
|
||||
|
|
|
@ -4558,7 +4558,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
|
|||
Assert(view->file_data.file);
|
||||
|
||||
Font_Set *font_set = models->font_set;
|
||||
Font_Info *info = 0;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
if (i != font_id){
|
||||
if (gui_do_font_button(target, id, i, info->name)){
|
||||
|
|
|
@ -204,18 +204,20 @@ font_set_add(Partition *partition, Font_Set *set,
|
|||
|
||||
internal b32
|
||||
font_set_find_pos(Font_Set *set, String name, u32 *position){
|
||||
b32 result;
|
||||
u32 hash, i, j;
|
||||
hash = font_hash(name);
|
||||
i = hash % set->max;
|
||||
j = i - 1;
|
||||
if (j <= 1) j += set->max;
|
||||
u32 hash = font_hash(name);
|
||||
u32 i = hash % set->max;
|
||||
u32 j = i - 1;
|
||||
if (j <= 1){
|
||||
j += set->max;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
Font_Table_Entry *entry;
|
||||
b32 result = 0;
|
||||
for (; i != j; ++i){
|
||||
if (i == set->max) i = 0;
|
||||
entry = set->entries + i;
|
||||
if (i == set->max){
|
||||
i = 0;
|
||||
}
|
||||
|
||||
Font_Table_Entry *entry = set->entries + i;
|
||||
if (entry->hash == hash){
|
||||
if (match_ss(name, entry->name)){
|
||||
result = 1;
|
||||
|
@ -229,15 +231,19 @@ font_set_find_pos(Font_Set *set, String name, u32 *position){
|
|||
}
|
||||
|
||||
internal b32
|
||||
font_set_extract(Font_Set *set, String name, i16 *font_id){
|
||||
b32 result;
|
||||
u32 position;
|
||||
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);
|
||||
}
|
||||
|
||||
result = font_set_find_pos(set, name, &position);
|
||||
internal b32
|
||||
font_set_extract(Font_Set *set, String name, i16 *font_id){
|
||||
u32 position;
|
||||
b32 result = font_set_find_pos(set, name, &position);
|
||||
if (result){
|
||||
*font_id = set->entries[position].font_id;
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
typedef Draw_Push_Piece_Sig(Draw_Push_Piece);
|
||||
|
||||
#define Font_Load_Sig(name) i32 name( \
|
||||
Render_Font *font_out, \
|
||||
char *filename, \
|
||||
char *fontname, \
|
||||
i32 pt_size, \
|
||||
i32 tab_width, \
|
||||
b32 store_texture)
|
||||
#define Font_Load_Sig(name) i32 name(Render_Font *font_out, char *filename, char *fontname, i32 pt_size, i32 tab_width, b32 store_texture)
|
||||
typedef Font_Load_Sig(Font_Load);
|
||||
|
||||
|
||||
|
||||
#define Release_Font_Sig(name) void name(Render_Font *font)
|
||||
typedef Release_Font_Sig(Release_Font);
|
||||
|
||||
|
|
2
TODO.txt
2
TODO.txt
|
@ -177,9 +177,9 @@
|
|||
; [X] handle unclosed statements
|
||||
; [X] wrapped line indication
|
||||
; [X] additional width for nesting?
|
||||
; [X] special indent rules in preprocessor body
|
||||
; [X] handle comments
|
||||
; [] solve the comment lead whitespace problem
|
||||
; [] special indent rules in preprocessor body
|
||||
; [] fix issues when relexing happens in parallel
|
||||
; [] remeasure version of measure_wraps
|
||||
|
||||
|
|
Loading…
Reference in New Issue