|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace MusicBoxConverter
|
|
|
|
|
{
|
|
|
|
|
public class SvgWriter
|
|
|
|
|
{
|
|
|
|
|
public XmlWriter xml;
|
|
|
|
|
|
|
|
|
|
public SvgWriter(string outputFilename, string widthspec = "100%", string heightspec = "100%")
|
|
|
|
|
{
|
|
|
|
|
xml = XmlWriter.Create(
|
|
|
|
|
outputFilename,
|
|
|
|
|
new XmlWriterSettings() { Indent = true }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
xml.WriteStartDocument();
|
|
|
|
|
xml.WriteStartElement("svg", "http://www.w3.org/2000/svg");
|
|
|
|
|
xml.WriteAttributeString("version", "1.1");
|
|
|
|
|
xml.WriteAttributeString("width", widthspec);
|
|
|
|
|
xml.WriteAttributeString("height", heightspec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Complete()
|
|
|
|
|
{
|
|
|
|
|
xml.WriteEndElement();
|
|
|
|
|
xml.WriteEndDocument();
|
|
|
|
|
xml.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WritePath(string pathData, string strokeStyle = "green", int strokeWidth = 3)
|
|
|
|
|
{
|
|
|
|
|
xml.WriteStartElement("path");
|
|
|
|
|
xml.WriteAttributeString("d", pathData);
|
|
|
|
|
xml.WriteAttributeString("stroke", strokeStyle);
|
|
|
|
|
xml.WriteAttributeString("stroke-width", strokeWidth.ToString());
|
|
|
|
|
xml.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WriteCircle(int cx, int cy, int radius, string fillStyle = "blue")
|
|
|
|
|
{
|
|
|
|
|
xml.WriteStartElement("circle");
|
|
|
|
|
xml.WriteAttributeString("cx", cx.ToString());
|
|
|
|
|
xml.WriteAttributeString("cy", cy.ToString());
|
|
|
|
|
xml.WriteAttributeString("r", radius.ToString());
|
|
|
|
|
xml.WriteAttributeString("fill", fillStyle);
|
|
|
|
|
xml.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|