Skip to content

fontlabapp.components.creation

creation

Add plain components to EXISTING glyphs, inside the caller's one history step.

What: a script that adds components to glyphs that exist (Make Lower Unicase, Set Default Figures) needs a new component shape for each (base glyph, layer). No component constructor is measured on this FontLab build (fl#8505: setGlyphComponents rejects every argument form, addComponent only records a recipe entry; the source has an flShape(glyph, layer) constructor, pyflshape.cpp:66-79, which is a native probe item and is not used). Two calls:

  1. build_components(package, target, wanted, facts), BEFORE the caller's history.commit. It clones one plain component that the font already has (the prototype), once per NewComponent, and points each detached clone at its base glyph, layer and offset. Nothing is added to the font yet. Refusals raise ValueError and name the target glyph, so a script can show a kept row: an unknown base, a base without that layer, a bad offset, and a font without any plain component (NO_PROTOTYPE).
  2. add_component(layer, shape), INSIDE mutate of the caller's history.commit(..., operation="geometry"): it adds one built shape to the target layer and checks that the layer holds one more component of that base. Declare the target layers and glyphs in the commit.

The caller's commit is then the ONE Undo step of the edit.

NEW glyphs get their components another way: put them in the glyph's own Add Glyph data (glyph_creation.NewGlyph(components=(Part(...), ...))). That works also in a font without any component, and each new glyph is its own Undo step with its components.

Why no scratch glyph: a temporary glyph made with fontpr set_glyph adds an Add Glyph Undo step, and flPackage.deleteGlyph removes it outside history, so Redo would put the temporary glyph back (flcommands.cpp:914,919). That path is a native milestone candidate, not shipped behaviour. The cost: an existing glyph in a font without any plain component is refused.

Prototype filter: a clone copies the builder state (attached flag, attach anchor, component variation; flcompositeshapesbuilder.cpp:79-93) and the shape style (excluded, content lock, non-spacing, boolean operation, opacity; flshape.cpp:1906-1934,2213). An attached clone gets its offset overwritten at the next layer update (fllayer.cpp:1493-1535). So a prototype qualifies only when every one of these reads as the default through Python; _qualifies holds the rules:

  • the bound flShape members (pyflshape.cpp:438-443): excluded is the bool False, opacity is 1.0 (contentLocked is not read: it is True for every component on FontLab 9.0.9808, 504 of 504 in plum, A2 report 18, so it cannot tell a user lock; the VFJ locked key below does);
  • the fontpr get_glyph VFJ of its glyph (mcptools_source.cpp:58-79, a bound Python call; no flShape member reads these fields): the layer's elements match the layer shapes one to one; the element of the prototype has no locked, nonSpacing, booleanOperation, opacity or excluded key with a non-default value, and its component holds only glyphName, layerName and attached: false (no attachAnchor, no off2026Variation; tags of bin_types.cpp:383,535-545; writers flshape.cpp:826-831, flcompositeshapesbuilder.cpp:1141-1170).

Anything that cannot be read, or reads otherwise, disqualifies the shape. No qualifying prototype gives the NO_PROTOTYPE kept row.

Not measured natively: that a clone of a component is detached (own shapeData, reference count 1), that setting componentGlyph, componentLayer and transform on the detached clone re-targets it, and the Undo/Redo/save/reopen result. build_components has no auto-glyph consent: the edit runs in the caller's commit, whose history.refusal policy refuses auto layers and bases of auto composites. Offline tests prove the call order and the refusals only.

This module imports only the standard library and stdlib-only App modules at load time; PythonQt, fontpr and scripting load when build_components runs.

How to use (a script)::

import fly.ap.components.creation as component_creation
import fly.ap.core.history.glyphs as history

facts = history.scan_auto_facts(package)
wanted = [component_creation.NewComponent("A", master) for master in package.masters]
shapes = component_creation.build_components(package, "a", wanted, facts)
target = package.findName("a")
layers = [target.findLayer(m) for m in package.masters]

def mutate():
    for layer, shape in zip(layers, shapes, strict=True):
        component_creation.add_component(layer, shape)

history.commit("Unicase", layers, [target], mutate, operation="geometry", facts=facts)

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
COMPONENT_KEYS attribute
EPSILON attribute (shared captured text)
NO_PROTOTYPE attribute
STYLE_DEFAULTS attribute
add_component function (layer: Any, shape: Any) -> Any Add one shape from <code>build&#95;components</code><code> to </code><code>layer</code><code>; call it INSIDE </code><code>mutate</code>.
build_components function (package: Any, target: str, wanted: Sequence[NewComponent], facts: history.AutoFacts, *, cache: dict[str, Any… Return one detached plain component per item of <code>wanted</code><code>; call it BEFORE </code><code>history.commit</code>.
prototype function (package: Any, facts: history.AutoFacts) -> Any | None Return the first component that qualifies as a prototype (module text), or None.