Class SvgFragment


public class SvgFragment
extends SvgContainer
An svg document can contain one or more svg fragments, each denoted by the "svg" tag. Each of these consists of all the information necessary to paint a graphic to the screen, including definition and css style child elements.

Of particular importance is that the svg fragment can also contain a viewbox which can be used for scaling the image to a particular size. Therefore this element is where the real-world rendered dimensions interact with the svg dimenions.

See also: http://www.w3.org/TR/SVG/struct.html#SVGElement

  • Field Details

  • Constructor Details

  • Method Details

    • apply

      public void apply​(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle bounds)
      Apply this svg fragment to the given graphics context, scaled to fit within the given bounds. This method will recursive call the apply methods of all contained svg elements, thereby painting the entire fragment to the given graphics context.
      Parameters:
      gc - the graphics context
      bounds - the bounds to which this fragment will be scaled
    • getElement

      public SvgElement getElement​(java.lang.String id)
      Overrides:
      getElement in class SvgElement
    • getFragment

      public SvgFragment getFragment()
      Overrides:
      getFragment in class SvgElement
    • getStyles

      public java.util.Map<java.lang.String,​java.lang.String> getStyles​(java.lang.String className)
      Return a map of css styles for the given class name, if it exists.

      Each SvgFragment can contain a style element which consists of css styles.

      Parameters:
      className - the name of the css class to return styles for.
      Returns:
      a map of css style for the given class name if it exists, null otherwise.
    • getViewport

      public float[] getViewport()
      Overrides:
      getViewport in class SvgElement
    • hasElement

      public boolean hasElement​(java.lang.String id)
      Returns true if this fragment contains an SvgElement with the given id.
      Parameters:
      id - the id of the element
      Returns:
      true if the element exists, false otherwise
    • isOutermost

      public boolean isOutermost()
      Returns true if this SvgFragment is at the outermost level, meaning it is a direct child of the SvgDocument. This is an important distinction because, as with all svg elements, fragments can be nested. Each svg fragment will establish a new coordinate system, but only the outer fragment will determine the scaling necessary to display at the requested size.
      Returns:
      true if this fragment is at the outermost level, false otherwise.
    • put

      void put​(SvgElement element)
    • getViewBox

      public float[] getViewBox()
    • getWidth

      public java.lang.Float getWidth()
    • getHeight

      public java.lang.Float getHeight()