Add text next to each hole
This commit is contained in:
parent
f20ddb5a8e
commit
e9f5f73668
2 changed files with 28 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue