LOTShapeStroke.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // LOTShapeStroke.m
  3. // LottieAnimator
  4. //
  5. // Created by Brandon Withrow on 12/15/15.
  6. // Copyright © 2015 Brandon Withrow. All rights reserved.
  7. //
  8. #import "LOTShapeStroke.h"
  9. #import "CGGeometry+LOTAdditions.h"
  10. @implementation LOTShapeStroke
  11. - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary {
  12. self = [super init];
  13. if (self) {
  14. [self _mapFromJSON:jsonDictionary];
  15. }
  16. return self;
  17. }
  18. - (void)_mapFromJSON:(NSDictionary *)jsonDictionary {
  19. if (jsonDictionary[@"nm"] ) {
  20. _keyname = [jsonDictionary[@"nm"] copy];
  21. }
  22. NSDictionary *color = jsonDictionary[@"c"];
  23. if (color) {
  24. _color = [[LOTKeyframeGroup alloc] initWithData:color];
  25. }
  26. NSDictionary *width = jsonDictionary[@"w"];
  27. if (width) {
  28. _width = [[LOTKeyframeGroup alloc] initWithData:width];
  29. }
  30. NSDictionary *opacity = jsonDictionary[@"o"];
  31. if (opacity) {
  32. _opacity = [[LOTKeyframeGroup alloc] initWithData:opacity];
  33. [_opacity remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  34. return LOT_RemapValue(inValue, 0, 100, 0, 1);
  35. }];
  36. }
  37. _capType = [jsonDictionary[@"lc"] integerValue] - 1;
  38. _joinType = [jsonDictionary[@"lj"] integerValue] - 1;
  39. NSNumber *fillEnabled = jsonDictionary[@"fillEnabled"];
  40. _fillEnabled = fillEnabled.boolValue;
  41. NSDictionary *dashOffset = nil;
  42. NSArray *dashes = jsonDictionary[@"d"];
  43. if (dashes) {
  44. NSMutableArray *dashPattern = [NSMutableArray array];
  45. for (NSDictionary *dash in dashes) {
  46. if ([dash[@"n"] isEqualToString:@"o"]) {
  47. dashOffset = dash[@"v"];
  48. continue;
  49. }
  50. // TODO DASH PATTERNS
  51. NSDictionary *value = dash[@"v"];
  52. LOTKeyframeGroup *keyframeGroup = [[LOTKeyframeGroup alloc] initWithData:value];
  53. [dashPattern addObject:keyframeGroup];
  54. }
  55. _lineDashPattern = dashPattern;
  56. }
  57. if (dashOffset) {
  58. _dashOffset = [[LOTKeyframeGroup alloc] initWithData:dashOffset];
  59. }
  60. }
  61. @end