Class SvgDrawContext

java.lang.Object
com.itextpdf.svg.renderers.SvgDrawContext

public class SvgDrawContext extends Object
The SvgDrawContext keeps a stack of PdfCanvas instances, which represent all levels of XObjects that are added to the root canvas.
  • Constructor Details

    • SvgDrawContext

      public SvgDrawContext (ResourceResolver resourceResolver, FontProvider fontProvider)
      Create an instance of the context that is used to store information when converting SVG.
      Parameters:
      resourceResolver - instance of ResourceResolver
      fontProvider - instance of FontProvider
  • Method Details

    • getCurrentCanvas

      public PdfCanvas getCurrentCanvas()
      Retrieves the current top of the stack, without modifying the stack.
      Returns:
      the current canvas that can be used for drawing operations.
    • popCanvas

      public PdfCanvas popCanvas()
      Retrieves the current top of the stack, thereby taking the current item off the stack.
      Returns:
      the current canvas that can be used for drawing operations.
    • pushCanvas

      public void pushCanvas (PdfCanvas canvas)
      Adds a PdfCanvas to the stack (by definition its top), for use in drawing operations.
      Parameters:
      canvas - the new top of the stack
    • size

      public int size()
      Get the current size of the stack, signifying the nesting level of the XObjects.
      Returns:
      the current size of the stack.
    • addViewPort

      public void addViewPort (Rectangle viewPort)
      Adds a viewbox to the context.
      Parameters:
      viewPort - rectangle representing the current viewbox
    • getCurrentViewPort

      public Rectangle getCurrentViewPort()
      Get the current viewbox.
      Returns:
      the viewbox as it is currently set
    • getRootViewPort

      public Rectangle getRootViewPort()
      Get the viewbox which is the root viewport for the current document.
      Returns:
      root viewbox.
    • removeCurrentViewPort

      public void removeCurrentViewPort()
      Remove the currently set view box.
    • addNamedObject

      public void addNamedObject (String name, ISvgNodeRenderer namedObject)
      Adds a named object to the draw context. These objects can then be referenced from a different tag.
      Parameters:
      name - name of the object
      namedObject - object to be referenced
    • getNamedObject

      public ISvgNodeRenderer getNamedObject (String name)
      Get a named object based on its name. If the name isn't listed, this method will return null.
      Parameters:
      name - name of the object you want to reference
      Returns:
      the referenced object
    • getResourceResolver

      public ResourceResolver getResourceResolver()
      Gets the ResourceResolver to be used during the drawing operations.
      Returns:
      resource resolver instance
    • addNamedObjects

      public void addNamedObjects (Map<String,ISvgNodeRenderer> namedObjects)
      * Adds a number of named object to the draw context. These objects can then be referenced from a different tag.
      Parameters:
      namedObjects - Map containing the named objects keyed to their ID strings
    • getFontProvider

      public FontProvider getFontProvider()
      Gets the FontProvider to be used during the drawing operations.
      Returns:
      font provider instance
    • getTempFonts

      public FontSet getTempFonts()
      Gets list of temporary fonts from @font-face.
      Returns:
      font set instance
    • setTempFonts

      public void setTempFonts (FontSet tempFonts)
      Sets the FontSet.
      Parameters:
      tempFonts - font set to be used during drawing operations
    • isIdUsedByUseTagBefore

      public boolean isIdUsedByUseTagBefore (String elementId)
      Returns true when this id has been used before
      Parameters:
      elementId - element id to check
      Returns:
      true if id has been encountered before through a use element
    • addUsedId

      public void addUsedId (String elementId)
      Adds an ID that has been referenced by a use element.
      Parameters:
      elementId - referenced element ID
    • removeUsedId

      public void removeUsedId (String elementId)
      Removes an ID that has been referenced by a use element.
      Parameters:
      elementId - referenced element ID
    • getLastTextTransform

      public AffineTransform getLastTextTransform()
      Get the text transformation that was last applied
      Returns:
      AffineTransform representing the last text transformation
    • setLastTextTransform

      public void setLastTextTransform (AffineTransform newTransform)
      Set the last text transformation
      Parameters:
      newTransform - last text transformation
    • getTextMove

      public float[] getTextMove()
      Get the stored current text move
      Returns:
      [horizontal text move, vertical text move]
    • resetTextMove

      public void resetTextMove()
      Reset the stored text move to [0f,0f]
    • addTextMove

      public void addTextMove (float additionalMoveX, float additionalMoveY)
      Increment the stored text move
      Parameters:
      additionalMoveX - horizontal value to add
      additionalMoveY - vertical value to add
    • getCurrentCanvasTransform

      public AffineTransform getCurrentCanvasTransform()
      Get the current canvas transformation
      Returns:
      the AffineTransform representing the current canvas transformation
    • getCssContext

      public SvgCssContext getCssContext()
      Gets the SVG CSS context.
      Returns:
      the SVG CSS context
    • setCssContext

      public void setCssContext (SvgCssContext cssContext)
      Sets the SVG CSS context.
      Parameters:
      cssContext - the SVG CSS context
    • pushPatternId

      public boolean pushPatternId (String patternId)
      Add pattern id to stack. Check if the id is already in the stack. If it is, then return false and not add, if it is not - add and return true.
      Parameters:
      patternId - pattern id
      Returns:
      true if pattern id was not on the stack and was pushed; false if it is on the stack
    • popPatternId

      public void popPatternId()
      Pops the last template id from the stack.
    • setPreviousElementTextMove

      public void setPreviousElementTextMove (float[] previousElementTextMove)
    • getPreviousElementTextMove

      public float[] getPreviousElementTextMove()