* @param gfxElem the gfx elem
*
* @return the mT base component
*/
private MTComponent handleGraphicsNode(SVGGraphicsElement gfxElem){
MTComponent returnComp = null;
// logger.debug("Handle Element: " + gfxElem.getTagName());
//Print all css properties and values
// logger.debug("Style Css Text: " + style.getCssText());
// SVG Defaults \\
float fillR = 255;
float fillG = 255;
float fillB = 255;
boolean noFill = false;
float strokeR = 0;
float strokeG = 0;
float strokeB = 0;
float strokeWidth = 1.0f;
boolean noStroke = false;
float strokeOpacity = 1;
float fillOpacity = 1;
int windingRule = GLU.GLU_TESS_WINDING_NONZERO;
// SVG Defaults \\
// Opacity, not as a style attribute but a separate
// as group opacity doesnt get computed right, so we
// mannually track it on a stack
float opacity = opacityStack.peek().floatValue();
//logger.debug("INHERITED OPACITY: " + opacity);
// FILL-RULE \\
Value fillRuleValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.FILL_RULE_INDEX);
String fillRule = fillRuleValue.getStringValue();
if (fillRule.equalsIgnoreCase("nonzero")){
windingRule = GLU.GLU_TESS_WINDING_NONZERO;
}else if (fillRule.equalsIgnoreCase("evenodd")){
windingRule = GLU.GLU_TESS_WINDING_ODD;
}else{
windingRule = GLU.GLU_TESS_WINDING_NONZERO;
}
//logger.debug("fillRule: " + fillRule);
// Fill Opacity \\
Value fillOpacValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.FILL_OPACITY_INDEX);
float computedfillOpac = PaintServer.convertOpacity(fillOpacValue);
fillOpacity = computedfillOpac;
//Multiplicate inherited opacity with this components opacities
fillOpacity *= opacity;
//Save for eventual lineargradient creation later that needs the not interpolated value
float originalFillOpacity = fillOpacity;
//logger.debug("fill opacity unnormalized: " + fillOpacity);
// Fill java.awt.Color \\
Value fillIndexValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.FILL_INDEX);
Object fill = SVGLoader.getFillOrStroke(gfxElem, fillIndexValue, fillOpacity, ctx);
SVGOMLinearGradientElement linearGradient = null;
SVGOMRadialGradientElement radialGradient = null;
if (fill instanceof java.awt.Color) {
java.awt.Color color = (Color) fill;
fillR = color.getRed();
fillG = color.getGreen();
fillB = color.getBlue();
fillOpacity = color.getAlpha();
noFill = false;
//logger.debug("Fill: " + color + " a=" + fillOpacity);
}else if (fill instanceof SVGOMLinearGradientElement) {
//TODO cache gradients so dass man nicht immer neu den gleichen
//machen muss!
linearGradient = (SVGOMLinearGradientElement) fill;
noFill = false;
}else if (fill instanceof SVGOMRadialGradientElement) {
//TODO!! //FIXME TEST
radialGradient = (SVGOMRadialGradientElement)fill;
noFill = false;
}else{
noFill = true;
}
// Stroke Opacity \\
Value strokeOpacValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.STROKE_OPACITY_INDEX);
float computedStrokeOpacity = PaintServer.convertOpacity(strokeOpacValue);
strokeOpacity = computedStrokeOpacity;
// Multiplicate inherited opacity with this components group opacities
strokeOpacity *= opacity;
// Stroke java.awt.Color \\
Value strokeIndexValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.STROKE_INDEX);
Object stroke = SVGLoader.getFillOrStroke(gfxElem, strokeIndexValue, strokeOpacity, ctx);
if (stroke instanceof java.awt.Color) {
java.awt.Color color = (Color) stroke;
strokeR = color.getRed();
strokeG = color.getGreen();
strokeB = color.getBlue();
strokeOpacity = color.getAlpha();
noStroke = false;
}else{
noStroke = true;
strokeR = fillR;
strokeG = fillG;
strokeB = fillB;
}
// Stroke Width \\
Stroke s = PaintServer.convertStroke(gfxElem);
if (s != null){
if (s instanceof BasicStroke) {
BasicStroke basicStroke = (BasicStroke) s;
strokeWidth = basicStroke.getLineWidth();
}
}else{
strokeWidth = 0.0f;
noStroke = true;
}
/*
logger.debug("Fill COL: " + fillR + " " + fillG + " " + fillB + " " fillopacity);
logger.debug("STROKE COL: " + strokeR + " " + strokeG + " " + strokeB + " " strokeOpacity);
*/
// CHECK WHAT KIND OF GRAPHICS ELEMENT IT IS AND CREATE IT \\
if (gfxElem instanceof SVGOMPathElement){
SVGOMPathElement pathElem = (SVGOMPathElement)gfxElem;
//FIXME handle clip-paths in the future
if (isUnderClipPath(pathElem)){
logger.error("Discarding clip-path path element. Not implemented.");
return null;
}
//Create the shape
AbstractShape pathComp = getLivePathComponent(pathElem, noFill, windingRule);
try{
pathComp.setLocalMatrix(currentLocalTransformMatrix);
}catch(Exception e){
logger.error(e.getMessage());
}
returnComp = pathComp;
}else if (gfxElem instanceof SVGOMPolygonElement){
SVGOMPolygonElement polygonElem = (SVGOMPolygonElement)gfxElem;
//Create the shape
AbstractShape comp = getLivePolygonComponent(polygonElem, noFill, windingRule);
try{
comp.setLocalMatrix(currentLocalTransformMatrix);
}catch(Exception e){
logger.error(e.getMessage());
}
returnComp = comp;
}else if (gfxElem instanceof SVGOMPolylineElement){
SVGOMPolylineElement polyLineElem = (SVGOMPolylineElement)gfxElem;
//Create Vertex[] from points
SVGPointList pointList = polyLineElem.getPoints();
Vertex[] vertices = new Vertex[pointList.getNumberOfItems()];
for (int i = 0; i < pointList.getNumberOfItems(); i++) {
SVGPoint p = pointList.getItem(i);
vertices[i] = new Vertex(p.getX(), p.getY(),0);
}
//Create the shape
AbstractShape comp = createPoly(vertices);
try{
comp.setLocalMatrix(currentLocalTransformMatrix);
}catch(Exception e){
logger.error(e.getMessage());
}
returnComp = comp;
}else if (gfxElem instanceof SVGOMRectElement){
SVGOMRectElement rectElem = (SVGOMRectElement)gfxElem;
if (isUnderClipPath(rectElem)){
logger.error("discarding clip-path Rect");
return null;
}
float x = rectElem.getX().getBaseVal().getValue();
float y = rectElem.getY().getBaseVal().getValue();
float width = rectElem.getWidth().getBaseVal().getValue();
float height = rectElem.getHeight().getBaseVal().getValue();
float rx = rectElem.getRx().getBaseVal().getValue();
float ry = rectElem.getRy().getBaseVal().getValue();
AbstractShape comp;
//Create a normal rectangle or a round rectangle
if (rx != 0.0f || ry != 0.0f){
if (rx > width/2 )
rx = width/2;
if (ry > height/2 )
ry = height/2;
comp = new MTRoundRectangle(x,y,0, width,height,rx, ry, pa);
}else{
comp = new MTRectangle(x,y, width,height, pa);
}
try{
comp.setLocalMatrix(currentLocalTransformMatrix);
}catch(Exception e){
logger.error(e.getMessage());
}
returnComp = comp;
}else if (gfxElem instanceof SVGOMEllipseElement){
SVGOMEllipseElement ellipseElem = (SVGOMEllipseElement)gfxElem;
float cx = ellipseElem.getCx().getBaseVal().getValue();
float cy = ellipseElem.getCy().getBaseVal().getValue();
float r = ellipseElem.getRx().getBaseVal().getValue();
float r2 = ellipseElem.getRy().getBaseVal().getValue();
Vertex middlePoint = new Vertex(cx,cy,0);
//Apply transformation, transform centerpoint and the radii
try{
middlePoint.transform(currentLocalTransformMatrix);
}catch(Exception e){
logger.error(e.getMessage());
}
//somehow the circle radii need to be doubled
//or else theyre too small => processing bug?
// r*=2;
// r2*=2;
MTEllipse comp = new MTEllipse(pa, middlePoint, r, r2);
returnComp = comp;
}else if (gfxElem instanceof SVGOMCircleElement){
SVGOMCircleElement circleElem = (SVGOMCircleElement)gfxElem;
float cx = circleElem.getCx().getBaseVal().getValue();
float cy = circleElem.getCy().getBaseVal().getValue();
float r = circleElem.getR().getBaseVal().getValue();
float r2 = circleElem.getR().getBaseVal().getValue();
Vertex middlePoint = new Vertex(cx,cy,0);
//Apply transformation, transform centerpoint and the radii
try{
middlePoint.transform(currentLocalTransformMatrix);
}catch(Exception e){
logger.error(e.getMessage());
}
//somehow the circle radii need to be doubled
//or else theyre too small => processing bug?
// r*=2;
// r2*=2;
MTEllipse comp = new MTEllipse(pa, middlePoint, r, r2);
returnComp = comp;
}else if (gfxElem instanceof SVGOMLineElement){
SVGOMLineElement line = (SVGOMLineElement)gfxElem;
float x1 = line.getX1().getBaseVal().getValue();
float y1 = line.getY1().getBaseVal().getValue();
float x2 = line.getX2().getBaseVal().getValue();
float y2 = line.getY2().getBaseVal().getValue();
//logger.debug("Line x1: " + x1 + ",y1:" + y1 + ",x2:" + x2 + ",y2:" + y2);
MTLine comp = new MTLine(pa, x1,y1 ,x2,y2);
try{
comp.setLocalMatrix(currentLocalTransformMatrix);
}catch(Exception e){
logger.error(e.getMessage());
}
returnComp = comp;
}else if (gfxElem instanceof SVGOMClipPathElement){
}else if (gfxElem instanceof SVGOMDefsElement){
}else if (gfxElem instanceof SVGOMMaskElement){
}else if (gfxElem instanceof SVGOMSwitchElement){
}else if (gfxElem instanceof SVGOMFlowRootElement){
}else if (gfxElem instanceof SVGURIReferenceGraphicsElement){
}else if (gfxElem instanceof BindableElement){
}else if (gfxElem instanceof SVGOMForeignObjectElement){
}else if (gfxElem instanceof SVGOMToBeImplementedElement){
}
//Do the finishing touch of the svg graphics element
if (returnComp != null){
returnComp.setName(gfxElem.getTagName());
//Set style infos
if (returnComp instanceof AbstractVisibleComponent){
AbstractVisibleComponent comp = (AbstractVisibleComponent)returnComp;
//Set Fill