Skip to content

fontlabapp.anchors.writer · declarations 001

Back to fontlabapp.anchors.writer

EPSILON module-attribute

EPSILON

Edit module-attribute

Edit

ORIGIN_ERROR module-attribute

ORIGIN_ERROR

Planner module-attribute

Planner

SHOWN_NAMES module-attribute

SHOWN_NAMES

Work module-attribute

Work

anchor_points

anchor_points(layer: Any) -> dict[str, tuple[float, float]]

Return {name: (x, y)} of the layer anchors, not rounded.

When several anchors share a name, the last one wins. Use duplicated to find such names. fontlabapp.anchors.inspect.model.anchor_points rounds; this function does not.

apply_work

apply_work(work: Work, title: str, facts: AutoFacts) -> dict[str, Any]

Write all edits as ONE native Undo step named title.

work holds no auto layer (collect); facts is a fresh history.scan_auto_facts. Call require_safe first. The commit uses history.commit(..., operation="geometry", read_back=...). No rollback is tried: a failure after history started raises history.PartialWriteError with "use Edit > Undo". A value that FontLab did not keep raises history.unstored_error ("FontLab did not store ... Check those layers before you save."). Empty work returns zeros and makes no history call.

Return {"anchors": native pin operations, "layers": edited layers}. One removed pin counts once, also for a repeated name.

blocked_rows

blocked_rows(work: Work, facts: AutoFacts) -> list[tuple[str, Change]]

Return one blocking row per edited glyph that the geometry policy refuses.

A glyph that owns an auto layer, or is a base of one (also through other composites), is refused: FontLab rebuilds the auto composite and Undo does not restore it. facts is a fresh history.scan_auto_facts.

collect

collect(glyphs: Iterable[Any], masters: Iterable[str], planner: Planner) -> Plan

Run planner on every existing layer and return the Plan.

An auto layer with changes is listed as "N anchors · auto layer, skipped" and goes into skipped, never into work. A layer with a blocked row goes into problems and not into work. A missing layer is ignored.

duplicated

duplicated(layer: Any, names: Iterable[str]) -> list[str]

Return the sorted names in names that several layer anchors carry.

fmt

fmt(value: float) -> str

Format a unit value without trailing decimals: 700.0 gives "700".

half_up

half_up(value: float) -> int

Round half up on every platform: 14.5 gives 15, -14.5 gives -14.

Python round() rounds half to even, so it is not used.

layer_of

layer_of(glyph: Any, master: str) -> Any | None

Return the existing layer of glyph in master, or None.

Never create a layer. Reuse fontlabapp.anchors.copy.model.layer_of; it loads when this function runs.

on_origin

on_origin(point: Iterable[float], near: float = 0.0) -> bool

True when point counts as 0, 0 for the Redo rule (FontLab issue 8527).

FontLab cannot Redo an existing anchor moved to 0, 0: the writer omits a default origin point, and the reader keeps the old point. near 0 accepts only exact zeros (require_safe). A caller that expects FontLab's rounding gives a tolerance: a value closer than near units to 0 also counts (Contours > Transform and Slant use 0.5).

parse_names

parse_names(text: str) -> list[str]

Split a name list at commas and semicolons: "top, bottom;ogonek" gives 3 names.

plural

plural(count: int, word: str) -> str

Return "1 layer" or "2 layers": add "s" when count is not 1.

prepare

prepare(layer: Any, edits: list[Edit]) -> list[tuple[str, Any, Any]]

Build every native pin and point BEFORE history opens.

Return [(step, pin, value)] with step "add", "move", "remove" or "rename". A new pin gets the name-derived appearance of fontlabapp.anchors.copy.model.APPEARANCE (lower-case name; 0 for other names). An existing pin is never rebuilt, so it keeps its own appearance and expressions.

raw_point

raw_point(pin: Any) -> tuple[float, float]

Return the stored position of an anchor, not rounded.

refusal

refusal(names: Iterable[str]) -> list[Change]

Return one blocking row per name: an edit of a repeated name is ambiguous.

require_safe

require_safe(work: Work, facts: AutoFacts) -> None

Refuse the whole batch before any history exists. Raise ValueError.

  1. A "set" edit of an existing anchor to 0, 0: FontLab cannot Redo it (FontLab issue 8527). A new anchor at 0, 0 is safe.
  2. A "set" edit of a name that several anchors of the layer carry: the move is ambiguous. "remove" and "rename" act on every pin with the name on purpose, so they pass.
  3. A glyph that owns an auto layer or is a base of one (blocked_rows).

shown

shown(names: list[str]) -> str

Join the first SHOWN_NAMES names with commas; add " …" for more.

unstored

unstored(work: Work, before: list[dict[str, tuple[float, float]]]) -> list[str]

Return "glyph/anchor" of each edit that FontLab did not keep.

before holds each layer's anchor_points from before the write. For "set", check only a coordinate that the edit changed: FontLab can round an untouched coordinate (strong rounding preference), and that is not an error. For "remove", the name must be gone. For "rename", the old name must be gone and the new name present.

write

write(layer: Any, steps: list[tuple[str, Any, Any]]) -> None

Run the prepared steps on the layer. Touch only the planned pins.

"add" adds the new pin; "move" sets the point of the existing pin; "remove" removes the pin; "rename" sets its name.