Class CssDimensionParsingUtils
java.lang.Object
com.itextpdf.styledxmlparser.css.util.CssDimensionParsingUtils
Utilities class for CSS dimension parsing operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Method used in preparation of splitting a string containing a numeric value with a metric unit (e.g.static float
parseAbsoluteFontSize
(String fontSizeValue) Parses the absolute font size.static float
parseAbsoluteFontSize
(String fontSizeValue, String defaultMetric) Parses the absolute font size.static float
parseAbsoluteLength
(String length) Parses the absolute length.static float
parseAbsoluteLength
(String length, String defaultMetric) Parses a length with an allowed metric unit (px, pt, in, cm, mm, pc, q) or numeric value (e.g.static float
parseAngle
(String angle) Parses a angle with an allowed metric unit (deg, grad, rad) or numeric value (e.g.static float
parseAngle
(String angle, String defaultMetric) Parses an angle with an allowed metric unit (deg, grad, rad) or numeric value (e.g.static int[]
parseAspectRatio
(String str) Parses an aspect ratio into an array with two integers.static TransparentColor
parseColor
(String colorValue) Parses either RGBA or CMYK color.static Double
parseDouble
(String str) Parses a double without throwing an exception if something goes wrong.static Float
parseFloat
(String str) Parses a float without throwing an exception if something goes wrong.static Integer
parseInteger
(String str) Parses an integer without throwing an exception if something goes wrong.static UnitValue
parseLengthValueToPt
(String value, float emValue, float remValue) Convenience method for parsing a value to pt.static float
parseRelativeFontSize
(String relativeFontSizeValue, float baseValue) Parses the relative font size.static float
parseRelativeValue
(String relativeValue, float baseValue) Parses an relative value based on the base value that was given, in the metric unit of the base value.
(e.g.static float
parseResolution
(String resolutionStr) Parses the resolution.static float[]
parseRgbaColor
(String colorValue) Parses the RGBA color.static UnitValue[]
parseSpecificCornerBorderRadius
(String specificBorderRadius, float emValue, float remValue) Parses the border radius of specific corner.
-
Method Details
-
parseInteger
Parses an integer without throwing an exception if something goes wrong.- Parameters:
-
str
- a string that might be an integer value - Returns:
- the integer value, or null if something went wrong
-
parseFloat
Parses a float without throwing an exception if something goes wrong.- Parameters:
-
str
- a string that might be a float value - Returns:
- the float value, or null if something went wrong
-
parseDouble
Parses a double without throwing an exception if something goes wrong.- Parameters:
-
str
- a string that might be a double value - Returns:
- the double value, or null if something went wrong
-
parseAngle
Parses an angle with an allowed metric unit (deg, grad, rad) or numeric value (e.g. 123, 1.23, .123) to rad.- Parameters:
-
angle
- String containing the angle to parse -
defaultMetric
- default metric to use in case the input string does not specify a metric - Returns:
- the angle in radians
-
parseAngle
Parses a angle with an allowed metric unit (deg, grad, rad) or numeric value (e.g. 123, 1.23, .123) to rad. Default metric is degrees- Parameters:
-
angle
- String containing the angle to parse - Returns:
- the angle in radians
-
parseAspectRatio
Parses an aspect ratio into an array with two integers.- Parameters:
-
str
- a string that might contain two integer values - Returns:
- the aspect ratio as an array of two integer values
-
parseAbsoluteLength
Parses a length with an allowed metric unit (px, pt, in, cm, mm, pc, q) or numeric value (e.g. 123, 1.23, .123) to pt.
A numeric value (without px, pt, etc in the given length string) is considered to be in the default metric that was given.- Parameters:
-
length
- the string containing the length -
defaultMetric
- the string containing the metric if it is possible that the length string does not contain one. If null the length is considered to be in px as is default in HTML/CSS - Returns:
- parsed value
-
parseAbsoluteLength
Parses the absolute length.- Parameters:
-
length
- the length as a string - Returns:
- the length as a float
-
parseRelativeValue
Parses an relative value based on the base value that was given, in the metric unit of the base value.
(e.g. margin=10% should be based on the page width, so if an A4 is used, the margin = 0.10*595.0 = 59.5f)- Parameters:
-
relativeValue
- in %, em or ex -
baseValue
- the value the returned float is based on - Returns:
- the parsed float in the metric unit of the base value
-
parseLengthValueToPt
Convenience method for parsing a value to pt. Possible values are:- a numeric value in pixels (e.g. 123, 1.23, .123),
- a value with a metric unit (px, in, cm, mm, pc or pt) attached to it,
- or a value with a relative value (%, em, ex).
- Parameters:
-
value
- the value -
emValue
- the em value -
remValue
- the root em value - Returns:
- the unit value
-
parseAbsoluteFontSize
Parses the absolute font size.A numeric value (without px, pt, etc in the given length string) is considered to be in the default metric that was given.
- Parameters:
-
fontSizeValue
- the font size value as aString
-
defaultMetric
- the string containing the metric if it is possible that the length string does not contain one. If null the length is considered to be in px as is default in HTML/CSS. - Returns:
-
the font size value as a
float
-
parseAbsoluteFontSize
Parses the absolute font size.A numeric value (without px, pt, etc in the given length string) is considered to be in the px.
- Parameters:
-
fontSizeValue
- the font size value as aString
- Returns:
-
the font size value as a
float
-
parseRelativeFontSize
Parses the relative font size.- Parameters:
-
relativeFontSizeValue
- the relative font size value as aString
-
baseValue
- the base value - Returns:
-
the relative font size value as a
float
-
parseSpecificCornerBorderRadius
public static UnitValue[] parseSpecificCornerBorderRadius(String specificBorderRadius, float emValue, float remValue) Parses the border radius of specific corner.- Parameters:
-
specificBorderRadius
- string that defines the border radius of specific corner -
emValue
- the em value -
remValue
- the root em value - Returns:
-
an array of
UnitValues
that define horizontal and vertical border radius values
-
parseResolution
Parses the resolution.- Parameters:
-
resolutionStr
- the resolution as a string - Returns:
- a value in dpi
-
parseColor
Parses either RGBA or CMYK color.- Parameters:
-
colorValue
- the color value - Returns:
- an RGBA or CMYK value expressed as an array with four float values
-
parseRgbaColor
Parses the RGBA color.- Parameters:
-
colorValue
- the color value - Returns:
- an RGBA value expressed as an array with four float values
-
determinePositionBetweenValueAndUnit
Method used in preparation of splitting a string containing a numeric value with a metric unit (e.g. 18px, 9pt, 6cm, etc).
Determines the position between digits and affiliated characters ('+','-','0-9' and '.') and all other characters.
e.g. string "16px" will return 2, string "0.5em" will return 3 and string '-8.5mm' will return 4.- Parameters:
-
string
- containing a numeric value with a metric unit - Returns:
- int position between the numeric value and unit or 0 if string is null or string started with a non-numeric value.
-