def test_glyph_lib_componentsAlignment_and_componentsLocked(self): font = generate_minimal_font() add_glyph(font, "a") add_glyph(font, "b") composite_glyph = add_glyph(font, "c") add_component(font, "c", "a", (1, 0, 0, 1, 0, 0)) add_component(font, "c", "b", (1, 0, 0, 1, 0, 100)) comp1 = composite_glyph.layers[0].components[0] comp2 = composite_glyph.layers[0].components[1] self.assertEqual(comp1.alignment, 0) self.assertEqual(comp1.locked, False) ufo = to_ufos(font)[0] # all components have deault values, no lib key is written self.assertNotIn(GLYPHS_PREFIX + "componentsAlignment", ufo["c"].lib) self.assertNotIn(GLYPHS_PREFIX + "componentsLocked", ufo["c"].lib) comp2.alignment = -1 comp1.locked = True ufo = to_ufos(font)[0] # if any component has a non-default alignment/locked values, write # list of values for all of them self.assertIn(GLYPHS_PREFIX + "componentsAlignment", ufo["c"].lib) self.assertEqual(ufo["c"].lib[GLYPHS_PREFIX + "componentsAlignment"], [0, -1]) self.assertIn(GLYPHS_PREFIX + "componentsLocked", ufo["c"].lib) self.assertEqual(ufo["c"].lib[GLYPHS_PREFIX + "componentsLocked"], [True, False])
def test_propagate_anchors(self): """Test anchor propagation for some relatively complicated cases.""" font = generate_minimal_font() glyphs = ( ('sad', [], [('bottom', 50, -50), ('top', 50, 150)]), ('dotabove', [], [('top', 0, 150), ('_top', 0, 100)]), ('dotbelow', [], [('bottom', 0, -50), ('_bottom', 0, 0)]), ('dad', [('sad', 0, 0), ('dotabove', 50, 50)], []), ('dadDotbelow', [('dad', 0, 0), ('dotbelow', 50, -50)], []), ('yod', [], [('bottom', 50, -50)]), ('yodyod', [('yod', 0, 0), ('yod', 100, 0)], []), ) for name, component_data, anchor_data in glyphs: glyph = add_glyph(font, name) for n, x, y, in anchor_data: add_anchor(font, name, n, x, y) for n, x, y in component_data: add_component(font, name, n, (1, 0, 0, 1, x, y)) ufos = to_ufos(font) ufo = ufos[0] glyph = ufo['dadDotbelow'] self.assertEqual(len(glyph.anchors), 2) # check propagated anchors are appended in a deterministic order self.assertEqual( [anchor.name for anchor in glyph.anchors], ['bottom', 'top'] ) for anchor in glyph.anchors: self.assertEqual(anchor.x, 50) if anchor.name == 'bottom': self.assertEqual(anchor.y, -100) else: self.assertEqual(anchor.name, 'top') self.assertEqual(anchor.y, 200) glyph = ufo['yodyod'] self.assertEqual(len(glyph.anchors), 2) for anchor in glyph.anchors: self.assertEqual(anchor.y, -50) if anchor.name == 'bottom_1': self.assertEqual(anchor.x, 50) else: self.assertEqual(anchor.name, 'bottom_2') self.assertEqual(anchor.x, 150)
def test_fail_during_anchor_propagation(self): """Fix https://github.com/googlei18n/glyphsLib/issues/317""" font = generate_minimal_font() glyphs = ( # This glyph has components that don't exist in the font ('yodyod', [('yod', 0, 0), ('yod', 100, 0)], []), ) for name, component_data, anchor_data in glyphs: add_glyph(font, name) for n, x, y, in anchor_data: add_anchor(font, name, n, x, y) for n, x, y in component_data: add_component(font, name, n, (1, 0, 0, 1, x, y)) # We just want the call to `to_ufos` to not crash assert to_ufos(font)