fontlab.flContourInfo
flContourInfo
Canvas proxy for a contour.
What is flContourInfo?
flContourInfo represents one contour on the FontLab canvas. It extends flShapeInfo with per-contour node queries and a parametric "where along the contour" tracker — the mechanism that lets tools show a preview point on a contour as the mouse moves over it (as in a knife or add-node tool).
While flContour stores the model data (nodes and segments in font units), flContourInfo knows where the contour appears on screen. It provides the canvas-space bounding rect for the contour, access to node info objects, and hit-testing at a specific mouse position.
Tutorial
The most practical use of flContourInfo in a custom tool is the parametric hover-point system: as the mouse moves, you find the nearest parametric position on a contour and show a small indicator there.
from PythonQt.QtCore import QPointF
import fontlab as fl
# ============================================================
# Simulate a knife-tool hover:
# Given a canvas mouse position, find the nearest point on any
# contour and display its parametric position (exT value).
# ============================================================
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
# Simulate a mouse position:
mouse_pos = QPointF(250, 350)
# Get nearby contours within 20 canvas pixels:
nearby = gi.getNearbyContours(mouse_pos, 20.0, "")
if not nearby:
print(f"No contours within 20 px of ({mouse_pos.x():.0f}, {mouse_pos.y():.0f}).")
else:
# The closest one (smallest dist):
ci = min(nearby, key=lambda c: c.dist)
print(f"Closest contour dist={ci.dist:.1f}px")
print(f" Canvas bounds: {ci.brectOnCanvas()}")
# The parametric position of the closest point:
ex_t = ci.paramExT()
t = ci.paramT()
print(f" Extended t: {ex_t:.4f} Segment t: {t:.4f}")
# Update the hover indicator (for tool paint):
ci.setExT(ex_t)
repaint_rect = ci.getUpdateRect(ex_t)
print(f" Repaint rect: {repaint_rect}")
# ============================================================
# Get all node info objects for this contour to draw handles:
# ============================================================
nodes_info = ci.getNodesInfo()
print(f"\nNodes in this contour ({len(nodes_info)}):")
for ni in nodes_info:
print(f" Node type={ni.node.type} "
f"canvas=({ni.canvasPoint.x():.1f}, {ni.canvasPoint.y():.1f})")
Common Scripting Patterns
Find the nearest node to a canvas point
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:
mouse_pos = QPointF(300, 400)
nearby = gi.getNearbyContours(mouse_pos, 50.0, "")
hit_node = None
for ci in nearby:
ni = ci.getHitNode(mouse_pos)
if ni is not None:
hit_node = ni
break
if hit_node:
print(f"Nearest node: type={hit_node.node.type} "
f"at ({hit_node.node.x:.0f}, {hit_node.node.y:.0f})")
else:
print("No node hit within 50px of cursor.")
Iterate all nodes in the current glyph with canvas positions
from PythonQt.QtCore import QPointF
import fontlab as fl
ws = fl.flWorkspace.instance()
gi = ws.getActiveCanvas().activeGlyphInfo() if ws.getActiveCanvas() else None
if gi:
all_contours = gi.getNearbyContours(QPointF(0, 0), 9999, "")
for ci in all_contours:
for ni in ci.getNodesInfo():
print(f" ({ni.node.x:.0f}, {ni.node.y:.0f}) → canvas "
f"({ni.canvasPoint.x():.1f}, {ni.canvasPoint.y():.1f})")
Inherited binding members: flSearchInfo.
Constructors: flContourInfo() flContourInfo(flObject) flContourInfo(flContour, flSearchInfo) flContourInfo(flContour, flShapeInfo) flContourInfo(flContour, flContourInfo) flContourInfo(flContour, QTransform)
Native bases: object
Captured native MRO: flContourInfo, 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:
Contour information. The captured declaration exposes contour, shapeInfo, glyphInfo, getHitNode, getNodesInfo, cloneSelected, brectOnCanvas, combine, dist and 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: flContourInfo 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) |
brectOnCanvas |
function | (self) -> QRectF |
Returns this contour's bounding rect in canvas coordinates. |
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) |
cloneSelected |
function | (self) -> list[flContourInfo] |
Clones only the selected portions of this contour, returning new flContourInfo objects. |
combine |
function | (self, transform: QTransform) -> Any |
|
contour |
attribute | Any |
The underlying flContour model object. |
createInstance |
function | () -> flContourInfo |
Factory. |
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 |
flObjectFlags |
attribute | dict |
(shared captured text) |
flag |
function | (self, f: int) -> Any |
(shared captured text) |
getHitNode |
function | (self, canvas_pos: QPointF, node_mask: Any=...) -> Any |
FlNodeInfo/Nothing getHitNode(QPointF canvas_pos, double dist[, int node_mask=flNode::AnyNodeMask]) |
getNodesInfo |
function | (self) -> list[flNodeInfo] |
Returns all nodes of this contour as flNodeInfo objects. |
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) |
getUpdateRect |
function | (self, ex_t: float) -> QRectF |
Returns the canvas rectangle that needs repainting when the hover point changes to ex_t. |
glyphInfo |
attribute | Any |
Glyph info |
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) |
paramExT |
function | (self) -> float |
Returns the extended parametric t value at the most recently computed closest point. |
paramT |
function | (self) -> float |
Returns the standard per-segment parametric t (0..1) of the closest hit point — useful to identify which segment the closest point is on. |
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) |
setExT |
function | (self, ex_t: float) -> Any |
Positions the contour's hover-point indicator at parametric position ex_t. |
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) |
shapeInfo |
attribute | Any |
The parent flShapeInfo this contour belongs to. |
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) |