def test_weight_class(self): ufo = defcon.Font() data = makeInstance("Bold", weight=("Bold", None, 150)) set_weight_class(ufo, data) self.assertEqual(ufo.info.openTypeOS2WeightClass, 700) self.assertEqual(ufo.lib[WEIGHT_CLASS_KEY], "Bold")
def test_explicit_default_weight(self): ufo = defcon.Font() data = makeInstance("Regular", weight=("Regular", None, 100)) set_weight_class(ufo, data) # the default OS/2 weight class is set self.assertEqual(ufo.info.openTypeOS2WeightClass, 400) # non-empty value is stored in the UFO lib even if same as default self.assertEqual(ufo.lib[WEIGHT_CLASS_KEY], "Regular")
def test_no_weigth_class(self): ufo = defcon.Font() # name here says "Bold", however no excplit weightClass # is assigned set_weight_class(ufo, makeInstance("Bold")) # the default OS/2 weight class is set self.assertEqual(ufo.info.openTypeOS2WeightClass, 400) # non-empty value is stored in the UFO lib even if same as default self.assertEqual(ufo.lib[WEIGHT_CLASS_KEY], "Regular")
def test_no_weigth_class(self): ufo = defcon.Font() # name here says "Bold", however no excplit weightClass # is assigned set_weight_class(ufo, makeInstance("Bold")) # the default OS/2 weight class is set self.assertEqual(ufo.info.openTypeOS2WeightClass, 400) # no value is stored in the UFO lib when instance in glyphs # source contains no `weightClass` (because same as default) self.assertTrue(WEIGHT_CLASS_KEY not in ufo.lib)
def test_weight_and_width_class(self): ufo = defcon.Font() data = makeInstance("SemiCondensed ExtraBold", weight=("ExtraBold", None, 160), width=("SemiCondensed", 90)) set_weight_class(ufo, data) set_width_class(ufo, data) self.assertEqual(ufo.info.openTypeOS2WeightClass, 800) self.assertEqual(ufo.lib[WEIGHT_CLASS_KEY], "ExtraBold") self.assertEqual(ufo.info.openTypeOS2WidthClass, 4) self.assertEqual(ufo.lib[WIDTH_CLASS_KEY], "SemiCondensed")
def test_unknown_weight_class(self): ufo = defcon.Font() # "DemiLight" is not among the predefined weight classes listed in # Glyphs.app/Contents/Frameworks/GlyphsCore.framework/Versions/A/ # Resources/weights.plist # NOTE It is not possible from the user interface to set a custom # string as instance 'weightClass' since the choice is constrained # by a drop-down menu. data = makeInstance("DemiLight Italic", weight=("DemiLight", 350, 70)) set_weight_class(ufo, data) # we do not set any OS/2 weight class; user needs to provide # a 'weightClass' custom parameter in this special case self.assertTrue(ufo.info.openTypeOS2WeightClass is None)