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 Detail

      • x

        java.lang.Float x
      • y

        java.lang.Float y
      • width

        java.lang.Float width
      • height

        java.lang.Float height
      • viewBox

        float[] viewBox
        viewBox[0] == x viewBox[1] == y viewBox[2] == w viewBox[3] == h
      • preserveAspectRatio

        boolean preserveAspectRatio
      • elementMap

        private java.util.Map<java.lang.String,​SvgElement> elementMap
    • Constructor Detail

      • SvgFragment

        SvgFragment​(SvgContainer container,
                    java.lang.String id)
    • Method Detail

      • 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
      • 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.
      • 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.