Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot write Chinese text correctly #432

Open
rogure opened this issue Aug 26, 2024 · 9 comments
Open

Cannot write Chinese text correctly #432

rogure opened this issue Aug 26, 2024 · 9 comments
Labels
help wanted Extra attention is needed

Comments

@rogure
Copy link

rogure commented Aug 26, 2024

When I used it, I found that I could not write Chinese text into MTEXT. When I saved it to DWG file, the Chinese MTEXT displayed "?????". Symbol. How can this be resolved?

@DomCR DomCR added the help wanted Extra attention is needed label Aug 30, 2024
@DomCR
Copy link
Owner

DomCR commented Aug 30, 2024

Hi @rogure,

I've tested this code and write the result into a DWG:

image

image

I'm using the master branch of this repo and seems to work.
Are you using the repo or the package?

If you are using the package can release an update.

@CatarinaVCh
Copy link

CatarinaVCh commented Feb 6, 2025

Used the package and when I saved to DWG file, the Chinese TEXT and MTEXT displayed "?????"
How can this be resolved?

@DomCR
Copy link
Owner

DomCR commented Feb 7, 2025

Hi @CatarinaVCh,

I've tested this again and it seems that only MText adapts the Chinese characters correctly.

To solve this you need to create a TextStyle compatible with them, like so:

TextStyle style = new TextStyle("custom");
style.Filename = "romans.shx";
style.BigFontFilename = "chineset.shx";

Remember to add the style to your entities:

TextEntity text = new TextEntity();
text.Value = "我的短信";
text.Style = style;

Here is more information about the solution:
https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/Chinese-text-shows-as-a-question-mark-in-AutoCAD.html

Hope this helps.

@CatarinaVCh
Copy link

Hi, @DomCR ,
Thanks for your help, but unfortunately, this doesn't work for me.
I don't know why, but any text not in Latin is displayed in DWG as '???'

@DomCR
Copy link
Owner

DomCR commented Feb 7, 2025

Which software are you using?
Can you add the characters for a file that has not been created with ACadSharp?
Can you share the code that you are using to generate the file?

@CatarinaVCh
Copy link

Using Window 10, Autodesk Autocad 2019 and Microsoft Visual Studio Community 2022 (17.6.5)
After opening the received file I can insert any symbols

My code:

        CadDocument doc = new CadDocument();
        Line line = new Line
        {
            StartPoint = CSMath.XYZ.Zero,
            EndPoint = new CSMath.XYZ(100, 100, 0)
        };

        TextEntity text = new TextEntity();
        TextStyle style = new TextStyle("custom");
        style.Filename = "romans.shx";
        style.BigFontFilename = "chineset.shx";


        text.Value = "jhfja hfjfg 我的短信";
        text.Style = style;
        text.Height = 50;
        text.Color = new ACadSharp.Color(new byte[] { 200, 20, 100 });
        text.InsertPoint = new CSMath.XYZ(10, 10, 0); 
                                                    
        string initialName1 = "blocks_layer";
        string initialName2 = "text_layer";
        Layer layer1 = new Layer(initialName1);
        Layer layer2 = new Layer(initialName2);

        doc.Layers.Add(layer1);
        doc.Layers.Add(layer2);

        line.Layer = layer1;
        doc.Entities.Add(line);

        text.Layer = layer2;
        doc.Entities.Add(text);

        VPort vport = doc.VPorts["*Active"];
        if (vport != null)
        {
            vport.Center = new CSMath.XY(0.0, 0.0);
            vport.ViewHeight = 2202.0730586005643;
            vport.ViewMode = ViewModeType.FrontClippingZ;
            vport.UseDefaultLighting = true;
        }

        var desktopPath2 = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
        string savePath2 = Path.Combine(desktopPath2, "2.dwg");

        using (DwgWriter writer = new DwgWriter(savePath2, doc))
        {
            writer.Write();
        }

@DomCR
Copy link
Owner

DomCR commented Feb 7, 2025

Ok, so you can create text in Autocad using Chinese characters, if that's the case, check the text style that Autocad is using and try to match the properties with the one that you are creating in your code, maybe you don't have the romans font in your system.

I've tested your code and works fine:

Image

@CatarinaVCh
Copy link

Thank you very much for checking the code, but it doesn't work for me)))
I checked the fonts, they are there)))
The style of the text corresponds to those installed programmatically, but the symbols are displayed as '???'
Applying this style to other text fields in Autocad itself works, but not to those created with ACadSharp
It seems that some encoding is applied during the saving process, and then '???' remain '???' in any encoding and fonts
I don't know, maybe Autocad was installed with errors...

@DomCR
Copy link
Owner

DomCR commented Feb 8, 2025

You can try to change the file encoding then:

CadDocument.Header.CodePage = "GB2312"; //Chinese simplified code page (GB2312)

Maybe for your version is needed.

Another test you can try is to save a document where the characters work and check the TextStyle and the Header encoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants