fontlab.TransformFrame
TransformFrame
Interactive Bounding Frame.
What is TransformFrame?
The TransformFrame is the rectangular selection bounding box you see in FontLab when you choose the Transform tool and select objects. It has eight handles (four corners plus four mid-edge points) that you can drag to scale, rotate, slant, or reflect the selected content. The box can be freely rotated, so it is not always axis-aligned.
In scripts, TransformFrame lets you compute what transform to apply based on dragging one handle to a new position — essentially implementing the math behind FontLab's Transform tool in your own scripts. You build a frame, manipulate it, then call getTransform() to get the resulting QTransform that you apply to the actual geometry.
Handle Query Methods
| Signature | Description |
|---|---|
QPointF mt() |
Returns the mid-top handle position — the midpoint of the top edge. |
QPointF mb() |
Returns the mid-bottom handle position — the midpoint of the bottom edge. |
QPointF ml() |
Returns the mid-left handle position. |
QPointF mr() |
Returns the mid-right handle position. |
QPolygonF polygon() |
Returns the frame as a four-point polygon (the four corners in order: TL, TR, BR, BL). |
double lh() |
The height of the left side of the frame (distance from bl to tl). |
double mh() |
The average height: (lh() + rh()) / 2. Useful when the frame is slightly non-rectangular due to floating-point rounding. |
double rh() |
The height of the right side of the frame (distance from br to tr). |
double tw() |
The width of the top edge (distance from tl to tr). |
double mw() |
The average width: (tw() + bw()) / 2. |
double bw() |
The width of the bottom edge (distance from bl to br). |
QRectF boundingRect() |
Returns the axis-aligned bounding rectangle that fully contains the (possibly rotated) frame. |
Transformation Methods
| Signature | Description |
|---|---|
TransformFrame getMapped(QTransform t) |
Returns a new TransformFrame with all four corners mapped through the transform t. Use this to preview what the frame will look like after a transformation, without modifying the original frame. |
QPointF getControlPos(TransformFrameControls) |
Returns the current canvas position of one of the eight control handles. Pass a TransformFrameControls enum value: TL, TR, BL, BR, MT, MB, ML, or MR. |
void translate(QPointF) |
Moves the entire frame by the given offset vector. All four corners are shifted by the same amount. |
void rotate(double) |
Rotates the frame by the given angle in degrees, counter-clockwise. The frame rotates around its centre point cr. |
void scale(QPointF s) |
Scales the frame: s.x() is the horizontal scale factor, s.y() is the vertical. Values greater than 1 enlarge; values less than 1 shrink. Scaling is relative to the frame's centre. |
void slant(double angle, double angle) |
Applies an oblique (slant) transform using the given horizontal and vertical angle values. This is what the Slant action uses internally. |
void horizontalReflection() |
Mirrors the frame horizontally: left becomes right, right becomes left. The centre stays fixed. |
void verticalReflection() |
Mirrors the frame vertically: top becomes bottom. The centre stays fixed. |
void flipHorizontal() |
Flips the frame horizontally (same effect as horizontalReflection). |
void flipVertical() |
Flips the frame vertically (same as verticalReflection). |
void rotate180() |
Rotates the frame exactly 180 degrees. Equivalent to both a horizontal and a vertical flip. |
void initCenter() |
Recomputes the centre point cr from the current corner positions. Always call this after manually repositioning corners so that rotations and scales pivot correctly. |
void doTransformation(int code, QPointF value) |
Applies a transformation identified by code (a TransformFrameControls integer) by the delta value. This is the core method behind drag-to-transform interactions — it is what gets called when you drag a handle in the editor. |
QTransform getTransform() |
Returns the net QTransform that maps the original (pre-interaction) frame to its current state. Apply this transform to the selected objects to commit the change to the geometry. |
void prepareTransformations([TransformFrameControls control, QPointF p,] double scale) |
Prepares the frame for an interactive transformation session. scale is the current canvas zoom factor. Optionally constrain to one control point and provide the starting mouse position p. |
void setControlPos([TransformFrameControls control,] QPointF position, bool reflection, bool proportional, bool fixed) |
Moves a handle to position. reflection mirrors the change to the opposite handle symmetrically; proportional locks the aspect ratio; fixed locks the opposite side in place. |
void setProjectionPos([TransformFrameControls control,] QPointF position, bool reflection, bool proportional, bool fixed) |
Like setControlPos but uses perspective-preserving (projection) mathematics for the handle movement. Used for the Perspective transformation. |
Corner Properties
| Name | Type | Access | Description |
|---|---|---|---|
tl |
QPointF |
rw | Top-left corner of the frame. |
tr |
QPointF |
rw | Top-right corner of the frame. |
bl |
QPointF |
rw | Bottom-left corner of the frame. |
br |
QPointF |
rw | Bottom-right corner of the frame. |
cr |
QPointF |
rw | Centre point of the frame. This is the pivot used for rotations and scales. Call initCenter() to recompute it from corners. |
Tutorial
from PythonQt.QtCore import QPointF
import fontlab as fl
from fontlab import TransformFrame
# ============================================================
# Goal: Scale a shape 2× horizontally using TransformFrame.
#
# The workflow is:
# 1. Get the shape's bounding box
# 2. Build a TransformFrame that matches it
# 3. Apply a transformation to the frame
# 4. Retrieve the resulting QTransform via getTransform()
# 5. Apply that QTransform to the actual shape geometry
# ============================================================
font = fl.CurrentFont()
glyph = font['A']
layer = glyph.layers[0]
shape = layer.shapes[0]
bbox = shape.boundingBox # returns a QRectF in glyph units
print(f"Shape bounding box: {bbox}")
# ============================================================
# Step 1: Build a frame from the bounding box corners.
# We set the four corners manually, then call initCenter()
# so that rotations and scales use the correct pivot point.
# ============================================================
frame = TransformFrame()
frame.tl = QPointF(bbox.left(), bbox.top())
frame.tr = QPointF(bbox.right(), bbox.top())
frame.bl = QPointF(bbox.left(), bbox.bottom())
frame.br = QPointF(bbox.right(), bbox.bottom())
frame.initCenter() # compute centre from corners
print(f"Frame centre: {frame.cr}")
print(f"Frame width: {frame.mw():.0f}")
print(f"Frame height: {frame.mh():.0f}")
# ============================================================
# Step 2: Scale the frame — 2× wide, same height.
# scale() takes a QPointF where x = horizontal factor,
# y = vertical factor.
# ============================================================
frame.scale(QPointF(2.0, 1.0))
print(f"\nAfter 2× horizontal scale:")
print(f" New width: {frame.mw():.0f}")
# ============================================================
# Step 3: Get the net transform and apply it to the shape.
# getTransform() returns the QTransform that maps the
# original frame to the current (scaled) frame.
# ============================================================
tx = frame.getTransform()
print(f"Net transform: {tx}")
shape.transformBy(tx)
fl.Update()
print("Done — shape scaled 2× horizontally.")
Common Scripting Patterns
Rotate a shape 45 degrees around its centre
from PythonQt.QtCore import QPointF
import fontlab as fl
from fontlab import TransformFrame
font = fl.CurrentFont()
glyph = font['A']
layer = glyph.layers[0]
shape = layer.shapes[0]
bbox = shape.boundingBox
frame = TransformFrame()
frame.tl = QPointF(bbox.left(), bbox.top())
frame.tr = QPointF(bbox.right(), bbox.top())
frame.bl = QPointF(bbox.left(), bbox.bottom())
frame.br = QPointF(bbox.right(), bbox.bottom())
frame.initCenter()
frame.rotate(45.0) # degrees, counter-clockwise
shape.transformBy(frame.getTransform())
fl.Update()
Mirror a shape horizontally
from PythonQt.QtCore import QPointF
import fontlab as fl
from fontlab import TransformFrame
font = fl.CurrentFont()
glyph = font['d']
layer = glyph.layers[0]
shape = layer.shapes[0]
bbox = shape.boundingBox
frame = TransformFrame()
frame.tl = QPointF(bbox.left(), bbox.top())
frame.tr = QPointF(bbox.right(), bbox.top())
frame.bl = QPointF(bbox.left(), bbox.bottom())
frame.br = QPointF(bbox.right(), bbox.bottom())
frame.initCenter()
frame.horizontalReflection()
shape.transformBy(frame.getTransform())
fl.Update()
print("Shape mirrored — 'd' now looks like 'b'.")
Constructors:
Native bases: object
Captured native MRO: TransformFrame, 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 transformation frame. The captured declaration exposes the transformation methods translate, scale, rotate, rotate180, slant, flipHorizontal, flipVertical, horizontalReflection, verticalReflection and doTransformation, the geometry methods boundingRect, polygon, expandPolygon, getMapped, getTransform, initCenter and prepareTransformations, the control methods getControlPos, setControlPos and setProjectionPos, the size and margin methods bw, lh, mb, mh, ml, mr, mt, mw, rh and tw, and the attributes tl, tr, bl, br and cr. It is created with no captured constructor overloads.
Source: FontLab Proteus API documentation
Source: generated/fontlab.py: TransformFrame 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) |
bl |
attribute | Any |
|
boundingRect |
function | (self) -> QRectF |
|
br |
attribute | Any |
|
bw |
function | (self) -> float |
|
cr |
attribute | Any |
|
doTransformation |
function | (self, code: int, value: QPointF) -> None |
|
expandPolygon |
function | (polygon: QPolygonF) -> QPolygonF |
Expands the given polygon outwards by the handle hit-test radius. |
flipHorizontal |
function | (self) -> None |
|
flipVertical |
function | (self) -> None |
|
getControlPos |
function | (self, TransformFrameControls: Any) -> QPointF |
|
getMapped |
function | (self, t: QTransform) -> Any |
|
getTransform |
function | (self) -> QTransform |
|
horizontalReflection |
function | (self) -> None |
|
initCenter |
function | (self) -> None |
|
lh |
function | (self) -> float |
|
mb |
function | (self) -> QPointF |
|
mh |
function | (self) -> float |
|
ml |
function | (self) -> QPointF |
|
mr |
function | (self) -> QPointF |
|
mt |
function | (self) -> QPointF |
|
mw |
function | (self) -> float |
|
polygon |
function | (self) -> QPolygonF |
|
prepareTransformations |
function | (self, scale: Any) -> None |
|
rh |
function | (self) -> float |
|
rotate |
function | (self, double: Any) -> None |
|
rotate180 |
function | (self) -> None |
|
scale |
function | (self, s: QPointF) -> None |
|
setControlPos |
function | (self, position: Any, reflection: bool, proportional: bool, fixed: bool) -> None |
|
setProjectionPos |
function | (self, position: Any, reflection: bool, proportional: bool, fixed: bool) -> None |
|
slant |
function | (self, *args: Any, **kwargs: Any) -> Any |
|
tl |
attribute | Any |
|
tr |
attribute | Any |
|
translate |
function | (self, arg0: QPointF) -> None |
|
tw |
function | (self) -> float |
|
verticalReflection |
function | (self) -> None |