Class AbstractSvgNodeRenderer

java.lang.Object
com.itextpdf.svg.renderers.impl.AbstractSvgNodeRenderer
All Implemented Interfaces:
ISvgNodeRenderer
Direct Known Subclasses:
AbstractBranchSvgNodeRenderer, EllipseSvgNodeRenderer, ImageSvgNodeRenderer, LineSvgNodeRenderer, PathSvgNodeRenderer, PolylineSvgNodeRenderer, RectangleSvgNodeRenderer, TextLeafSvgNodeRenderer, TextSvgBranchRenderer, UseSvgNodeRenderer

public abstract class AbstractSvgNodeRenderer extends Object implements ISvgNodeRenderer
ISvgNodeRenderer abstract implementation.
  • Field Details

    • MARKER_VERTEX_TYPES

      private static final MarkerVertexType[] MARKER_VERTEX_TYPES
    • attributesAndStyles

      protected Map<String,String> attributesAndStyles
      Map that contains attributes and styles used for drawing operations.
    • partOfClipPath

      boolean partOfClipPath
    • doFill

      boolean doFill
    • doStroke

      boolean doStroke
    • parent

      private ISvgNodeRenderer parent
  • Constructor Details

    • AbstractSvgNodeRenderer

      public AbstractSvgNodeRenderer()
  • Method Details

    • setParent

      public void setParent(ISvgNodeRenderer parent)
      Description copied from interface: ISvgNodeRenderer
      Sets the parent of this renderer. The parent may be the source of inherited properties and default values.
      Specified by:
      setParent in interface ISvgNodeRenderer
      Parameters:
      parent - the parent renderer
    • getParent

      public ISvgNodeRenderer getParent()
      Description copied from interface: ISvgNodeRenderer
      Gets the parent of this renderer. The parent may be the source of inherited properties and default values.
      Specified by:
      getParent in interface ISvgNodeRenderer
      Returns:
      the parent renderer; null in case of a root node
    • setAttributesAndStyles

      public void setAttributesAndStyles(Map<String,String> attributesAndStyles)
      Description copied from interface: ISvgNodeRenderer
      Sets the map of XML node attributes and CSS style properties that this renderer needs.
      Specified by:
      setAttributesAndStyles in interface ISvgNodeRenderer
      Parameters:
      attributesAndStyles - the mapping from key names to values
    • getAttribute

      public String getAttribute(String key)
      Description copied from interface: ISvgNodeRenderer
      Retrieves the property value for a given key name.
      Specified by:
      getAttribute in interface ISvgNodeRenderer
      Parameters:
      key - the name of the property to search for
      Returns:
      the value for this key, or null
    • getAttributeOrDefault

      public String getAttributeOrDefault(String key, String defaultValue)
      Retrieves the property value for a given key name or default if the property value is null or missing.
      Parameters:
      key - the name of the property to search for
      defaultValue - the default value to be returned if the property is null or missing
      Returns:
      the value for this key, or defaultValue
    • setAttribute

      public void setAttribute(String key, String value)
      Description copied from interface: ISvgNodeRenderer
      Sets a property key and value pairs for a given attribute
      Specified by:
      setAttribute in interface ISvgNodeRenderer
      Parameters:
      key - the name of the attribute
      value - the value of the attribute
    • getAttributeMapCopy

      public Map<String,String> getAttributeMapCopy()
      Description copied from interface: ISvgNodeRenderer
      Get a modifiable copy of the style and attribute map
      Specified by:
      getAttributeMapCopy in interface ISvgNodeRenderer
      Returns:
      copy of the attributes and styles-map
    • draw

      public final void draw(SvgDrawContext context)
      Applies transformations set to this object, if any, and delegates the drawing of this element and its children to the doDraw method.
      Specified by:
      draw in interface ISvgNodeRenderer
      Parameters:
      context - the object that knows the place to draw this element and maintains its state
    • canElementFill

      protected boolean canElementFill()
      Method to see if a certain renderer can use fill.
      Returns:
      true if the renderer can use fill
    • canConstructViewPort

      public boolean canConstructViewPort()
      Method to see if the renderer can create a viewport
      Returns:
      true if the renderer can construct a viewport
    • getCurrentFontSize

      public float getCurrentFontSize()
      Return font-size of the current element
      Returns:
      absolute value of font-size
    • deepCopyAttributesAndStyles

      protected void deepCopyAttributesAndStyles(ISvgNodeRenderer deepCopy)
      Make a deep copy of the styles and attributes of this renderer Helper method for deep copying logic
      Parameters:
      deepCopy - renderer to insert the deep copied attributes into
    • doDraw

      protected abstract void doDraw(SvgDrawContext context)
      Draws this element to a canvas-like object maintained in the context.
      Parameters:
      context - the object that knows the place to draw this element and maintains its state
    • calculateViewPortTranslation

      AffineTransform calculateViewPortTranslation(SvgDrawContext context)
      Calculate the transformation for the viewport based on the context. Only used by elements that can create viewports
      Parameters:
      context - the SVG draw context
      Returns:
      the transformation that needs to be applied to this renderer
    • postDraw

      void postDraw(SvgDrawContext context)
      Operations to be performed after drawing the element. This includes filling, stroking.
      Parameters:
      context - the svg draw context
    • setPartOfClipPath

      void setPartOfClipPath(boolean value)
    • preDraw

      void preDraw(SvgDrawContext context)
      Operations to perform before drawing an element. This includes setting stroke color and width, fill color.
      Parameters:
      context - the svg draw context
    • parseAbsoluteLength

      protected float parseAbsoluteLength(String length, float percentBaseValue, float defaultValue, SvgDrawContext context)
      Parse length attributes.
      Parameters:
      length - String for parsing
      percentBaseValue - the value on which percent length is based on
      defaultValue - default value if length is not recognized
      context - current SvgDrawContext
      Returns:
      absolute value in points
    • getColorFromAttributeValue

      private TransparentColor getColorFromAttributeValue(SvgDrawContext context, String rawColorValue, float objectBoundingBoxMargin, float parentOpacity)
    • getOpacityByAttributeName

      private float getOpacityByAttributeName(String attributeName, float generalOpacity)
    • drawInClipPath

      private boolean drawInClipPath(SvgDrawContext context)
    • normalizeLocalUrlName

      private String normalizeLocalUrlName(String name)
    • getOpacity

      private float getOpacity()
    • applyStrokeProperties

      private void applyStrokeProperties(SvgDrawContext context, PdfCanvas currentCanvas, PdfExtGState opacityGraphicsState)