use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGRectangular method initRectangle.
/**
* Initialises the rectangle using an SVGGElement provided by a latexdraw SVG document.
* @param elt The source element.
* @throws IllegalArgumentException If the given element is null or not valid.
*/
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);
setSVGRectParameters((SVGRectElement) elt2);
setSVGShadowParameters(getLaTeXDrawElement(elt, LNamespace.XML_TYPE_SHADOW));
setSVGDbleBordersParameters(getLaTeXDrawElement(elt, LNamespace.XML_TYPE_DBLE_BORDERS));
if (withTransformation) {
applyTransformations(elt);
}
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGRhombus method toSVG.
@Override
public SVGElement toSVG(final SVGDocument doc) {
if (doc == null) {
return null;
}
final IPoint tl = shape.getTopLeftPoint();
final IPoint br = shape.getBottomRightPoint();
final IPoint gc = shape.getGravityCentre();
final IPoint p1 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, tl.getY());
final IPoint p2 = ShapeFactory.INST.createPoint(br.getX(), (tl.getY() + br.getY()) / 2d);
final IPoint p3 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, br.getY());
final SVGElement root = new SVGGElement(doc);
final double gap = getPositionGap() / 2d;
final double cornerGap1 = MathUtils.INST.getCornerGap(gc, p1, p2, gap);
double cornerGap2 = MathUtils.INST.getCornerGap(gc, p2, p3, gap);
if (p2.getX() < p3.getX()) {
cornerGap2 *= -1d;
}
final String points = String.valueOf(p1.getX()) + ',' + (p1.getY() - cornerGap1) + ' ' + (p2.getX() + cornerGap2) + ',' + p2.getY() + ' ' + p3.getX() + ',' + (p3.getY() + cornerGap1) + ' ' + (tl.getX() - cornerGap2) + ',' + p2.getY();
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_RHOMBUS);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
setShadowPolygon(doc, root, points);
final SVGElement elt = new SVGPolygonElement(doc);
elt.setAttribute(SVGAttributes.SVG_POINTS, points);
root.appendChild(elt);
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_POINTS, String.valueOf(tl.getX()) + ' ' + tl.getY() + ' ' + br.getX() + ' ' + tl.getY() + ' ' + tl.getX() + ' ' + br.getY() + ' ' + br.getX() + ' ' + br.getY());
setDbleBorderPolygon(doc, root, points);
setSVGAttributes(doc, elt, true);
setSVGRotationAttribute(root);
return root;
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGShape method setSVGArrow.
protected static void setSVGArrow(final IArrowableSingleShape shape, final SVGElement parent, final int arrowPos, final boolean isShadow, final SVGDocument doc, final SVGDefsElement defs) {
final IArrow arrow = shape.getArrowAt(arrowPos);
if (arrow.getArrowStyle() != ArrowStyle.NONE) {
// NON-NLS
final String arrowName = "arrow" + arrowPos + (isShadow ? "Shad-" : "-") + shape.hashCode();
final SVGElement arrowSVG = new SVGArrow(arrow).toSVG(doc, isShadow);
arrowSVG.setAttribute(SVGAttributes.SVG_ID, arrowName);
defs.appendChild(arrowSVG);
parent.setAttribute(arrowPos == 0 ? SVGAttributes.SVG_MARKER_START : SVGAttributes.SVG_MARKER_END, SVG_URL_TOKEN_BEGIN + arrowName + ')');
}
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGSquare 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 x = tl.getX() - gap / 2d;
final double y = tl.getY() - gap / 2d;
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_SQUARE);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
setShadowSVGRect(root, x, y, width, width, 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, width, document);
setSVGBorderBackground(elt, root);
setSVGRoundCorner(elt);
}
elt = new SVGRectElement(x, y, width, width, document);
root.appendChild(elt);
setSVGAttributes(document, elt, true);
setSVGRoundCorner(elt);
setDbleBordSVGRect(root, x, y, width, width, document);
setSVGRotationAttribute(root);
return root;
}
use of net.sf.latexdraw.parsers.svg.SVGElement in project latexdraw by arnobl.
the class SVGDot method toSVG.
@Override
public SVGElement toSVG(final SVGDocument doc) {
if (doc == null) {
return null;
}
final SVGElement root = new SVGGElement(doc);
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());
ViewFactory.INSTANCE.createView(shape).ifPresent(vdot -> JFXToSVG.INSTANCE.shapesToElements(vdot.getChildren(), doc).forEach(elt -> root.appendChild(elt)));
setSVGRotationAttribute(root);
return root;
}
Aggregations