def test_GDEF_fractional_caret_position(self): # Some Glyphs sources happen to contain fractional caret positions. # In the Adobe feature file syntax (and binary OpenType GDEF tables), # caret positions must be integers. font = generate_minimal_font() add_glyph(font, 'fi') add_anchor(font, 'fi', 'caret_1', 499.9876, 0) self.assertIn('LigatureCaretByPos fi 500;', to_ufos(font)[0].features.text)
def test_GDEF_custom_category_subCategory(self): font = generate_minimal_font() add_glyph(font, 'foo')['subCategory'] = 'Ligature' add_anchor(font, 'foo', 'top', 400, 1000) bar = add_glyph(font, 'bar') bar['category'], bar['subCategory'] = 'Mark', 'Nonspacing' baz = add_glyph(font, 'baz') baz['category'], baz['subCategory'] = 'Mark', 'Spacing Combining' features = to_ufos(font)[0].features.text self.assertIn('[foo], # Liga', features) self.assertIn('[bar baz], # Mark', features)
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)
def test_GDEF_ligature_with_nonattaching_anchor(self): font = generate_minimal_font() add_glyph(font, 'fi') add_anchor(font, 'fi', '_top', 400, 1000) self.assertEqual('', to_ufos(font)[0].features.text)
def test_GDEF_ligature_with_attaching_anchor(self): font = generate_minimal_font() add_glyph(font, 'fi') add_anchor(font, 'fi', 'top', 400, 1000) self.assertIn('[fi], # Liga', to_ufos(font)[0].features.text)
def test_GDEF_base_with_attaching_anchor(self): font = generate_minimal_font() add_glyph(font, 'A.alt') add_anchor(font, 'A.alt', 'top', 400, 1000) self.assertIn('[A.alt], # Base', to_ufos(font)[0].features.text)
def test_GDEF(self): font = generate_minimal_font() for glyph in ('space', 'A', 'A.alt', 'wigglylinebelowcomb', 'wigglylinebelowcomb.alt', 'fi', 'fi.alt', 't_e_s_t', 't_e_s_t.alt'): add_glyph(font, glyph) add_anchor(font, 'A', 'bottom', 300, -10) add_anchor(font, 'wigglylinebelowcomb', '_bottom', 100, 40) add_anchor(font, 'fi', 'caret_1', 150, 0) add_anchor(font, 't_e_s_t.alt', 'caret_1', 200, 0) add_anchor(font, 't_e_s_t.alt', 'caret_2', 400, 0) add_anchor(font, 't_e_s_t.alt', 'caret_3', 600, 0) ufo = to_ufos(font)[0] self.assertEqual(ufo.features.text.splitlines(), [ 'table GDEF {', ' # automatic', ' GlyphClassDef', ' [A], # Base', ' [fi t_e_s_t.alt], # Liga', ' [wigglylinebelowcomb wigglylinebelowcomb.alt], # Mark', ' ;', ' LigatureCaretByPos fi 150;', ' LigatureCaretByPos t_e_s_t.alt 200 400 600;', '} GDEF;', ])