Ejemplo n.º 1
0
        public static void DrawLabel(AbstractGraphics g, string text, PointF center, AbstractFont font, AbstractBrush brush, LabelStyle labelStyle)
        {
            using (g.Save())
            {
                if (labelStyle.Uppercase)
                {
                    text = text.ToUpper();
                }
                if (labelStyle.Wrap)
                {
                    text = text.Replace(' ', '\n');
                }

                g.TranslateTransform(center.X, center.Y);
                g.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY);

                g.TranslateTransform(labelStyle.Translation.X, labelStyle.Translation.Y);
                g.RotateTransform(labelStyle.Rotation);
                g.ScaleTransform(labelStyle.Scale.Width, labelStyle.Scale.Height);

                if (labelStyle.Rotation != 0 && g.Graphics != null)
                {
                    g.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                }

                DrawString(g, text, font, brush, 0, 0);
            }
        }
Ejemplo n.º 2
0
        internal void DrawName(AbstractGraphics graphics, RectangleF rect, AbstractFont font, AbstractBrush textBrush, LabelStyle labelStyle)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            RectangleF bounds = TransformedBounds;

            if (bounds.IntersectsWith(rect))
            {
                if (Name != null)
                {
                    string str = Name;
                    if (labelStyle.Uppercase)
                    {
                        str = str.ToUpperInvariant();
                    }

                    PointF pos = NamePosition;// PointF( bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2 );

                    using (graphics.Save())
                    {
                        graphics.TranslateTransform(pos.X, pos.Y);
                        graphics.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY);
                        graphics.RotateTransform(-labelStyle.Rotation); // Rotate it

                        RenderUtil.DrawString(graphics, str, font, textBrush, 0, 0);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void DrawString(AbstractGraphics g, string text, AbstractFont font, AbstractBrush brush, float x, float y, TextFormat format = TextFormat.Center)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            var lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
            var sizes = lines.Select(s => g.MeasureString(s, font)).ToList();

            float fontUnitsToWorldUnits = font.Size / font.FontFamily.GetEmHeight(font.Style);
            float lineSpacing           = font.FontFamily.GetLineSpacing(font.Style) * fontUnitsToWorldUnits;
            float ascent = font.FontFamily.GetCellAscent(font.Style) * fontUnitsToWorldUnits;
            //float descent = font.FontFamily.GetCellDescent(font.Style) * fontUnitsToWorldUnits;

            SizeF boundingSize = new SizeF(sizes.Max(s => s.Width), lineSpacing * sizes.Count());

            // Offset from baseline to top-left.
            y += lineSpacing / 2;

            float widthFactor = 0;

            switch (format)
            {
            case TextFormat.MiddleLeft:
            case TextFormat.Center:
            case TextFormat.MiddleRight:
                y -= boundingSize.Height / 2;
                break;

            case TextFormat.BottomLeft:
            case TextFormat.BottomCenter:
            case TextFormat.BottomRight:
                y -= boundingSize.Height;
                break;
            }

            switch (format)
            {
            case TextFormat.TopCenter:
            case TextFormat.Center:
            case TextFormat.BottomCenter:
                widthFactor = -0.5f;
                break;

            case TextFormat.TopRight:
            case TextFormat.MiddleRight:
            case TextFormat.BottomRight:
                widthFactor = -1;
                break;
            }

            lines.ForEachZip(sizes, (line, sz) =>
            {
                g.DrawString(line, font, brush, x + widthFactor * sz.Width + sz.Width / 2, y, Graphics.StringAlignment.Centered);
                y += lineSpacing;
            });
        }
Ejemplo n.º 4
0
        internal void Paint(AbstractGraphics graphics, Color dotColor, AbstractBrush labelBrush, AbstractFont labelFont)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            Point pt = Astrometrics.LocationToCoordinates(Location);

            using (graphics.Save())
            {
                graphics.TranslateTransform(pt.X, pt.Y);
                graphics.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY);

                const float radius = 3;

                AbstractBrush brush = new AbstractBrush(dotColor);
                AbstractPen   pen   = new AbstractPen(dotColor);
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.DrawEllipse(pen, brush, -radius / 2, -radius / 2, radius, radius);

                RenderUtil.TextFormat format;
                if (LabelBiasX > 0)
                {
                    format = LabelBiasY < 0 ? RenderUtil.TextFormat.BottomLeft : LabelBiasY > 0 ? RenderUtil.TextFormat.TopLeft : RenderUtil.TextFormat.MiddleLeft;
                }
                else if (LabelBiasX < 0)
                {
                    format = LabelBiasY < 0 ? RenderUtil.TextFormat.BottomRight : LabelBiasY > 0 ? RenderUtil.TextFormat.TopRight : RenderUtil.TextFormat.MiddleRight;
                }
                else
                {
                    format = LabelBiasY < 0 ? RenderUtil.TextFormat.BottomCenter : LabelBiasY > 0 ? RenderUtil.TextFormat.TopCenter : RenderUtil.TextFormat.Center;
                }

                float y = (LabelBiasY * radius / 2);
                float x = (LabelBiasX * radius / 2);

                RenderUtil.DrawString(graphics, Name, labelFont, labelBrush, x, y, format);
            }
        }