Glyph

BaseGlyph(*args, **kwargs)

Represent the basis for a glyph object.

BaseGlyph.addImage([path, data, scale, ...])

Set the image in the glyph.

BaseGlyph.anchors

Get all anchors in the glyph.

BaseGlyph.appendAnchor([name, position, ...])

Append an anchor to the glyph.

BaseGlyph.appendComponent([baseGlyph, ...])

Append a component to the glyph.

BaseGlyph.appendContour(contour[, offset])

Append the given contour's data to the glyph.

BaseGlyph.appendGlyph(other[, offset])

Append data from other to new objects in the glyph.

BaseGlyph.appendGuideline([position, angle, ...])

Append a guideline to the glyph.

BaseGlyph.area

Get the area of the glyph

BaseGlyph.autoContourOrder()

Automatically order the glyph's contours based on heuristics.

BaseGlyph.autoUnicodes()

Use heuristics to set the Unicode values in the glyph.

BaseGlyph.bottomMargin

Get or set the glyph's bottom margin.

BaseGlyph.bounds

Get the bounds of the glyph.

BaseGlyph.box

Deprecated Glyph.box

BaseGlyph.center([padding])

BaseGlyph.changed(*args, **kwargs)

Tell the environment that something has changed in the object.

BaseGlyph.clear([contours, components, ...])

Clear the glyph data.

BaseGlyph.clearAnchors()

Clear all anchors in the glyph.

BaseGlyph.clearComponents()

Clear all components in the glyph.

BaseGlyph.clearContours()

Clear all contours in the glyph.

BaseGlyph.clearGuidelines()

Clear all guidelines in the glyph.

BaseGlyph.clearHGuides()

BaseGlyph.clearImage()

Remove the image from the glyph.

BaseGlyph.clearVGuides()

BaseGlyph.compatibilityReporterClass

BaseGlyph.components

Get all components in the glyph.

BaseGlyph.contours

Get all contours in the glyph.

BaseGlyph.copy()

Copy data from the current glyph into a new glyph.

BaseGlyph.copyAttributes

BaseGlyph.copyClass

BaseGlyph.copyData(source)

Copy data from another glyph instance.

BaseGlyph.correctDirection([trueType])

Correct the winding direction of the glyph's contours.

BaseGlyph.decompose()

Decompose all components in the glyph to contours.

BaseGlyph.draw(pen[, contours, components])

Draw the glyph's outline data to the given pen object.

BaseGlyph.drawPoints(pen[, contours, components])

Draw the glyph's outline data to the given point pen object.

BaseGlyph.dumpToGLIF([glyphFormatVersion])

Return the glyph's contents as a string in GLIF format.

BaseGlyph.font

Get the glyph's parent font object.

BaseGlyph.fromMathGlyph(mathGlyph[, ...])

Replace the glyph's data with the specified mathGlyph.

BaseGlyph.getAnchors()

BaseGlyph.getComponents()

BaseGlyph.getLayer(name)

Get the named layer from the glyph.

BaseGlyph.getParent()

BaseGlyph.getPen()

Return a pen object for adding outline data to the glyph.

BaseGlyph.getPointPen()

Return a point pen object for adding outline data to the glyph.

BaseGlyph.guidelines

Get all guidelines in the glyph.

BaseGlyph.height

Get or set the glyph's height.

BaseGlyph.image

Get the image for the glyph.

BaseGlyph.interpolate(factor, minGlyph, maxGlyph)

Interpolate all possible data in the glyph.

BaseGlyph.isCompatible(other[, cls])

Evaluate interpolation compatibility with another glyph.

BaseGlyph.isEmpty()

Check if the glyph is empty.

BaseGlyph.layer

Get or set the glyph's parent layer object.

BaseGlyph.layers

Get the layers of the glyph.

BaseGlyph.leftMargin

Get or set the glyph's left margin.

BaseGlyph.lib

Get the font's lib object.

BaseGlyph.loadFromGLIF(glifData)

Read data in GLIF format into the glyph.

BaseGlyph.mark

Deprecated Mark color

BaseGlyph.markColor

Get or set the glyph's mark color.

BaseGlyph.move(*args, **kwargs)

BaseGlyph.moveBy(value)

Move the object according to the given coordinates.

BaseGlyph.naked()

Return the environment's native object wrapped by the current object.

BaseGlyph.name

Get or set the name of the glyph.

BaseGlyph.newLayer(name)

Create a new layer in the glyph.

BaseGlyph.note

Get or set the glyph's note.

BaseGlyph.pointInside(point)

Check if point lies inside the filled area of the glyph.

BaseGlyph.raiseNotImplementedError()

Raise a NotImplementedError.

BaseGlyph.readGlyphFromString(glifData)

BaseGlyph.removeAnchor(anchor)

Remove the given anchor from the glyph.

BaseGlyph.removeComponent(component)

Remove the specified component from the glyph.

BaseGlyph.removeContour(contour)

Remove the given contour from the glyph.

BaseGlyph.removeGuideline(guideline)

Remove the given guideline from the glyph.

BaseGlyph.removeLayer(layer)

Remove the specified layer from the glyph.

BaseGlyph.removeOverlap()

Perform a remove overlap operation on the glyph's contours.

BaseGlyph.rightMargin

Get or set the glyph's right margin.

BaseGlyph.rotate(*args, **kwargs)

BaseGlyph.rotateBy(value[, origin])

Rotate the object by the specified value.

BaseGlyph.round()

Round coordinates in the glyph to the nearest integer.

BaseGlyph.scale(*args, **kwargs)

BaseGlyph.scaleBy(value[, origin, width, height])

Scale the glyph according to the given values.

BaseGlyph.selected

Get or set the object's selection state.

BaseGlyph.selectedAnchors

Get or set the selected anchors in the glyph.

BaseGlyph.selectedComponents

Get or set the selected components in the glyph.

BaseGlyph.selectedContours

Get or set the selected contours in the glyph.

BaseGlyph.selectedGuidelines

Get or set the selected guidelines in the glyph.

BaseGlyph.setChanged()

BaseGlyph.setParent(parent)

BaseGlyph.skew(*args, **kwargs)

BaseGlyph.skewBy(value[, origin])

Skew the object by the given value.

BaseGlyph.tempLib

Get the glyph's temporary lib object.

BaseGlyph.toMathGlyph([...])

Return the glyph as a fontMath MathGlyph object.

BaseGlyph.topMargin

Get or set the glyph's top margin.

BaseGlyph.transform(*args, **kwargs)

BaseGlyph.transformBy(matrix[, origin])

Transform the object according to the given matrix.

BaseGlyph.translate(*args, **kwargs)

BaseGlyph.unicode

Get or set the glyph's primary Unicode value.

BaseGlyph.unicodes

Get or set the glyph's Unicode values.

BaseGlyph.update()

BaseGlyph.width

Get or set the width of the glyph.

BaseGlyph.writeGlyphToString([...])

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

BaseGlyph.copy

Copy data from the current glyph into a new glyph.

Parents

BaseGlyph.layer

Get or set the glyph's parent layer object.

BaseGlyph.font

Get the glyph's parent font object.

Identification

BaseGlyph.name

Get or set the name of the glyph.

BaseGlyph.unicodes

Get or set the glyph's Unicode values.

BaseGlyph.unicode

Get or set the glyph's primary Unicode value.

Metrics

BaseGlyph.width

Get or set the width of the glyph.

BaseGlyph.leftMargin

Get or set the glyph's left margin.

BaseGlyph.rightMargin

Get or set the glyph's right margin.

BaseGlyph.height

Get or set the glyph's height.

BaseGlyph.bottomMargin

Get or set the glyph's bottom margin.

BaseGlyph.topMargin

Get or set the glyph's top margin.

Queries

BaseGlyph.bounds

Get the bounds of the glyph.

BaseGlyph.pointInside

Check if point lies inside the filled area of the glyph.

Pens and Drawing

BaseGlyph.getPen

Return a pen object for adding outline data to the glyph.

BaseGlyph.getPointPen

Return a point pen object for adding outline data to the glyph.

BaseGlyph.draw

Draw the glyph's outline data to the given pen object.

BaseGlyph.drawPoints

Draw the glyph's outline data to the given point pen object.

Layers

BaseGlyph.layers

Get the layers of the glyph.

BaseGlyph.getLayer

Get the named layer from the glyph.

BaseGlyph.newLayer

Create a new layer in the glyph.

BaseGlyph.removeLayer

Remove the specified layer from the glyph.

Global

BaseGlyph.clear

Clear the glyph data.

BaseGlyph.appendGlyph

Append data from other to new objects in the glyph.

Contours

BaseGlyph.contours

Get all contours in the glyph.

BaseGlyph.__len__

Get the number of contours in the glyph.

BaseGlyph.__iter__

Iterate through all contours in the glyph.

BaseGlyph.__getitem__

Get the contour located at the given index from the glyph.

BaseGlyph.appendContour

Append the given contour's data to the glyph.

BaseGlyph.removeContour

Remove the given contour from the glyph.

BaseGlyph.clearContours

Clear all contours in the glyph.

BaseGlyph.removeOverlap

Perform a remove overlap operation on the glyph's contours.

Components

BaseGlyph.components

Get all components in the glyph.

BaseGlyph.appendComponent

Append a component to the glyph.

BaseGlyph.removeComponent

Remove the specified component from the glyph.

BaseGlyph.clearComponents

Clear all components in the glyph.

BaseGlyph.decompose

Decompose all components in the glyph to contours.

Anchors

BaseGlyph.anchors

Get all anchors in the glyph.

BaseGlyph.appendAnchor

Append an anchor to the glyph.

BaseGlyph.removeAnchor

Remove the given anchor from the glyph.

BaseGlyph.clearAnchors

Clear all anchors in the glyph.

Guidelines

BaseGlyph.guidelines

Get all guidelines in the glyph.

BaseGlyph.appendGuideline

Append a guideline to the glyph.

BaseGlyph.removeGuideline

Remove the given guideline from the glyph.

BaseGlyph.clearGuidelines

Clear all guidelines in the glyph.

Image

BaseGlyph.image

Get the image for the glyph.

BaseGlyph.addImage

Set the image in the glyph.

BaseGlyph.clearImage

Remove the image from the glyph.

Note

BaseGlyph.note

Get or set the glyph's note.

BaseGlyph.markColor

Get or set the glyph's mark color.

Sub-Objects

BaseGlyph.lib

Get the font's lib object.

BaseGlyph.tempLib

Get the glyph's temporary lib object.

Transformations

BaseGlyph.transformBy

Transform the object according to the given matrix.

BaseGlyph.moveBy

Move the object according to the given coordinates.

BaseGlyph.scaleBy

Scale the glyph according to the given values.

BaseGlyph.rotateBy

Rotate the object by the specified value.

BaseGlyph.skewBy

Skew the object by the given value.

Interpolation

BaseGlyph.isCompatible

Evaluate interpolation compatibility with another glyph.

BaseGlyph.interpolate

Interpolate all possible data in the glyph.

Normalization

BaseGlyph.round

Round coordinates in the glyph to the nearest integer.

BaseGlyph.autoUnicodes

Use heuristics to set the Unicode values in the glyph.

Environment

BaseGlyph.naked

Return the environment's native object wrapped by the current object.

BaseGlyph.changed

Tell the environment that something has changed in the object.

Reference

class fontParts.base.BaseGlyph(*args: Any, **kwargs: Any)[source]

Represent the basis for a glyph object.

This object will almost always be created by retrieving it from a font object.

Copy

BaseGlyph.copy() BaseGlyph[source]

Copy data from the current glyph into a new glyph.

This new glyph object will not belong to a font.

This will copy:

Returns:

A new BaseGlyph instance with the same attributes.

Example:

>>> copiedGlyph = glyph.copy()

Parents

BaseGlyph.layer: dynamicProperty

Get or set the glyph’s parent layer object.

The value must be a BaseLayer instance or None.

Returns:

The BaseLayer instance containing the glyph or None.

Example:

>>> layer = glyph.layer
BaseGlyph.font: dynamicProperty

Get the glyph’s parent font object.

This property is read-only.

Returns:

The BaseFont instance containing the glyph or None.

Example:

>>> font = glyph.font

Identification

BaseGlyph.name: dynamicProperty

Get or set the name of the glyph.

The value must be a str.

Returns:

A str defining the name of the glyph.

Raises:

ValueError – If attempting to set the name to one that already exists in the layer.

Example:

>>> glyph.name
"A"
>>> glyph.name = "A.alt"
BaseGlyph.unicodes: dynamicProperty

Get or set the glyph’s Unicode values.

The value must be a list or tuple of int or hexadecimal str values, ordered from most to least important.

Returns:

A tuple of int values representing the glyphs Unicode values in order from most to least important.

Example:

>>> glyph.unicodes
(65,)
>>> glyph.unicodes = [65, 66]
>>> glyph.unicodes = []
BaseGlyph.unicode: dynamicProperty

Get or set the glyph’s primary Unicode value.

This property is equivalent to glyph.unicodes[0] and will reset BaseGlyph.unicodes to a tuple containing that value, or to an empty tuple if value is None.

The value must be an int, a hexadecimal str or None.

Returns:

An int representing the glyphs primary Unicode value or None.

Example:

>>> glyph.unicode
65
>>> glyph.unicode = None
None

Interaction with the BaseGlyph.unicodes property:

>>> glyph.unicodes
(65, 67)
>>> glyph.unicode = 65
>>> glyph.unicodes
(65,)
>>> glyph.unicode = None
>>> glyph.unicodes
()

Metrics

BaseGlyph.width: dynamicProperty

Get or set the width of the glyph.

The value must be an int or a float.

Returns:

An int or a float representing the width of the glyph.

Example:

>>> glyph.width
500
>>> glyph.width = 200
BaseGlyph.leftMargin: dynamicProperty

Get or set the glyph’s left margin.

The value must be either an int or a float.

Returns:

The left glyph margin as an int or a float, or None if the glyph has no outlines.

Example:

>>> glyph.leftMargin
35
>>> glyph.leftMargin = 45
BaseGlyph.rightMargin: dynamicProperty

Get or set the glyph’s right margin.

The value must be either an int or a float.

Returns:

The right glyph margin as an int or a float, or None if the glyph has no outlines.

Example:

>>> glyph.rightMargin
35
>>> glyph.rightMargin = 45
BaseGlyph.height: dynamicProperty

Get or set the glyph’s height.

The value must be int or float.

Returns:

The glyph height as an int or a float.

Example:

>>> glyph.height
500
>>> glyph.height = 200
BaseGlyph.bottomMargin: dynamicProperty

Get or set the glyph’s bottom margin.

The value must be either an int or a float.

Returns:

The bottom glyph margin as an int or a float, or None to indicate that the glyph has no outlines.

Example:

>>> glyph.bottomMargin
35
>>> glyph.bottomMargin = 45
BaseGlyph.topMargin: dynamicProperty

Get or set the glyph’s top margin.

The value must be either an int or a float.

Returns:

The top glyph margin as an int or a float, or None to indicate that the glyph has no outlines.

Example:

>>> glyph.topMargin
35
>>> glyph.topMargin = 45

Queries

BaseGlyph.bounds: dynamicProperty

Get the bounds of the glyph.

This property is read-only.

Returns:

A tuple of four int or float values in the form (x minimum, y minimum, x maximum, y maximum) representing the bounds of the glyph, or None if the glyph is empty.

Example:

>>> glyph.bounds
(10, 30, 765, 643)
BaseGlyph.pointInside(point: list[int | float] | tuple[int | float, int | float]) bool[source]

Check if point lies inside the filled area of the glyph.

Parameters:

point – The point to check as a Coordinate.

Returns:

True if point is inside the filled area of the glyph, False otherwise.

Example:

>>> glyph.pointInside((40, 65))
True

Pens and Drawing

BaseGlyph.getPen() AbstractPen[source]

Return a pen object for adding outline data to the glyph.

Returns:

An instance of an AbstractPen subclass.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Example:

>>> pen = glyph.getPen()
BaseGlyph.getPointPen() AbstractPointPen[source]

Return a point pen object for adding outline data to the glyph.

Returns:

An instance of an AbstractPointPen subclass.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Example:

>>> pointPen = glyph.getPointPen()
BaseGlyph.draw(pen: AbstractPen, contours: bool = True, components: bool = True) None[source]

Draw the glyph’s outline data to the given pen object.

Parameters:
  • pen – The AbstractPen subclass instance to which the data should be drawn.

  • contours – Whether to draw data from the glyph’s contours. Defaults to True

  • components – Whether to draw data from the glyph’s contours. Defaults to True

Example:

>>> glyph.draw(pen)
>>> glyph.draw(pen, contours=False)
>>> glyph.draw(pen, components=False)
BaseGlyph.drawPoints(pen: AbstractPointPen, contours: bool = True, components: bool = True) None[source]

Draw the glyph’s outline data to the given point pen object.

Parameters:
  • pen – The AbstractPointPen subclass instance to which the data should be drawn.

  • contours – Whether to draw data from the glyph’s contours. Defaults to True

  • components – Whether to draw data from the glyph’s contours. Defaults to True.

Example:

>>> glyph.drawPoints(pointPen)
>>> glyph.drawPoints(pointPen, contours=False)
>>> 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: dynamicProperty

Get the layers of the glyph.

This property is read-only.

Returns:

A tuple of the BaseLayer instances belonging to the glyph.

Example:

>>> glyphLayers = glyph.layers
BaseGlyph.getLayer(name: str) BaseGlyph[source]

Get the named layer from the glyph.

Parameters:

name – The name of the BaseLayer instance to retrieve.

Returns:

The specified BaseLayer instance.

Raises:

ValueError – If no layer with the given name exists in the font.

Example:

>>> glyphLayer = glyph.getLayer("foreground")
BaseGlyph.newLayer(name: str) BaseGlyph[source]

Create a new layer in the glyph.

If the named layer already exists in the glyph, it will be cleared.

Parameters:

name – The name of the new layer to create.

Returns:

A newly created BaseLayer instance.

Example:

>>> glyphLayer = glyph.newLayer("background")
BaseGlyph.removeLayer(layer: BaseGlyph | str) None[source]

Remove the specified layer from the glyph.

Parameters:

name – The layer to remove as a BaseLayer instance, or a str representing the layer name.

Example:

>>> glyph.removeLayer("background")

Global

BaseGlyph.clear(contours: bool = True, components: bool = True, anchors: bool = True, guidelines: bool = True, image: bool = True) None[source]

Clear the glyph data.

This will clear:

The clearing of portions of the glyph may be turned off with the listed parameters.

Parameters:
  • contours – Whether to clear the glyph’s contour data. Defaults to True

  • components – Whether to clear the glyph’s component data. Defaults to True

  • anchors – Whether to clear the glyph’s anchor data. Defaults to True

  • guidelines – Whether to clear the glyph’s guideline data. Defaults to True

  • image – Whether to clear the glyph’s image data. Defaults to True

Example:

>>> glyph.clear()
>>> glyph.clear(guidelines=False)
BaseGlyph.appendGlyph(other: BaseGlyph, offset: list[int | float] | tuple[int | float, int | float] | None = None) None[source]

Append data from other to new objects in the glyph.

This will append:

Parameters:
  • other – The BaseGlyph instace containing the source data to append.

  • offset – The x and y shift values to be applied to the appended data as a Coordinate, or None representing an offset of (0, 0).

Example:

>>> glyph.appendGlyph(otherGlyph)
>>> glyph.appendGlyph(otherGlyph, (100, 0))

Contours

BaseGlyph.contours: dynamicProperty

Get all contours in the glyph.

This property is read-only.

Returns:

A tuple of BaseContour objects.

Example:

>>> contours = glyph.contours
BaseGlyph.__len__() int[source]

Get the number of contours in the glyph.

Returns:

An int representing the number of contours in the glyph.

Example:

>>> len(glyph)
2
BaseGlyph.__iter__() Iterator[BaseContour][source]

Iterate through all contours in the glyph.

Returns:

An iterator of BaseContour instances.

Example:

>>> for contour in glyph:
...     contour.reverse()
BaseGlyph.__getitem__(index: int) BaseContour[source]

Get the contour located at the given index from the glyph.

Parameters:

index – The index of the glyph to return as an int.

Returns:

An instance of the BaseContour class.

Example:

>>> contour = glyph[0]
BaseGlyph.appendContour(contour: BaseContour, offset: CoordinateLike | None = None) BaseContour[source]

Append the given contour’s data to the glyph.

Parameters:
  • contour – The BaseContour instace containing the source data to append.

  • offset – The x and y shift values to be applied to the appended data as a Coordinate, or None representing an offset of (0, 0).

Returns:

A BaseContour instance containing the appended data.

Example:

>>> contour = glyph.appendContour(contour)
>>> contour = glyph.appendContour(contour, (100, 0))
BaseGlyph.removeContour(contour: BaseContour | int) None[source]

Remove the given contour from the glyph.

Parameters:

contour – The contour to remove as a BaseContour instance or an int representing a contour index.

Raises:

ValueError – If no contour can be found at the given index.

Example:

>>> glyph.removeContour(contour)
BaseGlyph.clearContours() None[source]

Clear all contours in the glyph.

Example:

>>> glyph.clearContours()
BaseGlyph.removeOverlap() None[source]

Perform a remove overlap operation on the glyph’s contours.

The behavior of this may vary across environments.

Example:

>>> glyph.removeOverlap()

Components

BaseGlyph.components: dynamicProperty

Get all components in the glyph.

This property is read-only.

Returns:

A tuple of BaseComponent instances.

Example:

>>> components = glyph.components
BaseGlyph.appendComponent(baseGlyph: str | None = None, offset: CoordinateLike | None = None, scale: ScaleFactorLike | None = None, component: BaseComponent | None = None) BaseComponent[source]

Append a component to the glyph.

If baseGlyph, offset or scale is specified, those values will be used instead of the values in the given component.

Parameters:
  • baseGlyph – An optional glyph name to append as a component. Defaults to None.

  • offset – The x and y shift values to be applied to the appended data as a Coordinate, or None representing an offset of (0, 0). Defaults to None

  • scale – The x and y scale values that should be applied to the appended component as a tuple of int or float values, or None representing a scale of (1.0, 1.0). Defaults to None

  • component – An optional BaseComponent instance from which to copy attribute values. Defaults to None.

Returns:

The newly appended BaseComponent instance.

Raises:

FontPartsError – If the baseGlyph refers to the current glyph instance, which would result in a component referencing itself. This is not permitted.

Example:

>>> component = glyph.appendComponent("A")
>>> component = glyph.appendComponent("A", offset=(10, 20))
>>> component = glyph.appendComponent("A", scale=(1.0, 2.0))
BaseGlyph.removeComponent(component: BaseComponent | int) None[source]

Remove the specified component from the glyph.

Parameters:

component – The component to remove as a BaseComponent instance or an int representing the component’s index.

Raises:

ValueError – If no component can be found at the given index.

Example:

>>> glyph.removeComponent(component)
BaseGlyph.clearComponents() None[source]

Clear all components in the glyph.

Example:

>>> glyph.clearComponents()
BaseGlyph.decompose() None[source]

Decompose all components in the glyph to contours.

Example:

>>> glyph.decompose()

Anchors

BaseGlyph.anchors: dynamicProperty

Get all anchors in the glyph.

This property is read-only.

Returns:

A tuple of BaseAnchor instances.

Example:

>>> anchors = glyph.anchors
BaseGlyph.appendAnchor(name: str | None = None, position: CoordinateLike | None = None, color: RGBALike | None = None, anchor: BaseAnchor | None = None) BaseAnchor[source]

Append an anchor to the glyph.

If name, position or color are specified, those values will be used instead of the values in the given anchor object.

Parameters:
  • name – An optional name to be assigned to the anchor as a str. Defaults to None.

  • position – The optional x and y location to be applied to the anchor as a Coordinate. Defaults to None.

  • color – The optional color to be applied to the anchor as a Color. Defaults to None.

  • anchor – An optional BaseAnchor instance from which attribute values will be copied. Defualts to None.

Returns:

The newly appended BaseAnchor instance.

Example:

>>> anchor = glyph.appendAnchor("top", (10, 20))
>>> anchor = glyph.appendAnchor("top", (10, 20), color=(1, 0, 0, 1))
BaseGlyph.removeAnchor(anchor: BaseAnchor | int) None[source]

Remove the given anchor from the glyph.

Parameters:

anchor – The anchor to remove as a BaseAnchor intance, or an int representing the anchor’s index.

Raises:

ValueError – If no anchor can be found at the given index.

Example:

>>> glyph.removeAnchor(anchor)
BaseGlyph.clearAnchors() None[source]

Clear all anchors in the glyph.

Example:

>>> glyph.clearAnchors()

Guidelines

BaseGlyph.guidelines: dynamicProperty

Get all guidelines in the glyph.

This property is read-only.

Returns:

A tuple of BaseGuideline instances.

Example:

>>> guidelines = glyph.guidelines
BaseGlyph.appendGuideline(position: CoordinateLike | None = None, angle: IntFloatType | None = None, name: str | None = None, color: RGBALike | None = None, guideline: BaseGuideline | None = None) BaseGuideline[source]

Append a guideline to the glyph.

If name, position or color are specified, those values will be used instead of the values in the given guideline object.

Parameters:
  • position – The optional x and y location to be applied to the guideline as a Coordinate. Defaults to None.

  • angle – The optional angle to be applied to the guideline as int or float. Defaults to None.

  • name – An optional name to be assigned to the guideline as a str. Defaults to None.

  • color – The optional color to be applied to the guideline as a Color. Defaults to None.

  • guideline – An optional BaseGuideline instance from which attribute values will be copied. Defualts to None.

Returns:

The newly appended BaseGuideline instance.

Example:

>>> anchor = glyph.appendGuideline("top", (10, 20))
>>> anchor = glyph.appendGuideline("top", (10, 20), color=(1, 0, 0, 1))
BaseGlyph.removeGuideline(guideline: BaseGuideline | int) None[source]

Remove the given guideline from the glyph.

Parameters:

guideline – The guideline to remove as a BaseGuideline intance, or an int representing the guideline’s index.

Raises:

ValueError – If no guideline can be found at the given index.

Example:

>>> glyph.removeGuideline(guideline)
BaseGlyph.clearGuidelines() None[source]

Clear all guidelines in the glyph.

Example:

>>> glyph.clearGuidelines()

Image

BaseGlyph.image: dynamicProperty

Get the image for the glyph.

This property is read-only.

Returns:

The BaseImage instance belonging to the glyph.

BaseGlyph.addImage(path: str | None = None, data: bytes | None = None, scale: ScaleFactorLike | None = None, position: CoordinateLike | None = None, color: RGBALike | None = None) BaseImage[source]

Set the image in the glyph.

The image data may be provided as either the path to an image file or directly as raw image data. The supported image formats will vary across environments. Refer to BaseImage for complete details.

Parameters:
  • path – The optional path to the image file to add to the glyph as a str. Defaults to None.

  • data – The optional raw image data to add to the glyph as bytes. Defaults to None.

  • scale – The optional x and y values to scale the glyph by as a tuple of two int or float values. Defaults to None.

  • position – The optional location of the lower left point of the image as a Coordinate. Defaults to None.

  • color – The optional color to be applied to the image as a Color. Defaults to None.

Returns:

The BaseImage instance added to the glyph.

Raises:
  • IOError – If no valid image file can be found at the given path.

  • FontPartsError – If path and data are both provided.

Add the image as a filepath:

>>> image = glyph.addImage(path="/path/to/my/image.png")

Add the image as raw data:

>>> image = glyph.addImage(data=someImageData)

Add the image with scale:

>>> image = glyph.addImage(path="/p/t/image.png", scale=(0.5, 1.0))

Add the image with position:

>>> image = glyph.addImage(path="/p/t/image.png", position=(10, 20))

Add the image with color:

>>> image = glyph.addImage(path="/p/t/image.png", color=(1, 0, 0, 0.5))
BaseGlyph.clearImage() None[source]

Remove the image from the glyph.

Example:

>>> glyph.clearImage()

Note

BaseGlyph.note: dynamicProperty

Get or set the glyph’s note.

The value must be a str or None.

Returns:

A str, or None representing an empty note.

Example:

>>> glyph.note
"P.B. said this looks 'awesome.'"
>>> glyph.note = "P.B. said this looks 'AWESOME.'"
BaseGlyph.markColor: dynamicProperty

Get or set the glyph’s mark color.

The value must be either a Color or None. :return: The Color instance assigned to the glyph, or None if

no color has been assigned.

Example:

>>> glyph.markColor
(1, 0, 0, 0.5)
>>> glyph.markColor = None

Sub-Objects

BaseGlyph.lib: dynamicProperty

Get the font’s lib object.

This property is read-only.

Returns:

An instance of the BaseLib class.

Example:

>>> lib = glyph.lib

Transformations

BaseGlyph.transformBy(matrix: list[int | float] | tuple[float, float, float, float, float, float], origin: list[int | float] | tuple[int | float, int | float] | None = None) None

Transform the object according to the given matrix.

Parameters:
  • matrix – The Transformation Matrix to apply.

  • origin – The optional point at which the transformation should originate as a:ref:type-coordinate. Defaults to None, representing an origin of (0, 0).

Example:

>>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0))
>>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0), origin=(500, 500))
BaseGlyph.moveBy(value: list[int | float] | tuple[int | float, int | float]) None

Move the object according to the given coordinates.

Parameters:

value – The x and y values to move the object by as a Coordinate.

Example:

>>> obj.moveBy((10, 0))
BaseGlyph.scaleBy(value: int | float | list[int | float] | tuple[float, float], origin: list[int | float] | tuple[int | float, int | float] | None = None, width: bool = False, height: bool = False) None[source]

Scale the glyph according to the given values.

Parameters:
  • value – The x and y values to scale the glyph by as a tuple of two int or float values.

  • origin – The optional point at which the scale should originate as a Coordinate. This must not be set when scaling the width or height. Defaults to None, representing an origin of (0, 0).

  • width – Whether the glyph’s width should be scaled. Defaults to False.

  • height – Whether the glyph’s height should be scaled. Defaults to False.

Raises:

FontPartsError – If the origin is specified while width or height are set to True.

Example:

>>> glyph.scaleBy(2.0)
>>> glyph.scaleBy((0.5, 2.0), origin=(500, 500))
BaseGlyph.rotateBy(value: int | float, origin: list[int | float] | tuple[int | float, int | float] | None = None) None

Rotate the object by the specified value.

Parameters:
  • value – The angle at which to rotate the object as an int or a float.

  • origin – The optional point at which the rotation should originate as a Coordinate. Defaults to None, representing an origin of (0, 0).

Example:

>>> obj.rotateBy(45)
>>> obj.rotateBy(45, origin=(500, 500))
BaseGlyph.skewBy(value: int | float | list[int | float] | tuple[float, float], origin: list[int | float] | tuple[int | float, int | float] | None = None) None

Skew the object by the given value.

Parameters:
  • value – The value by which to skew the object as either a single int or float corresponding to the x direction, or a tuple of two int or float values corresponding to the x and y directions.

  • origin – The optional point at which the rotation should originate as a Coordinate. Defaults to None, representing an origin of (0, 0).

Example:

>>> obj.skewBy(11)
>>> obj.skewBy((25, 10), origin=(500, 500))

Interpolation

BaseGlyph.isCompatible(other: BaseGlyph, cls=None) tuple[bool, GlyphCompatibilityReporter][source]

Evaluate interpolation compatibility with another glyph.

Parameters:

other – The other BaseGlyph instance to check compatibility with.

Returns:

A tuple where the first element is a bool indicating compatibility, and the second element is a fontParts.base.compatibility.GlyphCompatibilityReporter instance.

BaseGlyph.interpolate(factor: int | float | list[int | float] | tuple[float, float], minGlyph: BaseGlyph, maxGlyph: BaseGlyph, round: bool = True, suppressError: bool = True) None[source]

Interpolate all possible data in the glyph.

Parameters:
  • factor – The interpolation value as a single int or float or a tuple of two int or float values representing the factors (x, y).

  • minGlyph – The BaseGlyph instance corresponding to the 0.0 position in the interpolation.

  • maxGlyph – The BaseGlyph instance corresponding to the 1.0 position in the interpolation.

  • round – A bool indicating whether the result should be rounded to integers. Defaults to True.

  • suppressError – A bool indicating whether to ignore incompatible data or raise an error when such incompatibilities are found. Defaults to True.

Raises:

TypeError – If minGlyph or maxGlyph are not instances of BaseGlyph.

Example:

>>> glyph.interpolate(0.5, otherGlyph1, otherGlyph2)
>>> glyph.interpolate((0.5, 2.0), otherGlyph1, otherGlyph2, round=False)

Normalization

BaseGlyph.round() None[source]

Round coordinates in the glyph to the nearest integer.

This applies to:

Example:

>>> glyph.round()
BaseGlyph.autoUnicodes() None[source]

Use heuristics to set the Unicode values in the glyph.

Environments will define their own heuristics for automatically determining values.

Example:

>>> glyph.autoUnicodes()

Environment

BaseGlyph.naked() Any

Return the environment’s native object wrapped by the current object.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Example:

>>> loweLevelObj = obj.naked()
BaseGlyph.changed(*args: Any, **kwargs: Any) None

Tell the environment that something has changed in the object.

The behavior of this method will vary from environment to environment.

Parameters:
  • *args – Any positional arguments.

  • **kwargs – Any keyword arguments.

Example:

>>> obj.changed()