Skip to content

Commit

Permalink
Fixed the opacity of the nested elements (thanks to Paolo Ferracin)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebourg committed Jul 6, 2016
1 parent 3e71580 commit efe6098
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit efe6098

Please sign in to comment.