Skip to content

[Bug]: CAD DXF/DWG TEXT and Layer attributes are mojibake for ANSI_936 / GBK drawings #1973

Description

@mfkj8866

Before you start

  • I searched the existing issues and did not find a duplicate.
  • This is a bug report, not a usage question (questions belong in Discussions).

What happened?

Loading a local CAD drawing through Add data → CAD Layer imports geometry, but Chinese TEXT / MTEXT and layer names in the attribute table are mojibake.

The drawing is a DXF with $DWGCODEPAGE = ANSI_936 (GBK). Desktop GDAL (ogrinfo / ogr2ogr) decodes the same file correctly. In GeoLibre the attribute table shows GBK bytes interpreted as Latin-1 / Windows-1252, for example:

Field Actual (mojibake) Expected
Layer ¼¯µçÏß· 集电线路
Text μ Àý 图例
Text ·ûºÅ 符号
Text ÄÚÈÝ 内容
Text ÊýÁ¿ 数量
Text ·çµç³¡ 风电场
Text ZC-YJLV22-26/35kV-3¡Á95mm2 ZC-YJLV22-26/35kV-3×95mm2

SubClasses is AcDbEntity:AcDbMText / AcDbEntity:AcDbText:AcDbAttribute, so these rows are CAD text entities, not a separate encoding in GeoJSON.

Likely cause: CAD files are opened with DuckDB-WASM ST_Read (bundled GDAL). That build has no iconv, so it copies each file byte as a Latin-1 character instead of honouring $DWGCODEPAGE. × (GBK A1 C1) becoming ¡Á is the same pattern.

This is distinct from labels being off by default (labels.enabled is false). Even with labels enabled, the Text field is already garbled, so the map cannot show the original Chinese.

Steps to reproduce

  1. Run the web app from source (npm run dev) on current main.
  2. Open Add data → CAD Layer and choose a DXF whose header has $DWGCODEPAGE = ANSI_936 and whose TEXT/MTEXT is Chinese (a 192-byte sample is linked below).
  3. Add the entities layer.
  4. Open the attribute table and look at the Layer and Text columns.

Expected behavior

Text and Layer should be Unicode Chinese, matching desktop GDAL on the same file (工程名称, 集电线路, ×, …). Mojibake such as ¼¯µçÏß· and ¡Á should not appear.

How are you running GeoLibre?

Web build from source (npm run dev), main @ 5b89c26, v2.6.0

Operating system and browser

Ubuntu 24.04 + Chrome

Sample data

Any AutoCAD DXF with $DWGCODEPAGE = ANSI_936 and Chinese TEXT reproduces this. A minimal sample (one TEXT entity 集电线路) is here:

https://github.com/mfkj8866/GeoLibre/blob/fix/cad-text-encoding/issue/ansi936-text.dxf

The original drawing is DXF AC1018, $DWGCODEPAGE = ANSI_936, with TEXT/MTEXT such as 工程名称, 集电线路, 兴业大平山风电项目, and ZC-YJLV22-26/35kV-3×95mm2. It is larger than GitHub's issue-attachment limit, so it is not uploaded here.

Screenshots or logs

Attribute table after loading the CAD layer. Red arrows mark garbled Layer and Text values (¼¯µçÏß·, μ Àý, ¡Á, …):

Attribute table showing CAD Layer and Text fields as GBK-as-Latin-1 mojibake

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