Details
-
Bug
-
Status: Resolved
-
Resolution: Fixed
-
2.6
-
None
-
None
-
Operating System: Windows Vista
Platform: PC
Description
To reproduce:
1) Have an FO file in which an SVG (I have only tested with external-graphics)
2) Inside the SVG, have a gradient defined and two elements e.g. rectangles. Set the stroke opacity of the first element to a value near 0. NOTE: The order is important - the stroke opacity must be set on the element preceding the gradient filled element.
3) Make the second element have a gradient fill.
RESULT: The second element's gradient fill will have the same opacity as the stroke of the preceding element.
-
- Possible cause **
This is due to Batik's GraphicContext.setPaint() method replacing the "foreground" Color attribute if it receives a Color instance as a parameter (due to a "paint instanceof Color" check). The "foreground" of the GraphicsContext is later used to set the fill opacity in the line inside PDFGraphics2D.fill() method:
- Possible cause **
applyAlpha(c.getAlpha(), OPAQUE);
However in this case, batik's GraphicContext.setPaint() is receiving a LinearGradientPaint object which does not inherit from Color. Thus it does not set the "foreground" attribute, meaning that an alpha from a previous setPaint() will be used - in this case, the stroke opacity of the preceding SVG elemnt.
-
- Possible hack **
Since the applyAlpha line in PDFGraphics2D.fill() will not be correct when the paint returned by getPaint() is a gradient, I added an instanceof check so that it only runs when getPaint() returns an instance of Color. This is not a thouroughly thought-out fix and therefore should just be regarded as a workaround hack.
- Possible hack **
Attaching SVG file and FO, plus hack (most likely not suitable as fix) to get around issue.