Search in sources :

Example 1 with SVGAnimatedTransformList

use of org.loboevolution.html.dom.svg.SVGAnimatedTransformList in project LoboEvolution by LoboEvolution.

the class SVGAElementImpl method createShape.

/**
 * {@inheritDoc}
 */
@Override
public Shape createShape(AffineTransform transform) {
    GeneralPath path = new GeneralPath();
    if (hasChildNodes()) {
        NodeListImpl children = (NodeListImpl) getChildNodes();
        children.forEach(child -> {
            Shape childShape = null;
            if (child instanceof SVGGElementImpl) {
                childShape = ((SVGGElementImpl) child).createShape(transform);
            } else if (child instanceof SVGAElementImpl) {
                childShape = ((SVGAElementImpl) child).createShape(transform);
            } else if (child instanceof SVGImageElementImpl) {
                SVGRect bbox = ((SVGImageElement) child).getBBox();
                childShape = new Rectangle2D.Float(bbox.getX(), bbox.getY(), bbox.getWidth(), bbox.getHeight());
            } else if (child instanceof SVGUseElementImpl) {
                SVGRect bbox = ((SVGUseElement) child).getBBox();
                childShape = new Rectangle2D.Float(bbox.getX(), bbox.getY(), bbox.getWidth(), bbox.getHeight());
            } else if (child instanceof SVGSVGElementImpl) {
                SVGSVGElement svg = (SVGSVGElement) child;
                AffineTransform ctm = getCTM().getAffineTransform();
                AffineTransform inverseTransform;
                try {
                    inverseTransform = ctm.createInverse();
                } catch (NoninvertibleTransformException e) {
                    inverseTransform = null;
                }
                float x = ((SVGLengthImpl) svg.getX()).getTransformedLength(inverseTransform);
                float y = ((SVGLengthImpl) svg.getY()).getTransformedLength(inverseTransform);
                float width = ((SVGLengthImpl) svg.getWidth()).getTransformedLength(inverseTransform);
                float height = ((SVGLengthImpl) svg.getHeight()).getTransformedLength(inverseTransform);
                childShape = new Rectangle2D.Float(x, y, width, height);
            }
            if (child instanceof SVGTransformable) {
                SVGAnimatedTransformList childTransformList = ((SVGTransformable) child).getTransform();
                AffineTransform childTransform = ((SVGTransformListImpl) childTransformList.getAnimVal()).getAffineTransform();
                childShape = childTransform.createTransformedShape(childShape);
            }
            if (childShape != null) {
                path.append(childShape, false);
            }
        });
    }
    return path;
}
Also used : Shape(java.awt.Shape) GeneralPath(java.awt.geom.GeneralPath) NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) Rectangle2D(java.awt.geom.Rectangle2D) SVGSVGElement(org.loboevolution.html.dom.svg.SVGSVGElement) NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) SVGTransformable(org.loboevolution.html.dom.svg.SVGTransformable) SVGAnimatedTransformList(org.loboevolution.html.dom.svg.SVGAnimatedTransformList) SVGImageElement(org.loboevolution.html.dom.svg.SVGImageElement) AffineTransform(java.awt.geom.AffineTransform) SVGRect(org.loboevolution.html.dom.svg.SVGRect)

Example 2 with SVGAnimatedTransformList

use of org.loboevolution.html.dom.svg.SVGAnimatedTransformList in project LoboEvolution by LoboEvolution.

the class SVGGraphic method drawable.

/**
 * <p>drawable.</p>
 *
 * @param graphics a {@link java.awt.Graphics2D} object.
 * @param shape a {@link java.awt.Shape} object.
 */
protected void drawable(Graphics2D graphics, Shape shape) {
    final Paint fillPaint = getFillPaint(shape);
    final Paint strokePaint = getStrokelPaint(shape);
    final BasicStroke stroke = getStroke();
    SVGClipPathElementImpl clipPath = getClippingPath();
    SVGAnimatedTransformList animateTransformList = getTransform();
    graphics.setStroke(stroke);
    if (clipPath != null) {
        Shape clipShape = clipPath.getClippingShape(this);
        if (clipShape != null) {
            graphics.setClip(clipShape);
        }
    }
    if (animateTransformList != null) {
        SVGTransformList transformList = animateTransformList.getBaseVal();
        if (transformList != null) {
            transform(graphics, transformList);
        }
    }
    if (fillPaint == null && strokePaint == null) {
        graphics.setPaint(Color.BLACK);
        graphics.fill(shape);
    }
    if (fillPaint != null) {
        graphics.setPaint(fillPaint);
        graphics.fill(shape);
    }
    if (strokePaint != null) {
        graphics.setPaint(strokePaint);
        graphics.draw(shape);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) SVGAnimatedTransformList(org.loboevolution.html.dom.svg.SVGAnimatedTransformList) Shape(java.awt.Shape) Paint(java.awt.Paint) SVGTransformList(org.loboevolution.html.dom.svg.SVGTransformList)

Aggregations

Shape (java.awt.Shape)2 SVGAnimatedTransformList (org.loboevolution.html.dom.svg.SVGAnimatedTransformList)2 BasicStroke (java.awt.BasicStroke)1 Paint (java.awt.Paint)1 AffineTransform (java.awt.geom.AffineTransform)1 GeneralPath (java.awt.geom.GeneralPath)1 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)1 Rectangle2D (java.awt.geom.Rectangle2D)1 NodeListImpl (org.loboevolution.html.dom.nodeimpl.NodeListImpl)1 SVGImageElement (org.loboevolution.html.dom.svg.SVGImageElement)1 SVGRect (org.loboevolution.html.dom.svg.SVGRect)1 SVGSVGElement (org.loboevolution.html.dom.svg.SVGSVGElement)1 SVGTransformList (org.loboevolution.html.dom.svg.SVGTransformList)1 SVGTransformable (org.loboevolution.html.dom.svg.SVGTransformable)1