zst-embedded / STM32-LCD_Font_Generator

Generate text font for STM32xx-EVAL's LCD driver
GNU Affero General Public License v3.0
38 stars 21 forks source link

Error for decode Chinese on python script #1

Closed evan-opener closed 6 years ago

evan-opener commented 6 years ago

Hi, I am very happy to get this library to solve the issue for CN display. I can use the example font on my MCU and it works well. But I got trouble to create my own font C header.

I got an error on python when use the script to create font header. I added # -*- coding: utf-8 -*- on python script but I still got that error.

OS: WIN7 PRO Python 3.6.4 x86

D:\project\STM32-LCD_Font_Generator>python3 stm32-font.py -f msyh.ttf -s 24 -c . \example-chinese\chinese-hello-world.txt Traceback (most recent call last): File "stm32-font.py", line 151, in CHAR_SET = f.read().splitlines()[0] UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal mu ltibyte sequence

zst123 commented 6 years ago

Hello, thanks for trying it out :)

Seems like the error is that chinese-hello-world.txt is trying to open using gbk instead of utf-8.

Can you try to change this line to the following: with open(args.charset, encoding='utf-8') as f:

Please let me know if it works.

evan-opener commented 6 years ago

Hello.

Thanks for your reply and I think it is the decoder issue on txt file. I use the vscode to save the chinese-hello-world.text in Simplified Chinese GB2312 and it works.

Then I tried with the code with open(args.charset, encoding='utf-8') as f: and have the chinese-hello-world.txt in utf-8. It also works.

Thanks a lot.