Skip to content

fontlab.flLayer

flLayer

In FontLab, a layer is the container inside a glyph that holds the actual drawing for one master. If your font has a Light master and a Bold master, then every glyph has (at least) two layers — one for each master. The layer is where shapes live, where metrics are set, and where anchors and guidelines for that specific master are stored.

Inherits from flObject.

What is a Layer?

Think of layers as the per-master "slots" inside a glyph:

font
 └── glyph "A"
      ├── layer "Light"    ← shapes, metrics, anchors for the Light master
      ├── layer "Regular"  ← shapes, metrics, anchors for the Regular master
      └── layer "Bold"     ← shapes, metrics, anchors for the Bold master

Layer Types

Not every layer is a master. FontLab supports several layer types, each with a different role:

Layer type What it's for
Master layer (isMasterLayer = True) The real drawing layers that correspond to design-space masters. These are the layers that participate in interpolation.
Service layer (isService = True) Non-printing helper layers — for example a layer storing reference artwork or construction guides. They show up in the editor but don't export.
Mask layer (isMaskLayer = True) A special overlay layer for each master used during manual hinting and for storing reference outlines. Accessible via getMaskLayer().
Image layer (isImgLayer = True) A dedicated layer for raster image data attached to a glyph — typically a scan or reference image to draw on top of.
Body layer (isBodyLayer = True) The primary drawing layer for a glyph in simple (non-variable) fonts.
Auto layer (autoLayer = True) A layer whose content is generated automatically, usually by an interpolation recipe. You can read its content but manual edits may be overwritten.

What Lives on a Layer

A layer is not just outlines. It holds everything that can vary between masters:

  • Shapes — the contours and composite references that define the glyph drawing
  • Metrics — the advance width, left sidebearing (LSB), and right sidebearing (RSB)
  • Anchors — named attachment points used for mark positioning and component composition
  • Guidelines — per-glyph guidelines (as opposed to font-wide guidelines)
  • Stems and zones — PS hint stems and alignment zones for this master
  • TrueType hinting — the TTH command program for this master
  • A note — freeform text you can attach to this layer for editorial comments

Tutorial: Set Width of All "A" Glyphs Across All Masters

This script shows a real workflow: finding every glyph named "A" in the font, iterating over all its master layers, and setting a consistent advance width on each one.

import fontlab as fl
from fontlab import flLayer

font = fl.CurrentFont()

TARGET_GLYPH = "A"
NEW_WIDTH     = 620   # desired advance width in font units

glyph = font[TARGET_GLYPH]
if glyph is None:
    print(f"Glyph '{TARGET_GLYPH}' not found")
else:
    for layer in glyph.layers:
        # Only touch master layers — skip mask, service, and image layers
        if not layer.isMasterLayer:
            continue

        old_width = layer.advanceWidth
        layer.advanceWidth = NEW_WIDTH

        print(
            f"  [{layer.name}]  "
            f"width {old_width:.0f} → {NEW_WIDTH}"
        )

    glyph.changed()

fl.Update()
print("Done.")

Extending the same pattern to all glyphs in the font:

import fontlab as fl

font = fl.CurrentFont()

# Set all capital letters to a consistent side-bearing on the Regular master
REGULAR_MASTER = "Regular"
TARGET_LSB     = 70

for glyph in font.glyphs:
    if not glyph.name[0].isupper():
        continue

    for layer in glyph.layers:
        if layer.name != REGULAR_MASTER:
            continue
        if not layer.isMasterLayer:
            continue

        # Clear any expression so we can set a numeric value
        # Set a numeric LSB via the metrics expression string
        layer.resetMetricsLeft()
        layer.metricsLeft = str(TARGET_LSB)
        glyph.changed()

fl.Update()
print(f"Set LSB={TARGET_LSB} on all uppercase glyphs in '{REGULAR_MASTER}'.")

Common Patterns

Iterate only master layers

for layer in glyph.layers:
    if layer.isMasterLayer:
        print(f"{layer.name}: width={layer.advanceWidth}")

Read metrics in all masters

font  = fl.CurrentFont()
glyph = font["n"]

print(f"{'Master':<20} {'Width':>8} {'LSB':>8} {'RSB':>8}")
print("-" * 46)
for layer in glyph.layers:
    if layer.isMasterLayer:
        ib  = layer.inkBox()
        lsb = ib.x()
        rsb = layer.advanceWidth - (ib.x() + ib.width())
        print(f"{layer.name:<20} {layer.advanceWidth:>8.1f} {lsb:>8.1f} {rsb:>8.1f}")

Set a metrics expression (link LSB to another glyph)

# Link the 'n' glyph's LSB to the 'H' glyph on all master layers
for layer in font['n'].layers:
    if layer.isMasterLayer:
        layer.metricsLeft = "=H"
font['n'].changed()
fl.Update()

Add an anchor to all master layers

from PythonQt.QtCore import QPointF
from fontlab import flPinPoint
import fontlab as fl

font  = fl.CurrentFont()
glyph = font["a"]

for layer in glyph.layers:
    if not layer.isMasterLayer:
        continue
    # Remove existing "top" anchor if present, then add a new one
    existing = layer.findAnchor("top")
    if existing:
        layer.removeAnchor(existing)
    # Position the anchor at the bounding-box top center
    bb = layer.inkBox()
    x  = bb.x() + bb.width() / 2
    y  = bb.y() + bb.height()
    layer.createAnchor("top", QPointF(x, y), 0)

glyph.changed()
fl.Update()

Check interpolation compatibility across all masters

font   = fl.CurrentFont()
glyph  = font["g"]
layers = [l for l in glyph.layers if l.isMasterLayer]

reference = layers[0]
for layer in layers[1:]:
    ok = reference.isCompatible(layer, strong=True)
    status = "OK" if ok else "INCOMPATIBLE"
    print(f"  {reference.name} ↔ {layer.name}: {status}")

Leave an editorial note on a layer

for layer in glyph.layers:
    if layer.name == "Bold" and layer.isMasterLayer:
        layer.note = "Optical correction needed on right shoulder — see ticket #42"
        break

Count total nodes across all master layers

font  = fl.CurrentFont()
glyph = font["g"]

for layer in glyph.layers:
    if layer.isMasterLayer:
        n = layer.nodesCount()
        print(f"{layer.name}: {n} nodes")

Constructors: flLayer() flLayer(flObject) flLayer(flGlyph) flLayer('title')

Native bases: object

Captured native MRO: flLayer, object

Native new allocation evidence (not an init overload): (args, *kwargs) Create and return a new object. See help(type) for accurate signature.

Supplemental documentation: A drawing layer holding shapes, components and anchors. The captured declaration exposes getContours, name, shapes, components, anchors, advanceWidth, boundingBox and isService. Retrieve contours with getContours; the captured flLayer has no contours attribute.

Example::

layer = glyph.layers[0]
for contour in layer.getContours():
    for node in contour.nodes:
        print(node.x, node.y)

Source: FontLab Proteus API documentation

Source: generated/fontlab.py: flLayer captured declaration

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
__init__ function (self, /, *args: Any, **kwargs: Any) -> None Initialize self. (shared captured text)
addAnchor function (self, arg0: flPinPoint) -> Any Appends an already-constructed flPinPoint anchor to this layer.
addComponent function (self, *args: Any, **kwargs: Any) -> Any AddComponent(name or (name, QTransform)) creates a live component shape.
addShape function (self, arg0: flShape) -> flShape Appends the given shape to this layer and returns the added shape.
addShapes function (self, *args: Any, **kwargs: Any) -> Any Appends a list of shapes to this layer in one call.
advanceHeight attribute Any The vertical advance height, used when the font supports vertical writing modes.
advanceWidth attribute Any The horizontal advance width for this layer — the total space the glyph occupies from origin to the next glyph's origin.
anchors attribute Any All anchor pin-points on this layer.
appendGuidelines function (self, *args: Any, **kwargs: Any) -> Any Adds a list of guideline objects to this layer in one call.
applyTransform function (self, *args: Any, **kwargs: Any) -> Any Applies a geometric transformation to all shapes in this layer, permanently baking the transform into the node coordinates.
assignFgLayer function (self, arg0: fgLayer, doGuides: bool, doHints: bool, doAnchors: bool, doShapes: bool, doTTH: bool) -> Any Applies data from a fontgate layer to this layer, selectively importing guides, hints, anchors, shapes, and TrueType data based on the boolean flags.
assignStyle function (self, layer: flLayer) -> Any Copies display style settings (color, opacity, wireframe mode) from the given layer to this one.
autoLayer attribute Any When True, this layer's content is auto-generated (for example, by an interpolation recipe).
autohint function (self) -> bool Runs FontLab's automatic PostScript hint generator on this layer's outlines.
bindDependencies function (self) -> Any Rebuilds the internal dependency links between shapes and components.
boundingBox attribute Any The tight bounding box enclosing all shapes on this layer.
buildAuto function (self) -> bool Triggers generation of this layer's content from its recipe (if it is an auto layer).
changed function (self) -> Any (shared captured text)
checkInitHistoryState function (self, history_ix: int) -> Any (shared captured text)
checkTags function (glyph_tags: set[str], item_tags: str) -> bool Tests whether a set of glyph tags satisfies a tag-filter expression.
cleanEmptyShapes function (self) -> Any Deletes any shapes that have no contours or content.
clearAboveHistory function (self, history_ix: int) -> Any (shared captured text)
clearAnchors function (self) -> Any Removes all anchors from this layer at once.
clearAudit function (self) -> None Clears all recorded audit issues from this layer without re-running the checks.
clearComponents function (self) -> Any Removes all component (composite) shapes from this layer, leaving only drawn shapes.
clearFlag function (self, f: int) -> Any (shared captured text)
clearFlags function (self) -> Any (shared captured text)
clone function (self, *args: Any, **kwargs: Any) -> Any Clone the object (shared captured text)
cloneCustom function (self, *args: Any, **kwargs: Any) -> Any (flLayer, list(flObject)) cloneCustom(uint)
cloneObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
compare function (self, layer: flLayer, error: float) -> bool Compares this layer's geometry to another layer, returning True if they are equal within the given tolerance.
components attribute Any All composite/component shapes (references to other glyphs) on this layer, as name + transform pairs.
componentsCount attribute Any The number of component references on this layer.
compoundMakeSelected function (self, set_active: bool, process_all: bool) -> bool Decomposes the currently selected composite shapes into editable contours on this layer.
compoundMakeSelectedToShapes function (self, set_active: Any=...) -> bool Similar to compoundMakeSelected, but the decomposed result is returned as plain flShape objects rather than raw contours.
compoundReleaseSelected attribute Any True if there are selected composites that can be released (decomposed).
contourRect function (self) -> QRectF Returns a bounding rectangle around all contour data, including off-curve control points.
counterAnchors attribute Any The count of anchors on this layer.
createAnchor function (self, name: Any, p: QPointF, location: int) -> flPinPoint Creates a new named anchor at the given point and adds it to this layer.
createInstance function (*args: Any, **kwargs: Any) -> Any Native fontlab.flLayer.createInstance; argument details are not documented.
createObject function (*args: Any, **kwargs: Any) -> Any FlObject/Nothing createObject(int); (shared captured text)
currentHistoryState function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
deactivateAllShapes function (self) -> Any Exits per-shape edit mode for all shapes and returns to the layer-level selection state.
fillFgAnchors function (self, arg0: fgLayer) -> Any Exports this layer's anchor data into a fontgate layer object.
fillFgGuides function (self, arg0: fgLayer) -> Any Exports this layer's guideline data into a fontgate layer object.
findAnchor function (self, name: str) -> flPinPoint Searches the layer's anchors for one with the given name and returns it.
findNearestNode function (self, *args: Any, **kwargs: Any) -> Any Finds the node closest to the given canvas point, among nodes of the given type and within maxd units.
findNode function (self, *args: Any, **kwargs: Any) -> Any (flNode, QPointF)/Nothing findNode(string name)
flObjectFlags attribute dict (shared captured text)
flag function (self, f: int) -> Any (shared captured text)
getActiveComposite function (self) -> Any FlShape/Nothing getActiveComposite()
getActiveShape function (self, *args: Any, **kwargs: Any) -> Any (flShape, QTransform)/Nothing getActiveShape([bool = true])
getAuditInfo function (self) -> Any Returns a list of audit issue objects describing problems found on this layer — things like open contours, duplicate nodes, or incorrect path direction.
getContours function (self) -> Any Returns every contour from every shape in this layer as a flat list.
getImgLayer function (self, create: bool) -> flLayer Returns the image layer associated with this layer, creating it if create=True.
getMaskLayer function (self, create: bool) -> flLayer Returns the mask layer associated with this master layer.
getMasterPosition function (self) -> Any QMap<QString, double>/Nothing getMasterPosition()
getOwnerComposite function (self, *args: Any, **kwargs: Any) -> Any Given a sub-shape and a transform, finds the top-level composite that contains it.
getProperties function (self, *args: Any, **kwargs: Any) -> Any Get object's properties list (shared captured text)
getProperty function (self, *args: Any, **kwargs: Any) -> Any Get object property by 'key' or number (shared captured text)
getPropertyFloat function (self, *args: Any, **kwargs: Any) -> Any Get float object property by 'key' (shared captured text)
getPropertyInt function (self, *args: Any, **kwargs: Any) -> Any Get int object property by 'key' (shared captured text)
getSelected function (self, SelectionMode: Any) -> Any Returns contours (or parts of contours) that have selected nodes, filtered by the given selection mode.
getShapes function (self, shape_type: Any) -> Any Returns all shapes of the given type without removing them from the layer.
getTthCode function (self, fg_layer: fgLayer, itr: fgTTInterpreter) -> bool Compiles the TTH command list on this layer into executable bytecode and stores it in the given fontgate layer.
getTthData function (self, fg_layer: fgLayer, itr: fgTTInterpreter) -> Any Returns the compiled TrueType bytecode as a list of byte strings, or None if compilation fails.
getTthProgram function (self, itr: fgTTInterpreter) -> str Returns the TrueType hinting program for this layer as a human-readable text string.
glyph attribute Any The parent glyph that owns this layer.
goDown function (self, arg0: flShape) -> bool Moves the given shape one step lower in the z-order.
goUp function (self, arg0: flShape) -> bool Moves the given shape one step higher in the z-order.
guidelines attribute Any All glyph-level guidelines on this layer.
hasAdvanceHeight attribute Any True if a vertical advance height override is set.
hasAdvanceWidth attribute Any True if this layer has an advance width override set (as opposed to inheriting the font's default).
hasBody attribute Any True if this layer contains at least one drawn (non-component) shape.
hasChanges attribute Any (shared captured text)
hasComponents attribute Any True if this layer has at least one component (composite reference to another glyph).
hasComposites attribute Any True if this layer contains composite shapes (nested components).
hasFontAudit function (self) -> bool Returns True if any audit issues have been recorded for this layer.
hasGuides attribute Any True if this layer has at least one guideline.
hasHints attribute Any True if this layer has PostScript hint data.
hasHistoryState function (self, history_ix: int) -> Any (shared captured text)
hasHistoryStates attribute Any (shared captured text)
hasNote attribute Any True if a note text has been set on this layer.
hasShape function (self, arg0: flShape) -> bool Returns True if the given shape is currently part of this layer.
hasShapeData function (self, arg0: flShapeData) -> bool Returns True if the layer contains any shape that uses the given shared shape data object.
hasTTData attribute Any True if TrueType data is attached to this layer.
hasTTH attribute Any True if TrueType hinting commands are present on this layer.
haveActiveComposite attribute Any True if a composite shape is currently in the active/exploded editing state.
haveObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
haveSelected function (self, SelectionMode: Any) -> bool Returns True if there is any active selection matching the given selection mode.
hints2links function (self) -> bool Converts existing PostScript hint data on this layer into TrueType link commands.
historyStates function (self, accepted_state: bool) -> Any (shared captured text)
id attribute Any Object id (shared captured text)
independedAll function (self) -> Any (shared captured text)
initialHistoryState function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
inkBox function (self, tx: Any=...) -> QRectF Returns the bounding rectangle of all visible ink on this layer — the tightest box that encloses all the filled outlines.
insertShape function (self, index: int, shape: flShape) -> flShape Inserts a shape at a specific z-order position rather than appending it to the top.
instanceType function (*args: Any, **kwargs: Any) -> Any (shared captured text)
isActive attribute Any True when this is the glyph's currently active layer in the editor.
isAllSelected attribute Any True when all shapes and nodes in this layer are selected.
isBack function (self, arg0: flShape) -> bool Returns True if the given shape is at the very bottom of the z-order (rendered first, behind all others).
isBodyLayer attribute Any True for the main drawing layer of a glyph.
isChanged attribute Any (shared captured text)
isCompatible function (self, arg0: flLayer, strong: bool) -> bool Checks whether this layer is interpolation-compatible with the given layer.
isEqual function (self, arg0: flObject) -> Any (shared captured text)
isFront function (self, arg0: flShape) -> bool Returns True if the given shape is at the very top of the z-order (rendered last, in front of all others).
isImg attribute Any True if this layer contains image data (a raster scan or reference image).
isImgLayer attribute Any True if this is a dedicated image layer (as opposed to a drawing layer that happens to contain an image).
isLocked attribute Any When True, the layer is locked and cannot be edited in the UI.
isLockedI attribute Any The inherited lock state — True if this layer is locked either directly or because a parent is locked.
isMaskLayer attribute Any True if this is a mask layer.
isMasterLayer attribute Any True if this layer corresponds to a design-space master and participates in interpolation.
isNull attribute Any (shared captured text)
isPresent attribute Any (shared captured text)
isReleased attribute Any (shared captured text)
isService attribute Any When True, this is a service (non-printing) layer.
isServiceMA attribute Any True for service-with-masters layers — service layers that are associated with specific masters.
isValid attribute Any (shared captured text)
isVisible attribute Any Controls whether this layer is shown in the glyph editor.
isVisibleA attribute Any The accumulated (inherited) visibility — True only if both this layer and all its parent containers are visible.
isWireframe attribute Any When True, this layer is rendered in wireframe mode (outline only, no fill) in the editor.
killAuto function (self) -> Any Removes the auto-generated content from this layer, converting it back to a manually editable layer.
lib attribute Any An arbitrary metadata dictionary attached to this layer, compatible with UFO's lib concept.
mark attribute Any A numeric color mark used to visually flag this layer in the font window.
metricsLeft attribute Any The left sidebearing expression for this layer — a string like "=H" or "=@group_name" that links this glyph's LSB to another glyph or group.
metricsRight attribute Any The right sidebearing expression.
metricsWidth attribute Any The width expression.
name attribute Any Object name
nodesCount function (self) -> int Returns the total number of on-curve and off-curve nodes across all shapes and contours in this layer.
note attribute Any A freeform text note you can attach to this layer.
opacity attribute Any The display opacity of this layer in the editor, from 0.0 (invisible) to 1.0 (fully opaque).
prepareTransformationData function (self) -> Any Caches transformation geometry for this layer in preparation for a batch transform operation.
propertyNames function (self, *args: Any, **kwargs: Any) -> Any PropertyNames(): sorted snapshot of dynamic property keys (shared captured text)
recipe attribute Any The recipe string used to auto-build this layer's content.
refCnt attribute Any Object references count (shared captured text)
release function (self) -> Any (shared captured text)
remove function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
removeAllShapes function (self, shape_type: Any=...) -> Any Removes all shapes from the layer.
removeAnchor function (self, arg0: flPinPoint) -> Any Removes the given anchor from this layer.
removeChild function (self, arg0: flObject) -> Any (shared captured text)
removeGuides function (self, horizontal: bool, vertical: bool) -> bool Removes guidelines by orientation.
removeHints function (self, horizontal: bool, vertical: bool) -> bool Removes PS hints by direction.
removeShape function (self, recursive: Any=...) -> Any Removes the given shape from this layer.
reorderShapes function (self, *args: Any, **kwargs: Any) -> Any Reorders the layer's shapes by supplying a new sequence of shape IDs.
replaceShape function (self, old_shape: flShape, new_shape: flShape) -> Any Swaps old for new in place, preserving its position in the z-order.
resetInkBox function (self) -> Any Clears the cached ink bounding box, forcing it to be recalculated on the next access.
resetMetricsLeft function (self) -> Any Clears any left-sidebearing expression set on this layer, reverting to a plain numeric value.
resetMetricsRight function (self) -> Any Clears any right-sidebearing expression, reverting to a numeric RSB.
resetMetricsWidth function (self) -> Any Clears any width expression, reverting to a numeric advance width.
resetTransformationData function (self) -> Any Clears the cached transformation geometry.
restoreHistoryState function (self, history_ix: int) -> Any (shared captured text)
selectAll function (self) -> Any Selects all shapes and all nodes in this layer.
sendToBack function (self, arg0: flShape) -> bool Moves the given shape to the bottom of the z-order.
sendToFront function (self, arg0: flShape) -> bool Moves the given shape to the top of the z-order.
setActive function (self) -> Any Makes this layer the active layer for its parent glyph in the editor.
setActiveShape function (self, arg0: flShape) -> Any Marks a specific shape as the currently active (selected/edited) shape in the UI.
setAllShapesSelected function (self, bool: Any) -> Any Selects or deselects all shapes on this layer at once.
setFlag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
setGlyphComponents function (self, components: Any, width: Any, package: Any, colorize: Any, arg4: flags=0) -> Any SetGlyphComponents(components, width, package, colorize, flags=0) -> bool.
setProperty function (self, *args: Any, **kwargs: Any) -> Any Set object property by 'key' or number (shared captured text)
setPropertyFloat function (self, *args: Any, **kwargs: Any) -> Any Set float object property by 'key' (shared captured text)
setPropertyInt function (self, *args: Any, **kwargs: Any) -> Any Set int object property by 'key' (shared captured text)
setWireframeColorIx function (self, int: Any) -> Any Sets the wireframe display color for this layer using a color index from FontLab's color palette.
shapes attribute Any All shapes on this layer, in z-order from back to front.
shapesCount attribute Any The number of shapes on this layer.
sortShapes function (self) -> Any Re-sorts the layer's shape list according to FontLab's z-order rules.
tag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
takeShapes function (self, shape_type: Any) -> list[flShape] Removes all shapes of the given type from the layer and returns them as a list.
transferNames function (self, layer: flLayer) -> Any Copies the name and name-related metadata from the given layer to this one.
transferTTH function (self, arg0: flLayer) -> bool Copies all TrueType hinting commands from the given source layer to this layer.
transform attribute Any A layer-level geometric transform applied on top of all shape coordinates during display and export.
ttData attribute Any The TrueType-specific data blob for this layer, containing compiled hinting tables.
tthAutohint function (self, make_hints: bool, itr: fgTTInterpreter) -> Any Runs TrueType auto-hinting on this layer.
tthFixZones function (self, itr: fgTTInterpreter) -> Any Fixes any broken zone references in the TTH program.
tthProgram attribute Any The list of TrueType hinting commands for this layer.
tthReassignStems function (self, itr: fgTTInterpreter) -> Any Re-maps stem references in the TTH program after stems have been added, removed, or reordered in the font's stem list.
tthReassignZones function (self, itr: fgTTInterpreter, bool: Any) -> Any Reassigns zone references in the TTH program.
tthRemoveCommands function (self, vertical: bool, horizontal: bool) -> Any Removes TrueType alignment commands by direction.
tthRemoveDeltas function (self, middle: bool, final: bool) -> Any Removes TTH delta commands (fine per-PPEM pixel adjustments) by phase.
type attribute Any Object type (shared captured text)
unselectAllNodes function (self) -> Any Deselects every node in every shape in this layer.
update function (self) -> Any (shared captured text)
updateAnchors function (self) -> Any Recalculates anchor positions relative to the current outline geometry.
updateAudit function (self, *args: Any, **kwargs: Any) -> Any Re-runs the specified audit checks (identified by integer check IDs) on this layer and updates the stored results.
updateGuidelineNode function (self, node: flNode) -> flNode Recalculates a guideline's anchor node position after the outline geometry has changed.
updatePreviewLinks function (self) -> None Rebuilds the preview link chain used by the glyph editor's preview rendering.
wireframeColor attribute Any The display color used when this layer is in wireframe mode.