Package net.sf.latexdraw.parsers.svg

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


public class TestSVGPolygonElement extends AbstractTestSVGElement {
  @Test
  public void testEnableRendering() throws MalformedSVGDocument, ParseException {
    node.setAttribute(SVGAttributes.SVG_POINTS, "10,10 20,20"); //$NON-NLS-1$
    SVGPolygonElement pl = new SVGPolygonElement(node, null);
    assertTrue(pl.enableRendering());
  }
View Full Code Here


  @Test
  public void testSetPoints() throws ParseException, MalformedSVGDocument {
    String path = "10,10 20,20"; //$NON-NLS-1$
    node.setAttribute(SVGAttributes.SVG_POINTS, "10,10 20,20"); //$NON-NLS-1$
    SVGPolygonElement pl = new SVGPolygonElement(node, null);

    assertEquals(pl.getPoints(), path);
    pl.setPoints("10,10 20,20"); //$NON-NLS-1$
    assertEquals(2, pl.getPoints2D().size());
    assertEquals(new Point2D.Double(10, 10), pl.getPoints2D().get(0));
    assertEquals(new Point2D.Double(20, 20), pl.getPoints2D().get(pl.getPoints2D().size()-1));

    try {
      pl.setPoints("10,,20fdsf"); //$NON-NLS-1$
      fail();
    }
    catch(ParseException e) { /* */ }
  }
View Full Code Here

  @Test
  public void testGetPoints() throws MalformedSVGDocument, ParseException {
    String path = "10,10 20,20"; //$NON-NLS-1$
    node.setAttribute(SVGAttributes.SVG_POINTS, "10,10 20,20"); //$NON-NLS-1$
    SVGPolygonElement pl = new SVGPolygonElement(node, null);

    assertEquals(pl.getPoints(), path);
  }
View Full Code Here

  @Test
  public void testGetPoints2D() throws MalformedSVGDocument, ParseException {
    String path = "    10\t ,\n  10   \t   20 \t\n\t\r,  \n20   \r30,30  \n"; //$NON-NLS-1$

    node.setAttribute(SVGAttributes.SVG_POINTS, path);
    SVGPolygonElement pl = new SVGPolygonElement(node, null);
    List<Point2D> pts;

    pts = pl.getPoints2D();
    assertNotNull(pts);
    assertEquals(3, pts.size());
    assertEquals(new Point2D.Double(10, 10), pts.get(0));
    assertEquals(new Point2D.Double(20, 20), pts.get(1));
    assertEquals(new Point2D.Double(30, 30), pts.get(pts.size()-1));
View Full Code Here

  @SuppressWarnings("unused")
  @Test
  public void testContructor() throws MalformedSVGDocument, ParseException {
    try {
      new SVGPolygonElement(null, null);
      fail();
    }
    catch(Exception e){/**/}

    try {
      new SVGPolygonElement(node, null);
      fail();
    }
    catch(MalformedSVGDocument e){/**/}
    catch(ParseException e)      {/**/}

    node.setAttribute(SVGAttributes.SVG_POINTS, ""); //$NON-NLS-1$
    new SVGPolygonElement(node, null);

    try {
      node.setAttribute(SVGAttributes.SVG_POINTS, "dsqdgfd"); //$NON-NLS-1$
      new SVGPolygonElement(node, null);
      fail();
    }
    catch(MalformedSVGDocument e){/**/}
    catch(ParseException e)      {/**/}

    node.setAttribute(SVGAttributes.SVG_POINTS, "10,10"); //$NON-NLS-1$
    new SVGPolygonElement(node, null);

    try {
      node.setAttribute(SVGAttributes.SVG_POINTS, ","); //$NON-NLS-1$
      new SVGPolygonElement(node, null);
      fail();
    }
    catch(MalformedSVGDocument e){/**/}
    catch(ParseException e)      {/**/}

    node.setAttribute(SVGAttributes.SVG_POINTS, "10,10 20,20"); //$NON-NLS-1$
    new SVGPolygonElement(node, null);
  }
View Full Code Here

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

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

    final SVGPolygonElement main = (SVGPolygonElement)elt2;
    setSVGLatexdrawParameters(elt);
    setSVGModifiablePointsParameters(main);
    setSVGShadowParameters(getLaTeXDrawElement(elt, LNamespace.XML_TYPE_SHADOW));
    setSVGDbleBordersParameters(getLaTeXDrawElement(elt, LNamespace.XML_TYPE_DBLE_BORDERS));
View Full Code Here

  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

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

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

    final SVGPolygonElement main = (SVGPolygonElement)elt2;
    setSVGLatexdrawParameters(elt);
    setSVGParameters(main);

    final List<Point2D> ptsPol = SVGPointsParser.getPoints(elt.getAttribute(
                 elt.getUsablePrefix(LNamespace.LATEXDRAW_NAMESPACE_URI)+LNamespace.XML_POINTS));
View Full Code Here

            (p3x + cornerGap2) + "," + (p2y + (p1y<p2y ? gap : -gap));//$NON-NLS-1$
      final String ltdPoints = pt1.getX() + " " + pt1.getY() + " " + shape.getPtAt(1).getX() + " " + shape.getPtAt(1).getY() +//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                " " + shape.getPtAt(2).getX() + " " + shape.getPtAt(2).getY() + " " + pt2.getX() + " " + pt2.getY();//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$

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

         shad.setAttribute(SVGAttributes.SVG_POINTS, points);
         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);
        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, ltdPoints);

    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

    final SVGElement elt2 = getLaTeXDrawElement(elt, null);

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

    final SVGPolygonElement main = (SVGPolygonElement)elt2;
    setSVGLatexdrawParameters(elt);
    setSVGParameters(main);

    final List<Point2D> ptsPol = SVGPointsParser.getPoints(elt.getAttribute(
                 elt.getUsablePrefix(LNamespace.LATEXDRAW_NAMESPACE_URI)+LNamespace.XML_POINTS));
View Full Code Here

TOP

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

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.