uint LineNumber(NSTextView textView) { NSLayoutManager layoutManager = textView.LayoutManager; nint lineCharacterRange = layoutManager.NumberOfGlyphs; var lineRange = new NSRange(0, lineCharacterRange); var charRane = new NSRange(0, 1); CGRect lineRect = layoutManager.BoundingRectForGlyphRange(lineRange, textView.TextContainer); CGRect charRect = layoutManager.BoundingRectForGlyphRange(charRane, textView.TextContainer); uint lineNum = (uint)(lineRect.Bottom / charRect.Bottom); return(lineNum); }
static CGRect GetCharacterBounds(NSRange characterRange, NSLayoutManager layoutManager, NSTextContainer textContainer) { var glyphRange = new NSRange(); layoutManager.CharacterRangeForGlyphRange(characterRange, ref glyphRange); return(layoutManager.BoundingRectForGlyphRange(glyphRange, textContainer)); }
static CGRect GetCharacterBounds(NSRange characterRange, NSLayoutManager layoutManager, NSTextContainer textContainer) { var glyphRange = new NSRange(); #if __MOBILE__ layoutManager.CharacterRangeForGlyphRange(characterRange, ref glyphRange); #else #pragma warning disable CS0618 // Type or member is obsolete layoutManager.CharacterRangeForGlyphRange(characterRange, out glyphRange); #pragma warning restore CS0618 // Type or member is obsolete #endif return(layoutManager.BoundingRectForGlyphRange(glyphRange, textContainer)); }
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 CGRect boundingRectForCharacter(NSRange range) { NSTextStorage textStorage = new NSTextStorage(); textStorage.SetString(this.AttributedText); NSLayoutManager layoutManager = new NSLayoutManager(); textStorage.AddLayoutManager(layoutManager); NSTextContainer textContainer = new NSTextContainer(this.Bounds.Size); textContainer.LineFragmentPadding = 0f; layoutManager.AddTextContainer(textContainer); NSRange glyphRange; glyphRange = layoutManager.CharacterRangeForGlyphRange(range); return(layoutManager.BoundingRectForGlyphRange(glyphRange, textContainer)); }
public static SizeF MeasureString(NSAttributedString str, SizeF?availableSize = null) { SetContainerSize(availableSize); storage.SetString(str); return(layout.BoundingRectForGlyphRange(new NSRange(0, (int)str.Length), container).Size.ToEto()); }