glyphutils
Tools to work with glyphs.
- autoStartPoints(glyph)
Automatically set starting points in a glyph’s contours.
- getOriginPosition(glyph, posName)
Get a position based on the glyph bounds and a named reference point.
- Parameters
glyph (RGlyph) – A glyph object.
posName (str) – The name of a reference point. Supported keywords: topLeft, topCenter, topRight, middleLeft, middleCenter, middleRight, bottomLeft, bottomCenter, bottomRight.
- Returns
A position as a tuple of (x,y) values.
>>> from hTools3.modules.glyphutils import getOriginPosition >>> getOriginPosition(CurrentGlyph(), 'middleCenter') (243.5, 237.5)
- deselectPoints(glyph)
Deselect all points in a glyph.
- selectPointsLine(glyph, pos, axis='x', side=0)
Select all points below/above a given position.
- Parameters
glyph (RGlyph) – A glyph object.
pos (int or float) – The position of an imaginary line.
axis (str) – The selection axis perpendicular to the line. (x or y)
side (int) – The side of the selection in relation to the line.
0
: smaller or1
: greater than pos.
from hTools3.modules.glyphutils import selectPointsLine glyph = CurrentGlyph() selectPointsLine(glyph, 300, axis='x', side=1)
- shiftSelectedPoints(glyph, delta, axis='x')
Shift all selected points along one axis by a given amount of units.
- Parameters
glyph (RGlyph) – A glyph object.
delta (int or float) – The distance to move the selected points.
axis (str) – The axis along which to move the selected points.
g = CurrentGlyph() g.prepareUndo('shift points') deselectPoints(g) selectPointsLine(g, 200, axis='y', side=0) shiftSelectedPoints(g, -100, axis='y') g.changed() g.performUndo()
- setSmoothPoints(glyph)
- roundPoints(glyph, gridSize)
Round all point positions to a given grid.
- roundBPoints(glyph, gridSize)
Round all bPoint positions to a given grid.
- roundAnchors(glyph, gridSize)
Round all anchor positions to a given grid.
- roundComponents(glyph, gridSize)
Round all components positions to a given grid.
- roundMargins(glyph, gridSize)
Round the margins of a glyph to a given grid.
- roundWidth(glyph, gridSize)
Round the glyph width to a given grid.
- hasSuffix(glyph, suffix)
Check if a glyph’s name has a given
suffix
.
- changeSuffix(glyph, oldSuffix, newSuffix=None)
Create a new glyph name with a different suffix.
- Parameters
glyph (RGlyph) – A glyph object.
oldSuffix (str) – The old suffix to be replaced.
newSuffix (str or None) – The new suffix to be used in place of the old one.
- Returns
A new glyph name with a modified or removed suffix.
- renameGlyphSuffix(glyph, oldSuffix, newSuffix, overwrite=False, duplicate=False, verbose=True)
Add, remove or modify a glyph name’s suffix.
- Parameters
glyph (RGlyph) – A glyph object.
oldSuffix (str) – The old suffix to be replaced.
newSuffix (str or None) – The new suffix to be used in place of the old one.
overwrite (bool) – If a glyph with the new name already exist in the parent font, overwrite it (or not).
duplicate (bool) – Keep the original glyph with the old suffix name.
- renameGlyph(glyph, newName, overwrite=False, duplicate=False, verbose=True)
- findReplaceGlyphName(glyph, findText, replaceText, overwrite=False, duplicate=False, verbose=True)
- addToGlyphName(glyph, addText, suffix=True, overwrite=False, duplicate=False, verbose=True)
- setGlyphWidth(glyph, widthValue, positionMode='do not move')
Transform the width of a glyph.
- Parameters
glyph (RGlyph) – A glyph object.
widthValue (int) – A value to be used as input in the width modification.
positionMode (str) – The position mode. center glyph, split margins, relative split or
None
(do not move).
from hTools3.modules.glyphutils import setGlyphWidth g = CurrentGlyph() setGlyphWidth(g, 700, 'relative split')
- centerGlyph(glyph, useSlantAngle=True, verbose=False)
Center the glyph inside its advance width.
from hTools3.modules.glyphutils import centerGlyph g = CurrentGlyph() centerGlyph(g)
- getPointFromBPoint(bPoint)
Get a Point for a given bPoint.
>>> from hTools3.modules.glyphutils import getPointFromBPoint >>> glyph = CurrentGlyph() >>> bPoint = glyph.contours[0].bPoints[0] >>> print(bPoint) <RBPoint corner anchor='(315, 0)' at 4579032720> >>> pt = getPointFromBPoint(bPoint) >>> print(pt) <RPoint line (315, 0) at 4535967248>
- getBPointFromPoint(point)
Get a bPoint for a given point.
>>> from hTools3.modules.glyphutils import getBPointFromPoint >>> glyph = CurrentGlyph() >>> pt = glyph.contours[0].points[0] >>> print(pt) <RPoint line (315, 0) at 4535965072> >>> bPoint = getBPointFromPoint(pt) >>> print(bPoint) <RBPoint corner anchor='(315, 0)' at 4535965840>
- getPointByIndex(glyph, pointIndex)
- getPointByID(glyph, pointID)