protected void renderShape(Graphics2D g, Shape shape) throws SVGException
{
//g.setColor(Color.green);
StyleAttribute styleAttrib = new StyleAttribute();
//Don't process if not visible
if (getStyle(styleAttrib.setName("visibility")))
{
if (!styleAttrib.getStringValue().equals("visible")) return;
}
if (getStyle(styleAttrib.setName("display")))
{
if (styleAttrib.getStringValue().equals("none")) return;
}
//None, solid color, gradient, pattern
Paint fillPaint = Color.black; //Default to black. Must be explicitly set to none for no fill.
if (getStyle(styleAttrib.setName("fill")))
{
if (styleAttrib.getStringValue().equals("none")) fillPaint = null;
else
{
fillPaint = handleCurrentColor(styleAttrib);
if (fillPaint == null)
{
URI uri = styleAttrib.getURIValue(getXMLBase());
if (uri != null)
{
Rectangle2D bounds = shape.getBounds2D();
AffineTransform xform = g.getTransform();
SVGElement ele = diagram.getUniverse().getElement(uri);
if (ele != null)
{
fillPaint = ((FillElement)ele).getPaint(bounds, xform);
}
}
}
}
}
//Default opacity
float opacity = 1f;
if (getStyle(styleAttrib.setName("opacity")))
{
opacity = styleAttrib.getRatioValue();
}
float fillOpacity = opacity;
if (getStyle(styleAttrib.setName("fill-opacity")))
{
fillOpacity *= styleAttrib.getRatioValue();
}
Paint strokePaint = null; //Default is to stroke with none
if (getStyle(styleAttrib.setName("stroke")))
{
if (styleAttrib.getStringValue().equals("none")) strokePaint = null;
else
{
strokePaint = handleCurrentColor(styleAttrib);
if (strokePaint == null)
{
URI uri = styleAttrib.getURIValue(getXMLBase());
if (uri != null)
{
Rectangle2D bounds = shape.getBounds2D();
AffineTransform xform = g.getTransform();
SVGElement ele = diagram.getUniverse().getElement(uri);
if (ele != null)
{
strokePaint = ((FillElement)ele).getPaint(bounds, xform);
}
}
}
}
}
float[] strokeDashArray = null;
if (getStyle(styleAttrib.setName("stroke-dasharray")))
{
strokeDashArray = styleAttrib.getFloatList();
if (strokeDashArray.length == 0) strokeDashArray = null;
}
float strokeDashOffset = 0f;
if (getStyle(styleAttrib.setName("stroke-dashoffset")))
{
strokeDashOffset = styleAttrib.getFloatValueWithUnits();
}
int strokeLinecap = BasicStroke.CAP_BUTT;
if (getStyle(styleAttrib.setName("stroke-linecap")))
{
String val = styleAttrib.getStringValue();
if (val.equals("round"))
{
strokeLinecap = BasicStroke.CAP_ROUND;
}
else if (val.equals("square"))
{
strokeLinecap = BasicStroke.CAP_SQUARE;
}
}
int strokeLinejoin = BasicStroke.JOIN_MITER;
if (getStyle(styleAttrib.setName("stroke-linejoin")))
{
String val = styleAttrib.getStringValue();
if (val.equals("round"))
{
strokeLinejoin = BasicStroke.JOIN_ROUND;
}
else if (val.equals("bevel"))
{
strokeLinejoin = BasicStroke.JOIN_BEVEL;
}
}
float strokeMiterLimit = 4f;
if (getStyle(styleAttrib.setName("stroke-miterlimit")))
{
strokeMiterLimit = Math.max(styleAttrib.getFloatValueWithUnits(), 1);
}
float strokeOpacity = opacity;
if (getStyle(styleAttrib.setName("stroke-opacity")))
{
strokeOpacity *= styleAttrib.getRatioValue();
}
float strokeWidth = 1f;
if (getStyle(styleAttrib.setName("stroke-width")))
{
strokeWidth = styleAttrib.getFloatValueWithUnits();
}
// if (strokeWidthScalar != 1f)
// {
strokeWidth *= strokeWidthScalar;
// }
Marker markerStart = null;
if (getStyle(styleAttrib.setName("marker-start")))
{
if (!styleAttrib.getStringValue().equals("none"))
{
URI uri = styleAttrib.getURIValue(getXMLBase());
markerStart = (Marker)diagram.getUniverse().getElement(uri);
}
}
Marker markerMid = null;
if (getStyle(styleAttrib.setName("marker-mid")))
{
if (!styleAttrib.getStringValue().equals("none"))
{
URI uri = styleAttrib.getURIValue(getXMLBase());
markerMid = (Marker)diagram.getUniverse().getElement(uri);
}
}
Marker markerEnd = null;
if (getStyle(styleAttrib.setName("marker-end")))
{
if (!styleAttrib.getStringValue().equals("none"))
{
URI uri = styleAttrib.getURIValue(getXMLBase());
markerEnd = (Marker)diagram.getUniverse().getElement(uri);
}
}