Skip to content

Instantly share code, notes, and snippets.

@VisualMelon
Last active September 20, 2017 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VisualMelon/ab34de2faa64b9b46e686cf7bedcfc30 to your computer and use it in GitHub Desktop.
Save VisualMelon/ab34de2faa64b9b46e686cf7bedcfc30 to your computer and use it in GitHub Desktop.
SVG Text Rendering Testing
var model = new PlotModel { Title = "SVG Text Rendering" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A",
    TextPosition = new DataPoint(10, 80),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA",
    TextPosition = new DataPoint(20, 80),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA",
    TextPosition = new DataPoint(30, 80),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA\r\nA",
    TextPosition = new DataPoint(40, 80),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA\r\nA\r\nA",
    TextPosition = new DataPoint(50, 80),
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A",
    TextPosition = new DataPoint(10, 70),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA",
    TextPosition = new DataPoint(20, 70),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA",
    TextPosition = new DataPoint(30, 70),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA\r\nA",
    TextPosition = new DataPoint(40, 70),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "A\r\nA\r\nA\r\nA\r\nA",
    TextPosition = new DataPoint(50, 70),
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nHello2\r\nHello3\r\nHello4",
    TextPosition = new DataPoint(80, 20),
    TextVerticalAlignment = VerticalAlignment.Middle,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "H\r\nHe\r\nHel\r\nHell\r\nHello",
    TextPosition = new DataPoint(80, 40),
    TextVerticalAlignment = VerticalAlignment.Middle,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nBottom\r\nHello3",
    TextPosition = new DataPoint(20, 40),
    TextRotation = -45,
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nMiddle\r\nHello3",
    TextPosition = new DataPoint(40, 40),
    TextRotation = -45,
    TextVerticalAlignment = VerticalAlignment.Middle,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nTop\r\nHello3",
    TextPosition = new DataPoint(60, 40),
    TextRotation = -45,
    TextVerticalAlignment = VerticalAlignment.Top,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nBottom\r\nHello3",
    TextPosition = new DataPoint(20, 20),
    TextRotation = 45,
    TextVerticalAlignment = VerticalAlignment.Bottom,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nMiddle\r\nHello3",
    TextPosition = new DataPoint(40, 20),
    TextRotation = 45,
    TextVerticalAlignment = VerticalAlignment.Middle,
});
model.Annotations.Add(new OxyPlot.Annotations.TextAnnotation()
{
    Text = "Hello1\r\nTop\r\nHello3",
    TextPosition = new DataPoint(60, 20),
    TextRotation = 45,
    TextVerticalAlignment = VerticalAlignment.Top,
});
OxyPlot.WindowsForms.PlotView plotView = new OxyPlot.WindowsForms.PlotView();
plotView.Model = model;
this.Controls.Add(plotView);
plotView.Invalidate();
plotView.Dock = DockStyle.Fill;
this.Refresh();
SvgExporter svgExporter = new SvgExporter();
using (var fs = System.IO.File.Open("test2.svg", System.IO.FileMode.Create))
{
    svgExporter.Export(model, fs);
}
svgExporter = new SvgExporter();
svgExporter.UseVerticalTextAlignmentWorkaround = true;
using (var fs = System.IO.File.Open("test3.svg", System.IO.FileMode.Create))
{
    svgExporter.Export(model, fs);
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment