fontlabapp.glyphs.creation
creation
Create new glyphs through FontLab's own Add Glyph command, then fill them in one step.
What: the Contours creator scripts (Placeholder Glyphs, Small Caps From
Capitals, Superior & Inferior Figures, Tabular Figure Copies) make new
glyphs. create_glyphs does it in this order:
- Refuse before any change (
ValueError): a name listed twice, a name that exists now, a name that can make FontLab rebuild an automatic glyph (auto_candidates) without the user's consent, a Glyph window as the active canvas (edit_guards.require_history_scope, FontLab issue 8573: measured on 9790, Undo stays disabled for the new glyphs and their outlines there). Read queued native glyph updates for disclosure (FontLab issue 8537); never clear them. - Read the signature of every automatic layer (
auto_signatures). - For each new glyph, call the fontpr tool
set_glyph(create=True)with the name, one layer per master with its advance width, the code points and optional components (NewGlyph.components,Part;glyph_data). The components are checked after the call. FontLab runs its undoable Add Glyph command (commAddGlyph) for it. - Optionally
fillthe new layers in ONEhistory.commit(..., operation="geometry")that declares the new layers and glyphs. - Read back: the caller's
read_backtexts, then one text per automatic layer whose signature changed (auto_changes).
User text for the Undo shape: UNDO_TEXT ("Each new glyph is recorded as
its own Undo step, and the outlines as one more Undo step."). This module
makes no claim about what Undo restores.
Why: flPackage.addGlyph is a raw insert. It runs no command and records
no history (source: flpackage.cpp:18526-18532), and it skips
ensureComplete. set_glyph creates the glyph the way FontLab's own
tools do (source: mcptools_source.cpp:144-172); the command runs
synchronously and clears the queued glyph updates
(flhistorycontroller.cpp:1818-1914). Glyport creates glyphs the same
way. This module never calls addGlyph and never writes a FontGate
record.
The Add Glyph command re-resolves the default-recipe automatic composites
of the font (commAddGlyph::updateAutoGlyphs, fl#8512). FontLab gives no
Python call that predicts a default recipe, so auto_candidates is a
conservative guess: automatic layers without an own recipe whose glyph name
shares a dotted suffix segment with the new name (a new e.sc can change
eacute.sc). The script lists them ("may rebuild auto eacute.sc") and
creates such a glyph only after the user ticks REBUILD_LABEL. The
after-write check (auto_changes) stays. Automatic layers are never
notified.
This module imports only the standard library and stdlib-only App modules
at load time; fontpr loads when create_glyphs runs. Offline tests
prove the call order, not native Undo/Redo.
How to use (a script)::
import fly.ap.glyphs.creation as glyph_creation
specs = [glyph_creation.NewGlyph("h.sc", (("Regular", 450),))]
done = glyph_creation.create_glyphs(package, specs, "Small Caps", facts, fill=fill)
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 |
|---|---|---|---|
CREATE_UNDO_TEXT |
attribute | ||
LayerKey |
attribute | ||
REBUILD_LABEL |
attribute | ||
SHOWN_CANDIDATES |
attribute | ||
UNDO_TEXT |
attribute | ||
auto_candidates |
function | (package: Any, facts: history.AutoFacts, names: Iterable[str]) -> dict[str, tuple[str, ...]] |
Map each new name to the automatic glyphs that FontLab may rebuild when it appears. |
auto_changes |
function | (package: Any, before: Mapping[LayerKey, tuple[Any, ...]]) -> list[str] |
Return one text per automatic layer whose signature changed or that is gone. |
auto_signatures |
function | (package: Any, facts: history.AutoFacts) -> dict[LayerKey, tuple[Any, ...]] |
Return the signature of every automatic layer of the font, before the write. |
create_glyphs |
function | (package: Any, specs: Sequence[NewGlyph], title: str, facts: history.AutoFacts, *, fill: Callable[[dict[str, … |
Create every glyph of <code>specs</code>, then optionally fill them in ONE Undo step. |
glyph_data |
function | (spec: NewGlyph) -> dict[str, Any] |
Return the fontpr <code>glyph_data</code><code> JSON for </code><code>spec</code>: name, layers, code points. |
layer_signature |
function | (layer: Any) -> tuple[Any, ...] |
Return the component bases and transforms, anchors and width of <code>layer</code>. |
rebuild_note |
function | (candidates: Sequence[str]) -> str |
Return the preview note: "may rebuild auto eacute.sc, aacute.sc…". |
segments |
function | (name: str) -> frozenset[str] |
Return the dotted suffix segments of a glyph name: h.sc.ss01 -> {sc, ss01}. |
undo_text |
function | (filled: bool) -> str |
Return <code>UNDO_TEXT</code><code> when the script fills outlines, else </code><code>CREATE_UNDO_TEXT</code>. |