public class CssUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_FONT_SIZE_PT
Default font size if none is set.
|
Modifier and Type | Method and Description |
---|---|
float |
calculateMarginTop(float value, MarginMemory configuration)
Calculates the margin top or spacingBefore based on the given value and the last margin bottom.
|
float |
calculateMarginTop(String value, float largestFont, MarginMemory configuration)
Calculates the margin top or spacingBefore based on the given value and the last margin bottom.
|
Float |
checkMetricStyle(Map<String,String> css, String style)
Use only if value of style is a metric value ( isMetricValue(String) ) or a numeric value in pixels (isNumericValue(String) ).
|
float |
checkMetricStyle(Tag t, String style)
Use only if value of style is a metric value ( isMetricValue(String) ) or a numeric value in pixels (isNumericValue(String) ).
|
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).
|
String |
extractUrl(String url)
Parses url("file.jpg") to file.jpg .
|
static CssUtils |
getInstance() |
float |
getLeftAndRightMargin(Tag t, float pageWidth)
Returns the sum of the left and right margin of a tag.
|
boolean |
isMetricValue(String value)
Checks whether a string contains an allowed metric unit in HTML/CSS; px, in, cm, mm, pc or pt.
|
boolean |
isNumericValue(String value)
Checks whether a string matches a numeric value (e.g. 123, 1.23, .123).
|
boolean |
isRelativeValue(String value)
Checks whether a string contains an allowed value relative to previously set value.
|
Map<String,String> |
parseBorder(String border) |
Map<String,String> |
parseBorder(String border, String borderKey) |
Map<String,String> |
parseBoxValues(String box, String pre, String post)
Returns the top, bottom, left, right version for the given box. the keys will be the pre value concatenated with either top, bottom, right or left and the post value.
|
Map<String,String> |
parseBoxValues(String box, String pre, String post, String preKey) |
float |
parsePxInCmMmPcToPt(String length)
Parses a length with an allowed metric unit (px, pt, in, cm, mm, pc, em or ex) or numeric value (e.g. 123, 1.23, .123) to pt.
|
float |
parsePxInCmMmPcToPt(String length, String defaultMetric)
Parses a length with an allowed metric unit (px, pt, in, cm, mm, pc, em or ex) or numeric value (e.g. 123, 1.23, .123) to pt.
|
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.
|
float |
parseValueToPt(String value, float baseValue)
Convenience method for parsing a value to pt if a value can contain:
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). |
Map<String,String> |
processBackground(String background)
Preparation before implementing the background style in iText.
|
Map<String,String> |
processFont(String font)
Preparation before implementing the font style in iText.
|
Map<String,String> |
processListStyle(String listStyle)
Preparation before implementing the list style in iText.
|
String[] |
splitComplexCssStyle(String s) |
String |
stripDoubleSpacesAndTrim(String str)
Trims and Strips double spaces from the given string.
|
String |
stripDoubleSpacesTrimAndToLowerCase(String str) |
String |
trimAndRemoveQuoutes(String s)
Trims a string and removes surrounding " or '.
|
float |
validateTextHeight(Map<String,String> css, float textHeight)
Validates a given textHeight based on the content of a tag against the css styles "min-height" and "max-height" of the tag if present.
|
public static final int DEFAULT_FONT_SIZE_PT
public static CssUtils getInstance()
public Map<String,String> parseBoxValues(String box, String pre, String post)
stripDoubleSpacesAndTrim(String)
)
box
- the value to parse
pre
- the pre key part
post
- the post key part
public Map<String,String> parseBoxValues(String box, String pre, String post, String preKey)
public Map<String,String> parseBorder(String border)
border
- the border property
public String stripDoubleSpacesAndTrim(String str)
str
- the string to strip
public Map<String,String> processBackground(String background)
background
- the string containing the font style value.
public Map<String,String> processListStyle(String listStyle)
listStyle
- the string containing the list style value.
public Map<String,String> processFont(String font)
font
- the string containing the font style value.
public float checkMetricStyle(Tag t, String style)
isMetricValue(String)
) or a numeric value in pixels (isNumericValue(String)
).
t
- the tag which needs to be checked.
style
- the style which needs to be checked.
public Float checkMetricStyle(Map<String,String> css, String style)
isMetricValue(String)
) or a numeric value in pixels (isNumericValue(String)
).
css
- the map of css styles which needs to be checked.
style
- the style which needs to be checked.
public boolean isMetricValue(String value)
value
- the string that needs to be checked.
public boolean isRelativeValue(String value)
value
- the string that needs to be checked.
public boolean isNumericValue(String value)
value
- the string that needs to be checked.
public float parseValueToPt(String value, float baseValue)
value
- the string containing the value to be parsed.
baseValue
- float needed for the calculation of the relative value.
public float parseRelativeValue(String relativeValue, float baseValue)
relativeValue
- in %, em or ex.
baseValue
- the value the returned float is based on.
public float parsePxInCmMmPcToPt(String length, String defaultMetric)
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.
public float parsePxInCmMmPcToPt(String length)
length
- the string containing the length.
public int determinePositionBetweenValueAndUnit(String string)
string
- containing a numeric value with a metric unit
public float getLeftAndRightMargin(Tag t, float pageWidth)
t
- the tag of which the total horizontal margin is needed.
pageWidth
- the page width
public String extractUrl(String url)
url("file.jpg")
to file.jpg
.
url
- the url attribute to parse
public float validateTextHeight(Map<String,String> css, float textHeight)
css
- the styles of a tag
textHeight
- the current textHeight based on the content of a tag
public float calculateMarginTop(String value, float largestFont, MarginMemory configuration)
value
- the margin-top value of the given tag.
largestFont
- used if a relative value was given to calculate margin.
configuration
- XmlWorkerConfig containing the last margin bottom.
public float calculateMarginTop(float value, MarginMemory configuration)
value
- float containing the margin-top value.
configuration
- XmlWorkerConfig containing the last margin bottom.
public String trimAndRemoveQuoutes(String s)
s
- the string
Copyright © 1998–2016. All rights reserved.