use of org.loboevolution.html.dom.svg.SVGElement in project LoboEvolution by LoboEvolution.
the class SVGLocatableImpl method getScreenCTM.
/**
* {@inheritDoc}
*/
@Override
public SVGMatrix getScreenCTM() {
AffineTransform screenCTM = getCTM().getAffineTransform();
SVGSVGElementImpl root = (SVGSVGElementImpl) getOwnerSVGElement();
SVGSVGElementImpl parentSVGElement = (SVGSVGElementImpl) getOwnerSVGElement();
if (parentSVGElement != null) {
AffineTransform viewboxToViewportTransform = parentSVGElement.getViewboxToViewportTransform();
if (viewboxToViewportTransform != null) {
screenCTM.preConcatenate(viewboxToViewportTransform);
}
screenCTM.preConcatenate(AffineTransform.getTranslateInstance(parentSVGElement.getX().getAnimVal().getValue(), parentSVGElement.getY().getAnimVal().getValue()));
}
while (parentSVGElement != root) {
if (parentSVGElement.getParentNode() instanceof SVGLocatable && !(parentSVGElement.getParentNode() instanceof SVGSVGElementImpl)) {
SVGMatrix ctmMatrix = ((SVGLocatable) parentSVGElement.getParentNode()).getCTM();
AffineTransform ctm = ctmMatrix.getAffineTransform();
screenCTM.preConcatenate(ctm);
parentSVGElement = (SVGSVGElementImpl) ((SVGElement) parentSVGElement.getParentNode()).getOwnerSVGElement();
} else if (parentSVGElement.getParentNode() instanceof SVGSVGElementImpl) {
parentSVGElement = (SVGSVGElementImpl) parentSVGElement.getParentNode();
} else {
parentSVGElement = null;
}
if (parentSVGElement != null) {
AffineTransform viewboxToViewportTransform = parentSVGElement.getViewboxToViewportTransform();
if (viewboxToViewportTransform != null) {
screenCTM.preConcatenate(viewboxToViewportTransform);
}
screenCTM.preConcatenate(AffineTransform.getTranslateInstance(parentSVGElement.getX().getAnimVal().getValue(), parentSVGElement.getY().getAnimVal().getValue()));
}
}
SVGMatrix screenCTMMatrix = new SVGMatrixImpl();
screenCTMMatrix.setA((float) screenCTM.getScaleX());
screenCTMMatrix.setB((float) screenCTM.getShearY());
screenCTMMatrix.setC((float) screenCTM.getShearX());
screenCTMMatrix.setD((float) screenCTM.getScaleY());
screenCTMMatrix.setE((float) screenCTM.getTranslateX());
screenCTMMatrix.setF((float) screenCTM.getTranslateY());
return screenCTMMatrix;
}
use of org.loboevolution.html.dom.svg.SVGElement in project LoboEvolution by LoboEvolution.
the class SVGStylableImpl method drawStyle.
/**
* <p>drawStyle.</p>
*
* @param node a {@link org.loboevolution.html.node.Node} object.
*/
protected void drawStyle(Node node) {
AbstractCSSProperties style = getStyle();
SVGElement child = (SVGElement) node;
final String fill = Strings.isNotBlank(style.getFill()) ? style.getFill() : getAttribute("fill");
if (Strings.isNotBlank(fill)) {
child.setAttribute("fill", fill);
}
final String fillop = Strings.isNotBlank(style.getFillOpacity()) ? style.getFillOpacity() : getAttribute("fill-opacity");
if (Strings.isNotBlank(fillop)) {
child.setAttribute("fill-opacity", fillop);
}
final String stroke = Strings.isNotBlank(style.getStroke()) ? style.getStroke() : getAttribute("stroke");
if (Strings.isNotBlank(stroke)) {
child.setAttribute("stroke", stroke);
}
final String strokeop = Strings.isNotBlank(style.getStrokeOpacity()) ? style.getStrokeOpacity() : getAttribute("stroke-opacity");
if (Strings.isNotBlank(strokeop)) {
child.setAttribute("stroke-opacity", strokeop);
}
final String swidth = Strings.isNotBlank(style.getStrokeWidth()) ? style.getStrokeWidth() : getAttribute("stroke-width");
if (Strings.isNotBlank(swidth)) {
child.setAttribute("stroke-width", swidth);
}
final String slinecap = Strings.isNotBlank(style.getStrokeLineCap()) ? style.getStrokeLineCap() : getAttribute("stroke-linecap");
if (Strings.isNotBlank(slinecap)) {
child.setAttribute("stroke-linecap", slinecap);
}
final String slinejoin = Strings.isNotBlank(style.getStrokeLineJoin()) ? style.getStrokeLineJoin() : getAttribute("stroke-linejoin");
if (Strings.isNotBlank(slinejoin)) {
child.setAttribute("stroke-linejoin", slinejoin);
}
final String smiterlimit = Strings.isNotBlank(style.getStrokeMiterLimit()) ? style.getStrokeMiterLimit() : getAttribute("stroke-miterlimit");
if (Strings.isNotBlank(smiterlimit)) {
child.setAttribute("stroke-miterlimit", smiterlimit);
}
final String sdasharray = Strings.isNotBlank(style.getStrokeDashArray()) ? style.getStrokeDashArray() : getAttribute("stroke-dasharray");
if (Strings.isNotBlank(sdasharray)) {
child.setAttribute("stroke-dasharray", sdasharray);
}
final String opacity = Strings.isNotBlank(style.getOpacity()) ? style.getOpacity() : getAttribute("opacity");
if (Strings.isNotBlank(opacity)) {
child.setAttribute("opacity", opacity);
}
final String display = Strings.isNotBlank(style.getDisplay()) ? style.getDisplay() : getAttribute("display");
if (Strings.isNotBlank(display)) {
child.setAttribute("display", display);
}
final String visibility = Strings.isNotBlank(style.getVisibility()) ? style.getVisibility() : getAttribute("visibility");
if (Strings.isNotBlank(visibility)) {
child.setAttribute("visibility", visibility);
}
final String clipPath = Strings.isNotBlank(style.getClipPath()) ? style.getClipPath() : getAttribute("clip-path");
if (Strings.isNotBlank(clipPath)) {
child.setAttribute("clip-path", clipPath);
}
final String clipRule = Strings.isNotBlank(style.getClipRule()) ? style.getClipRule() : getAttribute("clip-rule");
if (Strings.isNotBlank(clipRule)) {
child.setAttribute("clip-rule", clipRule);
}
final String stopColor = Strings.isNotBlank(style.getStopColor()) ? style.getStopColor() : getAttribute("stop-color");
if (Strings.isNotBlank(stopColor)) {
child.setAttribute("stop-color", stopColor);
}
final String stopOpacity = Strings.isNotBlank(style.getStopOpacity()) ? style.getStopOpacity() : getAttribute("stop-opacity");
if (Strings.isNotBlank(stopOpacity)) {
child.setAttribute("stop-opacity", stopOpacity);
}
}
use of org.loboevolution.html.dom.svg.SVGElement in project LoboEvolution by LoboEvolution.
the class SVGStylableImpl method child.
/**
* <p>child.</p>
*
* @param elementId a {@link java.lang.String} object.
* @return a {@link org.loboevolution.html.node.Node} object.
*/
protected Node child(String elementId) {
SVGElement ownerSVGElement = getOwnerSVGElement();
NodeListImpl nodeList = (NodeListImpl) ownerSVGElement.getChildNodes();
for (Node child : nodeList) {
NodeListImpl nodeList1 = (NodeListImpl) child.getChildNodes();
for (Node child1 : nodeList1) {
if (child1 instanceof Element) {
final Element elem1 = (Element) child1;
NamedNodeMap attributes2 = elem1.getAttributes();
if (attributes2 != null) {
for (Attr attr : Nodes.iterable(attributes2)) {
if ("id".equals(attr.getNodeName()) && elementId.equals(attr.getNodeValue())) {
return child1;
}
}
}
}
}
if (child instanceof Element) {
final Element elem = (Element) child;
NamedNodeMap attributes2 = elem.getAttributes();
if (attributes2 != null) {
for (Attr attr : Nodes.iterable(attributes2)) {
if ("id".equals(attr.getNodeName()) && elementId.equals(attr.getNodeValue())) {
return child;
}
}
}
}
}
return null;
}
use of org.loboevolution.html.dom.svg.SVGElement in project LoboEvolution by LoboEvolution.
the class SVGStylableImpl method getStrokeWidth.
/**
* <p>getStrokeWidth.</p>
*
* @return a int.
*/
public int getStrokeWidth() {
AbstractCSSProperties style = getStyle();
int strokeWidth = 1;
final String strokeWidthProp = Strings.isNotBlank(style.getStrokeWidth()) ? style.getStrokeWidth() : getAttribute("stroke-width");
if (Strings.isNotBlank(strokeWidthProp)) {
SVGElement ownerSVGElement = getOwnerSVGElement();
HTMLDocumentImpl doc = (HTMLDocumentImpl) ownerSVGElement.getOwnerDocument();
strokeWidth = HtmlValues.getPixelSize(strokeWidthProp, null, doc.getDefaultView(), 1);
}
return strokeWidth;
}
use of org.loboevolution.html.dom.svg.SVGElement in project LoboEvolution by LoboEvolution.
the class SVGStylableImpl method getStrokeMiterlimit.
/**
* <p>getStrokeMiterlimit.</p>
*
* @return a int.
*/
public int getStrokeMiterlimit() {
AbstractCSSProperties style = getStyle();
int miterlimit = 4;
final String strokeMiterlimit = Strings.isNotBlank(style.getStrokeMiterLimit()) ? style.getStrokeMiterLimit() : getAttribute("stroke-miterlimit");
if (Strings.isNotBlank(strokeMiterlimit)) {
SVGElement ownerSVGElement = getOwnerSVGElement();
HTMLDocumentImpl doc = (HTMLDocumentImpl) ownerSVGElement.getOwnerDocument();
miterlimit = HtmlValues.getPixelSize(strokeMiterlimit, null, doc.getDefaultView(), 4);
}
return miterlimit;
}
Aggregations