probably fix linux font loading
This commit is contained in:
parent
36bb5f8db0
commit
2cc4a8f0a7
|
@ -94,7 +94,7 @@
|
||||||
#define function static
|
#define function static
|
||||||
#undef Cursor
|
#undef Cursor
|
||||||
|
|
||||||
#include <fontconfig/fontconfig.h>
|
//#include <fontconfig/fontconfig.h>
|
||||||
#define internal static
|
#define internal static
|
||||||
|
|
||||||
#include <GL/glx.h>
|
#include <GL/glx.h>
|
||||||
|
@ -158,7 +158,7 @@ struct Linux_Vars {
|
||||||
int xfixes_selection_event;
|
int xfixes_selection_event;
|
||||||
XIM xim;
|
XIM xim;
|
||||||
XIC xic;
|
XIC xic;
|
||||||
FcConfig* fontconfig;
|
//FcConfig* fontconfig;
|
||||||
XkbDescPtr xkb;
|
XkbDescPtr xkb;
|
||||||
|
|
||||||
Linux_Input_Chunk input;
|
Linux_Input_Chunk input;
|
||||||
|
@ -567,85 +567,24 @@ graphics_fill_texture_sig(){
|
||||||
|
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
internal Face_Description
|
internal Face*
|
||||||
linux_find_font(Face_Description* desc) {
|
font_make_face(Arena* arena, Face_Description* description, f32 scale_factor) {
|
||||||
Face_Description result = *desc;
|
|
||||||
|
|
||||||
char* name = strndupa((char*)desc->font.file_name.str, desc->font.file_name.size);
|
Face_Description local_description = *description;
|
||||||
|
String_Const_u8* name = &local_description.font.file_name;
|
||||||
|
|
||||||
double size;
|
// if description->font.file_name is a relative path, prepend the font directory.
|
||||||
const char* style;
|
if(string_get_character(*name, 0) != '/') {
|
||||||
{
|
String_Const_u8 binary = system_get_path(arena, SystemPath_Binary);
|
||||||
Face_Load_Parameters* p = &desc->parameters;
|
*name = push_u8_stringf(arena, "%.*sfonts/%.*s", string_expand(binary), string_expand(*name));
|
||||||
size = p->pt_size;
|
|
||||||
|
|
||||||
if(p->bold && p->italic) {
|
|
||||||
style = "Bold Italic";
|
|
||||||
} else if(p->bold) {
|
|
||||||
style = "Bold";
|
|
||||||
} else if(p->italic) {
|
|
||||||
style = "Italic";
|
|
||||||
} else {
|
|
||||||
style = "Regular";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FcPattern *pattern = FcPatternBuild(0,
|
Face* result = ft__font_make_face(arena, &local_description, scale_factor);
|
||||||
FC_POSTSCRIPT_NAME, FcTypeString, name,
|
|
||||||
FC_SIZE, FcTypeDouble, size,
|
|
||||||
FC_FONTFORMAT, FcTypeString, "TrueType",
|
|
||||||
FC_STYLE, FcTypeString, (FcChar8*)style,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if(!pattern) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FcConfigSubstitute(linuxvars.fontconfig, pattern, FcMatchPattern)){
|
|
||||||
FcDefaultSubstitute(pattern);
|
|
||||||
|
|
||||||
FcResult res;
|
|
||||||
FcPattern *font = FcFontMatch(linuxvars.fontconfig, pattern, &res);
|
|
||||||
if (!font){
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
FcChar8 *filename = 0;
|
|
||||||
FcPatternGetString(font, FC_FILE, 0, &filename);
|
|
||||||
if(filename) {
|
|
||||||
LINUX_FN_DEBUG("FONTCONFIG FILENAME = %s\n", filename);
|
|
||||||
result.font.file_name = push_u8_stringf(&linuxvars.frame_arena, "%s", filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
FcPatternDestroy(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
FcPatternDestroy(pattern);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal
|
|
||||||
font_make_face_sig() {
|
|
||||||
|
|
||||||
Face* result = ft__font_make_face(arena, description, scale_factor);
|
|
||||||
|
|
||||||
// if it failed to load the font directly, try via fontconfig.
|
|
||||||
if(!result) {
|
|
||||||
Face_Description desc2 = {};
|
|
||||||
desc2.parameters = description->parameters;
|
|
||||||
desc2.font.file_name = string_front_of_path(description->font.file_name);
|
|
||||||
|
|
||||||
printf("FONT %.*s\n", string_expand(desc2.font.file_name));
|
|
||||||
desc2 = linux_find_font(&desc2);
|
|
||||||
result = ft__font_make_face(arena, &desc2, scale_factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!result) {
|
if(!result) {
|
||||||
// is this fatal? 4ed.cpp:277 (caller) does not check for null.
|
// is this fatal? 4ed.cpp:277 (caller) does not check for null.
|
||||||
String_Const_u8 s = description->font.file_name;
|
|
||||||
char msg[4096];
|
char msg[4096];
|
||||||
snprintf(msg, sizeof(msg), "Unable to load font: %.*s", (int)s.size, s.str);
|
snprintf(msg, sizeof(msg), "Unable to load font: %.*s", string_expand(*name));
|
||||||
system_error_box(msg);
|
system_error_box(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1809,7 +1748,7 @@ main(int argc, char **argv){
|
||||||
linuxvars.clipboard_arena = make_arena_system();
|
linuxvars.clipboard_arena = make_arena_system();
|
||||||
render_target.arena = make_arena_system(KB(256));
|
render_target.arena = make_arena_system(KB(256));
|
||||||
|
|
||||||
linuxvars.fontconfig = FcInitLoadConfigAndFonts();
|
//linuxvars.fontconfig = FcInitLoadConfigAndFonts();
|
||||||
|
|
||||||
linuxvars.cursor_show = MouseCursorShow_Always;
|
linuxvars.cursor_show = MouseCursorShow_Always;
|
||||||
linuxvars.prev_cursor_show = MouseCursorShow_Always;
|
linuxvars.prev_cursor_show = MouseCursorShow_Always;
|
||||||
|
|
Loading…
Reference in New Issue