Layer

Note

This section needs to contain the following:

  • description of what this is
  • sub-object with basic usage
  • glyph interaction with basic usage

Overview

Copy

BaseLayer.copy Copy the layer into a new layer that does not belong to a font.

Parents

BaseLayer.font The layer’s parent BaseFont.

Attributes

BaseLayer.name The name of the layer.
BaseLayer.color The layer’s color.

Sub-Objects

BaseLayer.lib The layer’s BaseLib object.

Glyphs

BaseLayer.__len__ An int representing number of glyphs in the layer.
BaseLayer.keys Get a list of all glyphs in the layer.
BaseLayer.__iter__ Iterate through the BaseGlyph objects in the layer.
BaseLayer.__contains__ Test if the layer contains a glyph with name.
BaseLayer.__getitem__ Get the BaseGlyph with name from the layer.
BaseLayer.newGlyph Make a new glyph with name in the layer.
BaseLayer.insertGlyph Insert glyph into the layer.
BaseLayer.removeGlyph Remove the glyph with name from the layer.

Interpolation

BaseLayer.isCompatible Evaluate interpolation compatibility with other.
BaseLayer.interpolate Interpolate all possible data in the layer.

Normalization

BaseLayer.round Round all approriate data to integers.
BaseLayer.autoUnicodes Use heuristics to set Unicode values in all glyphs.

Environment

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

Reference

class fontParts.base.BaseLayer(*args, **kwargs)

Copy

BaseLayer.copy()

Copy the layer into a new layer that does not belong to a font.

>>> copiedLayer = layer.copy()

This will copy:

  • name
  • color
  • lib
  • glyphs

Parents

BaseLayer.font

The layer’s parent BaseFont.

>>> font = layer.font

Attributes

BaseLayer.name

The name of the layer.

>>> layer.name
"foreground"
>>> layer.name = "top"
BaseLayer.color

The layer’s color.

>>> layer.color
None
>>> layer.color = (1, 0, 0, 0.5)

Sub-Objects

BaseLayer.lib

The layer’s BaseLib object.

>>> layer.lib["org.robofab.hello"]
"world"

Glyphs

BaseLayer.__len__()

An int representing number of glyphs in the layer.

>>> len(layer)
256
BaseLayer.keys()

Get a list of all glyphs in the layer.

>>> layer.keys()
["B", "C", "A"]

The order of the glyphs is undefined.

BaseLayer.__iter__()

Iterate through the BaseGlyph objects in the layer.

>>> for glyph in layer:
...     glyph.name
"A"
"B"
"C"
BaseLayer.__contains__(name)

Test if the layer contains a glyph with name.

>>> "A" in layer
True
BaseLayer.__getitem__(name)

Get the BaseGlyph with name from the layer.

>>> glyph = layer["A"]
BaseLayer.newGlyph(name)

Make a new glyph with name in the layer.

>>> glyph = layer.newGlyph("A")

The newly created BaseGlyph will be returned.

BaseLayer.insertGlyph(glyph, name=None)

Insert glyph into the layer.

>>> glyph = layer.insertGlyph(otherGlyph, name="A")

This does not necessarily insert the glyph directly. In many cases, the environment will create a new glyph and copy the data from glyph to the new glyph. name indicates the name that should be assigned to the glyph after insertion. If name is not given, the glyph’s original name must be used. If the glyph does not have a name, an error must be raised. The data that will be inserted from glyph is the same data as documented in BaseGlyph.copy.

BaseLayer.removeGlyph(name)

Remove the glyph with name from the layer.

>>> layer.removeGlyph("A")

Interpolation

BaseLayer.isCompatible(other)

Evaluate interpolation compatibility with other.

>>> compat, report = self.isCompatible(otherLayer)
>>> compat
False
>>> report
A
-
[Fatal] The glyphs do not contain the same number of contours.

This will return a bool indicating if the layer is compatible for interpolation with other and a String of compatibility notes.

BaseLayer.interpolate(factor, minLayer, maxLayer, round=True, suppressError=True)

Interpolate all possible data in the layer.

>>> layer.interpolate(0.5, otherLayer1, otherLayer2)
>>> layer.interpolate((0.5, 2.0), otherLayer1, otherLayer2, round=False)

The interpolation occurs on a 0 to 1.0 range where minLayer is located at 0 and maxLayer is located at 1.0. factor is the interpolation value. It may be less than 0 and greater than 1.0. It may be a Integer/Float or a tuple of two Integer/Float. If it is a tuple, the first number indicates the x factor and the second number indicates the y factor. round indicates if the result should be rounded to integers. suppressError indicates if incompatible data should be ignored or if an error should be raised when such incompatibilities are found.

Normalization

BaseLayer.round()

Round all approriate data to integers.

>>> layer.round()

This is the equivalent of calling the round method on:

  • all glyphs in the layer
BaseLayer.autoUnicodes()

Use heuristics to set Unicode values in all glyphs.

>>> layer.autoUnicodes()

Environments will define their own heuristics for automatically determining values.

Environment

BaseLayer.naked()

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

>>> loweLevelObj = obj.naked()
BaseLayer.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()