diff --git a/ios/RNSVG.xcodeproj/project.pbxproj b/ios/RNSVG.xcodeproj/project.pbxproj index a3cbfaad..e8a194f6 100644 --- a/ios/RNSVG.xcodeproj/project.pbxproj +++ b/ios/RNSVG.xcodeproj/project.pbxproj @@ -231,7 +231,7 @@ 7FC260D31E34A12A00A39833 /* RNSVGSymbolManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGSymbolManager.m; sourceTree = ""; }; 7FFC4EA21E24E52500AD5BE5 /* RNSVGGlyphContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSVGGlyphContext.h; path = Text/RNSVGGlyphContext.h; sourceTree = ""; }; 7FFC4EA31E24E5AD00AD5BE5 /* RNSVGGlyphContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGGlyphContext.m; path = Text/RNSVGGlyphContext.m; sourceTree = ""; }; - A361E7A31EB0C33D00646005 /* libRNSVG-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRNSVG-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 94DDAC5C1F3D024300EED511 /* libRNSVG-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRNSVG-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -274,6 +274,7 @@ isa = PBXGroup; children = ( 0CF68AC11AF0540F00FF9E5C /* libRNSVG.a */, + 94DDAC5C1F3D024300EED511 /* libRNSVG-tvOS.a */, ); name = Products; sourceTree = ""; @@ -452,7 +453,7 @@ ); name = "RNSVG-tvOS"; productName = RNSVG; - productReference = A361E7A31EB0C33D00646005 /* libRNSVG-tvOS.a */; + productReference = 94DDAC5C1F3D024300EED511 /* libRNSVG-tvOS.a */; productType = "com.apple.product-type.library.static"; }; /* End PBXNativeTarget section */ diff --git a/ios/RNSVGRenderable.h b/ios/RNSVGRenderable.h index 8a17190b..1d56871a 100644 --- a/ios/RNSVGRenderable.h +++ b/ios/RNSVGRenderable.h @@ -21,11 +21,12 @@ @property (nonatomic, assign) RNSVGCGFCRule fillRule; @property (nonatomic, strong) RNSVGBrush *stroke; @property (nonatomic, assign) CGFloat strokeOpacity; -@property (nonatomic, assign) CGFloat strokeWidth; +@property (nonatomic, assign) NSString *strokeWidth; @property (nonatomic, assign) CGLineCap strokeLinecap; @property (nonatomic, assign) CGLineJoin strokeLinejoin; @property (nonatomic, assign) CGFloat strokeMiterlimit; @property (nonatomic, assign) RNSVGCGFloatArray strokeDasharray; +@property (nonatomic, assign) NSArray *strokeDasharrayData; @property (nonatomic, assign) CGFloat strokeDashoffset; @property (nonatomic, copy) NSArray *propList; diff --git a/ios/RNSVGRenderable.m b/ios/RNSVGRenderable.m index ccf972ea..4f6f0b4a 100644 --- a/ios/RNSVGRenderable.m +++ b/ios/RNSVGRenderable.m @@ -21,7 +21,7 @@ if (self = [super init]) { _fillOpacity = 1; _strokeOpacity = 1; - _strokeWidth = 1; + _strokeWidth = @"1"; _fillRule = kRNSVGCGFCRuleNonzero; } return self; @@ -72,7 +72,7 @@ _strokeOpacity = strokeOpacity; } -- (void)setStrokeWidth:(CGFloat)strokeWidth +- (void)setStrokeWidth:(NSString*)strokeWidth { if (strokeWidth == _strokeWidth) { return; @@ -108,16 +108,26 @@ _strokeMiterlimit = strokeMiterlimit; } -- (void)setStrokeDasharray:(RNSVGCGFloatArray)strokeDasharray +- (void)setStrokeDasharray:(NSArray *)strokeDasharray { - if (strokeDasharray.array == _strokeDasharray.array) { + if (strokeDasharray == _strokeDasharrayData) { return; } if (_strokeDasharray.array) { free(_strokeDasharray.array); } [self invalidate]; - _strokeDasharray = strokeDasharray; + NSUInteger count = strokeDasharray.count; + _strokeDasharray.count = count; + _strokeDasharray.array = nil; + + if (count) { + _strokeDasharray.array = malloc(sizeof(CGFloat) * count); + for (NSUInteger i = 0; i < count; i++) { + _strokeDasharray.array[i] = [strokeDasharray[i] floatValue]; + } + } + _strokeDasharrayData = strokeDasharray; } - (void)setStrokeDashoffset:(CGFloat)strokeDashoffset @@ -134,7 +144,7 @@ if (propList == _propList) { return; } - + _propList = _attributeList = propList; [self invalidate]; } @@ -153,11 +163,11 @@ CGContextSaveGState(context); CGContextConcatCTM(context, self.matrix); CGContextSetAlpha(context, self.opacity); - + [self beginTransparencyLayer:context]; [self renderLayerTo:context]; [self endTransparencyLayer:context]; - + CGContextRestoreGState(context); } @@ -167,23 +177,23 @@ if (!self.fill && !self.stroke) { return; } - + CGPathRef path = [self getPath:context]; [self setHitArea:path]; - + if (self.opacity == 0) { return; } - + CGPathDrawingMode mode = kCGPathStroke; BOOL fillColor = NO; [self clip:context]; - + BOOL evenodd = self.fillRule == kRNSVGCGFCRuleEvenodd; - + if (self.fill) { fillColor = [self.fill applyFillColor:context opacity:self.fillOpacity]; - + if (fillColor) { mode = evenodd ? kCGPathEOFill : kCGPathFill; } else { @@ -195,31 +205,31 @@ painter:[[self getSvgView] getDefinedPainter:self.fill.brushRef] ]; CGContextRestoreGState(context); - + if (!self.stroke) { return; } } } - + if (self.stroke) { - CGContextSetLineWidth(context, self.strokeWidth); + CGContextSetLineWidth(context, [self.strokeWidth floatValue]); CGContextSetLineCap(context, self.strokeLinecap); CGContextSetLineJoin(context, self.strokeLinejoin); RNSVGCGFloatArray dash = self.strokeDasharray; - + if (dash.count) { CGContextSetLineDash(context, self.strokeDashoffset, dash.array, dash.count); } - + if (!fillColor) { CGContextAddPath(context, path); CGContextReplacePathWithStrokedPath(context); CGContextClip(context); } - + BOOL strokeColor = [self.stroke applyStrokeColor:context opacity:self.strokeOpacity]; - + if (strokeColor && fillColor) { mode = evenodd ? kCGPathEOFillStroke : kCGPathFillStroke; } else if (!strokeColor) { @@ -228,12 +238,12 @@ CGContextAddPath(context, path); CGContextDrawPath(context, mode); } - + // draw stroke CGContextAddPath(context, path); CGContextReplacePathWithStrokedPath(context); CGContextClip(context); - + [self.stroke paint:context opacity:self.strokeOpacity painter:[[self getSvgView] getDefinedPainter:self.stroke.brushRef] @@ -241,7 +251,7 @@ return; } } - + CGContextAddPath(context, path); CGContextDrawPath(context, mode); } @@ -252,14 +262,14 @@ if ([self getSvgView].responsible) { // Add path to hitArea CGMutablePathRef hitArea = CGPathCreateMutableCopy(path); - + if (self.stroke && self.strokeWidth) { // Add stroke to hitArea - CGPathRef strokePath = CGPathCreateCopyByStrokingPath(hitArea, nil, self.strokeWidth, self.strokeLinecap, self.strokeLinejoin, self.strokeMiterlimit); + CGPathRef strokePath = CGPathCreateCopyByStrokingPath(hitArea, nil, [self.strokeWidth floatValue], self.strokeLinecap, self.strokeLinejoin, self.strokeMiterlimit); CGPathAddPath(hitArea, nil, strokePath); CGPathRelease(strokePath); } - + _hitArea = CGPathRetain(CFAutorelease(CGPathCreateCopy(hitArea))); CGPathRelease(hitArea); } @@ -277,22 +287,22 @@ if (!_hitArea) { return nil; } - + if (self.active) { if (!event) { self.active = NO; } return self; } - + CGAffineTransform matrix = CGAffineTransformConcat(self.matrix, transform); CGPathRef hitArea = CGPathCreateCopyByTransformingPath(_hitArea, &matrix); BOOL contains = CGPathContainsPoint(hitArea, nil, point, NO); CGPathRelease(hitArea); - + if (contains) { CGPathRef clipPath = [self getClipPath]; - + if (!clipPath) { return self; } else { @@ -314,14 +324,14 @@ - (void)mergeProperties:(__kindof RNSVGRenderable *)target { NSArray *targetAttributeList = [target getAttributeList]; - + if (targetAttributeList.count == 0) { return; } - + NSMutableArray* attributeList = [self.propList mutableCopy]; _originProperties = [[NSMutableDictionary alloc] init]; - + for (NSString *key in targetAttributeList) { [_originProperties setValue:[self valueForKey:key] forKey:key]; if (![attributeList containsObject:key]) { @@ -329,7 +339,7 @@ [self setValue:[target valueForKey:key] forKey:key]; } } - + _lastMergedList = targetAttributeList; _attributeList = [attributeList copy]; } @@ -339,7 +349,7 @@ for (NSString *key in _lastMergedList) { [self setValue:[_originProperties valueForKey:key] forKey:key]; } - + _lastMergedList = nil; _attributeList = _propList; } diff --git a/ios/Text/RNSVGGlyphContext.h b/ios/Text/RNSVGGlyphContext.h index d796c843..8fc03bc4 100644 --- a/ios/Text/RNSVGGlyphContext.h +++ b/ios/Text/RNSVGGlyphContext.h @@ -13,7 +13,7 @@ @interface RNSVGGlyphContext : NSObject - (instancetype)initWithDimensions:(CGFloat)width height:(CGFloat)height; -- (void)pushContext:(NSDictionary *)font deltaX:(NSArray *)deltaX deltaY:(NSArray *)deltaY positionX:(NSString *)positionX positionY:(NSString *)positionY; +- (void)pushContext:(NSDictionary *)font deltaX:(NSArray *)deltaX deltaY:(NSArray *)deltaY positionX:(NSArray *)positionX positionY:(NSArray *)positionY; - (void)popContext; - (CTFontRef)getGlyphFont; - (CGPoint)getNextGlyphPoint:(CGPoint)offset glyphWidth:(CGFloat)glyphWidth; diff --git a/ios/Text/RNSVGGlyphContext.m b/ios/Text/RNSVGGlyphContext.m index 0ced39c8..06dbe2a7 100644 --- a/ios/Text/RNSVGGlyphContext.m +++ b/ios/Text/RNSVGGlyphContext.m @@ -38,16 +38,16 @@ return self; } -- (void)pushContext:(NSDictionary *)font deltaX:(NSArray *)deltaX deltaY:(NSArray *)deltaY positionX:(NSString *)positionX positionY:(NSString *)positionY +- (void)pushContext:(NSDictionary *)font deltaX:(NSArray *)deltaX deltaY:(NSArray *)deltaY positionX:(NSArray *)positionX positionY:(NSArray *)positionY { CGPoint location = _currentLocation; if (positionX) { - location.x = [RNSVGPercentageConverter stringToFloat:positionX relative:_width offset:0]; + location.x = [RNSVGPercentageConverter stringToFloat:[positionX firstObject] relative:_width offset:0]; } if (positionY) { - location.y = [RNSVGPercentageConverter stringToFloat:positionY relative:_height offset:0]; + location.y = [RNSVGPercentageConverter stringToFloat:[positionY firstObject] relative:_height offset:0]; } [_locationContext addObject:[NSValue valueWithCGPoint:location]]; @@ -127,6 +127,8 @@ NSNumber *fontSize; NSString *fontWeight; NSString *fontStyle; + NSNumberFormatter *f = [[NSNumberFormatter alloc] init]; + f.numberStyle = NSNumberFormatterDecimalStyle; for (NSDictionary *font in [_fontContext reverseObjectEnumerator]) { if (!fontFamily) { @@ -134,7 +136,7 @@ } if (fontSize == nil) { - fontSize = font[@"fontSize"]; + fontSize = [f numberFromString:font[@"fontSize"]]; } if (!fontWeight) { diff --git a/ios/Text/RNSVGText.h b/ios/Text/RNSVGText.h index f6d843b1..b96215e8 100644 --- a/ios/Text/RNSVGText.h +++ b/ios/Text/RNSVGText.h @@ -14,10 +14,10 @@ @interface RNSVGText : RNSVGGroup @property (nonatomic, assign) RNSVGTextAnchor textAnchor; -@property (nonatomic, strong) NSArray *deltaX; -@property (nonatomic, strong) NSArray *deltaY; -@property (nonatomic, strong) NSString *positionX; -@property (nonatomic, strong) NSString *positionY; +@property (nonatomic, strong) NSArray *deltaX; +@property (nonatomic, strong) NSArray *deltaY; +@property (nonatomic, strong) NSArray *positionX; +@property (nonatomic, strong) NSArray *positionY; @property (nonatomic, strong) NSDictionary *font; - (RNSVGText *)getTextRoot; diff --git a/ios/Utils/RNSVGPathParser.m b/ios/Utils/RNSVGPathParser.m index 5479bc5b..719d8116 100644 --- a/ios/Utils/RNSVGPathParser.m +++ b/ios/Utils/RNSVGPathParser.m @@ -43,7 +43,7 @@ CGMutablePathRef path = CGPathCreateMutable(); NSArray* results = [_pathRegularExpression matchesInString:_d options:0 range:NSMakeRange(0, [_d length])]; _bezierCurves = [[NSMutableArray alloc] init]; - int count = [results count]; + unsigned long count = [results count]; if (count) { NSUInteger i = 0; diff --git a/ios/Utils/RNSVGPercentageConverter.m b/ios/Utils/RNSVGPercentageConverter.m index fe2cb778..62c9b3aa 100644 --- a/ios/Utils/RNSVGPercentageConverter.m +++ b/ios/Utils/RNSVGPercentageConverter.m @@ -19,7 +19,9 @@ static NSRegularExpression* percentageRegExp; + (CGFloat)stringToFloat:(NSString *)string relative:(CGFloat)relative offset:(CGFloat)offset { - if (![self isPercentage:string]) { + if (string == nil) { + return offset; + } else if (![self isPercentage:string]) { return [string floatValue] + offset; } else { return [self percentageToFloat:string relative:relative offset:offset]; diff --git a/ios/ViewManagers/RNSVGRenderableManager.m b/ios/ViewManagers/RNSVGRenderableManager.m index 4291886b..3cfa7bf0 100644 --- a/ios/ViewManagers/RNSVGRenderableManager.m +++ b/ios/ViewManagers/RNSVGRenderableManager.m @@ -25,10 +25,10 @@ RCT_EXPORT_VIEW_PROPERTY(fillOpacity, CGFloat) RCT_EXPORT_VIEW_PROPERTY(fillRule, RNSVGCGFCRule) RCT_EXPORT_VIEW_PROPERTY(stroke, RNSVGBrush) RCT_EXPORT_VIEW_PROPERTY(strokeOpacity, CGFloat) -RCT_EXPORT_VIEW_PROPERTY(strokeWidth, CGFloat) +RCT_EXPORT_VIEW_PROPERTY(strokeWidth, NSString) RCT_EXPORT_VIEW_PROPERTY(strokeLinecap, CGLineCap) RCT_EXPORT_VIEW_PROPERTY(strokeLinejoin, CGLineJoin) -RCT_EXPORT_VIEW_PROPERTY(strokeDasharray, RNSVGCGFloatArray) +RCT_EXPORT_VIEW_PROPERTY(strokeDasharray, NSArray) RCT_EXPORT_VIEW_PROPERTY(strokeDashoffset, CGFloat) RCT_EXPORT_VIEW_PROPERTY(strokeMiterlimit, CGFloat) RCT_EXPORT_VIEW_PROPERTY(propList, NSArray) diff --git a/ios/ViewManagers/RNSVGTextManager.m b/ios/ViewManagers/RNSVGTextManager.m index edbf7a21..45a8ea67 100644 --- a/ios/ViewManagers/RNSVGTextManager.m +++ b/ios/ViewManagers/RNSVGTextManager.m @@ -21,10 +21,10 @@ RCT_EXPORT_MODULE() } RCT_EXPORT_VIEW_PROPERTY(textAnchor, RNSVGTextAnchor) -RCT_EXPORT_VIEW_PROPERTY(deltaX, NSArray) -RCT_EXPORT_VIEW_PROPERTY(deltaY, NSArray) -RCT_EXPORT_VIEW_PROPERTY(positionX, NSString) -RCT_EXPORT_VIEW_PROPERTY(positionY, NSString) +RCT_EXPORT_VIEW_PROPERTY(deltaX, NSArray) +RCT_EXPORT_VIEW_PROPERTY(deltaY, NSArray) +RCT_EXPORT_VIEW_PROPERTY(positionX, NSArray) +RCT_EXPORT_VIEW_PROPERTY(positionY, NSArray) RCT_EXPORT_VIEW_PROPERTY(font, NSDictionary) @end