Skip to content

Commit 2da811d

Browse files
committed
Update SKSvgRenderer.cs
1 parent 095f6f4 commit 2da811d

File tree

1 file changed

+15
-61
lines changed

1 file changed

+15
-61
lines changed

src/Svg.Skia/SKSvgRenderer.cs

+15-61
Original file line numberDiff line numberDiff line change
@@ -1140,16 +1140,13 @@ public void DrawCircle(SvgCircle svgCircle, bool ignoreDisplay)
11401140
return;
11411141
}
11421142

1143-
float cx = svgCircle.CenterX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgCircle);
1144-
float cy = svgCircle.CenterY.ToDeviceValue(null, UnitRenderingType.Vertical, svgCircle);
1145-
float radius = svgCircle.Radius.ToDeviceValue(null, UnitRenderingType.Other, svgCircle);
1146-
1147-
if (radius <= 0f)
1143+
var skPath = SkiaUtil.ToSKPath(svgCircle, svgCircle.FillRule, _disposable);
1144+
if (skPath == null || skPath.IsEmpty)
11481145
{
11491146
return;
11501147
}
11511148

1152-
var skBounds = SKRect.Create(cx - radius, cy - radius, radius + radius, radius + radius);
1149+
var skBounds = skPath.Bounds;
11531150

11541151
_skCanvas.Save();
11551152

@@ -1164,13 +1161,13 @@ public void DrawCircle(SvgCircle svgCircle, bool ignoreDisplay)
11641161
if (SkiaUtil.IsValidFill(svgCircle))
11651162
{
11661163
var skPaintFill = SkiaUtil.GetFillSKPaint(svgCircle, _skSize, skBounds, _disposable);
1167-
_skCanvas.DrawCircle(cx, cy, radius, skPaintFill);
1164+
_skCanvas.DrawPath(skPath, skPaintFill);
11681165
}
11691166

11701167
if (SkiaUtil.IsValidStroke(svgCircle))
11711168
{
11721169
var skPaintStroke = SkiaUtil.GetStrokeSKPaint(svgCircle, _skSize, skBounds, _disposable);
1173-
_skCanvas.DrawCircle(cx, cy, radius, skPaintStroke);
1170+
_skCanvas.DrawPath(skPath, skPaintStroke);
11741171
}
11751172

11761173
if (skPaintFilter != null)
@@ -1193,17 +1190,13 @@ public void DrawEllipse(SvgEllipse svgEllipse, bool ignoreDisplay)
11931190
return;
11941191
}
11951192

1196-
float cx = svgEllipse.CenterX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgEllipse);
1197-
float cy = svgEllipse.CenterY.ToDeviceValue(null, UnitRenderingType.Vertical, svgEllipse);
1198-
float rx = svgEllipse.RadiusX.ToDeviceValue(null, UnitRenderingType.Other, svgEllipse);
1199-
float ry = svgEllipse.RadiusY.ToDeviceValue(null, UnitRenderingType.Other, svgEllipse);
1200-
1201-
if (rx <= 0f || ry <= 0f)
1193+
var skPath = SkiaUtil.ToSKPath(svgEllipse, svgEllipse.FillRule, _disposable);
1194+
if (skPath == null || skPath.IsEmpty)
12021195
{
12031196
return;
12041197
}
12051198

1206-
var skBounds = SKRect.Create(cx - rx, cy - ry, rx + rx, ry + ry);
1199+
var skBounds = skPath.Bounds;
12071200

12081201
_skCanvas.Save();
12091202

@@ -1218,13 +1211,13 @@ public void DrawEllipse(SvgEllipse svgEllipse, bool ignoreDisplay)
12181211
if (SkiaUtil.IsValidFill(svgEllipse))
12191212
{
12201213
var skPaintFill = SkiaUtil.GetFillSKPaint(svgEllipse, _skSize, skBounds, _disposable);
1221-
_skCanvas.DrawOval(cx, cy, rx, ry, skPaintFill);
1214+
_skCanvas.DrawPath(skPath, skPaintFill);
12221215
}
12231216

12241217
if (SkiaUtil.IsValidStroke(svgEllipse))
12251218
{
12261219
var skPaintStroke = SkiaUtil.GetStrokeSKPaint(svgEllipse, _skSize, skBounds, _disposable);
1227-
_skCanvas.DrawOval(cx, cy, rx, ry, skPaintStroke);
1220+
_skCanvas.DrawPath(skPath, skPaintStroke);
12281221
}
12291222

12301223
if (skPaintFilter != null)
@@ -1247,38 +1240,13 @@ public void DrawRectangle(SvgRectangle svgRectangle, bool ignoreDisplay)
12471240
return;
12481241
}
12491242

1250-
float x = svgRectangle.X.ToDeviceValue(null, UnitRenderingType.Horizontal, svgRectangle);
1251-
float y = svgRectangle.Y.ToDeviceValue(null, UnitRenderingType.Vertical, svgRectangle);
1252-
float width = svgRectangle.Width.ToDeviceValue(null, UnitRenderingType.Horizontal, svgRectangle);
1253-
float height = svgRectangle.Height.ToDeviceValue(null, UnitRenderingType.Vertical, svgRectangle);
1254-
float rx = svgRectangle.CornerRadiusX.ToDeviceValue(null, UnitRenderingType.Horizontal, svgRectangle);
1255-
float ry = svgRectangle.CornerRadiusY.ToDeviceValue(null, UnitRenderingType.Vertical, svgRectangle);
1256-
1257-
if (width <= 0f || height <= 0f || rx < 0f || ry < 0f)
1243+
var skPath = SkiaUtil.ToSKPath(svgRectangle, svgRectangle.FillRule, _disposable);
1244+
if (skPath == null || skPath.IsEmpty)
12581245
{
12591246
return;
12601247
}
12611248

1262-
if (rx > 0f)
1263-
{
1264-
float halfWidth = width / 2f;
1265-
if (rx > halfWidth)
1266-
{
1267-
rx = halfWidth;
1268-
}
1269-
}
1270-
1271-
if (ry > 0f)
1272-
{
1273-
float halfHeight = height / 2f;
1274-
if (ry > halfHeight)
1275-
{
1276-
ry = halfHeight;
1277-
}
1278-
}
1279-
1280-
bool isRound = rx > 0f && ry > 0f;
1281-
var skBounds = SKRect.Create(x, y, width, height);
1249+
var skBounds = skPath.Bounds;
12821250

12831251
_skCanvas.Save();
12841252

@@ -1293,27 +1261,13 @@ public void DrawRectangle(SvgRectangle svgRectangle, bool ignoreDisplay)
12931261
if (SkiaUtil.IsValidFill(svgRectangle))
12941262
{
12951263
var skPaintFill = SkiaUtil.GetFillSKPaint(svgRectangle, _skSize, skBounds, _disposable);
1296-
if (isRound)
1297-
{
1298-
_skCanvas.DrawRoundRect(x, y, width, height, rx, ry, skPaintFill);
1299-
}
1300-
else
1301-
{
1302-
_skCanvas.DrawRect(x, y, width, height, skPaintFill);
1303-
}
1264+
_skCanvas.DrawPath(skPath, skPaintFill);
13041265
}
13051266

13061267
if (SkiaUtil.IsValidStroke(svgRectangle))
13071268
{
13081269
var skPaintStroke = SkiaUtil.GetStrokeSKPaint(svgRectangle, _skSize, skBounds, _disposable);
1309-
if (isRound)
1310-
{
1311-
_skCanvas.DrawRoundRect(skBounds, rx, ry, skPaintStroke);
1312-
}
1313-
else
1314-
{
1315-
_skCanvas.DrawRect(skBounds, skPaintStroke);
1316-
}
1270+
_skCanvas.DrawPath(skPath, skPaintStroke);
13171271
}
13181272

13191273
if (skPaintFilter != null)

0 commit comments

Comments
 (0)