How to change Chinese Font in STM32F103 C programming

Thread Starter

Hasan2019

Joined Sep 5, 2019
62
Hi there,


I am handling a project which has display application both for English and Korean front but I would like to add Chiness front in it.
For that reason, I have to add more thing in front.c and front.h etc.

I can made some Chineess front/ charecter using Note pad pixel and a software named KSX1001 frontedit
BMP to front can be made. i.e IMAGE SIZE-16*16, front size-32. Software output gives .c file when input is a .bmp file.

Take a look output c file for a given .bmp,

Code:
#define byte unsigned char
#define word unsigned int
//---------------------------------------------------------
extern code byte ImageFontTbl[];
//---------------------------------------------------------

code byte ImageFontTbl[]={    // ImageSize: 16 X 16
    0xff,0x7f,    // QQQQQQQQ.QQQQQQQ
    0xff,0x7f,    // QQQQQQQQ.QQQQQQQ
    0xff,0x7f,    // QQQQQQQQ.QQQQQQQ
    0xff,0x7f,    // QQQQQQQQ.QQQQQQQ
    0xc0,0x01,    // QQ.............Q
    0xdf,0x7d,    // QQ.QQQQQ.QQQQQ.Q
    0xdf,0x7d,    // QQ.QQQQQ.QQQQQ.Q
    0xdf,0x7d,    // QQ.QQQQQ.QQQQQ.Q
    0xdf,0x7d,    // QQ.QQQQQ.QQQQQ.Q
    0xc0,0x01,    // QQ.............Q
    0xdf,0x7d,    // QQ.QQQQQ.QQQQQ.Q
    0xff,0x7f,    // QQQQQQQQ.QQQQQQQ
    0xff,0x7f,    // QQQQQQQQ.QQQQQQQ
    0xff,0x7f,    // QQQQQQQQ.QQQQQQQ
    0xff,0x7f,    // QQQQQQQQ.QQQQQQQ
    0xff,0x7f,    // QQQQQQQQ.QQQQQQQ
   
};    // FontSize= 32

Now my original front.c file called image registor in following way

Code:
const unsigned char IMAGE_16_16[COUNT_OF_16_IMAGE][32] = {

{0x11,0xaa,0x44,0x00,0xff,0x00,0xff,0x00,0x44,0xaa,0x11,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00}, // trace
{0x00,0xfe,0x02,0x12,0x12,0x12,0x12,0x82,0x42,0x22,0x12,0x0a,0x06,0xfe,0x00,0x00,0x00,0x3f,0x30,0x28,0x24,0x22,0x21,0x24,0x22,0x24,0x28,0x24,0x20,0x3f,0x00,0x00}, // Inverter
{0xff,0x01,0xfd,0xed,0xed,0xed,0xed,0x7d,0xbd,0xdd,0xed,0xf5,0xf9,0x01,0xff,0x00,0x7f,0x40,0x4f,0x57,0x5b,0x5d,0x5e,0x5b,0x5d,0x5b,0x57,0x5b,0x5f,0x40,0x7f,0x00}, // Reverse invertion
................................
................................
Another place they have represent korean front as follows,

Code:
const unsigned char FONT_HAN[0x168][32] = {  
  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  {0x00, 0x04, 0x04, 0x04, 0xc4, 0xfc, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x18, 0x0e, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  {0x00, 0x04, 0x04, 0xfc, 0xfc, 0x04, 0xfc, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1f, 0x07, 0x18, 0x1f, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
..................................
................................
Even they have also present each letter

Code:
const unsigned char WAN_TO_JO[0x92E][2] = {
    {0x88, 0x61},// 가
    {0x88, 0x62},// 각
    {0x88, 0x65},// 간
    {0x88, 0x68},// 갇
    {0x88, 0x69},// 갈
    {0x88, 0x6a},// 갉
    {0x88, 0x6b},// 갊
    {0x88, 0x71},// 감
    {0x88, 0x73},// 갑
    {0x88, 0x74},// 값
    {0x88, 0x75},// 갓
    {0x88, 0x76},// 갔
...............................
...............................

Kindly suggest me what to do things for chiness. Does Image count has particular meaning to display it?
Does chiness front also need ASCI II charecter ? My front C also includes ASCI II.
Figure out the difference between IMAGE and FRONT of constant unsigned charecter.
 
Last edited by a moderator:

click_here

Joined Sep 22, 2020
533
The charactors are not part of the ASCII code.

Have a look into the wchar_t data type and the wprintf(...) function. (All in "wchar.h")

From there, look for a tutorial on how to set your system up to view the charactors correctly :)
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
62
The charactors are not part of the ASCII code.

Have a look into the wchar_t data type and the wprintf(...) function. (All in "wchar.h")

From there, look for a tutorial on how to set your system up to view the charactors correctly :)
My application LCD also have English charector also. Do you have such kind of example code? Front.c also includes for size 6, 16

I have to modify all code. What I am doing is from the Chinese .bmp files I am making an unsigned FONT_CN[ 0×168][32]. Don't you think dimention is not ok?

Registers are defined for a particular LCD output for sure.
 

click_here

Joined Sep 22, 2020
533
0x168 = 360

So you are making an array of

360 * 32 = 11520 chars

That's fairly large, but whether or not that fits on your system depends on what you are running your program on.

From the C99 standards wrt multibyte charactors
5.2.1.2 Multibyte characters
...
The presence, meaning, and representation of any additional members is locale-specific.
That is to say, your LCD might/might not natively support the Chinese charactor set - What LCD screen are you using? Have you checked the documentation?

I personally have never written a program that uses Hanzi, but the usual thing when using a different character set is to use the function setlocal(...) from <locale.h>
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
62
0x168 = 360

So you are making an array of

360 * 32 = 11520 chars

One expart says,

Look at your first image, then think of the hexadecimal numbers in binary. You have 16 rows of 16 bits (the two bytes). Each bit decides whether the pixel within the font is bright or dark to construct the shape of the character.

If you start with a 16x16 grid, draw the shape you want to see which squares are dark or bright then divide it down the middle from top to bottom. Convert the filled squares to '1' and the empty ones to '0' to get a binary number then convert it to hex. Do the same for the both sides to get the two hex numbers for that line of the font.

Remember that in most cases there is a border around characters and it it usually part of the font itself so you should leave at least one border dark to create the gap between them.
That's fairly large, but whether or not that fits on your system depends on what you are running your program on.

From the C99 standards wrt multibyte charactors
I understand what you mean, but parhaps there will be some possibility.


That is to say, your LCD might/might not natively support the Chinese charactor set - What LCD screen are you using? Have you checked the documentation?
Yes I do have specification, Model Number : CD07017-06 Product Type : COG,FSTN .
See the attched files.

I personally have never written a program that uses Hanzi, but the usual thing when using a different character set is to use the function setlocal(...) from <locale.h>
STM32F103 library also has similar header.
 

Attachments

Thread Starter

Hasan2019

Joined Sep 5, 2019
62
Is there somewhere else that you've asked for help?
I want to make display for particular chinesse text.
I got a clue for it.

From the all image file, I got a range of 11000 hex data. All are possible matrix. Among those I made a sequence those are requred text charecter. But the problem is for repeting charecters. Image looks same but hex data are different.
 
Top