use of org.loboevolution.html.node.Element in project LoboEvolution by LoboEvolution.
the class SVGClipPathElementImpl method getClippingShape.
/**
* <p>getClippingShape.</p>
*
* @param clippedElement a {@link org.loboevolution.html.dom.svg.SVGElement} object.
* @return a {@link java.awt.Shape} object.
*/
protected Shape getClippingShape(SVGElement clippedElement) {
Area clipArea = null;
AffineTransform clipTransform = new AffineTransform();
if (hasChildNodes()) {
NodeListImpl children = (NodeListImpl) getChildNodes();
for (Node child : children) {
if (child instanceof SVGUseElementImpl) {
String href = ((SVGUseElementImpl) child).getHref().getAnimVal();
if (href.length() > 0) {
int index = href.indexOf('#');
if (index != -1) {
String id = href.substring(index + 1).trim();
Element ref = (Element) child(id);
if (ref != null) {
Shape childShape = ((Drawable) ref).createShape(clipTransform);
if (childShape != null) {
AffineTransform childAffineTransform = clipTransform;
if (ref instanceof SVGTransformable) {
SVGTransformListImpl childTransform = (SVGTransformListImpl) ((SVGTransformable) ref).getTransform().getAnimVal();
if (childTransform != null) {
childAffineTransform.concatenate(childTransform.getAffineTransform());
}
}
GeneralPath path = new GeneralPath(childShape);
path.transform(childAffineTransform);
String clipRule = ((SVGStylableImpl) child).getClipRule();
SVGClipPathElementImpl clipPath = ((SVGStylableImpl) child).getClippingPath();
if (clipRule.equals("evenodd")) {
path.setWindingRule(Path2D.WIND_EVEN_ODD);
} else {
path.setWindingRule(Path2D.WIND_NON_ZERO);
}
Area childClipArea = new Area(path);
if (clipPath != null) {
Shape clipShape = clipPath.getClippingShape(clippedElement);
if (clipShape != null) {
childClipArea.intersect(new Area(clipShape));
}
}
if (clipArea == null) {
clipArea = childClipArea;
} else {
clipArea.add(childClipArea);
}
}
}
}
}
} else if (child instanceof Drawable) {
Shape childShape = ((Drawable) child).createShape(clipTransform);
if (childShape != null) {
if (child instanceof SVGTransformable) {
SVGAnimatedTransformListImpl childTransform = (SVGAnimatedTransformListImpl) ((SVGTransformable) child).getTransform();
if (childTransform != null) {
clipTransform.concatenate(((SVGTransformListImpl) childTransform.getAnimVal()).getAffineTransform());
}
}
GeneralPath path = new GeneralPath(childShape);
path.transform(clipTransform);
String clipRule = ((SVGStylableImpl) child).getClipRule();
SVGClipPathElementImpl clipPath = ((SVGStylableImpl) child).getClippingPath();
if (clipRule.equals("evenodd")) {
path.setWindingRule(Path2D.WIND_EVEN_ODD);
} else {
path.setWindingRule(Path2D.WIND_NON_ZERO);
}
Area childClipArea = new Area(path);
// see if child has a clipPath property
if (clipPath != null) {
Shape clipShape = clipPath.getClippingShape(clippedElement);
if (clipShape != null) {
childClipArea.intersect(new Area(clipShape));
}
}
if (clipArea == null) {
clipArea = childClipArea;
} else {
clipArea.add(childClipArea);
}
}
}
}
}
SVGClipPathElementImpl clipPath = getClippingPath();
getClipRule();
if (clipPath != null) {
Shape clipShape = clipPath.getClippingShape(clippedElement);
if (clipShape != null) {
if (clipArea == null) {
clipArea = new Area(clipShape);
} else {
clipArea.intersect(new Area(clipShape));
}
}
}
if (clipArea != null) {
Shape clipShape = clipArea;
if (getClipPathUnits().getAnimVal() == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
SVGRectImpl bbox = null;
if (clippedElement instanceof SVGTransformable) {
bbox = (SVGRectImpl) ((SVGTransformable) clippedElement).getBBox();
} else if (clippedElement instanceof SVGSVGElementImpl) {
bbox = (SVGRectImpl) ((SVGSVGElementImpl) clippedElement).getBBox();
}
if (bbox != null) {
AffineTransform clipTrans = AffineTransform.getTranslateInstance(bbox.getX(), bbox.getY());
clipTrans.scale(bbox.getWidth(), bbox.getHeight());
clipShape = clipTrans.createTransformedShape(clipShape);
return clipShape;
}
}
}
return clipArea;
}
use of org.loboevolution.html.node.Element in project LoboEvolution by LoboEvolution.
the class XPathNSResolverImpl method lookupNamespaceURI.
/**
* {@inheritDoc}
*/
@Override
public String lookupNamespaceURI(String prefix) {
String namespace = null;
if (prefix.equals("xml")) {
namespace = Constants.S_XMLNAMESPACEURI;
} else {
int type;
while ((null != parent) && (null == namespace) && (((type = parent.getNodeType()) == NodeType.ELEMENT_NODE) || ((type = parent.getNodeType()) == NodeType.DOCUMENT_NODE) || (type == NodeType.ENTITY_REFERENCE_NODE))) {
if (type == NodeType.DOCUMENT_NODE) {
Document document = (Document) parent;
Element docelm = document.getDocumentElement();
if (docelm != null && docelm.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
return docelm.getNamespaceURI();
}
}
if (type == NodeType.ELEMENT_NODE) {
if (parent.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
return parent.getNamespaceURI();
}
NamedNodeMap nnm = ((Element) parent).getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
Node attr = nnm.item(i);
String aname = attr.getNodeName();
boolean isPrefix = aname.startsWith("xmlns:");
if (isPrefix || aname.equals("xmlns")) {
int index = aname.indexOf(':');
String p = isPrefix ? aname.substring(index + 1) : "";
if (p.equals(prefix)) {
namespace = attr.getNodeValue();
break;
}
}
}
}
parent = parent.getParentNode();
}
}
return namespace;
}
use of org.loboevolution.html.node.Element in project LoboEvolution by LoboEvolution.
the class SVGUseElementImpl method createShape.
/**
* {@inheritDoc}
*/
@Override
public Shape createShape(AffineTransform transform) {
String href = getHref().getBaseVal();
if (href.toLowerCase().indexOf("#") != -1) {
int hashIndex = href.indexOf('#');
if (hashIndex != -1) {
String idElement = href.substring(hashIndex + 1);
Element elementById = (Element) child(idElement);
if (elementById instanceof SVGSymbolElementImpl) {
SVGSymbolElementImpl symbol = (SVGSymbolElementImpl) elementById;
NodeListImpl children = (NodeListImpl) symbol.getChildNodes();
children.forEach(child -> {
if (child instanceof Drawable) {
Drawable drawable = (Drawable) child;
drawable.draw(graphics);
}
});
} else if (elementById instanceof Drawable) {
Drawable drawable = (Drawable) elementById;
drawable.draw(graphics);
}
}
}
return null;
}
use of org.loboevolution.html.node.Element in project LoboEvolution by LoboEvolution.
the class HTMLCollectionImpl method namedItem.
/**
* {@inheritDoc}
*/
@Override
public Element namedItem(String name) {
final Document doc = this.rootNode.getOwnerDocument();
if (doc == null) {
return null;
}
final HTMLCollectionImpl nodeList = (HTMLCollectionImpl) doc.getElementsByName(name);
if (nodeList.size() > 0) {
Optional<Node> node = nodeList.stream().findFirst();
return (Element) node.orElse(null);
} else {
return doc.getElementById(name);
}
}
use of org.loboevolution.html.node.Element in project LoboEvolution by LoboEvolution.
the class DOMImplementationImpl method createHTMLDocument.
/**
* {@inheritDoc}
*/
@Override
public Document createHTMLDocument() {
HTMLDocumentImpl doc = new HTMLDocumentImpl(this.context);
final Element body = doc.createElement("BODY");
doc.setBody((HTMLElementImpl) body);
return doc;
}
Aggregations