-
Notifications
You must be signed in to change notification settings - Fork 1.1k
2013base #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2013base
Are you sure you want to change the base?
2013base #39
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
| SVGTransformable { | ||
| */ | ||
|
|
||
| #import <UIKit/UIKit.h> | ||
|
|
||
| #import "SVGElement.h" | ||
| #import "SVGElement_ForParser.h" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,34 +53,63 @@ - (CALayer *) newLayer | |
| } | ||
|
|
||
| - (void)layoutLayer:(CALayer *)layer { | ||
| CGRect mainRect = CGRectZero; | ||
|
|
||
| /** Adam: make a frame thats the UNION of all sublayers frames */ | ||
| for ( CALayer *currentLayer in [layer sublayers] ) | ||
| { | ||
| CGRect subLayerFrame = currentLayer.frame; | ||
| mainRect = CGRectUnion(mainRect, subLayerFrame); | ||
| CGRect frameRect = CGRectZero; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has this been tested with all the current samples in Demo-iOS project? I don't know preciesly what the original was intended to do, but it seems to be forcing Apple to expand the bounds of each CALAyer to fit its content (because Apple's API isn't very good to start with)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tested this with SOME of the current samples. You can clearly see the difference with the introduced debug option OUTLINE_SHAPES enabled.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of Apple's API requires 0,0 to be included, otherwise all the co-ordinate systems are broken. Transforms are currently correct in all the samples. I'll try merging OUTLINE-SHAPES (looks very useful!), but also: do you have an example SVG that renders incorrectly with 0,0 included? would be good to add as a test case
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, actually, as it seems to me, all the coordinate systems with groups are broken now. Just because they are not transformed. They have a good explanation here: http://www.w3.org/TR/SVG/coords.html#EstablishingANewUserSpace It seems to render correctly, though (at least, until there's no transformed text). I will try to draw an example. |
||
| CGRect mainRect = CGRectZero; | ||
| CGRect boundsRect = CGRectZero; | ||
|
|
||
| NSArray *sublayers = [layer sublayers]; | ||
|
|
||
| for (NSUInteger n = 0; n < [sublayers count]; n++) { | ||
| CALayer *currentLayer = [sublayers objectAtIndex:n]; | ||
|
|
||
| if (n == 0) { | ||
| frameRect = currentLayer.frame; | ||
| } | ||
| else { | ||
| frameRect = CGRectUnion(frameRect, currentLayer.frame); | ||
| } | ||
| mainRect = CGRectUnion(mainRect, currentLayer.frame); | ||
| } | ||
|
|
||
| boundsRect = CGRectOffset(frameRect, -frameRect.origin.x, -frameRect.origin.y); | ||
|
|
||
| for (CALayer *currentLayer in sublayers) { | ||
| [currentLayer setAffineTransform:CGAffineTransformConcat(currentLayer.affineTransform, CGAffineTransformMakeTranslation(-frameRect.origin.x, -frameRect.origin.y))]; | ||
| } | ||
|
|
||
| layer.frame = mainRect; | ||
| layer.frame = boundsRect; | ||
|
|
||
| /** Adam:(dont know why this is here): set each sublayer to have a frame the same size as the parent frame, but with 0 offset. | ||
|
|
||
| Adam: if I understand this correctly, the person who wrote it should have just written: | ||
|
|
||
| "currentLayer.bounds = layer.frame" | ||
|
|
||
| i.e. make every layer have the same size as the parent layer. | ||
|
|
||
| But whoever wrote this didn't document their bad code, so I have no idea if thats correct or not | ||
| */ | ||
| for (CALayer *currentLayer in [layer sublayers]) { | ||
| CGRect frame = currentLayer.frame; | ||
| frame.origin.x -= mainRect.origin.x; | ||
| frame.origin.y -= mainRect.origin.y; | ||
|
|
||
| currentLayer.frame = frame; | ||
| } | ||
| #if OUTLINE_SHAPES | ||
|
|
||
| layer.borderColor = [UIColor redColor].CGColor; | ||
| layer.borderWidth = 2.0f; | ||
|
|
||
| NSString* textToDraw = [NSString stringWithFormat:@"%@ (%@): {%.1f, %.1f} {%.1f, %.1f}", self.identifier, [self class], layer.frame.origin.x, layer.frame.origin.y, layer.frame.size.width, layer.frame.size.height]; | ||
|
|
||
| UIFont* fontToDraw = [UIFont fontWithName:@"Helvetica" | ||
| size:10.0f]; | ||
| CGSize sizeOfTextRect = [textToDraw sizeWithFont:fontToDraw]; | ||
|
|
||
| CATextLayer *debugText = [[[CATextLayer alloc] init] autorelease]; | ||
| [debugText setFont:@"Helvetica"]; | ||
| [debugText setFontSize:10.0f]; | ||
| [debugText setFrame:CGRectMake(0, 0, sizeOfTextRect.width, sizeOfTextRect.height)]; | ||
| [debugText setString:textToDraw]; | ||
| [debugText setAlignmentMode:kCAAlignmentLeft]; | ||
| [debugText setForegroundColor:[UIColor redColor].CGColor]; | ||
| [debugText setContentsScale:[[UIScreen mainScreen] scale]]; | ||
| [debugText setShouldRasterize:NO]; | ||
| [layer addSublayer:debugText]; | ||
|
|
||
| #endif | ||
|
|
||
| //applying transform relative to centerpoint | ||
| CGAffineTransform tr1 = layer.affineTransform; | ||
| tr1 = CGAffineTransformConcat(tr1, CGAffineTransformMakeTranslation(frameRect.size.width/2, frameRect.size.height/2)); | ||
| CGAffineTransform tr2 = CGAffineTransformConcat(tr1, self.transformRelative); | ||
| tr2 = CGAffineTransformConcat(tr2, CGAffineTransformInvert(tr1)); | ||
| tr1 = CGAffineTransformConcat(CGAffineTransformMakeTranslation(frameRect.origin.x, frameRect.origin.y), tr2); | ||
| [layer setAffineTransform:tr1]; | ||
| } | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,7 +77,7 @@ - (void)postProcessAttributesAddingErrorsTo:(SVGKParseResult *)parseResult { | |
| _ry = [[self getAttribute:@"ry"] floatValue]; | ||
|
|
||
| CGMutablePathRef path = CGPathCreateMutable(); | ||
| CGRect rect = CGRectMake(_x, _y, _width, _height); | ||
| CGRect rect = CGRectMake(0, 0, _width, _height); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does this work? It seems to be ignoring the X and Y attributes.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. X and Y attributes are taken into account in the parent class (SVGShapeElement, line 194). That was made to have correct layer bounds with transforms. Also, can be seen with OUTLINE_SHAPES enabled. |
||
|
|
||
| if (_rx == 0 && _ry == 0) { | ||
| CGPathAddRect(path, NULL, rect); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,10 @@ | |
| CGRect _layerRect; | ||
| } | ||
|
|
||
| @property (nonatomic, readonly) CGFloat x; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accoridng to SVG spec, there's no X nor Y in SVGShapeElement - they only exist in SVGRectElement (some of these SVG*Element classes are badly wrong in SVGKit right now, but I'm moving them all towards being spec-compliant) |
||
|
|
||
| @property (nonatomic, readonly) CGFloat y; | ||
|
|
||
| @property (nonatomic, readwrite) CGFloat opacity; | ||
|
|
||
| @property (nonatomic) float fillOpacity, strokeOpacity; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I'd like to remove these convenience methods, and force all code to call through the "cascadedValueForStylableProperty:" method.
And ... make that method check if the incoming property CAN be cascaded (using the table from SVG Spec)