Package org.eclipse.nebula.cwt.svg
Class SvgFragment
java.lang.Object
org.eclipse.nebula.cwt.svg.SvgElement
org.eclipse.nebula.cwt.svg.SvgGraphic
org.eclipse.nebula.cwt.svg.SvgContainer
org.eclipse.nebula.cwt.svg.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.
-
Field Summary
Fields Modifier and Type Field Description (package private) SvgTransform
boundsTransform
(package private) java.lang.Float
height
(package private) boolean
preserveAspectRatio
(package private) float[]
viewBox
viewBox[0] == x viewBox[1] == y viewBox[2] == w viewBox[3] == h(package private) java.lang.Float
width
(package private) java.lang.Float
x
(package private) java.lang.Float
y
Fields inherited from class org.eclipse.nebula.cwt.svg.SvgGraphic
description, fill, stroke, title, transform
-
Constructor Summary
Constructors Constructor Description SvgFragment(SvgContainer container, java.lang.String id)
-
Method Summary
Modifier and Type Method Description 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.SvgElement
getElement(java.lang.String id)
SvgFragment
getFragment()
java.lang.Float
getHeight()
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.float[]
getViewBox()
float[]
getViewport()
java.lang.Float
getWidth()
boolean
hasElement(java.lang.String id)
Returns true if this fragment contains an SvgElement with the given id.boolean
isOutermost()
Returns true if this SvgFragment is at the outermost level, meaning it is a direct child of the SvgDocument.(package private) void
put(SvgElement element)
Methods inherited from class org.eclipse.nebula.cwt.svg.SvgContainer
add, apply, getElements, isEmpty
Methods inherited from class org.eclipse.nebula.cwt.svg.SvgGraphic
getDescription, getFill, getStroke, getTitle, getTransform
Methods inherited from class org.eclipse.nebula.cwt.svg.SvgElement
getAncestry, getContainer, getId, setContainer
-
Field Details
-
x
java.lang.Float x -
y
java.lang.Float y -
width
java.lang.Float width -
height
java.lang.Float height -
viewBox
float[] viewBoxviewBox[0] == x viewBox[1] == y viewBox[2] == w viewBox[3] == h -
boundsTransform
SvgTransform boundsTransform -
preserveAspectRatio
boolean preserveAspectRatio
-
-
Constructor Details
-
SvgFragment
SvgFragment(SvgContainer container, java.lang.String id)
-
-
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 contextbounds
- the bounds to which this fragment will be scaled
-
getElement
- Overrides:
getElement
in classSvgElement
-
getFragment
- Overrides:
getFragment
in classSvgElement
-
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 classSvgElement
-
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
-
getViewBox
public float[] getViewBox() -
getWidth
public java.lang.Float getWidth() -
getHeight
public java.lang.Float getHeight()
-