Пример #1
0
        /// <summary>
        /// Invalidates <see cref="FormattedText"/>.
        /// </summary>
        protected void InvalidateFormattedText()
        {
            if (_formattedText != null)
            {
                _constraint = _formattedText.Constraint;
                _formattedText.Dispose();
                _formattedText = null;
            }

            InvalidateMeasure();
        }
Пример #2
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 DrawingContext;

            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.Flags.HasFlag(FontStyleFlags.Italic))
            {
                fontStyle |= Perspex.Media.FontStyle.Italic;
            }

            var fontWeight = Perspex.Media.FontWeight.Normal;

            if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.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.Flags.HasFlag(FontStyleFlags.Underline))
             * {
             *  fontDecoration |= Perspex.Media.FontDecoration.Underline;
             * }
             *
             * if (text.Style.TextStyle.FontStyle.Flags.HasFlag(FontStyleFlags.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();
        }
Пример #3
0
 void UpdateText(int fps)
 {
     _text?.Dispose();
     _text = new FormattedText("FPS: " + fps, "Arial", 15, FontStyle.Normal, TextAlignment.Left,
                               FontWeight.Normal);
 }