g.copy

RoboFont Forums Help / General g.copy

This topic contains 4 replies, has 2 voices, and was last updated by  Thom 6 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5992

    Thom
    Participant

    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 way 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__'

    Who can help?
    Thanks! Thom

    #5993

    frederik
    Keymaster

    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())
    
    #5996

    Thom
    Participant

    Hi,

    OK it draws. But still overlapped, and composed…

    #5997

    frederik
    Keymaster

    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
    
    #5998

    Thom
    Participant

    Great, this works!
    Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.