Esempio n. 1
0
        private Size LayoutTypography(Size size)
        {
            if (UseLayoutManager)
            {
                if (_textContainer == null)
                {
                    return(default(Size));
                }

                _textContainer.Size = size;
                // Required for GetUsedRectForTextContainer to return a value.
                _layoutManager.GetGlyphRange(_textContainer);
                return(_layoutManager
#if NET6_0_OR_GREATER
                       .GetUsedRect
#else
                       .GetUsedRectForTextContainer
#endif
                           (_textContainer).Size);
            }
            else
            {
                if (_attributedString == null)
                {
                    return(default(Size));
                }

                return(_attributedString.BoundingRectWithSize(size, NSStringDrawingOptions.UsesLineFragmentOrigin, null).Size);
            }
        }
Esempio n. 2
0
        private Size LayoutTypography(Size size)
        {
            _textContainer.Size = size;

            // Required for GetUsedRectForTextContainer to return a value.
            _layoutManager.GetGlyphRange(_textContainer);

            return(_layoutManager.GetUsedRectForTextContainer(_textContainer).Size);
        }
Esempio n. 3
0
        nfloat HeightWrappedToViewWidth(NSTextView textView, float width)
        {
            NSLayoutManager layoutManager = textView.LayoutManager;
            NSTextContainer container     = textView.TextContainer;

            layoutManager.GetGlyphRange(container);              //force layout
            nfloat height = layoutManager.GetUsedRectForTextContainer(container).Height;

            return(height);
        }
Esempio n. 4
0
        public void NSLayoutManager_GlyphRangeForCharacterRange()
        {
            NSRange pnt;

#if NET
            NSRange range = manager.GetGlyphRange(new NSRange(0, 4), out pnt);
#else
            NSRange range = manager.GlyphRangeForCharacterRange(new NSRange(0, 4), out pnt);
#endif
            Assert.IsNotNull(range);
        }
Esempio n. 5
0
        nfloat HeightWrappedToWidth(float width)
        {
            nfloat          height        = 0;
            NSTextStorage   storage       = new NSTextStorage();
            NSLayoutManager layoutManager = new NSLayoutManager();
            CGSize          size          = new CGSize(width, 100);
            NSTextContainer container     = new NSTextContainer(size);

            layoutManager.AddTextContainer(container);
            storage.AddLayoutManager(layoutManager);
            layoutManager.GetGlyphRange(container);              //force layout
            height = layoutManager.GetUsedRectForTextContainer(container).Height;

            return(height);
        }
Esempio n. 6
0
        private CGSize textSize(string str, NSDictionary attributes)
        {
            // The three components
            var storage   = new NSTextStorage();
            var layout    = new NSLayoutManager();
            var container = new NSTextContainer();

            // Bind them
            layout.AddTextContainer(container);
            storage.AddLayoutManager(layout);

            storage.SetString(new NSAttributedString(str, attributes));

            // Compute
            layout.GetGlyphRange(container);

            // Get size
            CGSize size = layout.GetUsedRectForTextContainer(container).Size;

            return(size);
        }
Esempio n. 7
0
 public static NSRange GlyphRangeForCharacterRange(this NSLayoutManager layoutManager, NSRange charRange) => layoutManager.GetGlyphRange(charRange);