Package com.itextpdf.svg.utils
Class SvgCoordinateUtils
- java.lang.Object
-
- com.itextpdf.svg.utils.SvgCoordinateUtils
-
public class SvgCoordinateUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description SvgCoordinateUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Rectangle
applyViewBox(Rectangle viewBox, Rectangle currentViewPort, java.lang.String align, java.lang.String meetOrSlice)
Returns the viewBox received after scaling and displacement given preserveAspectRatio.static double
calculateAngleBetweenTwoVectors(Vector vectorA, Vector vectorB)
Calculate the angle between two vectorsstatic double
getCoordinateForObjectBoundingBox(java.lang.String attributeValue, double defaultValue)
Returns a value relative to the object bounding box.static double
getCoordinateForUserSpaceOnUse(java.lang.String attributeValue, double defaultValue, double start, double length, float em, float rem)
Returns absolute value for attribute in userSpaceOnUse coordinate system.private static double
getScaleWidthHeight(Rectangle viewBox, Rectangle currentViewPort, java.lang.String meetOrSlice)
static java.lang.String[]
makeRelativeOperatorCoordinatesAbsolute(java.lang.String[] relativeCoordinates, double[] currentCoordinates)
Converts relative coordinates to absolute ones.
-
-
-
Method Detail
-
makeRelativeOperatorCoordinatesAbsolute
public static java.lang.String[] makeRelativeOperatorCoordinatesAbsolute(java.lang.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 coordinatescurrentCoordinates
- 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 vectorvectorB
- second vector- Returns:
- angle between vectors in radians units
-
getCoordinateForUserSpaceOnUse
public static double getCoordinateForUserSpaceOnUse(java.lang.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(java.lang.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 parsedefaultValue
- 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, java.lang.String align, java.lang.String meetOrSlice)
Returns the viewBox received after scaling and displacement given preserveAspectRatio.- Parameters:
viewBox
- parsed viewBox rectangle. It should be a validRectangle
currentViewPort
- current element view port. It should be a validRectangle
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 isnull
or align is invalid (i.e. not in the predefined list), then the default logic with align = "xMidYMid", and meetOrSlice = "meet" would be usedmeetOrSlice
- the way to scale the viewBox. If meetOrSlice is notnull
and invalid, then the default logic with align = "xMidYMid" and meetOrSlice = "meet" would be used, if meetOrSlice isnull
then default "meet" value would be used with the specified align- Returns:
- the applied viewBox
Rectangle
-
-