예제 #1
0
        public static CATextLayer RenderLabel(Mapsui.Geometries.Point point, LabelStyle style, IFeature feature, IViewport viewport, string text)
        {
            // Offset stackOffset,
            Mapsui.Geometries.Point p = viewport.WorldToScreen(point);
            //var pointF = new xPointF((float)p.X, (float)p.Y);
            var label = new CATextLayer();


            var aString = new MonoTouch.Foundation.NSAttributedString(text,
                                                                      new MonoTouch.CoreText.CTStringAttributes()
            {
                Font = new MonoTouch.CoreText.CTFont("ArialMT", 10)
            });

            var frame = new RectangleF(new System.Drawing.Point((int)p.X, (int)p.Y), GetSizeForText(0, aString));

            //label.Frame = frame;
            //frame.Width = (float)(p2.X - p1.X);// + margin);
            //frame.Height = (float)(p1.Y - p2.Y);

            label.FontSize        = 10;
            label.ForegroundColor = new MonoTouch.CoreGraphics.CGColor(0, 0, 255, 150);
            label.BackgroundColor = new MonoTouch.CoreGraphics.CGColor(255, 0, 2, 150);
            label.String          = text;

            label.Frame = frame;

            Console.WriteLine("Pos " + label.Frame.X + ":" + label.Frame.Y + " w " + label.Frame.Width + " h " + label.Frame.Height);

            // = MonoTouch.UIKit.UIScreen.MainScreen.Scale;
            //	label.ContentsScale = scale;

            return(label);
        }
예제 #2
0
        private static CATextLayer CreateCATextLayer(LabelStyle style, string text)
        {
            var label = new CATextLayer();

            var ctFont  = new MonoTouch.CoreText.CTFont(style.Font.FontFamily, (float)style.Font.Size);
            var aString = new MonoTouch.Foundation.NSAttributedString(text,
                                                                      new MonoTouch.CoreText.CTStringAttributes()
            {
                Font = ctFont
            });

            label.SetFont(ctFont);
            label.FontSize        = (float)style.Font.Size;
            label.ForegroundColor = ToCGColor(style.ForeColor);
            label.BackgroundColor = TransparentColor;
            label.ShadowOpacity   = 0;
            label.BorderWidth     = 0;

            label.String = text;

            var size = GetSizeForText(0, aString);

            label.Frame = new RectangleF(0, 0, size.Width, size.Height);

            return(label);
        }
예제 #3
0
        private static SizeF GetSizeForText(int width, MonoTouch.Foundation.NSAttributedString aString)
        {
            var frameSetter = new MonoTouch.CoreText.CTFramesetter(aString);

            MonoTouch.Foundation.NSRange range;
            var size = frameSetter.SuggestFrameSize(new MonoTouch.Foundation.NSRange(0, 0), null,
                                                    new System.Drawing.Size(width, Int32.MaxValue), out range);

            return(size);
        }
예제 #4
0
        private static SizeF GetSizeForText(int width, MonoTouch.Foundation.NSAttributedString aString)
        {
            var frameSetter = new MonoTouch.CoreText.CTFramesetter(aString);

            MonoTouch.Foundation.NSRange range;
            //CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString( (CFMutableAttributedStringRef) attributedString);
            var size = frameSetter.SuggestFrameSize(new MonoTouch.Foundation.NSRange(0, 0), null,
                                                    new System.Drawing.Size(width, Int32.MaxValue), out range);

            //CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, 0), NULL, CGSizeMake(inWidth, CGFLOAT_MAX), NULL);
            //CFRelease(framesetter);
            Console.WriteLine("Size = " + size.Width + ":" + size.Height + "Range = " + range.Length);

            return(size);
        }
예제 #5
0
 public UIPrintFormatter(MonoTouch.Foundation.NSAttributedString attributedText)
 {
 }
예제 #6
0
        public static CATextLayer RenderLabel(Mapsui.Geometries.Point point, LabelStyle style, IFeature feature, IViewport viewport, string text)
        {
            // Offset stackOffset,
            Mapsui.Geometries.Point p = viewport.WorldToScreen(point);
            //var pointF = new xPointF((float)p.X, (float)p.Y);
            var label = new CATextLayer();


            var aString = new MonoTouch.Foundation.NSAttributedString(text,
                                                                      new MonoTouch.CoreText.CTStringAttributes()
            {
                Font = new MonoTouch.CoreText.CTFont("ArialMT", 10)
            });

            var frame = new RectangleF(new System.Drawing.Point((int)p.X, (int)p.Y), GetSizeForText(0, aString));

            //label.Frame = frame;
            //frame.Width = (float)(p2.X - p1.X);// + margin);
            //frame.Height = (float)(p1.Y - p2.Y);

            label.FontSize        = 10;
            label.ForegroundColor = new MonoTouch.CoreGraphics.CGColor(0, 0, 255, 150);
            label.BackgroundColor = new MonoTouch.CoreGraphics.CGColor(255, 0, 2, 150);
            label.String          = text;

            label.Frame = frame;

            Console.WriteLine("Pos " + label.Frame.X + ":" + label.Frame.Y + " w " + label.Frame.Width + " h " + label.Frame.Height);

            // = MonoTouch.UIKit.UIScreen.MainScreen.Scale;
            //	label.ContentsScale = scale;


            return(label);

            //var border = new Border();
            //var textblock = new TextBlock();

            //Text
            //textblock.Text = text;

            //Colors
            //textblock.Foreground = new SolidColorBrush(style.ForeColor.ToXaml());
            //border.Background = new SolidColorBrush(style.BackColor.Color.ToXaml());

            //Font
            //textblock.FontFamily = new FontFamily(style.Font.FontFamily);
            //textblock.FontSize = style.Font.Size;

            //set some defaults which should be configurable someday
            const double witdhMargin  = 3.0;
            const double heightMargin = 0.0;

            //textblock.Margin = new Thickness(witdhMargin, heightMargin, witdhMargin, heightMargin);
            //border.CornerRadius = new CornerRadius(4);
            //border.Child = textblock;
            //Offset

            //var textWidth = textblock.ActualWidth;
            //var textHeight = textblock.ActualHeight;
                        #if !SILVERLIGHT && !NETFX_CORE
            // in WPF the width and height is not calculated at this point. So we use FormattedText
            //getTextWidthAndHeight(ref textWidth, ref textHeight, style, text);
                        #endif
            //border.SetValue(Canvas.LeftProperty, windowsPoint.X + style.Offset.X + stackOffset.X - (textWidth + 2 * witdhMargin) * (short)style.HorizontalAlignment * 0.5f);
            //border.SetValue(Canvas.TopProperty, windowsPoint.Y + style.Offset.Y + stackOffset.Y - (textHeight + 2 * heightMargin) * (short)style.VerticalAlignment * 0.5f);

            //return border;
            //return null;
        }