8000 Implementing .tempLib by typemytype · Pull Request #367 · robotools/defcon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implementing .tempLib #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Lib/defcon/objects/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def __init__(self, path=None,
self._groups = None
self._features = None
self._lib = None
self._tempLib = None
self._kerningGroupConversionRenameMaps = None

self._layers = self.instantiateLayerSet()
Expand Down Expand Up @@ -600,6 +601,20 @@ def _get_lib(self):

lib = property(_get_lib, doc="The font's :class:`Lib` object.")

# temp lib

def _get_tempLib(self):
if self._tempLib is None:
self._tempLib = self.instantiateLib()
return self._tempLib

def _set_tempLib(self, value):
if value is not None:
self.tempLib.clear()
self.tempLib.update(value)

tempLib = property(_get_tempLib, _set_tempLib, doc="The font's :class:`tempLib` object.")

# images

def instantiateImageSet(self):
Expand Down Expand Up @@ -1743,6 +1758,7 @@ def getDataForSerialization(self, **kwargs):
('kerning', serialized_get),
('layers', serialized_get),
('lib', serialized_get),
('tempLib', serialized_get),
('guidelines', serialized_list_get)
)

Expand Down Expand Up @@ -1795,6 +1811,7 @@ def set_guidelines(key, data):
('kerning', single_update),
('layers', init_set_layers),
('lib', single_update),
('tempLib', single_update),
('guidelines', set_guidelines)
)

Expand Down
27 changes: 22 additions & 5 deletions Lib/defcon/objects/glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def __init__(self, layer=None,
self._anchors = []
self._guidelines = []
self._lib = None
self._tempLib = None

if contourClass is None:
contourClass = Contour
Expand Down Expand Up @@ -1098,6 +1099,20 @@ def endSelfLibNotificationObservation(self):
self._lib.removeObserver(observer=self, notification="Lib.Changed")
self._lib.endSelfNotificationObservation()

# temp lib

def _get_tempLib(self):
if self._tempLib is None:
self._tempLib = self.instantiateLib()
return self._tempLib

def _set_tempLib(self, value):
if value is not None:
self.tempLib.clear()
self.tempLib.update(value)

tempLib = property(_get_tempLib, _set_tempLib, doc="The glyph's :class:`tempLib` object.")

# -----
# Image
# -----
Expand Down Expand Up @@ -1354,7 +1369,8 @@ def getDataForSerialization(self, **kwargs):
('anchors', serialized_list_get),
('guidelines', serialized_list_get),
('image', serialized_get),
('lib', serialized_get)
('lib', serialized_get),
('tempLib', serialized_get),
]

if self._shallowLoadedContours is not None:
Expand Down Expand Up @@ -1396,10 +1412,11 @@ def wrapper(key, data):
setters = (
('name', set_attr),
('unicodes', set_attr),
('width', set_attr),
('height', set_attr),
('note', set_attr),
('lib', set_attr),
('width', set_attr),
('height', set_attr),
('note', set_attr),
('lib', set_attr),
('tempLib', set_attr),
('_shallowLoadedContours', set_attr),
('_contours', init_set(list_init, self.instantiateContour, set_each(self.appendContour, True))),
('components', init_set(list_init, self.instantiateComponent, set_each(self.appendComponent, True))),
Expand Down
18 changes: 18 additions & 0 deletions Lib/defcon/objects/layer.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Layer(BaseObject):
- Layer.GlyphUnicodesChanged
- Layer.NameChanged
- Layer.ColorChanged
- Layer.LibChanged

The Layer object has some dict like behavior. For example, to get a glyph::

Expand Down Expand Up @@ -83,6 +84,7 @@ def __init__(self, layerSet=None, glyphSet=None, libClass=None, unicodeDataClass

self._color = None
self._lib = None
self._tempLib = None
self._unicodeData = None

self._directory = None
Expand Down Expand Up @@ -473,6 +475,20 @@ def _set_lib(self, value):

lib = property(_get_lib, _set_lib, doc="The layer's :class:`Lib` object.")

# temp lib

def _get_tempLib(self):
if self._tempLib is None:
self._tempLib = self.instantiateLib()
return self._tempLib

def _set_tempLib(self, value):
if value is not None:
self.tempLib.clear()
self.tempLib.update(value)

tempLib = property(_get_tempLib, _set_tempLib, doc="The layer's :class:`tempLib` object.")

# unicode data

def instantiateUnicodeData(self):
Expand Down Expand Up @@ -716,6 +732,7 @@ def getDataForSerialization(self, **kwargs):

getters = (
('lib', serialized_get),
('tempLib', serialized_get),
('color', simple_get),
('glyphs', lambda _: {name: self[name].getDataForSerialization() for name in self.keys()})
)
Expand All @@ -740,6 +757,7 @@ def set_glyphs(key, glyphs):

setters = (
('lib', set_attr),
('tempLib', set_attr),
('color', set_attr),
('glyphs', set_glyphs)
)
Expand Down
11 changes: 11 additions & 0 deletions Lib/defcon/test/objects/test_font.py
Original file line number Diff line number Diff line change
6D47 Expand Up @@ -788,5 +788,16 @@ def test_glyph_unicodes_changed(self):
glyph.unicodes = [65]
self.assertEqual(font.unicodeData[65], ["test", "A"])

def test_tempLib(self):
font = Font()

font.tempLib["foo"] = "bar"
self.assertEqual(font.tempLib, {"foo": "bar"})

otherFont = Font()
otherFont.setDataFromSerialization(font.getDataForSerialization())
self.assertEqual(otherFont.tempLib, {"foo": "bar"})


if __name__ == "__main__":
unittest.main()
11 changes: 11 additions & 0 deletions Lib/defcon/test/objects/test_glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,17 @@ def test_area(self):
pointPen.addComponent("baseGlyph", [1, 0, 0, 1, 0, 0])
self.assertEqual(componentGlyph.area, 1000 9E81 0)

def test_tempLib(self):
font = Font()

glyph = font.newGlyph("A")
glyph.tempLib["foo"] = "bar"
self.assertEqual(glyph.tempLib, {"foo": "bar"})

otherGlyph = font.newGlyph("A.other")
otherGlyph.setDataFromSerialization(glyph.getDataForSerialization())
self.assertEqual(otherGlyph.tempLib, {"foo": "bar"})


if __name__ == "__main__":
unittest.main()
7 changes: 7 additions & 0 deletions Lib/defcon/test/objects/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def test_instance(self):
(i.fileName, i.transformation, i.color),
('foo.png', ('1', '2', '3', '4', '5', '6'), '0,0,0,0'))

def test_clear(self):
i = Image()
i.fileName = "foo"
self.assertEqual(i.fileName, "foo")
i.clear()
self.assertIsNone(i.fileName)

def test_read(self):
font = Font(getTestFontPath())
glyph = font.layers["Layer 1"]["A"]
Expand Down
10 changes: 10 additions & 0 deletions Lib/defcon/test/objects/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ def test_glyph_dispatcher_inserted(self):
self.assertTrue(guideline.getParent(), insertedGlyph)
self.assertTrue(guideline.dispatcher, newFont.dispatcher)

def test_tempLib(self):
font = Font()
layer = font.layers["public.default"]
layer.tempLib["foo"] = "bar"
self.assertEqual(layer.tempLib, {"foo": "bar"})

otherLayer = font.newLayer("other.layer")
otherLayer.setDataFromSerialization(layer.getDataForSerialization())
self.assertEqual(otherLayer.tempLib, {"foo": "bar"})


class LayerWithTestFontCopyTest(unittest.TestCase):

Expand Down
0