Permalink
Browse files

Merge branch 'master' of https://github.com/tsaizhenling/SVGKit into …

…tsaizhenling-master
  • Loading branch information...
adamgit adamgit
adamgit authored and adamgit committed May 5, 2013
2 parents c74a10d + e693e27 commit 1d1a5f1fdc87d13ce58f95575aa990a27abfd0f0
@@ -213,7 +213,7 @@ - (void)postProcessAttributesAddingErrorsTo:(SVGKParseResult *)parseResult {
* skewY(<skew-angle>), which specifies a skew transformation along the y-axis.
*/
- if( [[self getAttribute:@"transform"] length] > 0 )
+ if( [[self getAttribute:@"transform"] length] > 0 || [[self getAttribute:@"gradientTransform"] length] > 0)
{
if( [self conformsToProtocol:@protocol(SVGTransformable)] )
{
@@ -225,6 +225,9 @@ - (void)postProcessAttributesAddingErrorsTo:(SVGKParseResult *)parseResult {
The individual transform definitions are separated by whitespace and/or a comma.
*/
NSString* value = [self getAttribute:@"transform"];
+ if (!value.length) {
+ value = [self getAttribute:@"gradientTransform"];
+ }
#if !(TARGET_OS_IPHONE) && ( !defined( __MAC_10_7 ) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6_7 )
NSLog(@"[%@] WARNING: the transform attribute requires OS X 10.7 or above (we need Regular Expressions! Apple was slow to add them :( ). Ignoring TRANSFORMs in SVG!", [self class] );
@@ -26,8 +26,9 @@
#import "SVGRect.h"
#import "SVGGradientStop.h"
+#import "SVGTransformable.h"
-@interface SVGGradientElement : SVGElement /* NB: does NOT implemente "SVGLayeredElement" because spec says that these specifically NEVER appear in the output */
+@interface SVGGradientElement : SVGElement <SVGTransformable> /* NB: does NOT implemente "SVGLayeredElement" because spec says that these specifically NEVER appear in the output */
{
@public
BOOL radial; /* FIXME: not in SVG Spec */
@@ -9,6 +9,7 @@
@implementation SVGGradientElement
@synthesize stops = _stops;
+@synthesize transform;
-(void)addStop:(SVGGradientStop *)gradientStop
{
@@ -100,12 +101,16 @@ -(CAGradientLayer *)newGradientLayerForObjectRect:(CGRect) objectRect viewportRe
SVGLength* svgX1 = [SVGLength svgLengthFromNSString:[self getAttributeInheritedIfNil:@"x1"]];
SVGLength* svgY1 = [SVGLength svgLengthFromNSString:[self getAttributeInheritedIfNil:@"y1"]];
- CGPoint startPoint = [self normalizeGradientCoordinate:svgX1 y:svgY1 rectToFill:rectForRelativeUnits];
+ CGPoint startPoint = CGPointMake(svgX1.value, svgY1.value);
+ startPoint = CGPointApplyAffineTransform(startPoint, self.transform);
+ startPoint = [self normalizeGradientCoordinate:[SVGLength svgLengthFromNSString:[NSString stringWithFormat:@"%f",startPoint.x]] y:[SVGLength svgLengthFromNSString:[NSString stringWithFormat:@"%f",startPoint.y]] rectToFill:rectForRelativeUnits];
SVGLength* svgX2 = [SVGLength svgLengthFromNSString:[self getAttributeInheritedIfNil:@"x2"]];
SVGLength* svgY2 = [SVGLength svgLengthFromNSString:[self getAttributeInheritedIfNil:@"y2"]];
- CGPoint endPoint = [self normalizeGradientCoordinate:svgX2 y:svgY2 rectToFill:rectForRelativeUnits];
+ CGPoint endPoint = CGPointMake(svgX2.value, svgY2.value);
+ endPoint = CGPointApplyAffineTransform(endPoint, self.transform);
+ endPoint = [self normalizeGradientCoordinate:[SVGLength svgLengthFromNSString:[NSString stringWithFormat:@"%f",endPoint.x]] y:[SVGLength svgLengthFromNSString:[NSString stringWithFormat:@"%f",endPoint.y]] rectToFill:rectForRelativeUnits];
#ifdef SVG_DEBUG_GRADIENTS
NSLog(@"Gradient start point %@ end point %@", NSStringFromCGPoint(startPoint), NSStringFromCGPoint(endPoint));
View
@@ -196,6 +196,7 @@ - (id)initWithParsedSVG:(SVGKParseResult *)parseResult {
if ( self.DOMDocument == nil )
{
NSLog(@"[%@] ERROR: failed to init SVGKImage with source = %@, returning nil from init methods", [self class], source );
+ [self release];
self = nil;
}

0 comments on commit 1d1a5f1

Please sign in to comment.