public void DrawLine(Point start, Point end, double thickness) { Pen newPen = new Pen(Brushes.Black, thickness); newPen.StartLineCap = PenLineCap.Square; newPen.EndLineCap = PenLineCap.Square; Context.DrawLine(newPen, start.ToWinPoint(), end.ToWinPoint()); }
public void DrawLine(Point start, Point end, double thickness) { image.Mutate(ctx => ctx.DrawLines(Black, 2.0f, new[] { new PointF((float)start.X, (float)start.Y), new PointF((float)end.X, (float)end.Y) })); }
public void DrawPath(Point start, IList <IPathCommand> commands, double thickness, bool fill = false) { Pen newPen = new System.Windows.Media.Pen(Brushes.Black, thickness); newPen.StartLineCap = PenLineCap.Square; newPen.EndLineCap = PenLineCap.Square; Context.DrawGeometry((fill ? Brushes.Black : null), newPen, RenderHelper.GetGeometry(start.ToWinPoint(), commands, fill)); }
public void DrawLine(Point start, Point end, double thickness) { image.DrawLines(Black, 2.0f, new[] { new Vector2((float)start.X, (float)start.Y), new Vector2((float)end.X, (float)end.Y) }); }
public void DrawRectangle(Point start, Size size, double thickness, bool fill = false) { image.DrawPolygon(Black, 2.0f, new[] { new Vector2((float)start.X, (float)start.Y), new Vector2((float)start.X + (float)size.Width, (float)start.Y), new Vector2((float)start.X + (float)size.Width, (float)start.Y + (float)size.Height), new Vector2((float)start.X, (float)start.Y + (float)size.Height) }); }
public void DrawRectangle(Point start, Size size, double thickness, bool fill = false) { image.Mutate(ctx => ctx.DrawPolygon(Black, (float)thickness, new[] { new PointF((float)start.X, (float)start.Y), new PointF((float)start.X + (float)size.Width, (float)start.Y), new PointF((float)start.X + (float)size.Width, (float)start.Y + (float)size.Height), new PointF((float)start.X, (float)start.Y + (float)size.Height) })); }
public void DrawText(Point anchor, TextAlignment alignment, IList <TextRun> textRuns) { var font = new Font(SystemFonts.Find("Arial"), 12); image.Mutate(ctx => { foreach (var textRun in textRuns) { ctx.DrawText(textRun.Text, font, Black, anchor.ToPointF()); } }); }
public void DrawPath(Point start, IList <IPathCommand> commands, double thickness, bool fill = false) { // Not supported var builder = new PathBuilder(); builder.SetOrigin(new PointF((float)start.X, (float)start.Y)); builder.StartFigure(); PointF currentPoint = new PointF(); foreach (var c in commands) { switch (c) { case LineTo line: { builder.AddLine(currentPoint, line.End.ToPointF()); break; } case CurveTo curve: { builder.AddBezier(currentPoint, curve.ControlStart.ToPointF(), curve.ControlEnd.ToPointF(), curve.End.ToPointF()); break; } case MoveTo move: { builder.StartFigure(); break; } case QuadraticBeizerCurveTo curve: { builder.AddBezier(currentPoint, curve.Control.ToPointF(), curve.End.ToPointF()); break; } case ClosePath close: { builder.CloseFigure(); break; } } currentPoint = c.End.ToPointF(); } image.Mutate(ctx => ctx.Draw(Black, 2.0f, builder.Build())); }
public static PointF ToPointF(this Point point) { return(new PointF((float)point.X, (float)point.Y)); }
public void DrawText(Point anchor, TextAlignment alignment, IList <TextRun> textRuns) { var font = new Font(fontFamily, 12); image.Mutate(ctx => { float totalWidth = 0f; float totalHeight = 0f; foreach (TextRun run in textRuns) { Font renderFont = font; if (run.Formatting.FormattingType == TextRunFormattingType.Subscript) { renderFont = new Font(font.Family, font.Size / 1.5f); } var dimensions = TextMeasurer.MeasureBounds(run.Text, new RendererOptions(renderFont)); totalWidth += dimensions.Width; totalHeight = Math.Max(totalHeight, dimensions.Bottom); } var startLocation = anchor.ToPointF(); if (alignment == TextAlignment.TopCentre || alignment == TextAlignment.CentreCentre || alignment == TextAlignment.BottomCentre) { startLocation.X -= totalWidth / 2; } else if (alignment == TextAlignment.TopRight || alignment == TextAlignment.CentreRight || alignment == TextAlignment.BottomRight) { startLocation.X -= totalWidth; } if (alignment == TextAlignment.CentreLeft || alignment == TextAlignment.CentreCentre || alignment == TextAlignment.CentreRight) { startLocation.Y -= totalHeight / 2; } else if (alignment == TextAlignment.BottomLeft || alignment == TextAlignment.BottomCentre || alignment == TextAlignment.BottomRight) { startLocation.Y -= totalHeight; } float horizontalOffsetCounter = 0; foreach (TextRun run in textRuns) { var renderFont = font; var renderLocation = new PointF(startLocation.X + horizontalOffsetCounter, startLocation.Y); if (run.Formatting.FormattingType == TextRunFormattingType.Subscript) { renderFont = new Font(font.Family, font.Size / 1.5f); renderLocation.X = renderLocation.X + 3f; } else if (run.Formatting.FormattingType == TextRunFormattingType.Superscript) { renderFont = new Font(font.Family, font.Size / 1.5f); renderLocation.X = renderLocation.X - 3f; } ctx.DrawText(run.Text, font, NamedColors <Argb32> .Black, renderLocation); horizontalOffsetCounter += TextMeasurer.MeasureBounds(run.Text, new RendererOptions(renderFont)).Width; } }); }
public void DrawText(Point anchor, Drawing.Text.TextAlignment alignment, IList <TextRun> textRuns) { double totalWidth = 0d; double totalHeight = 0d; foreach (TextRun run in textRuns) { FormattedText ft = new FormattedText(run.Text, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(RenderHelper.CircuitFont()), run.Formatting.Size, Brushes.Black); if (run.Formatting.FormattingType == TextRunFormattingType.Subscript) { ft = new FormattedText(run.Text, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(RenderHelper.CircuitFont()), run.Formatting.Size / 1.5, Brushes.Black); } totalWidth += ft.Width; if (ft.Height > totalHeight) { totalHeight = ft.Height; } } var renderLocation = anchor.ToWinPoint(); if (alignment == TextAlignment.TopCentre || alignment == TextAlignment.CentreCentre || alignment == TextAlignment.BottomCentre) { renderLocation.X -= totalWidth / 2; } else if (alignment == TextAlignment.TopRight || alignment == TextAlignment.CentreRight || alignment == TextAlignment.BottomRight) { renderLocation.X -= totalWidth; } if (alignment == TextAlignment.CentreLeft || alignment == TextAlignment.CentreCentre || alignment == TextAlignment.CentreRight) { renderLocation.Y -= totalHeight / 2; } else if (alignment == TextAlignment.BottomLeft || alignment == TextAlignment.BottomCentre || alignment == TextAlignment.BottomRight) { renderLocation.Y -= totalHeight; } double horizontalOffsetCounter = 0; foreach (TextRun run in textRuns) { if (run.Formatting.FormattingType == TextRunFormattingType.Normal) { FormattedText formattedText = new FormattedText(run.Text, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(RenderHelper.CircuitFont()), run.Formatting.Size, Brushes.Black); Context.DrawText(formattedText, System.Windows.Point.Add(renderLocation, new Vector(horizontalOffsetCounter, 0d))); horizontalOffsetCounter += formattedText.Width; } else if (run.Formatting.FormattingType == TextRunFormattingType.Subscript) { FormattedText formattedText = new FormattedText(run.Text, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(RenderHelper.CircuitFont()), run.Formatting.Size / 1.5, Brushes.Black); Context.DrawText(formattedText, System.Windows.Point.Add(renderLocation, new Vector(horizontalOffsetCounter, totalHeight - formattedText.Height))); horizontalOffsetCounter += formattedText.Width; } else if (run.Formatting.FormattingType == TextRunFormattingType.Superscript) { FormattedText formattedText = new FormattedText(run.Text, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(RenderHelper.CircuitFont()), run.Formatting.Size / 1.5, Brushes.Black); Context.DrawText(formattedText, System.Windows.Point.Add(renderLocation, new Vector(horizontalOffsetCounter, -3d))); horizontalOffsetCounter += formattedText.Width; } } }
public void DrawEllipse(Point centre, double radiusX, double radiusY, double thickness, bool fill = false) { Pen.Thickness = thickness; Context.DrawEllipse(fill ? Brushes.Black : null, Pen, centre.ToWinPoint(), radiusX, radiusY); }
public void DrawText(Point anchor, TextAlignment alignment, IList <TextRun> textRuns) { // Not supported }
public void DrawPath(Point start, IList <IPathCommand> commands, double thickness, bool fill = false) { // Not supported }
public void DrawEllipse(Point centre, double radiusX, double radiusY, double thickness, bool fill = false) { // Not supported }
public void DrawEllipse(Point centre, double radiusX, double radiusY, double thickness, bool fill = false) { image.Mutate(ctx => ctx.Draw(Black, 2.0f, new EllipsePolygon(centre.ToPointF(), new SizeF((float)radiusX * 2, (float)radiusY * 2)))); }
public void DrawRectangle(Point start, Size size, double thickness, bool fill = false) { Pen.Thickness = thickness; Context.DrawRectangle(fill ? Brushes.Black : null, Pen, new Rect(start.ToWinPoint(), size.ToWinSize())); }