GenericMappingTools / GenericMappingTools/gmt

GMT sometime gives garbled Chinese characters

Open
#2,401 12 comments 0 reactions 0 assignees View on GitHub
longterm
Dominant language
C
Stars
979
Forks
414
Avg merge
17h 26m
Merged PRs (30d)
54

Description

GMT can plot Chinese characters after some simple configurations, but for some Chinese characters, the output is quite garbled.

Steps to reproduce the issue:

1. The attached file [text.txt](https://github.com/GenericMappingTools/gmt/files/4022164/text.txt) is a plain text file, which contains only one record `5 5 中文剑号巨阙`. **The text is GB-2321 encoded, not UTF8**. So you have to open it with "GB-2321" encoding to see the real Chinese characters.
2. Run `gmt pstext text.txt -R0/10/0/10 -JX10c > map.ps`
3. Open the PS file `map.ps` with encoding "GB-2321". At the end of the PS file, you will see
![image](https://user-images.githubusercontent.com/3974108/71768972-4221f200-2ee9-11ea-94ca-15d498a356ec.png). The first three Chinese characters are correct, and the others are wrong.

With GB-2321 encoding, the hex codes of these Chinese characters are (two bytes for each Chinese character).
```
D6 D0 CE C4 BD A3 BA C5 BE DE E3 DA
```
The hex code of `号` is `BA C5`, and the hex code of `巨` is `BE DE`. However, in the function `psl_fix_utf8`, `C5 BE` (one byte from `号` and one byte from `巨`) is interpreted/fixed as `ž`, resulting in the garbled Chinese characters.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.