From 5a0a844225fbcc0d039cca8f9b0fcc1cbb4be253 Mon Sep 17 00:00:00 2001 From: VanjaPin Date: Wed, 25 Oct 2023 13:04:54 +0300 Subject: [PATCH] feat/temp-language) : nameOrfontPath --- src/source/view/FontManager.bs | 19 +++++++++---------- src/source/view/FontManager.spec.bs | 12 ++++++------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/source/view/FontManager.bs b/src/source/view/FontManager.bs index d2b2a438..ba3e9f8f 100644 --- a/src/source/view/FontManager.bs +++ b/src/source/view/FontManager.bs @@ -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 diff --git a/src/source/view/FontManager.spec.bs b/src/source/view/FontManager.spec.bs index b36752b5..2495fc5f 100644 --- a/src/source/view/FontManager.spec.bs +++ b/src/source/view/FontManager.spec.bs @@ -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