A quick fix for 5.1.1

This commit is contained in:
Horcrux
2017-01-16 14:39:41 +08:00
parent a981585b6b
commit da9b9f0a20
+33 -33
View File
@@ -10,7 +10,7 @@
#import <React/RCTLog.h> #import <React/RCTLog.h>
#import "math.h" #import "math.h"
@implementation RNSVGPathParser : NSObject @implementation RNSVGPathParser : NSObject
{ {
NSString* _d; NSString* _d;
NSString* _originD; NSString* _originD;
@@ -44,7 +44,7 @@
NSArray<NSTextCheckingResult *>* results = [_pathRegularExpression matchesInString:_d options:0 range:NSMakeRange(0, [_d length])]; NSArray<NSTextCheckingResult *>* results = [_pathRegularExpression matchesInString:_d options:0 range:NSMakeRange(0, [_d length])];
_bezierCurves = [[NSMutableArray alloc] init]; _bezierCurves = [[NSMutableArray alloc] init];
int count = [results count]; int count = [results count];
if (count) { if (count) {
NSUInteger i = 0; NSUInteger i = 0;
#define NEXT_VALUE [self getNextValue:results[i++]] #define NEXT_VALUE [self getNextValue:results[i++]]
@@ -52,7 +52,7 @@
#define NEXT_BOOL [self bool:NEXT_VALUE] #define NEXT_BOOL [self bool:NEXT_VALUE]
NSString* lastCommand; NSString* lastCommand;
NSString* command = NEXT_VALUE; NSString* command = NEXT_VALUE;
@try { @try {
while (command) { while (command) {
if ([command isEqualToString:@"m"]) { // moveTo command if ([command isEqualToString:@"m"]) { // moveTo command
@@ -100,14 +100,14 @@
i--; i--;
continue; continue;
} }
lastCommand = command; lastCommand = command;
if ([lastCommand isEqualToString:@"m"]) { if ([lastCommand isEqualToString:@"m"]) {
lastCommand = @"l"; lastCommand = @"l";
} else if ([lastCommand isEqualToString:@"M"]) { } else if ([lastCommand isEqualToString:@"M"]) {
lastCommand = @"L"; lastCommand = @"L";
} }
command = i < count ? NEXT_VALUE : nil; command = i < count ? NEXT_VALUE : nil;
} }
} @catch (NSException *exception) { } @catch (NSException *exception) {
@@ -117,7 +117,7 @@
} }
} }
return (CGPathRef)CFAutorelease(path); return (CGPathRef)CFAutorelease(path);
} }
@@ -126,7 +126,7 @@
if (!_bezierCurves) { if (!_bezierCurves) {
CGPathRelease([self getPath]); CGPathRelease([self getPath]);
} }
return [_bezierCurves copy]; return [_bezierCurves copy];
} }
@@ -158,7 +158,7 @@
_pivotX = _penX = x; _pivotX = _penX = x;
_pivotY = _penY = y; _pivotY = _penY = y;
CGPathMoveToPoint(path, nil, x, y); CGPathMoveToPoint(path, nil, x, y);
_lastStartPoint = [NSValue valueWithCGPoint: CGPointMake(x, y)]; _lastStartPoint = [NSValue valueWithCGPoint: CGPointMake(x, y)];
[_bezierCurves addObject: @[_lastStartPoint]]; [_bezierCurves addObject: @[_lastStartPoint]];
} }
@@ -170,12 +170,12 @@
- (void)lineTo:(CGPathRef)path x:(float)x y:(float)y{ - (void)lineTo:(CGPathRef)path x:(float)x y:(float)y{
NSValue * source = [NSValue valueWithCGPoint:CGPointMake(_pivotX, _pivotY)]; NSValue * source = [NSValue valueWithCGPoint:CGPointMake(_pivotX, _pivotY)];
[self setPenDown]; [self setPenDown];
_pivotX = _penX = x; _pivotX = _penX = x;
_pivotY = _penY = y; _pivotY = _penY = y;
CGPathAddLineToPoint(path, nil, x, y); CGPathAddLineToPoint(path, nil, x, y);
NSValue * destination = [NSValue valueWithCGPoint:CGPointMake(x, y)]; NSValue * destination = [NSValue valueWithCGPoint:CGPointMake(x, y)];
[_bezierCurves addObject: @[destination, destination, destination]]; [_bezierCurves addObject: @[destination, destination, destination]];
} }
@@ -192,8 +192,8 @@
- (void)curveTo:(CGPathRef)path c1x:(float)c1x c1y:(float)c1y c2x:(float)c2x c2y:(float)c2y ex:(float)ex ey:(float)ey - (void)curveTo:(CGPathRef)path c1x:(float)c1x c1y:(float)c1y c2x:(float)c2x c2y:(float)c2y ex:(float)ex ey:(float)ey
{ {
_pivotX = ex; _pivotX = c2x;
_pivotY = ey; _pivotY = c2y;
[self curveToPoint:path c1x:(float)c1x c1y:(float)c1y c2x:(float)c2x c2y:(float)c2y ex:(float)ex ey:(float)ey]; [self curveToPoint:path c1x:(float)c1x c1y:(float)c1y c2x:(float)c2x c2y:(float)c2y ex:(float)ex ey:(float)ey];
} }
@@ -203,7 +203,7 @@
_penX = ex; _penX = ex;
_penY = ey; _penY = ey;
CGPathAddCurveToPoint(path, nil, c1x, c1y, c2x, c2y, ex, ey); CGPathAddCurveToPoint(path, nil, c1x, c1y, c2x, c2y, ex, ey);
[_bezierCurves addObject: @[ [_bezierCurves addObject: @[
[NSValue valueWithCGPoint:CGPointMake(c1x, c1y)], [NSValue valueWithCGPoint:CGPointMake(c1x, c1y)],
[NSValue valueWithCGPoint:CGPointMake(c2x, c2y)], [NSValue valueWithCGPoint:CGPointMake(c2x, c2y)],
@@ -268,16 +268,16 @@
{ {
float tX = _penX; float tX = _penX;
float tY = _penY; float tY = _penY;
ry = fabsf(ry == 0 ? (rx == 0 ? (y - tY) : rx) : ry); ry = fabsf(ry == 0 ? (rx == 0 ? (y - tY) : rx) : ry);
rx = fabsf(rx == 0 ? (x - tX) : rx); rx = fabsf(rx == 0 ? (x - tX) : rx);
if (rx == 0 || ry == 0 || (x == tX && y == tY)) { if (rx == 0 || ry == 0 || (x == tX && y == tY)) {
[self lineTo:path x:x y:y]; [self lineTo:path x:x y:y];
return; return;
} }
float rad = rotation * M_PI / 180; float rad = rotation * M_PI / 180;
float cosed = cosf(rad); float cosed = cosf(rad);
float sined = sinf(rad); float sined = sinf(rad);
@@ -290,7 +290,7 @@
float rycx = ry * ry * cx * cx; float rycx = ry * ry * cx * cx;
float rxcy = rx * rx * cy * cy; float rxcy = rx * rx * cy * cy;
float a = rxry - rxcy - rycx; float a = rxry - rxcy - rycx;
if (a < 0){ if (a < 0){
a = sqrtf(1 - a / rxry); a = sqrtf(1 - a / rxry);
rx *= a; rx *= a;
@@ -299,7 +299,7 @@
cy = y / 2; cy = y / 2;
} else { } else {
a = sqrtf(a / (rxcy + rycx)); a = sqrtf(a / (rxcy + rycx));
if (outer == clockwise) { if (outer == clockwise) {
a = -a; a = -a;
} }
@@ -308,27 +308,27 @@
cx = cosed * cxd - sined * cyd + x / 2; cx = cosed * cxd - sined * cyd + x / 2;
cy = sined * cxd + cosed * cyd + y / 2; cy = sined * cxd + cosed * cyd + y / 2;
} }
// Rotation + Scale Transform // Rotation + Scale Transform
float xx = cosed / rx; float xx = cosed / rx;
float yx = sined / rx; float yx = sined / rx;
float xy = -sined / ry; float xy = -sined / ry;
float yy = cosed / ry; float yy = cosed / ry;
// Start and End Angle // Start and End Angle
float sa = atan2f(xy * -cx + yy * -cy, xx * -cx + yx * -cy); float sa = atan2f(xy * -cx + yy * -cy, xx * -cx + yx * -cy);
float ea = atan2f(xy * (x - cx) + yy * (y - cy), xx * (x - cx) + yx * (y - cy)); float ea = atan2f(xy * (x - cx) + yy * (y - cy), xx * (x - cx) + yx * (y - cy));
cx += tX; cx += tX;
cy += tY; cy += tY;
x += tX; x += tX;
y += tY; y += tY;
[self setPenDown]; [self setPenDown];
_penX = _pivotX = x; _penX = _pivotX = x;
_penY = _pivotY = y; _penY = _pivotY = y;
[self arcToBezier:path cx:cx cy:cy rx:rx ry:ry sa:sa ea:ea clockwise:clockwise rad:rad]; [self arcToBezier:path cx:cx cy:cy rx:rx ry:ry sa:sa ea:ea clockwise:clockwise rad:rad];
} }
@@ -341,7 +341,7 @@
float yx = -sined * ry; float yx = -sined * ry;
float xy = sined * rx; float xy = sined * rx;
float yy = cosed * ry; float yy = cosed * ry;
// Bezier Curve Approximation // Bezier Curve Approximation
float arc = ea - sa; float arc = ea - sa;
if (arc < 0 && clockwise) { if (arc < 0 && clockwise) {
@@ -349,26 +349,26 @@
} else if (arc > 0 && !clockwise) { } else if (arc > 0 && !clockwise) {
arc -= M_PI * 2; arc -= M_PI * 2;
} }
int n = ceilf(fabsf(arc / (M_PI / 2))); int n = ceilf(fabsf(arc / (M_PI / 2)));
float step = arc / n; float step = arc / n;
float k = (4.0f / 3.0f) * tanf(step / 4); float k = (4.0f / 3.0f) * tanf(step / 4);
float x = cosf(sa); float x = cosf(sa);
float y = sinf(sa); float y = sinf(sa);
for (int i = 0; i < n; i++){ for (int i = 0; i < n; i++){
float cp1x = x - k * y; float cp1x = x - k * y;
float cp1y = y + k * x; float cp1y = y + k * x;
sa += step; sa += step;
x = cosf(sa); x = cosf(sa);
y = sinf(sa); y = sinf(sa);
float cp2x = x + k * y; float cp2x = x + k * y;
float cp2y = y - k * x; float cp2y = y - k * x;
CGPathAddCurveToPoint(path, CGPathAddCurveToPoint(path,
nil, nil,
cx + xx * cp1x + yx * cp1y, cx + xx * cp1x + yx * cp1y,