/// <summary> /// Exports the specified model to a file. /// </summary> /// <param name="model">The model.</param> /// <param name="fileName">Name of the file.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="textMeasurer">The text measurer.</param> public static void Export(PlotModel model, string fileName, double width, double height, IRenderContext textMeasurer = null) { using (var svgrc = new SvgRenderContext(fileName, width, height, textMeasurer)) { model.Update(); model.Render(svgrc); } }
/// <summary> /// Exports the specified model to a stream. /// </summary> /// <param name="model">The model.</param> /// <param name="stream">The output stream.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="textMeasurer">The text measurer.</param> public static void Export(PlotModel model, Stream stream, double width, double height, IRenderContext textMeasurer = null) { using (var svgrc = new SvgRenderContext(stream, width, height, true, textMeasurer)) { model.Update(); model.Render(svgrc); } }
/// <summary> /// Exports the specified model to a stream. /// </summary> /// <param name="model">The model.</param> /// <param name="stream">The output stream.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <param name="textMeasurer">The text measurer.</param> public static void Export(PlotModel model, Stream stream, double width, double height, bool isDocument, IRenderContext textMeasurer) { using (var rc = new SvgRenderContext(stream, width, height, true, textMeasurer, model.Background)) { model.Update(); model.Render(rc, width, height); rc.Complete(); rc.Flush(); } }
/// <summary> /// Exports the specified model to a stream. /// </summary> /// <param name="model">The model.</param> /// <param name="stream">The output stream.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <param name="textMeasurer">The text measurer.</param> /// <param name="useVerticalTextAlignmentWorkaround">Whether to use the workaround for vertical text alignment</param> public static void Export(IPlotModel model, Stream stream, double width, double height, bool isDocument, IRenderContext textMeasurer = null, bool useVerticalTextAlignmentWorkaround = false) { if (textMeasurer == null) { textMeasurer = new PdfRenderContext(width, height, model.Background); } using (var rc = new SvgRenderContext(stream, width, height, isDocument, textMeasurer, model.Background, useVerticalTextAlignmentWorkaround)) { model.Update(true); model.Render(rc, width, height); rc.Complete(); rc.Flush(); } }
/// <summary> /// Exports to string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="textMeasurer">The text measurer.</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <returns> /// The plot as a svg string. /// </returns> public static string ExportToString(PlotModel model, double width, double height, bool isDocument = false, IRenderContext textMeasurer = null) { string svg; using (var ms = new MemoryStream()) { var svgrc = new SvgRenderContext(ms, width, height, isDocument, textMeasurer); model.Update(); model.Render(svgrc); svgrc.Complete(); svgrc.Flush(); ms.Flush(); ms.Position = 0; var sr = new StreamReader(ms); svg = sr.ReadToEnd(); } return(svg); }
static void CreateSvg(int size, IconRenderer iconRenderer, string fileName) { using (var bm = new Bitmap(size, size)) { using (var grx = new GraphicsRenderContext(Graphics.FromImage(bm))) { using (var s = File.Create(fileName)) { using (var rc = new SvgRenderContext(s, size, size, true, grx, OxyColors.Transparent)) { iconRenderer.Render(rc, size); } } } } }
/// <summary> /// Exports to string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="textMeasurer">The text measurer.</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <returns> /// The plot as a svg string. /// </returns> public static string ExportToString(PlotModel model, double width, double height, bool isDocument = false, IRenderContext textMeasurer = null) { string svg; using (var ms = new MemoryStream()) { var svgrc = new SvgRenderContext(ms, width, height, isDocument, textMeasurer); model.Update(); model.Render(svgrc); svgrc.Complete(); svgrc.Flush(); ms.Flush(); ms.Position = 0; var sr = new StreamReader(ms); svg = sr.ReadToEnd(); } return svg; }