fontlab.flShapeInfo
flShapeInfo
Represents one flShape as displayed on the canvas. It knows about the compositing chain (which other shapes are layered above/below it), can be moved on-screen, and can answer hit-test questions.
When do you use it?
Whenever you need to know where on the canvas a shape is — for example, to show a tooltip at the correct screen position, or to find which shape the mouse cursor is hovering over.
Tutorial
flShapeInfo is the canvas proxy you use when you need to know where a shape is on screen — for drawing overlays, for hit-testing mouse clicks, or for querying the composite hierarchy.
from PythonQt.QtCore import QPointF
import fontlab as fl
# ============================================================
# Get all shapes on the active glyph canvas and print their
# canvas bounding boxes. This is the starting point for any
# tool that needs to know where shapes are on screen.
# ============================================================
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
# Collect all shape infos via the contour infos:
all_contours = gi.getNearbyContours(QPointF(0, 0), 9999, "")
seen_shapes = {}
for ci in all_contours:
si = ci.shapeInfo
key = id(si)
if key not in seen_shapes:
seen_shapes[key] = si
print(f"Shapes on canvas ({len(seen_shapes)}):")
for si in seen_shapes.values():
bbox_glyph = si.boundingBox() # glyph units
bbox_canvas = si.brectOnCanvas() # screen pixels
print(f" Glyph bbox: ({bbox_glyph.left():.0f}, {bbox_glyph.bottom():.0f})"
f" → ({bbox_glyph.right():.0f}, {bbox_glyph.top():.0f})")
print(f" Canvas bbox: ({bbox_canvas.left():.1f}, {bbox_canvas.top():.1f})"
f" → ({bbox_canvas.right():.1f}, {bbox_canvas.bottom():.1f})")
# ============================================================
# Hit-test: find which shape is under a canvas point.
# ============================================================
mouse_pos = QPointF(200, 300) # canvas (screen) position
hit_shape = None
for si in seen_shapes.values():
if si.contains(mouse_pos):
hit_shape = si
break
if hit_shape:
print(f"\nMouse ({mouse_pos.x():.0f}, {mouse_pos.y():.0f}) "
f"hits shape with {len(hit_shape.getContoursInfo())} contour(s).")
else:
print(f"\nMouse ({mouse_pos.x():.0f}, {mouse_pos.y():.0f}) "
f"doesn't hit any shape.")
# ============================================================
# Check if any shape is inside a composite group.
# ============================================================
for si in seen_shapes.values():
owner = si.ownerComposite()
if owner:
print(f" Shape is a component of a composite.")
if si.hasAboveComposites():
print(f" Shape has composites layered above it.")
Common Scripting Patterns
Convert a glyph-space point to canvas space using a shape's transform
from PythonQt.QtCore import QPointF
import fontlab as fl
ws = fl.flWorkspace.instance()
gi = ws.getActiveCanvas().activeGlyphInfo() if ws.getActiveCanvas() else None
if gi:
contours = gi.getNearbyContours(QPointF(0, 0), 9999, "")
if contours:
si = contours[0].shapeInfo
tx = si.toCanvasTransform()
pt = QPointF(250, 500) # glyph units
cpt = tx.map(pt) # canvas pixels
print(f"Glyph ({pt.x():.0f}, {pt.y():.0f}) → "
f"Canvas ({cpt.x():.1f}, {cpt.y():.1f})")
Drill into a composite to find which component was clicked
from PythonQt.QtCore import QPointF
import fontlab as fl
ws = fl.flWorkspace.instance()
canvas = ws.getActiveCanvas()
gi = canvas.activeGlyphInfo() if canvas else None
if gi:
contours = gi.getNearbyContours(QPointF(0, 0), 9999, "")
seen = {id(ci.shapeInfo): ci.shapeInfo for ci in contours}
click_pt = QPointF(300, 400)
for si in seen.values():
hit = si.getHitIncludedShape(click_pt)
if hit:
print(f"Clicked component: {hit.shape}")
break
Inherited binding members: flSearchInfo.
Constructors:
flShapeInfo()
flShapeInfo(flObject)
flShapeInfo(flShapeInfo)
flShapeInfo(flShape, flSearchInfo)
flShapeInfo(flShape, QTransform)
flShapeInfo(flShape, QTransform, QList
Native bases: object
Captured native MRO: flShapeInfo, 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:
Shape information. The captured declaration exposes shape, layer, composites, appendComposite, pushFrontComposite, takeFirstComposite, takeLastComposite, ownerComposite, ownerCompositeInfo, getContoursInfo, findNode, contains, boundingBox, toCanvasTransform, toGlyphTransform, replaceShape, move and hasAboveComposites. 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: flShapeInfo 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) |
appendComposite |
function | (self, arg0: flShapeInfo) -> Any |
Appends a composite child to the end of the composite chain. |
boundingBox |
function | (self) -> QRectF |
Returns the bounding rectangle of the shape in glyph units (not screen). |
brectOnCanvas |
function | (self) -> QRectF |
Returns the bounding rectangle of the shape in canvas (screen) coordinates at the current zoom. |
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) |
combine |
function | (self, transform: QTransform) -> Any |
(shared captured text) |
composites |
attribute | Any |
The ordered list of child composite shapes. |
compositesTransform |
function | (self) -> QTransform |
Returns the accumulated transform from compositing. |
contains |
function | (self, s: Any=...) -> bool |
Returns True if the canvas point hits this shape's filled area. |
createInstance |
function | () -> flShapeInfo |
Factory method. |
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 |
Double dist (shared captured text) |
findNode |
function | (self, arg0: QPointF) -> flNode |
Searches for the node closest to the given canvas-space point. |
flObjectFlags |
attribute | dict |
(shared captured text) |
flag |
function | (self, f: int) -> Any |
(shared captured text) |
getContoursInfo |
function | (self) -> list[flObject] |
Returns the list of flContourInfo objects for all contours in this shape. |
getHitIncludedShape |
function | (self, canvas_pos: QPointF, to_bottom: Any=...) -> Any |
FlShapeInfo/Nothing getHitIncludedShape(QPointF canvas_pos, double scale[, bool to_bottom=false]) |
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) |
glyphInfo |
attribute | Any |
Glyph info (shared captured text) |
hasAboveComposites |
function | (self) -> bool |
Returns True if there are composite shapes layered above (drawn on top of) this shape. |
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) |
isContentLockedSibling |
function | (self) -> bool |
Returns True if this shape is a content-locked sibling in a composite group — meaning its geometry is tied to another shape and can't be edited independently. |
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) |
layer |
attribute | Any |
The layer this shape lives on. |
move |
function | (self, arg0: QPointF) -> QRectF |
Moves the shape on the canvas by the given offset (in canvas coordinates). |
name |
attribute | Any |
Object name (shared captured text) |
ownerComposite |
function | (self) -> flShape |
Returns the composite flShape that includes this shape, or Nothing if this shape is not a component of any composite. |
ownerCompositeInfo |
function | (self) -> flShapeInfo |
Returns the flShapeInfo of the owning composite. |
propertyNames |
function | (self, *args: Any, **kwargs: Any) -> Any |
PropertyNames(): sorted snapshot of dynamic property keys (shared captured text) |
pushFrontComposite |
function | (self, arg0: flShapeInfo) -> Any |
Inserts a composite child at the beginning of the chain. |
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) |
replaceShape |
function | (self, arg0: flShape) -> Any |
Swaps the underlying flShape model object while keeping the info wrapper alive. |
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) |
shape |
attribute | Any |
The underlying flShape model object. |
tag |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
takeFirstComposite |
function | (self) -> flShapeInfo |
Removes and returns the first child composite from the composite list. |
takeLastComposite |
function | (self) -> flShapeInfo |
Like takeFirstComposite but removes from the end. |
toCanvasTransform |
function | (self) -> QTransform |
Returns the complete glyph-space → canvas-space transform for this shape. |
toGlyphTransform |
function | (self) -> QTransform |
Returns the canvas-space → glyph-space transform (the inverse). |
transform |
attribute | Any |
Transform matrix (shared captured text) |
type |
attribute | Any |
Object type (shared captured text) |
update |
function | (self) -> Any |
(shared captured text) |