diff --git a/Demo-Samples/SVG/sakamura-default-fill-opacity-test.svg b/Demo-Samples/SVG/sakamura-default-fill-opacity-test.svg new file mode 100644 index 000000000..eb3bfdf85 --- /dev/null +++ b/Demo-Samples/SVG/sakamura-default-fill-opacity-test.svg @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Demo-iOS.xcodeproj/project.pbxproj b/Demo-iOS.xcodeproj/project.pbxproj index b3e69fbba..27c724810 100644 --- a/Demo-iOS.xcodeproj/project.pbxproj +++ b/Demo-iOS.xcodeproj/project.pbxproj @@ -33,6 +33,7 @@ 66A09CAA16CFE67B003CD5CD /* text01.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66A09CA416CFE67B003CD5CD /* text01.svg */; }; 66A09CAB16CFE67B003CD5CD /* tspan01.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66A09CA516CFE67B003CD5CD /* tspan01.svg */; }; 66A9F4441688C66E000D4A2E /* RainbowWing.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66A9F4431688C66E000D4A2E /* RainbowWing.svg */; }; + 66C43EA918398E6E00299662 /* sakamura-default-fill-opacity-test.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66C43EA818398E6E00299662 /* sakamura-default-fill-opacity-test.svg */; }; 66E785AB171A228A001EF59D /* svg-with-explicit-width.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66E785AA171A228A001EF59D /* svg-with-explicit-width.svg */; }; 66E785AD171A2345001EF59D /* svg-with-explicit-width-large.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66E785AC171A2345001EF59D /* svg-with-explicit-width-large.svg */; }; 66E8626B1688BA0B0059C9C4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 66E862581688BA0B0059C9C4 /* AppDelegate.m */; }; @@ -113,6 +114,7 @@ 66A09CA416CFE67B003CD5CD /* text01.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = text01.svg; sourceTree = ""; }; 66A09CA516CFE67B003CD5CD /* tspan01.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = tspan01.svg; sourceTree = ""; }; 66A9F4431688C66E000D4A2E /* RainbowWing.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = RainbowWing.svg; sourceTree = ""; }; + 66C43EA818398E6E00299662 /* sakamura-default-fill-opacity-test.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "sakamura-default-fill-opacity-test.svg"; sourceTree = ""; }; 66E785AA171A228A001EF59D /* svg-with-explicit-width.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "svg-with-explicit-width.svg"; sourceTree = ""; }; 66E785AC171A2345001EF59D /* svg-with-explicit-width-large.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "svg-with-explicit-width-large.svg"; sourceTree = ""; }; 66E862571688BA0B0059C9C4 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -307,6 +309,7 @@ 66A9F4431688C66E000D4A2E /* RainbowWing.svg */, 66E862881688BA510059C9C4 /* Reinel_compass_rose-simplified-for-testing.svg */, 66E862891688BA510059C9C4 /* Reinel_compass_rose.svg */, + 66C43EA818398E6E00299662 /* sakamura-default-fill-opacity-test.svg */, 66E785AA171A228A001EF59D /* svg-with-explicit-width.svg */, 66E785AC171A2345001EF59D /* svg-with-explicit-width-large.svg */, 66E8628A1688BA510059C9C4 /* test-wave-1.svg */, @@ -433,6 +436,7 @@ 66E785AB171A228A001EF59D /* svg-with-explicit-width.svg in Resources */, 66E785AD171A2345001EF59D /* svg-with-explicit-width-large.svg in Resources */, 9ED79A21179D83580048AA5B /* radialGradientTest.svg in Resources */, + 66C43EA918398E6E00299662 /* sakamura-default-fill-opacity-test.svg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/DOM classes/SVG-DOM/SVGHelperUtilities.m b/Source/DOM classes/SVG-DOM/SVGHelperUtilities.m index 3c6b1fb0e..5cf0ba8a7 100644 --- a/Source/DOM classes/SVG-DOM/SVGHelperUtilities.m +++ b/Source/DOM classes/SVG-DOM/SVGHelperUtilities.m @@ -410,6 +410,7 @@ +(CALayer *) newCALayerForPathBasedSVGElement:(SVGElement*) sv NSString* actualFill = [svgElement cascadedValueForStylableProperty:@"fill"]; + NSString* actualFillOpacity = [svgElement cascadedValueForStylableProperty:@"fill-opacity"]; if ( [actualFill hasPrefix:@"none"]) { _shapeLayer.fillColor = nil; @@ -439,14 +440,16 @@ +(CALayer *) newCALayerForPathBasedSVGElement:(SVGElement*) sv return gradientLayer; } } - else if( actualFill.length > 0 ) + else if( actualFill.length > 0 || actualFillOpacity.length > 0 ) { - SVGColor fillColorAsSVGColor = SVGColorFromString([actualFill UTF8String]); // have to use the intermediate of an SVGColor so that we can over-ride the ALPHA component in next line - NSString* actualFillOpacity = [svgElement cascadedValueForStylableProperty:@"fill-opacity"]; - if( actualFillOpacity.length > 0 ) - fillColorAsSVGColor.a = (uint8_t) ([actualFillOpacity floatValue] * 0xFF); + SVGColor fillColorAsSVGColor = ( actualFill.length > 0 ) ? + SVGColorFromString([actualFill UTF8String]) // have to use the intermediate of an SVGColor so that we can over-ride the ALPHA component in next line + : SVGColorMake(0, 0, 0, 0); - _shapeLayer.fillColor = CGColorWithSVGColor(fillColorAsSVGColor); + if( actualFillOpacity.length > 0 ) + fillColorAsSVGColor.a = (uint8_t) ([actualFillOpacity floatValue] * 0xFF); + + _shapeLayer.fillColor = CGColorWithSVGColor(fillColorAsSVGColor); } else { diff --git a/XCodeProjectData/Demo-iOS/MasterViewController.m b/XCodeProjectData/Demo-iOS/MasterViewController.m index 4bf1a3d90..930881e77 100644 --- a/XCodeProjectData/Demo-iOS/MasterViewController.m +++ b/XCodeProjectData/Demo-iOS/MasterViewController.m @@ -22,7 +22,7 @@ @implementation MasterViewController - (id)init { if (self) { - self.sampleNames = [NSMutableArray arrayWithObjects: @"map-alaska-onlysimple", @"g-element-applies-rotation", @"groups-and-layers-test", @"http://upload.wikimedia.org/wikipedia/commons/f/f9/BlankMap-Africa.svg", @"shapes", @"strokes", @"transformations", @"rounded-rects", @"gradients",@"radialGradientTest", @"PreserveAspectRatio", @"australia_states_blank", @"Reinel_compass_rose", @"Monkey", @"Blank_Map-Africa", @"opacity01", @"Note", @"Note@2x", @"imageWithASinglePointPath", @"Lion", @"lingrad01", @"Map", @"CurvedDiamond", @"Text", @"text01", @"tspan01", @"Location_European_nation_states", @"uk-only", @"Europe_states_reduced", @"Compass_rose_pale", @"quad01", @"cubic01", @"rotated-and-skewed-text", @"RainbowWing", @"StyleAttribute", @"voies", @"nil-demo-layered-imageview", @"svg-with-explicit-width", @"svg-with-explicit-width-large", @"svg-with-explicit-width-large@160x240", @"BlankMap-World6-Equirectangular", nil]; + self.sampleNames = [NSMutableArray arrayWithObjects: @"map-alaska-onlysimple", @"g-element-applies-rotation", @"groups-and-layers-test", @"http://upload.wikimedia.org/wikipedia/commons/f/f9/BlankMap-Africa.svg", @"shapes", @"strokes", @"transformations", @"rounded-rects", @"gradients",@"radialGradientTest", @"PreserveAspectRatio", @"australia_states_blank", @"Reinel_compass_rose", @"Monkey", @"Blank_Map-Africa", @"opacity01", @"Note", @"Note@2x", @"imageWithASinglePointPath", @"Lion", @"lingrad01", @"Map", @"CurvedDiamond", @"Text", @"text01", @"tspan01", @"Location_European_nation_states", @"uk-only", @"Europe_states_reduced", @"Compass_rose_pale", @"quad01", @"cubic01", @"rotated-and-skewed-text", @"RainbowWing", @"sakamura-default-fill-opacity-test", @"StyleAttribute", @"voies", @"nil-demo-layered-imageview", @"svg-with-explicit-width", @"svg-with-explicit-width-large", @"svg-with-explicit-width-large@160x240", @"BlankMap-World6-Equirectangular", nil]; } /** Apple really sucks. They keep randomly changing which init methods they call, BREAKING ALL EXISTING CODE */