diff --git a/core/src/main/java/org/pushingpixels/flamingo/api/svg/SvgTranscoder.java b/core/src/main/java/org/pushingpixels/flamingo/api/svg/SvgTranscoder.java index 01aac33..4e1265b 100644 --- a/core/src/main/java/org/pushingpixels/flamingo/api/svg/SvgTranscoder.java +++ b/core/src/main/java/org/pushingpixels/flamingo/api/svg/SvgTranscoder.java @@ -362,7 +362,7 @@ private void transcodeCompositeChange(AlphaComposite composite) { * @throws UnsupportedOperationException if the graphics node is unsupported. */ private void transcodeGraphicsNode(GraphicsNode node, String comment) throws UnsupportedOperationException { - transcodeCompositeChange((AlphaComposite) node.getComposite()); + transcodeCompositeChange(getAbsoluteAlphaComposite(node)); AffineTransform transform = node.getTransform(); if (transform != null && !transform.isIdentity()) { @@ -393,6 +393,26 @@ private void transcodeGraphicsNode(GraphicsNode node, String comment) throws Uns } } + /** + * Get the absolute alpha composite of a node. + */ + private AlphaComposite getAbsoluteAlphaComposite(GraphicsNode node) { + AlphaComposite composite = (AlphaComposite) node.getComposite(); + + if (composite != null) { + float alpha = composite.getAlpha(); + while ((node = node.getParent()) != null) { + AlphaComposite parentComposite = (AlphaComposite) node.getComposite(); + if (parentComposite != null) { + alpha = alpha * parentComposite.getAlpha(); + } + } + composite = AlphaComposite.getInstance(composite.getRule(), alpha); + } + + return composite; + } + /** * Transcode the specified text node. *