TinySVGTextAreaElement.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // TinySVGTextAreaElement.m
  3. // SVGKit-iOS
  4. //
  5. // Created by David Gileadi on 8/26/14.
  6. // Copyright (c) 2014 na. All rights reserved.
  7. //
  8. #import "TinySVGTextAreaElement.h"
  9. #import "SVGKParseResult.h"
  10. #import "SVGElement_ForParser.h"
  11. @interface TinySVGTextAreaElement()
  12. @property(nonatomic,strong,readwrite) SVGLength* /* FIXME: should be SVGAnimatedLengthList */ width;
  13. @property(nonatomic,strong,readwrite) SVGLength* /* FIXME: should be SVGAnimatedLengthList */ height;
  14. @end
  15. @implementation TinySVGTextAreaElement
  16. @synthesize width;
  17. @synthesize height;
  18. - (void)postProcessAttributesAddingErrorsTo:(SVGKParseResult *)parseResult
  19. {
  20. [super postProcessAttributesAddingErrorsTo:parseResult];
  21. self.width = [self getAttributeAsSVGLength:@"width"];
  22. self.height = [self getAttributeAsSVGLength:@"height"];
  23. }
  24. - (CALayer *) newLayer
  25. {
  26. CATextLayer *label = (CATextLayer *) [super newLayer];
  27. label.wrapped = YES;
  28. float w = [self.width pixelsValue];
  29. float h = [self.height pixelsValue];
  30. if( w > 0 && h > 0 ) {
  31. if( w == 0.0f )
  32. w = label.bounds.size.width;
  33. if( h == 0.0f )
  34. h = label.bounds.size.height;
  35. label.bounds = CGRectMake(0, 0, w, h);
  36. }
  37. NSString* textAlign = [self cascadedValueForStylableProperty:@"text-align"];
  38. if( [@"start" isEqualToString:textAlign] )
  39. label.alignmentMode = kCAAlignmentLeft;
  40. else if( [@"center" isEqualToString:textAlign] )
  41. label.alignmentMode = kCAAlignmentCenter;
  42. else if( [@"end" isEqualToString:textAlign] )
  43. label.alignmentMode = kCAAlignmentRight;
  44. else if( [@"justify" isEqualToString:textAlign] )
  45. label.alignmentMode = kCAAlignmentJustified;
  46. label.position = CGPointZero;
  47. return label;
  48. }
  49. @end