gg: improve system_font_path on linux (#12290)
parent
18da724a9f
commit
77a1e3dedb
vlib/gg
|
@ -39,10 +39,8 @@ pub fn system_font_path() string {
|
||||||
debug_font_println('Using font "C:\\Windows\\Fonts\\arial.ttf"')
|
debug_font_println('Using font "C:\\Windows\\Fonts\\arial.ttf"')
|
||||||
return 'C:\\Windows\\Fonts\\arial.ttf'
|
return 'C:\\Windows\\Fonts\\arial.ttf'
|
||||||
}
|
}
|
||||||
mut fonts := ['Ubuntu-R.ttf', 'Arial.ttf', 'LiberationSans-Regular.ttf', 'NotoSans-Regular.ttf',
|
|
||||||
'FreeSans.ttf', 'DejaVuSans.ttf']
|
|
||||||
$if macos {
|
$if macos {
|
||||||
fonts = ['/System/Library/Fonts/SFNS.ttf', '/System/Library/Fonts/SFNSText.ttf',
|
fonts := ['/System/Library/Fonts/SFNS.ttf', '/System/Library/Fonts/SFNSText.ttf',
|
||||||
'/Library/Fonts/Arial.ttf']
|
'/Library/Fonts/Arial.ttf']
|
||||||
for font in fonts {
|
for font in fonts {
|
||||||
if os.is_file(font) {
|
if os.is_file(font) {
|
||||||
|
@ -78,19 +76,18 @@ pub fn system_font_path() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s := os.execute('fc-list')
|
mut fm := os.execute('fc-match -v')
|
||||||
if s.exit_code != 0 {
|
if fm.exit_code == 0 {
|
||||||
panic('failed to fetch system fonts')
|
lines := fm.output.split('\n')
|
||||||
}
|
for l in lines {
|
||||||
system_fonts := s.output.split('\n')
|
if l.contains('file:') {
|
||||||
for line in system_fonts {
|
font := l.find_between('"', '"')
|
||||||
for font in fonts {
|
debug_font_println('Using font "$font"')
|
||||||
if line.contains(font) && line.contains(':') {
|
return font
|
||||||
res := line.all_before(':')
|
|
||||||
debug_font_println('Using font "$res"')
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
panic('fc-match failed to fetch system font')
|
||||||
}
|
}
|
||||||
panic('failed to init the font')
|
panic('failed to init the font')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue