/// <summary> /// /// </summary> /// <param name="startPosition"></param> /// <param name="endPosition"></param> /// <param name="visibleRect"></param> /// <returns></returns> internal Geometry GetTightBoundingGeometryFromTextPositions(ITextPointer startPosition, ITextPointer endPosition, Rect visibleRect) { Geometry geometry = null; // Find out if cell is selected. We consider cell selected if its end tag is crossed by selection. // The asymmetry is important here - it allows to use only normalized positions // and still be able to select individual cells. // Note that this logic is an assumption in textselection unit expansion mechanism // (TexSelection.ExtendSelectionToStructuralUnit method). if (endPosition.CompareTo(Cell.StaticElementEnd) >= 0) { geometry = new RectangleGeometry(_rect.FromTextDpi()); } else { SubpageParagraphResult paragraphResult = (SubpageParagraphResult)(CreateParagraphResult()); ReadOnlyCollection<ColumnResult> colResults = paragraphResult.Columns; Transform transform; transform = new TranslateTransform(-TextDpi.FromTextDpi(ContentRect.u), -TextDpi.FromTextDpi(ContentRect.v)); visibleRect = transform.TransformBounds(visibleRect); transform = null; geometry = TextDocumentView.GetTightBoundingGeometryFromTextPositionsHelper(colResults[0].Paragraphs, paragraphResult.FloatingElements, startPosition, endPosition, 0.0, visibleRect); if (geometry != null) { // restrict geometry to the cell's content rect boundary. // because of end-of-line / end-of-para simulation calculated geometry could be larger. Rect viewport = new Rect(0, 0, TextDpi.FromTextDpi(ContentRect.du), TextDpi.FromTextDpi(ContentRect.dv)); CaretElement.ClipGeometryByViewport(ref geometry, viewport); transform = new TranslateTransform(TextDpi.FromTextDpi(ContentRect.u), TextDpi.FromTextDpi(ContentRect.v)); CaretElement.AddTransformToGeometry(geometry, transform); } } return (geometry); }