Class SvgCoordinateUtils

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

public class SvgCoordinateUtils extends Object
  • Constructor Details

    • SvgCoordinateUtils

      public SvgCoordinateUtils()
  • Method Details

    • makeRelativeOperatorCoordinatesAbsolute

      public static String[] makeRelativeOperatorCoordinatesAbsolute(String[] relativeCoordinates, double[] currentCoordinates)
      Converts relative coordinates to absolute ones. Assumes that relative coordinates are represented by an array of coordinates with length proportional to the length of current coordinates array, so that current coordinates array is applied in segments to the relative coordinates array
      Parameters:
      relativeCoordinates - the initial set of coordinates
      currentCoordinates - an array representing the point relative to which the relativeCoordinates are defined
      Returns:
      a String array of absolute coordinates, with the same length as the input array
    • calculateAngleBetweenTwoVectors

      public static double calculateAngleBetweenTwoVectors(Vector vectorA, Vector vectorB)
      Calculate the angle between two vectors
      Parameters:
      vectorA - first vector
      vectorB - second vector
      Returns:
      angle between vectors in radians units
    • getCoordinateForUserSpaceOnUse

      public static double getCoordinateForUserSpaceOnUse(String attributeValue, double defaultValue, double start, double length, float em, float rem)
      Returns absolute value for attribute in userSpaceOnUse coordinate system.
      Parameters:
      attributeValue - value of attribute.
      defaultValue - default value.
      start - start border for calculating percent value.
      length - length for calculating percent value.
      em - em value.
      rem - rem value.
      Returns:
      absolute value in the userSpaceOnUse coordinate system.
    • getCoordinateForObjectBoundingBox

      public static double getCoordinateForObjectBoundingBox(String attributeValue, double defaultValue)
      Returns a value relative to the object bounding box. We should only call this method for attributes with coordinates relative to the object bounding rectangle.
      Parameters:
      attributeValue - attribute value to parse
      defaultValue - this value will be returned if an error occurs while parsing the attribute value
      Returns:
      if attributeValue is a percentage value, the given percentage of 1 will be returned. And if it's a valid value with a number, the number will be extracted from that value.
    • applyViewBox

      public static Rectangle applyViewBox(Rectangle viewBox, Rectangle currentViewPort, String align, String meetOrSlice)
      Returns the viewBox received after scaling and displacement given preserveAspectRatio.
      Parameters:
      viewBox - parsed viewBox rectangle. It should be a valid Rectangle
      currentViewPort - current element view port. It should be a valid Rectangle
      align - the alignment value that indicates whether to force uniform scaling and, if so, the alignment method to use in case the aspect ratio of the viewBox doesn't match the aspect ratio of the viewport. If align is null or align is invalid (i.e. not in the predefined list), then the default logic with align = "xMidYMid", and meetOrSlice = "meet" would be used
      meetOrSlice - the way to scale the viewBox. If meetOrSlice is not null and invalid, then the default logic with align = "xMidYMid" and meetOrSlice = "meet" would be used, if meetOrSlice is null then default "meet" value would be used with the specified align
      Returns:
      the applied viewBox Rectangle
    • getScaleWidthHeight

      private static double getScaleWidthHeight(Rectangle viewBox, Rectangle currentViewPort, String meetOrSlice)