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

BaseContour.copy Copy this object into a new object of the same type.

Parents

BaseContour.glyph The contour’s parent BaseGlyph.
BaseContour.layer The contour’s parent layer.
BaseContour.font The contour’s parent font.

Identification

BaseContour.identifier The unique identifier for the object.
BaseContour.index The index of the contour within the parent glyph’s contours.

Winding Direction

BaseContour.clockwise Boolean indicating if the contour’s winding direction is clockwise.
BaseContour.reverse Reverse the direction of the contour.

Queries

BaseContour.bounds The bounds of the contour: (xMin, yMin, xMax, yMax) or None.
BaseContour.pointInside Determine if point is in the black or white of the contour.

Pens and Drawing

BaseContour.draw Draw the contour’s outline data to the given type-pen.
BaseContour.drawPoints Draw the contour’s outline data to the given type-point-pen.

Segments

BaseContour.segments
BaseContour.__len__
BaseContour.__iter__
BaseContour.__getitem__
BaseContour.appendSegment Append a segment to the contour.
BaseContour.insertSegment Insert a segment into the contour.
BaseContour.removeSegment Remove segment from the contour.
BaseContour.setStartSegment Set the first segment on the contour.
BaseContour.autoStartSegment Automatically calculate and set the first segment in this contour.

bPoints

BaseContour.bPoints
BaseContour.appendBPoint Append a bPoint to the contour.
BaseContour.insertBPoint Insert a bPoint at index in the contour.

Points

BaseContour.points
BaseContour.appendPoint Append a point to the contour.
BaseContour.insertPoint Insert a point into the contour.
BaseContour.removePoint Remove the point from the contour.

Transformations

BaseContour.transformBy Transform the object.
BaseContour.moveBy Move the object.
BaseContour.scaleBy Scale the object.
BaseContour.rotateBy Rotate the object.
BaseContour.skewBy Skew the object.

Normalization

BaseContour.round Round coordinates in all points to integers.

Environment

BaseContour.naked Return the environment’s native object that has been wrapped by this object.
BaseContour.changed Tell the environment that something has changed in the object.

Reference

class fontParts.base.BaseContour(*args, **kwargs)[source]

Copy

BaseContour.copy()

Copy this object into a new object of the same type. The returned object will not have a parent object.

Parents

BaseContour.glyph

The contour’s parent BaseGlyph.

BaseContour.layer

The contour’s parent layer.

BaseContour.font

The contour’s parent font.

Identification

BaseContour.identifier

The unique identifier for the object. This value will be an Identifier or a None. This attribute is read only.

>>> object.identifier
'ILHGJlygfds'

To request an identifier if it does not exist use object.getIdentifier()

BaseContour.index

The index of the contour within the parent glyph’s contours.

>>> contour.index
1
>>> contour.index = 0

The value will always be a type-int.

Winding Direction

BaseContour.clockwise

Boolean indicating if the contour’s winding direction is clockwise.

BaseContour.reverse()[source]

Reverse the direction of the contour.

Queries

BaseContour.bounds

The bounds of the contour: (xMin, yMin, xMax, yMax) or None.

BaseContour.pointInside(point)[source]

Determine if point is in the black or white of the contour.

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

point must be a Coordinate.

Pens and Drawing

BaseContour.draw(pen)[source]

Draw the contour’s outline data to the given type-pen.

>>> contour.draw(pen)
BaseContour.drawPoints(pen)[source]

Draw the contour’s outline data to the given type-point-pen.

>>> contour.drawPoints(pointPen)

Segments

BaseContour.segments
BaseContour.__len__()[source]
BaseContour.__iter__()[source]
BaseContour.__getitem__(index)[source]
BaseContour.appendSegment(type=None, points=None, smooth=False, segment=None)[source]

Append a segment to the contour.

BaseContour.insertSegment(index, type=None, points=None, smooth=False, segment=None)[source]

Insert a segment into the contour.

BaseContour.removeSegment(segment, preserveCurve=False)[source]

Remove segment from the contour. If preserveCurve is set to True an attempt will be made to preserve the shape of the curve if the environment supports that functionality.

BaseContour.setStartSegment(segment)[source]

Set the first segment on the contour. segment can be a segment object or an index.

BaseContour.autoStartSegment()[source]

Automatically calculate and set the first segment in this contour.

The behavior of this may vary accross environments.

bPoints

BaseContour.bPoints
BaseContour.appendBPoint(type=None, anchor=None, bcpIn=None, bcpOut=None, bPoint=None)[source]

Append a bPoint to the contour.

BaseContour.insertBPoint(index, type=None, anchor=None, bcpIn=None, bcpOut=None, bPoint=None)[source]

Insert a bPoint at index in the contour.

Points

BaseContour.points
BaseContour.appendPoint(position=None, type='line', smooth=False, name=None, identifier=None, point=None)[source]

Append a point to the contour.

BaseContour.insertPoint(index, position=None, type='line', smooth=False, name=None, identifier=None, point=None)[source]

Insert a point into the contour.

BaseContour.removePoint(point, preserveCurve=False)[source]

Remove the point from the contour. point can be a point object or an index. If preserveCurve is set to True an attempt will be made to preserve the shape of the curve if the environment supports that functionality.

Transformations

BaseContour.transformBy(matrix, origin=None)

Transform the object.

>>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0))
>>> obj.transformBy((0.5, 0, 0, 2.0, 10, 0), origin=(500, 500))

matrix must be a Transformation Matrix. origin defines the point at with the transformation should originate. It must be a Coordinate or None. The default is (0, 0).

BaseContour.moveBy(value)

Move the object.

>>> obj.moveBy((10, 0))

value must be an iterable containing two Integer/Float values defining the x and y values to move the object by.

BaseContour.scaleBy(value, origin=None)

Scale the object.

>>> obj.scaleBy(2.0)
>>> obj.scaleBy((0.5, 2.0), origin=(500, 500))

value must be an iterable containing two Integer/Float values defining the x and y values to scale the object by. origin defines the point at with the scale should originate. It must be a Coordinate or None. The default is (0, 0).

BaseContour.rotateBy(value, origin=None)

Rotate the object.

>>> obj.rotateBy(45)
>>> obj.rotateBy(45, origin=(500, 500))

value must be a Integer/Float values defining the angle to rotate the object by. origin defines the point at with the rotation should originate. It must be a Coordinate or None. The default is (0, 0).

BaseContour.skewBy(value, origin=None)

Skew the object.

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

value must be rone of the following:

  • single Integer/Float indicating the value to skew the x direction by.
  • iterable cointaining type Integer/Float defining the values to skew the x and y directions by.

origin defines the point at with the skew should originate. It must be a Coordinate or None. The default is (0, 0).

Normalization

BaseContour.round()[source]

Round coordinates in all points to integers.

Environment

BaseContour.naked()

Return the environment’s native object that has been wrapped by this object.

>>> loweLevelObj = obj.naked()
BaseContour.changed(*args, **kwargs)

Tell the environment that something has changed in the object. The behavior of this method will vary from environment to environment.

>>> obj.changed()