Package com.itextpdf.svg.utils
Class SvgTextUtil
- java.lang.Object
-
- com.itextpdf.svg.utils.SvgTextUtil
-
public final class SvgTextUtil extends java.lang.Object
Class containing utility methods for text operations in the context of SVG processing
-
-
Field Summary
Fields Modifier and Type Field Description private static float
TEXT_DECORATION_LINE_OVER_Y_POS
private static float
TEXT_DECORATION_LINE_THROUGH_Y_POS
private static float
TEXT_DECORATION_LINE_UNDER_Y_POS
-
Constructor Summary
Constructors Modifier Constructor Description private
SvgTextUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static void
addUnderline(SvgDrawContext context, java.util.List<Underline> underlineList, Color strokeColor, float strokeOpacity, Color fillColor, float fillOpacity, float textDecorationLine, boolean doFill, boolean doStroke)
static void
applyTextDecoration(ISvgTextNodeRenderer renderer, boolean doFill, boolean doStroke, SvgDrawContext context)
Processes text-decoration attribute which is shorthand for text-decoration-line and text-decoration-style.static java.lang.String
filterReferenceValue(java.lang.String name)
The reference value may contain a hashtag character or 'url' designation and this method will filter them.static boolean
isOnlyWhiteSpace(java.lang.String s)
Check if the String is only composed of whitespace charactersstatic void
processWhiteSpace(TextSvgBranchRenderer root, boolean isLeadingElement)
Deprecated.static void
processWhiteSpace(TextSvgBranchRenderer root, boolean isLeadingElement, SvgDrawContext context)
Process the whitespace inside the Text Tree.static float
resolveFontSize(ISvgTextNodeRenderer renderer, float parentFontSize)
Deprecated.will be removed together withTextLeafSvgNodeRenderer.getTextContentLength(float, PdfFont)
static java.lang.String
trimLeadingWhitespace(java.lang.String toTrim)
Trim all the leading whitespace characters from the passed stringstatic java.lang.String
trimTrailingWhitespace(java.lang.String toTrim)
Trim all the trailing whitespace characters from the passed string
-
-
-
Field Detail
-
TEXT_DECORATION_LINE_THROUGH_Y_POS
private static final float TEXT_DECORATION_LINE_THROUGH_Y_POS
- See Also:
- Constant Field Values
-
TEXT_DECORATION_LINE_OVER_Y_POS
private static final float TEXT_DECORATION_LINE_OVER_Y_POS
- See Also:
- Constant Field Values
-
TEXT_DECORATION_LINE_UNDER_Y_POS
private static final float TEXT_DECORATION_LINE_UNDER_Y_POS
- See Also:
- Constant Field Values
-
-
Method Detail
-
trimLeadingWhitespace
public static java.lang.String trimLeadingWhitespace(java.lang.String toTrim)
Trim all the leading whitespace characters from the passed string- Parameters:
toTrim
- string to trim- Returns:
- string with all leading whitespace characters removed
-
trimTrailingWhitespace
public static java.lang.String trimTrailingWhitespace(java.lang.String toTrim)
Trim all the trailing whitespace characters from the passed string- Parameters:
toTrim
- string to trim- Returns:
- string with al trailing whitespace characters removed
-
processWhiteSpace
@Deprecated public static void processWhiteSpace(TextSvgBranchRenderer root, boolean isLeadingElement)
Deprecated.Process the whitespace inside the Text Tree. Whitespace is collapsed and new lines are handled A leading element in each subtree is handled different: the preceding whitespace is trimmed instead of kept- Parameters:
root
- root of the text-renderer subtreeisLeadingElement
- true if this element is a leading element(either the first child or the first element after an absolute position change)
-
processWhiteSpace
public static void processWhiteSpace(TextSvgBranchRenderer root, boolean isLeadingElement, SvgDrawContext context)
Process the whitespace inside the Text Tree. Whitespace is collapsed and new lines are handled A leading element in each subtree is handled different: the preceding whitespace is trimmed instead of kept- Parameters:
root
- root of the text-renderer subtreeisLeadingElement
- true if this element is a leading element(either the first child or the first element after an absolute position change)context
- the svg draw context
-
isOnlyWhiteSpace
public static boolean isOnlyWhiteSpace(java.lang.String s)
Check if the String is only composed of whitespace characters- Parameters:
s
- string to check- Returns:
- true if the string only contains whitespace characters, false otherwise
-
resolveFontSize
@Deprecated public static float resolveFontSize(ISvgTextNodeRenderer renderer, float parentFontSize)
Deprecated.will be removed together withTextLeafSvgNodeRenderer.getTextContentLength(float, PdfFont)
Resolve the font size stored inside the passed renderer- Parameters:
renderer
- renderer containing the font size declarationparentFontSize
- parent font size to fall back on if the renderer does not contain a font size declarations or if the stored declaration is invalid- Returns:
- float containing the font-size, or the parent font size if the renderer's declaration cannot be resolved
-
filterReferenceValue
public static java.lang.String filterReferenceValue(java.lang.String name)
The reference value may contain a hashtag character or 'url' designation and this method will filter them.- Parameters:
name
- value to be filtered- Returns:
- filtered value
-
applyTextDecoration
public static void applyTextDecoration(ISvgTextNodeRenderer renderer, boolean doFill, boolean doStroke, SvgDrawContext context)
Processes text-decoration attribute which is shorthand for text-decoration-line and text-decoration-style.Note, that text-decoration from styles (resolved in SvgStyleResolver) takes precedence when both are specified.
- Parameters:
renderer
- to apply text-decoration fordoFill
- boolean specifying whether text should be filleddoStroke
- boolean specifying whether text should be strokedcontext
- current SVG draw context
-
addUnderline
private static void addUnderline(SvgDrawContext context, java.util.List<Underline> underlineList, Color strokeColor, float strokeOpacity, Color fillColor, float fillOpacity, float textDecorationLine, boolean doFill, boolean doStroke)
-
-