Glyph

See also

Notifications:
The Glyph object uses notifications to notify observers of changes.
Representations:
The Glyph object can maintain representations of various arbitrary types.

Tasks

Name and Unicodes

Reference Data

General Editing

Hit Testing

Changed State

Parent

Glyph

class defcon.Glyph(contourClass=None, pointClass=None, componentClass=None, anchorClass=None, libClass=None)

This object represents a glyph and it contains contour, component, anchor and other assorted bits data about the glyph.

This object posts the following notifications:

Name Note
Glyph.Changed Posted when the dirty attribute is set.
Glyph.NameChanged Posted after the reloadGlyphs method has been called.
Glyph.UnicodesChanged Posted after the reloadGlyphs method has been called.

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

contour = glyph[0]

To iterate over all contours:

for contour in glyph:

To get the number of contours:

contourCount = len(glyph)

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

dispatcher

The NotificationCenter object assigned to the glyph.

contourClass

The class used for contours.

pointClass

The class used for points.

componentClass

The class used for components.

anchorClass

The class used for anchors.

name

The name of the glyph. Setting this posts a Glyph.NameChanged notification.

unicodes

The list of unicode values assigned to the glyph. Setting this posts Glyph.UnicodesChanged and Glyph.Changed notifications.

unicode

The primary unicode value for the glyph. This is the equivalent of glyph.unicodes[0]. This is a convenience attribute that works with the unicodes attribute.

bounds

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

controlPointBounds

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

leftMargin

The left margin of the glyph. Setting this posts a Glyph.Changed notification.

rightMargin

The right margin of the glyph. Setting this posts a Glyph.Changed notification.

width

The width of the glyph. Setting this posts a Glyph.Changed notification.

components

An ordered list of Component objects stored in the glyph.

anchors

An ordered list of Anchor objects stored in the glyph.

note

An arbitrary note for the glyph. Setting this will post a Glyph.Changed notification.

lib

The glyph’s Lib object. Setting this will clear any existing lib data and post a Glyph.Changed notification if data was replaced.

draw(pen)

Draw the glyph with pen.

drawPoints(pointPen)

Draw the glyph with pointPen.

getPen()

Get the pen used to draw into this glyph.

getPointPen()

Get the point pen used to draw into this glyph.

appendContour(contour)

Append contour to the glyph. The contour must be a defcon Contour object or a subclass of that object.

This will post a Glyph.Changed notification.

appendComponent(component)

Append component to the glyph. The component must be a defcon Component object or a subclass of that object.

This will post a Glyph.Changed notification.

appendAnchor(anchor)

Append anchor to the glyph. The anchor must be a defcon Anchor object or a subclass of that object.

This will post a Glyph.Changed notification.

insertContour(index, contour)

Insert contour into the glyph at index. The contour must be a defcon Contour object or a subclass of that object.

This will post a Glyph.Changed notification.

insertComponent(index, component)

Insert component into the glyph at index. The component must be a defcon Component object or a subclass of that object.

This will post a Glyph.Changed notification.

insertAnchor(index, anchor)

Insert anchor into the glyph at index. The anchor must be a defcon Anchor object or a subclass of that object.

This will post a Glyph.Changed notification.

removeContour(contour)

Remove contour from the glyph.

This will post a Glyph.Changed notification.

removeComponent(component)

Remove component from the glyph.

This will post a Glyph.Changed notification.

removeAnchor(anchor)

Remove anchor from the glyph.

This will post a Glyph.Changed notification.

contourIndex(contour)

Get the index for contour.

componentIndex(component)

Get the index for component.

anchorIndex(anchor)

Get the index for anchor.

clear()

Clear all contours, components and anchors from the glyph.

This posts a Glyph.Changed notification.

clearContours()

Clear all contours from the glyph.

This posts a Glyph.Changed notification.

clearComponents()

Clear all components from the glyph.

This posts a Glyph.Changed notification.

clearAnchors()

Clear all anchors from the glyph.

This posts a Glyph.Changed notification.

move((x, y))

Move all contours, components and anchors in the glyph by (x, y).

This posts a Glyph.Changed notification.

pointInside((x, y), evenOdd=False)

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

representationKeys()

Get a list of all representation keys that have been called within this object.

destroyRepresentation(name, **kwargs)

Destroy the stored representation for name and **kwargs.

destroyAllRepresentations(notification=None)

Destroy all representations.

getRepresentation(name, **kwargs)

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

hasCachedRepresentation(name, **kwargs)

Returns a boolean indicating if a representation for name and **kwargs is cahced in the glyph.

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 epresenting 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)
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)
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)
getParent()

Get the parent. Returns None if no parent is set. Note that because the reference to the parent is stored as a weakref, the parent can disappear if it is no longer referenced by any object other than this one.

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)

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.

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

dispatcher = anObject.dispatcher
dispatcher.holdNotifications(
    observable=anObject, notification=notification)
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)
setParent(obj)

Set the parent of the object. This will reference the parent using weakref.

undoManager

The undo manager assigned to this object.