use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGAxes method setAxesStyleFromSVG.
private void setAxesStyleFromSVG(final SVGGElement elt) {
/* Looking for the two axe in order to get the position of the axes. */
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) {
if (l1 == null) {
l1 = (SVGGElement) element;
} else {
l2 = (SVGGElement) element;
}
}
i++;
}
if (l1 != null && l2 != null) {
try {
final IPolyline la = new SVGPolylines(l1, false).shape;
final IPolyline lb = new SVGPolylines(l2, false).shape;
// now, a translation is used.
if (elt.getTransform().stream().noneMatch(tr -> tr.isTranslation())) {
shape.setPosition(ShapeFactory.INST.createPoint(lb.getPtAt(0).getX(), la.getPtAt(0).getY()));
}
// End of legacy
shape.setLineStyle(la.getLineStyle());
shape.getArrowAt(1).setArrowStyle(la.getArrowAt(0).getArrowStyle());
shape.getArrowAt(3).setArrowStyle(la.getArrowAt(1).getArrowStyle());
shape.getArrowAt(0).setArrowStyle(lb.getArrowAt(0).getArrowStyle());
shape.getArrowAt(2).setArrowStyle(lb.getArrowAt(1).getArrowStyle());
} catch (final IllegalArgumentException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
}
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGPolygon method toSVG.
@Override
public SVGElement toSVG(final SVGDocument doc) {
if (doc == null) {
throw new IllegalArgumentException();
}
final SVGElement root = new SVGGElement(doc);
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.
final SVGPolygonElement elt = new SVGPolygonElement(doc);
try {
elt.setPoints(points);
} catch (final ParseException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
setSVGBorderBackground(elt, root);
}
final SVGPolygonElement 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;
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGPolygonBased method setShadowPolygon.
void setShadowPolygon(final SVGDocument doc, final SVGElement root, final String points) {
if (shape.hasShadow()) {
final SVGElement elt = new SVGPolygonElement(doc);
elt.setAttribute(SVGAttributes.SVG_POINTS, points);
setSVGShadowAttributes(elt, true);
root.appendChild(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.
final SVGElement elt = new SVGPolygonElement(doc);
elt.setAttribute(SVGAttributes.SVG_POINTS, points);
setSVGBorderBackground(elt, root);
}
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGPolygonBased method setDbleBorderPolygon.
void setDbleBorderPolygon(final SVGDocument doc, final SVGElement root, final String points) {
if (shape.hasDbleBord()) {
final SVGElement dblBord = new SVGPolygonElement(doc);
dblBord.setAttribute(SVGAttributes.SVG_POINTS, points);
setSVGDoubleBordersAttributes(dblBord);
root.appendChild(dblBord);
}
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGRectangle method toSVG.
@Override
public SVGElement toSVG(final SVGDocument document) {
if (document == null || document.getFirstChild().getDefs() == null) {
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(1d, br.getX() - tl.getX() + gap);
final double height = Math.max(1d, br.getY() - tl.getY() + gap);
final double x = tl.getX() - gap / 2d;
final double y = tl.getY() - gap / 2d;
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_RECT);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
setShadowSVGRect(root, x, y, width, height, document);
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);
setDbleBordSVGRect(root, x, y, width, height, document);
setSVGRotationAttribute(root);
return root;
}
Aggregations