If i use the code below, I can make a circle with two lots of text in it, with each segment having different styles.
var firstLine = new TextSegment
{
Text = "Header Text",
TextState = new TextState
{
ForegroundColor = Color.Purple,
FontSize = 12
}
};
var secondLine = new TextSegment
{
Text = "Child Text",
TextState = new TextState
{
ForegroundColor = Color.Black,
FontSize = 10
}
};
circle.Text = new TextFragment();
circle.Text.Segments.Add(firstLine);
circle.Text.Segments.Add(secondLine);
Which sets the style correctly, but the two segments are concatanated rather than being on seperate lines.
I.e The output is
Header TextChild Text
, and I want it to be
Header Text
Child Text
If I add a carriage return into the header like “Header Text \r\n”, Or append a segment between the two which utilises Environment.NewLine, then the text is broken, but then all styling is ignored and it revertys back to the base documents styling.
This is clearly a bug as I cannot see this is desired behaviour? How would I break text?
I see on the forums that you can use TextParagraph for this in some scenarios, but shapes like the circle do not accept anything other than a text property (so limited to text fragments and segments)
Edit:
Also tried appending a new segment between 1 and 2, with:
var lineBreak = new TextSegment
{
Text = "\r\n",
};
Which still causes the same issue. I went down this route as it looks like line breaks create additional segments anyway.
I also tried appending styles once the segments had been “constructed”
Final edit
It appears that the behaviour is, if a text segment contains a line break, ignore any defined segment styling and adopt the parent text fragments style.
I can confirm this by setting the circle.text foreground color to red and the final output is red text.