use of net.sf.latexdraw.parser.svg.SVGGElement in project latexdraw by arnobl.
the class SVGRhombus method toSVG.
@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
final Point tl = shape.getTopLeftPoint();
final Point br = shape.getBottomRightPoint();
final Point gc = shape.getGravityCentre();
final Point p1 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, tl.getY());
final Point p2 = ShapeFactory.INST.createPoint(br.getX(), (tl.getY() + br.getY()) / 2d);
final Point 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.parser.svg.SVGGElement in project latexdraw by arnobl.
the class SVGText method toSVG.
@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
final SVGElement root = new SVGGElement(doc);
final String ltdPref = LNamespace.LATEXDRAW_NAMESPACE + ':';
final Element txt = new SVGTextElement(doc);
root.setAttribute(ltdPref + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TEXT);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
root.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(shape.getLineColour(), true));
root.setAttribute(ltdPref + LNamespace.XML_POSITION, shape.getTextPosition().getLatexToken());
txt.setAttribute(SVGAttributes.SVG_X, String.valueOf(shape.getX()));
txt.setAttribute(SVGAttributes.SVG_Y, String.valueOf(shape.getY()));
txt.appendChild(doc.createTextNode(shape.getText()));
root.appendChild(txt);
setSVGRotationAttribute(root);
return root;
}
use of net.sf.latexdraw.parser.svg.SVGGElement in project latexdraw by arnobl.
the class SVGSquare method toSVG.
@Override
SVGElement toSVG(@NotNull final SVGDocument document) {
if (document.getFirstChild().getDefs() == null) {
return null;
}
final double gap = getPositionGap();
final Point tl = shape.getTopLeftPoint();
final Point 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() && !PSTricksConstants.LINE_NONE_STYLE.equals(shape.getLineStyle().getLatexToken())) {
// 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.parser.svg.SVGGElement in project latexdraw by arnobl.
the class SVGTriangle method toSVG.
@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
if (doc.getFirstChild().getDefs() == null) {
return null;
}
final SVGElement root = new SVGGElement(doc);
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TRIANGLE);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
final double gap = getPositionGap() / 2d;
final Point pt1 = shape.getTopLeftPoint();
final Point pt2 = shape.getBottomRightPoint();
final Point p1 = ShapeFactory.INST.createPoint((pt1.getX() + pt2.getX()) / 2d, pt1.getY());
final Point p2 = ShapeFactory.INST.createPoint(pt2.getX(), pt2.getY());
final Point p3 = ShapeFactory.INST.createPoint(pt1.getX(), pt2.getY());
final double p1x = p1.getX();
final double p1y = p1.getY();
final double p2x = p2.getX();
final double p2y = p2.getY();
final double p3x = p3.getX();
double cornerGap1 = MathUtils.INST.getCornerGap(ShapeFactory.INST.createPoint(p1x, p2y), p1, p2, gap);
double cornerGap2 = MathUtils.INST.getCornerGap(shape.getGravityCentre(), p2, p3, gap);
if (p2x > p3x) {
cornerGap2 *= -1d;
}
if (p1y > p2y) {
cornerGap1 *= -1d;
}
final double value = p2y + (p1y < p2y ? gap : -gap);
final String points = p1x + "," + (p1y - cornerGap1) + " " + (p2x - cornerGap2) + "," + value + " " + (p3x + cornerGap2) + "," + value;
final String ltdPoints = shape.getPoints().stream().flatMap(pt -> Stream.of(String.valueOf(pt.getX()), String.valueOf(pt.getY()))).collect(Collectors.joining(" "));
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, ltdPoints);
setDbleBorderPolygon(doc, root, points);
setSVGAttributes(doc, elt, true);
setSVGRotationAttribute(root);
return root;
}
use of net.sf.latexdraw.parser.svg.SVGGElement in project latexdraw by arnobl.
the class SVGCircleArc method getShowPointsElement.
/**
* Creates an SVG g element that contains the 'show points' plotting.
* @param doc The owner document.
* @return The created g element or null if the shape has not the 'show points' option activated.
*/
final SVGGElement getShowPointsElement(final SVGDocument doc) {
if (!shape.isShowPts() || doc == null) {
return null;
}
final SVGGElement showPts = new SVGGElement(doc);
final double thickness = shape.getThickness() / 2.;
showPts.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_SHOW_PTS);
showPts.appendChild(getShowPointsLine(doc, thickness, shape.getLineColour(), shape.getGravityCentre(), shape.getStartPoint(), shape.getDashSepBlack(), shape.getDashSepWhite(), false, 1, 0));
showPts.appendChild(getShowPointsLine(doc, thickness, shape.getLineColour(), shape.getGravityCentre(), shape.getEndPoint(), shape.getDashSepBlack(), shape.getDashSepWhite(), false, 1, 0));
return showPts;
}
Aggregations