G.copy
-
Hi,
For some observers I need the decomposed, removeOverlaped glyph.
I have sort of a solution by adding duplicate glyphs to the font and decompose, removeOverlap them. And automatically remove them when the observer was removed.
But I know this can be done in a nicer way. But this code doesn't do the trick. But why not? Seems okay to me...
f = CurrentFont() g = f['H'] temp = g.copy() temp.decompose() temp.removeOverlap() for c in temp.components: print c #these must be gone... drawGlyph(temp)
<Component for I> <Component for I> Traceback (most recent call last): File "<untitled>", line 10, in <module> File "main.py", line 29, in drawGlyph File "lib/fontObjects/robofabWrapper.pyc", line 2736, in draw File "/Applications/RoboFont_Beta.app/Contents/Resources/lib/python2.7/defcon/objects/glyph.py", line 299, in draw File "/Applications/RoboFont_Beta.app/Contents/Resources/lib/python2.7/defcon/objects/glyph.py", line 308, in drawPoints File "/Applications/RoboFont_Beta.app/Contents/Resources/lib/python2.7/defcon/objects/component.py", line 107, in drawPoints File "/Applications/RoboFont_Beta.app/Contents/Resources/lib/python2.7/robofab/pens/adapterPens.py", line 111, in addComponent File "/Applications/RoboFont_Beta.app/Contents/Resources/lib/python2.7/fontTools/pens/basePen.py", line 166, in addComponent TypeError: 'NoneType' object has no attribute '__getitem__'</code>
Who can help?
Thanks! Thom
-
Great, this works!
Thanks!
-
owke, this is idd not working cause a weakref object has to be referenced once or more.
you could force it with:
g = CurrentGlyph() copy = g.copy() # get the internal font and set it hard in the internal glyph object, even it is a copy copy.naked().setParent(g.naked().getParent()) copy.decompose() copy.removeOverlap() print copy.components
-
Hi,
OK it draws. But still overlapped, and composed...
-
he
A copy has no parent anymore… so it cannot find the referenced glyph in a component. So decompose will not work.
Maybe the best option is to set the parent in the copied glyph:
source = CurrentGlyph() g = source.copy() g.setParent(source.getParent())