示例#1
0
 protected override Size MeasureOverride(Size availableSize)
 {
     using (var line = new FormattedText(
         "Item 100",
         TextBlock.GetFontFamily(this),
         TextBlock.GetFontSize(this),
         TextBlock.GetFontStyle(this),
         TextAlignment.Left,
         TextBlock.GetFontWeight(this)))
     {
         line.Constraint = availableSize;
         _lineSize = line.Measure();
         return new Size(_lineSize.Width, _lineSize.Height * itemCount);
     }
 }
示例#2
0
        protected override Size MeasureOverride(Size availableSize)
        {
            var text = this.Text;

            if (!string.IsNullOrWhiteSpace(text))
            {
                return base.MeasureOverride(availableSize);
            }
            else
            {
                // TODO: Pretty sure that measuring "X" isn't the right way to do this...
                using (var formattedText = new FormattedText(
                    "X",
                    this.FontFamily,
                    this.FontSize,
                    this.FontStyle,
                    TextAlignment.Left,
                    this.FontWeight))
                {
                    return formattedText.Measure();
                }
            }
        }
示例#3
0
 public void DrawText(Brush foreground, Point origin, FormattedText text)
 {
     using (var br = CreateBrush(foreground, text.Measure()))
         MethodTable.Instance.DrawFormattedText(Handle, br.Brush, ((FormattedTextImpl) text.PlatformImpl).Handle,
             (float) origin.X, (float) origin.Y);
 }
示例#4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="text"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XText text, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            var _gfx = dc as IDrawingContext;

            var tbind = text.BindToTextProperty(db, r);
            if (string.IsNullOrEmpty(tbind))
                return;

            Brush brush = ToSolidBrush(text.Style.Stroke);

            var fontStyle = Perspex.Media.FontStyle.Normal;
            if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.Italic))
            {
                fontStyle |= Perspex.Media.FontStyle.Italic;
            }

            var fontWeight = Perspex.Media.FontWeight.Normal;
            if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.Bold))
            {
                fontWeight |= Perspex.Media.FontWeight.Bold;
            }

            // TODO: Implement font decoration after Perspex adds support for them.
            /*
            var fontDecoration = Perspex.Media.FontDecoration.None;
            if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.Underline))
            {
                fontDecoration |= Perspex.Media.FontDecoration.Underline;
            }

            if (text.Style.TextStyle.FontStyle.HasFlag(Test2d.FontStyle.Strikeout))
            {
                fontDecoration |= Perspex.Media.FontDecoration.Strikethrough;
            }
            */

            var ft = new FormattedText(
                tbind,
                text.Style.TextStyle.FontName,
                text.Style.TextStyle.FontSize * _textScaleFactor,
                fontStyle,
                TextAlignment.Left,
                fontWeight);

            var rect = CreateRect(
                text.TopLeft,
                text.BottomRight,
                dx, dy);

            var size = ft.Measure();
            var origin = GetTextOrigin(text.Style, ref rect, ref size);

            _gfx.DrawText(brush, origin, ft);

            // TODO: brush.Dispose();
            ft.Dispose();
        }