From 77a1e3dedbb8448af3062eedb8176caf32aa2d0a Mon Sep 17 00:00:00 2001 From: kahsa Date: Mon, 25 Oct 2021 21:16:29 +0900 Subject: [PATCH] gg: improve system_font_path on linux (#12290) --- vlib/gg/text_rendering.v | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/vlib/gg/text_rendering.v b/vlib/gg/text_rendering.v index 112e8ba8cd..0d431d6eda 100644 --- a/vlib/gg/text_rendering.v +++ b/vlib/gg/text_rendering.v @@ -39,10 +39,8 @@ pub fn system_font_path() string { debug_font_println('Using font "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 { - 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'] for font in fonts { if os.is_file(font) { @@ -78,19 +76,18 @@ pub fn system_font_path() string { } } } - s := os.execute('fc-list') - if s.exit_code != 0 { - panic('failed to fetch system fonts') - } - system_fonts := s.output.split('\n') - for line in system_fonts { - for font in fonts { - if line.contains(font) && line.contains(':') { - res := line.all_before(':') - debug_font_println('Using font "$res"') - return res + mut fm := os.execute('fc-match -v') + if fm.exit_code == 0 { + lines := fm.output.split('\n') + for l in lines { + if l.contains('file:') { + font := l.find_between('"', '"') + debug_font_println('Using font "$font"') + return font } } + } else { + panic('fc-match failed to fetch system font') } panic('failed to init the font') }