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

Commit 0a04f1c

Browse files
committed
[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.
1 parent 9bb9df9 commit 0a04f1c

File tree

7 files changed

+39
-5
lines changed

7 files changed

+39
-5
lines changed

TestDxfDocument/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace TestDxfDocument
2727
/// </summary>
2828
public class Program
2929
{
30+
3031
public static void Main()
3132
{
3233
DxfDocument doc = Test(@"sample.dxf");

doc/Changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Change history
22

3+
### [2023/08/31]
4+
* When creating a table object any leading or trailing white space will be automatically removed.
5+
* When reading a spline from a DXF if its degree is larger than 10 it will be set to the maximun allowed.
6+
* (fixed) The key of the references dictionary in the TableObjects must be case independent.
7+
38
### [2023/07/15]
49
* (fixed) StackOverflow exception when cloning the extended data associated to an application registry with circular references.
510

netDxf/Collections/TableObjects.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected TableObjects(DxfDocument document, string codeName, string handle)
5757
: base(codeName)
5858
{
5959
this.list = new Dictionary<string, T>(StringComparer.OrdinalIgnoreCase);
60-
this.references = new Dictionary<string, DxfObjectReferences>();
60+
this.references = new Dictionary<string, DxfObjectReferences>(StringComparer.OrdinalIgnoreCase);
6161
this.Owner = document;
6262

6363
if (string.IsNullOrEmpty(handle))

netDxf/Entities/HatchPattern.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,16 @@ public static HatchPattern Load(string file, string patternName)
337337
{
338338
string line = reader.ReadLine();
339339
if (line == null)
340+
{
340341
throw new FileLoadException("Unknown error reading pat file.", file);
342+
}
341343
line = line.Trim();
342344

343345
// every pattern definition starts with '*'
344346
if (!line.StartsWith("*"))
347+
{
345348
continue;
349+
}
346350

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

357363
// we have found the pattern name, the next lines of the file contains the pattern definition
358364
line = reader.ReadLine();
359365
if (line == null)
366+
{
360367
throw new FileLoadException("Unknown error reading PAT file.", file);
368+
}
369+
361370
line = line.Trim();
362371

363372
pattern = new HatchPattern(name, description);
364373

365374
while (!string.IsNullOrEmpty(line) && !line.StartsWith("*") && !line.StartsWith(";"))
366375
{
367376
string[] tokens = line.Split(',');
368-
if(tokens.Length < 5)
377+
if (tokens.Length < 5)
378+
{
369379
throw new FileLoadException("The hatch pattern definition lines must contain at least 5 values.", file);
380+
}
370381

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

393-
if(reader.EndOfStream) break;
404+
if (reader.EndOfStream)
405+
{
406+
break;
407+
}
394408

395409
line = reader.ReadLine();
396410
if (line == null)
411+
{
397412
throw new FileLoadException("Unknown error reading PAT file.", file);
413+
}
398414
line = line.Trim();
399415
}
400416

netDxf/Entities/Spline.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class Spline :
3838
{
3939
#region private fields
4040

41+
public const short MaxDegree = 10;
42+
4143
private readonly Vector3[] fitPoints;
4244
private readonly SplineCreationMethod creationMethod;
4345
private Vector3? startTangent;
@@ -160,7 +162,7 @@ public Spline(IEnumerable<Vector3> controlPoints, IEnumerable<double> weights, s
160162
: base(EntityType.Spline, DxfObjectCode.Spline)
161163
{
162164
// spline degree
163-
if (degree < 1 || degree > 10)
165+
if (degree < 1 || degree > MaxDegree)
164166
{
165167
throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10.");
166168
}
@@ -235,7 +237,7 @@ internal Spline(IEnumerable<Vector3> controlPoints, IEnumerable<double> weights,
235237
: base(EntityType.Spline, DxfObjectCode.Spline)
236238
{
237239
// spline degree
238-
if (degree < 1 || degree > 10)
240+
if (degree < 1 || degree > MaxDegree)
239241
{
240242
throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10.");
241243
}

netDxf/IO/DxfReader.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7799,6 +7799,10 @@ private Spline ReadSpline()
77997799
break;
78007800
case 71:
78017801
degree = this.chunk.ReadShort();
7802+
if (degree > Spline.MaxDegree)
7803+
{
7804+
degree = Spline.MaxDegree;
7805+
}
78027806
this.chunk.Next();
78037807
break;
78047808
case 72:
@@ -9393,6 +9397,11 @@ private MText ReadMText()
93939397
textString = textString.Replace("^J", "\\P");
93949398
}
93959399

9400+
if (spacingStyle == MTextLineSpacingStyle.Default || spacingStyle == MTextLineSpacingStyle.Multiple)
9401+
{
9402+
spacingStyle = MTextLineSpacingStyle.AtLeast;
9403+
}
9404+
93969405
Vector3 ocsDirection = MathHelper.Transform(direction, normal, CoordinateSystem.World, CoordinateSystem.Object);
93979406

93989407
MText entity = new MText

netDxf/Tables/TableObject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ protected virtual void OnNameChangedEvent(string oldName, string newName)
7474
protected TableObject(string name, string codeName, bool checkName)
7575
: base(codeName)
7676
{
77+
name = name.Trim();
7778
if (checkName)
7879
{
7980
if (!IsValidName(name))

0 commit comments

Comments
 (0)