From 373fc09df9fe860c898bdcb789f03796a13b5f26 Mon Sep 17 00:00:00 2001 From: Alby Blyth Date: Tue, 19 Dec 2023 11:42:26 +1000 Subject: [PATCH] Swap skia svg package --- .../Adapters/ImageAdapter.cs | 24 +++++++------------ .../Adapters/SkiaSharpAdapter.cs | 2 +- .../HtmlRenderer.SkiaSharp.csproj | 2 +- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Source/HtmlRenderer.SkiaSharp/Adapters/ImageAdapter.cs b/Source/HtmlRenderer.SkiaSharp/Adapters/ImageAdapter.cs index 12e9348c8..1c7575ff7 100644 --- a/Source/HtmlRenderer.SkiaSharp/Adapters/ImageAdapter.cs +++ b/Source/HtmlRenderer.SkiaSharp/Adapters/ImageAdapter.cs @@ -12,8 +12,7 @@ using SkiaSharp; using TheArtOfDev.HtmlRenderer.Adapters; -using SKSvg = SkiaSharp.Extended.Svg.SKSvg; - +using Svg.Skia; namespace TheArtOfDev.HtmlRenderer.SkiaSharp.Adapters { @@ -25,8 +24,7 @@ internal sealed class ImageAdapter : RImage /// /// the underlying image. This may be either a bitmap (_image) or an svg (_svg). /// - private SKImage _image; - + private SKImage? _image; private readonly SKSvg? _svg; /// @@ -42,36 +40,31 @@ public ImageAdapter(SKSvg svg) _svg = svg; } - /// /// the underline SkiaSharp image. /// public SKImage Image { get - { - if (_image == null && _svg != null) + { + if (_image == null && _svg?.Picture != null) { //Render the image from the picture, as this is being used in a texture brush. - _image = SKImage.FromBitmap(new SKBitmap((int)_svg.CanvasSize.Width, (int)_svg.CanvasSize.Height)); + _image = SKImage.FromPicture(_svg.Picture, _svg.Picture.CullRect.Size.ToSizeI()); } + return _image; } } - /// - /// Picture if this represents a structured image, eg, SVG. - /// - public SKPicture Picture { get; set; } - public override double Width { - get { return _image?.Width ?? ((int?)_svg?.CanvasSize.Width) ?? 0; } + get { return _image?.Width ?? _svg?.Picture?.CullRect.Width ?? 0; } } public override double Height { - get { return _image?.Height ?? ((int?)_svg?.CanvasSize.Height) ?? 0; } + get { return _image?.Height ?? _svg?.Picture?.CullRect.Height ?? 0; } } public override void Dispose() @@ -82,7 +75,6 @@ public override void Dispose() internal void DrawImage(SKCanvas canvas, SKRect dstRect, SKRect? srcRect = null) { - if (_svg != null) { //TODO: support the overload that passes a source rect. Using Matrix overload perhaps?.. diff --git a/Source/HtmlRenderer.SkiaSharp/Adapters/SkiaSharpAdapter.cs b/Source/HtmlRenderer.SkiaSharp/Adapters/SkiaSharpAdapter.cs index a3a112030..d09188391 100644 --- a/Source/HtmlRenderer.SkiaSharp/Adapters/SkiaSharpAdapter.cs +++ b/Source/HtmlRenderer.SkiaSharp/Adapters/SkiaSharpAdapter.cs @@ -119,7 +119,7 @@ protected override RImage ImageFromStreamInt(Stream memoryStream) { //Maybe an SVG? In future, let's make the html renderer pass media type if it's available. memoryStream.Seek(0, SeekOrigin.Begin); - var skSvg = new global::SkiaSharp.Extended.Svg.SKSvg(); + var skSvg = new Svg.Skia.SKSvg(); skSvg.Load(memoryStream); return new ImageAdapter(skSvg); } diff --git a/Source/HtmlRenderer.SkiaSharp/HtmlRenderer.SkiaSharp.csproj b/Source/HtmlRenderer.SkiaSharp/HtmlRenderer.SkiaSharp.csproj index 56244e714..7967eb004 100644 --- a/Source/HtmlRenderer.SkiaSharp/HtmlRenderer.SkiaSharp.csproj +++ b/Source/HtmlRenderer.SkiaSharp/HtmlRenderer.SkiaSharp.csproj @@ -11,7 +11,7 @@ - +