font embedding improvements
This commit is contained in:
parent
a551b87d87
commit
42339b739b
@ -6,8 +6,10 @@ ImFont* ImFont_LoadFromFile(const char* file_path, f32 font_size){
|
|||||||
return io.Fonts->AddFontFromFileTTF(file_path, font_size);
|
return io.Fonts->AddFontFromFileTTF(file_path, font_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImFont* _ImFont_LoadEmbedded(const void* data, int data_size, f32 font_size){
|
ImFont* _ImFont_LoadEmbedded(const void* data, int data_size, const char* font_name, f32 font_size){
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
font_size *= getMainWindowDPI();
|
font_size *= getMainWindowDPI();
|
||||||
return io.Fonts->AddFontFromMemoryCompressedTTF(data, data_size, font_size);
|
ImFontConfig font_cfg = ImFontConfig();
|
||||||
|
sprintf_s(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", font_name, font_size);
|
||||||
|
return io.Fonts->AddFontFromMemoryCompressedTTF(data, data_size, font_size, &font_cfg);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,16 +14,18 @@
|
|||||||
#include "../generated/fonts_embedded.h"
|
#include "../generated/fonts_embedded.h"
|
||||||
|
|
||||||
#define __CAT3(A,B,C) A##B##C
|
#define __CAT3(A,B,C) A##B##C
|
||||||
#define embedded_font_data(FONT_NAME) __CAT3(font_,FONT_NAME,_compressed_data)
|
#define embedded_font_data(FONT) __CAT3(font_,FONT,_compressed_data)
|
||||||
#define embedded_font_size(FONT_NAME) __CAT3(font_,FONT_NAME,_compressed_size)
|
#define embedded_font_size(FONT) __CAT3(font_,FONT,_compressed_size)
|
||||||
|
#define embedded_font_name(FONT) #FONT
|
||||||
|
|
||||||
f32 getMainWindowDPI();
|
f32 getMainWindowDPI();
|
||||||
ImFont* ImFont_LoadFromFile(const char* file_path, f32 font_size);
|
ImFont* ImFont_LoadFromFile(const char* file_path, f32 font_size);
|
||||||
ImFont* _ImFont_LoadEmbedded(const void* data, int data_size, f32 font_size);
|
ImFont* _ImFont_LoadEmbedded(const void* data, int data_size, const char* font_name, f32 font_size);
|
||||||
|
|
||||||
#define ImFont_LoadEmbedded(FONT_NAME, FONT_SIZE) _ImFont_LoadEmbedded( \
|
#define ImFont_LoadEmbedded(FONT, FONT_SIZE) _ImFont_LoadEmbedded( \
|
||||||
embedded_font_data(FONT_NAME), \
|
embedded_font_data(FONT), \
|
||||||
embedded_font_size(FONT_NAME), \
|
embedded_font_size(FONT), \
|
||||||
|
embedded_font_name(FONT), \
|
||||||
FONT_SIZE)
|
FONT_SIZE)
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#include "gui_internal.hpp"
|
#include "gui_internal.hpp"
|
||||||
|
|
||||||
#define default_font_name DroidSans
|
#define default_font_name font_DroidSans
|
||||||
const f32 default_font_size=14.0f;
|
const f32 default_font_size=14.0f;
|
||||||
ImVec4 clear_color = RGBAHexToF(35,35,50,255);
|
ImVec4 clear_color = RGBAHexToF(35,35,50,255);
|
||||||
bool loop_running=false;
|
bool loop_running=false;
|
||||||
@ -69,6 +69,8 @@ Maybe main_window_open(const char* window_title){
|
|||||||
// Setup Dear ImGui style
|
// Setup Dear ImGui style
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
io.FontDefault=ImFont_LoadEmbedded(default_font_name, default_font_size);
|
io.FontDefault=ImFont_LoadEmbedded(default_font_name, default_font_size);
|
||||||
|
kprintf("%s\n",ImFont_LoadEmbedded(font_Cousine_Regular, default_font_size)->GetDebugName());
|
||||||
|
io.Fonts->Build();
|
||||||
|
|
||||||
node_editor_open("node editor");
|
node_editor_open("node editor");
|
||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
|
|||||||
@ -6,9 +6,11 @@ HEADER="generated/fonts_embedded.h"
|
|||||||
|
|
||||||
function append_def_to_header {
|
function append_def_to_header {
|
||||||
local c_src_file=$1
|
local c_src_file=$1
|
||||||
local header_file=$2
|
local c_var_name=$2
|
||||||
sed '3!d;' $c_src_file | sed 's/const/static const/' >> $header_file
|
local header_file=$3
|
||||||
sed '4!d;' $c_src_file | sed 's/const/extern const/' | sed 's/\[.*/[];/' >> $header_file
|
echo "#define $c_var_name $(echo $c_var_name | sed 's/font_//')" >> "$header_file"
|
||||||
|
sed '3!d;' $c_src_file | sed 's/const/static const/' >> "$header_file"
|
||||||
|
sed '4!d;' $c_src_file | sed 's/const/extern const/' | sed 's/\[.*/[];/' >> "$header_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
rm -rf generated
|
rm -rf generated
|
||||||
@ -18,21 +20,27 @@ $CMP_CPP binary_to_compressed_c.cpp -o generated/binary_to_compressed_c.exe
|
|||||||
for ttf_file in $(ls *.ttf); do
|
for ttf_file in $(ls *.ttf); do
|
||||||
c_var_name="font_$(basename $ttf_file .ttf | tr ' ' '_' | tr '-' '_')"
|
c_var_name="font_$(basename $ttf_file .ttf | tr ' ' '_' | tr '-' '_')"
|
||||||
c_src_file="generated/src/$c_var_name.c"
|
c_src_file="generated/src/$c_var_name.c"
|
||||||
echo "$ttf_file : $c_var_name > c_src_file"
|
myprint "$ttf_file : $c_var_name > c_src_file"
|
||||||
generated/binary_to_compressed_c.exe -nostatic "$ttf_file" "$c_var_name" > "$c_src_file"
|
generated/binary_to_compressed_c.exe -nostatic "$ttf_file" "$c_var_name" > "$c_src_file"
|
||||||
SRC_C="$SRC_C fonts/$c_src_file"
|
SRC_C="$SRC_C fonts/$c_src_file"
|
||||||
append_def_to_header "$c_src_file" "$HEADER"
|
append_def_to_header "$c_src_file" "$c_var_name" "$HEADER"
|
||||||
done
|
done
|
||||||
cd ..
|
cd ..
|
||||||
mkdir -p src/generated/
|
mkdir -p src/generated/
|
||||||
cp fonts/$HEADER /src/generated/
|
cp -v fonts/$HEADER src/$HEADER
|
||||||
myprint "${GREEN}font arrays external definitions have been written to ${CYAN}/src/generated$HEADER"
|
myprint "${GREEN}font arrays external definitions have been written to ${CYAN}src/$HEADER"
|
||||||
|
|
||||||
clean_dir "$OBJDIR/objects"
|
clean_dir "$OBJDIR/objects"
|
||||||
clean_dir "$OBJDIR/libs"
|
myprint "${BLUE}hiding libs"
|
||||||
|
mv "$OBJDIR/libs" "$OBJDIR/libs_"
|
||||||
|
mkdir -p "$OBJDIR/libs"
|
||||||
|
# compiling
|
||||||
compile_c "$C_ARGS" "$SRC_C"
|
compile_c "$C_ARGS" "$SRC_C"
|
||||||
pack_static_lib "$STATIC_LIB_FILE"
|
pack_static_lib "$STATIC_LIB_FILE"
|
||||||
rm -rf $OUTDIR/fonts_embedded.a
|
rm -rf $OUTDIR/fonts_embedded.a
|
||||||
|
myprint "${BLUE}restoring libs"
|
||||||
|
rm -rf "$OBJDIR/libs"
|
||||||
|
mv "$OBJDIR/libs_" "$OBJDIR/libs"
|
||||||
|
|
||||||
cp "$OBJDIR/out/fonts_embedded.a" libs/
|
cp "$OBJDIR/out/fonts_embedded.a" libs/
|
||||||
myprint "$OBJDIR/out/fonts_embedded.a -> libs/"
|
myprint "$OBJDIR/out/fonts_embedded.a -> libs/"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user