Skip to content

Commit

Permalink
Change how glyph.unicode behaves (#258)
Browse files Browse the repository at this point in the history
* Change how `glyph.unicode` behaves

+ tests

* convert incoming unicodes value to a list

this could a set if comes from extractor which gets the unicodes from fontTools cmap, which sends its as set
  • Loading branch information
typemytype authored and benkiel committed Oct 4, 2019
1 parent 931b496 commit 87755e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Lib/defcon/objects/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def _get_unicodes(self):
def _set_unicodes(self, value):
oldValue = self.unicodes
if oldValue != value:
self._unicodes = value
self._unicodes = list(value)
self.postNotification(notification="Glyph.UnicodesChanged", data=dict(oldValue=oldValue, newValue=value))
self.dirty = True

Expand All @@ -231,11 +231,7 @@ def _set_unicode(self, value):
if value is None:
self.unicodes = []
else:
existing = list(self._unicodes)
if value in existing:
existing.pop(existing.index(value))
existing.insert(0, value)
self.unicodes = existing
self.unicodes = [value]

unicode = property(_get_unicode, _set_unicode, doc="The primary unicode value for the glyph. This is the equivalent of ``glyph.unicodes[0]``. This is a convenience attribute that works with the ``unicodes`` attribute.")

Expand Down
14 changes: 14 additions & 0 deletions Lib/defcon/test/objects/test_glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ def test_unicodes_set(self):
self.assertEqual(glyph.unicodes, [123, 456])
self.assertTrue(glyph.dirty)

def test_unicode_get(self):
font = Font(getTestFontPath())
glyph = font["A"]
self.assertEqual(glyph.unicode, 65)

def test_unicode_set(self):
font = Font(getTestFontPath())
glyph = font["A"]
glyph.unicode = 123
self.assertEqual(glyph.unicodes, [123])
glyph.unicode = 456
self.assertEqual(glyph.unicodes, [456])
self.assertTrue(glyph.dirty)

def test_bounds(self):
font = Font(getTestFontPath())
glyph = font["A"]
Expand Down

0 comments on commit 87755e8

Please sign in to comment.