use of net.sf.latexdraw.parser.svg.SVGElement in project latexdraw by arnobl.
the class SVGPolygonBased method setShadowPolygon.
final 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() && !PSTricksConstants.LINE_NONE_STYLE.equals(shape.getLineStyle().getLatexToken())) {
// 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.parser.svg.SVGElement in project latexdraw by arnobl.
the class SVGRectangle method toSVG.
@Override
SVGElement toSVG(@NotNull final SVGDocument document) {
if (document.getFirstChild().getDefs() == null) {
throw new IllegalArgumentException();
}
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 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() && !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, 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;
}
use of net.sf.latexdraw.parser.svg.SVGElement in project latexdraw by arnobl.
the class SVGGrid method createSVGSubGridDots.
/**
* Creates the SVG element corresponding to the sub dotted part of the grid.
*/
private void createSVGSubGridDots(final SVGDocument document, final SVGElement elt, final String prefix, final double subGridDiv, final double unit, final double xSubStep, final double ySubStep, final double minX, final double maxX, final double minY, final double maxY, final int subGridDots, final double subGridWidth, final double tlx, final double tly, final double brx, final double bry, final Color subGridColour) {
final double dotStep = unit * Shape.PPC / (subGridDots * subGridDiv);
final double nbX = (maxX - minX) * subGridDiv;
final double nbY = (maxY - minY) * subGridDiv;
final SVGElement subgridDots = new SVGGElement(document);
SVGElement dot;
subgridDots.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(subGridColour, true));
subgridDots.setAttribute(prefix + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GRID_SUB);
subgridDots.setAttribute(prefix + LNamespace.XML_GRID_DOTS, String.valueOf(subGridDots));
subgridDots.setAttribute(prefix + LNamespace.XML_GRID_SUB_DIV, String.valueOf(subGridDiv));
subgridDots.setAttribute(prefix + LNamespace.XML_GRID_WIDTH, String.valueOf(subGridWidth));
if (subGridColour.getO() < 1d) {
subgridDots.setAttribute(SVGAttributes.SVG_FILL_OPACITY, MathUtils.INST.format.format(subGridColour.getO()));
}
for (double i = 0, n = tlx; i < nbX; i++, n += xSubStep) {
for (double j = 0, m = tly; j <= nbY; j++, m += ySubStep) {
for (double k = 0; k < subGridDots; k++) {
dot = new SVGCircleElement(document);
dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(n + k * dotStep));
dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(m));
dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(subGridWidth / 2.));
subgridDots.appendChild(dot);
}
}
}
for (double j = 0, n = tly; j < nbY; j++, n += ySubStep) {
for (double i = 0, m = tlx; i <= nbX; i++, m += xSubStep) {
for (double k = 0; k < subGridDots; k++) {
dot = new SVGCircleElement(document);
dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(m));
dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(n + k * dotStep));
dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(subGridWidth / 2.));
subgridDots.appendChild(dot);
}
}
}
dot = new SVGCircleElement(document);
dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(brx));
dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(bry));
dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(subGridWidth / 2.));
elt.appendChild(subgridDots);
}
use of net.sf.latexdraw.parser.svg.SVGElement in project latexdraw by arnobl.
the class SVGGrid method produceSVGGridYWestLabelsTexts.
private final void produceSVGGridYWestLabelsTexts(final SVGDocument document, final SVGElement texts, final double xorigin, final double tly, final double gridWidth, final Text fooText, final double minY, final double maxY, final double labelHeight, final double absStep) {
final double width = gridWidth / 2d;
final int gridLabelsSize = shape.getLabelsSize();
for (double i = tly + (shape.isXLabelSouth() ? -width - gridLabelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
final String label = String.valueOf((int) j);
final SVGElement text = new SVGTextElement(document);
fooText.setText(label);
text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int) (xorigin - fooText.getLayoutBounds().getWidth() - gridLabelsSize / 4d - width)));
text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int) i));
text.setTextContent(label);
texts.appendChild(text);
}
}
use of net.sf.latexdraw.parser.svg.SVGElement in project latexdraw by arnobl.
the class SVGGrid method produceSVGGridXLabelsTexts.
private final void produceSVGGridXLabelsTexts(final SVGDocument document, final SVGElement texts, final double yorigin, final double minX, final double maxX, final double tlx, final double labelWidth, final double gridWidth, final double absStep) {
final int gridLabelsSize = shape.getLabelsSize();
final double width = gridWidth / 2d;
final double tmp = shape.isXLabelSouth() ? width : -width;
for (double i = tlx + (shape.isYLabelWest() ? width + gridLabelsSize / 4d : -width - labelWidth - gridLabelsSize / 4d), j = minX; j <= maxX; i += absStep, j++) {
final SVGElement text = new SVGTextElement(document);
text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int) i));
text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int) (yorigin + tmp)));
text.setTextContent(String.valueOf((int) j));
texts.appendChild(text);
}
}
Aggregations