Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified samples/svg/export_sample.dwg
Binary file not shown.
12 changes: 11 additions & 1 deletion src/ACadSharp/Entities/Hatch.BoundaryPath.Spline.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Attributes;
using CSMath;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace ACadSharp.Entities
Expand Down Expand Up @@ -130,7 +131,16 @@ public override Entity ToEntity()
spline.EndTangent = this.EndTangent.Convert<XYZ>();

spline.ControlPoints.AddRange(this.ControlPoints);
spline.Weights.AddRange(this.ControlPoints.Select(x => x.Z));

if (this.Weights.Any(w => w == 0))
{
spline.Weights.AddRange(Enumerable.Repeat(1.0d, this.ControlPoints.Count));
}
else
{
spline.Weights.AddRange(this.Weights);
}

spline.FitPoints.AddRange(this.FitPoints.Select(x => x.Convert<XYZ>()));
spline.Knots.AddRange(this.Knots);

Expand Down
39 changes: 33 additions & 6 deletions src/ACadSharp/IO/SVG/SvgXmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ protected void writeEntity(Entity entity, Transform transform)
case IText text:
this.writeText(text, transform);
break;
//case Spline spline:
// this.writeSpline(spline, transform);
// break;
case Spline spline:
this.writeSpline(spline, transform);
break;
default:
this.notify($"[{entity.ObjectName}] Entity not implemented.", NotificationType.NotImplemented);
break;
Expand Down Expand Up @@ -402,6 +402,8 @@ private void writeEntityAsPath<T>(Entity entity, Transform transform, params IEn

this.WriteAttributeString("d", this.createPath(lines));

this.WriteAttributeString("fill", "none");

this.WriteEndElement();
}

Expand Down Expand Up @@ -691,7 +693,7 @@ private void writeText(IText text, Transform transform)
this.WriteValue("px");
}

if(text.Style.TrueType.HasFlag(FontFlags.Bold))
if (text.Style.TrueType.HasFlag(FontFlags.Bold))
{
this.WriteValue("bold");
}
Expand Down Expand Up @@ -807,8 +809,33 @@ private void writeText(IText text, Transform transform)

private void writeSpline(Spline spline, Transform transform)
{
spline.UpdateFromFitPoints();
this.writeEntityAsPath(spline, transform, spline.PolygonalVertexes(this.Configuration.ArcPoints));
if (!spline.ControlPoints.Any())
{
spline.UpdateFromFitPoints();
}

if (!spline.TryPolygonalVertexes(this.Configuration.ArcPoints, out var pts))
{
return;
}

if (spline.IsClosed)
{
this.WriteStartElement("polygon");
}
else
{
this.WriteStartElement("polyline");
}

this.writeEntityHeader(spline, transform);

string svgPts = this.svgPoints(pts, transform);

this.WriteAttributeString("points", svgPts);
this.WriteAttributeString("fill", "none");

this.WriteEndElement();
}

private void writeTransform(Transform transform)
Expand Down