SVGLineElement.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // SVGLineElement.m
  3. // SVGKit
  4. //
  5. // Copyright Matt Rajca 2010-2011. All rights reserved.
  6. //
  7. #import "SVGLineElement.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. @implementation SVGLineElement
  11. @synthesize x1 = _x1;
  12. @synthesize y1 = _y1;
  13. @synthesize x2 = _x2;
  14. @synthesize y2 = _y2;
  15. - (void)postProcessAttributesAddingErrorsTo:(SVGKParseResult *)parseResult {
  16. [super postProcessAttributesAddingErrorsTo:parseResult];
  17. SVGRect r = parseResult.rootOfSVGTree.viewport;
  18. if( [[self getAttribute:@"x1"] length] > 0 )
  19. {
  20. _x1 = [[SVGLength svgLengthFromNSString:[self getAttribute:@"x1"] ]
  21. pixelsValueWithDimension:r.width];
  22. }
  23. if( [[self getAttribute:@"y1"] length] > 0 )
  24. {
  25. _y1 = [[SVGLength svgLengthFromNSString:[self getAttribute:@"y1"] ]
  26. pixelsValueWithDimension:r.height];
  27. }
  28. if( [[self getAttribute:@"x2"] length] > 0 )
  29. {
  30. _x2 = [[SVGLength svgLengthFromNSString:[self getAttribute:@"x2"] ]
  31. pixelsValueWithDimension:r.width];
  32. }
  33. if( [[self getAttribute:@"y2"] length] > 0 )
  34. {
  35. _y2 = [[SVGLength svgLengthFromNSString:[self getAttribute:@"y2"] ]
  36. pixelsValueWithDimension:r.height];
  37. }
  38. }
  39. -(CALayer *)newLayer
  40. {
  41. CGMutablePathRef path = CGPathCreateMutable();
  42. CGPathMoveToPoint(path, NULL, _x1, _y1);
  43. CGPathAddLineToPoint(path, NULL, _x2, _y2);
  44. CALayer* result = [SVGHelperUtilities newCALayerForPathBasedSVGElement:self withPath:path];
  45. CGPathRelease(path);
  46. return result;
  47. }
  48. @end