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

General Editing

Hit Testing

Changed State

Parent

  • getParent()
  • setParent()

Glyph

class defcon.Glyph(layer=None, contourClass=None, pointClass=None, componentClass=None, anchorClass=None, guidelineClass=None, libClass=None, imageClass=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:

  • Glyph.Changed
  • Glyph.BeginUndo
  • Glyph.EndUndo
  • Glyph.BeginRedo
  • Glyph.EndRedo
  • Glyph.NameWillChange
  • Glyph.NameChanged
  • Glyph.UnicodesChanged
  • Glyph.WidthChanged
  • Glyph.HeightChanged
  • Glyph.LeftMarginWillChange
  • Glyph.LeftMarginDidChange
  • Glyph.RightMarginWillChange
  • Glyph.RightMarginDidChange
  • Glyph.TopMarginWillChange
  • Glyph.TopMarginDidChange
  • Glyph.BottomMarginWillChange
  • Glyph.BottomMarginDidChange
  • Glyph.NoteChanged
  • Glyph.LibChanged
  • Glyph.ImageChanged
  • Glyph.ImageWillBeCleared
  • Glyph.ImageCleared
  • Glyph.ContourWillBeAdded
  • Glyph.ContourWillBeDeleted
  • Glyph.ContoursChanged
  • Glyph.ComponentWillBeAdded
  • Glyph.ComponentWillBeDeleted
  • Glyph.ComponentsChanged
  • Glyph.AnchorWillBeAdded
  • Glyph.AnchorWillBeDeleted
  • Glyph.AnchorsChanged
  • Glyph.GuidelineWillBeAdded
  • Glyph.GuidelineWillBeDeleted
  • Glyph.GuidelinesChanged
  • Glyph.MarkColorChanged
  • Glyph.VerticalOriginChanged

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.

addObserver(observer, methodName, notification, identifier=None)

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.
  • identifier None or a string identifying the observation. There is no requirement that the string be unique. A reverse domain naming scheme is recommended, but there are no requirements for the structure of the string.

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, identifier=identifier)
anchorClass

The class used for anchors.

anchorIndex(anchor)

Get the index for anchor.

anchors

An ordered list of Anchor objects stored in the glyph.

appendAnchor(anchor)

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

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. An error will be raised if the component’s identifier conflicts with any of the identifiers within the glyph.

This will post a Glyph.Changed notification.

appendContour(contour)

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

This will post a Glyph.Changed notification.

appendGuideline(guideline)

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

This will post a Glyph.Changed notification.

area

The area of the glyph’s outline.

bottomMargin

The bottom margin of the glyph. Setting this posts Glyph.HeightChanged, Glyph.BottomMarginWillChange, Glyph.BottomMarginDidChange and Glyph.Changed notifications among others.

bounds

The bounds of the glyph’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 all contours, components, anchors and guidelines from the glyph.

This posts a Glyph.Changed notification.

clearAnchors()

Clear all anchors from the glyph.

This posts a Glyph.Changed notification.

clearComponents()

Clear all components from the glyph.

This posts a Glyph.Changed notification.

clearContours()

Clear all contours from the glyph.

This posts a Glyph.Changed notification.

clearGuidelines()

Clear all guidelines from the glyph.

This posts a Glyph.Changed notification.

componentClass

The class used for components.

componentIndex(component)

Get the index for component.

components

An ordered list of Component objects stored in the glyph.

contourClass

The class used for contours.

contourIndex(contour)

Get the index for contour.

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.

copyDataFromGlyph(glyph)

Copy data from glyph. This copies the following data:

width height unicodes note image contours components anchors guidelines lib ==========

The name attribute is purposefully omitted.

correctContourDirection(trueType=False, segmentLength=10)

Correct the direction of all contours in the glyph.

This posts a Glyph.Changed notification.

decomposeAllComponents()

Decompose all components in this glyph. This will preserve the identifiers in the incoming contours and points unless there is a conflict. In that case, the conflicting incoming identifier will be discarded.

This posts Glyph.ComponentsChanged, Glyph.ContoursChanged and Glyph.Changed notifications.

decomposeComponent(component)

Decompose component. This will preserve the identifiers in the incoming contours and points unless there is a conflict. In that case, the conflicting incoming identifier will be discarded.

This posts Glyph.ComponentsChanged, Glyph.ContoursChanged and Glyph.Changed notifications.

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 glyph with pen.

drawPoints(pointPen)

Draw the glyph 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)
findObservations(observer=None, notification=None, observable=None, identifier=None)

Find observations of this object matching the given arguments based on the values that were passed during addObserver. A value of None for any of these indicates that all should be considered to match the value. In the case of identifier, strings will be matched using fnmatch.fnmatchcase. The returned value will be a list of dictionaries with this format:

[
{
observer=<…> observable=<…> methodName=”…” notification=”…” identifier=”…”

}

]

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

dispatcher = anObject.dispatcher
dispatcher.findObservations(
    observer=observer, observable=anObject,
    notification=notification, identifier=identifier
)
font

The Font that this glyph belongs to.

getDataForSerialization(**kwargs)

Return a dict of data that can be pickled.

getPen()

Get the pen used to draw into this glyph.

getPointPen()

Get the point pen used to draw into this glyph.

getRepresentation(name, **kwargs)

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

guidelineClass

The class used for guidelines.

guidelineIndex(guideline)

Get the index for guideline.

guidelines

An ordered list of Guideline objects stored in the glyph. Setting this will post a Glyph.Changed notification along with any notifications posted by the Glyph.appendGuideline() and Glyph.clearGuidelines() methods.

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)
height

The height of the glyph. Setting this posts Glyph.HeightChanged and Glyph.Changed notifications.

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)
identifiers

Set of identifiers for the glyph. This is primarily for internal use.

image

The glyph’s Image object. Setting this posts Glyph.ImageChanged and Glyph.Changed notifications.

imageClass

The class used for the image.

insertAnchor(index, anchor)

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

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. An error will be raised if the component’s identifier conflicts with any of the identifiers within the glyph.

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. An error will be raised if the contour’s identifier or a point identifier conflicts with any of the identifiers within the glyph.

This will post a Glyph.Changed notification.

insertGuideline(index, guideline)

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

This will post a Glyph.Changed notification.

layer

The Layer that this glyph belongs to.

layerSet

The LayerSet that this glyph belongs to.

leftMargin

The left margin of the glyph. Setting this posts Glyph.WidthChanged, Glyph.LeftMarginWillChange, Glyph.LeftMarginDidChange and Glyph.Changed notifications among others.

lib

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

libClass

The class used for the lib.

markColor

The glyph’s mark color. When setting, the value can be a UFO color string, a sequence of (r, g, b, a) or a Color object. Setting this posts Glyph.MarkColorChanged and Glyph.Changed notifications.

move(values)

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

This posts a Glyph.Changed notification.

name

The name of the glyph. Setting this posts GLyph.NameChanged and Glyph.NameChanged notifications.

note

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

pointClass

The class used for points.

pointInside(coordinates, evenOdd=False)

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

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)
removeAnchor(anchor)

Remove anchor from the glyph.

This will post a Glyph.Changed notification.

removeComponent(component)

Remove component from the glyph.

This will post a Glyph.Changed notification.

removeContour(contour)

Remove contour from the glyph.

This will post a Glyph.Changed notification.

removeGuideline(guideline)

Remove guideline from the glyph.

This will post a Glyph.Changed 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)
representationKeys()

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

rightMargin

The right margin of the glyph. Setting this posts Glyph.WidthChanged, Glyph.RightMarginWillChange, Glyph.RightMarginDidChange and Glyph.Changed notifications among others.

setDataFromSerialization(data)

Restore state from the provided data-dict.

tempLib

The glyph’s tempLib object.

topMargin

The top margin of the glyph. Setting this posts Glyph.HeightChanged, Glyph.VerticalOriginChanged, Glyph.TopMarginWillChange, Glyph.TopMarginDidChange and Glyph.Changed notifications among others.

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.

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.

unicodes

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

verticalOrigin

The glyph’s vertical origin. Setting this posts Glyph.VerticalOriginChanged and Glyph.Changed notifications.

width

The width of the glyph. Setting this posts Glyph.WidthChanged and Glyph.Changed notifications.