protected override Path ParsePath(Dictionary <string, string> properties) { // Get the attributes of the circle var cx = DoubleUtils.TryParse(properties.GetOrDefault("cx")) ?? 0; var cy = DoubleUtils.TryParse(properties.GetOrDefault("cy")) ?? 0; var r = DoubleUtils.TryParse(properties.GetOrDefault("r")) ?? 0; // Quit on invalid values if (r <= 0) { return(new Path()); } var rr = new Double2(r, r); // Mount the path commands return(new Path(new[] { PathCommand.MoveTo(new Double2(cx + r, cy)), PathCommand.ArcTo(rr, 0, false, true, new Double2(cx, cy + r)), PathCommand.ArcTo(rr, 0, false, true, new Double2(cx - r, cy)), PathCommand.ArcTo(rr, 0, false, true, new Double2(cx, cy - r)), PathCommand.ArcToClose(rr, 0, false, true) })); }
// Override the parse protected override void Parse(Dictionary<string, string> properties) { // Parse the common properties base.Parse(properties); // Parse the path data Path = new Path(properties.GetOrDefault("d", "")); // And the path length PathLength = DoubleUtils.TryParse(properties.GetOrDefault("pathLength")) ?? double.NaN; }
protected override Path ParsePath(Dictionary <string, string> properties) { // Get the attributes of the line var x1 = DoubleUtils.TryParse(properties.GetOrDefault("x1")) ?? 0; var y1 = DoubleUtils.TryParse(properties.GetOrDefault("y1")) ?? 0; var x2 = DoubleUtils.TryParse(properties.GetOrDefault("x2")) ?? 0; var y2 = DoubleUtils.TryParse(properties.GetOrDefault("y2")) ?? 0; // And finally return return(new Path(new[] { PathCommand.MoveTo(new Double2(x1, y1)), PathCommand.LineTo(new Double2(x2, y2)) })); }
protected override Path ParsePath(Dictionary <string, string> properties) { // Get the attributes of the ellipse var cx = DoubleUtils.TryParse(properties.GetOrDefault("cx")) ?? 0; var cy = DoubleUtils.TryParse(properties.GetOrDefault("cy")) ?? 0; var radii = new Double2(); radii.X = DoubleUtils.TryParse(properties.GetOrDefault("rx")) ?? double.NaN; radii.Y = DoubleUtils.TryParse(properties.GetOrDefault("ry")) ?? double.NaN; // Check both radii if (double.IsNaN(radii.X) && double.IsNaN(radii.Y)) { radii.X = radii.Y = 0; } else if (double.IsNaN(radii.X)) { radii.X = radii.Y; } else if (double.IsNaN(radii.Y)) { radii.Y = radii.X; } // Take out the sign and clamp them radii.X = Math.Abs(radii.X); radii.Y = Math.Abs(radii.Y); // Quit on invalid values if (radii.X <= 0 || radii.Y <= 0) { return(new Path()); } // Mount the path commands return(new Path(new[] { PathCommand.MoveTo(new Double2(cx + radii.X, cy)), PathCommand.ArcTo(radii, 0, false, true, new Double2(cx, cy + radii.Y)), PathCommand.ArcTo(radii, 0, false, true, new Double2(cx - radii.X, cy)), PathCommand.ArcTo(radii, 0, false, true, new Double2(cx, cy - radii.Y)), PathCommand.ArcToClose(radii, 0, false, true) })); }
public PathStyle(Dictionary <string, string> properties, PathStyle?parent) { // Fill in the default values according to the default values on https://svgwg.org/svg-next/painting.htm // Special handling for paint servers (which now only accept colors) FillColor = CSSColor.Parse(properties.GetOrDefault("fill")) ?? (parent.HasValue ? parent.Value.FillColor : Color.Black); StrokeColor = CSSColor.Parse(properties.GetOrDefault("stroke")) ?? parent?.StrokeColor; FillRule = CSSEnumPicker <FillRule> .Get(properties.GetOrDefault("fill-rule")) ?? parent?.FillRule ?? FillRule.Nonzero; StrokeWidth = DoubleUtils.TryParse(properties.GetOrDefault("stroke-width")) ?? parent?.StrokeWidth ?? 1; StrokeLineCap = CSSEnumPicker <StrokeLineCap> .Get(properties.GetOrDefault("stroke-linecap")) ?? parent?.StrokeLineCap ?? StrokeLineCap.Butt; StrokeLineJoin = CSSEnumPicker <StrokeLineJoin> .Get(properties.GetOrDefault("stroke-linejoin")) ?? parent?.StrokeLineJoin ?? StrokeLineJoin.Miter; MiterLimit = DoubleUtils.TryParse(properties.GetOrDefault("stroke-miterlimit")) ?? parent?.StrokeWidth ?? 4; }
protected override Path ParsePath(Dictionary <string, string> properties) { // Get the attributes of the rectangle var x = DoubleUtils.TryParse(properties.GetOrDefault("x")) ?? 0; var y = DoubleUtils.TryParse(properties.GetOrDefault("y")) ?? 0; var width = DoubleUtils.TryParse(properties.GetOrDefault("width")) ?? 0; var height = DoubleUtils.TryParse(properties.GetOrDefault("height")) ?? 0; var radii = new Double2(); radii.X = DoubleUtils.TryParse(properties.GetOrDefault("rx")) ?? double.NaN; radii.Y = DoubleUtils.TryParse(properties.GetOrDefault("ry")) ?? double.NaN; // Quit on invalid values if (width <= 0 || height <= 0) { return(new Path()); } // Check both radii if (double.IsNaN(radii.X) && double.IsNaN(radii.Y)) { radii.X = radii.Y = 0; } else if (double.IsNaN(radii.X)) { radii.X = radii.Y; } else if (double.IsNaN(radii.Y)) { radii.Y = radii.X; } // Take out the sign and clamp them radii.X = Math.Abs(radii.X); radii.Y = Math.Abs(radii.Y); if (radii.X > width / 2) { radii.X = width / 2; } if (radii.Y > height / 2) { radii.Y = height / 2; } // Now mount the path commands PathCommand[] pathCommands; if (radii.X == 0 || radii.Y == 0) { pathCommands = new[] { PathCommand.MoveTo(new Double2(x, y)), PathCommand.LineTo(new Double2(x + width, y)), PathCommand.LineTo(new Double2(x + width, y + height)), PathCommand.LineTo(new Double2(x, y + height)), PathCommand.ClosePath() } } ; else { pathCommands = new[] { PathCommand.MoveTo(new Double2(x + radii.X, y)), PathCommand.LineTo(new Double2(x + width - radii.X, y)), PathCommand.ArcTo(radii, 0, false, true, new Double2(x + width, y + radii.Y)), PathCommand.LineTo(new Double2(x + width, y + height - radii.Y)), PathCommand.ArcTo(radii, 0, false, true, new Double2(x + width - radii.X, y + height)), PathCommand.LineTo(new Double2(x + radii.X, y + height)), PathCommand.ArcTo(radii, 0, false, true, new Double2(x, y + height - radii.Y)), PathCommand.LineTo(new Double2(x, y + radii.Y)), PathCommand.ArcToClose(radii, 0, false, true) } }; // And finally return return(new Path(pathCommands)); } }