Mac font listing 50% done, switching to build the rest on windows where I can actually get stuff done quickly :///

master
Allen Webster 2017-11-17 17:53:17 -05:00
parent 149514dc7c
commit 421e3665db
3 changed files with 69 additions and 0 deletions

View File

@ -337,6 +337,14 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
Sys_Font_Data_Not_Used;
internal void
osx_get_loadable_fonts(Partition *part, Font_Setup_List *list){
OSX_Loadable_Fonts fonts = osx_list_loadable_fonts();
for (i32 i = 0; i < fonts.count; ++i){
}
}
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include "opengl/4ed_opengl_render.cpp"
@ -657,6 +665,7 @@ osx_init(){
Partition *scratch = &shared_vars.scratch;
Temp_Memory temp = begin_temp_memory(scratch);
Font_Setup_List font_setup = system_font_get_local_stubs(scratch);
osx_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

@ -725,6 +725,57 @@ osx_timer_seconds(void){
return(result);
}
NSString *get_font_path(NSFont *font){
CFStringRef name = (CFStringRef)[font fontName];
CGFloat size = [font pointSize];
CTFontDescriptorRef ref = CTFontDescriptorCreateWithNameAndSize(name, size);
CFURLRef url = CTFontDescriptorCopyAttribute(ref, kCTFontURLAttribute);
NSString *path = [(NSURL *)CFBridgingRelease(url) path];
return(path);
}
OSX_Loadable_Fonts
osx_list_loadable_fonts(void){
NSFontManager *font_manager = [NSFontManager sharedFontManager];
NSArray<NSString*> *fonts = [font_manager availableFontFamilies];
OSX_Loadable_Fonts result = {0};
NSUInteger count_u = [fonts count];
int count = (int)count_u;
result.count = count;
size_t memsize = count*2*sizeof(char*);
void *mem = malloc(memsize);
result.names = (char**)mem;
result.paths = result.names + count;
for (int i = 0; i < count; ++i){
NSString *font_n = fonts[i];
char *font_n_c = (char*)[font_n UTF8String];
NSFont *font = [font_manager
fontWithFamily:font_n
traits:NSUnboldFontMask|NSUnitalicFontMask
weight:5
size:12];
NSString *path = get_font_path(font);
char *path_c = 0;
if (path != nil){
path_c = (char*)[path UTF8String];
}
result.names[i] = font_n_c;
result.paths[i] = path_c;
}
for (int i = 0; i < count; ++i){
char *name = result.names[i];
char *path = result.paths[i];
fprintf(stdout, "found: %s\nat: %s\n", name, path);
fflush(stdout);
}
return(result);
}
int
main(int argc, char **argv){
memset(&osx_objc, 0, sizeof(osx_objc));

View File

@ -56,6 +56,12 @@ typedef struct OSX_Objective_C_Vars{
char **argv;
} OSX_Objective_C_Vars;
typedef struct OSX_Loadable_Fonts{
char **names;
char **paths;
i32 count;
} OSX_Loadable_Fonts;
// In C++ layer.
extern OSX_Objective_C_Vars osx_objc;
@ -129,6 +135,9 @@ osx_close_app(void);
external f32
osx_timer_seconds(void);
external OSX_Loadable_Fonts
osx_list_loadable_fonts(void);
#endif
// BOTTOM