Linux fonts up and running

This commit is contained in:
Allen Webster 2017-11-17 16:20:25 -05:00
parent 542d7a8a2a
commit eb6f4fa08e
4 changed files with 72 additions and 3 deletions

View File

@ -494,6 +494,7 @@ system_font_get_local_stubs(Partition *part){
if (dir_len + len + 1 <= sizeof(list.first->stub.name)){
Font_Setup *setup = push_struct(part, Font_Setup);
memset(setup, 0, sizeof(*setup));
partition_align(part, 8);
sll_push(list.first, list.last, setup);
@ -539,7 +540,13 @@ system_font_init(Font_Functions *font_links, u32 pt_size, b32 use_hinting, Font_
i32 capacity = (i32)(sizeof(loadable->display_name));
if (stub->load_from_path){
name_good = font_load_name(stub, loadable->display_name, capacity);
if (ptr->has_display_name){
name_good = true;
memcpy(loadable->display_name, ptr->name, ptr->len);
}
else{
name_good = font_load_name(stub, loadable->display_name, capacity);
}
if (name_good){
loadable->display_len = str_size(loadable->display_name);
}

View File

@ -36,6 +36,10 @@ global Font_Vars fontvars = {0};
struct Font_Setup{
Font_Setup *next;
Font_Loadable_Stub stub;
b32 has_display_name;
i32 len;
char name[64];
};
struct Font_Setup_List{
@ -54,7 +58,7 @@ struct Font_Raw_Data{
internal Sys_Font_Data(name);
#define Sys_Font_Data_Not_Used \
internal Sys_Font_Data(name){Font_Raw_Data data = {0}; InvalidCodePath; return(data);}
internal Sys_Font_Data(name){Font_Raw_Data data = {0}; LOG("there is no font data retrieval procedure available\n"); return(data);}
#endif

View File

@ -460,8 +460,63 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
#include "4ed_font_provider_freetype.h"
#include "4ed_font_provider_freetype.cpp"
#undef internal
#include <fontconfig/fontconfig.h>
#define internal static
Sys_Font_Data_Not_Used;
internal char*
linux_get_loadable_fonts(Partition *part, Font_Setup_List *list){
FcConfig* config = FcInitLoadConfigAndFonts();
FcPattern* pat = FcPatternBuild(
0,
FC_STYLE, FcTypeString, (FcChar8*)"Regular",
(void*)0);
FcObjectSet* os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char*)0);
FcFontSet* fs = FcFontList(config, pat, os);
if (fs != 0){
LOGF("Total matching fonts: %d\n", fs->nfont);
for (int i=0; fs && i < fs->nfont; ++i) {
FcPattern* font = fs->fonts[i];
FcChar8 *file = 0;
FcChar8 *style = 0;
FcChar8 *family = 0;
if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch &&
FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch)
{
Temp_Memory reset = begin_temp_memory(part);
Font_Setup *setup = push_array(part, Font_Setup, 1);
if (setup != 0){
memset(setup, 0, sizeof(*setup));
i32 len = str_size((char*)file);
if (len < sizeof(setup->stub.name)){
i32 name_len = str_size((char*)family);
if (name_len < sizeof(setup->name)){
setup->stub.load_from_path = true;
memcpy(setup->stub.name, file, len + 1);
setup->stub.len = len;
setup->has_display_name = true;
setup->len = name_len;
memcpy(setup->name, family, name_len + 1);
sll_push(list->first, list->last, setup);
}
else{
end_temp_memory(reset);
}
}
else{
end_temp_memory(reset);
}
}
}
}
FcFontSetDestroy(fs);
}
}
#include <GL/gl.h>
#include "opengl/4ed_opengl_render.cpp"
@ -1611,6 +1666,7 @@ main(int argc, char **argv){
Partition *scratch = &shared_vars.scratch;
Temp_Memory temp = begin_temp_memory(scratch);
Font_Setup_List font_setup = system_font_get_local_stubs(scratch);
linux_get_loadable_fonts(scratch, &font_setup);
system_font_init(&sysfunc.font, plat_settings.font_size, plat_settings.use_hinting, font_setup);
end_temp_memory(temp);

View File

@ -578,6 +578,7 @@ const TEXTMETRIC *lpntme,
DWORD FontType,
LPARAM lParam
){
if ((FontType & TRUETYPE_FONTTYPE) != 0){
ENUMLOGFONTEXDV *log_font = (ENUMLOGFONTEXDV*)lpelfe;
TCHAR *name = ((log_font)->elfEnumLogfontEx).elfLogFont.lfFaceName;
@ -594,8 +595,8 @@ LPARAM lParam
}
Win32_Font_Enum p = *(Win32_Font_Enum*)lParam;
Temp_Memory reset = begin_temp_memory(p.part);
Temp_Memory reset = begin_temp_memory(p.part);
Font_Setup *setup = push_array(p.part, Font_Setup, 1);
if (setup != 0){
memset(setup, 0, sizeof(*setup));
@ -619,6 +620,7 @@ LPARAM lParam
}
}
}
return(1);
}