Class Transform
This class can be used to compose translations, scaling, skewing, rotations, and lightweight 2D approximations of 3D rotations. It is used both for CSS-derived transforms and for programmatically defined layout transformations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class is used to store onetransformfunction. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSingleTransform(Transform.SingleTransform singleTransform) Deprecated.addTransform(Transform.SingleTransform singleTransform) Adds aTransform.SingleTransformin a list of single transforms to process later.static AffineTransformgetAffineTransform(Transform t, float width, float height) Converts theTransforminstance, i.e.rotate(float angle) Appends a counter-clockwise rotation transform.rotate(float angle, float cx, float cy) Appends a counter-clockwise rotation transform around a point offset from the element's center by(cx, cy).Appends a counter-clockwise rotation transform around a pivot point specified asUnitValueoffsets from the element's center.scaleX(float scX) Appends a horizontal scaling transform.scaleY(float scY) Appends a vertical scaling transform.simulateRotateX(float angle) Appends an orthographic 2D approximation of a 3D rotation around the X axis.simulateRotateY(float angle) Appends an orthographic 2D approximation of a 3D rotation around the Y axis.skewX(float skewAngleX) Appends a horizontal skewing (shearing) transform.skewY(float skewAngleY) Appends a vertical skewing (shearing) transform.translate(float x, float y) Appends a translation transform by the given point-unit offsets.Appends a translation transform by the givenUnitValueoffsets.
-
Constructor Details
-
Transform
public Transform()Creates a newTransforminstance. -
Transform
Creates a newTransforminstance.Detailed explanation of
[a b c d e f]parameters of transformation matrix can be found inMatrixdocumentation.- Parameters:
-
a- horizontal scaling -
b- vertical skewing -
c- horizontal skewing -
d- vertical scaling -
e- horizontal translation -
f- vertical translation
-
Transform
Deprecated.in favor ofTransform()Creates a newTransforminstance.- Parameters:
-
length- the amount ofTransform.SingleTransforminstances that thisTransforminstant shall contain and be able to process
-
-
Method Details
-
addSingleTransform
Deprecated.Adds aTransform.SingleTransformin a list of single transforms to process later.- Parameters:
-
singleTransform- aTransform.SingleTransforminstance
-
addTransform
Adds aTransform.SingleTransformin a list of single transforms to process later.- Parameters:
-
singleTransform- aTransform.SingleTransforminstance - Returns:
-
this
Transforminstance
-
translate
Appends a translation transform by the given point-unit offsets.- Parameters:
-
x- the horizontal translation in points -
y- the vertical translation in points - Returns:
-
this
Transforminstance
-
translate
Appends a translation transform by the givenUnitValueoffsets.Both point and percentage values are supported; percentages are resolved relative to the width (for
x) and the height (fory) of the available area at render time. -
scaleX
Appends a horizontal scaling transform.The element is stretched or compressed along the X axis by the given factor. A value of
1leaves the width unchanged, values greater than1widen the element, and values between0and1narrow it.Passing
0collapses the element to zero width, making it invisible. Passing a negative value flips the element horizontally and scales it by the absolute value of the factor.- Parameters:
-
scX- the horizontal scale factor - Returns:
-
this
Transforminstance
-
scaleY
Appends a vertical scaling transform.The element is stretched or compressed along the Y axis by the given factor. A value of
1leaves the height unchanged, values greater than1increase the height, and values between0and1reduce it.Passing
0collapses the element to zero height, making it invisible. Passing a negative value flips the element vertically and scales it by the absolute value of the factor.- Parameters:
-
scY- the vertical scale factor - Returns:
-
this
Transforminstance
-
skewX
Appends a horizontal skewing (shearing) transform.Vertical lines are tilted by the angle given in radians, shifting X coordinates proportionally to their Y position. Equivalent to the CSS
skewX()function.- Parameters:
-
skewAngleX- the skew angle, in radians - Returns:
-
this
Transforminstance
-
skewY
Appends a vertical skewing (shearing) transform.Horizontal lines are tilted by the angle given in radians, shifting Y coordinates proportionally to their X position. Equivalent to the CSS
skewY()function.- Parameters:
-
skewAngleY- the skew angle, in radians - Returns:
-
this
Transforminstance
-
simulateRotateX
Appends an orthographic 2D approximation of a 3D rotation around the X axis.This simulation applies vertical foreshortening only, equivalent to scaling the Y axis by
cos(angle). Perspective distortion is not applied.- Parameters:
-
angle- the rotation angle around the X axis, in radians - Returns:
-
this
Transforminstance
-
simulateRotateY
Appends an orthographic 2D approximation of a 3D rotation around the Y axis.This simulation applies horizontal foreshortening only, equivalent to scaling the X axis by
cos(angle). Perspective distortion is not applied.- Parameters:
-
angle- the rotation angle around the Y axis, in radians - Returns:
-
this
Transforminstance
-
rotate
Appends a counter-clockwise rotation transform.The rotation maps to the affine matrix
[cos θ, sin θ, -sin θ, cos θ, 0, 0], where θ is the supplied angle in radians. A positive angle rotates counter-clockwise in the PDF coordinate system (Y-axis pointing upward).Note: the renderer applies every
Transformcentered on the element's occupied area, so this effectively rotates around the center of the element, not around the element origin (0, 0).To rotate around a point offset from the element's center use
rotate(float, float, float).- Parameters:
-
angle- the counter-clockwise rotation angle, in radians - Returns:
-
this
Transforminstance
-
rotate
Appends a counter-clockwise rotation transform around a point offset from the element's center by(cx, cy).Because the renderer already centers the coordinate system on the element's occupied area before applying the transform,
(cx, cy)are interpreted as offsets from that center. Passing(0, 0)is equivalent to callingrotate(float).A positive angle rotates counter-clockwise in the PDF coordinate system (Y-axis pointing upward).
- Parameters:
-
angle- the counter-clockwise rotation angle, in radians -
cx- horizontal offset from the element's center to the pivot point, in points -
cy- vertical offset from the element's center to the pivot point, in points - Returns:
-
this
Transforminstance
-
rotate
Appends a counter-clockwise rotation transform around a pivot point specified asUnitValueoffsets from the element's center.Both point and percentage
UnitValues are supported. Percentages forcxare resolved relative to the element's width and percentages forcyrelative to its height at render time, consistent with howtranslate(UnitValue, UnitValue)works.Passing
UnitValue.createPointValue(0)for bothcxandcyis equivalent to callingrotate(float). A positive angle rotates counter-clockwise in the PDF coordinate system (Y-axis pointing upward).- Parameters:
-
angle- the counter-clockwise rotation angle, in radians -
cx- horizontal offset from the element's center to the pivot point -
cy- vertical offset from the element's center to the pivot point - Returns:
-
this
Transforminstance
-
getAffineTransform
Converts theTransforminstance, i.e. the list ofTransform.SingleTransforminstances, to the equivalentAffineTransforminstance relatively to the available area, including resolving of percent values to point values.- Parameters:
-
t- aTransforminstance to convert -
width- the width of available area, the point value of which is equivalent to 100% for percentage resolving -
height- the height of available area, the point value of which is equivalent to 100% for percentage resolving - Returns:
-
resulting affine transformation instance, accumulated from
Transform
-
Transform()