iText 7 7.1.12 API
iText.StyledXmlParser.Css.Util.CssUtils Class Reference

Utilities class for CSS operations. More...

Static Public Member Functions

static IList< IList< 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. More...
 
static String  NormalizeCssProperty (String str)
  Normalizes a CSS property. More...
 
static String  RemoveDoubleSpacesAndTrim (String str)
  Removes double spaces and trims a string. More...
 
static ? int  ParseInteger (String str)
  Parses an integer without throwing an exception if something goes wrong. More...
 
static ? float  ParseFloat (String str)
  Parses a float without throwing an exception if something goes wrong. More...
 
static ? double  ParseDouble (String str)
  Parses a double without throwing an exception if something goes wrong. More...
 
static float  ParseAngle (String angle, String defaultMetric)
  Parses an angle with an allowed metric unit (deg, grad, rad) or numeric value (e.g. 123, 1.23, .123) to rad. More...
 
static float  ParseAngle (String angle)
  Parses a angle with an allowed metric unit (deg, grad, rad) or numeric value (e.g. 123, 1.23, .123) to rad. More...
 
static int[]  ParseAspectRatio (String str)
  Parses an aspect ratio into an array with two integers. More...
 
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. 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. More...
 
static float  ParseAbsoluteLength (String length)
  Parses the absolute length. More...
 
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. margin=10% should be based on the page width, so if an A4 is used, the margin = 0.10*595.0 = 59.5f) More...
 
static UnitValue  ParseLengthValueToPt (String value, float emValue, float remValue)
  Convenience method for parsing a value to pt. More...
 
static float  ParseAbsoluteFontSize (String fontSizeValue, String defaultMetric)
  Parses the absolute font size. More...
 
static float  ParseAbsoluteFontSize (String fontSizeValue)
  Parses the absolute font size. More...
 
static float  ParseRelativeFontSize (String relativeFontSizeValue, float baseValue)
  Parses the relative font size. More...
 
static UnitValue[]  ParseSpecificCornerBorderRadius (String specificBorderRadius, float emValue, float remValue)
  Parses the border radius of specific corner. More...
 
static float  ParseResolution (String resolutionStr)
  Parses the resolution. More...
 
static int  DeterminePositionBetweenValueAndUnit (String @string)
  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. More...
 
static bool  IsMetricValue (String value)
  Checks whether a string contains an allowed metric unit in HTML/CSS; px, in, cm, mm, pc, Q or pt. More...
 
static bool  IsAngleValue (String value)
  Checks whether a string contains an allowed metric unit in HTML/CSS; rad, deg and grad. More...
 
static bool  IsRelativeValue (String value)
  Checks whether a string contains an allowed value relative to previously set value. More...
 
static bool  IsFontRelativeValue (String value)
  Checks whether a string contains an allowed value relative to font. More...
 
static bool  IsPercentageValue (String value)
  Checks whether a string contains a percentage value More...
 
static bool  IsRemValue (String value)
  Checks whether a string contains an allowed value relative to previously set root value. More...
 
static bool  IsEmValue (String value)
  Checks whether a string contains an allowed value relative to parent value. More...
 
static bool  IsExValue (String value)
  Checks whether a string contains an allowed value relative to element font height. More...
 
static bool  IsNumericValue (String value)
  Checks whether a string matches a numeric value (e.g. 123, 1.23, .123). More...
 
static String  ExtractUrl (String url)
  Parses url("file.jpg") to file.jpg. More...
 
static bool  IsBase64Data (String data)
  Checks if a data is base 64 encoded. More...
 
static int  FindNextUnescapedChar (String source, char ch, int startIndex)
  Find the next unescaped character. More...
 
static bool  IsColorProperty (String value)
  Checks if a value is a color property. More...
 
static bool  CompareFloats (double d1, double d2)
  Helper method for comparing floating point numbers More...
 
static bool  CompareFloats (float f1, float f2)
  Helper method for comparing floating point numbers More...
 
static float[]  ParseRgbaColor (String colorValue)
  Parses the RGBA color. More...
 
static Range  ParseUnicodeRange (String unicodeRange)
  Parses the unicode range. More...
 
static float  ConvertPtsToPx (float pts)
  Convert given point value to a pixel value. More...
 
static double  ConvertPtsToPx (double pts)
  Convert given point value to a pixel value. More...
 
static float  ConvertPxToPts (float px)
  Convert given point value to a point value. More...
 
static double  ConvertPxToPts (double px)
  Convert given point value to a point value. More...
 

Detailed Description

Utilities class for CSS operations.

Member Function Documentation

◆ CompareFloats() [1/2]

static bool iText.StyledXmlParser.Css.Util.CssUtils.CompareFloats ( double  d1,
double  d2 
)
inlinestatic

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() [2/2]

static bool iText.StyledXmlParser.Css.Util.CssUtils.CompareFloats ( float  f1,
float  f2 
)
inlinestatic

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

◆ ConvertPtsToPx() [1/2]

static double iText.StyledXmlParser.Css.Util.CssUtils.ConvertPtsToPx ( double  pts )
inlinestatic

Convert given point value to a pixel value.

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

◆ ConvertPtsToPx() [2/2]

static float iText.StyledXmlParser.Css.Util.CssUtils.ConvertPtsToPx ( float  pts )
inlinestatic

Convert given point value to a pixel value.

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

◆ ConvertPxToPts() [1/2]

static double iText.StyledXmlParser.Css.Util.CssUtils.ConvertPxToPts ( double  px )
inlinestatic

Convert given point value to a point value.

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

◆ ConvertPxToPts() [2/2]

static float iText.StyledXmlParser.Css.Util.CssUtils.ConvertPxToPts ( float  px )
inlinestatic

Convert given point value to a point value.

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

◆ DeterminePositionBetweenValueAndUnit()

static int iText.StyledXmlParser.Css.Util.CssUtils.DeterminePositionBetweenValueAndUnit ( String @  string )
inlinestatic

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.

◆ ExtractShorthandProperties()

static IList > iText.StyledXmlParser.Css.Util.CssUtils.ExtractShorthandProperties ( String  str )
inlinestatic

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

◆ ExtractUrl()

static String iText.StyledXmlParser.Css.Util.CssUtils.ExtractUrl ( String  url )
inlinestatic

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()

◆ FindNextUnescapedChar()

static int iText.StyledXmlParser.Css.Util.CssUtils.FindNextUnescapedChar ( String  source,
char  ch,
int  startIndex 
)
inlinestatic

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

◆ IsAngleValue()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsAngleValue ( String  value )
inlinestatic

Checks whether a string contains an allowed metric unit in HTML/CSS; rad, deg and grad.

Parameters
value the string that needs to be checked.
Returns
boolean true if value contains an allowed angle value.

◆ IsBase64Data()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsBase64Data ( String  data )
inlinestatic

Checks if a data is base 64 encoded.

Parameters
data the data
Returns
true, if the data is base 64 encoded

◆ IsColorProperty()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsColorProperty ( String  value )
inlinestatic

Checks if a value is a color property.

Parameters
value the value
Returns
true, if the value contains a color property

◆ IsEmValue()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsEmValue ( String  value )
inlinestatic

Checks whether a string contains an allowed value relative to parent value.

Parameters
value the string that needs to be checked.
Returns
boolean true if value contains a em value.

◆ IsExValue()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsExValue ( String  value )
inlinestatic

Checks whether a string contains an allowed value relative to element font height.

Parameters
value the string that needs to be checked.
Returns
boolean true if value contains a ex value.

◆ IsFontRelativeValue()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsFontRelativeValue ( String  value )
inlinestatic

Checks whether a string contains an allowed value relative to font.

Parameters
value the string that needs to be checked.
Returns
boolean true if value contains an allowed font relative value.

◆ IsMetricValue()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsMetricValue ( String  value )
inlinestatic

Checks whether a string contains an allowed metric unit in HTML/CSS; px, in, cm, mm, pc, Q or pt.

Parameters
value the string that needs to be checked.
Returns
boolean true if value contains an allowed metric value.

◆ IsNumericValue()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsNumericValue ( String  value )
inlinestatic

Checks whether a string matches a numeric value (e.g. 123, 1.23, .123).

Checks whether a string matches a numeric value (e.g. 123, 1.23, .123). All these metric values are allowed in HTML/CSS.

Parameters
value the string that needs to be checked.
Returns
boolean true if value contains an allowed metric value.

◆ IsPercentageValue()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsPercentageValue ( String  value )
inlinestatic

Checks whether a string contains a percentage value

Parameters
value the string that needs to be checked
Returns
boolean true if value contains an allowed percentage value

◆ IsRelativeValue()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsRelativeValue ( String  value )
inlinestatic

Checks whether a string contains an allowed value relative to previously set value.

Parameters
value the string that needs to be checked.
Returns
boolean true if value contains an allowed metric value.

◆ IsRemValue()

static bool iText.StyledXmlParser.Css.Util.CssUtils.IsRemValue ( String  value )
inlinestatic

Checks whether a string contains an allowed value relative to previously set root value.

Parameters
value the string that needs to be checked.
Returns
boolean true if value contains a rem value.

◆ NormalizeCssProperty()

static String iText.StyledXmlParser.Css.Util.CssUtils.NormalizeCssProperty ( String  str )
inlinestatic

Normalizes a CSS property.

Parameters
str the property
Returns
the normalized property

◆ ParseAbsoluteFontSize() [1/2]

static float iText.StyledXmlParser.Css.Util.CssUtils.ParseAbsoluteFontSize ( String  fontSizeValue )
inlinestatic

Parses the absolute font size.

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 a System.String
Returns
the font size value as a float

◆ ParseAbsoluteFontSize() [2/2]

static float iText.StyledXmlParser.Css.Util.CssUtils.ParseAbsoluteFontSize ( String  fontSizeValue,
String  defaultMetric 
)
inlinestatic

Parses the absolute font size.

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 a System.String
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

◆ ParseAbsoluteLength() [1/2]

static float iText.StyledXmlParser.Css.Util.CssUtils.ParseAbsoluteLength ( String  length )
inlinestatic

Parses the absolute length.

Parameters
length the length as a string
Returns
the length as a float

◆ ParseAbsoluteLength() [2/2]

static float iText.StyledXmlParser.Css.Util.CssUtils.ParseAbsoluteLength ( String  length,
String  defaultMetric 
)
inlinestatic

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

◆ ParseAngle() [1/2]

static float iText.StyledXmlParser.Css.Util.CssUtils.ParseAngle ( String  angle )
inlinestatic

Parses a angle with an allowed metric unit (deg, grad, rad) or numeric value (e.g. 123, 1.23, .123) to rad.

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

◆ ParseAngle() [2/2]

static float iText.StyledXmlParser.Css.Util.CssUtils.ParseAngle ( String  angle,
String  defaultMetric 
)
inlinestatic

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

◆ ParseAspectRatio()

static int [] iText.StyledXmlParser.Css.Util.CssUtils.ParseAspectRatio ( String  str )
inlinestatic

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

◆ ParseDouble()

static ? double iText.StyledXmlParser.Css.Util.CssUtils.ParseDouble ( String  str )
inlinestatic

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

◆ ParseFloat()

static ? float iText.StyledXmlParser.Css.Util.CssUtils.ParseFloat ( String  str )
inlinestatic

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

◆ ParseInteger()

static ? int iText.StyledXmlParser.Css.Util.CssUtils.ParseInteger ( String  str )
inlinestatic

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

◆ ParseLengthValueToPt()

static UnitValue iText.StyledXmlParser.Css.Util.CssUtils.ParseLengthValueToPt ( String  value,
float  emValue,
float  remValue 
)
inlinestatic

Convenience method for parsing a value to pt.

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

◆ ParseRelativeFontSize()

static float iText.StyledXmlParser.Css.Util.CssUtils.ParseRelativeFontSize ( String  relativeFontSizeValue,
float  baseValue 
)
inlinestatic

Parses the relative font size.

Parameters
relativeFontSizeValue the relative font size value as a System.String
baseValue the base value
Returns
the relative font size value as a float

◆ ParseRelativeValue()

static float iText.StyledXmlParser.Css.Util.CssUtils.ParseRelativeValue ( String  relativeValue,
float  baseValue 
)
inlinestatic

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.

◆ ParseResolution()

static float iText.StyledXmlParser.Css.Util.CssUtils.ParseResolution ( String  resolutionStr )
inlinestatic

Parses the resolution.

Parameters
resolutionStr the resolution as a string
Returns
a value in dpi

◆ ParseRgbaColor()

static float [] iText.StyledXmlParser.Css.Util.CssUtils.ParseRgbaColor ( String  colorValue )
inlinestatic

Parses the RGBA color.

Parameters
colorValue the color value
Returns
an RGBA value expressed as an array with four float values

◆ ParseSpecificCornerBorderRadius()

static UnitValue [] iText.StyledXmlParser.Css.Util.CssUtils.ParseSpecificCornerBorderRadius ( String  specificBorderRadius,
float  emValue,
float  remValue 
)
inlinestatic

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

◆ ParseUnicodeRange()

static Range iText.StyledXmlParser.Css.Util.CssUtils.ParseUnicodeRange ( String  unicodeRange )
inlinestatic

Parses the unicode range.

Parameters
unicodeRange the string which stores the unicode range
Returns
the unicode range as a iText.Layout.Font.Range object

◆ RemoveDoubleSpacesAndTrim()

static String iText.StyledXmlParser.Css.Util.CssUtils.RemoveDoubleSpacesAndTrim ( String  str )
inlinestatic

Removes double spaces and trims a string.

Parameters
str the string
Returns
the string without the unnecessary spaces