Class SvgStyleResolver

  • All Implemented Interfaces:
    ICssResolver

    public class SvgStyleResolver
    extends java.lang.Object
    implements ICssResolver
    Default implementation of SVG`s styles and attribute resolver .
    • 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
      • DEFAULT_CSS_PATH

        private static final java.lang.String DEFAULT_CSS_PATH
        See Also:
        Constant Field Values
      • isFirstSvgElement

        private boolean isFirstSvgElement
      • 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 a SvgStyleResolver with a given default CSS.
        Parameters:
        defaultCssStream - the default CSS
        context - the processor context
        Throws:
        java.io.IOException - if any input/output issue occurs
      • SvgStyleResolver

        public SvgStyleResolver​(INode rootNode,
                                SvgProcessorContext context)
        Creates a SvgStyleResolver. 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 from
        context - 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 interface ICssResolver
        Parameters:
        element - the node
        context - 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 node
        cssContext - 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 process
        attributesMap - 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)
      • collectFonts

        private void collectFonts()
        Collects fonts from the style sheet.
      • collectFonts

        private void collectFonts​(CssStatement cssStatement)
        Collects fonts from a CssStatement.
        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)