Skip to content

Instantly share code, notes, and snippets.

@charlesmchen
Created May 31, 2012 21:32
Show Gist options
  • Save charlesmchen/2846442 to your computer and use it in GitHub Desktop.
Save charlesmchen/2846442 to your computer and use it in GitHub Desktop.
Possible robofab bug?
'''
My understanding is that TrueType and OpenType external contours should be clockwise;
internal contours should be counter-clockwise.
RGlyph.correctDirection(), however, seems to normalize contours in exactly the opposite manner.
This script reproduces the issue, drawing a simple square.
'''
import os
import robofab.world
font = robofab.world.NewFont(familyName='test', styleName='test')
font.info.ascender = 1000
font.info.descender = 300
font.info.unitsPerEm = 2024
font.info.xHeight = 500
font.info.capHeight = 1000
glyph = font.newGlyph('A')
glyph.unicode = ord('A')
glyph.width = 1000
# Draw a square.
glyphPen = glyph.getPen()
glyphPen.moveTo((0, 0,))
glyphPen.lineTo((0, 1000,))
glyphPen.lineTo((1000, 1000,))
glyphPen.lineTo((1000, 0,))
glyphPen.closePath()
# The key line
glyph.correctDirection()
glyph.update()
font.update()
dstFile = 'test.ufo'
font.save(dstFile)
font.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment