Class SvgStyleResolver

java.lang.Object
com.itextpdf.svg.css.impl.SvgStyleResolver
All Implemented Interfaces:
ICssResolver

public class SvgStyleResolver extends Object implements ICssResolver
Default implementation of SVG`s styles and attribute resolver .
  • Field Details

    • INHERITANCE_RULES

      public static final Set<IStyleInheritance> INHERITANCE_RULES
    • ELEMENTS_INHERITING_PARENT_STYLES

      private static final 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 String DEFAULT_CSS_PATH
      See Also:
    • isFirstSvgElement

      private boolean isFirstSvgElement
    • deviceDescription

      private MediaDeviceDescription deviceDescription
      The device description.
    • fonts

      private final List<CssFontFaceRule> fonts
      The list of fonts.
    • resourceResolver

      private final ResourceResolver resourceResolver
      The resource resolver
  • Constructor Details

    • SvgStyleResolver

      public SvgStyleResolver(InputStream defaultCssStream, SvgProcessorContext context) throws IOException
      Creates a SvgStyleResolver with a given default CSS.
      Parameters:
      defaultCssStream - the default CSS
      context - the processor context
      Throws:
      IOException - if any input/output issue occurs
    • SvgStyleResolver

      public SvgStyleResolver(SvgProcessorContext context)
      Creates a SvgStyleResolver.
      Parameters:
      context - the processor context
    • 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 Details

    • resolveFontSizeStyle

      public static void resolveFontSizeStyle(Map<String,String> styles, SvgCssContext cssContext, String parentFontSizeStr)
    • isElementNested

      public static boolean isElementNested(IElementNode element, String parentElementNameForSearch)
    • resolveStyles

      public Map<String,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 Map<String,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 Map<String,String> resolveStyles(INode element, SvgCssContext context)
    • processXLink

      private void processXLink(IAttribute attr, Map<String,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(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 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 a CssStatement.
      Parameters:
      cssStatement - the CSS statement
    • processAttribute

      private void processAttribute(IAttribute attr, Map<String,String> styles)
    • parseStylesFromStyleAttribute

      private Map<String,String> parseStylesFromStyleAttribute(String style)