Skip to content

[bug] Layer names do not support Chinese characters. #2404

Open

Description

@libaineu2004

1.environment
klayout v0.30.7
windows 10 x64

2.read dxf, the Chinese text is garbled.

Image

Activity

  1. d-m-bailey commented on Jul 27, 2026

    @d-m-bailey

    @libaineu2004 What text are you trying to display?

    I can manually rename the layers to Chinese characters (Japanese).

    Image

    If you can manually edit the layer names to Chinese, but can't read them in, then it may be a file I/O problem.

  2. libaineu2004 commented on Jul 28, 2026

    @libaineu2004
    Author

    @libaineu2004 What text are you trying to display?

    I can manually rename the layers to Chinese characters (Japanese).

    Image If you can manually edit the layer names to Chinese, but can't read them in, then it may be a file I/O problem.

    Manual editing is possible; however, the changes are lost when the DXF file is reopened. The manual renaming was not saved.

  3. d-m-bailey commented on Jul 28, 2026

    @d-m-bailey

    Ok, so this may be a dxf import related issue.

  4. Kazzz-S commented on Jul 28, 2026

    @Kazzz-S
    Contributor

    Hi,

    Manual editing is possible; however, the changes are lost when the DXF file is reopened. The manual renaming was not saved.

    In my experiments, behaviors are a bit different, as follows.
    Nothing is weird to me.


    1. Environment and sample files

    • KLayout 0.30.10 / QCad Pro 3.32.9
    • macOS Tahoe 26.5.2 (M4 chip)
    • Sample files ===> GitHub2404.zip

    2. Generation flow of different image files

    • KLayout (new design) ===> gh2404-In.dxf

    • gh2404-In.dxf ===> QCad Pro ===> gh2404-01.png

    Image
    • gh2404-In.dxf ===> KLayout ===> gh2404-02.png
    Image
    • gh2404-In.dxf ===> KLayout ===> gh2404-Out.gds ===> KLayout ===> gh2404-03.png
    Image
    • gh2404-In.dxf ===> KLayout ===> gh2404-Out.oas ===> KLayout ===> gh2404-04.png
    Image
    • gh2404-In.dxf ===> KLayout ===> gh2404-Out.dxf ===> KLayout ===> gh2404-05.png
    Image
    • gh2404-In.dxf ===> KLayout ===> gh2404-Out.dxf ===> QCad Pro ===> gh2404-06.png
    Image
    • gh2404-In.dxf ===> KLayout (edited layer names) ===> gh2404-07.png ===> gh2404-Out2.oas ===> KLayout ===> gh2404-08.png
    Image Image
    • gh2404-In.dxf ===> KLayout (edited layer names) ===> gh2404-09.png ===> gh2404-Out2.dxf ===> QCad Pro ===> gh2404-10.png
    Image Image

    3. Encoding of the DXF files

    MacMiniKS{sekigawa} GitHub2404 (1)% nkf --guess *.dxf
    gh2404-In.dxf: UTF-8 (LF)
    gh2404-Out.dxf: UTF-8 (LF)
    gh2404-Out2.dxf: UTF-8 (LF)
    

    4. My understandings

    1. A GDS2 file cannot carry a file name string. So it is omitted during export, and only the layer/datatype combination is stored.
    2. An OASIS file can carry a file name string; however, it must be 7-bit ASCII.
      Therefore, any Asian character in UTF-8 is replaced with an asterisk.
      In my data, a layer name having 7 Chinese characters is represented by '*******'.
      One, two, and three with '*', '**', and '***', respectively.
  5. libaineu2004 commented on Jul 28, 2026

    @libaineu2004
    Author

    I found that it is indeed related to the file encoding.
    The original DXF was in ANSI format, and layer names appeared as garbled text when opened in KLayout;
    however, after I saved the DXF as UTF-8, it displayed correctly when opened again.

    1.demo.dxf with ANSI

    Image

    2.demo.dxf with UTF-8

    Image

    3.However, when I renamed the layer and saved the file, the change didn't actually take effect; upon reopening the file, the layer name had reverted to the original.

  6. libaineu2004 commented on Jul 28, 2026

    @libaineu2004
    Author

    environment
    klayout v0.30.7
    windows 10 x64

    However, when I renamed the layer and saved the file, the change didn't actually take effect; upon reopening the file, the layer name had reverted to the original.

  7. d-m-bailey commented on Jul 28, 2026

    @d-m-bailey

    @libaineu2004 once you have the layers defined as you want, try saving the layer information with File -> Save Layer Properties

    Then if you load a file that has unreadable layer names, user File -> Load Layer Properties to restore the layer names.

  8. libaineu2004 commented on Jul 29, 2026

    @libaineu2004
    Author

    "File -> Save Layer Properties", we can save the name of the layer.
    But it's too troublesome. A new file (*.lyp) has been added.
    I originally thought that the "Save" function could directly modify the dxf file.
    Only in this way we can use other CAD software to interpret the names of the new layers.

  9. klayoutmatthias commented on Aug 1, 2026

    @klayoutmatthias
    Collaborator

    Hi folks,

    thanks for this discussion and in particular to @Kazzz for the (as usual) meticulous analysis!

    I have some comments here:

    • GDS as you noticed does not support layer names at all. Be careful with non-ASCII cell names as KLayout uses UTF-8 for the encoding and other tools may not understand that.
    • OASIS is pretty strict when it comes to allowed characters. The original specification allows a small subset of ASCII only. For text strings I dropped this restriction and copy the texts as UTF-8, but names (layer names, property names, cell names) are a different thing. By default, KLayout replaces forbidden characters by "*", but you can configure that on the OASIS page of the Writer Options. If you delete that character, no substitution happens and you can save any kind of layer name - at the risk of generating incompatible OASIS files.
    • Layer names are written to DXF in UTF-8 encoding. Also upon reading, KLayout expects UTF-8 encoding. I don't know if that is compatible with the DXF standard, but I assume it's not. If someone has a valid DXF file with non-ASCII names that can be shared, I'll be happy to take a look. BTW: DXF does not support layers with layer/datatypes only. These are converted into LxDy-names.

    I'd like to take the opportunity to point you to the LStream format I introduced. This format does not have any constraints regarding names and employs UTF-8 encoding everywhere.

    Since however every stream format has different abilities, the best solution actually is to use the layer properties files. These also allow defining colors and much more, so I think there is enough benefit to compensate for the need of a second file.

    Matthias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions