From 0dda91f6ec4267e24e53218b6574709b8efb4faf Mon Sep 17 00:00:00 2001 From: gryaznulka Date: Sun, 6 Dec 2026 16:01:29 +0100 Subject: [PATCH 1/2] fix: strip MTEXT paragraph properties without adding line breaks --- src/DwgIO/Model/DwgEntity.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/DwgIO/Model/DwgEntity.cs b/src/DwgIO/Model/DwgEntity.cs index 23fa0d5..08fff16 100644 --- a/src/DwgIO/Model/DwgEntity.cs +++ b/src/DwgIO/Model/DwgEntity.cs @@ -322,10 +322,27 @@ private static string StripMTextFormatting(string raw) switch (next) { case 'P': - case 'p': sb.Append('\n'); i++; break; + case 'p': + { + // Paragraph properties (indentation, alignment, tabs) end at ';'. + // A missing terminator must not consume the next formatting command or group. + var arguments = raw.AsSpan(i + 2); + int end = arguments.IndexOfAny(";\\{}\r\n".AsSpan()); + if (end >= 0 && arguments[end] == ';') + { + i += end + 2; + } + else + { + sb.Append("\\p"); + i++; + } + + break; + } case '~': sb.Append(' '); i++; From 87f8678344f00c8f36d42eaa9776af0e6532c959 Mon Sep 17 00:00:00 2001 From: gryaznulka Date: Sun, 6 Dec 2026 16:02:15 +0100 Subject: [PATCH 2/2] test: cover MTEXT paragraph properties in scene labels --- .../DwgIO.Tests/HatchDimensionAttribTests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/DwgIO.Tests/HatchDimensionAttribTests.cs b/tests/DwgIO.Tests/HatchDimensionAttribTests.cs index 5b789cc..71f03a5 100644 --- a/tests/DwgIO.Tests/HatchDimensionAttribTests.cs +++ b/tests/DwgIO.Tests/HatchDimensionAttribTests.cs @@ -50,6 +50,31 @@ public void PlainText_DecodesUnicodeAndCadSpecialEscapes() Assert.Equal("Ось 45° ±0.5 ⌀100 10%", attrib.PlainText); } + [Theory] + [InlineData(@"{\pxi-2,l2;Ось\PРазмер}", "Ось\nРазмер")] + [InlineData(@"\pxqc,t1,r5,c8;A\P\pi*,l*,r*,q*,t;B", "A\nB")] + [InlineData(@"\U+041E\U+0441\U+044C\PРазмер", "Ось\nРазмер")] + [InlineData(@"\\pxi-2,l2;Ось", @"\pxi-2,l2;Ось")] + [InlineData(@"before\pafter\Pline; end", "before\\pafter\nline; end")] + public void PlainText_DistinguishesParagraphPropertiesFromParagraphBreaks(string raw, string expected) + { + var mtext = new DwgEntity + { + Handle = 0x10, + TypeCode = 0x2C, + TypeName = "MTEXT", + Kind = DwgEntityKind.MText, + Text = raw, + Geometry = [0, 0, 0, 1, 0, 5, 1], + }; + Assert.Equal(raw, mtext.Text); + Assert.Equal(expected, mtext.PlainText); + + var doc = new DwgDocument("paragraph.dwg", Header2018, [mtext]); + var scene = DwgSceneReader.Read(doc, new DwgSceneOptions { ModelKey = "paragraph" }); + Assert.Equal(expected, Assert.Single(scene.Annotations).Text); + } + [Fact] public void Hatch_Solid_EmitsOutlineAndFill_AndStaysFlatInAutoMode() {