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); }
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); }
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); }
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); }
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); }
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); }
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; }
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); }
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; } } }
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); }
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); } } }
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); } }
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); } } }
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; } }
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(); } }
public void DrawClosedCurve(AbstractPen pen, PointF[] points, float tension) { DrawClosedCurve(pen, null, points, tension); }
public void Apply(AbstractPen pen, AbstractBrush brush) { Apply(pen); Apply(brush); }
public void DrawRectangle(AbstractPen pen, RectangleF rect) { DrawRectangle(pen, null, rect.X, rect.Y, rect.Width, rect.Height); }
public void DrawEllipse(AbstractPen pen, float x, float y, float width, float height) { DrawEllipse(pen, null, x, y, width, height); }
public void DrawLine(AbstractPen pen, PointF pt1, PointF pt2) { DrawLine(pen, pt1.X, pt1.Y, pt2.X, pt2.Y); }
public void DrawPath(AbstractPen pen, AbstractPath path) { DrawPath(pen, null, path); }
public void DrawCurve(AbstractPen pen, PointF[] points, float tension) { Apply(pen); g.DrawCurve(this.pen, points, tension); }
public void DrawPath(AbstractPen pen, AbstractPath path) { Apply(pen); g.DrawPath(this.pen, new GraphicsPath(path.Points, path.Types, FillMode.Winding)); }
public void DrawRectangle(AbstractPen pen, RectangleF rect) { Apply(pen); g.DrawRectangle(this.pen, rect.X, rect.Y, rect.Width, rect.Height); }
public void DrawClosedCurve(AbstractPen pen, PointF[] points, float tension) { Apply(pen); g.DrawClosedCurve(this.pen, points, tension, FillMode.Winding); }
public void DrawEllipse(AbstractPen pen, float x, float y, float width, float height) { Apply(pen); g.DrawEllipse(this.pen, x, y, width, height); }
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); }
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); }
private void Apply(AbstractPen pen, AbstractBrush brush) { Apply(pen); Apply(brush); }
public void DrawLines(AbstractPen pen, PointF[] points) { Apply(pen); g.DrawLines(this.pen, points); }