Refactor renderers
MODIFY
WalletWasabi.Fluent/Screenshot/CanvasRenderer.cs
WalletWasabi.Fluent/Screenshot/CanvasRenderer.cs
@@ -6,20 +6,9 @@ namespace WalletWasabi.Fluent.Screenshot;
public static class CanvasRenderer
{
- public static void Render(Control target, SKCanvas canvas, double dpi = 96, bool useDeferredRenderer = false)
+ public static void Render(Control target, SKCanvas canvas, double dpi)
{
using var renderTarget = new CanvasRenderTarget(canvas, dpi);
- if (useDeferredRenderer)
- {
- using var renderer = new DeferredRenderer(target, renderTarget);
- renderer.Start();
- var renderLoopTask = renderer as IRenderLoopTask;
- renderLoopTask.Update(TimeSpan.Zero);
- renderLoopTask.Render();
- }
- else
- {
ImmediateRenderer.Render(target, renderTarget);
}
}
-}

MODIFY
WalletWasabi.Fluent/Screenshot/Capture.cs
WalletWasabi.Fluent/Screenshot/Capture.cs
@@ -65,33 +65,39 @@ public static class Capture
return;
}
- if (path.EndsWith("png", StringComparison.OrdinalIgnoreCase))
+ var extension = Path.GetExtension(path);
+ switch (extension.ToLower())
{
- PngRenderer.Render(control, size, path);
+ case ".png":
+ {
+ using var stream = File.Create(path);
+ PngRenderer.Render(control, size, stream);
+ break;
}
-
- if (path.EndsWith("svg", StringComparison.OrdinalIgnoreCase))
+ case ".svg":
{
using var stream = File.Create(path);
SvgRenderer.Render(control, size, stream);
+ break;
}
-
- if (path.EndsWith("pdf", StringComparison.OrdinalIgnoreCase))
+ case ".pdf":
{
using var stream = File.Create(path);
- PdfRenderer.Render(control, size, stream, 96);
+ PdfRenderer.Render(control, size, stream);
+ break;
}
-
- if (path.EndsWith("xps", StringComparison.OrdinalIgnoreCase))
+ case ".xps":
{
using var stream = File.Create(path);
- XpsRenderer.Render(control, size, stream, 96);
+ XpsRenderer.Render(control, size, stream);
+ break;
}
-
- if (path.EndsWith("skp", StringComparison.OrdinalIgnoreCase))
+ case ".skp":
{
using var stream = File.Create(path);
SkpRenderer.Render(control, size, stream);
+ break;
+ }
}
}
}

MODIFY
WalletWasabi.Fluent/Screenshot/Renderers/PdfRenderer.cs
WalletWasabi.Fluent/Screenshot/Renderers/PdfRenderer.cs
@@ -7,13 +7,13 @@ namespace WalletWasabi.Fluent.Screenshot.Renderers;
public static class PdfRenderer
{
- public static void Render(Control target, Size size, Stream stream, double dpi = 72, bool useDeferredRenderer = false)
+ public static void Render(Control target, Size size, Stream stream)
{
using var managedWStream = new SKManagedWStream(stream);
- using var document = SKDocument.CreatePdf(stream, (float)dpi);
+ using var document = SKDocument.CreatePdf(stream, 72f);
using var canvas = document.BeginPage((float)size.Width, (float)size.Height);
target.Measure(size);
target.Arrange(new Rect(size));
- CanvasRenderer.Render(target, canvas, dpi, useDeferredRenderer);
+ CanvasRenderer.Render(target, canvas, 72f);
}
}

MODIFY
WalletWasabi.Fluent/Screenshot/Renderers/PngRenderer.cs
WalletWasabi.Fluent/Screenshot/Renderers/PngRenderer.cs
+using System.IO;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media.Imaging;
@@ -6,14 +7,14 @@ namespace WalletWasabi.Fluent.Screenshot.Renderers;
public static class PngRenderer
{
- public static void Render(Control target, Size size, string path, double dpi = 96)
+ public static void Render(Control target, Size size, Stream stream)
{
var pixelSize = new PixelSize((int)size.Width, (int)size.Height);
- var dpiVector = new Vector(dpi, dpi);
+ var dpiVector = new Vector(96d, 96d);
using var bitmap = new RenderTargetBitmap(pixelSize, dpiVector);
target.Measure(size);
target.Arrange(new Rect(size));
bitmap.Render(target);
- bitmap.Save(path);
+ bitmap.Save(stream);
}
}

MODIFY
WalletWasabi.Fluent/Screenshot/Renderers/SkpRenderer.cs
WalletWasabi.Fluent/Screenshot/Renderers/SkpRenderer.cs
@@ -7,14 +7,14 @@ namespace WalletWasabi.Fluent.Screenshot.Renderers;
public static class SkpRenderer
{
- public static void Render(Control target, Size size, Stream stream, double dpi = 96, bool useDeferredRenderer = false)
+ public static void Render(Control target, Size size, Stream stream)
{
var bounds = SKRect.Create(new SKSize((float)size.Width, (float)size.Height));
using var pictureRecorder = new SKPictureRecorder();
using var canvas = pictureRecorder.BeginRecording(bounds);
target.Measure(size);
target.Arrange(new Rect(size));
- CanvasRenderer.Render(target, canvas, dpi, useDeferredRenderer);
+ CanvasRenderer.Render(target, canvas, 96d);
using var picture = pictureRecorder.EndRecording();
picture.Serialize(stream);
}

MODIFY
WalletWasabi.Fluent/Screenshot/Renderers/SvgRenderer.cs
WalletWasabi.Fluent/Screenshot/Renderers/SvgRenderer.cs
@@ -7,13 +7,13 @@ namespace WalletWasabi.Fluent.Screenshot.Renderers;
public static class SvgRenderer
{
- public static void Render(Control target, Size size, Stream stream, double dpi = 96, bool useDeferredRenderer = false)
+ public static void Render(Control target, Size size, Stream stream)
{
using var managedWStream = new SKManagedWStream(stream);
var bounds = SKRect.Create(new SKSize((float)size.Width, (float)size.Height));
using var canvas = SKSvgCanvas.Create(bounds, managedWStream);
target.Measure(size);
target.Arrange(new Rect(size));
- CanvasRenderer.Render(target, canvas, dpi, useDeferredRenderer);
+ CanvasRenderer.Render(target, canvas, 96d);
}
}

MODIFY
WalletWasabi.Fluent/Screenshot/Renderers/XpsRenderer.cs
WalletWasabi.Fluent/Screenshot/Renderers/XpsRenderer.cs
@@ -7,13 +7,13 @@ namespace WalletWasabi.Fluent.Screenshot.Renderers;
public static class XpsRenderer
{
- public static void Render(Control target, Size size, Stream stream, double dpi = 72, bool useDeferredRenderer = false)
+ public static void Render(Control target, Size size, Stream stream)
{
using var managedWStream = new SKManagedWStream(stream);
- using var document = SKDocument.CreateXps(stream, (float)dpi);
+ using var document = SKDocument.CreateXps(stream);
using var canvas = document.BeginPage((float)size.Width, (float)size.Height);
target.Measure(size);
target.Arrange(new Rect(size));
- CanvasRenderer.Render(target, canvas, dpi, useDeferredRenderer);
+ CanvasRenderer.Render(target, canvas, 72d);
}
}

Refactor renderers