Transforming/editing glyphs with fonttools?

Hello everyone!

I'm diving back into fonttools again and am wondering if there is a way to transform/edit glyphs with fonttools. Here are some examples of workflows I'd want to be able to do:
  • Scale all the glyphs in a font horizontally to 125% width. (Yes, I know this is a type crime, but this is for an experiment, not production use.)
  • Find all points touching (or close to) the baseline and shift them down by 10 units.
  • etc.
I browsed the fonttools API this morning and found the pen classes, but those seem to be for drawing glyphs from scratch as far as I can tell. Does fonttools support editing glyphs as I've described? If so, are there any examples out there? I searched this morning but couldn't find anything, which led me to ask here.

Comments

  • It's much easier to do this stuff at the UFO level. Fontmake supports filtering UFOs, including a filter which mimics the Glyphs "Transformation" filter. See https://github.com/googlefonts/fontmake/blob/main/USAGE.md#outline-filtering
  • I'll check that out. Thank you, Simon.
  • Wei Huang
    Wei Huang Posts: 98
    edited July 15
    Sorry to ressurect an old thread but I'd like to figure out how to do this with fontTools – I'm trying to scale and transform Source Han Sans as I don't know how to edit the sources for those so I'd like to do it just using the TTFs or OTFs. I pieced together this script based off a lonely question and answer on StackOverflow. But now I'm stuck for scaling the metrics, how can I transform that in fontTools?

    I found the solution it's to use `fontTools.ttLib.scaleUpem` function.