private void ReadTextSpans(XElement e, SKCanvas canvas, SKPoint location, SKPaint stroke, SKPaint fill)
{
var nodes = e.Nodes().ToArray();
for (int i = 0; i < nodes.Length; i++)
{
var c = nodes[i];
bool isFirst = i == 0;
bool isLast = i == nodes.Length - 1;
if (c.NodeType == XmlNodeType.Text)
{
// TODO: check for preserve whitespace
var textSegments = ((XText)c).Value.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
var count = textSegments.Length;
if (count > 0)
{
if (isFirst)
{
textSegments[0] = textSegments[0].TrimStart();
}
if (isLast)
{
textSegments[count - 1] = textSegments[count - 1].TrimEnd();
}
var text = WSRe.Replace(string.Concat(textSegments), " ");
canvas.DrawText(text, location.X, location.Y, fill);
location.X += fill.MeasureText(text);
}
}
else if (c.NodeType == XmlNodeType.Element)
{
var ce = (XElement)c;
if (ce.Name.LocalName == "tspan")
{
var spanFill = fill.Clone();
// the current span may want to change the cursor position
location.X = ReadOptionalNumber(ce.Attribute("x")) ?? location.X;
location.Y = ReadOptionalNumber(ce.Attribute("y")) ?? location.Y;
ReadFontAttributes(ce, spanFill);
var text = ce.Value.Trim();
canvas.DrawText(text, location.X, location.Y, spanFill);
location.X += spanFill.MeasureText(text);
}
}
}
}