Skip to content

fontlab.flGlyphInfo

flGlyphInfo

Canvas proxy for a rendered glyph.

What is flGlyphInfo?

flGlyphInfo is the top-level entry point into the canvas info system. When a glyph is displayed in the metrics view or glyph editor, FontLab wraps it in an flGlyphInfo that knows everything about how it appears on screen: its bounding rectangle in pixels, its screen position, whether it is currently active for editing, and where all its shapes, contours, and nodes are.

This is the class you reach for when writing interactive tools or canvas decorators. canvas.activeGlyphInfo() is the single most important call for tool code — it gives you the live rendering context for whatever glyph the user is currently editing.

flGlyphInfo is the root of the canvas info hierarchy:

flGlyphInfo              ← top-level proxy for one rendered glyph slot
  ├── flLayerInfo        ← canvas proxy for a layer (bounding rect)
  └── (via shapes/contours)
        flShapeInfo      ← shape-level: move, hit-test, composite queries
          └── flContourInfo  ← per-contour: node list, parametric hover point
                └── flNodeInfo  ← per-node: move in glyph space, repaint rect

The base info classes (flSearchInfo, flGraphicsInfo) hold shared infrastructure — distance values and canvas transform matrices — and are described in their own files.

When do you use it?

canvas.activeGlyphInfo() is the single most useful call for interactive tool code. It gives you the currently-being-edited glyph's canvas context — its screen position, bounds, and the full tree of shapes, contours, and nodes with canvas coordinates.

Tutorial

The standard flow in any canvas tool starts with getting the flGlyphInfo for the active glyph, then querying it for shapes, contours, or nodes near the mouse position.

from PythonQt.QtCore import QPointF
import fontlab as fl

# ============================================================
# Step 1: Get the active glyph info from the canvas.
# This works in both the glyph editor and the metrics view.
# ============================================================

ws     = fl.flWorkspace.instance()
canvas = ws.getActiveCanvas()
if canvas is None:
    print("Open a glyph window first.")
    raise SystemExit

gi = canvas.activeGlyphInfo()
if gi is None:
    print("No glyph is currently active for editing.")
    raise SystemExit

print(f"Active glyph:      '{gi.name}'")
print(f"Is active:          {gi.isActive}")
print(f"Canvas bounds:      {gi.brectOnCanvas}")
print(f"Body rect (UPM):    {gi.bodyRectOnCanvas}")
print(f"Null glyph:         {gi.isNullGlyph}")

# ============================================================
# Step 2: Hit-test — did the user click inside the glyph?
# This is the fastest way to answer "is this click on ink?"
# ============================================================

mouse_pos = QPointF(250, 400)   # canvas-space click position
hit = gi.hitToShape(mouse_pos)
print(f"\nPoint ({mouse_pos.x():.0f}, {mouse_pos.y():.0f}) inside glyph: {hit}")

# ============================================================
# Step 3: Find the nearest shape to a mouse position.
# ============================================================

top_shape = gi.getTopHitShape(mouse_pos)
if top_shape:
    print(f"Top hit shape canvas bounds: {top_shape.brectOnCanvas()}")

# ============================================================
# Step 4: Find nearby contours (the magnetic snap pattern).
# This is how knife tools and add-node tools find the curve
# to snap to.
# ============================================================

nearby = gi.getNearbyContours(mouse_pos, 30.0, "")
if nearby:
    nearest = min(nearby, key=lambda c: c.dist)
    print(f"\nNearest contour at {nearest.dist:.1f}px from mouse")
    print(f"  Parametric position (exT): {nearest.paramExT():.3f}")
    nodes = nearest.getNodesInfo()
    print(f"  Contour has {len(nodes)} node(s)")

# ============================================================
# Step 5: Access the model data through .glyph.
# ============================================================

glyph = gi.glyph
layer = glyph.layers[0]
print(f"\nGlyph '{glyph.name}' has {len(layer.shapes)} shape(s) "
      f"on layer '{layer.name}'")

Common Scripting Patterns

Check if a canvas point hits any glyph content

from PythonQt.QtCore import QPointF
import fontlab as fl

ws = fl.flWorkspace.instance()
gi = ws.getActiveCanvas().activeGlyphInfo() if ws.getActiveCanvas() else None
if gi:
    click = QPointF(300, 400)
    if gi.hitToShape(click):
        print("Click hit glyph ink.")
    elif gi.brectOnCanvas.contains(click):
        print("Click is in the glyph box but not on ink.")
    else:
        print("Click is outside the glyph box entirely.")

Get all selected nodes from the active glyph

import fontlab as fl

ws = fl.flWorkspace.instance()
gi = ws.getActiveCanvas().activeGlyphInfo() if ws.getActiveCanvas() else None
if gi:
    selected = gi.selectedNodes()
    print(f"Selected nodes ({len(selected)}):")
    for ni in selected:
        pt = ni.getGlyphPoint(True)   # rounded to integers
        print(f"  type={ni.node.type}  ({pt.x():.0f}, {pt.y():.0f})")

Read kerning offset for a glyph in the metrics view

import fontlab as fl

ws     = fl.flWorkspace.instance()
canvas = ws.getActiveCanvas()
if canvas:
    gi = canvas.activeGlyphInfo()
    if gi:
        kern_offset = gi.kerningOffset(True)
        print(f"'{gi.name}' kerning offset: {kern_offset:.0f} units")

Constructors: flGlyphInfo() flGlyphInfo(flObject) flGlyphInfo(flGlyphInfo) flGlyphInfo(flGlyph, QTransform) flGlyphInfo(fgSymbol, fgGlyph, fgFont)

Native bases: object

Captured native MRO: flGlyphInfo, 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: Glyph information. The captured declaration exposes glyph, boundingBox, createBoundingBox, applyTransform, applyTransformTo, getNearbyContours, getTopHitShape, hitToShape, kerningOffset, setKerningOffset, setBoundAscender, setBoundDescender, setBoundLeft, setBoundRight, setGlyphScale, fontSize, leftOffset, rightOffset, isActive, isSelected and isNullGlyph. It is created with no captured constructor overloads. It also carries the shared object members changed, clone, cloneObject, getProperty, setProperty, release, remove and update and the shared attributes id, name, type, isValid and isNull.

Source: FontLab Proteus API documentation

Source: generated/fontlab.py: flGlyphInfo 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 real layer resolved for this occurrence; no editable layer for an interpolated presentation.
applyTransform function (self) -> Any Commits the accumulated canvas transform to the glyph model and resets the transform.
applyTransformTo function (self, type: int) -> Any Applies the glyph's current canvas transform to a specific subset of its elements.
bodyRectOnCanvas attribute Any The UPM body rectangle (from descender to ascender) in canvas coordinates.
boundingBox attribute Any The bounding box of this glyph in glyph units (not canvas).
brectOnCanvas attribute Any The complete bounding rectangle of this glyph in canvas coordinates — including the advance width boxes on both sides.
changed function (self) -> Any (shared captured text)
changedRect attribute Any The canvas region that changed during the last editing operation.
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)
clearPresentationOverride function (self) -> bool
clone function (self, *args: Any, **kwargs: Any) -> Any Clone the object (shared captured text)
cloneObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
createBoundingBox function (self) -> Any Creates or refreshes the bounding box overlay shape for this glyph.
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)
dist attribute Any Distance value used in nearest-glyph queries (e.g. finding the glyph closest to a drag point).
flObjectFlags attribute dict (shared captured text)
flag function (self, f: int) -> Any (shared captured text)
fontSize attribute Any The point size at which this glyph is displayed in the metrics view.
getNearbyContours function (self, arg0: QPointF, max_dist: float, exclude_attr: str) -> Any
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)
getTopHitShape function (self, arg0: QPointF) -> Any FlShapeInfo/Nothing getTopHitShape(QPointF)
glyph attribute Any The flGlyph model object this info is rendering.
glyphRectCanvas attribute Any The ink (actual contour) bounding rectangle of this glyph in canvas coordinates.
hasChanges attribute Any (shared captured text)
hasHistoryState function (self, history_ix: int) -> Any (shared captured text)
hasHistoryStates attribute Any (shared captured text)
hasPresentationOverride attribute Any Whether this occurrence explicitly selects a layer or location.
haveObject function (*args: Any, **kwargs: Any) -> Any (shared captured text)
historyStates function (self, accepted_state: bool) -> Any (shared captured text)
hitToShape function (self, arg0: QPointF) -> bool Returns True if the given canvas point falls inside any filled shape of this glyph.
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)
isActive attribute Any True if this is the glyph currently open for editing in the glyph editor.
isChanged attribute Any (shared captured text)
isEditable attribute Any Whether the resolved layer permits editing, independent of the canvas's across-glyph policy.
isEqual function (self, arg0: flObject) -> Any (shared captured text)
isNull attribute Any (shared captured text)
isNullGlyph attribute Any True if this info represents a placeholder (e.g. a character not in the font).
isPresent attribute Any (shared captured text)
isReleased attribute Any (shared captured text)
isSelected attribute Any True if this glyph is selected in the metrics view.
isValid attribute Any (shared captured text)
kerningOffset function (self, useKerning: bool) -> float Returns the kerning offset that should be applied before this glyph when rendering in the metrics view.
leftOffset attribute Any Extra left-side offset for layout.
metricsRectOnCanvas attribute Any The metrics rectangle (descender to ascender) in canvas coordinates.
name attribute Any The glyph name (shortcut to glyph.name).
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)
restoreHistoryState function (self, history_ix: int) -> Any (shared captured text)
rightOffset attribute Any Extra right-side offset added when laying out this glyph in the metrics view.
setActiveLayer function (self, arg0: flLayer) -> bool
setBoundAscender function (self, double: Any) -> Any Overrides the ascender bound used for layout/clipping of this glyph in the metrics view.
setBoundDescender function (self, double: Any) -> Any Overrides the descender bound.
setBoundLeft function (self, double: Any) -> Any Overrides the left-side bound.
setBoundRight function (self, double: Any) -> Any Overrides the right-side bound.
setFlag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
setGlyphScale function (self, *args: Any, **kwargs: Any) -> Any Sets the horizontal and vertical rendering scale for this glyph instance on the canvas (does not change the font data).
setKerningOffset function (self, offs: float) -> Any Manually overrides the kerning offset for this glyph instance in the metrics display.
setLocation function (self, arg0: flLocation) -> 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)
shapesBoundingBoxOnCanvas attribute Any The combined bounding box of all shapes in canvas coordinates.
state attribute Any A bitmask of the current glyph-info state flags.
symbol attribute Any The character identity record for this glyph slot — contains the Unicode value, glyph name, and ligature index.
tag function (self, *args: Any, **kwargs: Any) -> Any (shared captured text)
textBlock attribute Any FlTextBlock, int
transform attribute Any Transform matrix (shared captured text)
type attribute Any Object type (shared captured text)
update function (self) -> Any (shared captured text)