Decompose in Robofont

Ondrej Jób
Ondrej Jób Posts: 12
edited March 2014 in Type Design Software
Hello typefolks!

I'm writing a script for FL and RF and I need to translate a glyph to SVG. I'm trying to find the best way to do this with a glyph with components and I have a problem with this sollutions:


if len(g.components): # if glyph has components
g = g.copy() # create a copy of it
g.decompose() # decompose it without affecting the original glyph
# do stuff with the decomposed glyph

This method works great in FL, in RF however, it doesn't create a copy, but decomposes the glyph directly in the font. I tried to implement prepareUndo and performUndo methods, but they didn't seem to work. Do you have any tips on how I could make this work in RF?

Comments

  • Update: RF doesn't decompose the glyph, as @typemytype pointed out on Twitter, the copy cannot be decomposed because it doesn't have a parent font.
  • it seems you need create a copy of font, then you can decompose any glyphs
  • Yes, this is how I do it eventually: I add the copy as a new glyph to my font, decompose, do my stuff and then get rid of it. I was affraid this will make the script slower, but it didn't affect the performance at all.
  • Kent Lew
    Kent Lew Posts: 944
    Seems like you could also use layers for this.
    g.copyToLayer('copyLayer')
    gCopy = g.getLayer('copyLayer')
    gCopy.decompose()
    # do stuff with gCopy
    # and then when you're all done
    f.removeLayer('copyLayer')
    If, for some reason, it worked better to do stuff in the foreground (so you could easily generate on-the-fly, for instance), you could decompose and do stuff to the glyph in the foreground, then at the end run a loop to swap your originals back into place.
    for g in f:
        g.flipLayers('foreground', 'copyLayer')
    I don’t know if there’s any real performance advantage to using layers over making new dummy glyphs. Just seems more self-contained.
  • Wouldn't it be easier to write a svg pen. Then you don't need to decompose anything.
  • Kent Lew
    Kent Lew Posts: 944
    I’ve never used this, so I can’t vouch for the functionality, but Tal has a ufo2svg tool/library here:

    https://github.com/typesupply/ufo2svg

    (including a SVGPathPen)