Skip to content

fontlabapp.fontui.outline_routes.straighten_short_curves

straighten_short_curves

Turn short, flat curves into straight lines.

What: For each selected glyph and master, the table lists every contour with curves that are short and flat: the number of curves now, how many become lines, and the largest handle deviation. Straighten converts them.

How: A cubic curve qualifies when its chord is no longer than "Chord up to" and both handles lie within "Handles within" of the chord, between its ends. FontLab's own flNode.convertToLine, called on the end node of the curve, removes the two handles and recomputes the smooth flags at both ends. TrueType (quadratic) contours are left alone.

Why: Autotracing and format conversion leave tiny curves that are really lines. As lines they hint better, interpolate more safely and take less space. With "Keep masters compatible" ticked, a glyph is held back when the masters would get different curves, or when only some masters are in scope.

Use: Select glyphs. Run the script. Set the two limits and the masters. Press Straighten. Press Reload selection after you change the selection.

Benefit: Cleans many glyphs over many masters in one Undo step, with the worst deviation shown before anything changes.

Safety: These shapes are listed and kept:

  • shared outline data (an edit would change other glyphs too);
  • shapes with scale, slant or rotation (stored lengths are not visible lengths).

A glyph that has an automatic layer is listed and skipped. So is a glyph that is a base of an automatic composite, also through other composites, unless you tick "Also edit bases of automatic composites" (FontLab then rebuilds those composites; anchor recovery through Undo is not assured). The script keeps the compatibility check; writes disclose queued ids and possible date changes. After the write, it reads the node counts back. If FontLab fails part-way, the error says that native changes may remain. The change is recorded as one Undo step. The one-step write, the automatic-layer rule, the pending-update check and the panel are shared (fly.ap.contours.writer, fly.ap.contours.panel.model); the planner belongs to this script.

Source: the author's own FontLab sample outlines_straighten_short_curves.py, Apache-2.0. Adapted for the current FontLab 9 API.

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
TITLE attribute
XY attribute (shared captured text)
chord_offset function (point: XY, a: XY, b: XY) -> tuple[float, float] (distance from the line ab, position along ab as a fraction of its length).
cubic_segments function (points: list[outline_writer.Point]) -> list[tuple[int, int, int, int]] (i0, i1, i2, i3) node indices of every cubic curve of a closed contour. (shared captured text)
main function () -> Any Open the panel, or replace the one that is already open.
straight_segments function (points: list[outline_writer.Point], max_length: float, tolerance: float) -> list[tuple[int, int, float]] [(start index, end index, deviation)] of curves short and flat enough.
straighten_changes function (layer: Any, max_length: float, tolerance: float) -> list[outline_writer.Change] One row per contour with curves to straighten; notes for kept shapes.