Package net.sf.latexdraw.parsers.svg

Examples of net.sf.latexdraw.parsers.svg.SVGElement


  public SVGElement toSVG(final SVGDocument doc) {
    if(doc==null)
      return null;

    if(!shape.isEmpty()) {
       final SVGElement root     = new SVGGElement(doc);
       final List<IShape> shapes   = shape.getShapes();

       root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_TYPE, LNamespace.XML_TYPE_GROUP);
       root.setAttribute(SVGAttributes.SVG_ID, getSVGID());

       for(final IShape f : shapes)
         root.appendChild(SVGShapesFactory.INSTANCE.createSVGElement(f, doc));

       return root;
    }

    return null;
View Full Code Here


   * @since 2.0.0
   */
  protected LPictureSVGGenerator(final SVGGElement elt, final boolean withTransformation) throws IOException {
    this(ShapeFactory.createPicture(ShapeFactory.createPoint()));

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

    if(elt==null || !(elt2 instanceof SVGImageElement))
      throw new IllegalArgumentException();

    final SVGImageElement main = (SVGImageElement)elt2;
View Full Code Here

  @Override
  public SVGElement toSVG(final SVGDocument doc) {
    if(doc == null)
      return null;

    final SVGElement root = new SVGGElement(doc);
        final SVGElement img;

        root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_PICTURE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());

    img = new SVGImageElement(doc, shape.getPathSource());
    img.setAttribute(SVGAttributes.SVG_X, String.valueOf(shape.getPosition().getX()));
    img.setAttribute(SVGAttributes.SVG_Y, String.valueOf(shape.getPosition().getY()));
    img.setAttribute(SVGAttributes.SVG_HEIGHT, String.valueOf(shape.getImage().getHeight(null)));
    img.setAttribute(SVGAttributes.SVG_WIDTH, String.valueOf(shape.getImage().getWidth(null)));
    setSVGRotationAttribute(root);
    root.appendChild(img);

    return root;
  }
View Full Code Here

   * @since 2.0.0
   */
  protected LCircleArcSVGGenerator(final SVGGElement elt, final boolean withTransformation) {
    this(ShapeFactory.createCircleArc());

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);
    final IArrow arr1  = shape.getArrowAt(0);
    final IArrow arr2  = shape.getArrowAt(-1);

    if(elt==null || !(elt2 instanceof SVGPathElement))
      throw new IllegalArgumentException();
View Full Code Here

    final SVGDefsElement defs  = doc.getFirstChild().getDefs();
    final double rotationAngle = shape.getRotationAngle();
    final double startAngle    = shape.getAngleStart()%(2.*Math.PI);
    final double endAngle      = shape.getAngleEnd()%(2.*Math.PI);
    final ArcStyle type      = shape.getArcStyle();
        final SVGElement root    = new SVGGElement(doc);
        final IPoint start      = shape.getStartPoint();
        final IPoint end        = shape.getEndPoint();
        final double radius      = shape.getWidth()/2.0;
        final boolean largeArcFlag = Math.abs(startAngle-endAngle)>=Math.PI || startAngle>endAngle;
        final SVGPathSegList path  = new SVGPathSegList();
        SVGElement elt;

        root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_TYPE, LNamespace.XML_TYPE_ARC);
        root.setAttribute(SVGAttributes.SVG_ID, getSVGID());

        path.add(new SVGPathSegMoveto(start.getX(), start.getY(), false));
        path.add(new SVGPathSegArc(end.getX(), end.getY(), radius, radius, 0, largeArcFlag, false, false));

        if(type==ArcStyle.CHORD)
          path.add(new SVGPathSegClosePath());
        else
          if(type==ArcStyle.WEDGE) {
            final IPoint gravityCenter = shape.getGravityCentre();
            path.add(new SVGPathSegLineto(gravityCenter.getX(), gravityCenter.getY(), false));
            path.add(new SVGPathSegClosePath());
          }

        if(shape.hasShadow())  {
          final SVGElement shad = new SVGPathElement(doc);

          shad.setAttribute(SVGAttributes.SVG_D, path.toString());
          setSVGShadowAttributes(shad, true);
          root.appendChild(shad);
          setSVGArrow(shape, shad, 0, true, doc, defs);
      setSVGArrow(shape, shad, 1, true, doc, defs);
        }

        // The background of the borders must be filled is there is a shadow.
        if(shape.hasShadow() && shape.getLineStyle()!=LineStyle.NONE) {
            elt = new SVGPathElement(doc);
            elt.setAttribute(SVGAttributes.SVG_D, path.toString());
            setSVGBorderBackground(elt, root);
        }

        elt = new SVGPathElement(doc);
        elt.setAttribute(SVGAttributes.SVG_D, path.toString());
        root.appendChild(elt);

        if(shape.hasDbleBord()) {
            final SVGElement dble = new SVGPathElement(doc);
            dble.setAttribute(SVGAttributes.SVG_D, path.toString());
          setSVGDoubleBordersAttributes(dble);
          root.appendChild(dble);
        }

        setSVGRotationAttribute(root);
View Full Code Here

   * @since 2.0.0
   */
  protected LRhombusSVGGenerator(final SVGGElement elt, final boolean withTransformation) {
    this(ShapeFactory.createRhombus());

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

    if(elt==null || !(elt2 instanceof SVGPolygonElement))
      throw new IllegalArgumentException();

    final SVGPolygonElement main = (SVGPolygonElement)elt2;
View Full Code Here

    final IPoint br  = shape.getBottomRightPoint();
    final IPoint gc = shape.getGravityCentre();
    final IPoint p1 = ShapeFactory.createPoint((tl.getX()+br.getX())/2., tl.getY());
    final IPoint p2 = ShapeFactory.createPoint(br.getX(), (tl.getY()+br.getY())/2.);
    final IPoint p3 = ShapeFactory.createPoint((tl.getX()+br.getX())/2., br.getY());
    final SVGElement root = new SVGGElement(doc);
    SVGElement elt;
      final double gap = getPositionGap()/2.;
      final double cornerGap1 = GLibUtilities.getCornerGap(gc, p1, p2, gap);
      double cornerGap2 = GLibUtilities.getCornerGap(gc, p2, p3, gap);

      if(p2.getX()<p3.getX())
        cornerGap2*=-1;

        final String points = String.valueOf(p1.getX()) + ',' + (p1.getY() - cornerGap1) + ' ' + (p2.getX() + cornerGap2) + ',' + p2.getY() + ' ' + p3.getX() + ',' + (p3.getY() + cornerGap1) + ' ' + (tl.getX() - cornerGap2) + ',' + p2.getY();

        root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_TYPE, LNamespace.XML_TYPE_RHOMBUS);
        root.setAttribute(SVGAttributes.SVG_ID, getSVGID());

        if(shape.hasShadow()) {
          elt = new SVGPolygonElement(doc);
          elt.setAttribute(SVGAttributes.SVG_POINTS, points);
          setSVGShadowAttributes(elt, true);
          root.appendChild(elt);
        }

        if(shape.hasShadow() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE)) {
          // The background of the borders must be filled is there is a shadow.
        elt = new SVGPolygonElement(doc);
        elt.setAttribute(SVGAttributes.SVG_POINTS, points);
        setSVGBorderBackground(elt, root);
        }

    elt = new SVGPolygonElement(doc);
    elt.setAttribute(SVGAttributes.SVG_POINTS, points);
    root.appendChild(elt);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_POINTS, String.valueOf(tl.getX()) + ' ' +
                tl.getY() + ' ' + br.getX() + ' ' + tl.getY() + ' ' + tl.getX() + ' ' + br.getY() + ' ' + br.getX() + ' ' + br.getY());

    if(shape.hasDbleBord()) {
      final SVGElement dblBord = new SVGPolygonElement(doc);
      dblBord.setAttribute(SVGAttributes.SVG_POINTS, points);
      setSVGDoubleBordersAttributes(dblBord);
      root.appendChild(dblBord);
    }

    setSVGAttributes(doc, elt, true);
View Full Code Here

   * @since 2.0.0
   */
  protected LBezierCurveSVGGenerator(final SVGGElement elt, final boolean withTransformation) {
    this(ShapeFactory.createBezierCurve());

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

    if(elt==null || !(elt2 instanceof SVGPathElement))
      throw new IllegalArgumentException();

    final SVGPathElement main = (SVGPathElement)elt2;
View Full Code Here

  public SVGElement toSVG(final SVGDocument doc) {
    if(doc==null || doc.getFirstChild().getDefs()==null)
      return null;

    final SVGDefsElement defs = doc.getFirstChild().getDefs();
    final SVGElement root   = new SVGGElement(doc);
        SVGElement elt;
        final String path     = getPathSegList().toString();

    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_TYPE, LNamespace.XML_TYPE_BEZIER_CURVE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());

         if(shape.hasShadow()) {
           final SVGElement shad = new SVGPathElement(doc);

      shad.setAttribute(SVGAttributes.SVG_D, path);
      setSVGShadowAttributes(shad, false);
      root.appendChild(shad);

      if(!shape.isClosed()) {
        setSVGArrow(shape, shad, 0, true, doc, defs);
        setSVGArrow(shape, shad, 1, true, doc, defs);
      }
    }

        if(shape.hasShadow() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE) && shape.isFilled()) {
          // The background of the borders must be filled is there is a shadow.
        elt = new SVGPathElement(doc);
        elt.setAttribute(SVGAttributes.SVG_D, path);
        setSVGBorderBackground(elt, root);
        }

    elt = new SVGPathElement(doc);
    elt.setAttribute(SVGAttributes.SVG_D, path);
    root.appendChild(elt);

    if(shape.hasDbleBord()) {
      final SVGElement dblBord = new SVGPathElement(doc);
      dblBord.setAttribute(SVGAttributes.SVG_D, path);
      setSVGDoubleBordersAttributes(dblBord);
      root.appendChild(dblBord);
    }

    setSVGAttributes(doc, elt, false);
View Full Code Here

    final String prefix = LNamespace.LATEXDRAW_NAMESPACE+':';

    setDimensionGridElement(elt, prefix);

    SVGElement gridElt = getLaTeXDrawElement(elt, LNamespace.XML_TYPE_GRID_SUB);

    if(gridElt!=null)
      setSubGridElement(gridElt, prefix);

    gridElt = getLaTeXDrawElement(elt, LNamespace.XML_TYPE_GRID);
View Full Code Here

TOP

Related Classes of net.sf.latexdraw.parsers.svg.SVGElement

Copyright © 2018 www.massapicom. 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.