// logger.debug("Node: " + node.getNodeName() + " Class: " + node.getClass());
//For opacity inheritance
if (node instanceof SVGGraphicsElement){
SVGGraphicsElement svgGfx = (SVGGraphicsElement)node;
//Handle inherited opacity settings
float opac = queryPrimitiveFloatValue(svgGfx, "opacity", 1f);
opacityStack.push(opac *= opacityStack.peek().floatValue());
}
// if G (GROUP) element, add all children to this element
if ( node instanceof SVGOMGElement
|| node instanceof SVGSVGElement
|| node instanceof SVGOMSVGElement
){
// SVGOMGElement gElem = (SVGOMGElement)node;
SVGElement gElem = (SVGElement)node;
MTComponent group = new MTComponent(pa);
group.setName(gElem.getTagName());
// Element viewPort = gElem.getViewportElement();
// logger.debug("Viewport " + viewPort.getNodeName());
//Set the <g> group to composite, meaning that it will
//be returned at picking, when one of the children gets picked
group.setComposite(true);
group.setLocalMatrix(currentLocalTransformMatrix);
//IF its <svg> element get the transform
//(to honor the viewBox and the width/height attributes
if (node instanceof SVGOMSVGElement ){
SVGOMSVGElement svgGom = ((SVGOMSVGElement)node);
Element viewPort = svgGom.getViewportElement();
if (viewPort != null)
logger.debug("Viewport " + viewPort.getNodeName());
// SVGMatrix mat = svgGom.getScreenCTM();
SVGAnimatedLength widthA = svgGom.getWidth();
SVGAnimatedLength heightA = svgGom.getHeight();
SVGLength w = widthA.getBaseVal();
float width = w.getValue();
SVGLength h = heightA.getBaseVal();
float height = h.getValue();
logger.debug("-> SVG Width: " + width + " Height: " + height);
SVGMatrix mat = svgGom.getCTM();
/*
logger.debug("mat: " + mat.toString());
logger.debug(mat.getA());
logger.debug(mat.getB());
logger.debug(mat.getC());
logger.debug(mat.getD());
logger.debug(mat.getE());
logger.debug(mat.getF());
SVGRect bbox = svgGom.getBBox();
logger.debug("BBOx: X:" + bbox.getX() + " Y:" + bbox.getY() + " Width:" + bbox.getWidth() + " Height:" + bbox.getHeight());
*/
//Hack, because if no width/height is specified default of 1.0
//is assumed by batik -> things may get scaled too small
if ( !(width == 1 && height == 1) ){
currentLocalTransformMatrix = new Matrix(mat.getA(), mat.getC(), 0, mat.getE(),
mat.getB(), mat.getD(), 0, mat.getF(),
0, 0, 1, 0,
0, 0, 0, 1
);
//logger.debug("Matrix: " + currentLocalTransformMatrix);
group.setLocalMatrix(currentLocalTransformMatrix);
}
}
//Make the group pickable and manipulatable
group.setPickable(true);
group.registerInputProcessor(new DragProcessor(pa));
group.setGestureAllowance(DragProcessor.class, true);
group.addGestureListener(DragProcessor.class, (IGestureEventListener)defaultDragAction);
group.registerInputProcessor(new RotateProcessor(pa));
group.addGestureListener(RotateProcessor.class, defaultRotateAction);
group.registerInputProcessor(new ScaleProcessor(pa));
group.addGestureListener(ScaleProcessor.class, defaultScaleAction);
ArrayList<MTComponent> groupChildren = new ArrayList<MTComponent>();
//Traverse the children and add them to a new arraylist
traverseChildren(gElem, groupChildren);
MTComponent[] childComps = (MTComponent[])groupChildren.toArray(new MTComponent[groupChildren.size()]);
//Add the children to the group
group.addChildren(childComps);
//Add the group to the arraylist of the parent
comps.add(group);
}else{//If NOT GROUP
if (node instanceof SVGGraphicsElement){
SVGGraphicsElement svgGfxElem = (SVGGraphicsElement)node;
//IF node isnt a group node just add it to the passed in comps arraylist
try{
//Create a component from the graphicsnode and add it to the parents arraylist
MTComponent liveComponent = handleGraphicsNode(svgGfxElem);
if (liveComponent != null){
comps.add(liveComponent);
}
}catch(Exception e){
logger.error("Error handling svg node: " + svgGfxElem.getTagName());
e.printStackTrace();
}
}
//FIXME IMPLEMENT