RoboFab

Support RoboFab

Up

See also

More links





RoboFab Mailinglist

Join the RoboFab users community at Google groups. Visit this group

Email:

RoboFadvertising

Some hinting in UFO

Regular postscript hints can be exported to UFO from FontLab. The zone information is stored in the glyph.lib and can easily be interpreted. TrueType hints and link information are not exported. The blues values are not exported either.

When you generate a UFO in FontLab, Hint export is switched off by default. By setting the _supportHints flag on a font object before exporting it, the PS hint info will be exported. Here is a modified version of a simple UFO exporting script for FontLab:

#FLM: Export Current Font to UFO Format

from robofab.world import CurrentFont
from robofab.tools.glyphNameSchemes import glyphNameToShortFileName

f = CurrentFont()
f._supportHints = True    # this switches the hinting on
f.writeUFO(doProgress=True, glyphNameToFileNameFunc=glyphNameToShortFileName)
print 'DONE!'

Now what?

Now that the hints are in the UFO, you can get to them with the glif.lib,

from robofab.world import OpenFont
path = "/some/ufo/path/MyFont.ufo"
f = OpenFont(path)

def getHints(self, glyph):
    """Retrieve hints from the glyph lib. This will return two lists:
        one for the horizontal zones
        one for the vertical zones.
        If no hints are defined in this glyph,
            or the lib is empty,
            two empty lists will be returned.
        """

    if self.hintKey in glyph.lib:
        h = glyph.lib[self.hintKey].get('hhints', [])
        v = glyph.lib[self.hintKey].get('vhints', [])
        h.sort()
        v.sort()
        return h, v
    return [], []

# using this function, it's easy to get the hints out.
h, v = getHints(f['a'])
print "h", h
>>> h [{'position': 0, 'width': 25}, {'position': 665, 'width': 23}]

print "v", v
>>> v [{'position': 176, 'width': 45}, {'position': 639, 'width': 46}]

The hinting information consists of a list of dictionaries, each with a "position" and "width" key. The value is a number representing the size of the zone.

Blues?

If there is interest in expanding the support for hints in RoboFab, for instance the blues values and so on, drop us a line on the Robofab Google group. Sample code showing how to get and set the values you want would be good.