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:

  • Field Details

  • Constructor Details

  • Method Details

    • apply

      public void apply​( gc, 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.
      gc - the graphics context
      bounds - the bounds to which this fragment will be scaled
    • getElement

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

      public SvgFragment getFragment()
      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.

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

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

      public boolean hasElement​(java.lang.String id)
      Returns true if this fragment contains an SvgElement with the given id.
      id - the id of the element
      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.
      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()