4coder/linux_font.cpp

105 lines
2.4 KiB
C++
Raw Normal View History

2017-03-10 20:44:42 +00:00
/*
* Insofaras
*
* ??.??.2016
*
* For getting the font files on Linux.
*
*/
// TOP
2017-03-19 18:25:12 +00:00
#if 0
2016-06-17 05:28:05 +00:00
#undef internal
#include <fontconfig/fontconfig.h>
#define internal static
//TODO(inso): put in linuxvars
static FcConfig* fc;
internal char*
linux_get_sys_font(char* name, i32 pt_size){
char* result = 0;
2017-03-10 20:44:42 +00:00
2016-06-17 05:28:05 +00:00
if(!fc){
fc = FcInitLoadConfigAndFonts();
}
2017-03-10 20:44:42 +00:00
2016-06-17 05:28:05 +00:00
FcPattern* pat = FcPatternBuild(
NULL,
FC_POSTSCRIPT_NAME, FcTypeString, name,
FC_SIZE, FcTypeDouble, (double)pt_size,
FC_FONTFORMAT, FcTypeString, "TrueType",
NULL
2017-03-10 20:44:42 +00:00
);
2016-06-17 05:28:05 +00:00
FcConfigSubstitute(fc, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
2017-03-10 20:44:42 +00:00
2016-06-17 05:28:05 +00:00
FcResult res;
FcPattern* font = FcFontMatch(fc, pat, &res);
FcChar8* fname = 0;
2017-03-10 20:44:42 +00:00
2016-06-17 05:28:05 +00:00
if(font){
FcPatternGetString(font, FC_FILE, 0, &fname);
if(fname){
result = strdup((char*)fname);
fprintf(stderr, "Got system font from FontConfig: %s\n", result);
}
FcPatternDestroy(font);
}
2017-03-10 20:44:42 +00:00
2016-06-17 05:28:05 +00:00
FcPatternDestroy(pat);
2017-03-10 20:44:42 +00:00
2016-06-17 05:28:05 +00:00
if(!result){
char space[1024];
String str = make_fixed_width_string(space);
if(sysshared_to_binary_path(&str, name)){
result = strdup(space);
} else {
result = strdup(name);
}
}
2017-03-10 20:44:42 +00:00
2016-06-17 05:28:05 +00:00
return result;
}
2016-06-21 18:13:28 +00:00
internal b32
2016-07-05 14:02:55 +00:00
linux_font_load(Partition *part, Render_Font *rf, char *name, i32 pt_size, i32 tab_width, b32 use_hinting){
2016-06-21 18:13:28 +00:00
b32 result = 0;
2017-03-10 20:44:42 +00:00
2016-06-21 18:13:28 +00:00
Temp_Memory temp = begin_temp_memory(part);
2017-03-10 20:44:42 +00:00
2016-06-17 05:28:05 +00:00
#if 0
char* filename = linux_get_sys_font(name, pt_size);
#else
2016-06-21 18:13:28 +00:00
char* filename = push_array(part, char, 256);
if (filename != 0){
String str = make_string_cap(filename, 0, 256);
2016-06-21 18:13:28 +00:00
sysshared_to_binary_path(&str, name);
2016-06-17 05:28:05 +00:00
}
#endif
2017-03-10 20:44:42 +00:00
2016-06-21 18:13:28 +00:00
if (filename != 0){
2016-09-04 21:24:48 +00:00
struct stat st;
if(stat(filename, &st) == -1 || S_ISDIR(st.st_mode)){
char buff[1024];
2017-03-10 20:44:42 +00:00
2016-09-04 21:24:48 +00:00
// NOTE(inso): if/when you can load fonts from anywhere, the message should be changed.
snprintf(buff, sizeof(buff), "Unable to load font '%s'. Make sure this file is in the same directory as the '4ed' executable.", filename);
LinuxFatalErrorMsg(buff);
exit(1);
}
2017-03-10 20:44:42 +00:00
2016-07-05 14:02:55 +00:00
result = font_load_freetype(part, rf, filename, pt_size, tab_width, use_hinting);
2016-06-17 05:28:05 +00:00
}
2017-03-10 20:44:42 +00:00
2016-06-21 18:13:28 +00:00
end_temp_memory(temp);
2017-03-10 20:44:42 +00:00
2016-06-21 18:13:28 +00:00
return(result);
2016-06-17 05:28:05 +00:00
}
2017-03-19 18:25:12 +00:00
#endif
2017-03-10 20:44:42 +00:00
// BOTTOM