Ejemplo n.º 1
0
        // not bound
        public static CGRect BoundingRect(this NSAttributedString str, CGSize size, NSStringDrawingOptions options)
        {
            CGRect rect;

            Messaging.RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options);
            return(rect);
        }
Ejemplo n.º 2
0
        public override Xamarin.Forms.Size Measure(string text, double fontSize, string fontName)
        {
            UIFont font = this.getFont(fontName, fontSize);

            UIStringAttributes attributes = new UIStringAttributes();

            attributes.Font = font;

            SizeF boundSize = new SizeF(float.PositiveInfinity, float.PositiveInfinity);
            NSStringDrawingOptions options = NSStringDrawingOptions.UsesFontLeading |
                                             NSStringDrawingOptions.UsesLineFragmentOrigin;

            NSString nsText     = new NSString(text);
            CGSize   resultSize = nsText.GetBoundingRect(
                boundSize,
                options,
                attributes,
                null).Size;

            nsText.Dispose();

            return(new Xamarin.Forms.Size(
                       Math.Ceiling((double)resultSize.Width),
                       Math.Ceiling((double)resultSize.Height)));
        }
Ejemplo n.º 3
0
		public static CGRect GetBoundingRect (this NSString This, CGSize size, NSStringDrawingOptions options, UIStringAttributes attributes, NSStringDrawingContext context)
		{
			// Define attributes
			var attr = new NSMutableDictionary ();
			attr.Add (NSFont.NameAttribute, attributes.Font.NSFont);

			var rect = This.BoundingRectWithSize (size, options, attr);

			// HACK: Cheating on the height
			return new CGRect(rect.Left, rect.Top , rect.Width, rect.Height * 1.5f);
		}
Ejemplo n.º 4
0
        public static CGRect GetBoundingRect(this NSString This, CGSize size, NSStringDrawingOptions options, UIStringAttributes attributes, NSStringDrawingContext context)
        {
            // Define attributes
            var attr = new NSMutableDictionary();

            attr.Add(NSFont.NameAttribute, attributes.Font.NSFont);

            var rect = This.BoundingRectWithSize(size, options, attr);

            // HACK: Cheating on the height
            return(new CGRect(rect.Left, rect.Top, rect.Width, rect.Height * 1.5f));
        }
Ejemplo n.º 5
0
        public void DrawingExtensions()
        {
            TestRuntime.AssertXcodeVersion(5, 0);

            using (var s = new NSString("foo")) {
                NSStringDrawingOptions options = NSStringDrawingOptions.OneShot;
                var attrib = new UIStringAttributes();
                using (var dict = new NSDictionary()) {
                    Assert.DoesNotThrow(() => s.GetBoundingRect(new SizeF(5, 5), options, attrib, null), "GetBoundingRect 1");
                    Assert.DoesNotThrow(() => s.WeakGetBoundingRect(new SizeF(5, 5), options, dict, null), "WeakGetBoundingRect 1");
                    Assert.DoesNotThrow(() => s.DrawString(new RectangleF(0, 0, 10, 10), options, attrib, null), "DrawString 1");
                    Assert.DoesNotThrow(() => s.WeakDrawString(new RectangleF(0, 0, 10, 10), options, dict, null), "WeakDrawString 1");
                    Assert.DoesNotThrow(() => s.WeakDrawString(new RectangleF(0, 0, 10, 10), dict), "WeakDrawString 2");
                    Assert.DoesNotThrow(() => s.WeakDrawString(new PointF(0, 0), dict), "WeakDrawString 3");
                }
            }
        }
Ejemplo n.º 6
0
        public void DrawingExtensions()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Inconclusive("requires iOS7+");
            }

            using (var s = new NSString("foo")) {
                NSStringDrawingOptions options = NSStringDrawingOptions.OneShot;
                var attrib = new UIStringAttributes();
                using (var dict = new NSDictionary()) {
                    Assert.DoesNotThrow(() => s.GetBoundingRect(new SizeF(5, 5), options, attrib, null), "GetBoundingRect 1");
                    Assert.DoesNotThrow(() => s.WeakGetBoundingRect(new SizeF(5, 5), options, dict, null), "WeakGetBoundingRect 1");
                    Assert.DoesNotThrow(() => s.DrawString(new RectangleF(0, 0, 10, 10), options, attrib, null), "DrawString 1");
                    Assert.DoesNotThrow(() => s.WeakDrawString(new RectangleF(0, 0, 10, 10), options, dict, null), "WeakDrawString 1");
                    Assert.DoesNotThrow(() => s.WeakDrawString(new RectangleF(0, 0, 10, 10), dict), "WeakDrawString 2");
                    Assert.DoesNotThrow(() => s.WeakDrawString(new PointF(0, 0), dict), "WeakDrawString 3");
                }
            }
        }
Ejemplo n.º 7
0
        public void DrawingExtensions()
        {
            TestRuntime.AssertXcodeVersion(5, 0);
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 11, throwIfOtherPlatform: false);

            using (var s = new NSString("foo")) {
                NSStringDrawingOptions options = NSStringDrawingOptions.OneShot;
                var attrib = new UIStringAttributes();
                using (var dict = new NSDictionary()) {
                    Assert.DoesNotThrow(() => s.GetBoundingRect(new CGSize(5, 5), options, attrib, null), "GetBoundingRect 1");
                    Assert.DoesNotThrow(() => s.WeakGetBoundingRect(new CGSize(5, 5), options, dict, null), "WeakGetBoundingRect 1");
                    Assert.DoesNotThrow(() => s.DrawString(new CGRect(0, 0, 10, 10), options, attrib, null), "DrawString 1");
                    Assert.DoesNotThrow(() => s.WeakDrawString(new CGRect(0, 0, 10, 10), options, dict, null), "WeakDrawString 1");
#if !MONOMAC //WeakDrawString on mac doesn't have versions with these parameters
                    Assert.DoesNotThrow(() => s.WeakDrawString(new CGRect(0, 0, 10, 10), dict), "WeakDrawString 2");
                    Assert.DoesNotThrow(() => s.WeakDrawString(new CGPoint(0, 0), dict), "WeakDrawString 3");
#endif
                }
            }
        }
Ejemplo n.º 8
0
 public virtual void DrawWithRect(CGRect rect, NSStringDrawingOptions options, Dictionary <NSObject, AnyObject> attributes, [Unwrapped] NSStringDrawingContext context)
 {
 }
Ejemplo n.º 9
0
 public virtual CGRect BoundingRectWithSize(CGSize size, NSStringDrawingOptions options, Dictionary <NSObject, AnyObject> attributes, [Unwrapped] NSStringDrawingContext context)
 {
     return(default(CGRect));
 }
Ejemplo n.º 10
0
		// not bound
		public static CGRect BoundingRect(this NSAttributedString str, CGSize size, NSStringDrawingOptions options)
		{
			CGRect rect;
			Messaging.RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options);
			return rect;
		}
Ejemplo n.º 11
0
 public static CGRect BoundingRectWithSize(this NSAttributedString attrString, CGSize size, NSStringDrawingOptions options)
 => attrString.GetBoundingRect(size, options, null);
Ejemplo n.º 12
0
		// not bound
		public static RectangleF BoundingRect(this NSAttributedString str, SizeF size, NSStringDrawingOptions options)
		{
			RectangleF rect;
			RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options);
			return rect;
		}
Ejemplo n.º 13
0
		public static CGRect BoundingRectWithSize (this NSAttributedString attrString, CGSize size, NSStringDrawingOptions options)
			=> attrString.GetBoundingRect (size, options, null);
Ejemplo n.º 14
0
        // not bound
        public static RectangleF BoundingRect(this NSAttributedString str, SizeF size, NSStringDrawingOptions options)
        {
            RectangleF rect;

            RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options);
            return(rect);
        }
Ejemplo n.º 15
0
 public virtual CGRect BoundingRectWithSize(CGSize size, NSStringDrawingOptions options, [Optional] NSStringDrawingContext context)
 {
     return(default(CGRect));
 }
Ejemplo n.º 16
0
 public virtual void DrawWithRect(CGRect rect, NSStringDrawingOptions options, [Optional] NSStringDrawingContext context)
 {
 }