Hi,
8
8
Hi,
You can replace the standard SVG generator for GoText by defining your own GoSvgGenerator:
public class CustomTextGenerator : GoSvgGenerator {
public override void GenerateBody(object obj) {
base.GenerateBody(obj);
WriteStartElement("animateColor");
WriteAttrVal("attributeName", "fill");
WriteAttrVal("attributeType", "CSS");
WriteAttrVal("begin", "1s");
WriteAttrVal("dur", "5s");
WriteAttrVal("from", "#FFFFFF");
WriteAttrVal("to", "#F00");
WriteAttrVal("fill", "freeze");
WriteEndElement();
}
}
Install this by doing:
[code] GoSvgWriter w = new GoSvgWriter();
CustomTextGenerator ctg = new CustomTextGenerator();
ctg.InheritsFromTransformer = w.GetTransformer(typeof(GoText));
w.SetTransformer(typeof(GoText), ctg);
XmlDocument svgdoc = w.Generate();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter svgwriter = XmlWriter.Create(@"C:\temp\text.svg", settings);
svgdoc.WriteContentTo(svgwriter);
svgwriter.Close();[/code]
The InheritsFromTransformer property causes the call to base.GenerateBody to get the standard GoText generator to produce what it normally does.
However, this doesn’t generate exactly what you want. It produces:
<g>
<text font-size="24pt" fill="rgb(0,191,255)">
<tspan x="128" y="158" textLength="154.32811">Some Text</tspan>
</text>
<animateColor attributeName="fill" attributeType="CSS" begin="1s" dur="5s" from="#FFFFFF" to="#F00" fill="freeze" />
</g>
Since you want to annotate XML deep inside what a generator normally produces, you cannot use the above technique to add some attributes (before the call to base.GenerateBody) or some elements to what is normally produced by the GoText SVG generator.
So your interest in getting to the XmlElement is going in the right direction. If you generate an XmlDocument instead of writing an XML stream, you can modify the XML DOM in memory.
Hence the start of the generator you want is:
// this only works for generating an XmlDocument
public class CustomTextGenerator : GoSvgGenerator {
public override void GenerateBody(object obj) {
base.GenerateBody(obj);
XmlElement elt = this.Writer.WriterElement;
// ELT is now the <G> element
XmlElement textelt = elt.ChildNodes[0] as XmlElement;
// this should be the <TEXT> element
}
}
Sorry I don’t have the time to finish this for you. You do need to know System.Xml, of course.
One of the benefits of GoXml is that you don’t need to know System.Xml. Another benefit is that it works with both streams and with Xml DOM.
Thank you for your help! Perfect!