Skip to content

Commit 9628830

Browse files
committed
feat: improve marker rendering
1 parent 2e3069d commit 9628830

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

android/src/main/java/com/horcrux/svg/MarkerView.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,15 @@ void renderMarker(Canvas canvas, Paint paint, float opacity, RNSVGMarkerPosition
132132

133133
Point origin = position.origin;
134134
Matrix transform = new Matrix();
135-
transform.setTranslate((float)origin.x, (float)origin.y);
135+
transform.setTranslate((float)origin.x * mScale, (float)origin.y * mScale);
136136

137137
double markerAngle = "auto".equals(mOrient) ? -1 : Double.parseDouble(mOrient);
138-
transform.postRotate((float)(markerAngle == -1 ? position.angle : markerAngle));
138+
float degrees = 180 + (float) (markerAngle == -1 ? position.angle : markerAngle);
139+
transform.preRotate(degrees);
139140

140141
boolean useStrokeWidth = "strokeWidth".equals(mMarkerUnits);
141142
if (useStrokeWidth) {
142-
transform.postScale(strokeWidth, strokeWidth);
143+
transform.preScale(strokeWidth, strokeWidth);
143144
}
144145

145146
canvas.concat(transform);

ios/Elements/RNSVGMarker.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ - (void)setMeetOrSlice:(RNSVGVBMOS)meetOrSlice
150150
_meetOrSlice = meetOrSlice;
151151
}
152152

153+
static CGFloat RNSVG_degToRad = (CGFloat)M_PI / 180;
154+
155+
double deg2rad(CGFloat deg) {
156+
return deg * RNSVG_degToRad;
157+
}
158+
153159
- (void)renderMarker:(CGContextRef)context rect:(CGRect)rect position:(RNSVGMarkerPosition*)position strokeWidth:(CGFloat)strokeWidth
154160
{
155161
CGContextSaveGState(context);
@@ -158,7 +164,9 @@ - (void)renderMarker:(CGContextRef)context rect:(CGRect)rect position:(RNSVGMark
158164
CGAffineTransform transform = CGAffineTransformMakeTranslation(origin.x, origin.y);
159165

160166
float markerAngle = [@"auto" isEqualToString:_orient] ? -1 : [_orient doubleValue];
161-
transform = CGAffineTransformRotate(transform, markerAngle == -1 ? [position angle] : markerAngle);
167+
float angle = 180 + (markerAngle == -1 ? [position angle] : markerAngle);
168+
float rad = deg2rad(angle);
169+
transform = CGAffineTransformRotate(transform, rad);
162170

163171
bool useStrokeWidth = [@"strokeWidth" isEqualToString:_markerUnits];
164172
if (useStrokeWidth) {

ios/Utils/RNSVGMarkerPosition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ typedef enum RNSVGMarkerType {
88
kEndMarker
99
} RNSVGMarkerType;
1010

11-
#define RNSVGNULLPOINT CGRectNull.origin
11+
#define RNSVGZEROPOINT CGRectZero.origin
1212

1313
@interface RNSVGMarkerPosition : NSObject
1414

ios/Utils/RNSVGMarkerPosition.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ - (instancetype) init
88
if (self)
99
{
1010
_type = kStartMarker;
11-
_origin = RNSVGNULLPOINT;
11+
_origin = RNSVGZEROPOINT;
1212
_angle = 0;
1313
}
1414
return self;
@@ -25,8 +25,8 @@ + (instancetype) markerPosition:(RNSVGMarkerType)type origin:(CGPoint)origin ang
2525
+ (NSArray<RNSVGMarkerPosition*>*) fromCGPath:(CGPathRef)path {
2626
positions_ = [[NSMutableArray alloc] init];
2727
element_index_ = 0;
28-
origin_ = RNSVGNULLPOINT;
29-
subpath_start_ = RNSVGNULLPOINT;
28+
origin_ = RNSVGZEROPOINT;
29+
subpath_start_ = RNSVGZEROPOINT;
3030
CGPathApply(path, (__bridge void *)positions_, UpdateFromPathElement);
3131
PathIsDone();
3232
return positions_;

0 commit comments

Comments
 (0)