fontlab.flTransform
flTransform
What is a Transform?
A transform is a recipe for repositioning, resizing, rotating, or slanting something. In type design you use transforms constantly: you move a shape to adjust its position, scale it up or down, rotate it to create swash variants, or skew it to fake an italic slant.
Mathematically, all of these operations — move, scale, rotate, skew — can be described with a single 3×3 table of numbers called a transformation matrix. You don't need to understand the maths; what matters is knowing that:
- Translate = move. The transform shifts every point by a fixed amount in X and/or Y.
- Scale = resize. A scale of
2.0doubles the size;0.5halves it. You can scale X and Y independently (e.g. make something taller without making it wider). - Rotate = spin. Points are rotated around the origin by an angle.
- Shear/skew = slant. Points are pushed sideways in proportion to their Y position — this is what makes something look italic.
Most transforms are a combination of the above. A slant plus a scale is still just one matrix.
flTransform vs. QTransform
FontLab uses Qt's QTransform type for the raw matrix arithmetic. flTransform wraps QTransform and adds a convenient scale property that reads the uniform scale factor out of the matrix automatically. flTransform is what you find on shapes (shape.fl_transform) and on canvas views (canvas.viewTransform).
In practice:
- Read the transform on a shape via shape.fl_transform — this is an flTransform.
- Build a new matrix using QTransform methods (.translate(), .scale(), .rotate(), .shear()), then wrap it in flTransform to apply it.
- Apply a transform to a shape using shape.transformBy(qt_transform) or glyph.applyTransform(qt_transform).
Common Patterns
Moving a shape by a fixed amount
from PythonQt.QtGui import QTransform
# Move 50 units to the right, 0 units vertically:
move_right = QTransform().translate(50, 0)
shape.transformBy(move_right)
Scaling a glyph to a new UPM
from PythonQt.QtGui import QTransform
# Scale everything by a factor of 1.1 (10% larger):
scale_up = QTransform().scale(1.1, 1.1)
glyph.applyTransform(scale_up)
Flipping a shape horizontally (mirror)
from PythonQt.QtGui import QTransform
# Scale X by -1 to mirror left-to-right:
mirror = QTransform().scale(-1.0, 1.0)
shape.transformBy(mirror)
Composing multiple operations into one transform
from PythonQt.QtGui import QTransform
# First move to the origin, then scale, then move back:
t = QTransform()
t = t.translate(-centre_x, -centre_y) # move pivot to origin
t = t.scale(0.8, 0.8) # scale down 20%
t = t.translate(centre_x, centre_y) # move back
shape.transformBy(t)
Tutorial
from PythonQt.QtCore import QPointF, QRectF
import fontlab as fl
from fontlab import flTransform
from PythonQt.QtGui import QTransform
font = fl.CurrentFont()
glyph = font['A']
layer = glyph.layers[0]
shape = layer.shapes[0]
# ============================================================
# Creating transforms from scratch
# ============================================================
# The identity transform: wrapping an empty QTransform means
# "apply no change at all". Useful as a starting point.
identity = flTransform()
# A pure translation: move 50 units to the right.
# QTransform().translate(dx, dy) builds the move matrix.
move_right = flTransform(QTransform().translate(50, 0))
# A pure scale: double the width while leaving height unchanged.
# scale(sx, sy) — values > 1 enlarge; values < 1 shrink.
double_wide = flTransform(QTransform().scale(2.0, 1.0))
# A uniform scale: make everything 80% of its original size.
shrink = flTransform(QTransform().scale(0.8, 0.8))
# A rotation: spin 15 degrees clockwise around the origin.
# Qt uses clockwise-positive angles (in a Y-down coordinate system).
rotate15 = flTransform(QTransform().rotate(15))
# ============================================================
# Inspecting a transform
# ============================================================
# Read the raw Qt matrix object:
print("Matrix:", move_right.transform)
# Read the uniform scale factor (useful for checking canvas zoom):
print("Scale factor:", shrink.scale) # should be 0.8
# ============================================================
# Mapping points and rectangles
# ============================================================
# Use map() to find where a point ends up after the transform.
# This is useful for calculating where outlines will land BEFORE
# you actually apply the transform.
pt = QPointF(100, 200)
moved_pt = move_right.map(pt)
print(f"Original: ({pt.x()}, {pt.y()})")
print(f"After move +50: ({moved_pt.x()}, {moved_pt.y()})")
# → (150.0, 200.0)
# Map a bounding rectangle to find the new bounds:
bounds = QRectF(0, 0, 300, 700)
new_bounds = double_wide.mapRect(bounds)
print(f"New width: {new_bounds.width()}") # → 600.0
# ============================================================
# Translating an existing transform
# ============================================================
# translate() modifies the transform in place by adding a move.
# Here we add a vertical shift to the existing horizontal move:
move_right.translate(QPointF(0, 100)) # also move 100 up
# Now move_right will shift (+50 in X, +100 in Y) when applied.
# ============================================================
# Applying transforms to shapes and glyphs
# ============================================================
# Apply a QTransform directly to a shape (the standard way):
shape.transformBy(double_wide.transform)
# Apply to every shape in the glyph across all layers:
glyph.applyTransform(shrink.transform)
# ============================================================
# Composing multiple transforms
# ============================================================
# You can chain Qt operations to build a single combined matrix.
# Operations apply right-to-left (last call is first applied).
# Here: rotate first, then move the result 200 units right.
combined = QTransform()
combined *= QTransform().rotate(45)
combined *= QTransform().translate(200, 0)
shape.transformBy(combined)
# ============================================================
# Resetting to identity (undo any transform)
# ============================================================
# Applying an identity matrix undoes all previous transforms
# by effectively resetting the shape to no-transform state
# (only if you are replacing the transform, not composing).
no_transform = QTransform() # identity matrix
shape.transformBy(no_transform)
fl.Update()
Inherited binding members: flObject.
Constructors: flTransform() flTransform(flTransform) flTransform(flObject) flTransform(QTransform)
Native bases: object
Captured native MRO: flTransform, object
Native new allocation evidence (not an init overload): (args, *kwargs) Create and return a new object. See help(type) for accurate signature.
Supplemental documentation:
A transform object. The captured declaration exposes the attributes transform and scale and the methods map, mapRect and translate. It is created as flTransform(), flTransform(flTransform), flTransform(flObject) or flTransform(QTransform). It also carries the shared object members name, id, type, isValid, release and remove.
Source: FontLab Proteus API documentation
Source: generated/fontlab.py: flTransform captured declaration
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 |
|---|---|---|---|
__init__ |
function | (self, /, *args: Any, **kwargs: Any) -> None |
Initialize self. (shared captured text) |
changed |
function | (self) -> Any |
(shared captured text) |
checkInitHistoryState |
function | (self, history_ix: int) -> Any |
(shared captured text) |
clearAboveHistory |
function | (self, history_ix: int) -> Any |
(shared captured text) |
clearFlag |
function | (self, f: int) -> Any |
(shared captured text) |
clearFlags |
function | (self) -> Any |
(shared captured text) |
clone |
function | (self, *args: Any, **kwargs: Any) -> Any |
Clone the object (shared captured text) |
cloneObject |
function | (*args: Any, **kwargs: Any) -> Any |
(shared captured text) |
createObject |
function | (*args: Any, **kwargs: Any) -> Any |
FlObject/Nothing createObject(int); (shared captured text) |
currentHistoryState |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
flObjectFlags |
attribute | dict |
(shared captured text) |
flag |
function | (self, f: int) -> Any |
(shared captured text) |
getProperties |
function | (self, *args: Any, **kwargs: Any) -> Any |
Get object's properties list (shared captured text) |
getProperty |
function | (self, *args: Any, **kwargs: Any) -> Any |
Get object property by 'key' or number (shared captured text) |
getPropertyFloat |
function | (self, *args: Any, **kwargs: Any) -> Any |
Get float object property by 'key' (shared captured text) |
getPropertyInt |
function | (self, *args: Any, **kwargs: Any) -> Any |
Get int object property by 'key' (shared captured text) |
hasChanges |
attribute | Any |
(shared captured text) |
hasHistoryState |
function | (self, history_ix: int) -> Any |
(shared captured text) |
hasHistoryStates |
attribute | Any |
(shared captured text) |
haveObject |
function | (*args: Any, **kwargs: Any) -> Any |
(shared captured text) |
historyStates |
function | (self, accepted_state: bool) -> Any |
(shared captured text) |
id |
attribute | Any |
Object id (shared captured text) |
independedAll |
function | (self) -> Any |
(shared captured text) |
initialHistoryState |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
instanceType |
function | (*args: Any, **kwargs: Any) -> Any |
(shared captured text) |
isChanged |
attribute | Any |
(shared captured text) |
isEqual |
function | (self, arg0: flObject) -> Any |
(shared captured text) |
isNull |
attribute | Any |
(shared captured text) |
isPresent |
attribute | Any |
(shared captured text) |
isReleased |
attribute | Any |
(shared captured text) |
isValid |
attribute | Any |
(shared captured text) |
map |
function | (self, *args: Any, **kwargs: Any) -> Any |
Pass a point, line, or single number through the transform and return the result. |
mapRect |
function | (self, QRect: Any) -> QRectF |
Pass a rectangle through the transform and return the transformed bounding rectangle. |
name |
attribute | Any |
Object name (shared captured text) |
propertyNames |
function | (self, *args: Any, **kwargs: Any) -> Any |
PropertyNames(): sorted snapshot of dynamic property keys (shared captured text) |
refCnt |
attribute | Any |
Object references count (shared captured text) |
release |
function | (self) -> Any |
(shared captured text) |
remove |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
removeChild |
function | (self, arg0: flObject) -> Any |
(shared captured text) |
restoreHistoryState |
function | (self, history_ix: int) -> Any |
(shared captured text) |
scale |
attribute | Any |
The uniform scale factor extracted from the matrix. |
setFlag |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
setProperty |
function | (self, *args: Any, **kwargs: Any) -> Any |
Set object property by 'key' or number (shared captured text) |
setPropertyFloat |
function | (self, *args: Any, **kwargs: Any) -> Any |
Set float object property by 'key' (shared captured text) |
setPropertyInt |
function | (self, *args: Any, **kwargs: Any) -> Any |
Set int object property by 'key' (shared captured text) |
tag |
function | (self, *args: Any, **kwargs: Any) -> Any |
(shared captured text) |
transform |
attribute | Any |
The underlying Qt transform matrix. |
translate |
function | (self, x: Any, y: float) -> None |
Add a translation (move) to this transform. |
type |
attribute | Any |
Object type (shared captured text) |
update |
function | (self) -> Any |
(shared captured text) |