# robofab manual # Glyph object # Usage examples # start using the current font from robofab.world import CurrentGlyph g = CurrentGlyph() # suppose you've done the right imports # different ways of creating glyphs # a new empty glyph object g = robofab.world.RGlyph() # a new empty fontlab glyph object g = robofab.objects.objectsFL.RGlyph() # a new empty robofab glyph object g = robofab.objects.objectsRF.RGlyph() # the easiest way to get a new glyph # is to ask a font to make you one: g = aFontObject[glyphName]
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
RGlyph is obtained from a RoboFab font object (see examples), the font is the parent object of the glyph.
A list of the Components in this glyph.
A list of the Anchors in this glyph.
The number of contours.
Get the Contour object at index.
The horizontal advance width of the glyph.
The left margin of the glyph.
The right margin of the glyph.
The glyph name.
The unicode value for this glyph, integer.
A place for a short string, a note about this glyph.
A list of unicodes value for this glyph. Not all applications and editors support multiple unicode values for a glyph. Assume that
glyph.unicode == glyph.unicodes.
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
+ - *
Math operators work on glyphs.
The glyph’s lib, an RLib.
A PostScriptGlyphHintValues object with all glyph level PostScript hints, vertical and horizontal.
# robofab manual # Glyph object # attribute examples from robofab.world import CurrentFont, CurrentGlyph f = CurrentFont() # create a glyph object by asking the font g = f["Adieresis"] # alternatively, create a glyph object for the current glyph g = CurrentGlyph() # get the width print g.width # get the name print g.name # a list of unicode values for this glyph. Can be more than 1! print g.unicodes # set the width g.width = 1000 print g.width # get the number of contours in a glyph by getting its length print len(g)
230 Adieresis [123, 345] 1000 4
Return the parent of this glyph, the font object it belongs to. The method returns
None if there is none.
appendComponent(glyphName, (offsetX=0, offsetY=0), (scaleX=1, scaleY=1))¶
Add a component to the glyph. Optional values for
Add a contour to the glyph.
Remove a component from the glyph.
appendGlyph(aGlyph, (offsetX=0, offsetY=0))¶
Add a whole glyph. This adds all the contours, anchors and components to the glyph.
Create a new anchor in this glyph with name at position.
Remove this anchor from the glyph. This only works if the glyph does not have anchors with duplicate names in exactly the same location with the same mark.
Try to find unicode values for this glyph. This method tries to match the glyph name to a known value.
Returns a deep copy of this glyph. That means that all parts of the glyph: contours, components, anchors etc. are duplicated.
Correct the direction of all contours in this glyphs.
Automatically order the contours based on (in this order):
- the point count of the contours
- the segment count of the contours
xvalue of the center of the contours
yvalue of the center of the contours
- the surface of the bounding box of the contours
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.
Get this glyph to draw itself with the pen on offer.
Get this glyph to draw itself with the points pen on offer. For differences between
PointsPen see here
Returns an appropriate
Pen object to draw in this glyph.
Returns an appropriate
PointPen object to draw in this glyph.
interpolate(factor, minGlyph, maxGlyph, suppressError=True, analyzeOnly=False)¶
Make this glyph the interpolation between
maxGlyph by factor. When
True (the default value) this method will not complain if the interpolation is not possible. When
True (default is
False), this method will only analyze if the interpolation is possible and provide a report if something is wrong.
True if the glyph has a compatible point structure as
anotherGlyph. When report is
isCompatible also returns a report on what the problems could be.
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
scale((x, y), center=(0, 0))¶
Scale the glyph by x and y. Optionally set the center of the scale.
Rotate the glyph by
angle (in degrees). Optionally set an
Skew the glyph by
angle (in degrees). Optionally set an
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!
# robofab manual # Glyph object # method examples # get a glyph object from a font f = CurrentFont() g = f["A"] print g # move the glyph 10 units to the right, and 200 units up: g = f["a"] g.move((10, 200))
Glyph methods only available in FontLab.
Remove overlap in this glyph.
Return the wrapped FontLab glyph object itself. This can be useful if you want to set very specific values in the FontLab font that aren’t wrapped or handled by RoboFab objects.
Tell FontLab to update all references to this glyph. Call this after you’ve changed something in the glyph object and you want these changes to be seen in the application. If you’re calling
glyph.update() a lot, for instance in a loop, consider calling it only once after the loop is done. You can also call
font.update() if you’ve changed several glyphs at once. Calling
update() makes a script slower.
Return a list of wrapped vertical guides in this
Return a list of wrapped horizontal guides in this
Add a vertical guide at
x in this
Add a horizontal guide at
y in this
Remove vertical guides from this
Remove horizontal guides from this
# robofab manual # Glyph object # method examples # In FontLab the baseglyph of a component can't be changed easily. # This assumes that there will only be # one component that needs to be remapped. def remapComponent(glyph, oldBaseGlyph, newBaseGlyph): foundComponent = None for component in glyph.components: if component.baseGlyph = oldBaseGlyph: foundComponent = component break if foundComponent is None: return offset = foundComponent.offset scale = foundComponent.scale glyph.removeComponent(component) glyph.appendComponent(newBaseGlyph, offset=offset, scale=scale)