pashapm / svg-android-2

Automatically exported from code.google.com/p/svg-android-2
Apache License 2.0
0 stars 0 forks source link

Incorrect handling of fill-opacity and stroke-opacity #11

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use an SVG that has a fill-opacity and/or stroke-opacity set at the group 
level and that is not set on an element within the group.
2. Notice that the children of the group do not inherit the opacity.

What is the expected output? What do you see instead?
Expected behavior is that children of a group inherit the opacity of the group, 
while children outside of all groups default to an opacity of 1 if not set.

Please provide any additional information below.
A super simple example SVG that exhibits this problem:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
 <g style="opacity:0.5">
  <rect x="50" y="20" width="150" height="150" style="fill:blue;stroke:pink;stroke-width:5" />
 </g>
 <rect x="250" y="20" width="150" height="150" style="fill:blue;stroke:pink;stroke-width:5" />
</svg>

With this example, you should see the rectangle on the left at 50% opacity and 
the rectangle on the right should be fully opaque.  However, with the current 
code, both rectangles are fully opaque.

Original issue reported on code.google.com by sc...@mobiata.com on 10 Feb 2012 at 7:52

GoogleCodeExporter commented 9 years ago
The fix to this appears to be straightforward.  Change the following lines:
        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
            //appendElementString(parsed, namespaceURI, localName, qName, atts);

            // Log.d(TAG, localName + showAttributes(atts));
            // Reset paint opacity
            strokePaint.setAlpha(255);
            fillPaint.setAlpha(255);
            // Ignore everything but rectangles in bounds mode
            if (boundsMode) {
                if (localName.equals("rect")) {

To this:
        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
            //appendElementString(parsed, namespaceURI, localName, qName, atts);

            // Log.d(TAG, localName + showAttributes(atts));
            // Reset paint opacity
            if (!strokeSet) {
                strokePaint.setAlpha(255);
            }
            if (!fillSet) {
                fillPaint.setAlpha(255);
            }
            // Ignore everything but rectangles in bounds mode
            if (boundsMode) {
                if (localName.equals("rect")) {

Original comment by sc...@mobiata.com on 10 Feb 2012 at 7:53

GoogleCodeExporter commented 9 years ago
fixed

Original comment by suh...@google.com on 30 Sep 2013 at 3:57

GoogleCodeExporter commented 9 years ago
update status

Original comment by suh...@google.com on 3 Jan 2014 at 11:28