예제 #1
0
        public static SizeF GetTextSize(string text, FontAttributes fontAttributes, TextAlignment alignment, LineBreakMode lineBreakMode, float maxWidth, float height = -1)
        {
            var tb = new TextBlock();

            tb.AddText(text, fontAttributes.ToStyle());
            tb.Alignment = alignment.ToTextAlignment();
            tb.MaxWidth  = maxWidth;

            tb.MaxLines = null;
            tb.Layout();
            return(new SizeF(tb.MeasuredWidth, tb.MeasuredHeight));
        }
예제 #2
0
        protected virtual void DrawText(string text, SKCanvas canvas, FontAttributes data, Color color, TextAlignment alignment, LineBreakMode lineBreakMode, VerticalAlignment verticalAlignment)
        {
            var tb = new TextBlock();

            tb.AddText(text, data.ToStyle(color));
            tb.MaxWidth  = VirtualView.Frame.Width;
            tb.MaxHeight = VirtualView.Frame.Height;
            tb.MaxLines  = null;
            tb.Alignment = alignment.ToTextAlignment();
            tb.Layout();

            var y = verticalAlignment switch
            {
                VerticalAlignment.Bottom => VirtualView.Frame.Height - tb.MeasuredHeight,
                VerticalAlignment.Center => (VirtualView.Frame.Height - tb.MeasuredHeight) / 2,
                _ => 0
            };

            tb.Paint(canvas, new SKPoint(0, y));
        }