Skip to content

fontlab.CurveEx

CurveEx

A single Bézier segment.

What is CurveEx?

When you look at a letterform's outline in FontLab, you see a series of nodes connected by curve segments. Internally, each of those curve segments is stored as a CurveEx object. It holds four points — the two on-curve endpoints and the two off-curve control points (the "handles") — and provides mathematical operations on that single Bézier segment.

Most designers won't use CurveEx directly unless they are writing geometry-processing scripts. The most common way to encounter CurveEx objects is through flShapeData.segments, which gives you all segments of a shape as a flat list for bulk processing.

Tutorial

import fontlab as fl

# ============================================================
# Get the segments from a shape.
# flShapeData.segments gives you a flat list of all Bézier
# segments for every contour in the shape.
# ============================================================

font  = fl.CurrentFont()
glyph = font['S']   # 'S' has nice smooth curves to inspect
layer = glyph.layers[0]
shape = layer.shapes[0]

segs = shape.shapeData.segments
print(f"Total Bézier segments in 'S': {len(segs)}")

# ============================================================
# Print the basic geometry of each segment.
# Each segment goes from p0 (start node) to p1 (end node),
# with bcp0 and bcp1 as the off-curve control handles.
# ============================================================

for i, seg in enumerate(segs):
    if not seg.empty():
        length = seg.fastLength()
        kind   = "line" if seg.countPoints == 1 else "curve"
        print(f"Segment {i} ({kind}): "
              f"p0=({seg.p0.x():.0f},{seg.p0.y():.0f}) → "
              f"p1=({seg.p1.x():.0f},{seg.p1.y():.0f})  "
              f"length≈{length:.0f}")

# ============================================================
# Find all smooth joins in the glyph.
# A smooth join is where two consecutive segments share a
# node whose handles are collinear — no corner, just a smooth
# transition. This is what you see as a "smooth node" in the UI.
# ============================================================

smooth_count = 0
for i in range(1, len(segs)):
    if segs[i].smooth(segs[i-1]):
        smooth_count += 1
print(f"\nSmooth joins: {smooth_count} out of {len(segs)-1}")

# ============================================================
# Find potential missing extremum nodes.
# An extremum is a topmost/bottommost/leftmost/rightmost point.
# If a curve reaches its extreme inside a segment (not at a
# node), that is a "missing extremum" — important for correct
# PostScript hinting and clean vector export.
# ============================================================

print("\nPotential missing extrema:")
missing = 0
for i in range(1, len(segs)):
    if segs[i].extremum(segs[i-1]):
        missing += 1
        print(f"  At node {i}: ({segs[i].p0.x():.0f}, {segs[i].p0.y():.0f})")

if missing == 0:
    print("  None found — all extrema have nodes.")

Common Scripting Patterns

Count curve vs line segments across a glyph

import fontlab as fl

font  = fl.CurrentFont()
glyph = font['O']
layer = glyph.layers[0]

curves = 0
lines  = 0
for shape in layer.shapes:
    for seg in shape.shapeData.segments:
        if not seg.empty():
            if seg.countPoints == 1:
                lines  += 1
            else:
                curves += 1

print(f"'O': {curves} curve segments, {lines} line segments")

Check if all smooth nodes are actually smooth

import fontlab as fl

font  = fl.CurrentFont()
glyph = font['n']
layer = glyph.layers[0]

for shape in layer.shapes:
    segs = shape.shapeData.segments
    for i in range(1, len(segs)):
        node_idx = segs[i].leftIdx
        # Compare the geometric smoothness of the join:
        is_smooth = segs[i].smooth(segs[i-1])
        print(f"  Node {node_idx}: geometrically smooth = {is_smooth}")

Constructors: CurveEx() - default CurveEx(QPointF p0, QPointF p1[, int leftIdx=0[, int _rightIdx=0]]) CurveEx(QPointF p0, QPointF p1, QPointF p2, QPointF p3) CurveEx( list(QPointF) )

Native bases: object

Captured native MRO: CurveEx, 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: A curve segment record. The captured declaration exposes the end points p0 and p1, the control points bcp0 and bcp1, the control vectors bcv0 and bcv1, the bounding rectangle brect, and the index attributes leftIdx, rightIdx and contourIx. Captured methods include split, extremum, smooth, improve, fastLength and applyTransform. Consult the retained constructor documentation for the supported point-based creation forms.

Source: FontLab Proteus API documentation

Source: generated/fontlab.py: CurveEx 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)
applyTransform function (self, tx: QTransform) -> None Moves, scales, or rotates all four points of this segment using the transform matrix tx.
bcp0 attribute Any QPointF bcp0
bcp1 attribute Any QPointF bcp1
bcv0 attribute Any QPointF bcv0
bcv1 attribute Any QPointF bcv1
brect attribute Any The cached axis-aligned bounding rectangle of this segment.
contourIx attribute Any Index of the parent contour within its shape.
countPoints attribute Any Number of on-curve points in this segment: 2 for a cubic Bézier, 1 for a straight line segment.
empty function (self) -> bool Returns True if this segment is degenerate — all four points coincide, or the segment has not been initialised.
extremum function (self, prev: Any) -> bool Checks whether the shared node between this segment and prev is at a local extremum — the topmost, bottommost, leftmost, or rightmost point of the curve at that junction.
fastLength function (self) -> float Computes a quick approximation of the arc length (the actual measured length along the curve).
improve function (self, curvature: Any=...) -> bool Adjusts the off-curve control points to improve the visual quality of the curve, targeting the given curvature factor.
leftIdx attribute Any Index of the left node (p0) within the parent contour's node list.
p0 attribute Any QPointF p0
p1 attribute Any QPointF p1
paramT attribute Any The parametric position (0..1) of the most recently queried point on this segment.
rightIdx attribute Any Index of the right node (p1) within the parent contour's node list.
smooth function (self, prev: Any) -> bool Checks whether this segment and the previous segment prev join smoothly (G1 continuity — the tangent direction is the same on both sides of the shared node).
smoothCurvature function (self, c1: Any, complete: bool) -> Any Returns a new CurveEx with its handles adjusted for smooth curvature continuity (G2) between this segment and c1.
split function (self, *args: Any, **kwargs: Any) -> Any Splits this segment at its stored paramT value into two new segments.
updateBRect function (self) -> None Recomputes the segment's cached bounding rectangle from its current point positions.