From eb6f4fa08e761e1acc1a3389ab06856ac1dcd2be Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 17 Nov 2017 16:20:25 -0500 Subject: [PATCH] Linux fonts up and running --- 4ed_font_provider_freetype.cpp | 9 +++++- 4ed_font_provider_freetype.h | 6 +++- platform_linux/linux_4ed.cpp | 56 ++++++++++++++++++++++++++++++++++ platform_win32/win32_4ed.cpp | 4 ++- 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/4ed_font_provider_freetype.cpp b/4ed_font_provider_freetype.cpp index c27f7228..11950b02 100644 --- a/4ed_font_provider_freetype.cpp +++ b/4ed_font_provider_freetype.cpp @@ -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); } diff --git a/4ed_font_provider_freetype.h b/4ed_font_provider_freetype.h index 75e56c06..41c55628 100644 --- a/4ed_font_provider_freetype.h +++ b/4ed_font_provider_freetype.h @@ -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 diff --git a/platform_linux/linux_4ed.cpp b/platform_linux/linux_4ed.cpp index dd5414d6..29e14a74 100644 --- a/platform_linux/linux_4ed.cpp +++ b/platform_linux/linux_4ed.cpp @@ -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 +#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 #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); diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 335e6347..b6eb5452 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -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); }