gg: fix default font style loading (#10309)
parent
b0c9a87292
commit
751b1cffd3
|
@ -317,47 +317,50 @@ pub fn system_font_path() string {
|
||||||
fn get_font_path_variant(font_path string, variant FontVariant) string {
|
fn get_font_path_variant(font_path string, variant FontVariant) string {
|
||||||
// TODO: find some way to make this shorter and more eye-pleasant
|
// TODO: find some way to make this shorter and more eye-pleasant
|
||||||
// NotoSans, LiberationSans, DejaVuSans, Arial and SFNS should work
|
// NotoSans, LiberationSans, DejaVuSans, Arial and SFNS should work
|
||||||
mut fpath := font_path.replace('.ttf', '')
|
mut file := os.file_name(font_path)
|
||||||
|
mut fpath := font_path.replace(file, '')
|
||||||
|
file = file.replace('.ttf', '')
|
||||||
|
|
||||||
match variant {
|
match variant {
|
||||||
.normal {}
|
.normal {}
|
||||||
.bold {
|
.bold {
|
||||||
if fpath.ends_with('-Regular') {
|
if fpath.ends_with('-Regular') {
|
||||||
fpath = fpath.replace('-Regular', '-Bold')
|
file = file.replace('-Regular', '-Bold')
|
||||||
} else if fpath.starts_with('DejaVuSans') {
|
} else if file.starts_with('DejaVuSans') {
|
||||||
fpath += '-Bold'
|
file += '-Bold'
|
||||||
} else if fpath.to_lower().starts_with('arial') {
|
} else if file.to_lower().starts_with('arial') {
|
||||||
fpath += 'bd'
|
file += 'bd'
|
||||||
} else {
|
} else {
|
||||||
fpath += '-bold'
|
file += '-bold'
|
||||||
}
|
}
|
||||||
$if macos {
|
$if macos {
|
||||||
if os.exists('SFNS-bold') {
|
if os.exists('SFNS-bold') {
|
||||||
fpath = 'SFNS-bold'
|
file = 'SFNS-bold'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.italic {
|
.italic {
|
||||||
if fpath.ends_with('-Regular') {
|
if file.ends_with('-Regular') {
|
||||||
fpath = fpath.replace('-Regular', '-Italic')
|
file = file.replace('-Regular', '-Italic')
|
||||||
} else if fpath.starts_with('DejaVuSans') {
|
} else if file.starts_with('DejaVuSans') {
|
||||||
fpath += '-Oblique'
|
file += '-Oblique'
|
||||||
} else if fpath.to_lower().starts_with('arial') {
|
} else if file.to_lower().starts_with('arial') {
|
||||||
fpath += 'i'
|
file += 'i'
|
||||||
} else {
|
} else {
|
||||||
fpath += 'Italic'
|
file += 'Italic'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.mono {
|
.mono {
|
||||||
if !fpath.ends_with('Mono-Regular') && fpath.ends_with('-Regular') {
|
if !file.ends_with('Mono-Regular') && file.ends_with('-Regular') {
|
||||||
fpath = fpath.replace('-Regular', 'Mono-Regular')
|
file = file.replace('-Regular', 'Mono-Regular')
|
||||||
} else if fpath.to_lower().starts_with('arial') {
|
} else if file.to_lower().starts_with('arial') {
|
||||||
// Arial has no mono variant
|
// Arial has no mono variant
|
||||||
} else {
|
} else {
|
||||||
fpath += 'Mono'
|
file += 'Mono'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fpath + '.ttf'
|
return fpath + file + '.ttf'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_font_println(s string) {
|
fn debug_font_println(s string) {
|
||||||
|
|
Loading…
Reference in New Issue