Class CssUtils

java.lang.Object
com.itextpdf.styledxmlparser.css.util.CssUtils

public class CssUtils extends Object
Utilities class for CSS operations.
  • Method Details

    • splitStringWithComma

      public static List<String> splitStringWithComma (String value)
      Splits the provided String by comma with respect of brackets.
      Parameters:
      value - to split
      Returns:
      the List of split result
    • splitString

      public static List<String> splitString (String value, char splitChar, EscapeGroup... escapeCharacters)
      Splits the provided String by split character with respect of escape characters.
      Parameters:
      value - value to split
      splitChar - character to split the String
      escapeCharacters - escape characters
      Returns:
      the List of split result
    • parseBlendMode

      public static BlendMode parseBlendMode (String cssValue)
      Parses the given css blend mode value. If the argument is null or an unknown blend mode, then the default css BlendMode.NORMAL value would be returned.
      Parameters:
      cssValue - the value to parse
      Returns:
      the BlendMode instance representing the parsed value
    • extractShorthandProperties

      public static List<List<String>> extractShorthandProperties (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 String normalizeCssProperty (String str)
      Normalizes a CSS property.
      Parameters:
      str - the property
      Returns:
      the normalized property
    • removeDoubleSpacesAndTrim

      public static String removeDoubleSpacesAndTrim (String str)
      Removes double spaces and trims a string.
      Parameters:
      str - the string
      Returns:
      the string without the unnecessary spaces
    • extractUrl

      public static String extractUrl (String url)
      Parses url("file.jpg") to file.jpg.
      Parameters:
      url - the url attribute to parse
      Returns:
      the parsed url. Or original url if not wrappend in url()
    • extractAttributeValue

      public static String extractAttributeValue (String attrStr, IElementNode element)
      Parses string and return attribute value.
      Parameters:
      attrStr - the string contains attr() to extract attribute value
      element - the parentNode from which we extract information
      Returns:
      the value of attribute
    • findNextUnescapedChar

      public static int findNextUnescapedChar (String source, char ch, int startIndex)
      Find the next unescaped character.
      Parameters:
      source - a source
      ch - the character to look for
      startIndex - 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 compare
      d2 - 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 compare
      f2 - 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 (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 an IElementNode represents a style sheet link.
      Parameters:
      headChildElement - the head child element
      Returns:
      true, if the element node represents a style sheet link