Glyph¶
|
A glyph object. |
|
Set the image in the glyph. |
An Immutable List of all anchors in the glyph. |
|
|
Append an anchor to this glyph. |
|
Append a component to this glyph. |
|
Append a contour containing the same data as |
|
Append the data from |
|
Append a guideline to this glyph. |
|
The area of the glyph as a Integer/Float or, in the case of empty glyphs |
|
Automatically order the contours based on heuristics. |
Use heuristics to set the Unicode values in the glyph. |
|
The glyph's bottom margin. |
|
The bounds of the glyph in the form |
|
|
Deprecated Glyph.box |
|
|
|
Tell the environment that something has changed in the object. |
|
Clear the glyph. |
Clear all anchors in the glyph. |
|
Clear all components in the glyph. |
|
Clear all contours in the glyph. |
|
Clear all guidelines in the glyph. |
|
|
|
Remove the image from the glyph. |
|
|
|
|
alias of |
An Immutable List of all components in the glyph. |
|
An Immutable List of all contours in the glyph. |
|
Copy this glyph's data into a new glyph object. |
|
|
|
|
|
|
Subclasses may override this method. |
|
Correct the winding direction of the contours following the PostScript recommendations. |
Decompose all components in the glyph to contours. |
|
|
Draw the glyph's outline data (contours and components) to the given type-pen. |
|
Draw the glyph's outline data (contours and components) to the given type-pointpen. |
|
This will return the glyph's contents as a string in GLIF format. |
The glyph's parent font. |
|
|
Replaces the contents of this glyph with the contents of |
|
|
|
|
|
Get the type-glyph-layer with |
|
|
Return a type-pen object for adding outline data to the glyph. |
|
Return a type-pointpen object for adding outline data to the glyph. |
|
An Immutable List of all guidelines in the glyph. |
|
The glyph's height. |
|
The |
|
|
Interpolate the contents of this glyph at location |
|
Evaluate the interpolation compatibility of this glyph and |
|
This will return type-bool indicating if there are contours and/or components in the glyph. |
The glyph's parent layer. |
|
Immutable tuple of the glyph's layers. |
|
The glyph's left margin. |
|
The |
|
|
Reads |
|
Deprecated Mark color |
The glyph's mark color. |
|
|
|
|
Move the object. |
Return the environment's native object that has been wrapped by this object. |
|
The glyph's name. |
|
|
Make a new layer with |
The glyph's note. |
|
|
Determine if |
|
This exception needs to be raised frequently by the base classes. |
|
|
|
Remove |
|
Remove |
|
Remove |
|
Remove |
|
Remove |
Perform a remove overlap operation on the contours. |
|
The glyph's right margin. |
|
|
|
|
Rotate the object. |
Round coordinates to the nearest integer. |
|
|
|
|
Scale the object. |
|
The object's selection state. |
|
An Immutable List of anchors selected in the glyph. |
|
An Immutable List of components selected in the glyph. |
|
An Immutable List of contours selected in the glyph. |
|
An Immutable List of guidelines selected in the glyph. |
|
|
|
|
|
|
|
Skew the object. |
|
The |
|
Returns the glyph as an object that follows the MathGlyph protocol. |
The glyph's top margin. |
|
|
|
|
Transform the object. |
|
|
The glyph's primary unicode value. |
|
The glyph's unicode values in order from most to least important. |
|
|
|
The glyph's width. |
|
|
Description¶
The Glyph object represents a glyph, its parts and associated data.
Glyph can be used as a list of Contour objects.
When a Glyph is obtained from a Font object, the font is the parent object of the glyph.
Overview¶
Copy¶
Copy this glyph's data into a new glyph object. |
Parents¶
The glyph's parent layer. |
|
The glyph's parent font. |
Identification¶
The glyph's name. |
|
The glyph's unicode values in order from most to least important. |
|
The glyph's primary unicode value. |
Metrics¶
The glyph's width. |
|
The glyph's left margin. |
|
The glyph's right margin. |
|
The glyph's height. |
|
The glyph's bottom margin. |
|
The glyph's top margin. |
Queries¶
The bounds of the glyph in the form |
|
Determine if |
Pens and Drawing¶
Return a type-pen object for adding outline data to the glyph. |
|
Return a type-pointpen object for adding outline data to the glyph. |
|
Draw the glyph's outline data (contours and components) to the given type-pen. |
|
Draw the glyph's outline data (contours and components) to the given type-pointpen. |
Layers¶
Immutable tuple of the glyph's layers. |
|
Get the type-glyph-layer with |
|
Make a new layer with |
|
Remove |
Global¶
Clear the glyph. |
|
Append the data from |
Contours¶
An Immutable List of all contours in the glyph. |
|
The number of contours in the glyph. |
|
Iterate through all contours in the glyph. |
|
Get the contour located at |
|
Append a contour containing the same data as |
|
Remove |
|
Clear all contours in the glyph. |
|
Perform a remove overlap operation on the contours. |
Components¶
An Immutable List of all components in the glyph. |
|
Append a component to this glyph. |
|
Remove |
|
Clear all components in the glyph. |
|
Decompose all components in the glyph to contours. |
Anchors¶
An Immutable List of all anchors in the glyph. |
|
Append an anchor to this glyph. |
|
Remove |
|
Clear all anchors in the glyph. |
Guidelines¶
An Immutable List of all guidelines in the glyph. |
|
Append a guideline to this glyph. |
|
Remove |
|
Clear all guidelines in the glyph. |
Image¶
The |
|
Set the image in the glyph. |
|
Remove the image from the glyph. |
Note¶
The glyph's note. |
|
The glyph's mark color. |
Sub-Objects¶
The |
|
|
The |
Transformations¶
Transform the object. |
|
Move the object. |
|
Scale the object. |
|
Rotate the object. |
|
Skew the object. |
Interpolation¶
Evaluate the interpolation compatibility of this glyph and |
|
Interpolate the contents of this glyph at location |
Normalization¶
Round coordinates to the nearest integer. |
|
Use heuristics to set the Unicode values in the glyph. |
Environment¶
Return the environment's native object that has been wrapped by this object. |
|
Tell the environment that something has changed in the object. |
Reference¶
- class fontParts.base.BaseGlyph(*args, **kwargs)[source]¶
A glyph object. This object will almost always be created by retrieving it from a font object.
Copy¶
Parents¶
- BaseGlyph.layer¶
The glyph’s parent layer.
>>> layer = glyph.layer
- BaseGlyph.font¶
The glyph’s parent font.
>>> font = glyph.font
Identification¶
- BaseGlyph.name¶
The glyph’s name. This will be a String.
>>> glyph.name "A" >>> glyph.name = "A.alt"
- BaseGlyph.unicodes¶
The glyph’s unicode values in order from most to least important.
>>> glyph.unicodes (65,) >>> glyph.unicodes = [65, 66] >>> glyph.unicodes = []
The values in the returned tuple will be type-int. When setting you may use a list of type-int or type-hex values.
- BaseGlyph.unicode¶
The glyph’s primary unicode value.
>>> glyph.unicode 65 >>> glyph.unicode = None
This is equivalent to
glyph.unicodes[0]. Setting aglyph.unicodevalue will resetglyph.unicodesto a tuple containing that value or an empty tuple ifvalueisNone.>>> glyph.unicodes (65, 67) >>> glyph.unicode = 65 >>> glyph.unicodes (65,) >>> glyph.unicode = None >>> glyph.unicodes ()
The returned value will be an type-int or
None. When setting you may send type-int or type-hex values orNone.
Metrics¶
- BaseGlyph.width¶
The glyph’s width.
>>> glyph.width 500 >>> glyph.width = 200
The value will be a Integer/Float.
- BaseGlyph.leftMargin¶
The glyph’s left margin.
>>> glyph.leftMargin 35 >>> glyph.leftMargin = 45
The value will be a Integer/Float or None if the glyph has no outlines.
- BaseGlyph.rightMargin¶
The glyph’s right margin.
>>> glyph.rightMargin 35 >>> glyph.rightMargin = 45
The value will be a Integer/Float or None if the glyph has no outlines.
- BaseGlyph.height¶
The glyph’s height.
>>> glyph.height 500 >>> glyph.height = 200
The value will be a Integer/Float.
- BaseGlyph.bottomMargin¶
The glyph’s bottom margin.
>>> glyph.bottomMargin 35 >>> glyph.bottomMargin = 45
The value will be a Integer/Float or None if the glyph has no outlines.
- BaseGlyph.topMargin¶
The glyph’s top margin.
>>> glyph.topMargin 35 >>> glyph.topMargin = 45
The value will be a Integer/Float or None if the glyph has no outlines.
Queries¶
- BaseGlyph.bounds¶
The bounds of the glyph in the form
(x minimum, y minimum, x maximum, y maximum)or, in the case of empty glyphsNone.>>> glyph.bounds (10, 30, 765, 643)
- BaseGlyph.pointInside(point)[source]¶
Determine if
pointis in the black or white of the glyph.>>> glyph.pointInside((40, 65)) True
pointmust be a Coordinate.
Pens and Drawing¶
- BaseGlyph.getPen()[source]¶
Return a type-pen object for adding outline data to the glyph.
>>> pen = glyph.getPen()
- BaseGlyph.getPointPen()[source]¶
Return a type-pointpen object for adding outline data to the glyph.
>>> pointPen = glyph.getPointPen()
- BaseGlyph.draw(pen, contours=True, components=True)[source]¶
Draw the glyph’s outline data (contours and components) to the given type-pen.
>>> glyph.draw(pen)
If
contoursis set toFalse, the glyph’s contours will not be drawn.>>> glyph.draw(pen, contours=False)
If
componentsis set toFalse, the glyph’s components will not be drawn.>>> glyph.draw(pen, components=False)
- BaseGlyph.drawPoints(pen, contours=True, components=True)[source]¶
Draw the glyph’s outline data (contours and components) to the given type-pointpen.
>>> glyph.drawPoints(pointPen)
If
contoursis set toFalse, the glyph’s contours will not be drawn.>>> glyph.drawPoints(pointPen, contours=False)
If
componentsis set toFalse, the glyph’s components will not be drawn.>>> glyph.drawPoints(pointPen, components=False)
Layers¶
Layer interaction in glyphs is very similar to the layer interaction in fonts. When you ask a glyph for a layer, you get a glyph layer in return. A glyph layer lets you do anything that you can do to a glyph. In fact a glyph layer is really just a glyph.
>>> bgdGlyph = glyph.newLayer('background')
>>> bgdGlyph.appendGlyph(glyph)
>>> bgdGlyph.appendGuideline((10, 10), 45)
- BaseGlyph.layers¶
Immutable tuple of the glyph’s layers.
>>> glyphLayers = glyph.layers
This will return a tuple of all type-glyph-layer in the glyph.
- BaseGlyph.getLayer(name)[source]¶
Get the type-glyph-layer with
namein this glyph.>>> glyphLayer = glyph.getLayer("foreground")
Global¶
- BaseGlyph.clear(contours=True, components=True, anchors=True, guidelines=True, image=True)[source]¶
Clear the glyph.
>>> glyph.clear()
This clears:
contours
components
anchors
guidelines
image
It’s possible to turn off the clearing of portions of the glyph with the listed arguments.
>>> glyph.clear(guidelines=False)
- BaseGlyph.appendGlyph(other, offset=None)[source]¶
Append the data from
otherto new objects in this glyph.>>> glyph.appendGlyph(otherGlyph)
This will append:
contours
components
anchors
guidelines
offsetindicates the x and y shift values that should be applied to the appended data. It must be a Coordinate value orNone. IfNoneis given, the offset will be(0, 0).>>> glyph.appendGlyph(otherGlyph, (100, 0))
Contours¶
- BaseGlyph.contours¶
An Immutable List of all contours in the glyph.
>>> contours = glyph.contours
The list will contain
BaseContourobjects.
- BaseGlyph.__iter__()[source]¶
Iterate through all contours in the glyph.
>>> for contour in glyph: ... contour.reverse()
- BaseGlyph.__getitem__(index)[source]¶
Get the contour located at
indexfrom the glyph.>>> contour = glyph[0]
The returned value will be a
BaseContourobject.
- BaseGlyph.appendContour(contour, offset=None)[source]¶
Append a contour containing the same data as
contourto this glyph.>>> contour = glyph.appendContour(contour)
This will return a
BaseContourobject representing the new contour in the glyph.offsetindicates the x and y shift values that should be applied to the appended data. It must be a Coordinate value orNone. IfNoneis given, the offset will be(0, 0).>>> contour = glyph.appendContour(contour, (100, 0))
Components¶
- BaseGlyph.components¶
An Immutable List of all components in the glyph.
>>> components = glyph.components
The list will contain
BaseComponentobjects.
- BaseGlyph.appendComponent(baseGlyph=None, offset=None, scale=None, component=None)[source]¶
Append a component to this glyph.
>>> component = glyph.appendComponent("A")
This will return a
BaseComponentobject representing the new component in the glyph.offsetindicates the x and y shift values that should be applied to the appended component. It must be a Coordinate value orNone. IfNoneis given, the offset will be(0, 0).>>> component = glyph.appendComponent("A", offset=(10, 20))
scaleindicates the x and y scale values that should be applied to the appended component. It must be a type-scale value orNone. IfNoneis given, the scale will be(1.0, 1.0).>>> component = glyph.appendComponent("A", scale=(1.0, 2.0))
componentmay be aBaseComponentobject from which attribute values will be copied. IfbaseGlyph,offsetorscaleare specified as arguments, those values will be used instead of the values in the given component object.
Anchors¶
- BaseGlyph.anchors¶
An Immutable List of all anchors in the glyph.
>>> anchors = glyph.anchors
The list will contain
BaseAnchorobjects.
- BaseGlyph.appendAnchor(name=None, position=None, color=None, anchor=None)[source]¶
Append an anchor to this glyph.
>>> anchor = glyph.appendAnchor("top", (10, 20))
This will return a
BaseAnchorobject representing the new anchor in the glyph.nameindicated the name to be assigned to the anchor. It must be a String orNone.positionindicates the x and y location to be applied to the anchor. It must be a Coordinate value.colorindicates the color to be applied to the anchor. It must be a Color orNone.>>> anchor = glyph.appendAnchor("top", (10, 20), color=(1, 0, 0, 1))
anchormay be aBaseAnchorobject from which attribute values will be copied. Ifname,positionorcolorare specified as arguments, those values will be used instead of the values in the given anchor object.
Guidelines¶
- BaseGlyph.guidelines¶
An Immutable List of all guidelines in the glyph.
>>> guidelines = glyph.guidelines
The list will contain
BaseGuidelineobjects.
- BaseGlyph.appendGuideline(position=None, angle=None, name=None, color=None, guideline=None)[source]¶
Append a guideline to this glyph.
>>> guideline = glyph.appendGuideline((100, 0), 90)
This will return a
BaseGuidelineobject representing the new guideline in the glyph.positionindicates the x and y location to be used as the center point of the anchor. It must be a Coordinate value.angleindicates the angle of the guideline, in degrees. This must be a Integer/Float between 0 and 360.nameindicates an name to be assigned to the guideline. It must be a String orNone.>>> guideline = glyph.appendGuideline((100, 0), 90, name="left")
colorindicates the color to be applied to the guideline. It must be a Color orNone.>>> guideline = glyph.appendGuideline((100, 0), 90, color=(1, 0, 0, 1))
guidelinemay be aBaseGuidelineobject from which attribute values will be copied. Ifposition,angle,nameorcolorare specified as arguments, those values will be used instead of the values in the given guideline object.
Image¶
- BaseGlyph.addImage(path=None, data=None, scale=None, position=None, color=None)[source]¶
Set the image in the glyph. This will return the assigned
BaseImage. The image data can be defined viapathto an image file:>>> image = glyph.addImage(path="/path/to/my/image.png")
The image data can be defined with raw image data via
data.>>> image = glyph.addImage(data=someImageData)
If
pathanddataare both provided, aFontPartsErrorwill be raised. The supported image formats will vary across environments. Refer toBaseImagefor complete details.scaleindicates the x and y scale values that should be applied to the image. It must be a type-scale value orNone.>>> image = glyph.addImage(path="/p/t/image.png", scale=(0.5, 1.0))
positionindicates the x and y location of the lower left point of the image.>>> image = glyph.addImage(path="/p/t/image.png", position=(10, 20))
colorindicates the color to be applied to the image. It must be a Color orNone.>>> image = glyph.addImage(path="/p/t/image.png", color=(1, 0, 0, 0.5))
Note¶
Sub-Objects¶
Transformations¶
- BaseGlyph.transformBy(matrix, origin=None)¶
Transform the object.
>>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0)) >>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0), origin=(500, 500))
matrix must be a Transformation Matrix. origin defines the point at with the transformation should originate. It must be a Coordinate or
None. The default is(0, 0).
- BaseGlyph.moveBy(value)¶
Move the object.
>>> obj.moveBy((10, 0))
value must be an iterable containing two Integer/Float values defining the x and y values to move the object by.
- BaseGlyph.scaleBy(value, origin=None, width=False, height=False)[source]¶
Scale the object.
>>> obj.scaleBy(2.0) >>> obj.scaleBy((0.5, 2.0), origin=(500, 500))
value must be an iterable containing two Integer/Float values defining the x and y values to scale the object by. origin defines the point at with the scale should originate. It must be a Coordinate or
None. The default is(0, 0).width indicates if the glyph’s width should be scaled. height indicates if the glyph’s height should be scaled.
The origin must not be specified when scaling the width or height.
- BaseGlyph.rotateBy(value, origin=None)¶
Rotate the object.
>>> obj.rotateBy(45) >>> obj.rotateBy(45, origin=(500, 500))
value must be a Integer/Float values defining the angle to rotate the object by. origin defines the point at with the rotation should originate. It must be a Coordinate or
None. The default is(0, 0).
- BaseGlyph.skewBy(value, origin=None)¶
Skew the object.
>>> obj.skewBy(11) >>> obj.skewBy((25, 10), origin=(500, 500))
value must be rone of the following:
single Integer/Float indicating the value to skew the x direction by.
iterable cointaining type Integer/Float defining the values to skew the x and y directions by.
origin defines the point at with the skew should originate. It must be a Coordinate or
None. The default is(0, 0).
Interpolation¶
- BaseGlyph.isCompatible(other)[source]¶
Evaluate the interpolation compatibility of this glyph and
other.>>> compatible, report = self.isCompatible(otherGlyph) >>> compatible False
This will return a type-bool indicating if this glyph is compatible with
otherand aGlyphCompatibilityReportercontaining a detailed report about compatibility errors.
- BaseGlyph.interpolate(factor, minGlyph, maxGlyph, round=True, suppressError=True)[source]¶
Interpolate the contents of this glyph at location
factorin a linear interpolation betweenminGlyphandmaxGlyph.>>> glyph.interpolate(0.5, otherGlyph1, otherGlyph2)
factormay be a Integer/Float or a tuple containing two Integer/Float values representing x and y factors.>>> glyph.interpolate((0.5, 1.0), otherGlyph1, otherGlyph2)
minGlyphmust be aBaseGlyphand will be located at 0.0 in the interpolation range.maxGlyphmust be aBaseGlyphand will be located at 1.0 in the interpolation range. IfroundisTrue, the contents of the glyph will be rounded to integers after the interpolation is performed.>>> glyph.interpolate(0.5, otherGlyph1, otherGlyph2, round=True)
This method assumes that
minGlyphandmaxGlyphare completely compatible with each other for interpolation. If not, any errors encountered will raise aFontPartsError. IfsuppressErrorisTrue, no exception will be raised and errors will be silently ignored.
Normalization¶
Environment¶
- BaseGlyph.naked()¶
Return the environment’s native object that has been wrapped by this object.
>>> loweLevelObj = obj.naked()
- BaseGlyph.changed(*args, **kwargs)¶
Tell the environment that something has changed in the object. The behavior of this method will vary from environment to environment.
>>> obj.changed()