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;

    final Graphics2D2SVG graphics = new Graphics2D2SVG(doc);
        final SVGElement root;
        final boolean viewCreated;
        // Instead of creating a view, its is gathered from the Java view of the application.
    IViewShape view = MappingRegistry.REGISTRY.getTargetFromSource(shape, IViewDot.class);

    if(view==null) {
      view =  View2DTK.getFactory().createView(shape);
      viewCreated = true;
    }
    else viewCreated = false;

        view.paint(graphics, null);
        root = graphics.getElement();

        root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_TYPE, LNamespace.XML_TYPE_DOT);
        root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_SIZE, String.valueOf(shape.getDiametre()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_DOT_SHAPE, shape.getDotStyle().getPSTToken());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_POSITION, shape.getPosition().getX() + " " + shape.getPosition().getY()); //$NON-NLS-1$

    graphics.dispose();

    if(viewCreated)
      view.flush();
View Full Code Here


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

    final SVGElement root = new SVGGElement(doc);
    final String ltdPref  = LNamespace.LATEXDRAW_NAMESPACE + ':';
    final Element txt     = new SVGTextElement(doc);

    root.setAttribute(ltdPref + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TEXT);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    root.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(shape.getLineColour(), true));
    root.setAttribute(ltdPref + LNamespace.XML_POSITION, String.valueOf(shape.getTextPosition().getLatexToken()));

    txt.setAttribute(SVGAttributes.SVG_X, String.valueOf(shape.getX()));
    txt.setAttribute(SVGAttributes.SVG_Y, String.valueOf(shape.getY()));
    txt.appendChild(doc.createCDATASection(shape.getText()));
    root.appendChild(txt);

    setSVGRotationAttribute(root);

    return root;
  }
View Full Code Here



  private double toSVGCircle(final SVGDocument doc, final double lineWidth, final boolean isShadow, final SVGElement marker) {
    final IShape shape     = arrow.getShape();
    final SVGElement circle = new SVGCircleElement(doc);
    final double r       = (arrow.getDotSizeDim()+arrow.getDotSizeNum()*lineWidth)/2.-lineWidth/2.;

    circle.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_ARROW_DOT_SIZE_NUM, String.valueOf(arrow.getDotSizeNum()));
    circle.setAttribute(SVGAttributes.SVG_R, String.valueOf(r/lineWidth));
    circle.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(shape.getFillingCol(), true));
    circle.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(isShadow ? shape.getShadowCol() : shape.getLineColour(), true));
    circle.setStrokeWidth(1);
    marker.appendChild(circle);

    return arrow.getArrowStyle()==ArrowStyle.CIRCLE_IN ? lineWidth*(arrow.isLeftArrow() ? -1. : 1.) : 0.;
  }
View Full Code Here



  private double toSVGDisk(final SVGDocument doc, final double lineWidth, final boolean isShadow, final SVGElement marker) {
    final IShape shape     = arrow.getShape();
    final SVGElement circle = new SVGCircleElement(doc);
    final double r       = (arrow.getDotSizeDim()+arrow.getDotSizeNum()*lineWidth)/2.;

    circle.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_ARROW_DOT_SIZE_NUM, String.valueOf(arrow.getDotSizeNum()));
    circle.setAttribute(SVGAttributes.SVG_R, String.valueOf(r/lineWidth));
    circle.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(isShadow ? shape.getShadowCol() : shape.getLineColour(), true));
    marker.appendChild(circle);

    return arrow.getArrowStyle()==ArrowStyle.DISK_IN ? lineWidth *  (arrow.isLeftArrow() ? -1. : 1.) : 0.;
  }
View Full Code Here



  private void toSVGArrow(final SVGDocument doc, final double lineWidth, final boolean isShadow, final SVGElement marker) {
    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 toSVGDoubleArrow(final SVGDocument doc, final double lineWidth, final boolean isShadow, final SVGElement marker) {
    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

  }


  private void toSVGRoundIn(final SVGDocument doc, final boolean isShadow, final SVGElement marker) {
    final IShape shape     = arrow.getShape();
    final SVGElement circle = new SVGCircleElement(doc);
    circle.setAttribute(SVGAttributes.SVG_R, "0.5"); //$NON-NLS-1$
    circle.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(isShadow ? shape.getShadowCol() : shape.getLineColour(), true));
    marker.appendChild(circle);
  }
View Full Code Here

  public SVGElement toSVG(final SVGDocument doc, final boolean isShadow) {
    if(doc==null || !arrow.hasStyle())
      return null;

    final ArrowStyle arrowStyle = arrow.getArrowStyle();
    final SVGElement marker   = new SVGMarkerElement(doc);
    final double lineWidth    = arrow.getShape().getFullThickness();
    double gapPostion       = 0.;

    if(arrowStyle==ArrowStyle.CIRCLE_END || arrowStyle==ArrowStyle.CIRCLE_IN)
      gapPostion = toSVGCircle(doc, lineWidth, isShadow, marker);
    else
    if(arrowStyle==ArrowStyle.DISK_END || arrowStyle==ArrowStyle.DISK_IN)
      gapPostion = toSVGDisk(doc, lineWidth, isShadow, marker);
    else
    if(arrowStyle.isBar())
      toSVGBar(doc, lineWidth, isShadow, marker);
    else if(arrowStyle.isSquareBracket())
      toSVGSquareBracket(doc, lineWidth, isShadow, marker);
    else
    if(arrowStyle==ArrowStyle.RIGHT_ARROW || arrowStyle==ArrowStyle.LEFT_ARROW)
      toSVGArrow(doc, lineWidth, isShadow, marker);
    else
    if(arrowStyle.isRoundBracket())
      toSVGRoundBracket(doc, lineWidth, isShadow, marker);
    else
    if(arrowStyle==ArrowStyle.LEFT_DBLE_ARROW || arrowStyle==ArrowStyle.RIGHT_DBLE_ARROW)
      toSVGDoubleArrow(doc, lineWidth, isShadow, marker);
    else
    if(arrowStyle==ArrowStyle.ROUND_IN)
      toSVGRoundIn(doc, isShadow, marker);

    if(!LNumber.equalsDouble(gapPostion,0.))
      marker.setAttribute(SVGAttributes.SVG_REF_X, String.valueOf(gapPostion/lineWidth));

    marker.setAttribute(SVGAttributes.SVG_OVERFLOW, SVGAttributes.SVG_VALUE_VISIBLE);
    marker.setAttribute(SVGAttributes.SVG_ORIENT, SVGAttributes.SVG_VALUE_AUTO);

    return marker;
  }
View Full Code Here

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

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

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

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

  @Override
  public SVGElement toSVG(final SVGDocument doc) {
    if(doc==null)
      throw new IllegalArgumentException();

    final SVGElement root = new SVGGElement(doc);
    SVGPolygonElement elt;
    final StringBuilder pointsBuilder = new StringBuilder();

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

        for(final IPoint pt : shape.getPoints())
          pointsBuilder.append(pt.getX()).append(',').append(pt.getY()).append(' ');

        final String points = pointsBuilder.toString();

        if(shape.hasShadow()) {
          final SVGPolygonElement shad = new SVGPolygonElement(doc);
          try { shad.setPoints(points); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
          setSVGShadowAttributes(shad, true);
          root.appendChild(shad);
        }

        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);
          try { elt.setPoints(points); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
          setSVGBorderBackground(elt, root);
        }

        elt = new SVGPolygonElement(doc);
        try { elt.setPoints(points); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
        root.appendChild(elt);
        setSVGAttributes(doc, elt, true);
        elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE +':'+ LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));

        if(shape.hasDbleBord()) {
          final SVGPolygonElement dblBord = new SVGPolygonElement(doc);
          try { dblBord.setPoints(points); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
          setSVGDoubleBordersAttributes(dblBord);
          root.appendChild(dblBord);
        }

        return root;
  }
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.