diff --git a/android/src/main/java/com/horcrux/svg/MarkerView.java b/android/src/main/java/com/horcrux/svg/MarkerView.java index d988424a9..dc130c241 100644 --- a/android/src/main/java/com/horcrux/svg/MarkerView.java +++ b/android/src/main/java/com/horcrux/svg/MarkerView.java @@ -132,14 +132,15 @@ void renderMarker(Canvas canvas, Paint paint, float opacity, RNSVGMarkerPosition Point origin = position.origin; Matrix transform = new Matrix(); - transform.setTranslate((float)origin.x, (float)origin.y); + transform.setTranslate((float)origin.x * mScale, (float)origin.y * mScale); double markerAngle = "auto".equals(mOrient) ? -1 : Double.parseDouble(mOrient); - transform.postRotate((float)(markerAngle == -1 ? position.angle : markerAngle)); + float degrees = 180 + (float) (markerAngle == -1 ? position.angle : markerAngle); + transform.preRotate(degrees); boolean useStrokeWidth = "strokeWidth".equals(mMarkerUnits); if (useStrokeWidth) { - transform.postScale(strokeWidth, strokeWidth); + transform.preScale(strokeWidth, strokeWidth); } canvas.concat(transform); diff --git a/ios/Elements/RNSVGMarker.m b/ios/Elements/RNSVGMarker.m index 57192e1f1..c9381aac7 100644 --- a/ios/Elements/RNSVGMarker.m +++ b/ios/Elements/RNSVGMarker.m @@ -150,6 +150,12 @@ - (void)setMeetOrSlice:(RNSVGVBMOS)meetOrSlice _meetOrSlice = meetOrSlice; } +static CGFloat RNSVG_degToRad = (CGFloat)M_PI / 180; + +double deg2rad(CGFloat deg) { + return deg * RNSVG_degToRad; +} + - (void)renderMarker:(CGContextRef)context rect:(CGRect)rect position:(RNSVGMarkerPosition*)position strokeWidth:(CGFloat)strokeWidth { CGContextSaveGState(context); @@ -158,7 +164,9 @@ - (void)renderMarker:(CGContextRef)context rect:(CGRect)rect position:(RNSVGMark CGAffineTransform transform = CGAffineTransformMakeTranslation(origin.x, origin.y); float markerAngle = [@"auto" isEqualToString:_orient] ? -1 : [_orient doubleValue]; - transform = CGAffineTransformRotate(transform, markerAngle == -1 ? [position angle] : markerAngle); + float angle = 180 + (markerAngle == -1 ? [position angle] : markerAngle); + float rad = deg2rad(angle); + transform = CGAffineTransformRotate(transform, rad); bool useStrokeWidth = [@"strokeWidth" isEqualToString:_markerUnits]; if (useStrokeWidth) { diff --git a/ios/Utils/RNSVGMarkerPosition.h b/ios/Utils/RNSVGMarkerPosition.h index 987870069..bf7b3c0f6 100644 --- a/ios/Utils/RNSVGMarkerPosition.h +++ b/ios/Utils/RNSVGMarkerPosition.h @@ -8,7 +8,7 @@ typedef enum RNSVGMarkerType { kEndMarker } RNSVGMarkerType; -#define RNSVGNULLPOINT CGRectNull.origin +#define RNSVGZEROPOINT CGRectZero.origin @interface RNSVGMarkerPosition : NSObject diff --git a/ios/Utils/RNSVGMarkerPosition.m b/ios/Utils/RNSVGMarkerPosition.m index b8e1aebef..86ab028de 100644 --- a/ios/Utils/RNSVGMarkerPosition.m +++ b/ios/Utils/RNSVGMarkerPosition.m @@ -8,7 +8,7 @@ - (instancetype) init if (self) { _type = kStartMarker; - _origin = RNSVGNULLPOINT; + _origin = RNSVGZEROPOINT; _angle = 0; } return self; @@ -25,8 +25,8 @@ + (instancetype) markerPosition:(RNSVGMarkerType)type origin:(CGPoint)origin ang + (NSArray*) fromCGPath:(CGPathRef)path { positions_ = [[NSMutableArray alloc] init]; element_index_ = 0; - origin_ = RNSVGNULLPOINT; - subpath_start_ = RNSVGNULLPOINT; + origin_ = RNSVGZEROPOINT; + subpath_start_ = RNSVGZEROPOINT; CGPathApply(path, (__bridge void *)positions_, UpdateFromPathElement); PathIsDone(); return positions_;