Skip to content

Commit

Permalink
FIXED: fill-opacity being ignored when no fill specified (fixed SVGKi…
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgit committed Nov 17, 2013
1 parent 336baab commit caedba9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Demo-Samples/SVG/sakamura-default-fill-opacity-test.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Demo-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -113,6 +114,7 @@
66A09CA416CFE67B003CD5CD /* text01.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = text01.svg; sourceTree = "<group>"; };
66A09CA516CFE67B003CD5CD /* tspan01.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = tspan01.svg; sourceTree = "<group>"; };
66A9F4431688C66E000D4A2E /* RainbowWing.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = RainbowWing.svg; sourceTree = "<group>"; };
66C43EA818398E6E00299662 /* sakamura-default-fill-opacity-test.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "sakamura-default-fill-opacity-test.svg"; sourceTree = "<group>"; };
66E785AA171A228A001EF59D /* svg-with-explicit-width.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "svg-with-explicit-width.svg"; sourceTree = "<group>"; };
66E785AC171A2345001EF59D /* svg-with-explicit-width-large.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "svg-with-explicit-width-large.svg"; sourceTree = "<group>"; };
66E862571688BA0B0059C9C4 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
};
Expand Down
15 changes: 9 additions & 6 deletions Source/DOM classes/SVG-DOM/SVGHelperUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ +(CALayer *) newCALayerForPathBasedSVGElement:(SVGElement<SVGTransformable>*) sv


NSString* actualFill = [svgElement cascadedValueForStylableProperty:@"fill"];
NSString* actualFillOpacity = [svgElement cascadedValueForStylableProperty:@"fill-opacity"];
if ( [actualFill hasPrefix:@"none"])
{
_shapeLayer.fillColor = nil;
Expand Down Expand Up @@ -439,14 +440,16 @@ +(CALayer *) newCALayerForPathBasedSVGElement:(SVGElement<SVGTransformable>*) 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
{
Expand Down
2 changes: 1 addition & 1 deletion XCodeProjectData/Demo-iOS/MasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit caedba9

Please sign in to comment.