Esempio n. 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);
     }
 }
Esempio n. 2
0
        public override void Render(DrawingContext context)
        {
            var y = 0.0;

            for (var i = (int)_offset.Y; i < itemCount; ++i)
            {
                using (var line = new FormattedText(
                    "Item " + (i + 1),
                    TextBlock.GetFontFamily(this),
                    TextBlock.GetFontSize(this),
                    TextBlock.GetFontStyle(this),
                    TextAlignment.Left,
                    TextBlock.GetFontWeight(this)))
                {
                    context.DrawText(Brushes.Black, new Point(-_offset.X, y), line);
                    y += _lineSize.Height;
                }
            }
        }
Esempio n. 3
0
        public Form1()
        {
            InitializeComponent();

            _render = new PlatformRenderInterface();
            PerspexLocator.CurrentMutable.Bind<IPlatformRenderInterface>().ToConstant(_render);
            _geometry =  new StreamGeometry();
            _rbitmap = new RenderTargetBitmap(50, 50);
            _renderTarget = _render.CreateRenderer(new PlatformHandle(Handle, "HWND"), ClientSize.Width,
                ClientSize.Height);
            var timer = new Timer() {Interval = 20};
            timer.Tick += delegate { Invalidate(); };
            timer.Start();
            components.Add(timer);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            using (var ctx = _geometry.Open())
            {
                ctx.BeginFigure(new Point(10,10), true);
                ctx.LineTo(new Point(40,25));
                ctx.BezierTo(new Point(50, 45), new Point(43, 48), new Point(20, 90));
                ctx.LineTo(new Point(10, 60));
                ctx.EndFigure(true);
            }

            _text =
                new FormattedText(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
                    "Arial", 25, FontStyle.Normal, TextAlignment.Left, FontWeight.Normal);

            _text.Constraint = new Size(400, double.PositiveInfinity);

            using (var ctx = _rbitmap.CreateDrawingContext())
                ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Aqua)), new Rect(10, 10, 30, 30), 5);

            _bitmap = new Bitmap(@"C:\Users\keks\Desktop\phoenix.png");
        }
Esempio n. 4
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();
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Draws text.
 /// </summary>
 /// <param name="foreground">The foreground brush.</param>
 /// <param name="origin">The upper-left corner of the text.</param>
 /// <param name="text">The text.</param>
 public void DrawText(Brush foreground, Point origin, FormattedText text)
     => _impl.DrawText(foreground, origin, text);
Esempio n. 6
0
        /// <summary>
        /// Draws text.
        /// </summary>
        /// <param name="foreground">The foreground brush.</param>
        /// <param name="origin">The upper-left corner of the text.</param>
        /// <param name="text">The text.</param>
        public void DrawText(Brush foreground, Point origin, FormattedText text)
        {
            var layout = ((FormattedTextImpl)text.PlatformImpl).Layout;
            _context.MoveTo(origin.X, origin.Y);

			using (var b = SetBrush(foreground, new Size(0, 0))) 
			{
				Pango.CairoHelper.ShowLayout(_context, layout);
			}
        }
Esempio n. 7
0
        /// <summary>
        /// Draws text.
        /// </summary>
        /// <param name="foreground">The foreground brush.</param>
        /// <param name="origin">The upper-left corner of the text.</param>
        /// <param name="text">The text.</param>
        public void DrawText(Perspex.Media.Brush foreground, Point origin, FormattedText text)
        {
            if (!string.IsNullOrEmpty(text.Text))
            {
                var impl = (FormattedTextImpl)text.PlatformImpl;

                using (var brush = CreateBrush(foreground, impl.Measure()))
                using (var renderer = new PerspexTextRenderer(this, _renderTarget, brush.PlatformBrush))
                {
                    if (brush.PlatformBrush != null)
                    {
                        impl.TextLayout.Draw(renderer, (float)origin.X, (float)origin.Y);
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Invalidates <see cref="FormattedText"/>.
        /// </summary>
        protected void InvalidateFormattedText()
        {
            if (_formattedText != null)
            {
                _constraint = _formattedText.Constraint;
                _formattedText.Dispose();
                _formattedText = null;
            }

            InvalidateMeasure();
        }
Esempio n. 9
0
 /// <summary>
 /// Creates the <see cref="FormattedText"/> used to render the text.
 /// </summary>
 /// <param name="constraint">The constraint of the text.</param>
 /// <returns>A <see cref="FormattedText"/> object.</returns>
 protected virtual FormattedText CreateFormattedText(Size constraint)
 {
     var result = new FormattedText(
         Text,
         FontFamily,
         FontSize,
         FontStyle,
         TextAlignment,
         FontWeight);
     result.Constraint = constraint;
     return result;
 }
Esempio n. 10
0
        /// <summary>
        /// Invalidates <see cref="FormattedText"/>.
        /// </summary>
        protected void InvalidateFormattedText()
        {
            if (this.formattedText != null)
            {
                this.constraint = this.formattedText.Constraint;
                this.formattedText.Dispose();
                this.formattedText = null;
            }

            this.InvalidateMeasure();
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
 void UpdateText(int fps)
 {
     _text?.Dispose();
     _text = new FormattedText("FPS: " + fps, "Arial", 15, FontStyle.Normal, TextAlignment.Left,
         FontWeight.Normal);
 }
Esempio n. 13
0
 /// <summary>
 /// Creates the <see cref="FormattedText"/> used to render the text.
 /// </summary>
 /// <param name="constraint">The constraint of the text.</param>
 /// <returns>A <see cref="FormattedText"/> object.</returns>
 protected virtual FormattedText CreateFormattedText(Size constraint)
 {
     var result = new FormattedText(
         Text ?? string.Empty,
         FontFamily ?? "Arial",
         FontSize > 0 ? FontSize : 12,
         FontStyle,
         TextAlignment,
         FontWeight);
     result.Constraint = constraint;
     return result;
 }
Esempio n. 14
0
 /// <summary>
 /// Draws text.
 /// </summary>
 /// <param name="foreground">The foreground brush.</param>
 /// <param name="origin">The upper-left corner of the text.</param>
 /// <param name="text">The text.</param>
 public void DrawText(Brush foreground, Point origin, FormattedText text)
 => _impl.DrawText(foreground, origin, text);
Esempio n. 15
0
 /// <summary>
 /// Creates the <see cref="FormattedText"/> used to render the text.
 /// </summary>
 /// <param name="constraint">The constraint of the text.</param>
 /// <returns>A <see cref="FormattedText"/> object.</returns>
 protected override FormattedText CreateFormattedText(Size constraint)
 {
     var result = new FormattedText(
         StripAccessKey(Text),
         FontFamily,
         FontSize,
         FontStyle,
         TextAlignment,
         FontWeight);
     result.Constraint = constraint;
     return result;
 }
Esempio n. 16
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);
 }
Esempio n. 17
0
        /// <summary>
        /// Draws text.
        /// </summary>
        /// <param name="foreground">The foreground brush.</param>
        /// <param name="origin">The upper-left corner of the text.</param>
        /// <param name="text">The text.</param>
        public void DrawText(Perspex.Media.Brush foreground, Perspex.Point origin, FormattedText text)
        {
            if (!string.IsNullOrEmpty(text.Text))
            {
                var impl = (FormattedTextImpl)text.PlatformImpl;

                using (var renderer = new PerspexTextRenderer(this.renderTarget, foreground.ToDirect2D(this.renderTarget)))
                {
                    impl.TextLayout.Draw(renderer, (float)origin.X, (float)origin.Y);
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Draws text.
        /// </summary>
        /// <param name="foreground">The foreground brush.</param>
        /// <param name="origin">The upper-left corner of the text.</param>
        /// <param name="text">The text.</param>
        public void DrawText(Brush foreground, Point origin, FormattedText text)
        {
            var layout = ((FormattedTextImpl)text.PlatformImpl).Layout;
            this.SetBrush(foreground);

            this.context.MoveTo(origin.X, origin.Y);
            Pango.CairoHelper.ShowLayout(this.context, layout);
        }