Пример #1
0
 public System.Drawing.Font GetFont(Styles.Font font)
 {
     System.Drawing.Font gdiFont;
     if (!fonts.TryGetValue(font, out gdiFont))
     {
         gdiFont = new System.Drawing.Font(font.FontFamily, (float)font.Size);
     }
     return(gdiFont);
 }
Пример #2
0
        private static SKPaint CreateTextPaint(SKPaintStyle style, float scale, Styles.Font font)
        {
            SKPaint paint = new SKPaint();

            paint.LcdRenderText = true;
            paint.Style         = style;
            paint.IsAntialias   = true;

            return(paint);
        }
Пример #3
0
        /// <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, Styles.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.Convert()); //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.Convert() != Brushes.Transparent)
                {
                    graphics.FillRectangle(backcolor.Convert(), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                }
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.Convert().Style, font.Convert().Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                {
                    graphics.DrawPath(halo.Convert(), path);
                }
                graphics.FillPath(new SolidBrush(forecolor.Convert()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.Convert() != Brushes.Transparent)
                {
                    graphics.FillRectangle(backcolor.Convert(), (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.Convert().Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                {
                    graphics.DrawPath(halo.Convert(), path);
                }
                graphics.FillPath(new SolidBrush(forecolor.Convert()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }