Search in sources :

Example 1 with SVGElement

use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.

the class TestSVGAttr method testLookupNamespaceURIOK.

@Test
public void testLookupNamespaceURIOK() {
    SVGAttr attr = new SVGAttr("pref:n", "", node);
    SVGElement elt = (SVGElement) node.getOwnerDocument().createElement("tag2");
    elt.setAttribute("xmlns:pref", "namespace");
    elt.appendChild(node);
    assertEquals("namespace", attr.lookupNamespaceURI("pref"));
}
Also used : SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGAttr(net.sf.latexdraw.parsers.svg.SVGAttr) Test(org.junit.Test)

Example 2 with SVGElement

use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.

the class TestSVGAttr method testGetNamespaceURIOK.

@Test
public void testGetNamespaceURIOK() {
    SVGAttr attr = new SVGAttr("pref:n", "", node);
    SVGElement elt = (SVGElement) node.getOwnerDocument().createElement("tag2");
    elt.setAttribute("xmlns:pref", "namespace");
    elt.appendChild(node);
    assertEquals("namespace", attr.getNamespaceURI());
}
Also used : SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGAttr(net.sf.latexdraw.parsers.svg.SVGAttr) Test(org.junit.Test)

Example 3 with SVGElement

use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.

the class TestSVGNodeList method testItemKO.

@Test
public void testItemKO() {
    final SVGElement elt = (SVGElement) doc.createElement("elt");
    list.getNodes().add(elt);
    assertNull(list.item(-1));
    assertNull(list.item(1));
}
Also used : SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) Test(org.junit.Test)

Example 4 with SVGElement

use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.

the class SVGAxes method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        return null;
    }
    currentDoc = doc;
    currentPath = new SVGPathSegList();
    currentTicks = new SVGGElement(doc);
    final SVGElement root = new SVGGElement(doc);
    final String pref = LNamespace.LATEXDRAW_NAMESPACE + ':';
    final SVGPathElement path = new SVGPathElement(doc);
    setSVGAttributes(doc, root, false);
    root.setAttribute(SVGAttributes.SVG_TRANSFORM, "translate(" + MathUtils.INST.format.format(shape.getPosition().getX()) + ',' + MathUtils.INST.format.format(shape.getPosition().getY()) + ')');
    root.setAttribute(pref + LNamespace.XML_STYLE, shape.getAxesStyle().toString());
    root.setAttribute(pref + LNamespace.XML_GRID_START, shape.getGridStartX() + " " + shape.getGridStartY());
    root.setAttribute(pref + LNamespace.XML_GRID_END, shape.getGridEndX() + " " + shape.getGridEndY());
    root.setAttribute(pref + LNamespace.XML_GRID_ORIGIN, shape.getOriginX() + " " + shape.getOriginY());
    root.setAttribute(pref + LNamespace.XML_AXE_INCREMENT, shape.getIncrementX() + " " + shape.getIncrementY());
    root.setAttribute(pref + LNamespace.XML_AXE_DIST_LABELS, shape.getDistLabelsX() + " " + shape.getDistLabelsY());
    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);
    updatePathTicks();
    updatePathLabels();
    root.appendChild(currentTicks);
    path.setPathData(currentPath);
    root.appendChild(path);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGPathElement(net.sf.latexdraw.parsers.svg.SVGPathElement) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList)

Example 5 with SVGElement

use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.

the class SVGAxes method createFrame.

private void createFrame(final SVGElement elt, final SVGDocument document) {
    final double gridEndx = shape.getGridEndX();
    final double gridEndy = shape.getGridEndY();
    if (gridEndx > 0 || gridEndy > 0) {
        final double positionx = shape.getPosition().getX();
        final double positiony = shape.getPosition().getY();
        final double xMax = positionx + gridEndx * IShape.PPC;
        final double yMax = positiony - gridEndy * IShape.PPC;
        final IPoint pos = ShapeFactory.INST.createPoint(positionx, gridEndy > 0 ? yMax : positiony);
        final IRectangle r = ShapeFactory.INST.createRectangle(pos, Math.abs(pos.getX() - (gridEndx > 0 ? xMax : positionx)), Math.abs(pos.getY() - positiony));
        r.setBordersPosition(BorderPos.MID);
        r.setLineColour(shape.getLineColour());
        r.setLineStyle(shape.getLineStyle());
        r.setThickness(shape.getThickness());
        final SVGElement frame = new SVGRectangle(r).toSVG(document);
        frame.setAttribute(SVGAttributes.SVG_TRANSFORM, "translate(" + MathUtils.INST.format.format(-shape.getPosition().getX()) + ',' + MathUtils.INST.format.format(-shape.getPosition().getY()) + ')');
        elt.appendChild(frame);
    }
}
Also used : SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IRectangle(net.sf.latexdraw.models.interfaces.shape.IRectangle)

Aggregations

SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)39 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)24 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)15 SVGPolygonElement (net.sf.latexdraw.parsers.svg.SVGPolygonElement)5 Test (org.junit.Test)5 SVGDefsElement (net.sf.latexdraw.parsers.svg.SVGDefsElement)4 SVGPathElement (net.sf.latexdraw.parsers.svg.SVGPathElement)4 SVGCircleElement (net.sf.latexdraw.parsers.svg.SVGCircleElement)3 SVGRectElement (net.sf.latexdraw.parsers.svg.SVGRectElement)3 Point2D (java.awt.geom.Point2D)2 ParseException (java.text.ParseException)2 List (java.util.List)2 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)2 Color (net.sf.latexdraw.models.interfaces.shape.Color)2 IArrow (net.sf.latexdraw.models.interfaces.shape.IArrow)2 IPolyline (net.sf.latexdraw.models.interfaces.shape.IPolyline)2 SVGAttr (net.sf.latexdraw.parsers.svg.SVGAttr)2 SVGAttributes (net.sf.latexdraw.parsers.svg.SVGAttributes)2 SVGDocument (net.sf.latexdraw.parsers.svg.SVGDocument)2 SVGLineElement (net.sf.latexdraw.parsers.svg.SVGLineElement)2