outline

Some helper functions around Frederik Berlaen’s OutlinePen.

makeOutline(glyph, distance, join, cap, inner=True, outer=True, miter=None)

Calculate expanded outlines for a given glyph using the OutlinePen.

Parameters
  • distance (int or float) – The amount of outline to apply.

  • join (int) – The type of linejoin.

  • cap (int) – The type of linecap.

  • inner (bool) – Include or not the inner outline contour.

  • outer (bool) – Include or not the outer outline contour.

  • miter (float or None) – The miter value. Used only if the linejoin style is miter.

Returns

An OutlinePen which can draw the resulting outlined shape into a glyph.

from hTools3.modules.outline import makeOutline
sourceGlyph = CurrentGlyph()
outlinePen = makeOutline(sourceGlyph, 20, 0, 0)
targetGlyph = sourceGlyph.getLayer('outline')
targetGlyph.clear()
targetPen = targetGlyph.getPointPen()
outlinePen.drawPoints(targetPen)
expandGlyph(sourceGlyph, targetGlyph, distance, join=1, cap=1, inner=True, outer=True, miter=None, round=False, clear=True)

Expand glyph outlines by a given amount of units.

Parameters
  • sourceGlyph (RGlyph) – The input glyph with contours to be outlined.

  • targetGlyph (RGlyph) – The destination glyph where the output outlined shape will be drawn.

  • distance (int) – The amount of outline to apply.

  • join (int) – The type of linejoin.

  • cap (int) – The type of linecap.

  • inner (bool) – Include or not the inner outline contour.

  • outer (bool) – Include or not the outer outline contour.

  • round (bool) – Round or not glyph coordinates to integers.

  • miter (float or None) – The miter value. Used only if the linejoin style is miter.

  • clear (bool) – Clear the contents of the target glyph before drawing.

from hTools3.modules.outline import expandGlyph
f = CurrentFont()
sourceGlyph = f['O']
targetGlyph = f['space']
distance = 20
expandGlyph(sourceGlyph, targetGlyph, distance, join=0, cap=0, inner=True, outer=True, clear=True)
expandFont(sourceFont, distance, join=1, cap=1)

Expand outlines of all glyphs in a font into a new font.

Parameters
  • sourceFont (RFont) – The input font with glyph contours to be outlined.

  • distance (int or float) – The amount of outline to apply.

  • join (int) – The type of linejoin.

  • cap (int) – The type of linecap.

Returns

A new font containing the outlined glyphs.

from hTools3.modules.outline import expandFont
f = CurrentFont()
distance = 20
expandFont(f, distance, join=1, cap=1).openInterface()