private IEnumerable<CanvasTextLayoutRegion> GetRegions(CanvasTextLayout tl, int idx, CanvasLineMetrics line, Range[] formatChanges) { var lineRange = new Range(idx, line.CharacterCount); var inLineChanges = formatChanges.Where(i => lineRange.InterlappedWith(i)).ToArray(); if (inLineChanges.Length == 0) { var regs = tl.GetCharacterRegions(idx, line.CharacterCount); foreach (var r in regs) { yield return r; } } else { foreach (var p in inLineChanges) { var b = Math.Max(p.Begin, lineRange.Begin); var e = Math.Min(p.End, lineRange.End); var c = e - b + 1; if (c > 0) { var regs = tl.GetCharacterRegions(b, c); foreach (var r in regs) { yield return r; } } } } }