Package net.sf.latexdraw.parsers.svg.path

Examples of net.sf.latexdraw.parsers.svg.path.SVGPathSegList


   * Sets the points of the modifiable points shape using the given SVG element.
   * @param elt The SVG element that contains the points to set.
   * @since 3.0
   */
  protected void initModifiablePointsShape(final SVGPathElement elt) {
    final SVGPathSegList segs = elt.getSegList();
    SVGPathSeg seg;
    final int size = segs.size()-1;
    int i;
    Point2D pt;

    for(i=0; i<size; i++) {
      seg = segs.get(i);

      if(!(seg instanceof SVGPathSegLineto))
        throw new IllegalArgumentException("The given SVG path element is not a polygon."); //$NON-NLS-1$

      pt = ((SVGPathSegLineto)seg).getPoint();
View Full Code Here


   * @param elt The arrowhead element.
   * @param owner The shape that has the arrow.
   * @since 2.0.0
   */
  protected void setArrow(final SVGPathElement path, final SVGMarkerElement elt, final IShape owner, final String svgMarker) {
    final SVGPathSegList list  = path.getSegList();
    final SVGPathSegMoveto m   = (SVGPathSegMoveto)list.get(0);
    final double lineWidth    = owner.hasDbleBord() ? owner.getDbleBordSep() + 2.*owner.getThickness() : owner.getThickness();

    if(list.size()==2 || list.size()==4) // It may be a bar or a bracket
      setArrowBarBracket(path, m, lineWidth, list.get(1), elt, list, svgMarker);
    else if(list.size()==5 || list.size()==10)// It may be an arrow or a double arrow
      setArrowArrow(path, m, lineWidth, list.get(1), list, svgMarker);
  }
View Full Code Here

  private void toSVGBar(final SVGDocument doc, final double lineWidth, final boolean isShadow, final SVGElement marker) {
    final IShape shape      = arrow.getShape();
    final SVGPathElement bar  = new SVGPathElement(doc);
    final double width       = arrow.getTBarSizeDim() + arrow.getTBarSizeNum()*lineWidth;
    final SVGPathSegList path   = new SVGPathSegList();
    final double x         = arrow.getArrowStyle()==ArrowStyle.BAR_IN ? arrow.isLeftArrow() ? 0.5 : -0.5 : 0.;

    bar.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_ARROW_TBAR_SIZE_NUM, String.valueOf(arrow.getTBarSizeNum()));
    path.add(new SVGPathSegMoveto(x, -width/(lineWidth*2.), false));
    path.add(new SVGPathSegLineto(x, width/(lineWidth*2.), false));
    bar.setPathData(path);
    bar.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(isShadow ? shape.getShadowCol() : shape.getLineColour(), true));
    bar.setAttribute(SVGAttributes.SVG_FILL, SVGAttributes.SVG_VALUE_NONE);
    bar.setPathData(path);
    bar.setStrokeWidth(1.);
View Full Code Here

  private double toSVGSquareBracket(final SVGDocument doc, final double lineWidth, final boolean isShadow, final SVGElement marker) {
    final IShape shape      = arrow.getShape();
    final SVGPathElement bar   = new SVGPathElement(doc);
    final double width       = arrow.getTBarSizeDim() + arrow.getTBarSizeNum()*lineWidth;
    final SVGPathSegList path   = new SVGPathSegList();
    final double lgth       = arrow.getBracketNum()*(arrow.getTBarSizeDim()/IShape.PPC + arrow.getTBarSizeNum()*lineWidth)/lineWidth;
    final boolean isInverted    = arrow.isInverted();//FIXME shape.PPC
    final double gapPostion;

    if(arrow.getArrowStyle()==ArrowStyle.LEFT_SQUARE_BRACKET) {
      final double lgth2 = isInverted ? -lgth : 0.;
      path.add(new SVGPathSegMoveto(lgth+lgth2+0.5, -width/(lineWidth*2)+0.5, false));
      path.add(new SVGPathSegLineto(lgth2, -width/(lineWidth*2)+0.5, false));
      path.add(new SVGPathSegLineto(lgth2, width/(lineWidth*2)-0.5, false));
      path.add(new SVGPathSegLineto(lgth+lgth2+0.5, width/(lineWidth*2)-0.5, false));
      gapPostion = isInverted ? -lineWidth/4. : -lineWidth/2.;
    }
    else {
      final double lgth2 = isInverted ? lgth : 0.;
      path.add(new SVGPathSegMoveto(-lgth+lgth2-0.5, -width/(lineWidth*2)+0.5, false));
      path.add(new SVGPathSegLineto(lgth2, -width/(lineWidth*2)+0.5, false));
      path.add(new SVGPathSegLineto(lgth2, width/(lineWidth*2)-0.5, false));
      path.add(new SVGPathSegLineto(-lgth+lgth2-0.5, width/(lineWidth*2)-0.5, false));
      gapPostion = isInverted ? lineWidth/4. : lineWidth/2.;
    }

    marker.appendChild(bar);
    bar.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_ARROW_TBAR_SIZE_NUM, String.valueOf(arrow.getTBarSizeNum()));
View Full Code Here

    final IShape shape      = arrow.getShape();
    final SVGElement arrowSVG   = new SVGPathElement(doc);
    final double width      = (arrow.getArrowSizeNum()*lineWidth + arrow.getArrowSizeDim())/lineWidth;
    double length         = arrow.getArrowLength()*width;
        double inset                = arrow.getArrowInset()*length;
        final SVGPathSegList path   = new SVGPathSegList();

    if(arrow.getArrowStyle()==ArrowStyle.LEFT_ARROW) {
      length *= -1.;
      inset *= -1.;
    }

    final double lgth2 = arrow.isInverted() ? length : 0.;
    path.add(new SVGPathSegMoveto(lgth2, 0., false));
    path.add(new SVGPathSegLineto(-length+lgth2, width/2., false));
    path.add(new SVGPathSegLineto(-length+inset+lgth2, 0.false));
    path.add(new SVGPathSegLineto(-length+lgth2, -width/2., false));
    path.add(new SVGPathSegClosePath());

    marker.appendChild(arrowSVG);
    arrowSVG.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_ARROW_SIZE_NUM, String.valueOf(arrow.getArrowSizeNum()));
    arrowSVG.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(isShadow ? shape.getShadowCol() : shape.getLineColour(), true));
    arrowSVG.setAttribute(SVGAttributes.SVG_D, path.toString());
  }
View Full Code Here

  private void toSVGRoundBracket(final SVGDocument doc, final double lineWidth, final boolean isShadow, final SVGElement marker) {
    final IShape shape        = arrow.getShape();
    final SVGPathElement rbracket   = new SVGPathElement(doc);
    final double width         = (arrow.getTBarSizeDim() + arrow.getTBarSizeNum()*lineWidth)/lineWidth;
    double lgth            = arrow.getRBracketNum()*width;
    final SVGPathSegList path     = new SVGPathSegList();
    double gap            = 0.5;

    if(arrow.getArrowStyle()==ArrowStyle.LEFT_ROUND_BRACKET) {
      lgth *= -1.;
      gap *= -1.;
    }

    final double lgth2 = arrow.isInverted() ? lgth : 0.;
    path.add(new SVGPathSegMoveto(-lgth+lgth2-gap, width/2., false));
    path.add(new SVGPathSegCurvetoCubic(-lgth+lgth2-gap, -width/2., 0., width/2., 0., -width/2., false));

    marker.appendChild(rbracket);
    rbracket.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(isShadow ? shape.getShadowCol() : shape.getLineColour(), true));
    rbracket.setAttribute(SVGAttributes.SVG_FILL, SVGAttributes.SVG_VALUE_NONE);
    rbracket.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_ARROW_TBAR_SIZE_NUM, String.valueOf(arrow.getTBarSizeNum()));
View Full Code Here

    final IShape shape      = arrow.getShape();
    final SVGElement arrowSVG   = new SVGPathElement(doc);
    final double width      = (arrow.getArrowSizeNum()*lineWidth + arrow.getArrowSizeDim())/lineWidth;
    double length         = arrow.getArrowLength()*width;
        double inset                = arrow.getArrowInset()*length;
        final SVGPathSegList path   = new SVGPathSegList();

    if(arrow.getArrowStyle()==ArrowStyle.LEFT_DBLE_ARROW) {
      inset *= -1.;
      length *= -1.;
    }

    final double lgth2 = arrow.isInverted() ? length*2 : 0.;
    path.add(new SVGPathSegMoveto(lgth2, 0., false));
    path.add(new SVGPathSegLineto(-length+lgth2, width/2., false));
    path.add(new SVGPathSegLineto(-length+inset+lgth2, 0., false));
    path.add(new SVGPathSegLineto(-length+lgth2, -width/2., false));
    path.add(new SVGPathSegClosePath());
    path.add(new SVGPathSegMoveto(-length+lgth2, 0., false));
    path.add(new SVGPathSegLineto(-length*2+lgth2, width/2., false));
    path.add(new SVGPathSegLineto(-length*2+inset+lgth2, 0., false));
    path.add(new SVGPathSegLineto(-length*2+lgth2, -width/2., false));
    path.add(new SVGPathSegClosePath());

    marker.appendChild(arrowSVG);
    arrowSVG.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_ARROW_SIZE_NUM, String.valueOf(arrow.getArrowSizeNum()));
    arrowSVG.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(isShadow ? shape.getShadowCol() : shape.getLineColour(), true));
    arrowSVG.setAttribute(SVGAttributes.SVG_D, path.toString());
  }
View Full Code Here

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

    final SVGPathElement main = (SVGPathElement)elt2;
    final SVGPathSegList l = main.getSegList();
    final double sx;
        final double sy;

        if(l.size()<2 && !(l.get(0) instanceof SVGPathSegMoveto) && !(l.get(1) instanceof SVGPathSegArc))
      throw new IllegalArgumentException();

    sx = ((SVGPathSegMoveto)l.get(0)).getX();
    sy = ((SVGPathSegMoveto)l.get(0)).getY();
    final Arc2D arc = ((SVGPathSegArc)l.get(1)).getArc2D(sx, sy);
    double angle = Math.toRadians(arc.getAngleStart())%(Math.PI*2);
    shape.setAngleStart(angle);
    angle = Math.toRadians(arc.getAngleExtent()+arc.getAngleStart())%(Math.PI*2);
    shape.setAngleEnd(angle);
    shape.setPosition(arc.getMinX(), arc.getMaxY());
    shape.setWidth(arc.getMaxX()-arc.getMinX());

    if(l.size()>2)
      if(l.get(2) instanceof SVGPathSegClosePath)
        shape.setArcStyle(ArcStyle.CHORD);
      else
        if(l.size()==4 && l.get(2) instanceof SVGPathSegLineto && l.get(3) instanceof SVGPathSegClosePath)
          shape.setArcStyle(ArcStyle.WEDGE);

    shape.setShowPts(getLaTeXDrawElement(elt, LNamespace.XML_TYPE_SHOW_PTS)!=null);

    setSVGParameters(main);
View Full Code Here

        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

  /**
   * @return True if the path is a unique line.
   * @since 0.1
   */
  public boolean isLine() {
    final SVGPathSegList segList = getSegList();

    return segList.size()==2 && segList.get(0) instanceof SVGPathSegMoveto &&
        segList.get(1) instanceof SVGPathSegLineto ;
  }
View Full Code Here

TOP

Related Classes of net.sf.latexdraw.parsers.svg.path.SVGPathSegList

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.