PDFium Delphi Component Docs

TPdfMatrix class

Unit: FPdfMatrix
Mutable OO wrapper around PDFium's FS_MATRIX for composing PDF user-space transforms

Syntax

type TPdfMatrix = class ... end;

Related types

TypeDescription
TPdfPointArrayDynamic array of FS_POINTF values used by bulk point operations
TPdfRectArrayDynamic array of FS_RECTF values used by bulk rectangle operations
TPdfMatrixFitModepmfStretch, pmfContain, or pmfCover fitting policy for rectangle mapping
TPdfMatrixDecompositionTranslation, signed scale, clockwise rotation, shear, determinant and reflection diagnostics returned by TryDecompose in the fields TranslationX, TranslationY, ScaleX, ScaleY, RotationDegrees, ShearDegrees, Determinant, and IsReflected

Methods

MemberDescription
CreateCreate an identity matrix, a six-value matrix or a defensive copy from FS_MATRIX
NewTranslationCreate a new translation matrix
NewScaleCreate a new non-uniform scale matrix
NewRotationCreate a clockwise or anticlockwise rotation matrix in degrees or radians
NewSkewCreate a matrix with separate X and Y shear angles
NewRectMappingCreate a matrix that stretches, contains or covers a source rectangle within a destination rectangle
TryCreateRectMappingReturn an FS_MATRIX mapping and reject zero-sized, non-finite or overflowing inputs without allocating an object
ResetReset the matrix to identity
SetElementsReplace all six matrix elements in one call
AssignCopy another TPdfMatrix or raw FS_MATRIX into this instance
CloneCreate an independent object copy
DeterminantReturn the determinant of the linear 2 by 2 component
IsFiniteReport whether every element is a finite Single value
IsIdentityTest identity using a caller-selectable tolerance
IsInvertibleTest finite and scale-aware invertibility without computing an inverse
IsTranslationOnlyTest whether the linear component is identity
IsAxisAlignedTest whether rectangles remain axis aligned, including quarter-turn layouts within tolerance
NearlyEqualsCompare against TPdfMatrix or FS_MATRIX using a tolerance
GetTranslationRead the X and Y translation elements together
SetTranslationReplace the X and Y translation whilst preserving the linear component
ClearTranslationSet both translation elements to zero
TryDecomposeExtract translation, signed scale, clockwise rotation, shear, determinant and reflection state when the matrix is non-singular
MultiplyPost-multiply by another TPdfMatrix or explicit a through f values
PreMultiplyPre-multiply by another TPdfMatrix or explicit six-value matrix
PreTranslatePrepend a translation in the matrix's local input space
PreScalePrepend separate X and Y scale factors
PreRotatePrepend a clockwise or anticlockwise rotation
PreSkewPrepend separate X and Y shear angles
TranslateAppend a translation by deltaX and deltaY
ScaleAppend separate X and Y scale factors
RotateAppend a clockwise or anticlockwise rotation in degrees or radians
HorizontalFlipAppend an X-axis flip
VerticalFlipAppend a Y-axis flip
CentralFlipAppend both axis flips, equivalent to a 180-degree rotation without trigonometry
SkewAppend separate X and Y shear angles
RotateAtAppend a rotation around a pivot that remains fixed
ScaleAtAppend a scale around a pivot that remains fixed
SkewAtAppend a shear around a pivot that remains fixed
HorizontalFlipAtAppend a horizontal flip around a caller-selected X coordinate
VerticalFlipAtAppend a vertical flip around a caller-selected Y coordinate
CentralFlipAtAppend both flips around a caller-selected pivot
MapRectToRectAppend a stretch, contain, or cover mapping between normalised rectangles
InvertReplace the matrix with its inverse or raise EPdfMatrixError when it is singular
TryInvertReplace the matrix with its inverse and return False without mutation when it is singular or near-singular
TryGetInverseCalculate an inverse FS_MATRIX without mutating this instance
InverseCopyCreate an independent inverse matrix or raise EPdfMatrixError when singular
TransformPointMap a coordinate through the affine transform using the PDF row-vector convention
TransformVectorMap a direction through only the linear component so translation is ignored
TryInverseTransformPointMap a point through the inverse without allocating a matrix and report a singular transform as False
InverseTransformPointMap a point through the inverse or raise EPdfMatrixError when singular
TransformQuadMap all four points of an FS_QUADPOINTSF value
TransformPointsMap a point array with one result allocation
TransformPointsInPlaceMap a point array in caller-owned storage without allocating another array
TryTransformBoundsAccumulate transformed point bounds in one pass and return False for empty input
TransformBoundsAccumulate transformed point bounds in one pass or raise EPdfMatrixError for empty input
TransformRectNormalise and map a rectangle through an exact axis-aligned fast path or tight four-corner bounds
TransformRectsMap a rectangle array with one result allocation
TransformRectsInPlaceMap a rectangle array in caller-owned storage without allocating another array

Properties

PropertyTypeDescription
aSingleRead-only first matrix element
bSingleRead-only second matrix element
cSingleRead-only third matrix element
dSingleRead-only fourth matrix element
eSingleRead-only translation X element
fSingleRead-only translation Y element
HandleFS_MATRIXRaw matrix value for PDFium APIs that accept FS_MATRIX or PFS_MATRIX

Description

TPdfMatrix uses the PDF affine layout a b c d e f and post-multiplies each operation, so calls read in the same order as the transforms applied to points

PreMultiply and the Pre* helpers add operations before the current transform, whilst the pivot helpers append translation-operation-translation sequences that keep the chosen pivot fixed

pmfContain preserves the complete source rectangle with centred unused space and pmfCover fills the destination with centred overflow, whilst pmfStretch allows independent X and Y scaling

Bulk point and rectangle methods allocate one output array, their in-place variants allocate none, and TryTransformBounds scans transformed points without constructing an intermediate array

Use Handle with APIs such as FPDFPageObj_SetMatrix, FPDFPageObj_Transform and FPDFText_SetMatrix

Example

var
  Matrix: TPdfMatrix;
begin
  Matrix := TPdfMatrix.Create;
  Matrix.ScaleAt(0.5, 0.5, 144, 144);
  Matrix.RotateAt(15, 144, 144);
  Matrix.Translate(72, 72);
  FPDFPageObj_SetMatrix(ObjectHandle, @Matrix.Handle);
end;

See Also

TPdf.CreateXObjectFromPage, TPdf.InsertFormObjectFromXObject