Skip to content

fontlabapp.contours.writer

writer

Shared plan kernel of the outline writer scripts (Contours folder).

What: the Contours writer scripts (Round Coordinates, Remove Overlap, Add Extremes, Correct Contour Direction, Straighten Short Curves, Optimize Start Points, Delete Small Contours, Fix Zero Handles, Delete Duplicate Contours, Transform, Slant) share one model. A script planner turns one layer into Change rows; the script's Editor writes them through apply_work (one Undo step). This module adds the outline parts to the generic fontlabapp.masters.layers.writer kernel and re-exports that kernel:

  • outline_shapes gives the own contour shapes that a script may edit in place, and a note for every shape that it keeps (shared outline data, scaled or rotated shapes). note_rows turns the notes into rows.
  • node_points and translation read nodes and plain shape moves.
  • collect runs the planner on every chosen layer. A glyph that the geometry policy refuses is listed and skipped as a whole; the other glyphs are still written. With compatible, a glyph whose structure edits would differ between masters is held back (held_back).
  • require_safe is a compatibility hook; apply_work discloses queued glyph updates through history (FontLab issue 8537).

How: a Change.key names a structure edit (for example the index of a deleted contour). held_back compares the keys of all masters: the masters stay compatible only when every master gets the same keys and every master with a key edit is in scope.

Why: the logic was a private copy in each of the eleven scripts. The refusal policy differs from component_writer on purpose: an outline batch skips each refused glyph, with a row that says why, and asks for consent (allow_bases) before it edits bases of automatic composites.

This module imports only the standard library and stdlib-only App modules (history, edit_guards, layer_writer) at load time, so FontLab's 5-second cold import stays fast. The panel base is in fontlabapp.contours.panel.model. Offline tests do not prove native Undo/Redo.

How to use (a script)::

import fly.ap.contours.writer as outline_writer

def planner(glyph, master, layer):
    shapes, notes = outline_writer.outline_shapes(layer)
    rows = [outline_writer.Change("nodes", "3", "4", ("nodes", shapes))]
    return rows + outline_writer.note_rows(notes)

plan = outline_writer.collect(glyphs, masters, planner, facts)
outline_writer.require_safe()
outline_writer.apply_work(plan.work, "Example", facts, ExampleEditor())

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
BASES_LABEL attribute
COMPATIBLE_LABEL attribute
PLACES attribute
Point attribute
collect function (glyphs: Iterable[Any], masters: Iterable[str], planner: Planner, facts: history.AutoFacts, *, compatible: bo… Run planner on every chosen layer and return the Plan.
fmt function (value: float) -> str Short number text with PLACES decimals: 700.0 -> 700, 12.254 -> 12.25.
held_back function (planned: dict[str, tuple[Any, list[Change]]], chosen: list[str]) -> str Why the structure edits of one glyph would break master compatibility, or "".
node_points function (contour: Any) -> list[Point] (x, y, on-curve) of every node, in stored order and shape coordinates.
note_rows function (notes: list[str]) -> list[Change] One muted row per distinct note, with the number of shapes.
outline_shapes function (layer: Any) -> tuple[list[Any], list[str]] Own contour shapes that a script may edit in place, and notes for the rest.
require_safe function () -> None Compatibility hook; the writer discloses queued ids through history.commit.
translation function (shape: Any) -> tuple[float, float] | None (dx, dy) when the shape transform only moves; None for scale, slant or turn.