fontforge / fontforge

Free (libre) font editor for Windows, Mac OS X and GNU+Linux
http://fontforge.github.io/
Other
6.35k stars 695 forks source link

Python: Bundle a 'UFO Export for AFDKO' script #2090

Open davelab6 opened 9 years ago

davelab6 commented 9 years ago

I'll add a UFO export python script and bundle it with the next release, "Export UFO for AFDKO", that runs

font = fontforge.activeFont()
for glyph in font.glyphs():
    glyph.layers[1] = glyph.layers[1].reverseDirection()
font.generate('font.ufo')

Or maybe @adrientetar will update the export window to add a checkbox similar to the one for choosing kerning (as export checkboxes retain a users' settings)

adrientetar commented 9 years ago

This script you can throw sfd and ufo at:

from ufo2fdk import OTFCompiler
from robofab.world import OpenFont
import sys

if len(sys.argv)>1:
    array = []
    for f in sys.argv[1:]:
        if ".sfd" in f:
            import fontforge
            font = fontforge.open(f)
            for glyph in font.glyphs():
                glyph.layers[1] = glyph.layers[1].removeOverlap().reverseDirection()
            name = font.fullname + ".ufo"
            font.generate(name, flags="round")
            array.append(name)
        else: array.append(f)
    for f in array:
        font = OpenFont(f)
        compiler = OTFCompiler()
        reports = compiler.compile(font, font.info.familyName + "-" + font.info.styleName + ".otf", checkOutlines=False, autohint=True, releaseMode=True)

        print reports["autohint"]
        print reports["makeotf"]

But removeOverlap() does not seem to work, it only adds points at intersections.

davelab6 commented 9 years ago

removeOverlap() does not seem to work

@frank-trampe sounds like this is now for you ;)

davelab6 commented 9 years ago

But removeOverlap() does not seem to work, it only adds points at intersections.

So it was not working because of mixed winding orders...

Is there a way to check for this situation and alert the user? Or is there no way to check for that situation?

davelab6 commented 9 years ago

This script you can throw sfd and ufo at:

I suggest to check your latest version in, such that I or someone else can add GUI hooks, so there will be a Tools menu item "Generate with AFDKO" that allows us to generate a OTF/TTF from the current font via UFO and FDK.

adrientetar commented 9 years ago

Is there a way to check for this situation and alert the user?

Not that I know of.

Edit: there is contour.isClockwise() w Python scripting.

davelab6 commented 9 years ago

@pathumego was this script useful for you?