Skip to content

fontlab.flGlyph

flGlyph

A glyph is your font's record for one character — the letter "A", the numeral "3", an ampersand, or any other symbol you draw. Think of it as a folder: the glyph holds your drawings (called layers), the character code it maps to (unicodes), the spacing information (metrics), and any organisational labels (tags) you want to attach.

Inherits from flObject.

What is a Glyph?

The shape of a glyph

The glyph itself doesn't contain drawing data directly. Instead it holds one or more layers. Each layer is a snapshot of the character at a particular design stage or design-space location:

  • Master layers (one per master in a variable font) are the interpolatable drawings that define your design space. In a simple single-master font there is just one — often called "Regular".
  • Service layers are helpers: the mask, reference drawings, or intermediate states used during editing. They do not export.

So when you draw the letter "A", you are drawing on a layer inside the glyph, not on the glyph itself. This distinction matters when scripting: to read or change actual node coordinates you go glyph → layer → shape → contour → node.

Unicodes

A unicode is the number that maps your glyph to a character in the Unicode standard. "A" is 0x0041, "α" is 0x03B1. A glyph can have more than one unicode (for example the standard "A" and its fullwidth variant "A" can share a single drawing). The font system uses unicodes to figure out which glyph to show when text is set.

Metrics

The advance width is how much horizontal space the glyph occupies — including any side-bearings. The left sidebearing is the gap between the glyph's left edge and the start of its outline; the right sidebearing is the gap on the other side. You can set these as raw numbers or as expressions that reference other glyphs (e.g. "=n" means "copy the left sidebearing from the glyph n"). Expressions let you keep spacing consistent across a family without maintaining numbers by hand.

Tags

Tags are free-form labels you attach to a glyph. They are invaluable for organising large font projects: tag all diacritics as "diacritic", all small caps as "sc", all glyphs that still need review as "todo". You can then filter or select glyphs by tag in the font window.

Common Patterns

Iterating every glyph and checking content

font = fl.CurrentFont()
for glyph in font.glyphs:
    if not glyph.hasBody:
        print(f"Empty glyph: {glyph.name}")

Finding a glyph and reading its active layer

glyph = font['A']
layer = glyph.layers[0]         # first (usually Regular) master layer
print(layer.name, layer.advanceWidth)

Adding and removing tags

# Tag all glyphs that still need spacing work
for glyph in font.glyphs:
    if glyph.advanceWidth == 0:
        glyph.setTag("no-width", True)

# Later, remove the tag after fixing
glyph.setTag("no-width", False)

Batch-setting sidebearings with a metric expression

# Make every lowercase letter inherit its left bearing from 'n'
import fontlab as fl
font = fl.CurrentFont()
lowercase = "abcdefghijklmnopqrstuvwxyz"
for name in lowercase:
    g = font.findName(name)
    if g:
        g.metricsLeft = "=n"

Copying a glyph

from fontlab import flGlyph
original = font['A']
copy = flGlyph(original)   # independent clone
copy.name = "A.ss01"
font.addGlyph(copy)

Tutorial

import fontlab as fl
from fontlab import flGlyph, flLayer, flShape, flContour, flNode

# ============================================================
# Get the current font and look at a glyph
# ============================================================

font = fl.CurrentFont()

# Access the glyph for the letter 'A'. The font acts like a
# dictionary — you can look glyphs up by name.
glyph = font['A']

# The advance width is the total horizontal space this character
# takes up in a line of text (left sidebearing + outline + right
# sidebearing).
print(f"Glyph: '{glyph.name}'")
print(f"Advance width: {glyph.advanceWidth} units")

# ============================================================
# Layers — one per master, plus service layers
# ============================================================

# Each glyph can have several layers. In a variable font you'll
# see one per master (e.g. "Light", "Regular", "Bold"). In a
# single-master font there is usually just one.
for layer in glyph.layers:
    print(f"  Layer '{layer.name}'  — width: {layer.advanceWidth}")

# The active layer is the one shown in the glyph editor right now.
active = glyph.activeLayer
print(f"Active layer: '{active.name}'")

# ============================================================
# Tags — organise your glyph set
# ============================================================

# Add a tag to mark this glyph for review:
glyph.setTag("needs-review", True)

# Read back the tags:
print("Tags:", glyph.tags)              # explicit tags you set
print("Auto-tags:", glyph.virtualTags())  # tags FontLab derives automatically

# Remove a tag once work is done:
glyph.setTag("needs-review", False)

# ============================================================
# Metrics — read and write sidebearings
# ============================================================

# Read both sidebearings at once (no italic transform needed here):
from PythonQt.QtGui import QTransform
identity = QTransform()
lsb, rsb = glyph.getSB(identity)
print(f"Left SB: {lsb}   Right SB: {rsb}")

# Set the left sidebearing directly:
glyph.setLSB(40.0, False, identity)

# Or use metric expressions so this glyph inherits spacing from 'H':
glyph.metricsLeft  = "=H"
glyph.metricsRight = "=H"
# Now tell FontLab to re-evaluate the expressions:
glyph.updateSidebearings(True)

# ============================================================
# OpenType glyph classification
# ============================================================

# Mark a glyph as a ligature (two components):
ligature = font.findName("f_i")
if ligature:
    ligature.otGlyphClass   = 2    # 2 = ligature
    ligature.otLigaturesCount = 2  # composed of 2 glyphs (f + i)

# Mark a glyph as a combining mark:
acute = font.findName("acutecomb")
if acute:
    acute.otGlyphClass = 3    # 3 = mark

# ============================================================
# Creating a brand new glyph from scratch
# ============================================================

# Create a detached glyph object:
new_glyph = flGlyph()
new_glyph.name    = "diamond"
new_glyph.mark    = 3   # colour-mark it so it's easy to spot

# Build a layer to hold the outline:
layer = flLayer()
layer.name  = "Regular"
layer.advanceWidth = 400   # advance width for this master

# Build the outline: a diamond shape made of 4 on-curve nodes.
# The path goes: bottom → right → top → left, closed.
shape   = flShape()
contour = flContour()
contour.closed = True
for x, y in [(200, 0), (400, 300), (200, 600), (0, 300)]:
    contour.add(flNode(x, y, nodeType='on'))

shape.addContour(contour)
layer.addShape(shape)

# Attach the layer to the glyph, then add the glyph to the font:
new_glyph.addLayer(layer)
font.addGlyph(new_glyph)

# Tell FontLab to refresh the UI:
fl.Update()

Glyph-only mark encoding and history

glyph.glyphMark exposes the existing FontLab integer, not a Glyphs label index. Nonpositive values render as no mark. Values 1–360 encode hue (value - 1). Values above 360 render as gray, with channel value min(255, lightness // 2 + max(0, value - 1000) // 2) using the current mark lightness setting. Thus 1000 uses the base gray and 1100 is 50 channel units lighter; neither specifies a fixed RGB gray across preferences. VFJ stores the integer. There is no categorical conversion from Glyphs label 11 to a FontLab charcoal label. Converting an achromatic QColor through the hue-based color adapter yields no mark and is not a substitute for this integer property.

The raw property is suitable when the caller manages change notification and history. Ordinary glyph history can import geometry to serialize a full snapshot. This binding does not provide a geometry-free metadata transaction, cross-document atomicity, or automatic rollback. Do not emulate glyph-only writes by changing mark and restoring layers: that can make inherited layer marks explicit. Existing scripts that use mark retain its previous behavior.

Sigma authoring data

The binding exposes the native Sigma metadata used for authored interpolation adjustments:

Method Result and behavior
getSigmaData() Return an editable dictionary snapshot of the glyph's Sigma metadata.
setSigmaData(data) Validate and apply a complete dictionary through the native Sigma authoring path; invalid data raises ValueError. The native operation records the edit in history.
clearSigmaData() Remove authored Sigma curves through the native editing path; errors raise ValueError.
initializeSigma() Bind compatible master points for Sigma, record the initialization in history, and return None. Errors raise ValueError.

Read the dictionary with getSigmaData() before editing it; retain unrelated keys and use the native validator rather than inventing a metadata schema. setSigmaData() and clearSigmaData() also return None on success. The current registration docstring for initializeSigma() says dict, but the implementation returns None; call getSigmaData() afterward to inspect the initialized data.

Constructors: flGlyph() flGlyph(flGlyph) flGlyph(flObject) flGlyph(fgGlyph, fgFont)

Native bases: object

Captured native MRO: flGlyph, 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 FontLab editing glyph containing flLayer objects. The captured declaration exposes name and layers; iterate layers to inspect layer names. Unicode assignments belong to the associated fontgate glyph; they are not flGlyph attributes.

Example::

glyph = fl.CurrentGlyph()
if glyph:
    print(glyph.name)
    for layer in glyph.layers:
        print(layer.name)

Source: FontLab Proteus API documentation

Source: generated/fontlab.py: flGlyph 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)
activeLayer attribute Any The shared legacy/default layer.
addLayer function (self, back: Any=...) -> None Append a layer to the glyph's layer stack.
addLayers function (self, *args: Any, **kwargs: Any) -> Any Add multiple layers at once — more efficient than calling addLayer in a loop when you have many layers to add.
advanceWidth attribute Any The total advance width in font units — the horizontal distance the cursor moves after this glyph.
applyTransform function (self, *args: Any, **kwargs: Any) -> Any Apply a geometric transform (move, scale, rotate, skew) to all shapes in all layers.
ascender attribute Any A glyph-specific ascender override.
assignFontGateData function (self, arg0: fgFontGateData, doGuide: bool=True, doHints: bool=True, doAnchors: bool=True) -> None Apply a previously collected low-level data snapshot back onto this glyph, restoring guides, hints, and/or anchors.
bindDependencies function (self) -> Any Re-link component references — useful after you have programmatically added glyphs that are used as components in other glyphs.
bodyLayer attribute Any The primary drawing layer — usually the one whose name matches the active master.
bodyRect attribute Any The bounding rectangle of the glyph's "body" layer shapes only — excluding service layers.
boundingBox attribute Any The tightest rectangle that encloses all outlines in the active layer.
changed function (self) -> Any (shared captured text)
checkInitHistoryState function (self, history_ix: int) -> Any (shared captured text)
clearAboveHistory function (self, history_ix: int) -> Any (shared captured text)
clearFlag function (self, f: int) -> Any (shared captured text)
clearFlags function (self) -> Any (shared captured text)
clearSigmaData function (self, *args: Any, **kwargs: Any) -> Any ClearSigmaData(): remove authored Sigma curves
clearUpdateFgGlyphs function () -> Any Clear the queue of glyphs pending a low-level refresh.
clone function (self, *args: Any, **kwargs: Any) -> Any Clone the object (shared captured text)
cloneObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
createInstance function () -> flGlyph Allocate and return a fresh internal glyph instance.
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)
deactivateAll function (self) -> Any Deactivate all active shapes and contours in this glyph.
descender attribute Any A glyph-specific descender override.
ensureFgData function (arg0: fgGlyph) -> fgFontGateData Guarantee the glyph has an associated low-level data block, creating it if absent.
ensureMaskLayer function (self) -> flLayer Return the glyph's mask layer, creating it if it doesn't exist yet.
fgGlyph attribute Any The underlying low-level glyph object.
fgGlyphId attribute Any The low-level numeric identifier for this glyph within the fontgate engine.
fgPackage attribute Any The underlying low-level font object.
fillFgData function (self, doGuides: bool, doHints: bool) -> fgFontGateData Collect the glyph's guide and hint data into a low-level snapshot object.
findLayer function (self, cs: Any=...) -> flLayer Search for a layer by name and return it, or None if no layer with that name exists.
findLayerCreate function (self, cs: Any=...) -> flLayer Like findLayer, but if no layer is found it creates a new empty layer with the given name and returns it.
findVerticalGuideline function (self, arg0: str) -> Any Double/Nothing findVerticalGuideline(QString)
flObjectFlags attribute dict (shared captured text)
flag function (self, f: int) -> Any (shared captured text)
getAuditInfo function (self) -> Any Return the list of currently recorded quality issues for this glyph — open contours, wrong curve directions, duplicate nodes, and so on.
getLSB function (self, tr: QTransform) -> float Return the current left sidebearing, measured under the given transform.
getLayerByName function (self, create: Any=...) -> flLayer Look up a layer by name.
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)
getRSB function (self, tr: QTransform) -> float Return the current right sidebearing, measured under the given transform.
getSB function (self, *args: Any, **kwargs: Any) -> Any Return both sidebearings as a tuple (left, right).
getSigmaData function (self, *args: Any, **kwargs: Any) -> Any Dict getSigmaData(): return editable Sigma metadata
glyphMark attribute Any Int: glyph-only mark; does not change layer marks or record history
glyphName function (self) -> str Return the canonical glyph name as a string.
glyphRect attribute Any The full glyph cell rectangle, spanning the advance width and the font's ascender-to-descender range.
hasBody attribute Any True if the body layer contains at least some visible outline data.
hasChanges attribute Any True if the glyph has been modified since the last save.
hasFontAudit function (self) -> bool Return True if there is at least one outstanding audit issue recorded for this glyph.
hasHistoryState function (self, history_ix: int) -> Any (shared captured text)
hasHistoryStates attribute Any (shared captured text)
hasInstance function (arg0: fgGlyph) -> bool Check whether a given low-level fgGlyph already has a Python flGlyph wrapper bound to it.
has_layer function (self, name: str) -> bool Check for a named layer; see extensions.has_layer on immutable classes.
haveObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
haveSelected function (self, SelectionMode: Any) -> bool Return True if there is an active selection of the given type (nodes, shapes, etc.).
historyStates function (self, accepted_state: bool) -> Any (shared captured text)
horzReflection function (self) -> bool Return True if the glyph is horizontally mirrored (flipped left–right).
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)
initializeSigma function (self, *args: Any, **kwargs: Any) -> Any Dict initializeSigma(): bind compatible master points for Sigma
inkBox function (self, tx: Any=...) -> QRectF Returns the tightest bounding box that fits around all visible outlines, optionally measured under a coordinate transform.
instanceType function (*args: Any, **kwargs: Any) -> Any (shared captured text)
interpolateInstance function (self, location: flLocation, round: bool) -> flLayer Compute and return a new layer that is the interpolated result at the given point in design space.
isChanged attribute Any (shared captured text)
isEqual function (self, arg0: flObject) -> Any (shared captured text)
isNull attribute Any (shared captured text)
isPresent attribute Any (shared captured text)
isReleased attribute Any (shared captured text)
isUnbindedDependecies function (self) -> bool Return True if any component references are currently unresolved — meaning a component points to a glyph name that doesn't exist in the font.
isValid attribute Any (shared captured text)
lastModified attribute Any The timestamp of the most recent change to this glyph.
layer_names function (self) -> list[str] List layer names; immutable native classes use extensions.layer_names.
layers attribute Any All layers belonging to this glyph — master layers plus any service layers.
leftMetric attribute Any The left metric attachment point.
lib attribute Any An arbitrary key–value dictionary for storing custom metadata on the glyph.
linkInstances function (arg0: flGlyph, arg1: fgGlyph) -> bool Bind an existing flGlyph to a given fgGlyph identifier.
mark attribute Any Effective colour mark, which can come from the active layer.
masters2PS function (self, precision: float) -> bool Convert all master layers from TrueType quadratic curves back to PostScript cubic Bézier curves.
masters2TT function (self, precision: float) -> bool Convert all master layers from PostScript cubic Bézier curves to TrueType quadratic curves.
measurementLine function (self) -> Any Double/Nothing measurementLine()
metricsLeft attribute Any The left sidebearing expression.
metricsRect attribute Any The rectangle defined by the advance width and the font's vertical metrics.
metricsRight attribute Any The right sidebearing expression.
metricsWidth attribute Any An expression for the total advance width.
name attribute Any The glyph's name — for example "A", "a.sc", or "uni0041".
nodesCount attribute Any The total number of nodes across all shapes in the active layer.
note attribute Any A freeform text note you can attach to any glyph.
otGlyphClass attribute Any The OpenType glyph class: 0 = unassigned, 1 = base, 2 = ligature, 3 = mark, 4 = component.
otLigaturesCount attribute Any The number of components in a ligature.
otMarkClass attribute Any The OpenType mark class index.
package attribute Any The font that contains this glyph.
prepareTransformationData function (self) -> Any Cache the current geometry before beginning a transform operation.
propertyNames function (self, *args: Any, **kwargs: Any) -> Any PropertyNames(): sorted snapshot of dynamic property keys (shared captured text)
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)
removeChild function (self, arg0: flObject) -> Any (shared captured text)
removeEmptyShapes function (self) -> Any Delete any shapes in the glyph that contain no contours — useful for cleaning up stray empty shape containers.
removeLayer function (self, arg0: flLayer) -> None Detach and remove a layer from this glyph.
resetInkBox function (self) -> Any Invalidate the cached ink bounding box so it will be recalculated on the next access.
resetTransformationData function (self) -> Any Clear the transformation data cache after a transform is complete.
restoreHistoryState function (self, history_ix: int) -> Any (shared captured text)
rightMetric attribute Any The right metric attachment point — used when linking metrics to a specific location on the outline.
setAllShapesSelected function (self, bool: Any) -> Any Select (True) or deselect (False) every shape in the glyph.
setFlag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
setLSB function (self, v: float, move_guidelines: bool, tr: QTransform) -> bool Set the left sidebearing to v font units.
setLayers function (self, *args: Any, **kwargs: Any) -> Any Replace the glyph's entire layer list with a new one.
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)
setRSB function (self, v: float, tr: QTransform) -> bool Set the right sidebearing.
setReflected function (self, *args: Any, **kwargs: Any) -> Any Set the horizontal and/or vertical reflection flags.
setSB function (self, l: float, r: float, move_guidelines: bool, all_layers: bool, tr: QTransform) -> bool Set both sidebearings in one call.
setSigmaData function (self, *args: Any, **kwargs: Any) -> Any SetSigmaData(dict): validate and apply Sigma metadata as an undoable edit
setTag function (self, arg0: str, bool: Any) -> None Add (state=True) or remove (state=False) a single tag string from this glyph.
tag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
tags attribute Any The list of explicit tags you have applied to this glyph.
type attribute Any Object type (shared captured text)
unselectAllNodes function (self) -> Any Deselect every node across all layers and shapes in this glyph.
update function (self) -> Any (shared captured text)
updateActiveLayer function (self, bool: Any) -> flLayer Force FontLab to re-evaluate which layer should be shown as active in the glyph editor.
updateAudit function (self, *args: Any, **kwargs: Any) -> Any Re-run specific audit checks on this glyph, identified by their integer check IDs.
updateFgGlyph function (id: int) -> Any Schedule a glyph (by its internal id) for a low-level data refresh on the next update cycle.
updateSidebearings function (self, nofify: bool) -> bool Re-evaluate the glyph's metric expressions and recalculate the sidebearings from them.
updatedFgGlyphs function () -> Any Return the list of glyph ids that are queued for a low-level data refresh.
vertReflection function (self) -> bool Return True if the glyph is vertically mirrored (flipped upside-down).
virtualTags function (self) -> Any QSet<QString>/Nothing virtualTags()