diff --git a/MusicBoxConverter/MusicBoxScoreGenerator.cs b/MusicBoxConverter/MusicBoxScoreGenerator.cs index b453ca0..272a559 100644 --- a/MusicBoxConverter/MusicBoxScoreGenerator.cs +++ b/MusicBoxConverter/MusicBoxScoreGenerator.cs @@ -130,6 +130,7 @@ namespace MusicBoxConverter svg.WriteRectangle(Offset, area, "red", 0.75f); + int noteIndex = 0; foreach (Note note in AllNotes()) { if(Debug) { @@ -155,6 +156,13 @@ namespace MusicBoxConverter new Vector2(HoleSize, HoleSize) ); + svg.WriteText( + holePosition.Subtract(new Vector2(-HoleSize * 2, HoleSize/2 + -svg.FontSizeRegular/2)), + $"{noteIndex}", + "regular" + ); + + noteIndex++; } svg.Complete(); diff --git a/MusicBoxConverter/SvgWriter.cs b/MusicBoxConverter/SvgWriter.cs index 0302c76..e0180e8 100644 --- a/MusicBoxConverter/SvgWriter.cs +++ b/MusicBoxConverter/SvgWriter.cs @@ -27,6 +27,10 @@ namespace MusicBoxConverter public string UnitSuffix { get; set; } = ""; + public float FontSizeRegular { get; set; } = 3; + + private bool haveWrittenFontStyles = false; + public SvgWriter(string outputFilename, string widthspec = "100%", string heightspec = "100%", Rectangle viewBox = null) { xml = XmlWriter.Create( @@ -57,6 +61,22 @@ namespace MusicBoxConverter xml.Close(); } + public void WriteText(Vector2 pos, string text, string className) + { + if (!haveWrittenFontStyles) + { + xml.WriteElementString("style", $".regular {{ font: {FontSizeRegular}{UnitSuffix} sans-serif; }}"); + haveWrittenFontStyles = true; + } + + xml.WriteStartElement("text"); + xml.WriteAttributeString("x", $"{pos.X}{UnitSuffix}"); + xml.WriteAttributeString("y", $"{pos.Y}{UnitSuffix}"); + xml.WriteAttributeString("class", className); + xml.WriteString(text); + xml.WriteEndElement(); + } + public void WriteLine(Vector2 start, Vector2 end, string strokeStyle = "darkgreen", float strokeWidth = 3) { xml.WriteStartElement("line");