primitives

Helpers for drawing basic geometric shapes with a pen.

BEZIER_ARC_CIRCLE = 0.5522847493

A constant for drawing circular arcs with beziers.

rect(pen, x, y, w, h)

Draw a rectangle with a pen object.

oval(pen, x, y, w, h)

Draw an oval with a pen object.

element(pen, x, y, w, h, ratio=0.5522847493)

Draw an element with a pen object.

roundedRect(pen, x, y, w, h, radius, ratio=0.5522847493)
drawRectInGlyph(glyph, x, y, w, h)

Draw a rectangle in a glyph.

Parameters
  • glyph (RGlyph) – A glyph object.

  • x (int or float) – Horizontal position.

  • y (int or float) – Vertical position.

  • w (int or float) – The width of the rectangle.

  • h (int or float) – The height of the rectangle.

g = CurrentGlyph()
drawRectInGlyph(g, 50, 100, 120, 120)
drawOvalInGlyph(glyph, x, y, w, h)

Draw an oval in a glyph.

Parameters
  • glyph (RGlyph) – A glyph object.

  • x (int or float) – Horizontal position.

  • y (int or float) – Vertical position.

  • w (int or float) – The width of the rectangle.

  • h (int or float) – The height of the rectangle.

g = CurrentGlyph()
drawOvalInGlyph(g, 50, 100, 120, 120)
drawElementInGlyph(glyph, x, y, w, h, ratio=0.5522847493)

Draw an element inside a glyph.

Parameters
  • glyph (RGlyph) – A glyph object.

  • x (int or float) – Horizontal position.

  • y (int or float) – Vertical position.

  • w (int or float) – The width of the rectangle.

  • h (int or float) – The height of the rectangle.

  • ratio (float) – The ratio of the handle lengths in relation to width or height.

g = CurrentGlyph()
drawElementInGlyph(g, 50, 100, 120, 120, ratio=0.75)
drawRoundedRectInGlyph(glyph, x, y, w, h, radius, ratio=0.5522847493)
addGlyphDrawingTools(RGlyph)

Adds drawing methods to RGlyph objects.

Parameters

RGlyph (RGlyph) – The environment’s RGlyph object.

Call addGlyphDrawingTools once to add drawing methods to the RGlyph object:

from mojo.roboFont import RGlyph
addGlyphDrawingTools(RGlyph)

After that it becomes possible to draw shapes in a glyph directly:

g = CurrentGlyph()
g.rect(0, 0, 80, 80)
g.oval(80, 80, 90, 90)
g.element(170, 170, 100, 100, ratio=0.85)