Class SvgStyleResolver
java.lang.Object
com.itextpdf.svg.css.impl.SvgStyleResolver
- All Implemented Interfaces:
ICssResolver
Default implementation of SVG`s styles and attribute resolver .
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CssStyleSheetprivate static final Stringstatic final floatprivate MediaDeviceDescriptionThe device description.private static final String[]private final List<CssFontFaceRule> The list of fonts.static final Set<IStyleInheritance> private booleanprivate static final org.slf4j.Loggerprivate final ResourceResolverThe resource resolver -
Constructor Summary
ConstructorsConstructorDescriptionSvgStyleResolver(INode rootNode, SvgProcessorContext context) Creates aSvgStyleResolver.SvgStyleResolver(SvgProcessorContext context) Creates aSvgStyleResolver.SvgStyleResolver(InputStream defaultCssStream, SvgProcessorContext context) Creates aSvgStyleResolverwith a given default CSS. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcollectCssDeclarations(INode rootNode, ResourceResolver resourceResolver) private voidCollects fonts from the style sheet.private voidcollectFonts(CssStatement cssStatement) Collects fonts from aCssStatement.getFonts()Gets the list of fonts.static booleanisElementNested(IElementNode element, String parentElementNameForSearch) Checks whether element is nested within the passed parent element.private booleanChecks if string starts with #.private static booleanprivate voidparseStylesheet(IAttributesContainer attributesNode) private voidprocessAttribute(IAttribute attr, Map<String, String> styles) private voidprocessXLink(IAttribute attr, Map<String, String> attributesMap) Resolves the full path of link href attribute, thanks to the resource resolver.private static voidMerge variables from parent node with current one.static voidresolveFontSizeStyle(Map<String, String> styles, SvgCssContext cssContext, String parentFontSizeStr) Resolves the font size stored inside the current element.resolveNativeStyles(INode node, AbstractCssContext cssContext) Resolves node styles without inheritance of parent element styles.resolveStyles(INode element, AbstractCssContext context) Resolves the styles of a node given the passed context.resolveStyles(INode element, SvgCssContext context)
-
Field Details
-
INHERITANCE_RULES
-
DEFAULT_FONT_SIZE
public static final float DEFAULT_FONT_SIZE -
ELEMENTS_INHERITING_PARENT_STYLES
-
LOGGER
private static final org.slf4j.Logger LOGGER -
css
-
DEFAULT_CSS_PATH
- See Also:
-
isFirstSvgElement
private boolean isFirstSvgElement -
deviceDescription
The device description. -
fonts
The list of fonts. -
resourceResolver
The resource resolver
-
-
Constructor Details
-
SvgStyleResolver
public SvgStyleResolver(InputStream defaultCssStream, SvgProcessorContext context) throws IOException Creates aSvgStyleResolverwith a given default CSS.- Parameters:
defaultCssStream- the default CSScontext- the processor context- Throws:
IOException- if any input/output issue occurs
-
SvgStyleResolver
Creates aSvgStyleResolver.- Parameters:
context- the processor context
-
SvgStyleResolver
Creates aSvgStyleResolver. This constructor will instantiate its internal style sheet and it will collect the css declarations from the provided node.- Parameters:
rootNode- node to collect css fromcontext- the processor context
-
-
Method Details
-
resolveFontSizeStyle
public static void resolveFontSizeStyle(Map<String, String> styles, SvgCssContext cssContext, String parentFontSizeStr) Resolves the font size stored inside the current element.- Parameters:
styles- attributes map of the current elementcssContext-SvgCssContextinstance in order to resolve relative font sizeparentFontSizeStr- parent font size value
-
isElementNested
Checks whether element is nested within the passed parent element. Nesting is checked at several levels (recursively).- Parameters:
element-IElementNodeelement to checkparentElementNameForSearch- expected parent element name- Returns:
trueif element is nested within the expected parent,falseotherwise
-
resolveStyles
Description copied from interface:ICssResolverResolves the styles of a node given the passed context.- Specified by:
resolveStylesin interfaceICssResolver- Parameters:
element- the nodecontext- the CSS context (RootFontSize, etc.)- Returns:
- the map containing the resolved styles
-
resolveNativeStyles
Resolves node styles without inheritance of parent element styles.- Parameters:
node- the nodecssContext- the CSS context (RootFontSize, etc.)- Returns:
- the map containing the resolved styles that are defined in the body of the element
-
onlyNativeStylesShouldBeResolved
-
putMissingVariables
Merge variables from parent node with current one. This is needed for svg elements like <defs>, which do not inherit parent styles, but do inherit css variables.- Parameters:
styles- current element styles to put variable inparentStyles- styles to search variables for
-
resolveStyles
-
processXLink
Resolves the full path of link href attribute, thanks to the resource resolver.- Parameters:
attr- the attribute to processattributesMap- the element styles map
-
isStartedWithHash
Checks if string starts with #.- Parameters:
s- the test string- Returns:
- true if the string starts with #, otherwise false
-
collectCssDeclarations
-
parseStylesheet
-
getFonts
Gets the list of fonts.- Returns:
- the list of
CssFontFaceRuleinstances
-
collectFonts
private void collectFonts()Collects fonts from the style sheet. -
collectFonts
Collects fonts from aCssStatement.- Parameters:
cssStatement- the CSS statement
-
processAttribute
-
parseStylesFromStyleAttribute
-