gg: improve font loading diagnostics with `-d debug_font`

pull/12404/head
Delyan Angelov 2021-11-06 17:15:04 +02:00
parent 5f3dcde358
commit 8be64ef80e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 11 additions and 3 deletions

View File

@ -65,6 +65,7 @@ fn new_ft(c FTConfig) ?&FT {
}
}
mut normal_path := c.font_path
mut bytes := []byte{}
$if android {
// First try any filesystem paths
@ -82,26 +83,33 @@ fn new_ft(c FTConfig) ?&FT {
return none
}
}
bold_path := if c.custom_bold_font_path != '' {
mut bold_path := if c.custom_bold_font_path != '' {
c.custom_bold_font_path
} else {
get_font_path_variant(c.font_path, .bold)
}
bytes_bold := os.read_bytes(bold_path) or {
debug_font_println('failed to load font "$bold_path"')
bold_path = c.font_path
bytes
}
mono_path := get_font_path_variant(c.font_path, .mono)
mut mono_path := get_font_path_variant(c.font_path, .mono)
bytes_mono := os.read_bytes(mono_path) or {
debug_font_println('failed to load font "$mono_path"')
mono_path = c.font_path
bytes
}
italic_path := get_font_path_variant(c.font_path, .italic)
mut italic_path := get_font_path_variant(c.font_path, .italic)
bytes_italic := os.read_bytes(italic_path) or {
debug_font_println('failed to load font "$italic_path"')
italic_path = c.font_path
bytes
}
fons := sfons.create(512, 512, 1)
debug_font_println('Font used for font_normal : $normal_path')
debug_font_println('Font used for font_bold : $bold_path')
debug_font_println('Font used for font_mono : $mono_path')
debug_font_println('Font used for font_italic : $italic_path')
return &FT{
fons: fons
font_normal: C.fonsAddFontMem(fons, c'sans', bytes.data, bytes.len, false)