Ejemplo n.º 1
0
        public override void Render(ISurface surface)
        {
            var contextSurface = (ContextSurface)surface;

            if (string.IsNullOrEmpty(this.Text))
            {
                return;
            }

            var matrix = contextSurface.Matrix;

            if (matrix.M11 < 0.2d || matrix.M22 < 0.2d)
            {
                return;
            }

            var ctx   = contextSurface.Context;
            var style = this.Style;
            var shape = this.OuterShape;
            var font  = Style.Font;

            if (AlignText && shape is IVectorShape)
            {
                var vector = ((IVectorShape)shape).Data;

                var f     = ctx.DpiFactor();
                var width = Vector.Length(vector);

                var height = Math.Ceiling(font.Size);

                var text = new TextLayout(ctx);
                text.Trimming = TextTrimming.WordElipsis;
                text.Text     = this.Text;
                text.Font     = font;
                var size = text.GetSize();
                width       = Math.Min(size.Width, width);
                height      = Math.Max(size.Height, height);
                text.Width  = width;
                text.Height = height;

                var c = new Point(
                    (vector.Start.X + (vector.End.X - vector.Start.X) / 2d),
                    (vector.Start.Y + (vector.End.Y - vector.Start.Y) / 2d));

                ctx.Save();
                ctx.Translate(c.X, c.Y);
                ctx.Rotate(Vector.Angle(vector));

                ctx.SetColor(style.TextColor);
                ctx.SetLineWidth(1);
                ctx.DrawTextLayout(text, -width / 2d, -height / 2d);
                ctx.Restore();
            }
            else
            {
                var rect = shape.BoundsRect.Padding(Style.Padding);
                ContextPainterExtensions.DrawText(ctx, rect, this.Text, font, style.TextColor);
            }
        }
Ejemplo n.º 2
0
        protected virtual void SetRoundedRect(Context ctx, Rectangle rectangle, double radius)
        {
            // if corner radius is less than or equal to zero,
            // return the original Rectangle
            if (radius <= 0.0d)
            {
                ctx.Rectangle(rectangle);
                return;
            }

            // if the corner radius is greater than or equal to
            // half the width, or height (whichever is shorter)
            // then return a capsule instead of a lozenge
            if (radius >= (Math.Min(rectangle.Width, rectangle.Height)) / 2.0)
            {
                DrawCapsule(ctx, rectangle);
                return;
            }

            ContextPainterExtensions.DrawRoundedRect(ctx, rectangle, radius);

            ctx.ClosePath();
        }