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
comp.setFillColor(new MTColor(fillR, fillG, fillB, fillOpacity));
comp.setNoFill(noFill);
//Set Stroke
comp.setStrokeColor(new MTColor(strokeR, strokeG, strokeB, strokeOpacity));
//Opengl cant handle big lines well
//So cap at width 3
if (strokeWidth > 2.0f)
strokeWidth = 2.0f;
comp.setStrokeWeight(strokeWidth);
comp.setNoStroke(noStroke);
//Other
comp.setDrawSmooth(true);
comp.setPickable(false);
//Hack for smoothing non stroked components with a stroke same as fillcolor
if (comp.isNoStroke()
&& linearGradient == null
){
comp.setStrokeColor(new MTColor(fillR, fillG, fillB, fillOpacity)); //fillOpacity
comp.setStrokeWeight(0.6f);
//Ellipse doesent smooth right with 0.1f strokeweight
if (comp instanceof MTEllipse){
comp.setStrokeWeight(1.0f);
}
comp.setNoStroke(false);
}
//Some settings for Geometric shapes (actually should all be)
if (comp instanceof AbstractShape ){
AbstractShape shape = (AbstractShape)comp;
//Set a bounding rectangle to check first at picking
if (shape.getVerticesLocal().length >= 3){
shape.setBoundsBehaviour(AbstractShape.BOUNDS_CHECK_THEN_GEOMETRY_CHECK);
//shape.setBoundingShape(new BoundsZPlaneRectangle(shape)); //already done by override, (ie svgpoly)
//Create amd apply the linear gradient if existant and if we are in opengl rendering mode
if (MT4jSettings.getInstance().isOpenGlMode()){
if (linearGradient != null){
FillPaint gradient = this.createLinearGradient(linearGradient, gfxElem, originalFillOpacity, shape);
if (gradient != null){
shape.setFillPaint(gradient);
}
}
if (radialGradient != null){
FillPaint gradient = this.createRadialGradient(radialGradient, gfxElem, opacity, shape);
if (gradient != null){
shape.setFillPaint(gradient);
}
}
//Per default use direct gl drawing and displaylists in OGL mode
if (pa instanceof MTApplication) {
MTApplication app = (MTApplication) pa;
app.invokeLater(new InvokeLaterAction(shape));
}
}
//IF shape has no or only 1 vertex return null
}else if (shape.getVerticesLocal().length < 2){
return null;
}else{
shape.setBoundsBehaviour(AbstractShape.BOUNDS_DONT_USE);
shape.setBounds(null);
// shape.setUseDirectGL(false);
}
//Allow for picking the shape
shape.setPickable(true);
//Assign default gestures
// shape.assignGestureClassAndAction(DragGestureAnalyzer.class, defaultDragAction);
// shape.registerInputAnalyzer(new DragDetector(pa));
// shape.setGestureAllowance(DragDetector.class, true);