Package com.itextpdf.svg.css.impl
Class SvgStyleResolver
- java.lang.Object
-
- com.itextpdf.svg.css.impl.SvgStyleResolver
-
- All Implemented Interfaces:
ICssResolver
public class SvgStyleResolver extends java.lang.Object implements ICssResolver
Default implementation of SVG`s styles and attribute resolver .
-
-
Field Summary
Fields Modifier and Type Field Description private CssStyleSheet
css
private static java.lang.String
DEFAULT_CSS_PATH
private static float
DEFAULT_FONT_SIZE
private MediaDeviceDescription
deviceDescription
The device description.private static java.lang.String[]
ELEMENTS_INHERITING_PARENT_STYLES
private java.util.List<CssFontFaceRule>
fonts
The list of fonts.static java.util.Set<IStyleInheritance>
INHERITANCE_RULES
private boolean
isFirstSvgElement
private static org.slf4j.Logger
LOGGER
private ResourceResolver
resourceResolver
The resource resolver
-
Constructor Summary
Constructors Constructor Description SvgStyleResolver(INode rootNode, SvgProcessorContext context)
Creates aSvgStyleResolver
.SvgStyleResolver(SvgProcessorContext context)
Creates aSvgStyleResolver
.SvgStyleResolver(java.io.InputStream defaultCssStream, SvgProcessorContext context)
Creates aSvgStyleResolver
with a given default CSS.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
collectCssDeclarations(INode rootNode, ResourceResolver resourceResolver)
private void
collectFonts()
Collects fonts from the style sheet.private void
collectFonts(CssStatement cssStatement)
Collects fonts from aCssStatement
.java.util.List<CssFontFaceRule>
getFonts()
Gets the list of fonts.static boolean
isElementNested(IElementNode element, java.lang.String parentElementNameForSearch)
private boolean
isStartedWithHash(java.lang.String s)
Checks if string starts with #.private static boolean
onlyNativeStylesShouldBeResolved(IElementNode element)
private java.util.Map<java.lang.String,java.lang.String>
parseStylesFromStyleAttribute(java.lang.String style)
private void
processAttribute(IAttribute attr, java.util.Map<java.lang.String,java.lang.String> styles)
private void
processXLink(IAttribute attr, java.util.Map<java.lang.String,java.lang.String> attributesMap)
Resolves the full path of link href attribute, thanks to the resource resolver.static void
resolveFontSizeStyle(java.util.Map<java.lang.String,java.lang.String> styles, SvgCssContext cssContext, java.lang.String parentFontSizeStr)
java.util.Map<java.lang.String,java.lang.String>
resolveNativeStyles(INode node, AbstractCssContext cssContext)
Resolves node styles without inheritance of parent element styles.java.util.Map<java.lang.String,java.lang.String>
resolveStyles(INode element, AbstractCssContext context)
Resolves the styles of a node given the passed context.private java.util.Map<java.lang.String,java.lang.String>
resolveStyles(INode element, SvgCssContext context)
-
-
-
Field Detail
-
INHERITANCE_RULES
public static final java.util.Set<IStyleInheritance> INHERITANCE_RULES
-
ELEMENTS_INHERITING_PARENT_STYLES
private static final java.lang.String[] ELEMENTS_INHERITING_PARENT_STYLES
-
DEFAULT_FONT_SIZE
private static final float DEFAULT_FONT_SIZE
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
css
private CssStyleSheet css
-
DEFAULT_CSS_PATH
private static final java.lang.String DEFAULT_CSS_PATH
- See Also:
- Constant Field Values
-
isFirstSvgElement
private boolean isFirstSvgElement
-
deviceDescription
private MediaDeviceDescription deviceDescription
The device description.
-
fonts
private final java.util.List<CssFontFaceRule> fonts
The list of fonts.
-
resourceResolver
private final ResourceResolver resourceResolver
The resource resolver
-
-
Constructor Detail
-
SvgStyleResolver
public SvgStyleResolver(java.io.InputStream defaultCssStream, SvgProcessorContext context) throws java.io.IOException
Creates aSvgStyleResolver
with a given default CSS.- Parameters:
defaultCssStream
- the default CSScontext
- the processor context- Throws:
java.io.IOException
- if any input/output issue occurs
-
SvgStyleResolver
public SvgStyleResolver(SvgProcessorContext context)
Creates aSvgStyleResolver
.- Parameters:
context
- the processor context
-
SvgStyleResolver
public SvgStyleResolver(INode rootNode, SvgProcessorContext context)
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 Detail
-
resolveFontSizeStyle
public static void resolveFontSizeStyle(java.util.Map<java.lang.String,java.lang.String> styles, SvgCssContext cssContext, java.lang.String parentFontSizeStr)
-
isElementNested
public static boolean isElementNested(IElementNode element, java.lang.String parentElementNameForSearch)
-
resolveStyles
public java.util.Map<java.lang.String,java.lang.String> resolveStyles(INode element, AbstractCssContext context)
Description copied from interface:ICssResolver
Resolves the styles of a node given the passed context.- Specified by:
resolveStyles
in interfaceICssResolver
- Parameters:
element
- the nodecontext
- the CSS context (RootFontSize, etc.)- Returns:
- the map containing the resolved styles
-
resolveNativeStyles
public java.util.Map<java.lang.String,java.lang.String> resolveNativeStyles(INode node, AbstractCssContext cssContext)
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
private static boolean onlyNativeStylesShouldBeResolved(IElementNode element)
-
resolveStyles
private java.util.Map<java.lang.String,java.lang.String> resolveStyles(INode element, SvgCssContext context)
-
processXLink
private void processXLink(IAttribute attr, java.util.Map<java.lang.String,java.lang.String> attributesMap)
Resolves the full path of link href attribute, thanks to the resource resolver.- Parameters:
attr
- the attribute to processattributesMap
- the element styles map
-
isStartedWithHash
private boolean isStartedWithHash(java.lang.String s)
Checks if string starts with #.- Parameters:
s
- the test string- Returns:
- true if the string starts with #, otherwise false
-
collectCssDeclarations
private void collectCssDeclarations(INode rootNode, ResourceResolver resourceResolver)
-
getFonts
public java.util.List<CssFontFaceRule> getFonts()
Gets the list of fonts.- Returns:
- the list of
CssFontFaceRule
instances
-
collectFonts
private void collectFonts()
Collects fonts from the style sheet.
-
collectFonts
private void collectFonts(CssStatement cssStatement)
Collects fonts from aCssStatement
.- Parameters:
cssStatement
- the CSS statement
-
processAttribute
private void processAttribute(IAttribute attr, java.util.Map<java.lang.String,java.lang.String> styles)
-
parseStylesFromStyleAttribute
private java.util.Map<java.lang.String,java.lang.String> parseStylesFromStyleAttribute(java.lang.String style)
-
-