// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2020 OxyPlot contributors // // -------------------------------------------------------------------------------------------------------------------- namespace OxyPlot.SkiaSharp { using global::SkiaSharp; using System.IO; /// /// Provides functionality to export plots to scalable vector graphics using the SkiaSharp SVG canvas. /// public class SvgExporter : IExporter { /// /// Gets or sets the height (in user units) of the output area. /// public float Height { get; set; } /// /// Gets or sets the width (in user units) of the output area. /// public float Width { get; set; } /// public void Export(IPlotModel model, Stream stream) { using var skStream = new SKManagedWStream(stream); using var canvas = SKSvgCanvas.Create(new SKRect(0, 0, this.Width, this.Height), skStream); if (!model.Background.IsInvisible()) { canvas.Clear(model.Background.ToSKColor()); } // SVG export does not work with UseTextShaping=true. However SVG does text shaping by itself anyway, so we can just disable it using var context = new SkiaRenderContext { RenderTarget = RenderTarget.VectorGraphic, SkCanvas = canvas, UseTextShaping = false }; model.Update(true); model.Render(context, new OxyRect(0, 0, this.Width, this.Height)); } } }