public CGSize GetSize() { using (var TextLayout = new NSLayoutManager()) { TextLayout.AddTextContainer(TextContainer); TextStorage.AddLayoutManager(TextLayout); TextLayout.GlyphRangeForBoundingRect(new CGRect(CGPoint.Empty, TextContainer.Size), TextContainer); var s = TextLayout.GetUsedRectForTextContainer(TextContainer); TextStorage.RemoveLayoutManager(TextLayout); TextLayout.RemoveTextContainer(0); return(s.Size); } }
NSRange LineRange(NSTextView textView) { NSLayoutManager layoutManager = textView.LayoutManager; var charRane = new NSRange(0, 1); CGRect charRect = layoutManager.BoundingRectForGlyphRange(charRane, textView.TextContainer); var lRect = new CGRect(charRect.Left, charRect.Size.Height * 6, charRect.Size.Width, charRect.Size.Height); NSRange lRange = layoutManager.GlyphRangeForBoundingRect(lRect, textView.TextContainer); var nOrange = new NSRange(0, lRange.Location - 1); return(nOrange); }
public CGPoint GetCoordinateFromIndex(int index) { using (var TextLayout = new NSLayoutManager()) { TextLayout.AddTextContainer(TextContainer); TextStorage.AddLayoutManager(TextLayout); TextLayout.GlyphRangeForBoundingRect(new CGRect(CGPoint.Empty, TextContainer.Size), TextContainer); var glyphIndex = TextLayout.GlyphIndexForCharacterAtIndex(index); var p = TextLayout.LocationForGlyphAtIndex((nint)glyphIndex); TextStorage.RemoveLayoutManager(TextLayout); TextLayout.RemoveTextContainer(0); return(p); } }
public nuint GetIndexFromCoordinates(double x, double y) { using (var TextLayout = new NSLayoutManager()) { TextLayout.AddTextContainer(TextContainer); TextStorage.AddLayoutManager(TextLayout); TextLayout.GlyphRangeForBoundingRect(new CGRect(CGPoint.Empty, TextContainer.Size), TextContainer); nfloat fraction = 0; var index = TextLayout.CharacterIndexForPoint(new CGPoint(x, y), TextContainer, ref fraction); TextStorage.RemoveLayoutManager(TextLayout); TextLayout.RemoveTextContainer(0); return(index); } }