RoboFab





RGlyph()

Usage

g = robofab.world.RGlyph()
g = robofab.objects.objectsFL.RGlyph()
g = robofab.objects.objectsRF.RGlyph()
g = aFontObject[glyphName]

Description

The RGlyph object represents a glyph, its parts and associated data. In FontLab RGlyph talks directly to a glyph in an open font. In NoneLab the RGlyph refers to data read from (and written to) a specific glif file in a UFO. RGlyph can be used as a list of RContours. When RGlyph is obtained from a RoboFab font object (see examples), the font is the parent object of the glyph.

Attributes

  • components: a list of the Components in this glyph.
  • anchors: a list of the Anchors in this glyph.
  • len(aGlyph): the number of contours.
  • aGlyph[index]: get the Contour object at index.
  • width: the horizontal advance width of the glyph.
  • leftMargin: the left margin of the glyph.
  • rightMargin: the right margin of the glyph.
  • name: the glyph name.
  • box: the bounding box. The values are (xMin, yMin, xMax, yMax). Note: these values represent the actual measurements of the shape of the glyph. They're usually different from the rectangle described by glyph.width / font.info.unitsPerEm
  • + - *: math operators work on glyphs. See how to glyphmath.
  • lib: the glyph's lib, an RLib. See also how to use the lib.

Attribute examples

from robofab.world import CurrentFont
f = CurrentFont()

g = f["Adieresis"]
# get the width
print g.width
>>> 358

# get the width
print g.name
# surprise!
>>> Adieresis

print g.unicodes
# a  list of unicode values for this glyph. Can be more than 1!
>>> [196]

# set the width
g.width = 1000
print g.width
>>> 1000

# get the number of contours in a glyph:
print len(g)
>>> 3

# get the name of the glyph
print g.name
>>> Adieresis
    

Methods

  • appendComponent(baseGlyph, offset=(0, 0), scale=(1, 1)): Append a component to the glyph. x and y are optional offset values.
  • appendContour(aContour): add a contour to the glyph.
  • appendComponent(glyphName, (offsetX=0, offsetY=0), (scaleX=1, scaleY=1)): add a component to the glyph. Optional values for offset and scale.
  • >>>>>>> 1.14 appendGlyph(aGlyph): add a whole glyph. This adds all the contours, anchors and components to the glyph.
  • autoUnicodes(): try to find unicode values for this glyph. This method tries to match the glyph name to a known value.
  • copy(): returns a deep copy of this glyph. That means that all parts of the glyph: contours, components, anchors etc. are duplicated.
  • correctDirection(): correct the direction of all contours in this glyphs.
  • autoContourOrder(): automatically order the contours based on (in this order): the point count of the contours, the segment count of the contours, the x value of the center of the contours, the y value of the center of the contours and the surface of the bounding box of the contours.
  • pointInside((x, y)): returns True if the point is inside the "black" area of the glyph or False if the point is inside the "white" area of the glyph.
  • draw(aPen): get this glyph to draw itself with the pen on offer.
  • drawPoints(aPointsPen): get this glyph to draw itself with the points pen on offer. For differences between Pen and PointsPen see here Pens.
  • getPen() returns an appropriate Pen object to draw in this glyph.
  • getPointPen() returns an appropriate Point Pen object to draw in this glyph.
  • removeOverlap(): remove overlap in this glyph (currently only supported in FontLab)
  • interpolate(factor, minGlyph, maxGlyph, suppressError=True, analyzeOnly=False): make this glyph the interpolation between minGlyph and maxGlyph by factor. When suppressError is True (the default value) this method will not complain if the interpolation is not possible. When analyzeOnly is True (default is False), this method will only analyze if the interpolation is possible and provide a report if something is wrong. See also how to interpolate.
  • isCompatible(anotherGlyph, report=True): returns True if the glyph has a compatible point structure as anotherGlyph. When report is True, isCompatible also returns a report on what the problems could be. See also how to interpolate.
  • isEmpty(): returns True when the glyph does not contain any contours, components or anchors.
  • move(x, y), contours=True, components=True, anchors=True): Move a glyph's items that are flagged as True
  • scale((x, y), center=(0, 0)): Scale the glyph by x and y. Optionally set the center of the scale.
  • rotate(angle, offset=None): Rotate the glyph by angle (in degrees). Optionally set an offset value.
  • skew(angle, offset=None): Skew the glyph by angle (in degrees). Optionally set an offset value.
  • rasterize(cellSize=50, xMin=None, yMin=None, xMax=None, yMax=None): Slice the glyph into a grid based on the cell size. It returns a list of lists containing bool values that indicate the black (True) or white (False) value of that particular cell. These lists are arranged from top to bottom of the glyph and proceed from left to right. This is an expensive operation!

Method examples

# get a glyph object from a font
f = CurrentFont()
g = f["A"]
print g
>>> < RGlyph for MyFont-Regular.ufo >

# move the glyph 10 units to the right, and 200 units up:
g = f["a"]
g.move((10, 200))