Layer

Layer

class defcon.Layer(layerSet=None, glyphSet=None, libClass=None, unicodeDataClass=None, guidelineClass=None, glyphClass=None, glyphContourClass=None, glyphPointClass=None, glyphComponentClass=None, glyphAnchorClass=None, glyphImageClass=None)

This object represents a layer in a LayerSet.

This object posts the following notifications:

  • Layer.Changed
  • Layer.GlyphsChanged
  • Layer.GlyphChanged
  • Layer.GlyphWillBeAdded
  • Layer.GlyphAdded
  • Layer.GlyphWillBeDeleted
  • Layer.GlyphDeleted
  • Layer.GlyphNameChanged
  • Layer.GlyphUnicodesChanged
  • Layer.NameChanged
  • Layer.ColorChanged
  • Layer.LibChanged

The Layer object has some dict like behavior. For example, to get a glyph:

glyph = layer["aGlyphName"]

To iterate over all glyphs:

for glyph in layer:

To get the number of glyphs:

glyphCount = len(layer)

To find out if a font contains a particular glyph:

exists = "aGlyphName" in layer

To remove a glyph:

del layer["aGlyphName"]
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)
bounds

The bounds of all glyphs in the layer. This can be an expensive operation.

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.

color

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

componentReferences

A dict of describing the component relationships in the layer. The dictionary is of form {base glyph : [references]}.

controlPointBounds

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

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.

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 layer belongs to.

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.

getSaveProgressBarTickCount(formatVersion)

Get the number of ticks that will be used by a progress bar in the save method. This method should not be called externally. Subclasses may override this method to implement custom saving behavior.

glyphsWithOutlines

A list of glyphs containing outlines.

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

A dict of describing the image file references in the layer. The dictionary is of form {image file name : [references]}.

insertGlyph(glyph, name=None)

Insert glyph into the layer. Optionally, the glyph can be renamed at the same time by providing name. If a glyph with the glyph name, or the name provided as name, already exists, the existing glyph will be replaced with the new glyph.

This posts Layer.GlyphWillBeAdded, Layer.GlyphAdded and Layer.Changed notifications.

keys()

The names of all glyphs in the layer.

layerSet

The LayerSet that this layer belongs to.

lib

The layer’s Lib object.

loadGlyph(name)

Load a glyph from the glyph set. This should not be called externally, but subclasses may override it for custom behavior.

name

The name of the layer. Setting this posts Layer.NameChanged and Layer.Changed notifications.

newGlyph(name)

Create a new glyph with name. If a glyph with that name already exists, the existing glyph will be replaced with the new glyph.

This posts Layer.GlyphWillBeAdded, Layer.GlyphAdded and Layer.Changed notifications.

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)
reloadGlyphs(glyphNames)

Reload the glyphs. This should not be called externally.

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.

save(glyphSet, saveAs=False, progressBar=None)

Save the layer. This method should not be called externally. Subclasses may override this method to implement custom saving behavior.

saveGlyph(glyph, glyphSet, saveAs=False)

Save a glyph. This method should not be called externally. Subclasses may override this method to implement custom saving behavior.

setDataFromSerialization(data)

Restore state from the provided data-dict.

tempLib

The layer’s tempLib object.

testForExternalChanges(reader)

Test for external changes. This should not be called externally.

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.

unicodeData

The layer’s UnicodeData object.