Class TransformUtils

java.lang.Object
com.itextpdf.svg.utils.TransformUtils

public final class TransformUtils extends Object
Utility class responsible for converting Strings containing transformation declarations into AffineTransform objects.

This class only supports the transformations as described in the SVG specification: - matrix - rotate - scale - skewX - skewY - translate

  • Field Details

    • MATRIX

      private static final String MATRIX
      Keyword for matrix transformations. Accepts 6 values.

      matrix(0 1 2 3 4 5)

      See Also:
    • ROTATE

      private static final String ROTATE
      Keyword for rotation transformation. Accepts either 1 or 3 values. In the case of 1 value, x and y are assumed to be the origin of the user space.

      rotate(angle x y) rotate(angle)

      See Also:
    • SCALE

      private static final String SCALE
      Keyword for scale transformation. Accepts either 1 or 2 values. In the case of 1 value, the second value is assumed to be the same as the first one.

      scale(x y) scale(x)

      See Also:
    • SKEWX

      private static final String SKEWX
      Keyword for skewX transformation. Accepts 1 value.

      skewX(angle)

      See Also:
    • SKEWY

      private static final String SKEWY
      Keyword for skewY transformation. Accepts 1 value.

      skewY(angle)

      See Also:
    • TRANSLATE

      private static final String TRANSLATE
      Keyword for translate transformation. Accepts either 1 or 2 values. In the case of 1 value, the y value is assumed to be 0.

      translate(x y) translate(x)

      See Also:
  • Constructor Details

    • TransformUtils

      private TransformUtils()
  • Method Details

    • parseTransform

      public static AffineTransform parseTransform(String transform)
      Converts a string containing a transform declaration into an AffineTransform object. This class only supports the transformations as described in the SVG specification: - matrix - translate - skewx - skewy - rotate - scale
      Parameters:
      transform - value to be parsed
      Returns:
      the AffineTransform object
    • splitString

      private static List<String> splitString(String transform)
      A transformation attribute can encompass multiple transformation operation (e.g. "translate(10,20) scale(30,40)". This method splits the original transformation string into multiple strings so that they can be handled separately.
      Parameters:
      transform - the transformation value
      Returns:
      a list containing strings describing a single transformation operation
    • transformationStringToMatrix

      private static AffineTransform transformationStringToMatrix(String transformation)
      This method decides which transformation operation the given transformation strings maps onto.
      Parameters:
      transformation - string containing a transformation operation
      Returns:
      the mapped AffineTransform object
    • createSkewYTransformation

      private static AffineTransform createSkewYTransformation(List<String> values)
      Creates a skewY transformation.
      Parameters:
      values - values of the transformation
      Returns:
      AffineTransform for the skew operation
    • createSkewXTransformation

      private static AffineTransform createSkewXTransformation(List<String> values)
      Creates a skewX transformation.
      Parameters:
      values - values of the transformation
      Returns:
      AffineTransform for the skew operation
    • createRotationTransformation

      private static AffineTransform createRotationTransformation(List<String> values)
      Creates a rotate transformation.
      Parameters:
      values - values of the transformation
      Returns:
      AffineTransform for the rotate operation
    • createScaleTransformation

      private static AffineTransform createScaleTransformation(List<String> values)
      Creates a scale transformation.
      Parameters:
      values - values of the transformation
      Returns:
      AffineTransform for the scale operation
    • createTranslateTransformation

      private static AffineTransform createTranslateTransformation(List<String> values)
      Creates a translate transformation.
      Parameters:
      values - values of the transformation
      Returns:
      AffineTransform for the translate operation
    • createMatrixTransformation

      private static AffineTransform createMatrixTransformation(List<String> values)
      Creates a matrix transformation.
      Parameters:
      values - values of the transformation
      Returns:
      AffineTransform for the matrix keyword
    • getNameFromString

      private static String getNameFromString(String transformation)
      This method extracts the transformation name given a transformation.
      Parameters:
      transformation - the transformation
      Returns:
      the name of the transformation
    • getValuesFromTransformationString

      private static List<String> getValuesFromTransformationString(String transformation)
      This method extracts the values from a transformation.
      Parameters:
      transformation - the transformation
      Returns:
      values of the transformation