Exemple #1
0
        public void DrawText(object dc, IStyle style, XText text)
        {
            var foreground = new SolidColorBrush(
                Color.FromArgb(
                    (byte)style.Stroke.A,
                    (byte)style.Stroke.R,
                    (byte)style.Stroke.G,
                    (byte)style.Stroke.B));

            foreground.Freeze();

            var ft = new FormattedText(
                text.Bind(Database),
                System.Globalization.CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                new Typeface(text.FontName),
                text.FontSize,
                foreground,
                null,
                TextFormattingMode.Ideal);

            double x = text.X;
            double y = text.Y;

            switch (text.HAlignment)
            {
            case HAlignment.Left:
                break;

            case HAlignment.Center:
                x += text.Width / 2.0 - ft.Width / 2.0;
                break;

            case HAlignment.Right:
                x += text.Width - ft.Width;
                break;
            }

            switch (text.VAlignment)
            {
            case VAlignment.Top:
                break;

            case VAlignment.Center:
                y += text.Height / 2.0 - ft.Height / 2.0;
                break;

            case VAlignment.Bottom:
                y += text.Height - ft.Height;
                break;
            }

            if (text.IsFilled)
            {
                var background = new SolidColorBrush(
                    Color.FromArgb(
                        (byte)style.Fill.A,
                        (byte)style.Fill.R,
                        (byte)style.Fill.G,
                        (byte)style.Fill.B));
                background.Freeze();

                (dc as DrawingContext).DrawRectangle(
                    background,
                    null,
                    new Rect(
                        text.X,
                        text.Y,
                        text.Width,
                        text.Height));
            }

            (dc as DrawingContext).DrawText(
                ft,
                new Point(x, y));
        }