Skip to content

fontlab.flAnchor

flAnchor

flAnchor is a geometric attachment link — it records a connection between a shape and another object (a guideline, another shape, or a specific node). FontLab uses these internally in its smart component and composite shape system to keep shapes locked to each other or to guidelines.

You'll encounter flAnchor objects if FontLab passes one to you in a callback. They are managed internally and are not enumerable from Python — there is no shape.anchors() method in the scripting API. You don't create them by hand; FontLab creates and destroys them as you build composites in the editor.

Properties (Read-only)

Property Type Description Access
anchorCode quint64 A unique hash that identifies this anchor's geometry. Two anchors with the same code attach to the same geometric position read
anchorPoint QPointF The attachment point's position in font units read
isGlobal bool True if this is a font-level anchor (rather than glyph-level) read
fixHorzDirection bool True if this anchor constrains horizontal movement — the attached shape cannot move left or right independently of what it's anchored to read
fixVertDirection bool True if this anchor constrains vertical movement read

flPinPoint Properties

flPinPoint is the Python class for named mark-to-base anchors on layers (what you access via layer.anchors). flAnchor (above) is a different, internal-only class for geometric shape attachments.

Read-write

Property Type Description
point QPointF The anchor's position in font units. Set this to move the anchor to a specific coordinate.
cloudEnabled bool When True, the anchor position is recalculated from the nearest point on the outline each time the outline changes. Use for variable fonts where glyph geometry shifts between masters.
anchor bool Internal flag that controls whether this point acts as an attachment anchor. Normally True for all anchors you create.
appearance int A numeric appearance code that controls how the anchor is drawn in the editor.
expressionX str A formula that determines the anchor's X position, e.g. "=lsb + (width - lsb - rsb) / 2". When set, the X coordinate is computed from the expression rather than stored as a fixed value.
expressionY str A formula that determines the anchor's Y position, e.g. "=xHeight".

Read-only

Property Type Description
hasExpression bool True if either expressionX or expressionY is set. Check this before assuming the point coordinates are fixed values.
style PinPointStyle The visual style used to draw this anchor in the editor (e.g. cross, circle).
isLatch bool True if this anchor is in "latch" mode — locked to a specific node on the outline.

Tutorial

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

font  = fl.CurrentFont()

# ============================================================
# 1. Creating anchors on a combining mark
# ============================================================
# A combining mark like acutecomb needs a "_top" anchor to tell
# FontLab where to align it when it attaches to a base letter.
# The underscore prefix means "I am the mark's attachment point."

acute_glyph = font['acutecomb']
acute_layer = acute_glyph.layers[0]

# Create the mark anchor at the visual bottom of the acute accent
# (this is where it will "sit on" the base letter's top anchor).
mark_anchor = flPinPoint(QPointF(250, 0))
mark_anchor.name = "_top"          # underscore = I'm a mark anchor
acute_layer.addAnchor(mark_anchor)

print(f"Added '{mark_anchor.name}' anchor at {mark_anchor.point}")

# ============================================================
# 2. Creating anchors on a base letter
# ============================================================
# The base letter needs a matching anchor WITHOUT the underscore.
# This says: "I accept marks named 'top' at this position."

base_glyph = font['a']
base_layer = base_glyph.layers[0]

# Place the top anchor near the top of the letter, optically centered.
base_anchor = flPinPoint(QPointF(220, 600))
base_anchor.name = "top"           # no underscore = I'm a base anchor
base_layer.addAnchor(base_anchor)

print(f"Added '{base_anchor.name}' anchor at {base_anchor.point}")
# Now acutecomb._top will align with a.top to produce áCorrect

# ============================================================
# 3. Adding multiple anchors for different mark types
# ============================================================
# A base letter can have anchors for many different diacritics.
# Add them all to the same layer.

anchor_positions = {
    "top":    (220, 600),    # for above marks (acute, grave, etc.)
    "bottom": (220, -10),    # for below marks (cedilla, etc.)
}

for name, (x, y) in anchor_positions.items():
    a = flPinPoint(x, y)
    a.name = name
    base_layer.addAnchor(a)

# List everything that's on this layer now:
for a in base_layer.anchors:
    print(f"  '{a.name}'  at ({a.point.x():.0f}, {a.point.y():.0f})")

# ============================================================
# 4. Repositioning an anchor
# ============================================================
# You can reposition anchors by setting .point directly, or
# nudge them with .translate() for small adjustments.

a = base_layer.anchors[0]

# Move to an absolute position:
a.point = QPointF(225, 610)

# Nudge by a relative offset (10 units right, 5 units up):
a.translate(QPointF(10, 5))

print(f"Repositioned '{a.name}' to {a.point}")

# ============================================================
# 5. Expression anchors — positions driven by formulas
# ============================================================
# Expression anchors are incredibly useful for variable fonts
# or for glyphs that exist in many widths. Instead of hardcoding
# coordinates, you write a formula.
#
# Font metric variables you can use in expressions:
#   lsb    — left side-bearing
#   rsb    — right side-bearing
#   xHeight, capHeight, ascender, descender
#   width  — advance width

a.expressionX = "=lsb + (width - lsb - rsb) / 2"  # horizontal center
a.expressionY = "=xHeight"                          # exactly at x-height

print("Expression-driven?", a.hasExpression)   # True

# ============================================================
# 6. Cloud mode — let the anchor follow the outline
# ============================================================
# With cloud mode, the anchor's position is recalculated from
# the nearest point on the outline each time the outline changes.
# This is great for variable fonts where the outline shape
# varies between masters.

mark_anchor.cloudEnabled = True
print("Cloud mode active:", mark_anchor.cloudEnabled)

# ============================================================
# 7. Listing and inspecting all anchors on a layer
# ============================================================

for glyph in font.glyphs:
    layer = glyph.layers[0]
    anchors = layer.anchors
    if anchors:
        print(f"\nGlyph '{glyph.name}':")
        for a in anchors:
            mode = "cloud" if a.cloudEnabled else "fixed"
            print(f"  '{a.name}'  ({a.point.x():.0f}, {a.point.y():.0f})  "
                  f"mode={mode}  hasExpr={a.hasExpression}")

# ============================================================
# 8. Removing an anchor
# ============================================================

acute_layer.removeAnchor(mark_anchor)
print("Anchors remaining on acutecomb:", len(acute_layer.anchors))

# ============================================================
# 9. Working with flAnchor (geometric shape anchors)
# ============================================================
# flAnchor objects represent geometric attachment links inside
# FontLab's composite/smart-corner system. They are NOT the same
# as flPinPoint (mark-to-base anchors on layers).
# flAnchor objects are managed internally by FontLab and are NOT
# directly enumerable via Python — there is no shape.anchors()
# method in the Python API. If you receive an flAnchor in a
# callback, its read-only properties (anchorPoint, anchorCode,
# isGlobal, fixHorzDirection, fixVertDirection) are accessible.

fl.Update()

Common Scripting Patterns

Add top/bottom anchors to all lowercase letters

# A quick script to add "top" and "bottom" anchors to all
# glyphs in a range. Adjust y-positions for your font's metrics.
import fontlab as fl
from fontlab import flPinPoint

font = fl.CurrentFont()

# Map glyph names to the anchor positions you want.
# You'd typically generate these from the actual glyph geometry.
lowercase = [g for g in font.glyphs
             if g.unicode and 0x61 <= int(g.unicode, 16) <= 0x7A]

for glyph in lowercase:
    layer = glyph.layers[0]
    # Skip glyphs that already have a "top" anchor
    if any(a.name == "top" for a in layer.anchors):
        continue
    # Approximate center-x from metrics
    cx = (glyph.advanceWidth or 500) / 2
    a = flPinPoint(cx, 600)
    a.name = "top"
    layer.addAnchor(a)

fl.Update()

Sync anchor X position to glyph center

# Use an expression to keep every "top" anchor horizontally
# centered in each glyph's advance width.
import fontlab as fl

font = fl.CurrentFont()
for glyph in font.glyphs:
    layer = glyph.layers[0]
    for a in layer.anchors:
        if a.name in ("top", "_top"):
            a.expressionX = "=lsb + (width - lsb - rsb) / 2"
fl.Update()

List all anchors across the font as a report

# Print a summary of every anchor in the font.
import fontlab as fl

font = fl.CurrentFont()
print("Glyph".ljust(20), "Anchor".ljust(15), "X", "Y")
print("-" * 50)
for glyph in font.glyphs:
    for layer in glyph.layers:
        for a in layer.anchors:
            print(
                glyph.name.ljust(20),
                a.name.ljust(15),
                f"{a.point.x():.0f}".rjust(6),
                f"{a.point.y():.0f}".rjust(6),
            )

Copy anchors from one master layer to another

# In a multi-master setup, copy the anchor names and
# relative positions from the Regular layer to the Bold layer.
import fontlab as fl
from fontlab import flPinPoint

font   = fl.CurrentFont()
glyph  = font['a']
src    = glyph.layers[0]   # Regular
dst    = glyph.layers[1]   # Bold

# Remove existing anchors from the destination layer first
for a in list(dst.anchors):
    dst.removeAnchor(a)

# Copy each anchor from source to destination
for a in src.anchors:
    new_a = flPinPoint(a.point)
    new_a.name = a.name
    dst.addAnchor(new_a)

fl.Update()

Enable cloud mode on all mark anchors

# Turn on cloud mode for every anchor whose name starts with "_"
# (i.e., all mark attachment anchors). This is useful in variable
# fonts where the outline geometry shifts significantly.
import fontlab as fl

font = fl.CurrentFont()
for glyph in font.glyphs:
    for layer in glyph.layers:
        for a in layer.anchors:
            if a.name.startswith("_"):
                a.cloudEnabled = True
fl.Update()

flAnchor.ModeSnap

Use the flAnchor.ModeSnap dictionary with subscription.

Key Native value Description
SnapToHorz flAnchor::ModeSnap::SnapToHorz Native enum value.
SnapToVert flAnchor::ModeSnap::SnapToVert Native enum value.
CoordSnap flAnchor::ModeSnap::CoordSnap Native enum value.

Constructors: flAnchor() - default flAnchor(flAnchor) - copy flAnchor(flObject)

Native bases: object

Captured native MRO: flAnchor, 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: An editing anchor whose name identifies the object and whose anchorPoint holds its QPointF position. The captured declaration exposes isGlobal, fixHorzDirection and fixVertDirection as boolean attributes. Consult the retained constructor documentation for supported creation forms.

Source: FontLab Proteus API documentation

Source: generated/fontlab.py: flAnchor 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
ModeSnap attribute dict
__init__ function (self, /, *args: Any, **kwargs: Any) -> None Initialize self. (shared captured text)
added function (self) -> Any Internal notification callback: called by the system when this anchor is added to a shape.
anchorCode attribute Any
anchorPoint attribute Any
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)
clone function (self, *args: Any, **kwargs: Any) -> Any Clone the object (shared captured text)
cloneObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
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)
fixHorzDirection attribute Any
fixVertDirection attribute Any
flObjectFlags attribute dict (shared captured text)
flag function (self, f: int) -> Any (shared captured text)
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)
hasChanges attribute Any (shared captured text)
hasHistoryState function (self, history_ix: int) -> Any (shared captured text)
hasHistoryStates attribute Any (shared captured text)
hasObject function (self, arg0: flObject) -> bool Returns True if the given object is one of the things this anchor connects.
haveObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
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)
instanceType function (*args: Any, **kwargs: Any) -> Any (shared captured text)
isChanged attribute Any (shared captured text)
isEqual function (self, arg0: flObject) -> Any (shared captured text)
isGlobal attribute Any
isNull attribute Any (shared captured text)
isPresent attribute Any (shared captured text)
isReleased attribute Any (shared captured text)
isValid attribute Any (shared captured text)
name attribute Any Object name (shared captured text)
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)
removed function (self) -> Any Internal notification callback: called when this anchor is removed from a shape
restoreHistoryState function (self, history_ix: int) -> Any (shared captured text)
setFlag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
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)
tag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
type attribute Any Object type (shared captured text)
update function (self) -> Any (shared captured text)