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¶
Get or set the component's parent glyph object. |
|
Get the component's parent layer object. |
|
Get the component's parent font object. |
Copy¶
Copy the current object into a new object of the same type. |
Identification¶
Get the object's unique identifier. |
|
Get or set the index of the contour. |
Attributes¶
Get or set the name of the glyph referenced by the component. |
|
Get or set the component's transformation matrix. |
|
Get or set the component's offset. |
|
Get or set the component's scale. |
Queries¶
Get the bounds of the component. |
|
Check if point lies inside the filled area of the component. |
Pens and Drawing¶
Draw the component with the given pen. |
|
Draw the component with the given point pen. |
Transformations¶
Transform the object according to the given matrix. |
|
Move the object according to the given coordinates. |
|
Scale the object according to the given values. |
|
Rotate the object by the specified value. |
|
Skew the object by the given value. |
Normalization¶
Decompose the component. |
|
Round the compnent's offset coordinates. |
Environment¶
Return the environment's native object wrapped by the current object. |
|
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
BaseGlyphinstance orNone.- Returns:
- 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.
Example:
>>> layer = component.layer
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
BaseObjectsubclass instance with the same attributes.
Identification¶
- BaseComponent.identifier¶
Get the object’s unique identifier.
This attribute is read-only. Use
IdentifierMixin.getIdentifierto request an identifier if it does not exist.- Returns:
The unique identifier assigned to the object as a
str, orNoneindicating the object has no identifier.
Example
>>> object.identifier 'ILHGJlygfds'
Attributes¶
- BaseComponent.baseGlyph: dynamicProperty¶
Get or set the name of the glyph referenced by the component.
The value must be a
str.- Returns:
A
strrepresenting the name of the base glyph, orNoneif 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.
Queries¶
- BaseComponent.bounds: dynamicProperty¶
Get the bounds of the component.
This property is read-only.
- Returns:
A
tupleof fourintorfloatvalues in the form(x minimum, y minimum, x maximum, y maximum)representing the bounds of the component, orNoneif 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:
Trueif point is inside the filled area of the glyph,Falseotherwise.
Example:
>>> glyph.pointInside((40, 65)) True
Pens and Drawing¶
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:
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
intor afloat.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
intorfloatcorresponding to the x direction, or atupleof twointorfloatvalues 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¶
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()