private void DrawText(MapGraphics g, bool drawShadow)
        {
            if (string.IsNullOrEmpty(Text))
            {
                return;
            }
            RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
            string     text = Text;

            _    = Font;
            text = text.Replace("\\n", "\n");
            StringFormat      stringFormat      = GetStringFormat();
            TextRenderingHint textRenderingHint = g.TextRenderingHint;
            float             num = DetermineAngle();

            if (num % 90f != 0f)
            {
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
            }
            Brush brush = null;

            brush = ((!drawShadow) ? new SolidBrush(TextColor) : g.GetShadowBrush());
            try
            {
                if (num != 0f)
                {
                    RectangleF layoutRectangle = DetermineTextRectangle(g, stringFormat);
                    PointF     point           = new PointF(layoutRectangle.X + layoutRectangle.Width / 2f, layoutRectangle.Y + layoutRectangle.Height / 2f);
                    Matrix     transform       = g.Transform;
                    Matrix     matrix          = g.Transform.Clone();
                    matrix.RotateAt(num, point, MatrixOrder.Prepend);
                    if (drawShadow)
                    {
                        matrix.Translate(TextShadowOffset, TextShadowOffset, MatrixOrder.Append);
                    }
                    g.Transform = matrix;
                    StringFormat stringFormat2 = new StringFormat();
                    stringFormat2.Alignment     = StringAlignment.Center;
                    stringFormat2.LineAlignment = StringAlignment.Center;
                    stringFormat2.Trimming      = StringTrimming.EllipsisCharacter;
                    layoutRectangle.Inflate(1000f, 1000f);
                    g.DrawString(text, Font, brush, layoutRectangle, stringFormat2);
                    g.Transform = transform;
                }
                else
                {
                    if (drawShadow)
                    {
                        absoluteRectangle.X += TextShadowOffset;
                        absoluteRectangle.Y += TextShadowOffset;
                    }
                    g.DrawString(text, Font, brush, absoluteRectangle, stringFormat);
                }
            }
            finally
            {
                brush?.Dispose();
            }
            g.Graphics.TextRenderingHint = textRenderingHint;
        }
Exemple #2
0
        internal override void Render(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            g.AntiAliasing = AntiAliasing.None;
            RectangleF rectangleF = new RectangleF(GetAbsoluteLocation(), GetAbsoluteSize());

            rectangleF.X      = (float)Math.Round(rectangleF.X);
            rectangleF.Y      = (float)Math.Round(rectangleF.Y);
            rectangleF.Width  = (float)Math.Round(rectangleF.Width);
            rectangleF.Height = (float)Math.Round(rectangleF.Height);
            if (!(rectangleF.Width > 0f) || !(rectangleF.Height > 0f))
            {
                return;
            }
            try
            {
                if (BackShadowOffset != 0)
                {
                    RectangleF rect = rectangleF;
                    rect.Offset(BackShadowOffset, BackShadowOffset);
                    g.FillRectangle(g.GetShadowBrush(), rect);
                }
                using (Brush brush = g.CreateBrush(rectangleF, BackColor, BackHatchStyle, "", MapImageWrapMode.Unscaled, Color.Empty, MapImageAlign.Center, BackGradientType, BackSecondaryColor))
                {
                    g.FillRectangle(brush, rectangleF);
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }
Exemple #3
0
 internal void RenderStaticShadows(MapGraphics g)
 {
     using (GraphicsPath graphicsPath = new GraphicsPath())
     {
         GraphicsPath shadowPath = Scale.GetShadowPath();
         if (shadowPath != null)
         {
             graphicsPath.AddPath(shadowPath, connect: false);
         }
         graphicsPath.FillMode = FillMode.Winding;
         using (Brush brush = g.GetShadowBrush())
         {
             g.FillPath(brush, graphicsPath);
         }
     }
 }
 public void RenderDynamicShadows(MapGraphics g)
 {
     using (GraphicsPath graphicsPath = new GraphicsPath())
     {
         GraphicsPath shadowPath = this.Pointer.GetShadowPath(g);
         if (shadowPath != null)
         {
             graphicsPath.AddPath(shadowPath, false);
         }
         graphicsPath.FillMode = FillMode.Winding;
         using (Brush brush = g.GetShadowBrush())
         {
             g.FillPath(brush, graphicsPath);
         }
     }
 }
        internal virtual void RenderBackground(MapGraphics g)
        {
            AntiAliasing antiAliasing = g.AntiAliasing;

            g.AntiAliasing = AntiAliasing.None;
            RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));

            absoluteRectangle.X      = (float)Math.Round(absoluteRectangle.X);
            absoluteRectangle.Y      = (float)Math.Round(absoluteRectangle.Y);
            absoluteRectangle.Width  = (float)Math.Round(absoluteRectangle.Width);
            absoluteRectangle.Height = (float)Math.Round(absoluteRectangle.Height);
            try
            {
                if (BackShadowOffset != 0)
                {
                    RectangleF rect = absoluteRectangle;
                    rect.Offset(BackShadowOffset, BackShadowOffset);
                    g.FillRectangle(g.GetShadowBrush(), rect);
                }
                if (IsMakeTransparentRequired())
                {
                    using (Brush brush = new SolidBrush(GetColorForMakeTransparent()))
                    {
                        g.FillRectangle(brush, absoluteRectangle);
                    }
                }
                using (Brush brush2 = g.CreateBrush(absoluteRectangle, BackColor, BackHatchStyle, "", MapImageWrapMode.Unscaled, Color.Empty, MapImageAlign.Center, BackGradientType, BackSecondaryColor))
                {
                    g.FillRectangle(brush2, absoluteRectangle);
                }
            }
            finally
            {
                g.AntiAliasing = antiAliasing;
            }
        }
 private void RenderText(MapGraphics g)
 {
     if (!(this.TextInt == string.Empty))
     {
         string text = (this.TextInt.IndexOf("#", StringComparison.Ordinal) == -1) ? this.TextInt : this.GetMapCore().ResolveAllKeywords(this.TextInt, this);
         text = text.Replace("\\n", "\n");
         StringFormat stringFormat = new StringFormat();
         if (this.TextAlignment == ContentAlignment.BottomRight)
         {
             stringFormat.Alignment     = StringAlignment.Near;
             stringFormat.LineAlignment = StringAlignment.Near;
         }
         else if (this.TextAlignment == ContentAlignment.BottomCenter)
         {
             stringFormat.Alignment     = StringAlignment.Center;
             stringFormat.LineAlignment = StringAlignment.Near;
         }
         else if (this.TextAlignment == ContentAlignment.BottomLeft)
         {
             stringFormat.Alignment     = StringAlignment.Far;
             stringFormat.LineAlignment = StringAlignment.Near;
         }
         else if (this.TextAlignment == ContentAlignment.MiddleRight)
         {
             stringFormat.Alignment     = StringAlignment.Near;
             stringFormat.LineAlignment = StringAlignment.Center;
         }
         else if (this.TextAlignment == ContentAlignment.MiddleCenter)
         {
             stringFormat.Alignment     = StringAlignment.Center;
             stringFormat.LineAlignment = StringAlignment.Center;
         }
         else if (this.TextAlignment == ContentAlignment.MiddleLeft)
         {
             stringFormat.Alignment     = StringAlignment.Far;
             stringFormat.LineAlignment = StringAlignment.Center;
         }
         else if (this.TextAlignment == ContentAlignment.TopRight)
         {
             stringFormat.Alignment     = StringAlignment.Near;
             stringFormat.LineAlignment = StringAlignment.Far;
         }
         else if (this.TextAlignment == ContentAlignment.TopCenter)
         {
             stringFormat.Alignment     = StringAlignment.Center;
             stringFormat.LineAlignment = StringAlignment.Far;
         }
         else
         {
             stringFormat.Alignment     = StringAlignment.Far;
             stringFormat.LineAlignment = StringAlignment.Far;
         }
         SizeF  sizeF = g.MeasureString(text, this.Font, new SizeF(0f, 0f), StringFormat.GenericTypographic);
         PointF centerPointInContentPixels = this.GetCenterPointInContentPixels(g);
         new RectangleF(centerPointInContentPixels.X, (float)(centerPointInContentPixels.Y - 1.0), 0f, 0f).Inflate((float)(sizeF.Width / 2.0), (float)(sizeF.Height / 2.0));
         if (this.TextShadowOffset != 0)
         {
             using (Brush brush = g.GetShadowBrush())
             {
                 PointF point = new PointF(centerPointInContentPixels.X + (float)this.TextShadowOffset, centerPointInContentPixels.Y + (float)this.TextShadowOffset);
                 g.DrawString(text, this.Font, brush, point, stringFormat);
             }
         }
         using (Brush brush2 = new SolidBrush(this.TextColor))
         {
             g.DrawString(text, this.Font, brush2, centerPointInContentPixels, stringFormat);
         }
     }
 }