Component

Description

A component can be a part of a glyph, and it is a reference to another glyph in the same font. With components you can make glyphs depend on other glyphs. Changes to the base glyph will reflect in the component as well.

The parent of a component is usually a glyph. Components can be decomposed: they replace themselves with the actual outlines from the base glyph. When that happens, the link between the original and the component is broken: changes to the base glyph will no longer reflect in the glyph that had the component.

Overview

Parents

BaseComponent.glyph

Get or set the component's parent glyph object.

BaseComponent.layer

Get the component's parent layer object.

BaseComponent.font

Get the component's parent font object.

Copy

BaseComponent.copy

Copy the current object into a new object of the same type.

Identification

BaseComponent.identifier

Get the object's unique identifier.

BaseComponent.index

Get or set the index of the contour.

Attributes

BaseComponent.baseGlyph

Get or set the name of the glyph referenced by the component.

BaseComponent.transformation

Get or set the component's transformation matrix.

BaseComponent.offset

Get or set the component's offset.

BaseComponent.scale

Get or set the component's scale.

Queries

BaseComponent.bounds

Get the bounds of the component.

BaseComponent.pointInside

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

Pens and Drawing

BaseComponent.draw

Draw the component with the given pen.

BaseComponent.drawPoints

Draw the component with the given point pen.

Transformations

BaseComponent.transformBy

Transform the object according to the given matrix.

BaseComponent.moveBy

Move the object according to the given coordinates.

BaseComponent.scaleBy

Scale the object according to the given values.

BaseComponent.rotateBy

Rotate the object by the specified value.

BaseComponent.skewBy

Skew the object by the given value.

Normalization

BaseComponent.decompose

Decompose the component.

BaseComponent.round

Round the compnent's offset coordinates.

Environment

BaseComponent.naked

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

BaseComponent.changed

Tell the environment that something has changed in the object.

Reference

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

Represent the basis for a component object.

This object provides a reference to another glyph, allowing it to be inserted as part of an outline.

Parents

BaseComponent.glyph: dynamicProperty

Get or set the component’s parent glyph object.

The value must be a BaseGlyph instance or None.

Returns:

The BaseGlyph instance containing the component or None.

Raises:

AssertionError – If attempting to set the glyph when it has already been set.

Example:

>>> glyph = component.glyph
BaseComponent.layer: dynamicProperty

Get the component’s parent layer object.

This property is read-only.

Returns:

The BaseLayer instance containing the component or None.

Example:

>>> layer = component.layer
BaseComponent.font: dynamicProperty

Get the component’s parent font object.

This property is read-only.

Returns:

The BaseFont instance containing the component or None.

Example:

>>> font = component.font

Copy

BaseComponent.copy() BaseObjectType

Copy the current object into a new object of the same type.

The returned object will not have a parent object.

Returns:

A new BaseObject subclass instance with the same attributes.

Identification

BaseComponent.identifier

Get the object’s unique identifier.

This attribute is read-only. Use IdentifierMixin.getIdentifier to request an identifier if it does not exist.

Returns:

The unique identifier assigned to the object as a str, or None indicating the object has no identifier.

Example

>>> object.identifier
'ILHGJlygfds'
BaseComponent.index: dynamicProperty

Get or set the index of the contour.

The value must be an int

Returns:

An int representing the index of the component within the ordered list of parent glyph’s components, or None if the component does not belong to a glyph.

Raises:

FontPartsError – If attempting to set the index while the component does not belong to a glyph.

Attributes

BaseComponent.baseGlyph: dynamicProperty

Get or set the name of the glyph referenced by the component.

The value must be a str.

Returns:

A str representing the name of the base glyph, or None if the component does not belong to a layer.

Raises:

ValueError – If value is None when the component is part of a layer.

BaseComponent.transformation: dynamicProperty

Get or set the component’s transformation matrix.

The value must be a Transformation Matrix.

Returns:

A Transformation Matrix value representing the transformation matrix of the component.

BaseComponent.offset: dynamicProperty

Get or set the component’s offset.

The value must be a Coordinate.

Returns:

A Coordinate representing the offset of the component.

BaseComponent.scale: dynamicProperty

Get or set the component’s scale.

The value must be a list or tuple of two int or float items representing the (x, y) scale of the component.

Returns:

A tuple of two float items representing the (x, y) scale of the component.

Queries

BaseComponent.bounds: dynamicProperty

Get the bounds of the component.

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 component, or None if the component is empty.

Example:

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

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

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

BaseComponent.draw(pen: AbstractPen) None[source]

Draw the component with the given pen.

Parameters:

pen – The fontTools.pens.basePen.AbstractPen with which to draw the componnet.

BaseComponent.drawPoints(pen: AbstractPointPen) None[source]

Draw the component with the given point pen.

Parameters:

pen – The fontTools.pens.pointPen.AbstractPointPen with which to draw the componnet.

Transformations

BaseComponent.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))
BaseComponent.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))
BaseComponent.scaleBy(value: int | float | list[int | float] | tuple[float, float], origin: list[int | float] | tuple[int | float, int | float] | None = None) None

Scale the object according to the given values.

Parameters:
  • value – The value to scale the glyph by as a single int or float, or a tuple or list of two int or float values representing the values (x, y).

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

Example:

>>> obj.scaleBy(2.0)
>>> obj.scaleBy((0.5, 2.0), origin=(500, 500))
BaseComponent.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))
BaseComponent.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))

Normalization

BaseComponent.decompose() None[source]

Decompose the component.

BaseComponent.round() None[source]

Round the compnent’s offset coordinates.

This applies to offset

Environment

BaseComponent.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()
BaseComponent.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()