Пример #1
0
 public void DrawText(IBrush foreground, Point origin, FormattedText text)
 {
     using (var paint = CreatePaint(foreground, text.Measure()))
     {
         var textImpl = text.PlatformImpl as FormattedTextImpl;
         textImpl.Draw(this, Canvas, origin.ToSKPoint(), paint);
     }
 }
Пример #2
0
        protected override Size MeasureOverride(Size availableSize)
        {
            var text = Text;

            if (!string.IsNullOrEmpty(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",
                    FontFamily,
                    FontSize,
                    FontStyle,
                    TextAlignment,
                    FontWeight))
                {
                    return formattedText.Measure();
                }
            }
        }
Пример #3
0
        /// <inheritdoc/>
        public override void Draw(object dc, XText text, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            var _gfx = dc as AM.DrawingContext;

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

            AM.IBrush brush = ToBrush(text.Style.Stroke);

            var fontStyle = AM.FontStyle.Normal;
            var fontWeight = AM.FontWeight.Normal;
            //var fontDecoration = PM.FontDecoration.None;

            if (text.Style.TextStyle.FontStyle != null)
            {
                if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Italic))
                {
                    fontStyle |= AM.FontStyle.Italic;
                }

                if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Bold))
                {
                    fontWeight |= AM.FontWeight.Bold;
                }

                // TODO: Implement font decoration after Avalonia adds support.
                /*
                if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Underline))
                {
                    fontDecoration |= PM.FontDecoration.Underline;
                }

                if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Strikeout))
                {
                    fontDecoration |= PM.FontDecoration.Strikethrough;
                }
                */
            }

            if (text.Style.TextStyle.FontSize >= 0.0)
            {
                var ft = new AM.FormattedText(
                    tbind,
                    text.Style.TextStyle.FontName,
                    text.Style.TextStyle.FontSize * _textScaleFactor,
                    fontStyle,
                    AM.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);

                ft.Dispose();
            }
        }
Пример #4
0
        /// <inheritdoc/>
        public override void Draw(object dc, TextShape text, double dx, double dy, object db, object r)
        {
            var _gfx = dc as AM.DrawingContext;

            var properties = (ImmutableArray <Property>)db;
            var record     = (Record)r;
            var tbind      = text.BindText(properties, record);

            if (string.IsNullOrEmpty(tbind))
            {
                return;
            }

            AM.IBrush brush = ToBrush(text.Style.Stroke);

            var fontStyle  = AM.FontStyle.Normal;
            var fontWeight = AM.FontWeight.Normal;

            //var fontDecoration = PM.FontDecoration.None;

            if (text.Style.TextStyle.FontStyle != null)
            {
                if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Italic))
                {
                    fontStyle |= AM.FontStyle.Italic;
                }

                if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Bold))
                {
                    fontWeight |= AM.FontWeight.Bold;
                }

                // TODO: Implement font decoration after Avalonia adds support.

                /*
                 * if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Underline))
                 * {
                 *  fontDecoration |= PM.FontDecoration.Underline;
                 * }
                 *
                 * if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.Strikeout))
                 * {
                 *  fontDecoration |= PM.FontDecoration.Strikethrough;
                 * }
                 */
            }

            if (text.Style.TextStyle.FontSize >= 0.0)
            {
                var tf = new AM.Typeface(
                    text.Style.TextStyle.FontName,
                    text.Style.TextStyle.FontSize * _textScaleFactor,
                    fontStyle,
                    fontWeight);

                var ft = new AM.FormattedText()
                {
                    Typeface      = tf,
                    Text          = tbind,
                    TextAlignment = AM.TextAlignment.Left,
                    Wrapping      = AM.TextWrapping.NoWrap
                };

                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);
            }
        }
Пример #5
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);
     }
 }