Package net.sf.latexdraw.parsers.svg

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


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

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

    if(elt==null || !(elt2 instanceof SVGPolyLineElement) && !(elt2 instanceof SVGLineElement))
      throw new IllegalArgumentException();

    if(elt2 instanceof SVGPolyLineElement) {
      setSVGModifiablePointsParameters((SVGPolyLineElement)elt2);
    }else {
      final SVGLineElement lineElt = (SVGLineElement)elt2;
      shape.addPoint(ShapeFactory.createPoint(lineElt.getX1(), lineElt.getY1()));
      shape.addPoint(ShapeFactory.createPoint(lineElt.getX2(), lineElt.getY2()));
    }

    setSVGParameters(elt2);
    setSVGLatexdrawParameters(elt);
    setSVGShadowParameters(getLaTeXDrawElement(elt, LNamespace.XML_TYPE_SHADOW));
    setSVGDbleBordersParameters(getLaTeXDrawElement(elt, LNamespace.XML_TYPE_DBLE_BORDERS));
    final IArrow arrow1   = shape.getArrowAt(0);
    final IArrow arrow2   = shape.getArrowAt(-1);
    setSVGArrow(arrow1, elt2.getAttribute(elt2.getUsablePrefix()+SVGAttributes.SVG_MARKER_START), elt2, SVGAttributes.SVG_MARKER_START);
    setSVGArrow(arrow2, elt2.getAttribute(elt2.getUsablePrefix()+SVGAttributes.SVG_MARKER_END), elt2, SVGAttributes.SVG_MARKER_END);
    homogeniseArrows(arrow1, arrow2);

    if(withTransformation)
      applyTransformations(elt);
  }
View Full Code Here


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

        final SVGElement root     = new SVGGElement(doc);
    final SVGDefsElement defs   = doc.getFirstChild().getDefs();
    final StringBuilder points   = new StringBuilder();
    final List<IPoint> pts    = shape.getPoints();
    SVGPolyLineElement elt;

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

    for(final IPoint pt : pts)
      points.append(pt.getX()).append(',').append(pt.getY()).append(' ');

    final String pointsStr = points.toString();

    if(shape.hasShadow()) {
      final SVGPolyLineElement shad = new SVGPolyLineElement(doc);
      try { shad.setPoints(pointsStr); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
      setSVGShadowAttributes(shad, false);
      root.appendChild(shad);
      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 SVGPolyLineElement(doc);
        try { elt.setPoints(pointsStr); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
        setSVGBorderBackground(elt, root);
        }

    elt = new SVGPolyLineElement(doc);
    try { elt.setPoints(pointsStr); }catch(final ParseException ex) { BadaboomCollector.INSTANCE.add(ex); }
    root.appendChild(elt);

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

    setSVGAttributes(doc, elt, false);
    elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));
View Full Code Here

     * @param doc The SVG document used to create elements.
     * @return The created view or null.
     * @since 3.0
     */
    public SVGElement execute(final IShape model, final SVGDocument doc) {
      final SVGElement view;

      if(clazz.isInstance(model))
        view = create(model, doc);
      else
        view = next==null ? null : next.execute(model, doc);
View Full Code Here

    final SVGNodeList nl = elt.getChildren(SVGElements.SVG_G);
    int i=0;
        final int size = nl.getLength();
        SVGGElement l1=null;
        SVGGElement l2=null;
        SVGElement element;

    while((l1==null || l2==null) && i<size) {
      element = nl.item(i);

      if(element instanceof SVGGElement)
View Full Code Here

//    final Graphics2D2SVG graphics = new Graphics2D2SVG(doc);
//    IViewShape view = View2DTK.getFactory().createView(shape);

//        view.paint(graphics);
        //  graphics.getElement();
        final SVGElement root = new SVGGElement(doc);
    final String pref = LNamespace.LATEXDRAW_NAMESPACE+':';
    setThickness(root, shape.getThickness(), false, 0.);
    root.setStroke(shape.getLineColour());

    root.setAttribute(pref+LNamespace.XML_STYLE, shape.getAxesStyle().toString());
    root.setAttribute(pref+LNamespace.XML_GRID_START, shape.getGridStartX() + " " + shape.getGridStartY()); //$NON-NLS-1$
    root.setAttribute(pref+LNamespace.XML_GRID_END, shape.getGridEndX() + " " + shape.getGridEndY());//$NON-NLS-1$
    root.setAttribute(pref+LNamespace.XML_GRID_ORIGIN, shape.getOriginX() + " " + shape.getOriginY());//$NON-NLS-1$
    root.setAttribute(pref+LNamespace.XML_AXE_INCREMENT, shape.getIncrementX() + " " + shape.getIncrementY());//$NON-NLS-1$
    root.setAttribute(pref+LNamespace.XML_AXE_DIST_LABELS, shape.getDistLabelsX() + " " + shape.getDistLabelsY());//$NON-NLS-1$
    root.setAttribute(pref+LNamespace.XML_AXE_TICKS_SIZE, String.valueOf(shape.getTicksSize()));
    root.setAttribute(pref+LNamespace.XML_AXE_SHOW_ORIGIN, String.valueOf(shape.isShowOrigin()));
    root.setAttribute(pref+LNamespace.XML_AXE_SHOW_TICKS, shape.getTicksDisplayed().toString());
    root.setAttribute(pref+LNamespace.XML_AXE_LABELS_STYLE, shape.getLabelsDisplayed().toString());
    root.setAttribute(pref+LNamespace.XML_AXE_TICKS_STYLE, shape.getTicksStyle().toString());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE+':'+LNamespace.XML_TYPE, LNamespace.XML_TYPE_AXE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    createSVGAxe(root, doc);
    setSVGRotationAttribute(root);

//    view.flush();
//    graphics.dispose();
View Full Code Here

      xLine.getArrowAt(0).copy(arr0);
      xLine.getArrowAt(1).copy(arr1);
      yLine.getArrowAt(0).copy(shape.getArrowAt(0));
      yLine.getArrowAt(1).copy(shape.getArrowAt(2));
      final SVGElement eltX = new LPolylinesSVGGenerator(xLine).toSVG(document);
      final SVGElement eltY = new LPolylinesSVGGenerator(yLine).toSVG(document);

      elt.appendChild(eltX);
      elt.appendChild(eltY);
    }
  }
View Full Code Here

   * @param elt The source element.
   * @throws IllegalArgumentException If the given element is null or not valid.
   * @since 3.0
   */
  protected void initRectangle(final SVGGElement elt, final boolean withTransformation) {
    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

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

    setSVGLatexdrawParameters(elt);
View Full Code Here

      throw new IllegalArgumentException();

    final double gap = getPositionGap();
    final IPoint tl  = shape.getTopLeftPoint();
    final IPoint br  = shape.getBottomRightPoint();
    SVGElement elt;
        final SVGElement root = new SVGGElement(document);
        final double width  = Math.max(1, br.getX()-tl.getX()+gap);
        final double height = Math.max(1., br.getY()-tl.getY()+gap);
        final double x    = tl.getX()-gap/2.;
        final double y    = tl.getY()-gap/2.;

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

        if(shape.hasShadow()) {
          elt = new SVGRectElement(x, y, width, height, document);
          setSVGShadowAttributes(elt, true);
          root.appendChild(elt);
          setSVGRoundCorner(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 SVGRectElement(x, y, width, height, document);
          setSVGBorderBackground(elt, root);
          setSVGRoundCorner(elt);
        }

        elt = new SVGRectElement(x, y, width, height, document);
        root.appendChild(elt);
        setSVGAttributes(document, elt, true);
        setSVGRoundCorner(elt);

        if(shape.hasDbleBord()) {
          elt = new SVGRectElement(x, y, width, height, document);
          setSVGDoubleBordersAttributes(elt);
          setSVGRoundCorner(elt);
          root.appendChild(elt);
        }

        setSVGRotationAttribute(root);

    return root;
View Full Code Here


  protected LFreeHandSVGGenerator(final SVGGElement elt, final boolean withTransformation) {
    this(ShapeFactory.createFreeHand());

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

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

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

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

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

    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_FREEHAND);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_PATH_TYPE, String.valueOf(shape.getType()));
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_INTERVAL, String.valueOf(shape.getInterval()));
    final String path = getPath().toString();
    final StringBuilder pts = new StringBuilder();

    for(int i = 0, size = shape.getNbPoints(); i < size; i++)
        pts.append(shape.getPtAt(i).getX()).append(' ').append(shape.getPtAt(i).getY()).append(' ');

    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POINTS, pts.toString());

    if(shape.hasShadow()) {
      final SVGElement shad = new SVGPathElement(doc);
      shad.setAttribute(SVGAttributes.SVG_D, path);
      setSVGShadowAttributes(shad, false);
      root.appendChild(shad);
    }

        if(shape.hasShadow() && shape.getLineStyle()!=LineStyle.NONE && shape.isFilled())
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.