Class SvgCssUtils
java.lang.Object
com.itextpdf.svg.utils.SvgCssUtils
Utility class that facilitates parsing values from CSS.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static floatcalculateFinalSvgRendererLength(String length, float em, float rem, float percentBase) private static floatcalculatePercentBaseValueIfNeeded(AbstractSvgNodeRenderer svgNodeRenderer, SvgDrawContext context, String length, boolean isXAxis) static StringconvertDoubleToString(double value) Deprecated.static StringconvertFloatToString(float value) Deprecated.can be replaced byFloat.toString(float)static RectangleextractWidthAndHeight(ISvgNodeRenderer svgRenderer, float em, SvgDrawContext context) Extract width and height of the passed SVGNodeRenderer, defaulting toSvgDrawContext.getCustomViewport()if either one is not present.static floatparseAbsoluteHorizontalLength(AbstractSvgNodeRenderer svgNodeRenderer, String length, float defaultValue, SvgDrawContext context) Parses horizontal length attribute and converts it to an absolute value.static floatparseAbsoluteLength(AbstractSvgNodeRenderer svgNodeRenderer, String length, float percentBaseValue, float defaultValue, SvgDrawContext context) Parse length attribute and convert it to an absolute value.static floatparseAbsoluteVerticalLength(AbstractSvgNodeRenderer svgNodeRenderer, String length, float defaultValue, SvgDrawContext context) Parses vertical length attribute and converts it to an absolute value.static float[]parseViewBox(ISvgNodeRenderer svgRenderer) Extract svg viewbox values.splitValueList(String value) Splits a given String into a list of substrings.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
-
Constructor Details
-
SvgCssUtils
private SvgCssUtils()
-
-
Method Details
-
splitValueList
Splits a given String into a list of substrings. The string is split up by commas and whitespace characters (\t, \n, \r, \f).- Parameters:
value- the string to be split- Returns:
- a list containing the split strings, an empty list if the value is null or empty
-
convertFloatToString
Deprecated.can be replaced byFloat.toString(float)Converts a float to a String.- Parameters:
value- to be converted float value- Returns:
- the value in a String representation
-
convertDoubleToString
Deprecated.can be replaced byDouble.toString(float)Converts a double to a String.- Parameters:
value- to be converted double value- Returns:
- the value in a String representation
-
parseAbsoluteLength
public static float parseAbsoluteLength(AbstractSvgNodeRenderer svgNodeRenderer, String length, float percentBaseValue, float defaultValue, SvgDrawContext context) Parse length attribute and convert it to an absolute value.- Parameters:
svgNodeRenderer- renderer for which length should be parsedlength-Stringfor parsingpercentBaseValue- the value on which percent length is based ondefaultValue- default value if length is not recognizedcontext- currentSvgDrawContext- Returns:
- absolute value in points
-
parseAbsoluteVerticalLength
public static float parseAbsoluteVerticalLength(AbstractSvgNodeRenderer svgNodeRenderer, String length, float defaultValue, SvgDrawContext context) Parses vertical length attribute and converts it to an absolute value.- Parameters:
svgNodeRenderer- renderer for which length should be parsedlength-Stringfor parsingdefaultValue- default value if length is not recognizedcontext- currentSvgDrawContext- Returns:
- absolute value in points
-
parseAbsoluteHorizontalLength
public static float parseAbsoluteHorizontalLength(AbstractSvgNodeRenderer svgNodeRenderer, String length, float defaultValue, SvgDrawContext context) Parses horizontal length attribute and converts it to an absolute value.- Parameters:
svgNodeRenderer- renderer for which length should be parsedlength-Stringfor parsingdefaultValue- default value if length is not recognizedcontext- currentSvgDrawContext- Returns:
- absolute value in points
-
parseViewBox
Extract svg viewbox values.- Parameters:
svgRenderer- theISvgNodeRendererinstance that contains the renderer tree- Returns:
- float[4] or null, if no correct viewbox property is present.
-
extractWidthAndHeight
public static Rectangle extractWidthAndHeight(ISvgNodeRenderer svgRenderer, float em, SvgDrawContext context) Extract width and height of the passed SVGNodeRenderer, defaulting toSvgDrawContext.getCustomViewport()if either one is not present. IfSvgDrawContext.getCustomViewport()isn't specified, than respective viewbox values or browser default (if viewbox is missing) will be used.- Parameters:
svgRenderer- theISvgNodeRendererinstance that contains the renderer treeem- em value in ptcontext- the svg draw context- Returns:
- rectangle, where x,y = 0 and width and height are extracted ones by this method.
-
calculateFinalSvgRendererLength
private static float calculateFinalSvgRendererLength(String length, float em, float rem, float percentBase) -
calculatePercentBaseValueIfNeeded
private static float calculatePercentBaseValueIfNeeded(AbstractSvgNodeRenderer svgNodeRenderer, SvgDrawContext context, String length, boolean isXAxis)
-
Double.toString(float)