Skip to content

Commit

Permalink
fix bbox as per spec
Browse files Browse the repository at this point in the history
  • Loading branch information
omeid authored and Omeid Matten committed Oct 8, 2024
1 parent 690cddd commit 4a9716c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public WritableMap getBBox(Double tag, ReadableMap options) {
return Arguments.createMap();
}

float scale = svg.mScale;
svg.initBounds();

RectF bounds = new RectF();
Expand All @@ -186,10 +185,10 @@ public WritableMap getBBox(Double tag, ReadableMap options) {
}

WritableMap result = Arguments.createMap();
result.putDouble("x", bounds.left / scale);
result.putDouble("y", bounds.top / scale);
result.putDouble("width", bounds.width() / scale);
result.putDouble("height", bounds.height() / scale);
result.putDouble("x", bounds.left);
result.putDouble("y", bounds.top);
result.putDouble("width", bounds.width());
result.putDouble("height", bounds.height());
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions apple/Elements/RNSVGForeignObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ - (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
[self setHitArea:path];
if (!CGRectEqualToRect(bounds, CGRectNull)) {
self.clientRect = bounds;
self.fillBounds = CGPathGetBoundingBox(path);
self.strokeBounds = CGPathGetBoundingBox(self.strokePath);
self.fillBounds = CGPathGetPathBoundingBox(path);
self.strokeBounds = CGPathGetPathBoundingBox(self.strokePath);
self.pathBounds = CGRectUnion(self.fillBounds, self.strokeBounds);

CGAffineTransform current = CGContextGetCTM(context);
Expand Down
4 changes: 2 additions & 2 deletions apple/Elements/RNSVGGroup.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ - (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
[self setHitArea:path];
if (!CGRectEqualToRect(bounds, CGRectNull)) {
self.clientRect = bounds;
self.fillBounds = CGPathGetBoundingBox(path);
self.strokeBounds = CGPathGetBoundingBox(self.strokePath);
self.fillBounds = CGPathGetPathBoundingBox(path);
self.strokeBounds = CGPathGetPathBoundingBox(self.strokePath);
self.pathBounds = CGRectUnion(self.fillBounds, self.strokeBounds);

CGAffineTransform current = CGContextGetCTM(context);
Expand Down
4 changes: 2 additions & 2 deletions apple/RNSVGRenderable.mm
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ - (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
self.path = CGPathRetain(path);
}
[self setHitArea:path];
self.fillBounds = CGPathGetBoundingBox(path);
self.strokeBounds = CGPathGetBoundingBox(self.strokePath);
self.fillBounds = CGPathGetPathBoundingBox(path);
self.strokeBounds = CGPathGetPathBoundingBox(self.strokePath);
self.pathBounds = CGRectUnion(self.fillBounds, self.strokeBounds);
}
const CGRect pathBounds = self.pathBounds;
Expand Down
6 changes: 3 additions & 3 deletions apple/RNSVGRenderableModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ @implementation RNSVGRenderableModule
BOOL clipped = [[options objectForKey:@"clipped"] boolValue];
[svg getPath:nil];

CGRect bounds = CGRectZero;
CGRect bounds = CGRectNull;
if (fill) {
bounds = CGRectUnion(bounds, svg.fillBounds);
}
Expand All @@ -150,12 +150,12 @@ @implementation RNSVGRenderableModule
}
if (clipped) {
CGPathRef clipPath = [svg getClipPath];
CGRect clipBounds = CGPathGetBoundingBox(clipPath);
CGRect clipBounds = CGPathGetPathBoundingBox(clipPath);
if (clipPath && !CGRectIsEmpty(clipBounds)) {
bounds = CGRectIntersection(bounds, clipBounds);
}
}

if (CGRectIsNull(bounds)) bounds = CGRectZero;
CGPoint origin = bounds.origin;
CGSize size = bounds.size;
return @{@"x" : @(origin.x), @"y" : @(origin.y), @"width" : @(size.width), @"height" : @(size.height)};
Expand Down

0 comments on commit 4a9716c

Please sign in to comment.