Exemplo n.º 1
0
        /// <summary>
        /// Draws an <see cref="InvariantTextPrimitive"/>.
        /// </summary>
        protected override void DrawTextPrimitive(InvariantTextPrimitive textPrimitive)
        {
            textPrimitive.CoordinateSystem = CoordinateSystem.Destination;

            // We adjust the font size depending on the scale so that it's the same size
            // irrespective of the zoom
            var  fontSize = CalculateScaledFontPoints(textPrimitive.SizeInPoints, Dpi);
            Font font     = _fontFactory.CreateFont(textPrimitive.Font, fontSize, FontStyle.Regular, GraphicsUnit.Point, _defaultFont);

            // Calculate how big the text will be so we can set the bounding box
            textPrimitive.Dimensions = Surface.FinalBuffer.Graphics.MeasureString(textPrimitive.Text, font);

            // Draw drop shadow
            _brush.Color = Color.Black;

            SizeF  dropShadowOffset   = new SizeF(1, 1);
            PointF boundingBoxTopLeft = new PointF(textPrimitive.BoundingBox.Left, textPrimitive.BoundingBox.Top);

            Surface.FinalBuffer.Graphics.DrawString(
                textPrimitive.Text,
                font,
                _brush,
                boundingBoxTopLeft + dropShadowOffset);

            // Draw text
            _brush.Color = textPrimitive.Color;

            Surface.FinalBuffer.Graphics.DrawString(
                textPrimitive.Text,
                font,
                _brush,
                boundingBoxTopLeft);

            textPrimitive.ResetCoordinateSystem();
        }
            public override void OnDrawing()
            {
                // upon drawing, re-centre the text
                RectangleF bounds = base.ParentPresentationImage.ClientRectangle;
                PointF     anchor = new PointF(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2);

                _textGraphic.CoordinateSystem = CoordinateSystem.Destination;
                _textGraphic.Location         = anchor;
                _textGraphic.ResetCoordinateSystem();
                base.OnDrawing();
            }
        protected override void OnDrawing()
        {
            // upon drawing, re-centre the text
            RectangleF             bounds      = base.ClientRectangle;
            PointF                 anchor      = new PointF(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2);
            InvariantTextPrimitive textGraphic = (InvariantTextPrimitive)base.ApplicationGraphics.FirstOrDefault(IsType <InvariantTextPrimitive>);

            textGraphic.CoordinateSystem = CoordinateSystem.Destination;
            textGraphic.Location         = anchor;
            textGraphic.ResetCoordinateSystem();
            base.OnDrawing();
        }
 private void DecoratedGraphic_VisualStateChanged(object sender, VisualStateChangedEventArgs e)
 {
     base.DecoratedGraphic.CoordinateSystem = CoordinateSystem.Destination;
     _textGraphic.CoordinateSystem          = CoordinateSystem.Destination;
     try
     {
         RectangleF rectangle = base.DecoratedGraphic.BoundingBox;
         _textGraphic.Location = new PointF(rectangle.Right, rectangle.Top);
     }
     finally
     {
         _textGraphic.ResetCoordinateSystem();
         base.DecoratedGraphic.ResetCoordinateSystem();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Draws a text primitive to the specified destination buffer.
        /// </summary>
        /// <param name="buffer">The destination buffer.</param>
        /// <param name="gdiObjectFactory">A factory for GDI+ objects.</param>
        /// <param name="text">The text primitive to be drawn.</param>
        /// <param name="dpi">The intended output DPI.</param>
        public static void DrawTextPrimitive(IGdiBuffer buffer, IGdiObjectFactory gdiObjectFactory, InvariantTextPrimitive text, float dpi = _nominalScreenDpi)
        {
            text.CoordinateSystem = CoordinateSystem.Destination;
            try
            {
                // We adjust the font size depending on the scale so that it's the same size
                // irrespective of the zoom
                var fontSize       = CalculateScaledFontPoints(text.SizeInPoints, dpi);
                var createFontArgs = new CreateFontArgs(text.Font, fontSize, FontStyle.Regular, GraphicsUnit.Point)
                {
                    DefaultFontName = FontFactory.GenericSansSerif
                };
                var font = gdiObjectFactory.CreateFont(createFontArgs);

                // Calculate how big the text will be so we can set the bounding box
                text.Dimensions = buffer.Graphics.MeasureString(text.Text, font);

                // Draw drop shadow
                var brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(Color.Black));

                var dropShadowOffset   = new SizeF(1, 1);
                var boundingBoxTopLeft = new PointF(text.BoundingBox.Left, text.BoundingBox.Top);

                buffer.Graphics.DrawString(
                    text.Text,
                    font,
                    brush,
                    boundingBoxTopLeft + dropShadowOffset);

                // Draw text
                brush = gdiObjectFactory.CreateBrush(new CreateBrushArgs(text.Color));

                buffer.Graphics.DrawString(
                    text.Text,
                    font,
                    brush,
                    boundingBoxTopLeft);
            }
            finally
            {
                text.ResetCoordinateSystem();
            }
        }