2017-11-30 22:45:39 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
2017-11-30 23:03:55 +00:00
|
|
|
|
using SBRL.Utilities;
|
2017-11-30 22:45:39 +00:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 23:15:52 +00:00
|
|
|
|
public void WriteRectangle(Vector2 position, Vector2 size, string strokeStyle = "red", int strokeWidth = 3)
|
|
|
|
|
{
|
|
|
|
|
xml.WriteStartElement("rect");
|
|
|
|
|
xml.WriteAttributeString("x", position.X.ToString());
|
|
|
|
|
xml.WriteAttributeString("y", position.Y.ToString());
|
|
|
|
|
xml.WriteAttributeString("width", size.X.ToString());
|
|
|
|
|
xml.WriteAttributeString("height", size.Y.ToString());
|
|
|
|
|
xml.WriteAttributeString("fill", "transparent");
|
|
|
|
|
xml.WriteAttributeString("stroke", strokeStyle);
|
|
|
|
|
xml.WriteAttributeString("stroke-width", strokeWidth.ToString());
|
|
|
|
|
xml.WriteEndElement();
|
|
|
|
|
}
|
2017-11-30 23:03:55 +00:00
|
|
|
|
public void WriteCircle(Vector2 centre, int radius, string fillStyle = "blue")
|
2017-11-30 22:45:39 +00:00
|
|
|
|
{
|
|
|
|
|
xml.WriteStartElement("circle");
|
2017-11-30 23:03:55 +00:00
|
|
|
|
xml.WriteAttributeString("cx", centre.X.ToString());
|
|
|
|
|
xml.WriteAttributeString("cy", centre.Y.ToString());
|
2017-11-30 22:45:39 +00:00
|
|
|
|
xml.WriteAttributeString("r", radius.ToString());
|
|
|
|
|
xml.WriteAttributeString("fill", fillStyle);
|
|
|
|
|
xml.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|