2438 views|4 replies

28

Posts

1

Resources
The OP
 

How to use the national standard font library (HZK16, ASC16) to basically solve the Chinese display problem under Micropython [Copy link]

 
This post was last edited by lemon1394 on 2021-8-23 23:37

There are many problems with fonts. Many netizens' methods have their own advantages and disadvantages, which are summarized as follows:

  • The font library needs to be modeled by yourself. After it is made into a TXT file, it is huge in size and the reading algorithm is complicated, and Chinese cannot be used as you wish.
  • The character library is in dictionary format, which takes up a lot of memory when loaded and is easy to read, but can only store a few Chinese characters.
  • The Chinese character modeling software is complex to set up, difficult to add midway, and often needs to be modified.

Based on the above problems, the font file should be generated as far as possible, and the file size should not be too large. In this case, it is more appropriate to use standard fonts such as HZK16 and ASC16.

The ASC16 font library is not a big problem to drive, but HZK16 is difficult. The biggest problem is encoding.

ASC16 driving method:

ASC16 is a binary file arranged in the order of ASCII codes. After opening the file, just jump the file pointer to the position corresponding to the character and read the 16-byte dot matrix.

f.open('ASC16', 'rb')
f.seek((ord('A') * 16)
buf = f.read(16)

f.close

The ord() function here returns the unicode code value of the character, which is actually the sequence number of this character in the unicode code. ASC16 is sorted according to the ASCII code, so you can directly take out the desired dot matrix.

However, HZK16 is not sorted by unicode code, but by area code. GBK encoding has no direct operable correspondence with unicode code, so the desired dot matrix data cannot be directly retrieved.

Python supports GBK encoding, but MicroPython does not, so the best way is to make a transcoding table and store the area code of each Chinese character according to the unicode encoding number.

First find the area code of the Chinese character in the conversion table, and then use the area code to find the corresponding dot matrix in HZK16. Although there is an additional conversion table, there is no need for polling, so the efficiency is still very high.

Latest reply

You can take a look first~   Details Published on 2023-2-6 09:30
 
 

6555

Posts

0

Resources
2
 

Find the area code of the Chinese character in the conversion table, and then use the area code to find the corresponding dot matrix in HZK16. It is indeed efficient.

 
 
 

1w

Posts

25

Resources
3
 
 
 
 

64

Posts

0

Resources
4
 

Recommend my Chinese support

https://github.com/wangshujun-tj/mpy-Framebuf-boost-code

More than you expect

Supports text magnification, highlighting, rotation, up to 12, 16, 24, 32 dots, supports gb2312 and gbk18030 fonts

Other repositories contain compiled firmware and screen examples

Comments

You can take a look first~  Details Published on 2023-2-6 09:30
 
 
 

64

Posts

0

Resources
5
 
wangshujun72 posted on 2023-2-6 08:54 I recommend the Chinese support https://github.com/wangshujun-tj/mpy-Framebuf-boost-code I made. It has more content than you expect...

You can take a look first~

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list