Contour

See also

Notifications:
The Contour object uses notifications to notify observers of changes.

Tasks

Changed State

Parent

  • getParent()
  • setParent()

Contour

class defcon.Contour(glyph=None, pointClass=None)

This object represents a contour and it contains a list of points.

This object posts the following notifications:

  • Contour.Changed
  • Contour.WindingDirectionChanged
  • Contour.PointsChanged
  • Contour.IdentifierChanged

The Contour object has list like behavior. This behavior allows you to interact with point data directly. For example, to get a particular point:

point = contour[0]

To iterate over all points:

for point in contour:

To get the number of points:

pointCount = len(contour)

To interact with components or anchors in a similar way, use the components and anchors attributes.

addObserver(observer, methodName, notification)

Add an observer to this object’s notification dispatcher.

  • observer An object that can be referenced with weakref.
  • methodName A string representing the method to be called when the notification is posted.
  • notification The notification that the observer should be notified of.

The method that will be called as a result of the action must accept a single notification argument. This will be a defcon.tools.notifications.Notification object.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.addObserver(observer=observer, methodName=methodName,
    notification=notification, observable=anObject)
addPoint(values, segmentType=None, smooth=False, name=None, identifier=None, **kwargs)

Standard point pen addPoint method. This should not be used externally.

appendPoint(point)

Append point to the glyph. The point must be a defcon Point object or a subclass of that object. An error will be raised if the point’s identifier conflicts with any of the identifiers within the glyph.

This will post Contour.PointsChanged and Contour.Changed notifications.

area

The area of the contour’s outline.

beginPath(identifier=None)

Standard point pen beginPath method. This should not be used externally.

bounds

The bounds of the contour’s outline expressed as a tuple of form (xMin, yMin, xMax, yMax).

canRedo()

Returns a boolean indicating whether the undo manager is able to perform a redo.

canUndo()

Returns a boolean indicating whether the undo manager is able to perform an undo.

clear()

Clear the contents of the contour.

This posts Contour.PointsChanged and Contour.Changed notifications.

clockwise

A boolean representing if the contour has a clockwise direction. Setting this posts Contour.WindingDirectionChanged and Contour.Changed notifications.

contourInside(other, segmentLength=10)

Returns a boolean indicating if other is in the “black” area of the contour. This uses a flattened version of other’s curves to calculate the location of the curves within this contour. segmentLength defines the desired length for the flattening process. A lower value will yeild higher accuracy but will require more computation time.

controlPointBounds

The control bounds of all points in the contour. This only measures the point positions, it does not measure curves. So, curves without points at the extrema will not be properly measured.

destroyAllRepresentations(notification=None)

Destroy all representations.

destroyRepresentation(name, **kwargs)

Destroy the stored representation for name and **kwargs. If no kwargs are given, any representation with name will be destroyed regardless of the kwargs passed when the representation was created.

dirty

The dirty state of the object. True if the object has been changed. False if not. Setting this to True will cause the base changed notification to be posted. The object will automatically maintain this attribute and update it as you change the object.

disableNotifications(notification=None, observer=None)

Disable this object’s notifications until told to resume them.

  • notification The specific notification to disable. This is optional. If no notification is given, all notifications will be disabled.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.disableNotifications(
    observable=anObject, notification=notification, observer=observer)
dispatcher

The defcon.tools.notifications.NotificationCenter assigned to the parent of this object.

draw(pen)

Draw the contour with pen.

drawPoints(pointPen)

Draw the contour with pointPen.

enableNotifications(notification=None, observer=None)

Enable this object’s notifications.

  • notification The specific notification to enable. This is optional.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.enableNotifications(
    observable=anObject, notification=notification, observer=observer)
endPath()

Standard point pen endPath method. This should not be used externally.

font

The Font that this contour belongs to.

generateIdentifier()

Create a new, unique identifier for and assign it to the contour. This will post Contour.IdentifierChanged and Contour.Changed notifications.

generateIdentifierForPoint(point)

Create a new, unique identifier for and assign it to the point. This will post Contour.Changed notification.

getDataForSerialization(**kwargs)

Return a dict of data that can be pickled.

getRepresentation(name, **kwargs)

Get a representation. name must be a registered representation name. **kwargs will be passed to the appropriate representation factory.

glyph

The Glyph that this contour belongs to. This should not be set externally.

hasCachedRepresentation(name, **kwargs)

Returns a boolean indicating if a representation for name and **kwargs is cached in the object.

hasObserver(observer, notification)

Returns a boolean indicating is the observer is registered for notification.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.hasObserver(observer=observer,
    notification=notification, observable=anObject)
holdNotifications(notification=None, note=None)

Hold this object’s notifications until told to release them.

  • notification The specific notification to hold. This is optional. If no notification is given, all notifications will be held.
  • note An arbitrary string containing information about why the hold has been requested, the requester, etc. This is used for reference only.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.holdNotifications(
    observable=anObject, notification=notification, note=note)
identifier

The identifier. Setting this will post Contour.IdentifierChanged and Contour.Changed notifications.

identifiers

Set of identifiers for the glyph that this contour belongs to. This is primarily for internal use.

index(point)

Get the index for point.

insertPoint(index, point)

Insert point into the contour at index. The point must be a defcon Point object or a subclass of that object. An error will be raised if the points’s identifier conflicts with any of the identifiers within the glyph.

This will post Contour.PointsChanged and Contour.Changed notifications.

layer

The Layer that this contour belongs to.

layerSet

The LayerSet that this contour belongs to.

move(values)

Move all points in the contour by (x, y).

This will post Contour.PointsChanged and Contour.Changed notifications.

onCurvePoints

A list of all on curve points in the contour.

open

A boolean indicating if the contour is open or not.

pointClass

The class used for point.

pointInside(coordinates, evenOdd=False)

Returns a boolean indicating if (x, y) is in the “black” area of the contour.

positionForProspectivePointInsertionAtSegmentAndT(segmentIndex, t)

Get the precise coordinates and a boolean indicating if the point will be smooth for the given segmentIndex and t.

postNotification(notification, data=None)

Post a notification through this object’s notification dispatcher.

  • notification The name of the notification.
  • data Arbitrary data that will be stored in the Notification object.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.postNotification(
    notification=notification, observable=anObject, data=data)
redo()

Perform a redo if possible, or return. If redo is performed, this will post BaseObject.BeginRedo and BaseObject.EndRedo notifications.

releaseHeldNotifications(notification=None)

Release this object’s held notifications.

  • notification The specific notification to hold. This is optional.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.releaseHeldNotifications(
    observable=anObject, notification=notification)
removeObserver(observer, notification)

Remove an observer from this object’s notification dispatcher.

  • observer A registered object.
  • notification The notification that the observer was registered to be notified of.

This is a convenience method that does the same thing as:

dispatcher = anObject.dispatcher
dispatcher.removeObserver(observer=observer,
    notification=notification, observable=anObject)
removePoint(point)

Remove point from the contour.

This will post Contour.PointsChanged and Contour.Changed notifications.

removeSegment(segmentIndex, preserveCurve=False)

Remove the segment at segmentIndex. If preserveCurve is True, the contour will try to preserve the overall curve shape.

representationKeys()

Get a list of all representation keys that are currently cached.

reverse()

Reverse the direction of the contour. It’s important to note that the actual points stored in this object will be completely replaced by new points.

This will post Contour.WindingDirectionChanged, Contour.PointsChanged and Contour.Changed notifications.

segments

A list of all points in the contour organized into segments.

setDataFromSerialization(data)

Restore state from the provided data-dict.

setStartPoint(index)

Set the point at index as the first point in the contour. This point must be an on-curve point.

This will post Contour.PointsChanged and Contour.Changed notifications.

splitAndInsertPointAtSegmentAndT(segmentIndex, t)

Insert a point into the contour for the given segmentIndex and t.

This posts a Contour.Changed notification.

undo()

Perform an undo if possible, or return. If undo is performed, this will post BaseObject.BeginUndo and BaseObject.EndUndo notifications.

undoManager

The undo manager assigned to this object.