os.font: fixes for -os android

This commit is contained in:
Delyan Angelov 2025-06-18 14:06:35 +03:00
parent 2cd1c9e26b
commit 131449e70d
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -57,14 +57,16 @@ pub fn default() string {
if os.is_file(xml_file) && os.is_readable(xml_file) { if os.is_file(xml_file) && os.is_readable(xml_file) {
xml := os.read_file(xml_file) or { continue } xml := os.read_file(xml_file) or { continue }
lines := xml.split('\n') lines := xml.split('\n')
unsafe { xml.free() }
mut candidate_font := '' mut candidate_font := ''
for line in lines { for line in lines {
if line.contains('<font') { if line.contains('<font') {
candidate_font = line.all_after('>').all_before('<').trim(' \n\t\r') tmp1 := line.all_after('>')
tmp2 := tmp1.all_before('<')
tmp3 := tmp2.trim(' \n\t\r')
mut_assign(candidate_font, tmp3)
if candidate_font.contains('.ttf') { if candidate_font.contains('.ttf') {
for location in font_locations { for location in font_locations {
candidate_path := os.join_path(location, candidate_font) candidate_path := os.join_path_single(location, candidate_font)
if os.is_file(candidate_path) && os.is_readable(candidate_path) { if os.is_file(candidate_path) && os.is_readable(candidate_path) {
debug_font_println('Using font "${candidate_path}"') debug_font_println('Using font "${candidate_path}"')
return candidate_path return candidate_path
@ -72,9 +74,14 @@ pub fn default() string {
unsafe { candidate_path.free() } unsafe { candidate_path.free() }
} }
} }
unsafe { tmp3.free() }
unsafe { tmp2.free() }
unsafe { tmp1.free() }
} }
} }
unsafe { candidate_font.free() } unsafe { candidate_font.free() }
unsafe { lines.free() }
unsafe { xml.free() }
} }
} }
unsafe { font_locations.free() } unsafe { font_locations.free() }
@ -157,6 +164,7 @@ pub fn get_path_variant(font_path string, variant Variant) string {
return res return res
} }
@[manualfree]
fn mut_replace(s &string, find string, replacement string) { fn mut_replace(s &string, find string, replacement string) {
new := (*s).replace(find, replacement) new := (*s).replace(find, replacement)
unsafe { s.free() } unsafe { s.free() }
@ -165,6 +173,7 @@ fn mut_replace(s &string, find string, replacement string) {
} }
} }
@[manualfree]
fn mut_plus(s &string, tail string) { fn mut_plus(s &string, tail string) {
new := (*s) + tail new := (*s) + tail
unsafe { s.free() } unsafe { s.free() }
@ -173,6 +182,7 @@ fn mut_plus(s &string, tail string) {
} }
} }
@[manualfree]
fn mut_assign(s &string, value string) { fn mut_assign(s &string, value string) {
unsafe { s.free() } unsafe { s.free() }
unsafe { unsafe {