Package org.newdawn.slick.svg.inkscape

Source Code of org.newdawn.slick.svg.inkscape.EllipseProcessor

package org.newdawn.slick.svg.inkscape;

import org.newdawn.slick.geom.Ellipse;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.geom.Transform;
import org.newdawn.slick.svg.Diagram;
import org.newdawn.slick.svg.Figure;
import org.newdawn.slick.svg.Loader;
import org.newdawn.slick.svg.NonGeometricData;
import org.newdawn.slick.svg.ParsingException;
import org.w3c.dom.Element;

/**
* Processor for <ellipse> and <path> nodes marked as arcs
*
* @author kevin
*/
public class EllipseProcessor implements ElementProcessor {
 
  /**
   * @see org.newdawn.slick.svg.inkscape.ElementProcessor#process(org.newdawn.slick.svg.Loader, org.w3c.dom.Element, org.newdawn.slick.svg.Diagram, org.newdawn.slick.geom.Transform)
   */
  public void process(Loader loader, Element element, Diagram diagram, Transform t) throws ParsingException {
    Transform transform = Util.getTransform(element);
    transform = new Transform(t, transform);
   
    float x = Util.getFloatAttribute(element,"cx");
    float y = Util.getFloatAttribute(element,"cy");
    float rx = Util.getFloatAttribute(element,"rx");
    float ry = Util.getFloatAttribute(element,"ry");
   
    Ellipse ellipse = new Ellipse(x,y,rx,ry);
    Shape shape = ellipse.transform(transform);

    NonGeometricData data = Util.getNonGeometricData(element);
    data.addAttribute("cx", ""+x);
    data.addAttribute("cy", ""+y);
    data.addAttribute("rx", ""+rx);
    data.addAttribute("ry", ""+ry);
   
    diagram.addFigure(new Figure(Figure.ELLIPSE, shape, data, transform));
  }

  /**
   * @see org.newdawn.slick.svg.inkscape.ElementProcessor#handles(org.w3c.dom.Element)
   */
  public boolean handles(Element element) {
    if (element.getNodeName().equals("ellipse")) {
      return true;
    }
    if (element.getNodeName().equals("path")) {
      if ("arc".equals(element.getAttributeNS(Util.SODIPODI, "type"))) {
        return true;
      }
    }
   
    return false;
  }

}
TOP

Related Classes of org.newdawn.slick.svg.inkscape.EllipseProcessor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.