fontlab.flGraphicsInfo
flGraphicsInfo
Canvas-transform-aware info object.
What is flGraphicsInfo?
flGraphicsInfo extends flSearchInfo with the one thing that makes canvas rendering possible: the transformation matrix (transform) that maps from glyph-space coordinates (font units) to canvas-space coordinates (screen pixels at the current zoom level).
Once you have an flGraphicsInfo, you can convert any glyph-space point to its screen position by applying the transform. Conversely, you can map screen coordinates back to glyph coordinates using the inverse transform. Every shape, contour, and node info object inherits from flGraphicsInfo, which is why all of them can answer "where on screen am I?".
Most scripting that works with canvas positions will receive flGraphicsInfo (or one of its subclasses like flShapeInfo, flContourInfo, or flNodeInfo) back from a query method rather than constructing one directly.
Tutorial
The transform property is the bridge between the mathematical world of font units and the visual world of the screen. Here is how to use it to map points between the two coordinate systems.
from PythonQt.QtCore import QPointF
import fontlab as fl
# ============================================================
# Get the canvas transform for a specific shape on screen.
# flShapeInfo inherits from flGraphicsInfo, so every shape
# info object has a .transform property.
# ============================================================
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 active glyph.")
raise SystemExit
# Get shape infos through a broad contour query:
all_contours = gi.getNearbyContours(QPointF(0, 0), 99999, "")
if all_contours:
ci = all_contours[0]
si = ci.shapeInfo # flShapeInfo, which has transform
# The transform maps glyph units → canvas pixels:
tx = si.transform
# Map a glyph-space point to canvas space:
glyph_pt = QPointF(100, 500) # 100 units right, 500 units up
canvas_pt = tx.map(glyph_pt) # apply the transform
print(f"Glyph ({glyph_pt.x():.0f}, {glyph_pt.y():.0f}) "
f"→ Canvas ({canvas_pt.x():.1f}, {canvas_pt.y():.1f})")
# Map back from canvas → glyph space using the inverse:
inverse_tx = tx.inverted()[0] # inverted() returns (QTransform, bool_ok)
back = inverse_tx.map(canvas_pt)
print(f"Canvas ({canvas_pt.x():.1f}, {canvas_pt.y():.1f}) "
f"→ Glyph ({back.x():.1f}, {back.y():.1f})")
Common Scripting Patterns
Get the canvas zoom level from a shape's transform
from PythonQt.QtCore import QPointF
import fontlab as fl
import math
ws = fl.flWorkspace.instance()
gi = ws.getActiveCanvas().activeGlyphInfo() if ws.getActiveCanvas() else None
if gi:
contours = gi.getNearbyContours(QPointF(0, 0), 99999, "")
if contours:
tx = contours[0].shapeInfo.transform
# The scale factor is the length of the first column vector:
zoom = math.hypot(tx.m11(), tx.m21())
print(f"Current canvas zoom: {zoom:.3f}× (1.0 = 100%)")
Inherited binding members: flObject.
Constructors: flGraphicsInfo() flGraphicsInfo(flObject) flGraphicsInfo(flGraphicsInfo)
Native bases: object
Captured native MRO: flGraphicsInfo, 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:
Graphics information. The captured declaration exposes the attribute transform. 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: flGraphicsInfo 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) |
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) |
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) |
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) |
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) |
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) |
transform |
attribute | Any |
Transform matrix |
type |
attribute | Any |
Object type (shared captured text) |
update |
function | (self) -> Any |
(shared captured text) |