fontlabapp.studios.anchor_studio.model
model
Anchor Studio maths: Qt-free planners, safety checks and the read-back check.
What: A layer's anchors are read once into Pin tuples (name, x, y). Every
planner turns those pins (plus the layer's ink box and advance) into
Change rows; a Change with an edit is written, one with a
problem is shown and refused. Edits are ("set", name, (x, y)) (add the
anchor or move the only anchor of that name), ("remove", index) and
("rename", index, new) where index is the pin's place in the snapshot.
verify compares the stored anchors with the planned result within
TOLERANCE and names every sub-unit move that FontLab rounded to no change
(Scriptmix TODO:78), so the studio reports it instead of claiming success.
Why: The planners reproduce the Scriptmix Scripts/Anchors tools; keeping
them free of Qt and FontLab makes every rule unit-testable.
Used by fontlabapp.studios.anchor_studio.session and .tabs.
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 |
|---|---|---|---|
APPEARANCE |
attribute | Name-derived pin appearance of a new anchor (FontLab <code>flPinPoint</code> detectAppearance). |
|
BOUNDS_ANCHORS |
attribute | ||
Box |
attribute | (shared captured text) | |
DUPLICATE_ERROR |
attribute | ||
EPSILON |
attribute | (shared captured text) | |
Edit |
attribute | ||
HANDLE_SIZES |
attribute | ||
MAX_COLUMNS |
attribute | ||
METRICS |
attribute | ||
OPPOSITES |
attribute | ||
OPTICAL_BUDGET |
attribute | ||
ORIGIN_ERROR |
attribute | ||
Planner |
attribute | ||
REFERENCES |
attribute | ||
Ring |
attribute | ||
STACK_DISTANCE |
attribute | ||
TOLERANCE |
attribute | ||
bounds_changes |
function | (facts: Facts, wanted: Sequence[tuple[str, str, float]]) -> list[Change] | str |
Place From Bounds: add or move each <code>(name, edge, offset)</code> anchor from the ink box. |
census |
function | (rows: Iterable[tuple[Iterable[Pin], bool]]) -> dict[str, list[int]] |
Delete By Name list: <code>{name: [editable layers, auto layers]}</code><code> over </code><code>(pins, auto)</code> rows. |
centre_changes |
function | (facts: Facts, names: Sequence[str], reference: str, fraction: float, angle: float) -> list[Change] |
Center Horizontally: move the named anchors sideways; y never changes. |
column_weight |
function | (rings: Sequence[Ring], x: float, deadline: float) -> float |
Filled length of the vertical line at <code>x</code> under the nonzero winding rule. |
delete_changes |
function | (facts: Facts, names: Iterable[str]) -> list[Change] |
Delete By Name: remove every anchor whose name is ticked. |
duplicate_changes |
function | (facts: Facts, coincident: bool) -> list[Change] |
Remove every extra duplicate; coincident extras only when <code>coincident</code> is ticked. |
duplicated |
function | (pins: Iterable[Pin], names: Iterable[str] | None=None) -> list[str] |
Names carried by several pins (limited to <code>names</code> when given). |
estimate_rings |
function | (rings: Sequence[Ring], deadline: float) -> int |
Optical x of closed rings, sampled in at most <code>MAX_COLUMNS</code> columns. |
expected |
function | (pins: Sequence[Pin], edits: Sequence[Edit]) -> list[Pin] |
The pins after <code>edits</code>, in snapshot order with new anchors at the end. |
extremes |
function | (points: Sequence[tuple[float, float]]) -> str |
"x a…b, y c…d" of the cloud, or "" when empty. |
findings |
function | (pins: Sequence[Pin]) -> list[tuple[str, list[int]]] |
Duplicates Finder: <code>(kind, indices)</code> groups; the first pin of each group is kept. |
fmt |
function | (value: float) -> str |
|
half_up |
function | (value: float) -> int |
|
marker |
function | (x: float, y: float, size: float) -> OverlayContour |
A small diamond at (x, y) for the anchor cloud. |
metric_value |
function | (metrics: Any, attribute: str | None) -> int |
A master's metric in font units; <code>None</code> is the baseline, 0. |
opposite_changes |
function | (facts: Facts) -> list[Change] |
Remove Extraneous Mark Anchors: a mark with <code>_top</code><code> loses </code><code>bottom</code><code>; with </code><code>_bottom</code><code>, </code><code>top</code>. |
optical_changes |
function | (facts: Facts, estimate: int | str) -> list[Change] |
Optical Center: report the optical x; align the x of an existing <code>top</code> anchor. |
optical_position |
function | (strips: Sequence[tuple[float, float]], left: float, right: float) -> float |
Ink-weighted median column, moved one third of the way from the box centre. |
outline |
function | (rings: Iterable[Ring]) -> tuple[OverlayContour, ...] |
|
parse_names |
function | (text: str) -> list[str] |
Anchor names typed with commas, semicolons or spaces, in order, once each. |
point_text |
function | (x: float, y: float) -> str |
|
refusal |
function | (names: Sequence[str]) -> list[Change] |
|
rename_changes |
function | (facts: Facts, rename: Callable[[str], str]) -> list[Change] |
Rename Bulk: rename matching anchors; empty or clashing new names are refused. |
renamer |
function | (find: str, replace: str, regex: bool) -> Callable[[str], str] |
The name substitution; a bad pattern raises <code>ValueError("Pattern error: …")</code> at once. |
ring |
function | (x: float, y: float, radius: float) -> OverlayContour |
An octagon of <code>radius</code> around (x, y) for stacked anchors. |
rings_overlay |
function | (pins: Sequence[Pin], size: int) -> Overlay |
One ring per stacked anchor, each a little larger, so three coincident anchors show three rings. |
round_changes |
function | (facts: Facts, step: int, do_x: bool, do_y: bool, names: Sequence[str]) -> list[Change] |
Round To Grid: snap the named anchors (every anchor when <code>names</code> is empty). |
setter |
function | (pins: Sequence[Pin], name: str, x: float, y: float) -> Change | None |
The <code>set</code><code> change for </code><code>name</code> at (x, y); None when nothing moves. |
snap |
function | (value: float, step: int) -> int |
Nearest multiple of <code>step</code>, halves upward: 15→20, −15→−10. |
snap_changes |
function | (facts: Facts, names: Sequence[str], y: float) -> list[Change] |
Snap To Metrics: move the named anchors vertically to <code>y</code>. |
stacked |
function | (pins: Sequence[Pin]) -> list[list[Pin]] |
Groups of anchors that lie less than <code>STACK_DISTANCE</code> apart (three coincident → one group of 3). |
subject |
function | (names: Sequence[str]) -> str |
Undo-label subject: the glyph name, or <code>"N glyphs"</code> for several. |
target_point |
function | (box: Box, edge: str, offset: float) -> tuple[int, int] |
Centre of the box on <code>edge</code><code> ("top"/"bottom"), pushed out by </code><code>offset</code>. |
target_x |
function | (facts: Facts, reference: str, fraction: float, angle: float, y: float) -> float | None |
X on the reference line at height <code>y</code>; None for an empty ink box. |
verify |
function | (where: str, before: Sequence[Pin], edits: Sequence[Edit], stored: Sequence[Pin]) -> list[str] |
Problems after a write: missing/extra names, moves beyond <code>TOLERANCE</code> and swallowed moves. |