multiple inheritance

30 views
Skip to first unread message

Peter Bilak

unread,
May 29, 2014, 2:07:33 PM5/29/14
to rob...@googlegroups.com
Is using recursive components ok with UFO? For example making 'Agrave.c2sc' based on 'agrave.smcp' which is made of 'a.smcp' + 'grave'. Shouldn't inserting 'agrave.smcp' component automatically use the 'a.smcp' + 'grave'?

I am having trouble bringing UFO back into VFB (and back), using 'ufocentral.py' + Robofab. The trouble is multiple inheritance in UFO files - which break recursive components.

I suppose it would be possible to analyse inheritance and rewrite the components. Anyone tried scripting this?

Please don't ask why I need to bring UFO to VFB.

best, peter

Tal Leming

unread,
May 29, 2014, 2:20:21 PM5/29/14
to rob...@googlegroups.com

On May 29, 2014, at 2:07 PM, Peter Bilak <peter...@gmail.com> wrote:

> Is using recursive components ok with UFO? For example making 'Agrave.c2sc' based on 'agrave.smcp' which is made of 'a.smcp' + 'grave'. Shouldn't inserting 'agrave.smcp' component automatically use the 'a.smcp' + 'grave’?

Nested components are allowed as long as they don’t create circular references.

> I am having trouble bringing UFO back into VFB (and back), using 'ufocentral.py' + Robofab. The trouble is multiple inheritance in UFO files - which break recursive components.
>
> I suppose it would be possible to analyse inheritance and rewrite the components. Anyone tried scripting this?

Yes. Here’s a function that you can use.

###

from robofab.pens.adapterPens import TransformPointPen

def fixNestedComponents(glyph, font):
# gather all nested components
toRecompose = []
for component in glyph.components:
baseGlyph = font[component.baseGlyph]
if len(baseGlyph.components):
toRecompose.append(component)
# if no nested were found, stop the recursion
if not toRecompose:
return
for component in toRecompose:
# get the data
transformation = component.naked().transformation
baseGlyph = font[component.baseGlyph]
# remove the component
glyph.removeComponent(component)
# draw the transformed base glyph
transformPointPen = TransformPointPen(glyph.getPointPen(), transformation)
# contours
baseGlyph.drawPoints(transformPointPen)
# recurse
fixNestedComponents(glyph, font)


glyph = CurrentGlyph()
font = CurrentFont()
fixNestedComponents(glyph, font)

###

> Please don't ask why I need to bring UFO to VFB.

Likewise, please don’t ask why I have code that fixes the very problem that you described. :-)

Tal



Reply all
Reply to author
Forward
0 new messages