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})
import drawBot drawBot.size(500, 70) fontPath = "../data/MutatorSans.ttf" drawBot.font(fontPath) drawBot.fontSize(20) drawBot.text("HELLO MUTATOR", (10, 10)) drawBot.fontVariations(wdth=500, wght=900) drawBot.text("HELLO MUTATOR", (10, 40))