Skip to content

Commit 2d92052

Browse files
authored
Merge pull request ArthurHub#3 from albyoo/features/net60
Swap Skia SVG NuGet Package
2 parents ca1c472 + 373fc09 commit 2d92052

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

Source/HtmlRenderer.SkiaSharp/Adapters/ImageAdapter.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
using SkiaSharp;
1414
using TheArtOfDev.HtmlRenderer.Adapters;
15-
using SKSvg = SkiaSharp.Extended.Svg.SKSvg;
16-
15+
using Svg.Skia;
1716

1817
namespace TheArtOfDev.HtmlRenderer.SkiaSharp.Adapters
1918
{
@@ -25,8 +24,7 @@ internal sealed class ImageAdapter : RImage
2524
/// <summary>
2625
/// the underlying image. This may be either a bitmap (_image) or an svg (_svg).
2726
/// </summary>
28-
private SKImage _image;
29-
27+
private SKImage? _image;
3028
private readonly SKSvg? _svg;
3129

3230
/// <summary>
@@ -42,36 +40,31 @@ public ImageAdapter(SKSvg svg)
4240
_svg = svg;
4341
}
4442

45-
4643
/// <summary>
4744
/// the underline SkiaSharp image.
4845
/// </summary>
4946
public SKImage Image
5047
{
5148
get
52-
{
53-
if (_image == null && _svg != null)
49+
{
50+
if (_image == null && _svg?.Picture != null)
5451
{
5552
//Render the image from the picture, as this is being used in a texture brush.
56-
_image = SKImage.FromBitmap(new SKBitmap((int)_svg.CanvasSize.Width, (int)_svg.CanvasSize.Height));
53+
_image = SKImage.FromPicture(_svg.Picture, _svg.Picture.CullRect.Size.ToSizeI());
5754
}
55+
5856
return _image;
5957
}
6058
}
6159

62-
/// <summary>
63-
/// Picture if this represents a structured image, eg, SVG.
64-
/// </summary>
65-
public SKPicture Picture { get; set; }
66-
6760
public override double Width
6861
{
69-
get { return _image?.Width ?? ((int?)_svg?.CanvasSize.Width) ?? 0; }
62+
get { return _image?.Width ?? _svg?.Picture?.CullRect.Width ?? 0; }
7063
}
7164

7265
public override double Height
7366
{
74-
get { return _image?.Height ?? ((int?)_svg?.CanvasSize.Height) ?? 0; }
67+
get { return _image?.Height ?? _svg?.Picture?.CullRect.Height ?? 0; }
7568
}
7669

7770
public override void Dispose()
@@ -82,7 +75,6 @@ public override void Dispose()
8275

8376
internal void DrawImage(SKCanvas canvas, SKRect dstRect, SKRect? srcRect = null)
8477
{
85-
8678
if (_svg != null)
8779
{
8880
//TODO: support the overload that passes a source rect. Using Matrix overload perhaps?..

Source/HtmlRenderer.SkiaSharp/Adapters/SkiaSharpAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected override RImage ImageFromStreamInt(Stream memoryStream)
119119
{
120120
//Maybe an SVG? In future, let's make the html renderer pass media type if it's available.
121121
memoryStream.Seek(0, SeekOrigin.Begin);
122-
var skSvg = new global::SkiaSharp.Extended.Svg.SKSvg();
122+
var skSvg = new Svg.Skia.SKSvg();
123123
skSvg.Load(memoryStream);
124124
return new ImageAdapter(skSvg);
125125
}

Source/HtmlRenderer.SkiaSharp/HtmlRenderer.SkiaSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="SkiaSharp" Version="2.88.6" />
14-
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
14+
<PackageReference Include="Svg.Skia" Version="1.0.0.9" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

0 commit comments

Comments
 (0)