use of net.sf.latexdraw.parsers.svg.SVGCircleElement in project latexdraw by arnobl.
the class SVGCircle method toSVG.
@Override
public SVGElement toSVG(final SVGDocument doc) {
if (doc == null || doc.getFirstChild().getDefs() == null) {
return null;
}
final IPoint tl = shape.getTopLeftPoint();
final IPoint br = shape.getBottomRightPoint();
final double tlx = tl.getX();
final double tly = tl.getY();
final double brx = br.getX();
final double bry = br.getY();
SVGElement elt;
final SVGElement shad;
final SVGElement dblBord;
final SVGElement root = new SVGGElement(doc);
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_CIRCLE);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
final double gap = getPositionGap();
if (shape.hasShadow()) {
shad = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, Math.abs((brx - tlx + gap) / 2d), doc);
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.
elt = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, Math.abs((brx - tlx + gap) / 2d), doc);
setSVGBorderBackground(elt, root);
}
elt = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, Math.abs((brx - tlx + gap) / 2d), doc);
root.appendChild(elt);
if (shape.hasDbleBord()) {
dblBord = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, Math.abs((brx - tlx + gap) / 2d), doc);
setSVGDoubleBordersAttributes(dblBord);
root.appendChild(dblBord);
}
setSVGAttributes(doc, elt, true);
setSVGRotationAttribute(root);
return root;
}
use of net.sf.latexdraw.parsers.svg.SVGCircleElement 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 * IShape.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.parsers.svg.SVGCircleElement in project latexdraw by arnobl.
the class SVGArrow method createCircle.
@Override
public void createCircle(final double cx, final double cy, final double r) {
if (currentDoc != null && currentMarker != null) {
currentCircle = new SVGCircleElement(currentDoc);
currentCircle.setAttribute(SVGAttributes.SVG_R, MathUtils.INST.format.format(r));
currentCircle.setAttribute(SVGAttributes.SVG_CX, MathUtils.INST.format.format(cx));
currentCircle.setAttribute(SVGAttributes.SVG_CY, MathUtils.INST.format.format(cy));
currentCircle.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ARROW_DOT_SIZE_NUM, MathUtils.INST.format.format(arrow.getDotSizeNum()));
currentMarker.appendChild(currentCircle);
}
}
use of net.sf.latexdraw.parsers.svg.SVGCircleElement in project latexdraw by arnobl.
the class SVGShape method getShowPointsDot.
/**
* Creates an SVG circle that represents a dot for the option 'show points'.
* @param doc The document owner.
* @param rad The radius of the circle.
* @param pt The position of the point.
* @param col The colour of the dot.
* @return The created dot or null.
*/
protected static SVGCircleElement getShowPointsDot(final SVGDocument doc, final double rad, final IPoint pt, final Color col) {
if (doc == null) {
return null;
}
final SVGCircleElement circle = new SVGCircleElement(doc);
circle.setR(rad);
if (pt != null) {
circle.setCx(pt.getX());
circle.setCy(pt.getY());
}
circle.setFill(col);
return circle;
}
use of net.sf.latexdraw.parsers.svg.SVGCircleElement in project latexdraw by arnobl.
the class SVGGrid method createSVGGridDots.
/**
* Creates the SVG element corresponding to the main dotted part of the grid.
*/
private void createSVGGridDots(final SVGDocument document, final SVGElement elt, final String prefix, final double absStep, final double minX, final double maxX, final double minY, final double maxY, final double tlx, final double tly, final double brx, final double bry, final double unit, final double posX, final double posY, final double xStep, final double yStep, final double gridWidth, final Color linesColour) {
double k;
double i;
double m;
double n;
double l;
double j;
final int gridDots = shape.getGridDots();
final double dotStep = unit * IShape.PPC / gridDots;
final SVGElement gridDotsElt = new SVGGElement(document);
SVGElement dot;
gridDotsElt.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(linesColour, true));
gridDotsElt.setAttribute(prefix + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GRID);
gridDotsElt.setAttribute(prefix + LNamespace.XML_GRID_DOTS, String.valueOf(gridDots));
gridDotsElt.setAttribute(prefix + LNamespace.XML_GRID_WIDTH, String.valueOf(gridWidth));
if (linesColour.getO() < 1d) {
gridDotsElt.setAttribute(SVGAttributes.SVG_FILL_OPACITY, MathUtils.INST.format.format(linesColour.getO()));
}
for (k = minX, i = posX; k <= maxX; i += xStep, k++) for (m = tly, n = minY; n < maxY; n++, m += absStep) for (l = 0, j = m; l < gridDots; l++, j += dotStep) {
dot = new SVGCircleElement(document);
dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(i));
dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(j));
dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(gridWidth / 2.));
gridDotsElt.appendChild(dot);
}
for (k = minY, i = posY; k <= maxY; i -= yStep, k++) for (m = tlx, n = minX; n < maxX; n++, m += absStep) for (l = 0, j = m; l < gridDots; l++, j += dotStep) {
dot = new SVGCircleElement(document);
dot.setAttribute(SVGAttributes.SVG_CX, String.valueOf(j));
dot.setAttribute(SVGAttributes.SVG_CY, String.valueOf(i));
dot.setAttribute(SVGAttributes.SVG_R, String.valueOf(gridWidth / 2.));
gridDotsElt.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(gridWidth / 2.));
gridDotsElt.appendChild(dot);
elt.appendChild(gridDotsElt);
}
Aggregations