SVGEllipseElement.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // SVGEllipseElement.m
  3. // SVGKit
  4. //
  5. // Copyright Matt Rajca 2010-2011. All rights reserved.
  6. //
  7. #import "SVGEllipseElement.h"
  8. #import "SVGElement_ForParser.h" // to resolve Xcode circular dependencies; in long term, parsing SHOULD NOT HAPPEN inside any class whose name starts "SVG" (because those are reserved classes for the SVG Spec)
  9. #import "SVGHelperUtilities.h"
  10. @interface SVGEllipseElement()
  11. @property (nonatomic, readwrite) CGFloat cx;
  12. @property (nonatomic, readwrite) CGFloat cy;
  13. @property (nonatomic, readwrite) CGFloat rx;
  14. @property (nonatomic, readwrite) CGFloat ry;
  15. @end
  16. @implementation SVGEllipseElement
  17. @synthesize cx = _cx;
  18. @synthesize cy = _cy;
  19. @synthesize rx = _rx;
  20. @synthesize ry = _ry;
  21. - (void)postProcessAttributesAddingErrorsTo:(SVGKParseResult *)parseResult {
  22. [super postProcessAttributesAddingErrorsTo:parseResult];
  23. SVGRect r = parseResult.rootOfSVGTree.viewport;
  24. if( [[self getAttribute:@"cx"] length] > 0 )
  25. {
  26. self.cx = [[SVGLength svgLengthFromNSString:[self getAttribute:@"cx"] ]
  27. pixelsValueWithDimension:r.width];
  28. }
  29. if( [[self getAttribute:@"cy"] length] > 0 )
  30. {
  31. self.cy = [[SVGLength svgLengthFromNSString:[self getAttribute:@"cy"] ]
  32. pixelsValueWithDimension:r.height];
  33. }
  34. if( [[self getAttribute:@"rx"] length] > 0 )
  35. {
  36. self.rx = [[SVGLength svgLengthFromNSString:[self getAttribute:@"rx"] ]
  37. pixelsValueWithDimension:r.width];
  38. }
  39. if( [[self getAttribute:@"ry"] length] > 0 )
  40. {
  41. self.ry = [[SVGLength svgLengthFromNSString:[self getAttribute:@"ry"] ]
  42. pixelsValueWithDimension:r.height];
  43. }
  44. if( [[self getAttribute:@"r"] length] > 0 ) { // circle
  45. self.ry = self.rx = [[SVGLength svgLengthFromNSString:[self getAttribute:@"r"] ]
  46. pixelsValueWithDimension:hypot(r.width, r.height)/M_SQRT2];
  47. }
  48. CGMutablePathRef path = CGPathCreateMutable();
  49. CGPathAddEllipseInRect(path, NULL, CGRectMake(self.cx - self.rx, self.cy - self.ry, self.rx * 2, self.ry * 2));
  50. self.pathForShapeInRelativeCoords = path;
  51. CGPathRelease(path);
  52. }
  53. @end