IList <VSTF.TextBounds> GetTextBounds(HexViewLine line) { if (lineSpan.IsTextSpan) { if (lineSpan.TextSpan.Value.Length == 0) { if (line.BufferSpan.Contains(lineSpan.BufferSpan)) { var bounds = line.GetCharacterBounds(lineSpan.TextSpan.Value.Start); // It's just a point, so use zero width bounds = new VSTF.TextBounds(bounds.Leading, bounds.Top, 0, bounds.Height, bounds.TextTop, bounds.TextHeight); return(new VSTF.TextBounds[] { bounds }); } return(Array.Empty <VSTF.TextBounds>()); } else { return(line.GetNormalizedTextBounds(lineSpan)); } } else { var fullSpan = lineSpan.BufferSpan; if (fullSpan.Length == 0) { if (line.BufferSpan.Contains(fullSpan)) { return(line.GetNormalizedTextBounds(fullSpan, lineSpan.SelectionFlags.Value)); } return(Array.Empty <VSTF.TextBounds>()); } else { return(line.GetNormalizedTextBounds(lineSpan)); } } }
IEnumerable <(HexColumnType type, Rect rect)> GetRectanglePositions(HexViewLine line) { var column = wpfHexView.Caret.Position.Position.ActiveColumn; if (!line.BufferLine.IsColumnPresent(column)) { yield break; } var span = line.BufferLine.GetSpan(column, onlyVisibleCells: false); var rect = GetBounds(line.GetNormalizedTextBounds(span)); if (rect == null || rect.Value.Width <= 0) { yield break; } yield return(column, new Rect(rect.Value.X, wpfHexView.ViewportTop, rect.Value.Width, wpfHexView.ViewportHeight)); }
Rect GetCaretRect(HexViewLine line, bool drawOverwriteMode, HexColumnType column, HexCell cell, int cellPosition) { if (cell == null) { return(new Rect()); } int linePosition = cell.CellSpan.Start + Math.Max(0, Math.Min(cell.CellSpan.Length - 1, cellPosition)); if (hexCaret.CurrentPosition.ActiveColumn != column) { var r = ToRect(line.GetNormalizedTextBounds(cell.CellSpan)); return(new Rect(r.X, r.Bottom - INACTIVE_CARET_HEIGHT, r.Width, INACTIVE_CARET_HEIGHT)); } else if (drawOverwriteMode) { var textBounds = line.GetExtendedCharacterBounds(linePosition); var left = textBounds.Left; var top = line.TextTop; var width = textBounds.Width; var height = line.TextHeight; return(new Rect(left, top, width, height)); } else { double left; if (linePosition != 0 && linePosition <= line.BufferLine.Text.Length) { left = line.GetExtendedCharacterBounds(linePosition - 1).Trailing; } else { left = line.GetExtendedCharacterBounds(linePosition).Leading; } var top = line.TextTop; var width = SystemParameters.CaretWidth; var height = line.TextHeight; return(new Rect(left, top, width, height)); } }