fontlabapp.contours.transform.model
model
Shared transform writer and preview of Contours > Transform and Slant.
What: both scripts apply one affine matrix to the chosen layers.
transform_changes plans one layer: one row for its shapes and one row
for its anchors. TransformEditor writes the plan; bakes decides per
shape how. layer_outline, mapped, outline_path and fit feed
the before/after preview. panel_type() returns TransformPanel: the
OutlinePanel of fontlabapp.contours.panel.model plus an outline preview of
the first glyph that may change.
How: every shape gets the composed transform (old shape transform, then the
matrix). A shape that bakes accepts then gets shape.applyTransform():
FontLab writes the new nodes and resets the matrix. This is FontLab's own
per-shape rule of the layer transform (fllayer.cpp:6957-6978): it bakes
only own contour shapes that only move, whose data no other shape shares
and that include no other shapes, and composes every other shape. The
write never calls layer.applyTransform: the one-argument Python binding
also moves the guides, scales the advance and moves every anchor. Anchors
move in place, only when the user asks. An existing anchor that would land
on 0, 0 blocks Apply: anchor_writer.on_origin is the shared Redo rule
(FontLab issue 8527), here with a tolerance of ORIGIN_NEAR because
FontLab may round the stored point. The read-back accepts the same
tolerance for rounded nodes and anchors.
Why: Transform and Slant used private copies of this code. This module
imports only the standard library and stdlib-only App modules (affine,
anchor_writer, outline_writer) at load time. PythonQt loads inside
the functions, and panel_type() loads the class from
fontlabapp.contours.transform.ui, so FontLab's 5-second cold import stays
fast. Offline tests do not prove native Undo/Redo.
How to use (a script)::
import fly.ap.contours.transform.model as outline_transform
class Slant(outline_transform.panel_type()):
def preview_matrix(self, layer):
return matrix, guide_y
def planner(self):
return lambda glyph, master, layer: outline_transform.transform_changes(
layer, matrix, True, "250"
)
def editor(self):
return outline_transform.TransformEditor()
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 |
|---|---|---|---|
Affine |
attribute | ||
FIT_MARGIN |
attribute | ||
ORIGIN_NEAR |
attribute | ||
XY |
attribute | ||
bakes |
function | (shape: Any) -> bool |
True when FontLab's own layer transform writes the new nodes into the shape. |
fit |
function | (box: Any, width: float, height: float) -> Affine |
Map font units in box (y up) into a width × height widget (y down). |
layer_outline |
function | (layer: Any) -> list[list[Point]] |
Every contour of the layer as (x, y, on) lists, placed by its shape transform. |
mapped |
function | (contours: list[list[Point]], matrix: Affine) -> list[list[Point]] |
The same contours after matrix. |
outline_path |
function | (contours: list[list[Point]]) -> Any |
QPainterPath of closed contours: cubic for two controls, quadratic for one. |
panel_type |
function | () -> type |
Return the <code>TransformPanel</code><code> base class (a PythonQt </code><code>QDialog</code>). |
transform_changes |
function | (layer: Any, matrix: Affine, anchors: bool, note: str) -> list[Change] |
Rows for one layer: the shapes, then the anchors when asked. |