Segment

Description

A Contour object is a list of segments. A Segment is a list of points with some special attributes and methods.

Overview

Parents

BaseSegment.contour

Get or set the segment's parent contour object.

BaseSegment.glyph

Get the segment's parent glyph object.

BaseSegment.layer

Get the segment's parent layer object.

BaseSegment.font

Get the segment's parent font object.

Identification

BaseSegment.index

Get the index of the segment.

Attributes

BaseSegment.type

Get or set the segment's type.

BaseSegment.smooth

Get or set the segment's smooth state.

Points

BaseSegment.points

Get a list of all points in the segment.

BaseSegment.onCurve

Get the on-curve point in the segment.

BaseSegment.offCurve

Get the off-curve points in the segment.

Transformations

BaseSegment.transformBy

Transform the object according to the given matrix.

BaseSegment.moveBy

Move the object according to the given coordinates.

BaseSegment.scaleBy

Scale the object according to the given values.

BaseSegment.rotateBy

Rotate the object by the specified value.

BaseSegment.skewBy

Skew the object by the given value.

Normalization

BaseSegment.round

Round coordinates in all the segment's points.

Environment

BaseSegment.naked

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

BaseSegment.changed

Tell the environment that something has changed in the object.

Reference

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

Represent the basis for a segment object.

Parents

BaseSegment.contour: dynamicProperty

Get or set the segment’s parent contour object.

The value must be a BaseContour instance or None.

Returns:

The BaseContour instance containing the segment or None.

Raises:

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

Example:

>>> contour = segment.contour
BaseSegment.glyph: dynamicProperty

Get the segment’s parent glyph object.

This property is read-only.

The value must be a BaseGlyph instance or None.

Returns:

The BaseGlyph instance containing the segment or None.

Example:

>>> glyph = segment.glyph
BaseSegment.layer: dynamicProperty

Get the segment’s parent layer object.

This property is read-only.

Returns:

The BaseLayer instance containing the segemnt or None.

Example:

>>> layer = segment.layer
BaseSegment.font: dynamicProperty

Get the segment’s parent font object.

This property is read-only.

Returns:

The BaseFont instance containing the segment or None.

Example:

>>> font = segment.font

Identification

BaseSegment.index: dynamicProperty

Get the index of the segment.

This property is read-only.

Returns:

An int representing the segment’s index within an ordered list of the parent contour’s segments, or None if the segment does not belong to a contour.

Example:

>>> segment.index
0

Attributes

BaseSegment.type: dynamicProperty

Get or set the segment’s type.

The value must be a str containing one of the following alternatives:

Type

Description

'move' 'line' 'curve' 'qcurve'

An on-curve move to. An on-curve line to. An on-curve cubic curve to. An on-curve quadratic curve to.

Returns:

A str representing the type of the segment.

BaseSegment.smooth: dynamicProperty

Get or set the segment’s smooth state.

The value must be a bool indicating the segment’s smooth state.

Returns:

True if the segment is smooth, False if it is sharp.

Example:

>>> segment.smooth
False
>>> segment.smooth = True

Points

BaseSegment.points: dynamicProperty

Get a list of all points in the segment.

This attribute is read-only.

Returns:

A tuple of :class`BasePoint` instances.

BaseSegment.onCurve: dynamicProperty

Get the on-curve point in the segment.

This property is read-only.

Returns:

An on-curve BasePoint instance or None.

BaseSegment.offCurve: dynamicProperty

Get the off-curve points in the segment.

This property is read-only.

Returns:

An off-curve BasePoint instance or None.

Transformations

BaseSegment.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))
BaseSegment.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))
BaseSegment.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))
BaseSegment.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))
BaseSegment.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

BaseSegment.round() None[source]

Round coordinates in all the segment’s points.

Environment

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