Skip to content

fontlabapp.fontui.tglyph_edit

tglyph_edit

Qt-free point edits for TGlyph: move, delete, rubber band and redraw.

What: pure functions over fontlabapp.fontui.tglyph_model values. move_points shifts the selected points; a moved on-curve point carries its adjacent off-curve handles (wrapping round a closed contour, not an open one). delete_points removes the selected points, and the handles of selected on-curve points, then normalise keeps each touched contour valid: a contour with no on-curve point left is dropped, handles left in front of a line or move point are dropped, a curve left without handles becomes a line, a cubic curve left with exactly one handle becomes a line (the lone handle is dropped rather than reinterpreted as an implied quadratic), a closed contour starts on an on-curve point and an open contour starts with a move point. points_in_rect is the rubber-band hit test in screen pixels and draw_contours replays contours into a point pen. Every coordinate is stored as a float so a written glyph fingerprints exactly like the same glyph read back. Editor is the gesture state over a TGlyphModel: select, toggle, rubber band, drag with a preview, nudge, delete and the pen tool. The pen's first click only sets Editor.pending (drawn as a preview, never written); the second click writes a two-point open contour, and Escape or a tool switch discards the pending point. Each gesture yields at most one Edit; Editor.commit writes it once through font.edit_glyph(name, layer=..., undo_name="TGlyph: <action> <name>"), redrawing only the staged contours (components and anchors stay), and returns the fingerprint of the state it drew for fontlabapp.fontui.livesync.Echo. A failed write restores the pre-gesture glyph and re-raises. Use: fontlabapp.fontui.tglyph.TGlyph forwards canvas input to Editor. Why: the structural rules stay unit-testable without Qt or FontLab.

Classes

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
Key attribute
delete_points function (data: GlyphData, selection: set[Key]) -> GlyphData <code>data</code> without the selected points; touched contours are normalised or dropped.
draw_contours function (contours: tuple[Contour, ...], pen: Any) -> None Replay <code>contours</code> into a FontParts point pen.
handles function (contour: Contour, index: int) -> list[int] Indices of the off-curve points next to the on-curve point at <code>index</code>.
move_points function (data: GlyphData, selection: set[Key], dx: float, dy: float) -> GlyphData <code>data</code><code> with the selected points (and their handles) shifted by </code><code>(dx, dy)</code>.
normalise function (points: tuple[Point, ...], closed: bool) -> tuple[Point, ...] | None A valid contour from <code>points</code>, or None when no on-curve point is left.
points_in_rect function (data: GlyphData | None, view: View, rect: tuple[float, float, float, float]) -> set[Key] (contour, point) keys of own points inside the screen rectangle <code>(x0, y0, x1, y1)</code>.
toggle_points function (data: GlyphData, selection: set[Key]) -> GlyphData Toggle point roles, preserving coordinates and valid point-pen segments.
write_contours function (font: Any, name: str, layer: str, contours: tuple[Contour, ...], undo_name: str) -> None Replace <code>name</code><code>&#x27;s own contours on </code><code>layer</code><code> in one </code><code>edit&#95;glyph</code> write.