Embed the bundled monospace font in the client binary
The font atlas loader read the bundled Noto Sans Mono from a cwd-relative path with system-font fallbacks, so launching the editor from outside the repo root could pick a different font or fail. The bundled font is now embedded with #load; EditorMono.ttf remains an optional on-disk override, and the system fallback paths are gone. Together with the embedded shaders this makes the binary fully self-contained. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
8d85568713
commit
41adeeb47f
2 changed files with 15 additions and 19 deletions
|
|
@ -61,12 +61,12 @@ GPU_FONT_ATLAS_SIZE :: 512
|
|||
GPU_FONT_PIXEL_HEIGHT :: 15.0
|
||||
GPU_FONT_BASELINE_OFFSET :: 11.0
|
||||
GPU_FONT_CELL_PADDING :: 1.0
|
||||
GPU_FONT_PATHS := [?]string{
|
||||
// The bundled font is embedded at build time so the binary always has a
|
||||
// working monospace font. EditorMono.ttf remains an optional on-disk override.
|
||||
@(rodata)
|
||||
GPU_EMBEDDED_FONT := #load("assets/fonts/NotoSansMono-Regular.ttf")
|
||||
GPU_FONT_OVERRIDE_PATHS := [?]string{
|
||||
"client/odin/assets/fonts/EditorMono.ttf",
|
||||
"client/odin/assets/fonts/NotoSansMono-Regular.ttf",
|
||||
"/usr/share/fonts/google-noto/NotoSansMono-Regular.ttf",
|
||||
"/usr/share/fonts/dejavu-sans-mono-fonts/DejaVuSansMono.ttf",
|
||||
"/usr/share/fonts/dejavu/DejaVuSansMono.ttf",
|
||||
}
|
||||
|
||||
gpu_renderer_make :: proc(window: ^SDL.Window) -> GPU_Renderer {
|
||||
|
|
@ -436,12 +436,8 @@ gpu_present :: proc(gpu: ^GPU_Renderer) {
|
|||
}
|
||||
|
||||
gpu_create_font_atlas :: proc(gpu: ^GPU_Renderer) -> bool {
|
||||
font_bytes, font_path, ok := gpu_read_font_file()
|
||||
if !ok {
|
||||
fmt.println("read font failed: no configured monospace font found")
|
||||
return false
|
||||
}
|
||||
defer delete(font_bytes)
|
||||
font_bytes, font_path, owned := gpu_read_font_file()
|
||||
defer if owned do delete(font_bytes)
|
||||
|
||||
atlas_size := GPU_FONT_ATLAS_SIZE * GPU_FONT_ATLAS_SIZE
|
||||
atlas := make([]u8, atlas_size)
|
||||
|
|
@ -509,17 +505,17 @@ gpu_create_font_atlas :: proc(gpu: ^GPU_Renderer) -> bool {
|
|||
return SDL.SubmitGPUCommandBuffer(command)
|
||||
}
|
||||
|
||||
gpu_read_font_file :: proc() -> ([]u8, string, bool) {
|
||||
for path in GPU_FONT_PATHS {
|
||||
bytes, err := os.read_entire_file(path, context.allocator)
|
||||
if err == nil && len(bytes) > 0 {
|
||||
return bytes, path, true
|
||||
gpu_read_font_file :: proc() -> (bytes: []u8, path: string, owned: bool) {
|
||||
for override_path in GPU_FONT_OVERRIDE_PATHS {
|
||||
data, err := os.read_entire_file(override_path, context.allocator)
|
||||
if err == nil && len(data) > 0 {
|
||||
return data, override_path, true
|
||||
}
|
||||
if err == nil {
|
||||
delete(bytes)
|
||||
delete(data)
|
||||
}
|
||||
}
|
||||
return nil, "", false
|
||||
return GPU_EMBEDDED_FONT, "embedded NotoSansMono-Regular.ttf", false
|
||||
}
|
||||
|
||||
gpu_push_quad :: proc(gpu: ^GPU_Renderer, x0, y0, x1, y1: f32, c: [4]f32) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue