/// <summary> /// Renders a label to the map. /// </summary> /// <param name="graphics">Graphics reference</param> /// <param name="labelPoint">Label placement</param> /// <param name="offset">Offset of label in screen coordinates</param> /// <param name="font">Font used for rendering</param> /// <param name="forecolor">Font forecolor</param> /// <param name="backcolor">Background color</param> /// <param name="halo">Color of halo</param> /// <param name="rotation">Text rotation in degrees</param> /// <param name="text">Text to render</param> /// <param name="viewport"></param> public static void DrawLabel(Graphics graphics, Point labelPoint, Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport, StyleContext context) { SizeF fontSize = graphics.MeasureString(text, font.ToGdi(context)); //Calculate the size of the text labelPoint.X += offset.X; labelPoint.Y += offset.Y; //add label offset if (Math.Abs(rotation) > Constants.Epsilon && !double.IsNaN(rotation)) { graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y); graphics.RotateTransform((float)rotation); graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2); if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent) graphics.FillRectangle(backcolor.ToGdi(context), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f); var path = new GraphicsPath(); path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToGdi(context).Style, font.ToGdi(context).Size, new System.Drawing.Point(0, 0), null); if (halo != null) graphics.DrawPath(halo.ToGdi(context), path); graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0); } else { if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent) graphics.FillRectangle(backcolor.ToGdi(context), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f); var path = new GraphicsPath(); //Arial hack path.AddString(text, new FontFamily("Arial"), (int)font.ToGdi(context).Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null); if (halo != null) graphics.DrawPath(halo.ToGdi(context), path); graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path); //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y); } }