Class Transform

java.lang.Object
com.itextpdf.layout.properties.Transform

public class Transform extends Object
Represents a sequence of 2D transformations to be applied during rendering.

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.

  • Constructor Details

    • Transform

      public Transform()
      Creates a new Transform instance.
    • Transform

      public Transform (float a, float b, float c, float d, UnitValue e, UnitValue f)
      Creates a new Transform instance.

      Detailed explanation of [a b c d e f] parameters of transformation matrix can be found in Matrix documentation.

      Parameters:
      a - horizontal scaling
      b - vertical skewing
      c - horizontal skewing
      d - vertical scaling
      e - horizontal translation
      f - vertical translation
    • Transform

      @Deprecated public Transform (int length)
      Deprecated.
      in favor of Transform()
      Creates a new Transform instance.
      Parameters:
      length - the amount of Transform.SingleTransform instances that this Transform instant shall contain and be able to process
  • Method Details

    • addSingleTransform

      @Deprecated public void addSingleTransform (Transform.SingleTransform singleTransform)
      Adds a Transform.SingleTransform in a list of single transforms to process later.
      Parameters:
      singleTransform - a Transform.SingleTransform instance
    • addTransform

      public Transform addTransform (Transform.SingleTransform singleTransform)
      Adds a Transform.SingleTransform in a list of single transforms to process later.
      Parameters:
      singleTransform - a Transform.SingleTransform instance
      Returns:
      this Transform instance
    • translate

      public Transform translate (float x, float y)
      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 Transform instance
    • translate

      public Transform translate (UnitValue x, UnitValue y)
      Appends a translation transform by the given UnitValue offsets.

      Both point and percentage values are supported; percentages are resolved relative to the width (for x) and the height (for y) of the available area at render time.

      Parameters:
      x - the horizontal translation as a UnitValue
      y - the vertical translation as a UnitValue
      Returns:
      this Transform instance
    • scaleX

      public Transform scaleX (float scX)
      Appends a horizontal scaling transform.

      The element is stretched or compressed along the X axis by the given factor. A value of 1 leaves the width unchanged, values greater than 1 widen the element, and values between 0 and 1 narrow it.

      Passing 0 collapses 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 Transform instance
    • scaleY

      public Transform scaleY (float scY)
      Appends a vertical scaling transform.

      The element is stretched or compressed along the Y axis by the given factor. A value of 1 leaves the height unchanged, values greater than 1 increase the height, and values between 0 and 1 reduce it.

      Passing 0 collapses 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 Transform instance
    • skewX

      public Transform skewX (float skewAngleX)
      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 Transform instance
    • skewY

      public Transform skewY (float skewAngleY)
      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 Transform instance
    • simulateRotateX

      public Transform simulateRotateX (float angle)
      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 Transform instance
    • simulateRotateY

      public Transform simulateRotateY (float angle)
      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 Transform instance
    • rotate

      public Transform rotate (float angle)
      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 Transform centered 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 Transform instance
    • rotate

      public 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).

      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 calling rotate(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 Transform instance
    • rotate

      public Transform rotate (float angle, UnitValue cx, UnitValue cy)
      Appends a counter-clockwise rotation transform around a pivot point specified as UnitValue offsets from the element's center.

      Both point and percentage UnitValues are supported. Percentages for cx are resolved relative to the element's width and percentages for cy relative to its height at render time, consistent with how translate(UnitValue, UnitValue) works.

      Passing UnitValue.createPointValue(0) for both cx and cy is equivalent to calling rotate(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 Transform instance
    • getAffineTransform

      public static AffineTransform getAffineTransform (Transform t, float width, float height)
      Converts the Transform instance, i.e. the list of Transform.SingleTransform instances, to the equivalent AffineTransform instance relatively to the available area, including resolving of percent values to point values.
      Parameters:
      t - a Transform instance 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