RGlyph()
Usage
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
Methods
- getParent(): 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 offset and scale.
- appendContour(aContour): add a contour to the glyph.
- removeComponent(componentObject): remove a component from the glyph.
- appendGlyph(aGlyph): add a whole glyph. This adds all the contours, anchors and components to the glyph.
- appendAnchor(name, position): create a new anchor in this glyph with name at position.
- removeAnchor(anchor): 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.
- 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.
- 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
FontLab
Methods
Glyph methods only available in FontLab.
- removeOverlap(): remove overlap in this glyph.
- naked(): 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.
- update(): 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.
- getVGuides(): Return a list of wrapped vertical guides in this RGlyph.
- getHGuides(): Return a list of wrapped horizontal guides in this RGlyph.
- appendVGuide(): Add a vertical guide in this RGlyph.
- appendHGuide(): Add a horizontal guide in this RGlyph.
- clearVGuides(): Remove vertical guides from this RGlyph.
- clearHGuides(): Remove horizontal guides from this RGlyph.