Kaven Kaven - 3 months ago 26
C# Question

vvvv/SVG not rendering text

I'm trying to use vvvv/SVG library (https://github.com/vvvv/SVG , current version) in my C# project. I've managed to do some simple drawing, however ended on strange behaviour when rendering text.

Following code adds text element to SvgDocument, but no text is rendered in bitmap.

this.SvgDoc = new SvgDocument();
this.SvgDoc.Width = new SvgUnit(400);
this.SvgDoc.Height = new SvgUnit(400);

SvgText txt = new SvgText("TEST");
txt.X.Add(new SvgUnit(100));
txt.Y.Add(new SvgUnit(100));
//txt.FontFamily = "Arial";
txt.FontSize = new SvgUnit(15);
txt.Fill = new SvgColourServer(Color.Black);
this.SvgDoc.Children.Add(txt);

var bmp2 = this.SvgDoc.Draw();
this.PBoxRes.Image = bmp2;


If I try to add eg. circle node, it renders ok. Text will not render until I store svg to string, parse it with SvgDocument.FromSvg() and render bitmap after that. That's working, however too slow with larger SVG and minor changes. Is there something I can do to make the text renderable imediatelly, without reparsing?

Answer

try to add this:

SvgContentNode newContent = new SvgContentNode();
newContent.Content = "Text";
txt.Nodes.Add(newContent);