translation:Achieving of Chinese Display in the embedded graphical user interface of uC/GUI in Two

Translation:http://www.docin.com/p-43459745.html#

I only translate essential parts of this essay and omit trivial parts.



Achieving of Chinese Display in the embedded graphical user interface of uC/GUI in Two Methods

Abstract: This article provides two methods for the uC/GUI to achieve the Chinese display, and each of them makes an analysis its specific project implementation, scope and limitations. In the hardware environment, the actual testing and using prove that these two implementations are reliable and practical. In this paper, the two kinds of ideas for uC/GUI to achieve the Chinese display also have a certain significance as reference to implement Chinese display in other GUI.

Keywords: uC/GUI, Chinese display, embedded system, GUI



1.Propaedeutics:

Related knowledge below is necessary before learning how to display Chinese in the embedded graphical user interface uC/GUI:



1.1 The principle of displaying Chinese in dot lattice

In brief, the dot lattice of a word refers to how many pixels are used to display a Chinese and which color each pixel is set in. In general, HZK16 uses 16*16 dot lattice, that is using 256 pixels to display a Chinese. There are two kinds of color of these dots: foreground colorand background color.

Then, how to decide which dot is set in foreground color, which one in background color?

We can think like this: write a Chinese in a 16*16 square grid on paper. We can see clearly which grids strokes pass through. So these passed grids are set in foreground color and the last in background color.

Now, we have to use data to save the information of dot lattice. Usually, we use 32 bytes to present a Chinese in 16*16 dot lattice. That is using 2 bytes per line to describe the colors of 16 pixels, 0 presents background color, 1 presents foreground color, so 16 lines need 32 bytes.

The principle of displaying Chinese in dot lattice also determines its shortcomings—lack of amplification characteristics. Because its display is based on the fixed dot lattice. After amplifying the Chinese, obvious saw tooth is generated around the Chinese. This problem can hardly be solved.

The virtue of displaying Chinese in dot lattice is simple, to complex Chinese, its process is faster, compared with vector displaying Chinese.

uC/GUI also uses dot lattice to display Chinese.



1.2 The font in uC/GUI

There are two kinds of fonts in uC/GUI: one is Monospaced Font, in which all words are in same width and its corresponding structure body in uC/GUI is GUI_FONT_MONO; the other is Proportional font, in which all words have their independent widths—each word can have different width, and its corresponding structure body is GUI_FONT_PROP. To monospaced font, we usually put the dot lattices of all words in arrays because all words have same width. To proportional font, we use an array to define the dot lattice of a word individually, then put the information of width and height of the word into the array (its corresponding structure body in uC/GUI is GUI_CHARINFO).

The first method to display Chinese in uC/GUI below is to use proportional font. In this kind of font library, each word owns its corresponding font and the two structure bodies GUI_FONT and GUI_FONT_PROP manage all words’ fonts. In GUI_FONT,the size of dot lattice of the word (like 16*16 or 8*8) and the entry address of GUI_FONT_PROP are defined. GUI_FONT_PROP builds character coding in character library and mapping of address where font data is saved.



2. Two methods to display Chinese in uC/GUI

Below are two methods to display Chinese in uC/GUI in detail. Two methods have their own virtues and adapt to different request and application environment.



2.1 The first method

You can download the software UCGUIGenApp which can generate different proportional fonts atwww.ucgui.com. By this software, you can generate a .c file which is similar to proportional font library in uC/GUI.

First, open UCGUIGenAPP.exe, choose font like song typeface, font style like general, size like 12. Then in the output limited GBK code window input the desired Chinese, like”我是谁”,then kick the sure button, the SimSun_16.c file will be generated automatically in the path where UCGUIGenApp.exe belongs to.

Add SimSum_16.c file to the font fold in uC/GUI project.

Aimed at the new font library, make a declaration like below before using:

extern GUI_FLASH const GUI_FONT GUI-FontHZ_SimSun_16;(but I find declaration like this may be wrong, because during my debug, compiler always reports errors,but if declaration like extern const GUI_FONT GUI_FontHZ_SimSun_16; is right)

After declaration, use it like this:

GUI_SetFont(&GUI_FontHZ_SimSun_16); //set font

GUI_DispStringAt(“我是谁abc”,10,30);

Although this method is simple, it only fits in small self-defined Chinese character library. If full Chinese character library is needed, this method is not practical and recommended, because font library generated by this method occupies large space, like 4000 Chinese characters’ fonts would occupy more than 200K bytes storage space, it would take more time to debug and download and it is inconvenient and low efficient. Because of complicated structure and process, we cannot store the font library in exterior flash storage.



2.2 the second method

Aimed at the limitation of the first method, we can display Chinese by analyzing character display function. We can add judgment of whether character is Chinese in _DispLine(const char GUI_UNIT_PTR *s, int MaxNumChars, const GUI_RECT *pRect) function to realize the display of Chinese in uC/GUI. Here Chinese display is controllable and font library can be stored in exterior storage.

Modify the function like below to support Chinese display

static void _DispLine(const char GUI_UNI_PTR *s, int MaxNumChars, const GUI-RECT *pRect){

GUI_DRAWMODE DrawMode=GUI_Context.TextMode;

GUI_DRAWMODE Old DrawMode;

unsigned char temp=0;

unsigned char FontCN[32];

unsigned int addr;

................

while(--MaxNumChar>=0){

Char=GUI_UC_GetCharCodeInc(&s);

if((Char &0x80)&&((*(U8*)s)&0x80)) // if character is Chinese, display it

{

MaxNumChars--; //Chinese occupies two ASCII spaces, so need one more minus operation

read corresponding Chinese font to array FontCN[32];

OldDrawMode =LCD_SetDrawMode(DrawMode);

//temporarily change global variables operation to be compatible with the font chosed in current uC/GUI

temp=GUI_Context.ClipRect.y1;

GUI_Context.ClipRect.y1=GUI_Context.ClipRect.y1+8;

//display a Chinese

LCD_DrawBitmap(GUI_Context.DispPosX,GUI_Context.DisPosY,

16,16,

1,1,

1,

2,

(U8*)FontCN,

NULL);

GUI_Context.DispPosX=GUI_Context.DispPosX+16;

LCD_SetDrawMode(OldDrawMode);

//resume global variables operation to be compatible with the font chosed in current uC/GUI

GUI_Context.ClipRect.y1=temp;

s++;

}

else

GUI_Context.pAFont->pfDispChar(Char);

if(GUI_pfDispCharStyle){

GUI_pfDispCharStyle(Char);

}

}

}

}



referance:

http://www.laogu.com/wz_8456.htm

http://wenku.baidu.com/view/1f35ab51f01dc281e53af0e9.html

http://happywu5.blog.163.com/blog/static/2790040220096585798/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值