コード例 #1
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
        public void DrawArc(AbstractPen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
        {
            // Convert from center to endpoint parameterization
            // https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes

            float rx = width / 2;
            float ry = height / 2;
            float cx = x + rx;
            float cy = y + ry;

            // GDI+ uses angles in degrees, clockwise from x axis
            startAngle = -startAngle * (float)Math.PI / 180;
            sweepAngle = -sweepAngle * (float)Math.PI / 180;

            // Since phi is always 0, conversion is simplified
            const float phi = 0;

            float x1 = rx * (float)Math.Cos(startAngle) + cx;
            float y1 = -ry * (float)Math.Sin(startAngle) + cy;
            float x2 = rx * (float)Math.Cos(startAngle + sweepAngle) + cx;
            float y2 = -ry * (float)Math.Sin(startAngle + sweepAngle) + cy;

            int fA = Math.Abs(sweepAngle) > Math.PI ? 1 : 0;
            int fS = sweepAngle < 0 ? 1 : 0;

            var e    = Append(new Element(ElementNames.PATH));
            var path = new PathBuilder();

            path.MoveTo(x1, y1);
            path.ArcTo(rx, ry, phi, fA, fS, x2, y2);
            e.Set("d", path.ToString());
            e.Apply(pen, null);
        }
コード例 #2
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
        public void DrawCurve(AbstractPen pen, PointF[] points, float tension)
        {
            var e = Append(new Element(ElementNames.PATH));

            e.Set("d", ToSVG(points, tension, false));
            e.Apply(pen, null);
        }
コード例 #3
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
        public void DrawPath(AbstractPen pen, AbstractBrush brush, AbstractPath path)
        {
            var e = Append(new Element(ElementNames.PATH));

            e.Set("d", ToSVG(path));
            e.Apply(pen, brush);
        }
コード例 #4
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
        public void DrawClosedCurve(AbstractPen pen, AbstractBrush brush, PointF[] points, float tension)
        {
            var e = Append(new Element(ElementNames.PATH));

            e.Set("d", ToSVG(points, tension, true));
            e.Apply(pen, brush);
        }
コード例 #5
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
        public void DrawLine(AbstractPen pen, float x1, float y1, float x2, float y2)
        {
            var e = Append(new Element(ElementNames.LINE));

            e.Set("x1", x1);
            e.Set("y1", y1);
            e.Set("x2", x2);
            e.Set("y2", y2);
            e.Apply(pen);
        }
コード例 #6
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
        public void DrawRectangle(AbstractPen pen, AbstractBrush brush, float x, float y, float width, float height)
        {
            var e = Append(new Element(ElementNames.RECT));

            e.Set("x", x);
            e.Set("y", y);
            e.Set("width", width);
            e.Set("height", height);
            e.Apply(pen, brush);
        }
コード例 #7
0
        public void Apply(ref AbstractPen pen)
        {
            if (width == 0f)
            {
                throw new ArgumentOutOfRangeException(nameof(width), width, "Hairline pens not supported, set width > 0");
            }

            pen.Color             = color;
            pen.Width             = width;
            pen.DashStyle         = dashStyle;
            pen.CustomDashPattern = dashPattern;
        }
コード例 #8
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
        public void DrawLines(AbstractPen pen, PointF[] points)
        {
            var e    = Append(new Element(ElementNames.PATH));
            var path = new PathBuilder();

            path.MoveTo(points[0].X, points[0].Y);
            for (var i = 0; i < points.Length; ++i)
            {
                path.LineTo(points[i].X, points[i].Y);
            }
            e.Set("d", path.ToString());
            e.Apply(pen, null);
        }
コード例 #9
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
            public void Apply(AbstractPen pen)
            {
                if (pen == null)
                {
                    Set("stroke", Color.Empty);
                }
                else
                {
                    Set("stroke", pen.Color);
                    Set("stroke-width", pen.Width);

                    switch (pen.DashStyle)
                    {
                    case DashStyle.Solid:
                        // "solid" is SVG default
                        break;

                    case DashStyle.Dot:
                        Set("stroke-dasharray", $"{pen.Width:G2} {pen.Width:G2}");
                        break;

                    case DashStyle.Dash:
                        Set("stroke-dasharray", $"{pen.Width * 2:G2} {pen.Width:G2}");
                        break;

                    case DashStyle.DashDot:
                        Set("stroke-dasharray", $"{pen.Width * 2:G2} {pen.Width:G2} {pen.Width:G2} {pen.Width:G2}");
                        break;

                    case DashStyle.DashDotDot:
                        Set("stroke-dasharray", $"{pen.Width * 2:G2} {pen.Width:G2} {pen.Width:G2} {pen.Width:G2} {pen.Width:G2} {pen.Width:G2}");
                        break;

                    case DashStyle.Custom:
                        if (pen.CustomDashPattern == null)
                        {
                            throw new ApplicationException("Custom dash style specified but no pattern set");
                        }
                        Set("stroke-dasharray",
                            string.Join(" ", pen.CustomDashPattern.Select(w => (w * pen.Width).ToString(NumberFormat))));
                        break;
                    }
                }
            }
コード例 #10
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
        public void DrawEllipse(AbstractPen pen, AbstractBrush brush, float x, float y, float width, float height)
        {
            Element e;

            if (width == height)
            {
                e = Append(new Element(ElementNames.CIRCLE));
                e.Set("r", width / 2);
            }
            else
            {
                e = Append(new Element(ElementNames.ELLIPSE));
                e.Set("rx", width / 2);
                e.Set("ry", height / 2);
            }
            e.Set("cx", x + width / 2);
            e.Set("cy", y + height / 2);
            e.Apply(pen, brush);
        }
コード例 #11
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);
                }
            }
        }
コード例 #12
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);
            }
        }
コード例 #13
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);
                }
            }
        }
コード例 #14
0
        private void Apply(AbstractPen pen)
        {
            this.pen.Color = pen.Color;
            this.pen.Width = pen.Width;
            switch (pen.DashStyle)
            {
            case DashStyle.Solid: this.pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; break;

            case DashStyle.Dot: this.pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; break;

            case DashStyle.Dash: this.pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; break;

            case DashStyle.DashDot: this.pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; break;

            case DashStyle.DashDotDot: this.pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; break;

            case DashStyle.Custom: this.pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; break;
            }
            if (pen.CustomDashPattern != null)
            {
                this.pen.DashPattern = pen.CustomDashPattern;
            }
        }
コード例 #15
0
        private void Apply(AbstractPen pen)
        {
            this.pen.Color = pen.Color;
            this.pen.Width = pen.Width;
            switch (pen.DashStyle)
            {
            case DashStyle.Solid: this.pen.DashStyle = XDashStyle.Solid; break;

            case DashStyle.Dot: this.pen.DashStyle = XDashStyle.Dot; break;

            case DashStyle.Dash: this.pen.DashStyle = XDashStyle.Dash; break;

            case DashStyle.DashDot: this.pen.DashStyle = XDashStyle.DashDot; break;

            case DashStyle.DashDotDot: this.pen.DashStyle = XDashStyle.DashDotDot; break;

            case DashStyle.Custom: this.pen.DashStyle = XDashStyle.Custom; break;
            }
            if (pen.CustomDashPattern != null)
            {
                this.pen.DashPattern = pen.CustomDashPattern.Select(f => (double)f).ToArray();
            }
        }
コード例 #16
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
 public void DrawClosedCurve(AbstractPen pen, PointF[] points, float tension)
 {
     DrawClosedCurve(pen, null, points, tension);
 }
コード例 #17
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
 public void Apply(AbstractPen pen, AbstractBrush brush)
 {
     Apply(pen);
     Apply(brush);
 }
コード例 #18
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
 public void DrawRectangle(AbstractPen pen, RectangleF rect)
 {
     DrawRectangle(pen, null, rect.X, rect.Y, rect.Width, rect.Height);
 }
コード例 #19
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
 public void DrawEllipse(AbstractPen pen, float x, float y, float width, float height)
 {
     DrawEllipse(pen, null, x, y, width, height);
 }
コード例 #20
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
 public void DrawLine(AbstractPen pen, PointF pt1, PointF pt2)
 {
     DrawLine(pen, pt1.X, pt1.Y, pt2.X, pt2.Y);
 }
コード例 #21
0
ファイル: SVGGraphics.cs プロジェクト: 77topaz/travellermap
 public void DrawPath(AbstractPen pen, AbstractPath path)
 {
     DrawPath(pen, null, path);
 }
コード例 #22
0
 public void DrawCurve(AbstractPen pen, PointF[] points, float tension)
 {
     Apply(pen); g.DrawCurve(this.pen, points, tension);
 }
コード例 #23
0
 public void DrawPath(AbstractPen pen, AbstractPath path)
 {
     Apply(pen); g.DrawPath(this.pen, new GraphicsPath(path.Points, path.Types, FillMode.Winding));
 }
コード例 #24
0
 public void DrawRectangle(AbstractPen pen, RectangleF rect)
 {
     Apply(pen); g.DrawRectangle(this.pen, rect.X, rect.Y, rect.Width, rect.Height);
 }
コード例 #25
0
 public void DrawClosedCurve(AbstractPen pen, PointF[] points, float tension)
 {
     Apply(pen); g.DrawClosedCurve(this.pen, points, tension, FillMode.Winding);
 }
コード例 #26
0
 public void DrawEllipse(AbstractPen pen, float x, float y, float width, float height)
 {
     Apply(pen); g.DrawEllipse(this.pen, x, y, width, height);
 }
コード例 #27
0
 public void DrawEllipse(AbstractPen pen, AbstractBrush brush, float x, float y, float width, float height)
 {
     Apply(pen, brush); g.FillEllipse(this.brush, x, y, width, height); g.DrawEllipse(this.pen, x, y, width, height);
 }
コード例 #28
0
 public void DrawArc(AbstractPen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
 {
     Apply(pen); g.DrawArc(this.pen, x, y, width, height, startAngle, sweepAngle);
 }
コード例 #29
0
 private void Apply(AbstractPen pen, AbstractBrush brush)
 {
     Apply(pen); Apply(brush);
 }
コード例 #30
0
 public void DrawLines(AbstractPen pen, PointF[] points)
 {
     Apply(pen); g.DrawLines(this.pen, points);
 }