/// <summary> /// Set shape style. /// </summary> /// <param name="project">The project instance.</param> /// <param name="shape">The shape instance.</param> /// <param name="style">The style instance.</param> public static void ApplyStyle(this IProjectContainer project, IBaseShape shape, IShapeStyle style) { if (shape != null && style != null) { if (shape is IGroupShape group) { var shapes = ProjectContainer.GetAllShapes(group.Shapes); foreach (var child in shapes) { var previous = child.Style; var next = (IShapeStyle)style.Copy(null); project?.History?.Snapshot(previous, next, (p) => child.Style = p); child.Style = next; } } else { var previous = shape.Style; var next = (IShapeStyle)style.Copy(null); project?.History?.Snapshot(previous, next, (p) => shape.Style = p); shape.Style = next; } } }
public void BreakPathFigure(IPathFigure pathFigure, IShapeStyle style, bool isStroked, bool isFilled, List <IBaseShape> result) { var factory = _serviceProvider.GetService <IFactory>(); var firstPoint = pathFigure.StartPoint; var lastPoint = pathFigure.StartPoint; foreach (var segment in pathFigure.Segments) { switch (segment) { case ILineSegment lineSegment: { var convertedStyle = style != null ? (IShapeStyle)style?.Copy(null) : factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName); var convertedPathShape = factory.CreateLineShape( lastPoint, lineSegment.Point, convertedStyle, isStroked); lastPoint = lineSegment.Point; result.Add(convertedPathShape); } break; case IQuadraticBezierSegment quadraticBezierSegment: { var convertedStyle = style != null ? (IShapeStyle)style?.Copy(null) : factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName); var convertedPathShape = factory.CreateQuadraticBezierShape( lastPoint, quadraticBezierSegment.Point1, quadraticBezierSegment.Point2, convertedStyle, isStroked, isFilled); lastPoint = quadraticBezierSegment.Point2; result.Add(convertedPathShape); } break; case ICubicBezierSegment cubicBezierSegment: { var convertedStyle = style != null ? (IShapeStyle)style?.Copy(null) : factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName); var convertedPathShape = factory.CreateCubicBezierShape( lastPoint, cubicBezierSegment.Point1, cubicBezierSegment.Point2, cubicBezierSegment.Point3, convertedStyle, isStroked, isFilled); lastPoint = cubicBezierSegment.Point3; result.Add(convertedPathShape); } break; case IArcSegment arcSegment: { var convertedStyle = style != null ? (IShapeStyle)style?.Copy(null) : factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName); var point2 = factory.CreatePointShape(0, 0); // TODO: var point3 = factory.CreatePointShape(0, 0); // TODO: var convertedPathShape = factory.CreateArcShape( lastPoint, point2, point3, arcSegment.Point, convertedStyle, isStroked, isFilled); lastPoint = arcSegment.Point; result.Add(convertedPathShape); } break; } } if (pathFigure.Segments.Length > 0 && pathFigure.IsClosed) { var convertedStyle = style != null ? (IShapeStyle)style?.Copy(null) : factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName); var convertedPathShape = factory.CreateLineShape( lastPoint, firstPoint, convertedStyle, isStroked); result.Add(convertedPathShape); } }