Skip to content

fontlabapp.masters.layers.writer

writer

Generic plan and write kernel of the layer writer scripts.

What: the writer scripts of the Components and Contours folders share one model. A script planner turns one layer into Change rows. A row can hold one edit. A collect function of the script family (component_writer, outline_writer) runs the planner on the chosen layers and fills a Plan. The script's Editor writes the edits, and apply_work makes that write ONE history.commit with operation="geometry".

How: apply_work calls editor.prepare for every layer BEFORE history opens, so native objects exist before the first init. Inside history, editor.write changes each layer and settle lets FontLab rebuild the layer caches. editor.retain names the native objects that the write removes; history.commit puts them first in the notification with deep history (FontLab issue 7641). An editor that removes nothing gives the two-argument notification. editor.check reads the font back: a value that FontLab did not keep raises RuntimeError. A failure after history started raises history.PartialWriteError ("... use Edit > Undo").

Why: the component and outline families used private copies of the same kernel. One App module keeps the Undo protocol, the read-back and the error texts the same everywhere. The two families keep their own collect and refusal policy: component_writer refuses the whole batch, and outline_writer lists and skips each refused glyph.

This module imports only the standard library and stdlib-only App modules (history) at load time, so FontLab's 5-second cold import stays fast. Offline tests do not prove native Undo/Redo.

How to use (a family module)::

from fly.ap.masters.layers.writer import Change, Editor, Plan, apply_work

class Shift(Editor):
    def write(self, layer, steps):
        ...

apply_work(plan.work, "Shift", facts, Shift())

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
EPSILON attribute (shared captured text)
Planner attribute
SHOWN_NAMES attribute (shared captured text)
Work attribute
apply_work function (work: Work, title: str, facts: history.AutoFacts, edit: Editor, *, allow_bases: bool=False) -> dict[str, Any] Write all edits as ONE native Undo step through history.commit.
fmt function (value: float, places: int | None=None) -> str Short number text: 700.0 -> 700.
layer_of function (glyph: Any, master: str) -> Any | None Existing master layer, or None.
plural function (count: int, word: str) -> str '1 layer', '2 layers'.
settle function (layer: Any) -> None Mark the layer changed and let FontLab rebuild its caches.
shown function (names: list[str]) -> str 'a, b, c …' for long lists: the first SHOWN_NAMES names.