netDxf
netDxf copied to clipboard
Creating multiple row Text entity corrupts output file
Hello Affected code is
using netDxf;
using netDxf.Entities;
var invalid = new DxfDocument();
var text = new Text("Multiply\nrows\ntext");
invalid.Entities.Add(text);
invalid.Save("invalid.dxf");
var valid = new DxfDocument();
text = new Text("One row text");
valid.Entities.Add(text);
valid.Save("valid.dxf");
The first one should throw an Argument exception because text entity does not support multiple rows.
A Text entity only can hold a single line of text and "\n" is not a valid character. Use the MText entity instead, and read the documentation to know how to format the text string. "\n" is not the new paragraph character.
I know how Text and MText works. I met this behavior on generating drawing with Text entities from a bunch of text data. I spent a time on looking up what went wrong. So I think the Text entity constructor should not accept wrong text.
On August 4, 2023 8:24:18 PM GMT+03:00, Daniel Carvajal @.***> wrote:
A Text entity only can hold a single line of text and "\n" is not a valid character. Use the MText entity instead, and read the documentation to know how to format the text string. "\n" is not the new paragraph character.
-- Reply to this email directly or view it on GitHub: https://github.com/haplokuon/netDxf/issues/472#issuecomment-1665950305 You are receiving this because you authored the thread.
Message ID: @.***>
You should ask Autodesk for that, no way I am gonna test what characters AutoCAD likes and what doesn't, because I do not know. The DXF documentation just says that code 1 holds a string.
Never try to force a new line when defining strings in any place or you will brake the line in the code-value pair in the DXF.