Skip to content

Commit

Permalink
feat/temp-language) : nameOrfontPath
Browse files Browse the repository at this point in the history
  • Loading branch information
VanjaPin committed Oct 25, 2023
1 parent d68c84d commit 5a0a844
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
19 changes: 9 additions & 10 deletions src/source/view/FontManager.bs
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,23 @@ namespace mv
return invalid
end function

function getLanguageCode()
return m.getInstance("languageCode") ?? "en"
end function

public function getFont(name as string, size as integer) as dynamic
if name = invalid or name.trim() = ""
public function getFont(nameOrPath as string, size as integer) as dynamic
if nameOrPath = invalid or nameOrPath.trim() = ""
return invalid
end if
key = `${name},${size}`
key = `${nameOrPath},${size}`
font = m.cachedFonts[key]

if font = invalid
font = CreateObject("roSGNode", "Font")
if name.instr(".ttf") <> -1
font.uri = name

if nameOrPath.instr(":") <> -1
font.uri = nameOrPath
else if nameOrPath.instr(".ttf") <> -1
font.uri = "pkg:" + "/fonts/" + nameOrPath
else
'it's a system font
m.fontLabel.font = "font:" + name + "SystemFont"
m.fontLabel.font = "font:" + nameOrPath + "SystemFont"
font = m.fontLabel.font
end if

Expand Down
12 changes: 6 additions & 6 deletions src/source/view/FontManager.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ namespace tests

'/* cspell:disable *\
@it("gets filesystem fonts")
@params("pkg:/fonts/HelveticaNeue.ttf", 20)
@params("pkg:/fonts/HelveticaNeue.ttf", 30)
@params("pkg:/fonts/HelveticaNeue.ttf", 50)
@params("pkg:/fonts/HelveticaNeue.ttf", 30)
@params("pkg:/fonts/HelveticaNeue.ttf", 30)
@params("HelveticaNeue.ttf", 20)
@params("HelveticaNeue.ttf", 30)
@params("HelveticaNeue.ttf", 50)
@params("HelveticaNeue.ttf", 30)
@params("HelveticaNeue.ttf", 30)
function _(name, size)
'/* cspell:enable *\
font = m.manager.getFont(name, size)
m.assertEqual(font.uri, name)
m.assertEqual(font.uri, "pkg:" + "/fonts/" + name)
m.assertEqual(font.size, size)
m.assertSubType(font, "Font")
end function
Expand Down

0 comments on commit 5a0a844

Please sign in to comment.