Skip to content

fontlabapp.contours.affine

affine

Pure 2D affine math in Qt's row-vector convention. No Qt import.

What it does: Holds a transform as six floats (a, b, c, d, e, f), the same order as QTransform(m11, m12, m21, m22, dx, dy). A point maps as x' = a*x + c*y + e and y' = b*x + d*y + f.

How to use: concat(first, then) applies first, then then. This is Qt's first * then. apply maps one point. invert gives the inverse. rotation makes a rotation; IDENTITY changes nothing. from_qtransform copies a native QTransform into plain floats. viewport_transform reads a FontLab canvas map as one Affine. Example: apply(concat(glyph_to_canvas, canvas_to_view), x, y) maps one glyph point to widget pixels.

Why this design: - Plain tuples keep no native wrapper alive and are safe in paint code. - No Qt import. The module loads in a cold FontLab start (5 s limit) and in tests without PythonQt. Qt classes arrive as arguments. - Every public function rejects non-finite numbers with ValueError by default. A bad native matrix then fails loud, not as a silent bad paint. Pass finite=False only for deliberate raw math.

Used by: canvas_rsb, canvas_anchor_rings, drawing. Glyport adopts the same names later (fontlab_glyport.drawing.context).

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
IDENTITY attribute Affine
SINGULAR_EPSILON attribute
apply function (t: Affine, x: float, y: float, *, finite: bool=True) -> tuple[float, float] Map one point <code>(x, y)</code><code> through </code><code>t</code>.
concat function (first: Affine, then: Affine, *, finite: bool=True) -> Affine Apply <code>first</code><code>, then </code><code>then</code><code> (Qt&#x27;s row-vector </code><code>first &#42; then</code>).
from_qtransform function (qt_transform: Any, *, finite: bool=True) -> Affine Copy a QTransform into six floats; retain no native wrapper.
invert function (t: Affine) -> Affine Return the inverse of <code>t</code>.
rotation function (degrees: float) -> Affine Return a rotation about the origin; positive turns x toward y.
viewport_transform function (canvas: Any, point_type: Callable[[float, float], Any]) -> Affine Sample <code>canvas.mapToViewportF</code> at (0,0), (1,0), (0,1) as one Affine.