// Просматривает всю коллекцию цветосегментов, и удалаяет все сегменты в интервале [start, end) public void EraseColorSegment(int start, int end) { for (int i = ColorSegments.Count - 1; i >= 0; i--) { ColorSegment segment = ColorSegments[i]; if ((start < segment.Start.Offset && end < segment.Start.Offset) || (start > segment.End.Offset && end > segment.End.Offset)) { continue; } if (start <= segment.Start.Offset && end >= segment.End.Offset) { ColorSegments.RemoveAt(i); } else if (start <= segment.Start.Offset && end < segment.End.Offset) { TextAnchor startAnchor = Document.CreateAnchor(end); segment.Start = startAnchor; } else if (segment.Start.Offset < start && segment.End.Offset <= end) { TextAnchor endAnchor = Document.CreateAnchor(start); segment.End = endAnchor; } else if (segment.Start.Offset < start && end < segment.End.Offset) { // разбиваем на 2 // add new AddColorSegment(end, segment.End.Offset, segment.Color); TextAnchor endAnchor = Document.CreateAnchor(start); segment.End = endAnchor; } else { Debug.Assert(false, "WE CAN'T BE HERE!!!!!"); } } IsChanged = true; }
public void AddColorSegment(int start, int end, SolidColorBrush color) { TextAnchor startAnchor = Document.CreateAnchor(start); startAnchor.MovementType = AnchorMovementType.AfterInsertion; startAnchor.SurviveDeletion = true; TextAnchor endAnchor = Document.CreateAnchor(end); endAnchor.MovementType = AnchorMovementType.BeforeInsertion; endAnchor.SurviveDeletion = true; ColorSegment segment = new ColorSegment() { Color = color, Start = startAnchor, End = endAnchor }; ColorSegments.Add(segment); IsChanged = true; }
public void ClearAllColorSegments() { ColorSegments.Clear(); IsChanged = true; }