use of net.sf.latexdraw.parsers.svg.SVGRectElement 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;
}
use of net.sf.latexdraw.parsers.svg.SVGRectElement in project latexdraw by arnobl.
the class SVGRectangular method setDbleBordSVGRect.
protected void setDbleBordSVGRect(final SVGElement root, final double x, final double y, final double width, final double height, final SVGDocument doc) {
if (shape.hasDbleBord()) {
final SVGRectElement elt = new SVGRectElement(x, y, width, height, doc);
setSVGDoubleBordersAttributes(elt);
setSVGRoundCorner(elt);
root.appendChild(elt);
}
}
use of net.sf.latexdraw.parsers.svg.SVGRectElement in project latexdraw by arnobl.
the class SVGShape method setSVGHatchings.
private void setSVGHatchings(final SVGDocument doc, final SVGElement root, final boolean shadowFills) {
final SVGDefsElement defs = doc.getFirstChild().getDefs();
final String id = SVGElements.SVG_PATTERN + shape.hashCode();
final SVGPatternElement hatch = new SVGPatternElement(doc);
final SVGGElement gPath = new SVGGElement(doc);
final IPoint max = shape.getFullBottomRightPoint();
final SVGPathElement path = new SVGPathElement(doc);
root.setAttribute(SVGAttributes.SVG_FILL, SVG_URL_TOKEN_BEGIN + id + ')');
hatch.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, shape.getFillingStyle().getLatexToken());
hatch.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getHatchingsAngle()));
hatch.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_SIZE, String.valueOf(shape.getHatchingsSep()));
hatch.setAttribute(SVGAttributes.SVG_PATTERN_UNITS, SVGAttributes.SVG_UNITS_VALUE_USR);
hatch.setAttribute(SVGAttributes.SVG_ID, id);
hatch.setAttribute(SVGAttributes.SVG_X, "0");
hatch.setAttribute(SVGAttributes.SVG_Y, "0");
hatch.setAttribute(SVGAttributes.SVG_WIDTH, String.valueOf((int) max.getX()));
hatch.setAttribute(SVGAttributes.SVG_HEIGHT, String.valueOf((int) max.getY()));
gPath.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(shape.getHatchingsCol(), true));
gPath.setAttribute(SVGAttributes.SVG_STROKE_WIDTH, String.valueOf(shape.getHatchingsWidth()));
gPath.setAttribute(SVGAttributes.SVG_STROKE_DASHARRAY, SVGAttributes.SVG_VALUE_NONE);
if (shape.getHatchingsCol().getO() < 1d) {
gPath.setAttribute(SVGAttributes.SVG_STROKE_OPACITY, MathUtils.INST.format.format(shape.getHatchingsCol().getO()));
}
path.setAttribute(SVGAttributes.SVG_D, getSVGHatchingsPath().toString());
gPath.appendChild(path);
// Several shapes having hatching must have their shadow filled.
if (shape.isFilled() || (shape.hasShadow() && shadowFills)) {
final SVGRectElement fill = new SVGRectElement(doc);
fill.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(shape.getFillingCol(), true));
if (shape.getFillingCol().getO() < 1d) {
fill.setAttribute(SVGAttributes.SVG_FILL_OPACITY, MathUtils.INST.format.format(shape.getFillingCol().getO()));
}
fill.setAttribute(SVGAttributes.SVG_STROKE, SVGAttributes.SVG_VALUE_NONE);
fill.setAttribute(SVGAttributes.SVG_WIDTH, String.valueOf((int) max.getX()));
fill.setAttribute(SVGAttributes.SVG_HEIGHT, String.valueOf((int) max.getY()));
hatch.appendChild(fill);
}
defs.appendChild(hatch);
hatch.appendChild(gPath);
}
use of net.sf.latexdraw.parsers.svg.SVGRectElement in project latexdraw by arnobl.
the class SVGRectangular method setShadowSVGRect.
protected void setShadowSVGRect(final SVGElement root, final double x, final double y, final double width, final double height, final SVGDocument doc) {
if (shape.hasShadow()) {
final SVGRectElement elt = new SVGRectElement(x, y, width, height, doc);
setSVGShadowAttributes(elt, true);
root.appendChild(elt);
setSVGRoundCorner(elt);
}
}
use of net.sf.latexdraw.parsers.svg.SVGRectElement 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);
}
}
Aggregations