Class CssUtils
- java.lang.Object
-
- com.itextpdf.styledxmlparser.css.util.CssUtils
-
public class CssUtils extends java.lang.Object
Utilities class for CSS operations.
-
-
Field Summary
Fields Modifier and Type Field Description private static float
EPSILON
private static org.slf4j.Logger
logger
private static int
QUANTITY_OF_PARAMS_WITH_FALLBACK_OR_TYPE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static boolean
addRange(RangeBuilder builder, java.lang.String range)
private static boolean
addRange(RangeBuilder builder, java.lang.String left, java.lang.String right)
static boolean
compareFloats(double d1, double d2)
Helper method for comparing floating point numbersstatic boolean
compareFloats(float f1, float f2)
Helper method for comparing floating point numbersstatic double
convertPtsToPx(double pts)
Convert given point value to a pixel value.static float
convertPtsToPx(float pts)
Convert given point value to a pixel value.static double
convertPxToPts(double px)
Convert given point value to a point value.static float
convertPxToPts(float px)
Convert given point value to a point value.static java.lang.String
extractAttributeValue(java.lang.String attrStr, IElementNode element)
Parses string and return attribute value.private static java.lang.String
extractFallback(java.lang.String fallbackString)
static java.util.List<java.util.List<java.lang.String>>
extractShorthandProperties(java.lang.String str)
Extracts shorthand properties as list of string lists from a string, where the top level list is shorthand property and the lower level list is properties included in shorthand property.private static java.lang.String
extractTypeOfAttribute(java.lang.String typeString)
static java.lang.String
extractUnquotedString(java.lang.String str)
Unquotes the passed string, e.g.static java.lang.String
extractUrl(java.lang.String url)
Parsesurl("file.jpg")
tofile.jpg
.static int
findNextUnescapedChar(java.lang.String source, char ch, int startIndex)
Find the next unescaped character.private static java.lang.String
getAttributeValue(java.lang.String attributeName, java.lang.String typeOfAttribute, java.lang.String fallback, IElementNode elementNode)
private static boolean
isAttributeNameValid(java.lang.String attributeName)
static boolean
isStyleSheetLink(IElementNode headChildElement)
Checks if anIElementNode
represents a style sheet link.static java.lang.String
normalizeCssProperty(java.lang.String str)
Normalizes a CSS property.static BlendMode
parseBlendMode(java.lang.String cssValue)
Parses the given css blend mode value.static Range
parseUnicodeRange(java.lang.String unicodeRange)
Parses the unicode range.static java.lang.String
removeDoubleSpacesAndTrim(java.lang.String str)
Removes double spaces and trims a string.static java.util.List<java.lang.String>
splitString(java.lang.String value, char splitChar, EscapeGroup... escapeCharacters)
Splits the providedString
by split character with respect of escape characters.static java.util.List<java.lang.String>
splitStringWithComma(java.lang.String value)
Splits the providedString
by comma with respect of brackets.
-
-
-
Field Detail
-
EPSILON
private static final float EPSILON
- See Also:
- Constant Field Values
-
logger
private static final org.slf4j.Logger logger
-
QUANTITY_OF_PARAMS_WITH_FALLBACK_OR_TYPE
private static final int QUANTITY_OF_PARAMS_WITH_FALLBACK_OR_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CssUtils
private CssUtils()
Creates a newCssUtils
instance.
-
-
Method Detail
-
splitStringWithComma
public static java.util.List<java.lang.String> splitStringWithComma(java.lang.String value)
Splits the providedString
by comma with respect of brackets.- Parameters:
value
- to split- Returns:
- the
List
of split result
-
splitString
public static java.util.List<java.lang.String> splitString(java.lang.String value, char splitChar, EscapeGroup... escapeCharacters)
Splits the providedString
by split character with respect of escape characters.- Parameters:
value
- value to splitsplitChar
- character to split the StringescapeCharacters
- escape characters- Returns:
- the
List
of split result
-
parseBlendMode
public static BlendMode parseBlendMode(java.lang.String cssValue)
Parses the given css blend mode value. If the argument isnull
or an unknown blend mode, then the default cssBlendMode.NORMAL
value would be returned.- Parameters:
cssValue
- the value to parse- Returns:
- the
BlendMode
instance representing the parsed value
-
extractShorthandProperties
public static java.util.List<java.util.List<java.lang.String>> extractShorthandProperties(java.lang.String str)
Extracts shorthand properties as list of string lists from a string, where the top level list is shorthand property and the lower level list is properties included in shorthand property.- Parameters:
str
- the source string with shorthand properties- Returns:
- the list of string lists
-
normalizeCssProperty
public static java.lang.String normalizeCssProperty(java.lang.String str)
Normalizes a CSS property.- Parameters:
str
- the property- Returns:
- the normalized property
-
removeDoubleSpacesAndTrim
public static java.lang.String removeDoubleSpacesAndTrim(java.lang.String str)
Removes double spaces and trims a string.- Parameters:
str
- the string- Returns:
- the string without the unnecessary spaces
-
extractUrl
public static java.lang.String extractUrl(java.lang.String url)
Parsesurl("file.jpg")
tofile.jpg
.- Parameters:
url
- the url attribute to parse- Returns:
- the parsed url. Or original url if not wrappend in url()
-
extractUnquotedString
public static java.lang.String extractUnquotedString(java.lang.String str)
Unquotes the passed string, e.g. parse"text"
totext
.- Parameters:
str
- the quotes string- Returns:
- the unquoted string, or original
str
if not wrapped in quotes
-
extractAttributeValue
public static java.lang.String extractAttributeValue(java.lang.String attrStr, IElementNode element)
Parses string and return attribute value.- Parameters:
attrStr
- the string contains attr() to extract attribute valueelement
- the parentNode from which we extract information- Returns:
- the value of attribute
-
findNextUnescapedChar
public static int findNextUnescapedChar(java.lang.String source, char ch, int startIndex)
Find the next unescaped character.- Parameters:
source
- a sourcech
- the character to look forstartIndex
- where to start looking- Returns:
- the position of the next unescaped character
-
compareFloats
public static boolean compareFloats(double d1, double d2)
Helper method for comparing floating point numbers- Parameters:
d1
- first float to compared2
- second float to compare- Returns:
- True if both floats are equal within a Epsilon defined in this class, false otherwise
-
compareFloats
public static boolean compareFloats(float f1, float f2)
Helper method for comparing floating point numbers- Parameters:
f1
- first float to comparef2
- second float to compare- Returns:
- True if both floats are equal within a Epsilon defined in this class, false otherwise
-
parseUnicodeRange
public static Range parseUnicodeRange(java.lang.String unicodeRange)
Parses the unicode range.- Parameters:
unicodeRange
- the string which stores the unicode range- Returns:
- the unicode range as a
Range
object
-
convertPtsToPx
public static float convertPtsToPx(float pts)
Convert given point value to a pixel value. 1 px is 0.75 pts.- Parameters:
pts
- float value to be converted to pixels- Returns:
- float converted value pts/0.75f
-
convertPtsToPx
public static double convertPtsToPx(double pts)
Convert given point value to a pixel value. 1 px is 0.75 pts.- Parameters:
pts
- double value to be converted to pixels- Returns:
- double converted value pts/0.75
-
convertPxToPts
public static float convertPxToPts(float px)
Convert given point value to a point value. 1 px is 0.75 pts.- Parameters:
px
- float value to be converted to pixels- Returns:
- float converted value px*0.75
-
convertPxToPts
public static double convertPxToPts(double px)
Convert given point value to a point value. 1 px is 0.75 pts.- Parameters:
px
- double value to be converted to pixels- Returns:
- double converted value px*0.75
-
isStyleSheetLink
public static boolean isStyleSheetLink(IElementNode headChildElement)
Checks if anIElementNode
represents a style sheet link.- Parameters:
headChildElement
- the head child element- Returns:
- true, if the element node represents a style sheet link
-
addRange
private static boolean addRange(RangeBuilder builder, java.lang.String range)
-
addRange
private static boolean addRange(RangeBuilder builder, java.lang.String left, java.lang.String right)
-
isAttributeNameValid
private static boolean isAttributeNameValid(java.lang.String attributeName)
-
extractFallback
private static java.lang.String extractFallback(java.lang.String fallbackString)
-
extractTypeOfAttribute
private static java.lang.String extractTypeOfAttribute(java.lang.String typeString)
-
getAttributeValue
private static java.lang.String getAttributeValue(java.lang.String attributeName, java.lang.String typeOfAttribute, java.lang.String fallback, IElementNode elementNode)
-
-