Contour¶
Description¶
A Contour is a single path of any number of points. A Glyph usually consists of a couple of contours, and this is the object that represents each one. The Contour object offers access to the outline matter in various ways. The parent of Contour is usually Glyph.
Overview¶
Copy¶
Copy the current object into a new object of the same type. |
Parents¶
Get or set the contour's parent glyph object. |
|
Get the contour's parent layer object. |
|
Get the contour's parent font object. |
Identification¶
Get the object's unique identifier. |
|
Get or set the index of the contour. |
Winding Direction¶
Specify or determine whether the contour's winding direction is clockwise. |
|
Reverse the direction of the contour. |
Queries¶
Get the bounds of the contour. |
|
Check if point is within the filled area of the contour. |
Pens and Drawing¶
Draw the contour's outline data to the given pen. |
|
Draw the contour's outline data to the given point pen. |
Segments¶
Get the contour's segments. |
|
Return the number of segments in the contour. |
|
Return an iterator over the segments in the contour. |
|
Get the segment at the specified index. |
|
Append the given segment to the contour. |
|
Insert the given segment into the contour. |
|
Remove the given segment from the contour. |
|
Set the first segment in the contour. |
|
Automatically calculate and set the contour's first segment. |
bPoints¶
Get a list of all bPoints in the contour. |
|
Append the given bPoint to the contour. |
|
Insert the given bPoint into the contour. |
Points¶
Get a list of all points in the contour. |
|
Append the given point to the contour. |
|
Insert the given point into the contour. |
|
Remove the given point from the contour. |
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¶
Round all point coordinates in the contour to the nearest integer. |
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.BaseContour(*args: Any, **kwargs: Any)[source]¶
Represent the basis for a contour object.
- Variables:
segmentClass – A class representing contour segments. This will usually be a
BaseSegmentsubclass.bPointClass – A class representing contour bPoints. This will usually be a
BaseBPointsubclass.
Copy¶
- BaseContour.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.
Parents¶
- BaseContour.glyph: dynamicProperty¶
Get or set the contour’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 = contour.glyph
- BaseContour.layer: dynamicProperty¶
Get the contour’s parent layer object.
This property is read-only.
Example:
>>> layer = contour.layer
Identification¶
- BaseContour.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'
- BaseContour.index: dynamicProperty¶
Get or set the index of the contour.
The value must be an
int.- Returns:
An
intrepresenting the contour’s index within an ordered list of the parent glyph’s contours, orNoneif the contour does not belong to a glyph.- Raises:
FontPartsError – If the contour does not belong to a glyph.
Example:
>>> contour.index 1 >>> contour.index = 0
Winding Direction¶
Queries¶
- BaseContour.bounds: dynamicProperty¶
Get the bounds of the contour.
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 contour, orNoneif the contour is open.
Example:
>>> contour.bounds (10, 30, 765, 643)
- BaseContour.pointInside(point: list[int | float] | tuple[int | float, int | float]) bool[source]¶
Check if point is within the filled area of the contour.
- Parameters:
point – The point to check as a Coordinate.
- Returns:
Trueif point is inside the filled area of the contour,Falseotherwise.
Example:
>>> contour.pointInside((40, 65)) True
Pens and Drawing¶
Segments¶
- BaseContour.segments: dynamicProperty¶
Get the contour’s segments.
This property is read-only.
- Returns:
A
tupleofBaseSegmentinstances.
Example:
>>> contour.segments (<BaseSegment curve index='0' at 4573388368>, ...)
- BaseContour.__len__() int[source]¶
Return the number of segments in the contour.
- Returns:
An
intrepresenting the number ofBaseSegmentinstances belonging to the contour.
- BaseContour.__iter__() Iterator[BaseSegment][source]¶
Return an iterator over the segments in the contour.
- Returns:
An iterator over the
BaseSegmentinstances belonging to the contour.
- BaseContour.__getitem__(index: int) BaseSegment[source]¶
Get the segment at the specified index.
- Parameters:
index – The zero-based index of the point to retrieve as an
int.- Returns:
The
BaseSegmentinstance located at the specified index.- Raises:
IndexError – If the specified index is out of range.
- BaseContour.appendSegment(type: str | None = None, points: PointCollectionType | None = None, smooth: bool = False, segment: BaseSegment | None = None) None[source]¶
Append the given segment to the contour.
If type or points are specified, those values will be used instead of the values in the given segment object. The specified smooth state will be applied if
segment=None.- Parameters:
type – An optional
BaseSegment.typeto be applied to the segment as astr. Defaults toNone.points – The optional
BaseSegment.pointsto be applied to the segment as alistortupleof Coordinate items. Defaults toNone.smooth – The
BaseSegment.smoothstate to be applied to the segment as abool. Defaults toFalse.segment – An optional
BaseSegmentinstance from which attribute values will be copied. Defualts toNone.
- BaseContour.insertSegment(index: int, type: str | None = None, points: PointCollectionType | None = None, smooth: bool = False, segment: BaseSegment | None = None) None[source]¶
Insert the given segment into the contour.
If type or points are specified, those values will be used instead of the values in the given segment object. The specified smooth state will be applied if
segment=None.- Parameters:
index – The
BaseSegment.indexto be applied to the segment as aint.type – An optional
BaseSegment.typeto be applied to the segment as astr. Defaults toNone.points – The optional
BaseSegment.pointsto be applied to the segment as alistortupleof Coordinate items. Defaults toNone.smooth – The
BaseSegment.smoothstate to be applied to the segment as abool. Defaults toFalse.segment – An optional
BaseSegmentinstance from which attribute values will be copied. Defualts toNone.
- BaseContour.removeSegment(segment: BaseSegment | int, preserveCurve: bool = False) None[source]¶
Remove the given segment from the contour.
If
preserveCurve=True, an attempt will be made to preserve the overall shape of the curve after the segment is removed, provided the environment supports such functionality.- Parameters:
segment – The segment to remove as a
BaseSegmentinstance, or anintrepresenting the segment’s index.preserveCurve – A
boolindicating whether to preserve the curve’s shape after the segment is removed. Defaults toFalse.
- Raises:
ValueError – If the segment index is out of range or if the specified segment is not part of the contour.
Example:
>>> contour.removeSegment(mySegment) >>> contour.removeSegment(2, preserveCurve=True)
- BaseContour.setStartSegment(segment: BaseSegment | int) None[source]¶
Set the first segment in the contour.
- Parameters:
segment – The segment to set as the first instance in the contour as a
BaseSegmentinstance, or anintrepresenting the segment’s index.- Raises:
FontPartsError – If the contour is open.
ValueError – If the segment index is out of range or if the specified segment is not part of the contour.
Example:
>>> contour.setStartSegment(mySegment) >>> contour.setStartSegment(2)
bPoints¶
- BaseContour.bPoints: dynamicProperty¶
Get a list of all bPoints in the contour.
This property is read-only.
- Returns:
A
tupleof :class`BaseBPoints`.
- BaseContour.appendBPoint(type: str | None = None, anchor: CoordinateLike | None = None, bcpIn: CoordinateLike | None = None, bcpOut: CoordinateLike | None = None, bPoint: BaseBPoint | None = None) None[source]¶
Append the given bPoint to the contour.
If type, anchor, bcpIn or bcpOut are specified, those values will be used instead of the values in the given segment object.
- Parameters:
type – An optional
BaseBPoint.typeto be applied to the bPoint as astr. Defaults toNone.anchor – An optional
BaseBPoint.anchorto be applied to the bPoint as a Coordinate. Defaults toNone.bcpIn – An optional
BaseBPoint.bcpInto be applied to the bPoint as a Coordinate. Defaults toNone.bcpOut – An optional
BaseBPoint.bcpOutto be applied to the bPoint as a Coordinate. Defaults toNone.bPoint – An optional
BaseBPointinstance from which attribute values will be copied. Defualts toNone.
- BaseContour.insertBPoint(index: int, type: str | None = None, anchor: CoordinateLike | None = None, bcpIn: CoordinateLike | None = None, bcpOut: CoordinateLike | None = None, bPoint: BaseBPoint | None = None) None[source]¶
Insert the given bPoint into the contour.
If type, anchor, bcpIn or bcpOut are specified, those values will be used instead of the values in the given segment object.
- Parameters:
index – The
BaseBPoint.indexto be applied to the bPoint as anint.type – An optional
BaseBPoint.typeto be applied to the bPoint as astr. Defaults toNone.anchor – An optional
BaseBPoint.anchorto be applied to the bPoint as a Coordinate. Defaults toNone.bcpIn – An optional
BaseBPoint.bcpInto be applied to the bPoint as a Coordinate. Defaults toNone.bcpOut – An optional
BaseBPoint.bcpOutto be applied to the bPoint as a Coordinate. Defaults toNone.bPoint – An optional
BaseBPointinstance from which attribute values will be copied. Defualts toNone.
Points¶
- BaseContour.points: dynamicProperty¶
Get a list of all points in the contour.
This property is read-only.
- Returns:
A
tupleof :class`BasePoints`.
- BaseContour.appendPoint(position: CoordinateLike | None = None, type: str = 'line', smooth: bool = False, name: str | None = None, identifier: str | None = None, point: BasePoint | None = None) None[source]¶
Append the given point to the contour.
If position, type or name are specified, those values will be used instead of the values in the given segment object. The specified smooth state will be applied if
point=None.- Parameters:
position – An optional position to be applied to the point as a Coordinate. Defaults to
None.type – An optional
BasePoint.typeto be applied to the point as astr. Defaults to'line'.smooth – The
BasePoint.smoothstate to be applied to the point as abool. Defaults toFalse.name – An optional
BasePoint.nameto be applied to the point as astr. Defaults toNone.identifier – An optional
BasePoint.identifierto be applied to the point as astr. Defaults toNone.point – An optional
BasePointinstance from which attribute values will be copied. Defualts toNone.
- BaseContour.insertPoint(index: int, position: CoordinateLike | None = None, type: str = 'line', smooth: bool = False, name: str | None = None, identifier: str | None = None, point: BasePoint | None = None) None[source]¶
Insert the given point into the contour.
If position, type or name are specified, those values will be used instead of the values in the given segment object. The specified smooth state will be applied if
point=None.- Parameters:
index – The
BasePoint.indexto be applied to the point as anint.position – An optional position to be applied to the point as a Coordinate. Defaults to
None.type – An optional
BasePoint.typeto be applied to the point as astr. Defaults to'line'.smooth – The
BasePoint.smoothstate to be applied to the point as abool. Defaults toFalse.name – An optional
BasePoint.nameto be applied to the point as astr. Defaults toNone.identifier – An optional
BasePoint.identifierto be applied to the point as astr. Defaults toNone.point – An optional
BasePointinstance from which attribute values will be copied. Defualts toNone.
- BaseContour.removePoint(point: BasePoint | int, preserveCurve: bool = False) None[source]¶
Remove the given point from the contour.
If
preserveCurve=True, an attempt will be made to preserve the overall shape of the curve after the segment is removed, provided the environment supports such functionality.- Parameters:
- Raises:
ValueError – If the point index is out of range or if the specified point is not part of the contour.
Example:
>>> contour.removePoint(myPoint) >>> contour.removePoint(2, preserveCurve=True)
Transformations¶
- BaseContour.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))
- BaseContour.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))
- BaseContour.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))
- BaseContour.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))
- BaseContour.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¶
- BaseContour.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()