Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
[2023/08/31]
Browse files Browse the repository at this point in the history
* When creating a table object any leading or trailing white space will be automatically removed.
* When reading a spline from a DXF if its degree is larger than 10 it will be set to the maximun allowed.
* (fixed) The key of the references dictionary in the TableObjects must be case independent.
  • Loading branch information
haplokuon committed Aug 31, 2023
1 parent 9bb9df9 commit 0a04f1c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions TestDxfDocument/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace TestDxfDocument
/// </summary>
public class Program
{

public static void Main()
{
DxfDocument doc = Test(@"sample.dxf");
Expand Down
5 changes: 5 additions & 0 deletions doc/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Change history

### [2023/08/31]
* When creating a table object any leading or trailing white space will be automatically removed.
* When reading a spline from a DXF if its degree is larger than 10 it will be set to the maximun allowed.
* (fixed) The key of the references dictionary in the TableObjects must be case independent.

### [2023/07/15]
* (fixed) StackOverflow exception when cloning the extended data associated to an application registry with circular references.

Expand Down
2 changes: 1 addition & 1 deletion netDxf/Collections/TableObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected TableObjects(DxfDocument document, string codeName, string handle)
: base(codeName)
{
this.list = new Dictionary<string, T>(StringComparer.OrdinalIgnoreCase);
this.references = new Dictionary<string, DxfObjectReferences>();
this.references = new Dictionary<string, DxfObjectReferences>(StringComparer.OrdinalIgnoreCase);
this.Owner = document;

if (string.IsNullOrEmpty(handle))
Expand Down
20 changes: 18 additions & 2 deletions netDxf/Entities/HatchPattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,16 @@ public static HatchPattern Load(string file, string patternName)
{
string line = reader.ReadLine();
if (line == null)
{
throw new FileLoadException("Unknown error reading pat file.", file);
}
line = line.Trim();

// every pattern definition starts with '*'
if (!line.StartsWith("*"))
{
continue;
}

// reading pattern name and description
int endName = line.IndexOf(','); // the first semicolon divides the name from the description that might contain more semicolons
Expand All @@ -352,21 +356,28 @@ public static HatchPattern Load(string file, string patternName)
// remove start and end spaces
description = description.Trim();
if (!name.Equals(patternName, StringComparison.OrdinalIgnoreCase))
{
continue;
}

// we have found the pattern name, the next lines of the file contains the pattern definition
line = reader.ReadLine();
if (line == null)
{
throw new FileLoadException("Unknown error reading PAT file.", file);
}

line = line.Trim();

pattern = new HatchPattern(name, description);

while (!string.IsNullOrEmpty(line) && !line.StartsWith("*") && !line.StartsWith(";"))
{
string[] tokens = line.Split(',');
if(tokens.Length < 5)
if (tokens.Length < 5)
{
throw new FileLoadException("The hatch pattern definition lines must contain at least 5 values.", file);
}

double angle = double.Parse(tokens[0], NumberStyles.Float, CultureInfo.InvariantCulture);
Vector2 origin = new Vector2(
Expand All @@ -390,11 +401,16 @@ public static HatchPattern Load(string file, string patternName)
pattern.LineDefinitions.Add(lineDefinition);
pattern.Type = HatchType.UserDefined;

if(reader.EndOfStream) break;
if (reader.EndOfStream)
{
break;
}

line = reader.ReadLine();
if (line == null)
{
throw new FileLoadException("Unknown error reading PAT file.", file);
}
line = line.Trim();
}

Expand Down
6 changes: 4 additions & 2 deletions netDxf/Entities/Spline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class Spline :
{
#region private fields

public const short MaxDegree = 10;

private readonly Vector3[] fitPoints;
private readonly SplineCreationMethod creationMethod;
private Vector3? startTangent;
Expand Down Expand Up @@ -160,7 +162,7 @@ public Spline(IEnumerable<Vector3> controlPoints, IEnumerable<double> weights, s
: base(EntityType.Spline, DxfObjectCode.Spline)
{
// spline degree
if (degree < 1 || degree > 10)
if (degree < 1 || degree > MaxDegree)
{
throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10.");
}
Expand Down Expand Up @@ -235,7 +237,7 @@ internal Spline(IEnumerable<Vector3> controlPoints, IEnumerable<double> weights,
: base(EntityType.Spline, DxfObjectCode.Spline)
{
// spline degree
if (degree < 1 || degree > 10)
if (degree < 1 || degree > MaxDegree)
{
throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10.");
}
Expand Down
9 changes: 9 additions & 0 deletions netDxf/IO/DxfReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7799,6 +7799,10 @@ private Spline ReadSpline()
break;
case 71:
degree = this.chunk.ReadShort();
if (degree > Spline.MaxDegree)
{
degree = Spline.MaxDegree;
}
this.chunk.Next();
break;
case 72:
Expand Down Expand Up @@ -9393,6 +9397,11 @@ private MText ReadMText()
textString = textString.Replace("^J", "\\P");
}

if (spacingStyle == MTextLineSpacingStyle.Default || spacingStyle == MTextLineSpacingStyle.Multiple)
{
spacingStyle = MTextLineSpacingStyle.AtLeast;
}

Vector3 ocsDirection = MathHelper.Transform(direction, normal, CoordinateSystem.World, CoordinateSystem.Object);

MText entity = new MText
Expand Down
1 change: 1 addition & 0 deletions netDxf/Tables/TableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected virtual void OnNameChangedEvent(string oldName, string newName)
protected TableObject(string name, string codeName, bool checkName)
: base(codeName)
{
name = name.Trim();
if (checkName)
{
if (!IsValidName(name))
Expand Down

0 comments on commit 0a04f1c

Please sign in to comment.