Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix linear gradients

transform of the gradients were not taken into account before.
  • Loading branch information...
commit ef6a6797493a03121c201e3613df31ed188c8811 1 parent f2f365d
@tsaizhenling tsaizhenling authored
View
5 Source/DOM classes/Unported or Partial DOM/SVGElement.m
@@ -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] );
View
3  Source/DOM classes/Unported or Partial DOM/SVGGradientElement.h
@@ -25,8 +25,9 @@
#import "SVGLayeredElement.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 */
View
9 Source/DOM classes/Unported or Partial DOM/SVGGradientElement.m
@@ -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));
Please sign in to comment.
Something went wrong with that request. Please try again.