Chinaunix首页 | 论坛 | 博客
  • 博客访问: 165846
  • 博文数量: 73
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 235
  • 用 户 组: 普通用户
  • 注册时间: 2014-06-27 09:43
个人简介

为兴趣挑灯夜战

文章分类
文章存档

2018年(4)

2017年(7)

2016年(9)

2015年(4)

2014年(49)

分类: 嵌入式

2016-08-11 23:18:13

本文是讲一种快速制作字库的方法,在不需要显示大量中文的时候,一般是两三百个以内的,使用我要说的这种方法效率非常高。如果是完整的GBK字库那需要把字库存在Flash存储器上,但在此就不讲了。
先介绍一下这个字库的来源,那是在几年前使用ucGUI时,发现它里面的那个字库很有意思,很直观,不再是枯燥十六进制代码,但是还是没有中文字库,后来我就在网上找软件,果然找到一个可以生成ucGUI格式的中文字库的软件----ucGUI-gb2312汉字生成器v3,在此得感谢这位大侠提供了这个软件,也才有我今天要说的内容。
现在看看这个软件生成的字库长什么样吧:


这个软件操作简单,在此不多说,如果你真用得着的时候自己去摸索,为了简洁,我没勾选ASCII码,把生成的字库导出来,如下:


点击(此处)折叠或打开

  1. #include "GUI.H"
  2.  
  3.  
  4. /* char: 好 code:0xBAC3 */
  5. unsigned char acFontHZ_BAC3[24] = {
  6.   __X_____,________,
  7.   __X__XXX,XX______,
  8.   __X_____,_X______,
  9.   XXXXX___,X_______,
  10.   _X__X__X,________,
  11.   _X__X__X,________,
  12.   _X__XXXX,XXX_____,
  13.   X__X___X,________,
  14.   _X_X___X,________,
  15.   __X____X,________,
  16.   _X_X___X,________,
  17.   X___X_XX,________
  18. };

  19. /* char: 界 code:0xBDE7 */
  20. unsigned char acFontHZ_BDE7[24] = {
  21.   _XXXXXXX,XX______,
  22.   _X___X__,_X______,
  23.   _XXXXXXX,XX______,
  24.   _X___X__,_X______,
  25.   _XXXXXXX,XX______,
  26.   _____X__,________,
  27.   ___XX_XX,________,
  28.   XXX_____,XXX_____,
  29.   ___X___X,________,
  30.   ___X___X,________,
  31.   __X____X,________,
  32.   _X_____X,________
  33. };

  34. /* char: 你 code:0xC4E3 */
  35. unsigned char acFontHZ_C4E3[24] = {
  36.   ___X_X__,________,
  37.   ___X_X__,________,
  38.   __X__XXX,XXX_____,
  39.   __X__X__,__X_____,
  40.   _XX_X__X,_X______,
  41.   X_X____X,________,
  42.   __X__X_X,_X______,
  43.   __X__X_X,__X_____,
  44.   __X__X_X,__X_____,
  45.   __X_X__X,__X_____,
  46.   __X____X,________,
  47.   __X___XX,________
  48. };

  49. /* char: 世 code:0xCAC0 */
  50. unsigned char acFontHZ_CAC0[24] = {
  51.   _____X__,X_______,
  52.   __X__X__,X_______,
  53.   __X__X__,X_______,
  54.   __X__X__,X_______,
  55.   XXXXXXXX,XXX_____,
  56.   __X__X__,X_______,
  57.   __X__X__,X_______,
  58.   __X__X__,X_______,
  59.   __X__XXX,X_______,
  60.   __X_____,________,
  61.   __X_____,________,
  62.   __XXXXXX,XXX_____
  63. };

  64. GUI_CHARINFO GUI_FontHZ_12x12_CharInfo[4] = {
  65.   { 12, 12, 2, (unsigned char *)&acFontHZ_BAC3 }, /*0:*/
  66.   { 12, 12, 2, (unsigned char *)&acFontHZ_BDE7 }, /*1:*/
  67.   { 12, 12, 2, (unsigned char *)&acFontHZ_C4E3 }, /*2:*/
  68.   { 12, 12, 2, (unsigned char *)&acFontHZ_CAC0 }, /*3:*/
  69. };

  70. GUI_FONT_PROP GUI_FontHZ_12x12_Prop4 = {
  71.   0xCAC0, /*start :*/
  72.   0xCAC0, /*end :, len=1*/
  73.   &GUI_FontHZ_12x12_CharInfo[ 3 ],
  74.   (void*)0
  75. };


  76. GUI_FONT_PROP GUI_FontHZ_12x12_Prop3 = {
  77.   0xC4E3, /*start :*/
  78.   0xC4E3, /*end :, len=1*/
  79.   &GUI_FontHZ_12x12_CharInfo[ 2 ],
  80.   &GUI_FontHZ_12x12_Prop4
  81. };


  82. GUI_FONT_PROP GUI_FontHZ_12x12_Prop2 = {
  83.   0xBDE7, /*start :*/
  84.   0xBDE7, /*end :, len=1*/
  85.   &GUI_FontHZ_12x12_CharInfo[ 1 ],
  86.   &GUI_FontHZ_12x12_Prop3
  87. };


  88. GUI_FONT_PROP GUI_FontHZ_12x12_Prop1 = {
  89.   0xBAC3, /*start :*/
  90.   0xBAC3, /*end :, len=1*/
  91.   &GUI_FontHZ_12x12_CharInfo[ 0 ],
  92.   &GUI_FontHZ_12x12_Prop2
  93. };


  94. GUI_FONT GUI_FontHZ12x12 = {
  95.   GUI_FONTTYPE_PROP_SJIS,
  96.   12,
  97.   12,
  98.   1,
  99.   1,
  100.   &GUI_FontHZ_12x12_Prop1
  101. };


 注意:在正式使用时要把所有的unsigned char替换成const unsigned char,这样代码才会不会放到单片机的RAM中而是flash中
上面字库中GUI_FontHZ12x12就是这个字库的名字,它是字库链表的头,在显示函数中就是通过这个头去查找要显示的字所在字库的位置,
看看下面这个数组:

点击(此处)折叠或打开

  1. GUI_CHARINFO GUI_FontHZ_12x12_CharInfo[4] = {
  2.   { 12, 12, 2, (unsigned char *)&acFontHZ_BAC3 }, /*0:*/
  3.   { 12, 12, 2, (unsigned char *)&acFontHZ_BDE7 }, /*1:*/
  4.   { 12, 12, 2, (unsigned char *)&acFontHZ_C4E3 }, /*2:*/
  5.   { 12, 12, 2, (unsigned char *)&acFontHZ_CAC0 }, /*3:*/
  6. };



这个数组中存的就是生成的每一个字符或汉字的信息,看数组中的第一行,12, 12, 2, (unsigned char *)&acFontHZ_BAC3,从左到右分别是字库点阵的行宽、列数、每行所占字节数。

点击(此处)折叠或打开

  1. /* char: 好 code:0xBAC3 */
  2. unsigned char acFontHZ_BAC3[24] = {
  3.   __X_____,________,
  4.   __X__XXX,XX______,
  5.   __X_____,_X______,
  6.   XXXXX___,X_______,
  7.   _X__X__X,________,
  8.   _X__X__X,________,
  9.   _X__XXXX,XXX_____,
  10.   X__X___X,________,
  11.   _X_X___X,________,
  12.   __X____X,________,
  13.   _X_X___X,________,
  14.   X___X_XX,________
  15. };


这个数组就是字库中好字的点阵,第一次看到这些“X”和“_”我也很疑惑,其实它只是红定义,“X”代表二进制的1,"_"代表二进制的0 。__X_____表示的就是0010 0000(二进制),注释中的BAC3就是好字的GBK码,显示函数就是通过这个编码来查找到存放“好”字点阵数据的这个数组,再根据这个点阵的行、列和每行所占字节数的信息来在屏幕上绘字。
要使用这个字库还得需要两个uCGUI中的头文件,GUI.h和GUIType.h,这两个文件的代码放在最后面,现在来看看使用这个字库的代码:

点击(此处)折叠或打开

  1. #include "GUI.h"

  2. GUI_FONT * SystemFont=&GUI_FontHZ12x12;

  3. extern UInt8 s_lcdBuff[(LCD_Y_MAX+1)/8][LCD_X_MAX+1];


  4. u8 ScreenDrawPoint(u8 x,u8 y,u8 color);//在屏上画一个点的函数

  5. extern void def_CDC_setPoint(UInt8 (*pLcdBuff)[LCD_X_MAX+1],LCDSIZETYPE xpoint,LCDSIZETYPE ypoint,COLOR color);

  6. const GUI_CHARINFO * GetBitMapStruct(GUI_FONT  *Font,u16 ch)//根据字符编码查找字符点阵数据
    {
        GUI_FONT_PROP  pProp;
        pProp.First=Font->pProp->First;
        pProp.Last= Font->pProp->Last;
        pProp.paCharInfo=Font->pProp->paCharInfo;
        pProp.pNext=Font->pProp->pNext;

        if((ch>=0x20 && ch<=0x7F)&& (pProp.First>=0x20 && pProp.Last<=0x7F))
        {
            while((chpProp.Last)&&pProp.pNext>0)
            {
                memcpy(&pProp,pProp.pNext,sizeof( GUI_FONT_PROP));
            }        
            if(pProp.First==pProp.Last&&ch==pProp.First)
                return pProp.paCharInfo;
            else if(!(chpProp.Last)&&pProp.First             return &pProp.paCharInfo[ch-pProp.First];
            else if(!pProp.pNext&&ch>pProp.Last)
                return Font->pProp->paCharInfo;//反回空格    
        }
        else if(ch>=0x8140 && ch<=0xfefe)
        {    
            while((chpProp.Last)&&pProp.pNext>0)
            {
                memcpy(&pProp,pProp.pNext,sizeof( GUI_FONT_PROP));
            }        
            if(pProp.First==pProp.Last&&ch==pProp.First)
                return pProp.paCharInfo;
            else if(!(chpProp.Last)&&pProp.First             return &pProp.paCharInfo[ch-pProp.First];
            else if(!pProp.pNext&&ch>pProp.Last)
                return Font->pProp->paCharInfo;//反回空格                        
        }            
        return Font->pProp->paCharInfo;//反回空格
    }


  7. void ShowChar(u16 x,u16 y,const GUI_CHARINFO * BitMapStruct,u16 FontColor,u16 BkColor)//显示一个字符的函数
  8. {
  9.     u8 BitMapData;
  10.     u8 i,j,m;
  11.     u16 x0=x;//保存x 起点
  12.     
  13.     if(x>MAX_CHAR_POSX||y>MAX_CHAR_POSY)return;
  14.     
  15.         for(i=0;iXDist;i++)
  16.         {
  17.             for(j=0;jBytesPerLine;j++)//显示点阵的一行
  18.             {
  19.                 BitMapData=BitMapStruct->pData[i*BitMapStruct->BytesPerLine+j];
  20.                 for(m=0;m<8;m++)
  21.                 {
  22.                     if(BitMapData&0x80)
  23.                         DrawPoint(x,y,FontColor);
  24.                     else
  25.                         DrawPoint(x,y,BkColor);
  26.                     BitMapData<<=1;
  27.                     x++;
  28.                     if((x-x0)>=BitMapStruct->XSize)
  29.                         break;
  30.                 }
  31.             }
  32.             x=x0;
  33.             y++;
  34.         }
  35. }


  36. void ShowStrings(u16 x,u16 y, GUI_FONT *Font,const u8*pStrings,u16 FontColor,u16 BkColor)//显示一串字符的函数
  37. {
  38.     u8 i=0;
  39.     u16 Strings[64]={0};
  40.     const GUI_CHARINFO * BitMapStruct;
  41.     u8 StringSize=0;

  42.     for(i=0;pStrings[i++]!='\0';StringSize++);//计算字符长度
  43.     for(i=0;StringSize>0;i++)
  44.     {
  45.         if(*pStrings<0x7f)
  46.         {
  47.             Strings[i]=(u16)*pStrings;
  48.             pStrings++;
  49.             StringSize--;
  50.         }
  51.         else if(*pStrings>0x7f)
  52.         {
  53.             Strings[i]=((u16)*pStrings)<<8;
  54.             pStrings++;
  55.             StringSize--;
  56.             Strings[i]|=(u16)*pStrings;
  57.             pStrings++;
  58.             StringSize--;
  59.         }
  60.     }
  61.                     
  62.     StringSize=0;
  63.     i=0;
  64.     for(i=0;Strings[i++]>0x19;StringSize++);//计算字符长度
  65.     
  66.     for(i=0;i {
  67.         BitMapStruct=GetBitMapStruct(Font,Strings[i]);
  68.         if(x>(127-BitMapStruct->XSize))
  69.         {
  70.             y+=BitMapStruct->XDist+1;
  71.             x=0;
  72.         }
  73.         ShowChar(x,y,BitMapStruct,FontColor,BkColor);
  74.         x+=BitMapStruct->XSize+1;
  75.     }
  76. }



  77. u8 ScreenDrawPoint(u8 xpoint,u8 ypoint,u8 color)//画点的函数
  78. {
  79.     UInt8 row,col,offset;
  80.     
  81.     if( (xpoint>LCD_X_MAX) || (ypoint>LCD_Y_MAX) ) return 1;
  82.     ypoint=LCD_Y_MAX-ypoint;
  83.     row=ypoint/8;
  84.     col=xpoint;
  85.     offset=ypoint%8;
  86.     if( color==COLOR_WHITE ){
  87.         s_lcdBuff[row][col] &= ~(0x01< s_lcdBuff[row][col] |= (0x01< }else if( color==COLOR_XOR ){
  88.         s_lcdBuff[row][col] ^= (0x01< }

  89.     return 0;
  90. }
只要实现在屏上任意坐标画一个点的函数,就可以实现利用上面的函数了,如上面的u8 ScreenDrawPoint(u8 x,u8 y,u8 color),函数中查找字符信息的函数const GUI_CHARINFO * GetBitMapStruct(GUI_FONT  *Font,u16 ch)有点难度,这需要对字库结构仔细研究一下才能理解,在此不多说,大家先把代码利用起来再慢慢研究。要显示一串字符只需要调用ShowStrings(u16 x,u16 y, GUI_FONT  *Font,const u8*pStrings,u16 FontColor,u16 BkColor)函数,参数x是屏幕X坐标,y是屏幕Y坐标,Font是指定的字库,如ShowStrings(5,10, GUI_FontHZ12x12,“世界你好”,0,0);
下面是GUI.h和GUIType.h的代码:

点击(此处)折叠或打开

  1. //GUIType.h文件
  2. #ifndef GUITYPE_H_INCLUDED
  3. #define GUITYPE_H_INCLUDED

  4. #include "LCD.h"
  5. #include "GUIConf.h"

  6. /* *************************************************************
  7.         * *
  8.         * Simple types *
  9.         * *
  10.         *************************************************************
  11. */

  12. typedef const char * GUI_ConstString;


  13. /* *************************************************************
  14.         * *
  15.         * Structures *
  16.         * *
  17.         *************************************************************
  18. */

  19. typedef LCD_COLOR GUI_COLOR;
  20. typedef LCD_LOGPALETTE GUI_LOGPALETTE;
  21. typedef LCD_DRAWMODE GUI_DRAWMODE;
  22. typedef LCD_RECT GUI_RECT;

  23. typedef struct {
  24.   void (* pfDraw)(int x0,int y0,int xsize, int ysize, const U8 GUI_UNI_PTR * pPixel, const LCD_LOGPALETTE GUI_UNI_PTR * pLogPal, int xMag, int yMag);
  25.   GUI_COLOR (* pfIndex2Color)(int Index);
  26. } GUI_BITMAP_METHODS;

  27. typedef struct {
  28.   U16P XSize;
  29.   U16P YSize;
  30.   U16P BytesPerLine;
  31.   U16P BitsPerPixel;
  32.   const U8 GUI_UNI_PTR * pData;
  33.   const GUI_LOGPALETTE GUI_UNI_PTR * pPal;
  34.   const GUI_BITMAP_METHODS * pMethods;
  35. } GUI_BITMAP;

  36. /* This structure may not be changed because the data that it
  37.    expects is read in binary form (via any kind of interface,
  38.    at runtime).
  39.    This structure should therefor not be changed.
  40. */
  41. typedef struct {
  42.   U16 ID; /* Version 1.00 => 100*/
  43.   U16 Version;
  44.   U16 XSize;
  45.   U16 YSize;
  46.   U16 BytesPerLine;
  47.   U16 BitsPerPixel;
  48.   U16 NumColors;
  49.   U16 HasTrans;
  50. } GUI_BITMAP_STREAM;

  51. typedef struct {
  52.   int x,y;
  53.   unsigned char Pressed;
  54. } GUI_PID_STATE;

  55. /*
  56.       ****************************************
  57.       * *
  58.       * FONT structures (new in V1.10) *
  59.       * *
  60.       ****************************************
  61. */

  62. /* Translation list. Translates a character code into up to 2
  63.    indices of images to display on top of each other;
  64.    '? -> index('a'), index('?) */
  65. typedef struct {
  66.   I16P c0;
  67.   I16P c1;
  68. } GUI_FONT_TRANSLIST;

  69. typedef struct {
  70.   U16P FirstChar;
  71.   U16P LastChar;
  72.   const GUI_FONT_TRANSLIST GUI_UNI_PTR * pList;
  73. } GUI_FONT_TRANSINFO;

  74. typedef struct {
  75.   U8 XSize;
  76.   U8 XDist;
  77.   U8 BytesPerLine;
  78.   const unsigned char GUI_UNI_PTR * pData;
  79. } GUI_CHARINFO;

  80. typedef struct GUI_FONT_PROP {
  81.   U16P First; /* first character */
  82.   U16P Last; /* last character */
  83.   const GUI_CHARINFO GUI_UNI_PTR * paCharInfo; /* address of first character */
  84.   const struct GUI_FONT_PROP GUI_UNI_PTR * pNext; /* pointer to next */
  85. } GUI_FONT_PROP;

  86. typedef struct {
  87.   const unsigned char GUI_UNI_PTR * pData;
  88.   const U8 GUI_UNI_PTR * pTransData;
  89.   const GUI_FONT_TRANSINFO GUI_UNI_PTR * pTrans;
  90.   U16P FirstChar;
  91.   U16P LastChar;
  92.   U8 XSize;
  93.   U8 XDist;
  94.   U8 BytesPerLine;
  95. } GUI_FONT_MONO;


  96. typedef struct GUI_FONT_INFO {
  97.   U16P First; /* first character */
  98.   U16P Last; /* last character */
  99.   const GUI_CHARINFO* paCharInfo; /* address of first character */
  100.   const struct GUI_FONT_INFO* pNext; /* pointer to next */
  101. } GUI_FONT_INFO;

  102. /*
  103.       ****************************************
  104.       * *
  105.       * FONT info structure *
  106.       * *
  107.       ****************************************

  108. This structure is used when retrieving information about a font.
  109. It is designed for future expansion without incompatibilities.
  110. */
  111. typedef struct {
  112.   U16 Flags;
  113.   U8 Baseline;
  114.   U8 LHeight; /* height of a small lower case character (a,x) */
  115.   U8 CHeight; /* height of a small upper case character (A,X) */
  116. } GUI_FONTINFO;

  117. #define GUI_FONTINFO_FLAG_PROP (1<<0) /* Is proportional */
  118. #define GUI_FONTINFO_FLAG_MONO (1<<1) /* Is monospaced */
  119. #define GUI_FONTINFO_FLAG_AA (1<<2) /* Is an antialiased font */
  120. #define GUI_FONTINFO_FLAG_AA2 (1<<3) /* Is an antialiased font, 2bpp */
  121. #define GUI_FONTINFO_FLAG_AA4 (1<<4) /* Is an antialiased font, 4bpp */


  122. /**********************************************************************
  123. *
  124. * UNICODE Encoding
  125. *
  126. ***********************************************************************
  127. */
  128. typedef U16 tGUI_GetCharCode(const char GUI_UNI_PTR *s);
  129. typedef int tGUI_GetCharSize(const char GUI_UNI_PTR *s);
  130. typedef int tGUI_CalcSizeOfChar(U16 Char);
  131. typedef int tGUI_Encode(char *s, U16 Char);

  132. typedef struct {
  133.   tGUI_GetCharCode* pfGetCharCode;
  134.   tGUI_GetCharSize* pfGetCharSize;
  135.   tGUI_CalcSizeOfChar* pfCalcSizeOfChar;
  136.   tGUI_Encode* pfEncode;
  137. } GUI_UC_ENC_APILIST;

  138. /**********************************************************************
  139. *
  140. * FONT Encoding
  141. *
  142. ***********************************************************************
  143. */

  144. typedef int tGUI_GetLineDistX(const char GUI_UNI_PTR *s, int Len);
  145. typedef int tGUI_GetLineLen(const char GUI_UNI_PTR *s, int MaxLen);
  146. typedef void tGL_DispLine(const char GUI_UNI_PTR *s, int Len);

  147. typedef struct {
  148.   tGUI_GetLineDistX* pfGetLineDistX;
  149.   tGUI_GetLineLen* pfGetLineLen;
  150.   tGL_DispLine* pfDispLine;
  151. } tGUI_ENC_APIList;

  152. extern const tGUI_ENC_APIList GUI_ENC_APIList_SJIS;


  153. /*
  154.       ****************************************
  155.       * *
  156.       * FONT methods *
  157.       * *
  158.       ****************************************

  159. The parameter to the methods called pFont should be of type
  160. GUI_FONT, but unfortunately a lot of compilers can not handle
  161. forward declarations right ...
  162. So it ends up to be a void pointer.
  163. */

  164. typedef struct GUI_FONT GUI_FONT;

  165. typedef void GUI_DISPCHAR(U16 c);
  166. typedef int GUI_GETCHARDISTX(U16P c);
  167. typedef void GUI_GETFONTINFO(const GUI_FONT GUI_UNI_PTR * pFont, GUI_FONTINFO * pfi);
  168. typedef char GUI_ISINFONT (const GUI_FONT GUI_UNI_PTR * pFont, U16 c);

  169. #define DECLARE_FONT(Type) \
  170. void GUI##Type##_DispChar (U16P c); \
  171. int GUI##Type##_GetCharDistX(U16P c); \
  172. void GUI##Type##_GetFontInfo (const GUI_FONT GUI_UNI_PTR * pFont, GUI_FONTINFO * pfi); \
  173. char GUI##Type##_IsInFont (const GUI_FONT GUI_UNI_PTR * pFont, U16 c)

  174. #if defined(__cplusplus)
  175. extern "C" { /* Make sure we have C-declarations in C++ programs */
  176. #endif

  177. /* MONO: Monospaced fonts */
  178. DECLARE_FONT(MONO);
  179. #define GUI_FONTTYPE_MONO \
  180.   GUIMONO_DispChar, \
  181.     GUIMONO_GetCharDistX, \
  182.     GUIMONO_GetFontInfo, \
  183.     GUIMONO_IsInFont, \
  184.   (tGUI_ENC_APIList*)0

  185. /* PROP: Proportional fonts */
  186. DECLARE_FONT(PROP);
  187. #define GUI_FONTTYPE_PROP \
  188.   GUIPROP_DispChar, \
  189.     GUIPROP_GetCharDistX, \
  190.     GUIPROP_GetFontInfo, \
  191.     GUIPROP_IsInFont, \
  192.   (tGUI_ENC_APIList*)0

  193. /* PROP: Proportional fonts SJIS */
  194. DECLARE_FONT(PROP);
  195. #define GUI_FONTTYPE_PROP_SJIS \
  196.   GUIPROP_DispChar, \
  197.     GUIPROP_GetCharDistX, \
  198.     GUIPROP_GetFontInfo, \
  199.     GUIPROP_IsInFont, \
  200.   &GUI_ENC_APIList_SJIS

  201. /* PROPAA: Proportional, antialiased fonts */
  202. DECLARE_FONT(PROPAA);
  203. #define GUI_FONTTYPE_PROPAA \
  204.   GUIPROPAA_DispChar, \
  205.     GUIPROPAA_GetCharDistX, \
  206.     GUIPROPAA_GetFontInfo, \
  207.     GUIPROPAA_IsInFont, \
  208.   (tGUI_ENC_APIList*)0

  209. /* PROPAA: Proportional, antialiased fonts, 2bpp */
  210. DECLARE_FONT(PROP_AA2);
  211. #define GUI_FONTTYPE_PROP_AA2 \
  212.   GUIPROP_AA2_DispChar, \
  213.     GUIPROP_AA2_GetCharDistX, \
  214.     GUIPROP_AA2_GetFontInfo, \
  215.     GUIPROP_AA2_IsInFont, \
  216.   (tGUI_ENC_APIList*)0

  217. /* PROPAA: Proportional, antialiased fonts, 2bpp, SJIS encoding */
  218. DECLARE_FONT(PROP_AA2);
  219. #define GUI_FONTTYPE_PROP_AA2_SJIS \
  220.   GUIPROP_AA2_DispChar, \
  221.     GUIPROP_AA2_GetCharDistX, \
  222.     GUIPROP_AA2_GetFontInfo, \
  223.     GUIPROP_AA2_IsInFont, \
  224.   GUI_ENCODE_SJIS

  225. /* PROPAA: Proportional, antialiased fonts, 4bpp */
  226. DECLARE_FONT(PROP_AA4);
  227. #define GUI_FONTTYPE_PROP_AA4 \
  228.   GUIPROP_AA4_DispChar, \
  229.     GUIPROP_AA4_GetCharDistX, \
  230.     GUIPROP_AA4_GetFontInfo, \
  231.     GUIPROP_AA4_IsInFont, \
  232.   (tGUI_ENC_APIList*)0

  233. /* PROPAA: Proportional, antialiased fonts, 4bpp, SJIS encoding */
  234. DECLARE_FONT(PROP_AA4);
  235. #define GUI_FONTTYPE_PROP_AA4_SJIS \
  236.   GUIPROP_AA4_DispChar, \
  237.     GUIPROP_AA4_GetCharDistX, \
  238.     GUIPROP_AA4_GetFontInfo, \
  239.     GUIPROP_AA4_IsInFont, \
  240.   GUI_ENCODE_SJIS

  241. #if defined(__cplusplus)
  242.   }
  243. #endif

  244. struct GUI_FONT {
  245.   GUI_DISPCHAR* pfDispChar;
  246.   GUI_GETCHARDISTX* pfGetCharDistX;
  247.   GUI_GETFONTINFO* pfGetFontInfo;
  248.   GUI_ISINFONT* pfIsInFont;
  249.   const tGUI_ENC_APIList* pafEncode;
  250.   U8 YSize;
  251.   U8 YDist;
  252.   U8 XMag;
  253.   U8 YMag;
  254.   union {
  255.     const void GUI_UNI_PTR * pFontData;
  256.     const GUI_FONT_MONO GUI_UNI_PTR * pMono;
  257.     const GUI_FONT_PROP GUI_UNI_PTR * pProp;
  258.   } p;
  259.   U8 Baseline;
  260.   U8 LHeight; /* height of a small lower case character (a,x) */
  261.   U8 CHeight; /* height of a small upper case character (A,X) */
  262. };

  263. /*********************************************************************
  264. *
  265. * Position independent font structures
  266. */
  267. typedef struct {
  268.   U32 ID; /* Font file ID */
  269.   U16 YSize; /* Height of font */
  270.   U16 YDist; /* Space of font Y */
  271.   U16 Baseline; /* Index of baseline */
  272.   U16 LHeight; /* Height of a small lower case character (a) */
  273.   U16 CHeight; /* Height of a upper case character (A) */
  274.   U16 NumAreas; /* Number of character areas */
  275. } GUI_SI_FONT;

  276. typedef struct {
  277.   U16 First; /* Index of first character */
  278.   U16 Last; /* Index of last character */
  279. } GUI_SIF_CHAR_AREA;

  280. typedef struct {
  281.   U16 XSize; /* Size of bitmap data in X */
  282.   U16 XDist; /* Number of pixels for increment cursor in X */
  283.   U16 BytesPerLine; /* Number of bytes per line */
  284.   U16 Dummy;
  285.   U32 OffData; /* Offset of pixel data */
  286. } GUI_SIF_CHARINFO;

  287. typedef struct tGUI_SIF_APIList_struct {
  288.   GUI_DISPCHAR * pDispChar;
  289.   GUI_GETCHARDISTX * pGetCharDistX;
  290.   GUI_GETFONTINFO * pGetFontInfo;
  291.   GUI_ISINFONT * pIsInFont;
  292. } tGUI_SIF_APIList;

  293. #define GUI_SIF_TYPE tGUI_SIF_APIList
  294. #define GUI_SIF_TYPE_PROP &GUI_SIF_APIList_Prop

  295. extern const tGUI_SIF_APIList GUI_SIF_APIList_Prop;

  296. /*
  297.       *********************************
  298.       * *
  299.       * Typedefs *
  300.       * *
  301.       *********************************
  302. */

  303. #ifndef GUI_HMEM
  304.   #define GUI_HMEM I16P
  305. #endif
  306. #define GUI_HMEM_NULL (0)
  307. typedef GUI_HMEM GUI_HWIN;
  308. #endif /* GUITYPE_H_INCLUDED */

  309. /*************************** End of file ****************************/



点击(此处)折叠或打开

  1. //GUI.h文件
  2. #ifndef __GUI_H__
  3. #define __GUI_H__

  4. #include "stm32f10x.h"
  5. /**************************************************************
  6. *
  7. * Defines for constants
  8. *
  9. ***************************************************************
  10. */
  11.  
  12. #define USE_HORIZONTAL 1

  13.     
  14. #define MAX_CHAR_POSX 240
  15. #define MAX_CHAR_POSY 400


  16. extern u16 POINT_COLOR,BACK_COLOR;

  17. #define GUI_FONTTYPE_PROP_SJIS 0
  18. //#pragma pack(1)
  19. typedef struct {
  20.   u8 XSize;
  21.   u8 XDist;
  22.   u8 BytesPerLine;
  23.   const u8 * pData;
  24. } GUI_CHARINFO;

  25. typedef struct GUI_FONT_PROP {
  26.   u16 First; /* first character */
  27.   u16 Last; /* last character */
  28.   const GUI_CHARINFO * paCharInfo; /* address of first character */
  29.   const struct GUI_FONT_PROP * pNext; /* pointer to next */
  30. } GUI_FONT_PROP;

  31. typedef struct GUI_FONT {
  32.   void * ShowFunction;
  33.   u8 YSize;
  34.   u8 YDist;
  35.   u8 XMag;
  36.   u8 YMag;
  37.   const GUI_FONT_PROP * pProp;
  38. }GUI_FONT;

  39. //#pragma pack()

  40. extern GUI_FONT GUI_FontHZ12x12;
  41. //extern GUI_FONT GUI_FontHZ24x24;
  42. //extern GUI_FONT GUI_FontHZ26x26;

  43. extern GUI_FONT * SystemFont;

  44. #define DrawPoint(x,y,color) ScreenDrawPoint(x,y,color)
  45. #define Clear(Color) LCD_Clear(Color)

  46. extern void LCD_Clear(u16 Color);
  47. const GUI_CHARINFO * GetBitMapStruct(GUI_FONT *Font,u16 ch);
  48. void ShowChar(u16 x,u16 y,const GUI_CHARINFO * BitMapStruct,u16 FontColor,u16 BkColor);
  49. void ShowStrings(u16 x,u16 y, GUI_FONT *Font,const u8*pStrings,u16 FontColor,u16 BkColor);
  50. void DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2);

  51. /*****************************************************************************************************/


  52. #define ________ 0x0
  53. #define _______X 0x1
  54. #define ______X_ 0x2
  55. #define ______XX 0x3
  56. #define _____X__ 0x4
  57. #define _____X_X 0x5
  58. #define _____XX_ 0x6
  59. #define _____XXX 0x7
  60. #define ____X___ 0x8
  61. #define ____X__X 0x9
  62. #define ____X_X_ 0xa
  63. #define ____X_XX 0xb
  64. #define ____XX__ 0xc
  65. #define ____XX_X 0xd
  66. #define ____XXX_ 0xe
  67. #define ____XXXX 0xf
  68. #define ___X____ 0x10
  69. #define ___X___X 0x11
  70. #define ___X__X_ 0x12
  71. #define ___X__XX 0x13
  72. #define ___X_X__ 0x14
  73. #define ___X_X_X 0x15
  74. #define ___X_XX_ 0x16
  75. #define ___X_XXX 0x17
  76. #define ___XX___ 0x18
  77. #define ___XX__X 0x19
  78. #define ___XX_X_ 0x1a
  79. #define ___XX_XX 0x1b
  80. #define ___XXX__ 0x1c
  81. #define ___XXX_X 0x1d
  82. #define ___XXXX_ 0x1e
  83. #define ___XXXXX 0x1f
  84. #define __X_____ 0x20
  85. #define __X____X 0x21
  86. #define __X___X_ 0x22
  87. #define __X___XX 0x23
  88. #define __X__X__ 0x24
  89. #define __X__X_X 0x25
  90. #define __X__XX_ 0x26
  91. #define __X__XXX 0x27
  92. #define __X_X___ 0x28
  93. #define __X_X__X 0x29
  94. #define __X_X_X_ 0x2a
  95. #define __X_X_XX 0x2b
  96. #define __X_XX__ 0x2c
  97. #define __X_XX_X 0x2d
  98. #define __X_XXX_ 0x2e
  99. #define __X_XXXX 0x2f
  100. #define __XX____ 0x30
  101. #define __XX___X 0x31
  102. #define __XX__X_ 0x32
  103. #define __XX__XX 0x33
  104. #define __XX_X__ 0x34
  105. #define __XX_X_X 0x35
  106. #define __XX_XX_ 0x36
  107. #define __XX_XXX 0x37
  108. #define __XXX___ 0x38
  109. #define __XXX__X 0x39
  110. #define __XXX_X_ 0x3a
  111. #define __XXX_XX 0x3b
  112. #define __XXXX__ 0x3c
  113. #define __XXXX_X 0x3d
  114. #define __XXXXX_ 0x3e
  115. #define __XXXXXX 0x3f
  116. #define _X______ 0x40
  117. #define _X_____X 0x41
  118. #define _X____X_ 0x42
  119. #define _X____XX 0x43
  120. #define _X___X__ 0x44
  121. #define _X___X_X 0x45
  122. #define _X___XX_ 0x46
  123. #define _X___XXX 0x47
  124. #define _X__X___ 0x48
  125. #define _X__X__X 0x49
  126. #define _X__X_X_ 0x4a
  127. #define _X__X_XX 0x4b
  128. #define _X__XX__ 0x4c
  129. #define _X__XX_X 0x4d
  130. #define _X__XXX_ 0x4e
  131. #define _X__XXXX 0x4f
  132. #define _X_X____ 0x50
  133. #define _X_X___X 0x51
  134. #define _X_X__X_ 0x52
  135. #define _X_X__XX 0x53
  136. #define _X_X_X__ 0x54
  137. #define _X_X_X_X 0x55
  138. #define _X_X_XX_ 0x56
  139. #define _X_X_XXX 0x57
  140. #define _X_XX___ 0x58
  141. #define _X_XX__X 0x59
  142. #define _X_XX_X_ 0x5a
  143. #define _X_XX_XX 0x5b
  144. #define _X_XXX__ 0x5c
  145. #define _X_XXX_X 0x5d
  146. #define _X_XXXX_ 0x5e
  147. #define _X_XXXXX 0x5f
  148. #define _XX_____ 0x60
  149. #define _XX____X 0x61
  150. #define _XX___X_ 0x62
  151. #define _XX___XX 0x63
  152. #define _XX__X__ 0x64
  153. #define _XX__X_X 0x65
  154. #define _XX__XX_ 0x66
  155. #define _XX__XXX 0x67
  156. #define _XX_X___ 0x68
  157. #define _XX_X__X 0x69
  158. #define _XX_X_X_ 0x6a
  159. #define _XX_X_XX 0x6b
  160. #define _XX_XX__ 0x6c
  161. #define _XX_XX_X 0x6d
  162. #define _XX_XXX_ 0x6e
  163. #define _XX_XXXX 0x6f
  164. #define _XXX____ 0x70
  165. #define _XXX___X 0x71
  166. #define _XXX__X_ 0x72
  167. #define _XXX__XX 0x73
  168. #define _XXX_X__ 0x74
  169. #define _XXX_X_X 0x75
  170. #define _XXX_XX_ 0x76
  171. #define _XXX_XXX 0x77
  172. #define _XXXX___ 0x78
  173. #define _XXXX__X 0x79
  174. #define _XXXX_X_ 0x7a
  175. #define _XXXX_XX 0x7b
  176. #define _XXXXX__ 0x7c
  177. #define _XXXXX_X 0x7d
  178. #define _XXXXXX_ 0x7e
  179. #define _XXXXXXX 0x7f
  180. #define X_______ 0x80
  181. #define X______X 0x81
  182. #define X_____X_ 0x82
  183. #define X_____XX 0x83
  184. #define X____X__ 0x84
  185. #define X____X_X 0x85
  186. #define X____XX_ 0x86
  187. #define X____XXX 0x87
  188. #define X___X___ 0x88
  189. #define X___X__X 0x89
  190. #define X___X_X_ 0x8a
  191. #define X___X_XX 0x8b
  192. #define X___XX__ 0x8c
  193. #define X___XX_X 0x8d
  194. #define X___XXX_ 0x8e
  195. #define X___XXXX 0x8f
  196. #define X__X____ 0x90
  197. #define X__X___X 0x91
  198. #define X__X__X_ 0x92
  199. #define X__X__XX 0x93
  200. #define X__X_X__ 0x94
  201. #define X__X_X_X 0x95
  202. #define X__X_XX_ 0x96
  203. #define X__X_XXX 0x97
  204. #define X__XX___ 0x98
  205. #define X__XX__X 0x99
  206. #define X__XX_X_ 0x9a
  207. #define X__XX_XX 0x9b
  208. #define X__XXX__ 0x9c
  209. #define X__XXX_X 0x9d
  210. #define X__XXXX_ 0x9e
  211. #define X__XXXXX 0x9f
  212. #define X_X_____ 0xa0
  213. #define X_X____X 0xa1
  214. #define X_X___X_ 0xa2
  215. #define X_X___XX 0xa3
  216. #define X_X__X__ 0xa4
  217. #define X_X__X_X 0xa5
  218. #define X_X__XX_ 0xa6
  219. #define X_X__XXX 0xa7
  220. #define X_X_X___ 0xa8
  221. #define X_X_X__X 0xa9
  222. #define X_X_X_X_ 0xaa
  223. #define X_X_X_XX 0xab
  224. #define X_X_XX__ 0xac
  225. #define X_X_XX_X 0xad
  226. #define X_X_XXX_ 0xae
  227. #define X_X_XXXX 0xaf
  228. #define X_XX____ 0xb0
  229. #define X_XX___X 0xb1
  230. #define X_XX__X_ 0xb2
  231. #define X_XX__XX 0xb3
  232. #define X_XX_X__ 0xb4
  233. #define X_XX_X_X 0xb5
  234. #define X_XX_XX_ 0xb6
  235. #define X_XX_XXX 0xb7
  236. #define X_XXX___ 0xb8
  237. #define X_XXX__X 0xb9
  238. #define X_XXX_X_ 0xba
  239. #define X_XXX_XX 0xbb
  240. #define X_XXXX__ 0xbc
  241. #define X_XXXX_X 0xbd
  242. #define X_XXXXX_ 0xbe
  243. #define X_XXXXXX 0xbf
  244. #define XX______ 0xc0
  245. #define XX_____X 0xc1
  246. #define XX____X_ 0xc2
  247. #define XX____XX 0xc3
  248. #define XX___X__ 0xc4
  249. #define XX___X_X 0xc5
  250. #define XX___XX_ 0xc6
  251. #define XX___XXX 0xc7
  252. #define XX__X___ 0xc8
  253. #define XX__X__X 0xc9
  254. #define XX__X_X_ 0xca
  255. #define XX__X_XX 0xcb
  256. #define XX__XX__ 0xcc
  257. #define XX__XX_X 0xcd
  258. #define XX__XXX_ 0xce
  259. #define XX__XXXX 0xcf
  260. #define XX_X____ 0xd0
  261. #define XX_X___X 0xd1
  262. #define XX_X__X_ 0xd2
  263. #define XX_X__XX 0xd3
  264. #define XX_X_X__ 0xd4
  265. #define XX_X_X_X 0xd5
  266. #define XX_X_XX_ 0xd6
  267. #define XX_X_XXX 0xd7
  268. #define XX_XX___ 0xd8
  269. #define XX_XX__X 0xd9
  270. #define XX_XX_X_ 0xda
  271. #define XX_XX_XX 0xdb
  272. #define XX_XXX__ 0xdc
  273. #define XX_XXX_X 0xdd
  274. #define XX_XXXX_ 0xde
  275. #define XX_XXXXX 0xdf
  276. #define XXX_____ 0xe0
  277. #define XXX____X 0xe1
  278. #define XXX___X_ 0xe2
  279. #define XXX___XX 0xe3
  280. #define XXX__X__ 0xe4
  281. #define XXX__X_X 0xe5
  282. #define XXX__XX_ 0xe6
  283. #define XXX__XXX 0xe7
  284. #define XXX_X___ 0xe8
  285. #define XXX_X__X 0xe9
  286. #define XXX_X_X_ 0xea
  287. #define XXX_X_XX 0xeb
  288. #define XXX_XX__ 0xec
  289. #define XXX_XX_X 0xed
  290. #define XXX_XXX_ 0xee
  291. #define XXX_XXXX 0xef
  292. #define XXXX____ 0xf0
  293. #define XXXX___X 0xf1
  294. #define XXXX__X_ 0xf2
  295. #define XXXX__XX 0xf3
  296. #define XXXX_X__ 0xf4
  297. #define XXXX_X_X 0xf5
  298. #define XXXX_XX_ 0xf6
  299. #define XXXX_XXX 0xf7
  300. #define XXXXX___ 0xf8
  301. #define XXXXX__X 0xf9
  302. #define XXXXX_X_ 0xfa
  303. #define XXXXX_XX 0xfb
  304. #define XXXXXX__ 0xfc
  305. #define XXXXXX_X 0xfd
  306. #define XXXXXXX_ 0xfe
  307. #define XXXXXXXX 0xff


  308. #endif /* ifdef GUI_H */





阅读(2021) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~