def test_fontVariations(self): drawBot.newDrawing() var = drawBot.listFontVariations() self.assertEqual(var, {}) drawBot.font("Skia") # get the default font variations var = drawBot.listFontVariations() expectedVar = { 'wght': { 'name': 'Weight', 'minValue': 0.4799, 'maxValue': 3.1999, 'defaultValue': 1.0 }, 'wdth': { 'name': 'Width', 'minValue': 0.6199, 'maxValue': 1.2999, 'defaultValue': 1.0 } } self.assertEqual(var, expectedVar) # set a font variation var = drawBot.fontVariations(wght=5) expectedVarChanged = {'wght': 5, 'wdth': 1.0} self.assertEqual(var, expectedVarChanged) # clear all font variations settings var = drawBot.fontVariations(resetVariations=True) self.assertEqual(var, {'wght': 1.0, 'wdth': 1.0}) drawBot.font("Helvetica") var = drawBot.listFontVariations() self.assertEqual(var, {}) var = drawBot.fontVariations(wght=5) self.assertEqual(var, {"wght": 5})
def test_fontVariations(self): drawBot.newDrawing() var = drawBot.listFontVariations() self.assertEqual(var, {}) drawBot.font("Skia") # get the default font variations var = drawBot.listFontVariations() var['wght'] = _roundDictValues(var['wght'], 3) var['wdth'] = _roundDictValues(var['wdth'], 3) expectedVar = OrderedDict({ 'wght': {'name': 'Weight', 'minValue': 0.48, 'maxValue': 3.2, 'defaultValue': 1.0}, 'wdth': {'name': 'Width', 'minValue': 0.62, 'maxValue': 1.3, 'defaultValue': 1.0}, }) self.assertEqual(var, expectedVar) # set a font variation var = drawBot.fontVariations(wght=5) expectedVarChanged = {'wght': 5, 'wdth': 1.0} self.assertEqual(var, expectedVarChanged) # clear all font variations settings var = drawBot.fontVariations(resetVariations=True) self.assertEqual(var, {'wght': 1.0, 'wdth': 1.0}) drawBot.font("Helvetica") var = drawBot.listFontVariations() self.assertEqual(var, {}) var = drawBot.fontVariations(wght=5) self.assertEqual(var, {"wght": 5})
def test_font_install(self): fontPath = os.path.join(testDataDir, "MutatorSans.ttf") drawBot.newDrawing() drawBot.newPage() postscriptName = drawBot.font(fontPath) self.assertEqual(postscriptName, "MutatorMathTest-LightCondensed") variations = drawBot.listFontVariations() self.assertEqual(variations, {'wdth': {'name': 'Width', 'minValue': 0.0, 'maxValue': 1000.0, 'defaultValue': 0.0}, 'wght': {'name': 'Weight', 'minValue': 0.0, 'maxValue': 1000.0, 'defaultValue': 0.0}})