Exemplo n.º 1
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);
                    }
                }
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     if (g != null)
     {
         g.Restore(this);
         g = null;
     }
 }
Exemplo n.º 4
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;
            });
        }
Exemplo n.º 5
0
        public static void DrawGlyph(AbstractGraphics g, Glyph glyph, FontCache styleRes, AbstractBrush brush, float x, float y)
        {
            Font font;
            string s = glyph.Characters;
            if (g.SupportsWingdings && s.All(c => DING_MAP.ContainsKey(c)))
            {
                s = string.Join("", s.Select(c => DING_MAP[c]));
                font = styleRes.WingdingFont;
            }
            else
            {
                font = styleRes.GlyphFont;
            }

            g.DrawString(s, font, brush, x, y, Maps.Graphics.StringAlignment.Centered);
        }
Exemplo n.º 6
0
        internal void Draw(AbstractGraphics graphics, RectangleF rect, AbstractPen pen)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            RectangleF bounds = TransformedBounds;

            if (bounds.IntersectsWith(rect))
            {
                var path = Path;
                using (graphics.Save())
                {
                    graphics.ScaleTransform(ScaleX, ScaleY);
                    graphics.TranslateTransform(-OriginX, -OriginY);
                    graphics.DrawPath(pen, path);
                }
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        internal void Draw(AbstractGraphics graphics, RectangleF rect, AbstractPen pen)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }

            RectangleF bounds = TransformedBounds;

            if (bounds.IntersectsWith(rect))
            {
                var path = Path;
                using (graphics.Save())
                {
                    XMatrix matrix = new XMatrix();
                    matrix.ScalePrepend(ScaleX, ScaleY);
                    matrix.TranslatePrepend(-OriginX, -OriginY);
                    graphics.MultiplyTransform(matrix);
                    graphics.DrawPath(pen, path);
                }
            }
        }
Exemplo n.º 9
0
        internal void Fill(AbstractGraphics graphics, RectangleF rect, AbstractBrush fillBrush)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            RectangleF bounds = TransformedBounds;

            if (bounds.IntersectsWith(rect))
            {
                var path = Path;

                using (graphics.Save())
                {
                    var matrix = new AbstractMatrix();
                    matrix.ScalePrepend(ScaleX, ScaleY);
                    matrix.TranslatePrepend(-OriginX, -OriginY);
                    graphics.MultiplyTransform(matrix);
                    graphics.DrawPath(fillBrush, path);
                }
            }
        }
Exemplo n.º 10
0
            private static void RenderToGraphics(RenderContext ctx, AbstractMatrix transform, AbstractGraphics graphics)
            {
                graphics.MultiplyTransform(transform);

                if (ctx.DrawBorder && ctx.ClipPath != null)
                {
                    using (graphics.Save())
                    {
                        // Render border in world space
                        AbstractMatrix m = ctx.ImageSpaceToWorldSpace;
                        graphics.MultiplyTransform(m);
                        AbstractPen pen = new AbstractPen(ctx.Styles.imageBorderColor, ctx.Styles.imageBorderWidth);

                        // SVG/PdfSharp can't ExcludeClip so we take advantage of the fact that we know
                        // the path starts on the left edge and proceeds clockwise. We extend the
                        // path with a counterclockwise border around it, then use that to exclude
                        // the original path's region for rendering the border.
                        RectangleF bounds = PathUtil.Bounds(ctx.ClipPath);
                        bounds.Inflate(2 * (float)pen.Width, 2 * (float)pen.Width);
                        List <byte>   types  = new List <byte>(ctx.ClipPath.Types);
                        List <PointF> points = new List <PointF>(ctx.ClipPath.Points);

                        PointF key = points[0];
                        points.Add(new PointF(bounds.Left, key.Y)); types.Add(1);
                        points.Add(new PointF(bounds.Left, bounds.Bottom)); types.Add(1);
                        points.Add(new PointF(bounds.Right, bounds.Bottom)); types.Add(1);
                        points.Add(new PointF(bounds.Right, bounds.Top)); types.Add(1);
                        points.Add(new PointF(bounds.Left, bounds.Top)); types.Add(1);
                        points.Add(new PointF(bounds.Left, key.Y)); types.Add(1);
                        points.Add(new PointF(key.X, key.Y)); types.Add(1);

                        graphics.IntersectClip(new AbstractPath(points.ToArray(), types.ToArray()));
                        graphics.DrawPath(pen, ctx.ClipPath);
                    }
                }

                using (graphics.Save())
                {
                    ctx.Render(graphics);
                }
            }
Exemplo n.º 11
0
 public void Dispose()
 {
     g?.Restore(this);
     g = null;
 }
Exemplo n.º 12
0
 public void Restore()
 {
     g.Restore(this);
     g = null;
 }
Exemplo n.º 13
0
 protected AbstractGraphicsState(AbstractGraphics graphics)
 {
     g = graphics;
 }
Exemplo n.º 14
0
 public State(AbstractGraphics g, GraphicsState state) : base(g)
 {
     this.state = state;
 }
Exemplo n.º 15
0
 public State(AbstractGraphics g, Element e) : base(g)
 {
     element = e;
 }