Skip to content
Merged
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
19 changes: 18 additions & 1 deletion src/DwgIO/Model/DwgEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
25 changes: 25 additions & 0 deletions tests/DwgIO.Tests/HatchDimensionAttribTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading