Search in sources :

Example 6 with Element

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;
}
Also used : Shape(java.awt.Shape) NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) Node(org.loboevolution.html.node.Node) Element(org.loboevolution.html.node.Element)

Example 7 with Element

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;
}
Also used : NamedNodeMap(org.loboevolution.html.node.NamedNodeMap) Element(org.loboevolution.html.node.Element) Node(org.loboevolution.html.node.Node) Document(org.loboevolution.html.node.Document)

Example 8 with Element

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;
}
Also used : NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) Element(org.loboevolution.html.node.Element)

Example 9 with Element

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);
    }
}
Also used : Node(org.loboevolution.html.node.Node) Element(org.loboevolution.html.node.Element) Document(org.loboevolution.html.node.Document)

Example 10 with Element

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;
}
Also used : Element(org.loboevolution.html.node.Element)

Aggregations

Element (org.loboevolution.html.node.Element)10 Node (org.loboevolution.html.node.Node)5 Document (org.loboevolution.html.node.Document)4 HTMLDocumentImpl (org.loboevolution.html.dom.domimpl.HTMLDocumentImpl)2 NodeListImpl (org.loboevolution.html.dom.nodeimpl.NodeListImpl)2 DOMException (com.gargoylesoftware.css.dom.DOMException)1 Shape (java.awt.Shape)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Test (org.junit.Test)1 LoboUnitTest (org.loboevolution.driver.LoboUnitTest)1 HTMLTag (org.loboevolution.html.HTMLTag)1 DocumentTypeImpl (org.loboevolution.html.dom.domimpl.DocumentTypeImpl)1 NodeImpl (org.loboevolution.html.dom.nodeimpl.NodeImpl)1 XMLDocument (org.loboevolution.html.js.xml.XMLDocument)1 DocumentType (org.loboevolution.html.node.DocumentType)1 NamedNodeMap (org.loboevolution.html.node.NamedNodeMap)1 UserAgentContext (org.loboevolution.http.UserAgentContext)1 ElementInfo (org.loboevolution.info.ElementInfo)1