Exemple #1
0
 private static Color ToGdi(Styles.Color color)
 {
     return(Color.FromArgb(color.A, color.R, color.G, color.B));
 }
Exemple #2
0
 private void Render(Graphics graphics, IViewport viewport, IEnumerable <ILayer> layers, Styles.Color background = null)
 {
     VisibleFeatureIterator.IterateLayers(graphics, viewport, layers, RenderFeature);
 }
        /// <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)
        {
            SizeF fontSize = graphics.MeasureString(text, font.ToBitmap()); //Calculate the size of the text

            labelPoint.X += offset.X; labelPoint.Y += offset.Y;             //add label offset
            if (rotation != 0 && !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.ToBitmap() != Brushes.Transparent)
                {
                    graphics.FillRectangle(backcolor.ToBitmap(), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                }
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToBitmap().Style, font.ToBitmap().Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                {
                    graphics.DrawPath(halo.ToBitmap(), path);
                }
                graphics.FillPath(new SolidBrush(forecolor.ToBitmap()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.ToBitmap() != Brushes.Transparent)
                {
                    graphics.FillRectangle(backcolor.ToBitmap(), (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.ToBitmap().Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                {
                    graphics.DrawPath(halo.ToBitmap(), path);
                }
                graphics.FillPath(new SolidBrush(forecolor.ToBitmap()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Exemple #4
0
 public void Render(object target, IViewport viewport, IEnumerable <ILayer> layers, Styles.Color background = null)
 {
     Render((Graphics)target, viewport, layers, background);
 }