This project has moved and is read-only. For the latest updates, please go here.

support multi language ?

Feb 13, 2014 at 2:50 AM

my dxf file contains chinese character which unicode is GB2312. what work should i do to get correct text ?
Feb 17, 2014 at 7:18 PM
Take a look at the following code sample, this is how it works at least for me. Hopefully the text in Chinese makes sense.
// use a font that has support for Chinese characters
TextStyle textStyle = new TextStyle("Chinese text", "simsun.ttf");

// for dxf database version 2007 and later you can use directly the characters,
DxfDocument dxf1 = new DxfDocument(DxfVersion.AutoCad2010);
Text text1 = new Text("这是中国文字", Vector2.Zero, 10, textStyle);
MText mtext1 = new MText("这是中国文字", new Vector2(0, 30), 10, 0, textStyle);

// for previous versions (this method will also work for later ones) you will need to supply the Unicode value (U+value),
// you can get this value with the Windows Character Map application
DxfDocument dxf2 = new DxfDocument(DxfVersion.AutoCad2000);
Text text2 = new Text("\\U+8FD9\\U+662F\\U+4E2D\\U+56FD\\U+6587\\U+5B57", Vector2.Zero, 10, textStyle);
MText mtext2 = new MText("\\U+8FD9\\U+662F\\U+4E2D\\U+56FD\\U+6587\\U+5B57", new Vector2(0, 30), 10, 0, textStyle);
Feb 22, 2014 at 2:42 PM
thanks Daniel.

I have a DXF file which contains chinese text. when i use netdxf to read it, the character can not be recognised. what work should i do ?

now my business has not refer to save dxf file. :-)
Feb 24, 2014 at 6:30 PM
Does the file throw an exception while trying to load it? The samples I showed to you in the previous post load just fine and they contain Chinese text. I don't know what might happen. Are those Chinese texts part of a Text or MText entity or they appear somewhere else. Perhaps if I can have access to the dxf file giving you troubles I might figure out what is going on.

Feb 26, 2014 at 5:18 AM
The dxf file can be loaded without throw exception. But when I get the Text or MText which contains Chinese texts, it can not be encoded correctly. That is issue.
Mar 11, 2014 at 10:28 AM
Hi Daniel,

do you have catch my issue? What work should i do ?
Mar 12, 2014 at 7:33 PM
I have not been able to reproduce the problem that you describe. The library does nothing out of ordinary when reading the text strings associated with a Text or MText entity, it just uses the standard net TextReader to get whatever is written in the dxf file.

If you try to write the entity Text.Value to the console, for example, you might get a string of question marks but this problem has nothing to do with the library, but with the console, or the font it uses, that does not support Chinese characters; same thing happens with other non standard characters of other languages. If you debug your program and check the value of the Text entity inside Visual Studio through a watch you should get the correct string of Chinese characters.

Mar 13, 2014 at 1:18 AM
Can you help me to test my dxf file? How to upload? email ?
Mar 13, 2014 at 7:17 PM
It's fine, you can just email me the dxf file. You can find my email at the head of the source code files. You could also open an issue, this will allow you to upload the file, but it will make it public both options are fine to me.

If you can, try to include only the problematic entities, if you can't giving me the entity handles will be great since they are unique identifiers.

Mar 19, 2014 at 8:47 AM
Hi Daniel,
I have email to you. please check it out, thanks. :-P
Mar 20, 2014 at 7:42 PM
I have updated the code with a fix. Hopefully, this will correct the problems you had with the Chinese texts. The library was expecting utf8 encoded files, but in your case it was not this way; so, now, if the file is not utf8 (unicode) it will use the dxf code page header variable to create a suitable encoding. In any case, the saved DxfDocument will always be utf8 without BOM. Try it and tell me if it works now as expected.

My knowledge on this text encoding business is limited and I hope nothing else has broken in the process.

Mar 21, 2014 at 5:52 AM
Edited Mar 21, 2014 at 6:23 AM
thanks daniel. It works!
Jun 18 at 6:25 PM
Need Help !!!!!

// use a font that has support for Persian characters
TextStyle textStyle = new TextStyle("Chinese text", "Farsi.ttf");
DxfDocument dxf1 = new DxfDocument();
Text text1 = new Text("سلام", Vector2.Zero, 10, textStyle);
MText mtext1 = new MText("سلام", new Vector2(0, 30), 10, 0, textStyle);

this code is correctly work but in Print Preview for print this font not correctly print
please help me how to adjust this textstyle to print correctly

My Thanks alot
Jun 22 at 11:14 PM
Have you tried to load your file with a program like DWG TrueView from Autodesk or similar, to see if the your text appears correctly? If it does the problem might be in the way you are printing. How and where are you printing the text?

When using no Latin characters I would recommend to use dxf files with version higher than AutoCad2007, the files are saved as UTF8.