static Win2D.CanvasGeometry ToWin2dCanvasGeometry(Wcd.Mgcg.CanvasGeometry geometry) { switch (geometry.Type) { case Wcd.Mgcg.CanvasGeometry.GeometryType.Ellipse: var ellipse = (Wcd.Mgcg.CanvasGeometry.Ellipse)geometry; return(Win2D.CanvasGeometry.CreateEllipse( null, ellipse.X, ellipse.Y, ellipse.RadiusX, ellipse.RadiusY)); case Wcd.Mgcg.CanvasGeometry.GeometryType.Group: var group = (Wcd.Mgcg.CanvasGeometry.Group)geometry; var geometries = group.Geometries.Select(g => ToWin2dCanvasGeometry(g)).ToArray(); return(Win2D.CanvasGeometry.CreateGroup( null, geometries, group.FilledRegionDetermination)); case Wcd.Mgcg.CanvasGeometry.GeometryType.Path: using (var builder = new Win2D.CanvasPathBuilder(null)) { var path = (Wcd.Mgcg.CanvasGeometry.Path)geometry; builder.SetFilledRegionDetermination(Win2DFilledRegionDetermination(path.FilledRegionDetermination)); foreach (var command in path.Commands) { switch (command.Type) { case Wcd.Mgcg.CanvasPathBuilder.CommandType.BeginFigure: builder.BeginFigure(SnVector2(((Wcd.Mgcg.CanvasPathBuilder.Command.BeginFigure)command).StartPoint)); break; case Wcd.Mgcg.CanvasPathBuilder.CommandType.EndFigure: builder.EndFigure(Win2DCanvasFigureLoop(((Wcd.Mgcg.CanvasPathBuilder.Command.EndFigure)command).FigureLoop)); break; case Wcd.Mgcg.CanvasPathBuilder.CommandType.AddLine: builder.AddLine(SnVector2(((Wcd.Mgcg.CanvasPathBuilder.Command.AddLine)command).EndPoint)); break; case Wcd.Mgcg.CanvasPathBuilder.CommandType.AddCubicBezier: var cb = (Wcd.Mgcg.CanvasPathBuilder.Command.AddCubicBezier)command; builder.AddCubicBezier(SnVector2(cb.ControlPoint1), SnVector2(cb.ControlPoint2), SnVector2(cb.EndPoint)); break; default: throw new InvalidOperationException(); } } return(Win2D.CanvasGeometry.CreatePath(builder)); } case Wcd.Mgcg.CanvasGeometry.GeometryType.RoundedRectangle: var roundedRectangle = (Wcd.Mgcg.CanvasGeometry.RoundedRectangle)geometry; return(Win2D.CanvasGeometry.CreateRoundedRectangle( null, roundedRectangle.X, roundedRectangle.Y, roundedRectangle.W, roundedRectangle.H, roundedRectangle.RadiusX, roundedRectangle.RadiusY)); case Wcd.Mgcg.CanvasGeometry.GeometryType.Combination: default: throw new InvalidOperationException(); } }
internal void DrawPart(CanvasDrawingSession win2d, ViewInfo info) { switch (Command) { case 'c': case 'C': { if (befor != null) { var bp = befor.GetPoint(); bp.X *= info.Scale; bp.Y *= info.Scale; var canvasPathBuilder = new Microsoft.Graphics.Canvas.Geometry.CanvasPathBuilder(win2d); int index = 0; index++; canvasPathBuilder.BeginFigure(bp); var p0 = points[0]; var p1 = points[1]; var p2 = points[2]; p0.X *= info.Scale; p0.Y *= info.Scale; p1.X *= info.Scale; p1.Y *= info.Scale; p2.X *= info.Scale; p2.Y *= info.Scale; canvasPathBuilder.AddCubicBezier(p0, p1, p2); canvasPathBuilder.EndFigure(CanvasFigureLoop.Open); win2d.DrawGeometry(CanvasGeometry.CreatePath(canvasPathBuilder), Colors.HotPink, 1); } } break; case 'l': case 'L': case 'h': case 'H': case 'v': case 'V': { if (befor != null) { var bp = befor.GetPoint(); bp.X *= info.Scale; bp.Y *= info.Scale; var canvasPathBuilder = new Microsoft.Graphics.Canvas.Geometry.CanvasPathBuilder(win2d); int index = 0; index++; canvasPathBuilder.BeginFigure(bp); var p0 = points[0]; p0.X *= info.Scale; p0.Y *= info.Scale; canvasPathBuilder.AddLine(p0); canvasPathBuilder.EndFigure(CanvasFigureLoop.Open); win2d.DrawGeometry(CanvasGeometry.CreatePath(canvasPathBuilder), Colors.HotPink, 1); } } break; } }