一 开源库简介与移植
最近一个项目需要用12864屏幕呈现一组较为复杂的菜单界面,本着不重复造轮子的原则找到了SimpleGUI开源库。
开源地址:SimpleGUI: 一个面向单色显示屏的开源GUI接口库。
SimpleGUI是一款针对单色显示屏设计的接口库。相比于传统的GUI框架,SimpleGUI的出发点,是在一个单色显示器上,以尽可能少的消耗、尽可能多且直观的表达需要的内容,为此,SimpleGUI抛弃了诸如图层、遮罩、阴影、非等宽字体等高级的、复杂的操作,力求以简单快捷、易于操作的方式,使开发者尽快实现自己需要的功能需求。 同时在满足基本绘图需求的前提下,SimpleGUI还提供了一套被称为HMI的交互引擎,用于统合用户交互、数据处理和屏幕内容绘制与更新,提供了一种简明、易组织、易拓展、低消耗的交互系统。
开源库的模拟器部署以及嵌入式移植参考前文:
【嵌入式】STM32&12864点阵屏使用SimpleGUI单色屏接口库——(1)移植-CSDN博客
二 精简字库的制作
如果片上资源足够,可以使用全中文字库。以SimpleGUI默认的12像素字体为例,每个半角字符需要消耗6*2字节,全角字符需要消耗12*2字节,那么整个GB2312字库对Flash的消耗为:
(6*2)*96+(12*2)*3755+(12*2)*3008 = 1152 + 90120 + 72192 = 163464 Bytes
约164KB的Flash消耗对于单片机来说还是非常可观的,如果还需要其他不同大小的字体,空间资源需求还要成倍增加,所以这种时候,通常就要使用外部字库了。
但事实上,很多时候,界面上的文字都是既定好的,不需要动态的变化,这也就决定了整个系统中可能仅仅就需要使用少数的几个字符。这时候如果还要去设计外部字库显然对软硬件成本都是一种浪费,精简字库消耗才是正途。 通过前文的说明,字符和字符串的编码,说到底不过就是从字符编码到字库索引上的一种算法表达,精简字库,说到底也是从这一方面着手,删除掉字库中用不到的文字和符号,重新定义编码和索引,字库的精简就完成了。
基于以上思想,精简字库首先要列出整个目标系统中所有可能用到的文字,然后进行去重,提炼出目标系统中用到的所有汉字。然后给这些汉字进行重新编码,简而言之就是进行简单排序,然后重新编号,这个编号就是新规定的字符编码。最后,用这个新的编码重新去对字符串进行编码,这样就完成了字库的精简了。
举个例子,我想在12864屏幕上显示一首词《虞美人·春花秋月何时了》:
春花秋月何时了?往事知多少。
小楼昨夜又东风,故国不堪回首月明中。
雕栏玉砌应犹在,只是朱颜改。
问君能有几多愁?恰似一江春水向东流。
【1】开源库的作者提供了一个小工具(MinimumFontLib: 一个用于精简单色点阵字库数据的工具),用来文字的提取和重编码,省去了大量的人工工作,非常方便。将所用到的文字粘进去,点击提取和重编码,得到重新排序后的文字和重编码之后的代码:
【2】将重编码后的代码(上图中的Record Text)替换到 GUI\src\SGUI_FontResource.c 文件中默认 SGUI_DEFAULT_FONT_16 字库的汉字编码数组 s_arrUnicodeTable 中:
static const SGUI_UINT32 s_arrUnicodeTable[] = {0x4E00, // U+4E00 一
0x4E0D, // U+4E0D 不
0x4E1C, // U+4E1C 东
0x4E2D, // U+4E2D 中
0x4E86, // U+4E86 了
0x4E8B, // U+4E8B 事
0x4F3C, // U+4F3C 似
0x4F55, // U+4F55 何
0x51E0, // U+51E0 几
0x53C8, // U+53C8 又
0x53EA, // U+53EA 只
0x5411, // U+5411 向
0x541B, // U+541B 君
0x56DE, // U+56DE 回
0x56FD, // U+56FD 国
0x5728, // U+5728 在
0x582A, // U+582A 堪
0x591A, // U+591A 多
0x591C, // U+591C 夜
0x5C0F, // U+5C0F 小
0x5C11, // U+5C11 少
0x5E94, // U+5E94 应
0x5F80, // U+5F80 往
0x6070, // U+6070 恰
0x6101, // U+6101 愁
0x6539, // U+6539 改
0x6545, // U+6545 故
0x65F6, // U+65F6 时
0x660E, // U+660E 明
0x6625, // U+6625 春
0x6628, // U+6628 昨
0x662F, // U+662F 是
0x6708, // U+6708 月
0x6709, // U+6709 有
0x6731, // U+6731 朱
0x680F, // U+680F 栏
0x697C, // U+697C 楼
0x6C34, // U+6C34 水
0x6C5F, // U+6C5F 江
0x6D41, // U+6D41 流
0x72B9, // U+72B9 犹
0x7389, // U+7389 玉
0x77E5, // U+77E5 知
0x780C, // U+780C 砌
0x79CB, // U+79CB 秋
0x80FD, // U+80FD 能
0x82B1, // U+82B1 花
0x95EE, // U+95EE 问
0x96D5, // U+96D5 雕
0x989C, // U+989C 颜
0x98CE, // U+98CE 风
0x9996, // U+9996 首
};
【3】将重新排序后的文字(上图中的Extracted Text)用字库处理软件(推荐: PCtoLCD2002完美版 )处理成C51形式:
【4】将上一步生成的内容直接复制替换到 GUI\src\SGUI_FontResource.c 文件中默认 SGUI_DEFAULT_FONT_16 字库的字符库数组 SGUI_FONT_H16 中(注意:中文是从第95下标往后添加):
//======================================================================//
//= 16 Pix font library.宋体16 //
//======================================================================//
const SGUI_BYTE SGUI_FONT_H16[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space Index 0
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,/*"!",0*/
0x00,0x10,0x0C,0x02,0x10,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*""",1*/
0x00,0x40,0xC0,0x78,0x40,0xC0,0x78,0x00,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x00,/*"#",2*/
0x00,0x70,0x88,0x88,0xFC,0x08,0x30,0x00,0x00,0x18,0x20,0x20,0xFF,0x21,0x1E,0x00,/*"$",3*/
0xF0,0x08,0xF0,0x80,0x60,0x18,0x00,0x00,0x00,0x31,0x0C,0x03,0x1E,0x21,0x1E,0x00,/*"%",4*/
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x2C,0x19,0x27,0x21,0x10,/*"&",5*/
0x00,0x12,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"'",6*/
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,/*"(",7*/
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,/*")",8*/
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,/*"*",9*/
0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x0F,0x01,0x01,0x01,/*"+",10*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x70,0x00,0x00,0x00,0x00,0x00,/*",",11*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,/*"-",12*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,/*".",13*/
0x00,0x00,0x00,0x00,0xC0,0x38,0x04,0x00,0x00,0x60,0x18,0x07,0x00,0x00,0x00,0x00,/*"/",14*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*"0",15*/
0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,/*"1",16*/
0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",17*/
0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00,/*"3",18*/
0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24,/*"4",19*/
0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00,/*"5",20*/
0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00,/*"6",21*/
0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00,/*"7",22*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*"8",23*/
0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00,/*"9",24*/
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,/*":",25*/
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,/*";",26*/
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,/*"<",27*/
0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x00,/*"=",28*/
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,/*">",29*/
0x00,0x70,0x48,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x30,0x37,0x00,0x00,0x00,/*"?",30*/
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x28,0x2F,0x28,0x17,0x00,/*"@",31*/
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,/*"A",32*/
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,/*"B",33*/
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,/*"C",34*/
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,/*"D",35*/
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,/*"E",36*/
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,/*"F",37*/
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,/*"G",38*/
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,/*"H",39*/
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"I",40*/
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,/*"J",41*/
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,/*"K",42*/
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,/*"L",43*/
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x01,0x3E,0x01,0x3F,0x20,0x00,/*"M",44*/
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,/*"N",45*/
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,/*"O",46*/
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,/*"P",47*/
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x28,0x28,0x30,0x50,0x4F,0x00,/*"Q",48*/
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,/*"R",49*/
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,/*"S",50*/
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,/*"T",51*/
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,/*"U",52*/
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,/*"V",53*/
0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00,/*"W",54*/
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,/*"X",55*/
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,/*"Y",56*/
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,/*"Z",57*/
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,/*"[",58*/
0x00,0x04,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,/*"\",59*/
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,/*"]",60*/
0x00,0x00,0x04,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"^",61*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,/*"_",62*/
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"`",63*/
0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00,/*"a",64*/
0x10,0xF0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,/*"b",65*/
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,/*"c",66*/
0x00,0x00,0x80,0x80,0x80,0x90,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,/*"d",67*/
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x24,0x24,0x24,0x24,0x17,0x00,/*"e",68*/
0x00,0x80,0x80,0xE0,0x90,0x90,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"f",69*/
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,/*"g",70*/
0x10,0xF0,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,/*"h",71*/
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"i",72*/
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,/*"j",73*/
0x10,0xF0,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x06,0x29,0x30,0x20,0x00,/*"k",74*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"l",75*/
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,/*"m",76*/
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,/*"n",77*/
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,/*"o",78*/
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0x91,0x20,0x20,0x11,0x0E,0x00,/*"p",79*/
0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0x91,0xFF,0x80,/*"q",80*/
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,/*"r",81*/
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,/*"s",82*/
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x10,0x00,/*"t",83*/
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,/*"u",84*/
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,/*"v",85*/
0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x01,0x0E,0x30,0x0C,0x07,0x38,0x06,0x01,/*"w",86*/
0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x20,0x31,0x0E,0x2E,0x31,0x20,0x00,/*"x",87*/
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00,/*"y",88*/
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,/*"z",89*/
0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x02,0x00,0x00,0x00,0x00,0x01,0x3E,0x40,0x40,/*"{",90*/
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,/*"|",91*/
0x02,0x02,0xFC,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x3E,0x01,0x00,0x00,0x00,0x00,/*"}",92*/
0x00,0x02,0x01,0x02,0x02,0x04,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"~",93*/
0x00,0xFE,0x02,0x02,0x72,0x7A,0x1A,0x1A,0x1A,0x9A,0xFA,0xF2,0x02,0x02,0xFE,0x00,0x00,0x7F,0x40,0x40,0x40,0x40,0x40,0x5A,0x5B,0x43,0x41,0x40,0x40,0x40,0x7F,0x00,/* [0 ] ['?' for undefined character. ] */
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"一",0*/
0x00,0x02,0x02,0x02,0x02,0x82,0x42,0xF2,0x0E,0x42,0x82,0x02,0x02,0x02,0x00,0x00,
0x10,0x08,0x04,0x02,0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x01,0x02,0x0C,0x00,0x00,/*"不",1*/
0x00,0x08,0x88,0x48,0x28,0x18,0x0F,0xE8,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
0x00,0x20,0x11,0x09,0x05,0x41,0x81,0x7F,0x01,0x01,0x05,0x09,0x11,0x20,0x00,0x00,/*"东",2*/
0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,
0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00,/*"中",3*/
0x00,0x02,0x02,0x02,0x02,0x02,0x02,0xE2,0x22,0x12,0x0A,0x06,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"了",4*/
0x04,0x04,0x74,0x54,0x54,0x54,0x54,0xFF,0x54,0x54,0x54,0x54,0x74,0x04,0x04,0x00,
0x04,0x04,0x15,0x15,0x15,0x55,0x95,0x7F,0x15,0x15,0x15,0x15,0x1F,0x04,0x04,0x00,/*"事",5*/
0x80,0x60,0xF8,0x07,0x00,0xF8,0x00,0x02,0x04,0x18,0x00,0x00,0xFF,0x00,0x00,0x00,
0x00,0x00,0xFF,0x00,0x00,0x3F,0x10,0x88,0x40,0x20,0x18,0x07,0x08,0x30,0xC0,0x00,/*"似",6*/
0x00,0x80,0x60,0xF8,0x07,0x04,0xE4,0x24,0x24,0xE4,0x04,0x04,0xFC,0x04,0x04,0x00,
0x01,0x00,0x00,0xFF,0x00,0x00,0x0F,0x04,0x04,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00,/*"何",7*/
0x00,0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x00,
0x80,0x40,0x30,0x0C,0x03,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x78,0x00,/*"几",8*/
0x00,0x00,0x02,0x1E,0x62,0x82,0x02,0x02,0x02,0x82,0x72,0x0E,0x00,0x00,0x00,0x00,
0x80,0x80,0x40,0x40,0x20,0x11,0x0A,0x04,0x0A,0x11,0x20,0x40,0x40,0x80,0x80,0x00,/*"又",9*/
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,
0x00,0x80,0x40,0x23,0x19,0x01,0x01,0x01,0x01,0x01,0x09,0x13,0x20,0xC0,0x00,0x00,/*"只",10*/
0x00,0xF8,0x08,0x08,0x0C,0xCA,0x49,0x48,0x48,0xC8,0x08,0x08,0x08,0xF8,0x00,0x00,
0x00,0xFF,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00,/*"向",11*/
0x10,0x10,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x10,0x10,0x00,
0x40,0x20,0x10,0x0C,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFC,0x00,0x00,0x00,/*"君",12*/
0x00,0x00,0xFE,0x02,0x02,0xF2,0x12,0x12,0x12,0xF2,0x02,0x02,0xFE,0x00,0x00,0x00,
0x00,0x00,0x7F,0x20,0x20,0x27,0x24,0x24,0x24,0x27,0x20,0x20,0x7F,0x00,0x00,0x00,/*"回",13*/
0x00,0xFE,0x02,0x12,0x92,0x92,0x92,0xF2,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00,
0x00,0xFF,0x40,0x48,0x48,0x48,0x48,0x4F,0x48,0x4A,0x4C,0x48,0x40,0xFF,0x00,0x00,/*"国",14*/
0x08,0x08,0x88,0xC8,0x38,0x0C,0x0B,0x08,0x08,0xE8,0x08,0x08,0x08,0x08,0x08,0x00,
0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,/*"在",15*/
0x20,0x20,0x20,0xFF,0x20,0x20,0x04,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x04,0x00,
0x10,0x30,0x10,0x0F,0x08,0x08,0x02,0x7E,0x53,0x4A,0x42,0x42,0x4B,0x52,0x42,0x00,/*"堪",16*/
0x00,0x00,0x10,0x10,0x98,0xA4,0x47,0x44,0xA4,0x54,0x0C,0x04,0x00,0x00,0x00,0x00,
0x00,0x81,0x89,0x89,0x44,0x44,0x4A,0x31,0x21,0x11,0x09,0x05,0x03,0x00,0x00,0x00,/*"多",17*/
0x04,0x04,0x84,0xE4,0x1C,0x04,0x05,0xC6,0x3C,0xA4,0x24,0x24,0xE4,0x04,0x04,0x00,
0x02,0x01,0x00,0xFF,0x00,0x82,0x81,0x46,0x28,0x10,0x29,0x46,0x41,0x80,0x80,0x00,/*"夜",18*/
0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x20,0x40,0x80,0x00,0x00,
0x08,0x04,0x03,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x01,0x0E,0x00,/*"小",19*/
0x00,0x00,0x80,0x60,0x18,0x00,0x00,0xFF,0x00,0x00,0x08,0x90,0x20,0xC0,0x00,0x00,
0x00,0x81,0x80,0x80,0x40,0x40,0x20,0x13,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,/*"少",20*/
0x00,0x00,0xFC,0x04,0x44,0x84,0x04,0x25,0xC6,0x04,0x04,0x04,0x04,0xE4,0x04,0x00,
0x40,0x30,0x0F,0x40,0x40,0x41,0x4E,0x40,0x40,0x63,0x50,0x4C,0x43,0x40,0x40,0x00,/*"应",21*/
0x00,0x10,0x88,0xC4,0x33,0x08,0x08,0x08,0x09,0xFA,0x08,0x08,0x08,0x08,0x00,0x00,
0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,/*"往",22*/
0x00,0xE0,0x00,0xFF,0x10,0x20,0x50,0x48,0x44,0x43,0x44,0x48,0x50,0x20,0x20,0x00,
0x01,0x00,0x00,0xFF,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,/*"恰",23*/
0x10,0x92,0x52,0x32,0xFF,0x51,0x91,0x20,0x18,0xC0,0x3F,0xC0,0x10,0x0C,0x00,0x00,
0x01,0x40,0x30,0x00,0x77,0x80,0x84,0x8A,0xB1,0x80,0xE0,0x00,0x11,0x62,0x04,0x00,/*"愁",24*/
0x04,0x84,0x84,0x84,0x84,0xFC,0x40,0x30,0xCC,0x0B,0x08,0x08,0xF8,0x08,0x08,0x00,
0x00,0x7F,0x20,0x10,0x10,0x08,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,/*"改",25*/
0x10,0x10,0x10,0xFF,0x10,0x10,0x50,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,
0x00,0x7F,0x21,0x21,0x21,0x7F,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,/*"故",26*/
0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00,/*"时",27*/
0x00,0xFC,0x44,0x44,0x44,0xFC,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,
0x00,0x0F,0x04,0x04,0x04,0x8F,0x40,0x30,0x0F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,/*"明",28*/
0x40,0x44,0x54,0x54,0xD4,0x54,0x74,0x5F,0x54,0x54,0xD4,0x54,0x54,0x44,0x40,0x00,
0x04,0x04,0x02,0x01,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x01,0x02,0x04,0x04,0x00,/*"春",29*/
0x00,0xFC,0x84,0x84,0xFC,0x40,0x30,0x0F,0xF8,0x88,0x88,0x88,0x88,0x08,0x08,0x00,
0x00,0x3F,0x10,0x10,0x3F,0x00,0x00,0x00,0xFF,0x08,0x08,0x08,0x08,0x08,0x00,0x00,/*"昨",30*/
0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x7F,0x00,0x00,0x00,0x00,
0x81,0x41,0x21,0x1D,0x21,0x41,0x81,0xFF,0x89,0x89,0x89,0x89,0x89,0x81,0x81,0x00,/*"是",31*/
0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,
0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,/*"月",32*/
0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00,
0x04,0x02,0x01,0x00,0xFF,0x09,0x09,0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,0x00,/*"有",33*/
0x80,0xA0,0x90,0x8E,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0x88,0x80,0x80,0x00,
0x20,0x20,0x10,0x08,0x04,0x02,0x01,0xFF,0x01,0x02,0x04,0x08,0x10,0x20,0x20,0x00,/*"朱",34*/
0x10,0x10,0xD0,0xFF,0x90,0x10,0x20,0x22,0x2C,0x20,0x20,0x28,0x26,0x20,0x20,0x00,
0x04,0x03,0x00,0xFF,0x00,0x03,0x40,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x00,/*"栏",35*/
0x10,0x90,0xFF,0x90,0x10,0x00,0x90,0x52,0x34,0x10,0x7F,0x10,0x34,0x52,0x90,0x00,
0x06,0x01,0xFF,0x00,0x01,0x82,0x82,0x5A,0x56,0x23,0x22,0x52,0x4E,0x82,0x02,0x00,/*"楼",36*/
0x00,0x20,0x20,0x20,0xA0,0x60,0x00,0xFF,0x60,0x80,0x40,0x20,0x18,0x00,0x00,0x00,
0x20,0x10,0x08,0x06,0x01,0x40,0x80,0x7F,0x00,0x01,0x02,0x04,0x08,0x10,0x10,0x00,/*"水",37*/
0x10,0x60,0x02,0x0C,0xC0,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,0x00,
0x04,0x04,0x7C,0x03,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x00,/*"江",38*/
0x10,0x60,0x02,0x8C,0x00,0x44,0x64,0x54,0x4D,0x46,0x44,0x54,0x64,0xC4,0x04,0x00,
0x04,0x04,0x7E,0x01,0x80,0x40,0x3E,0x00,0x00,0xFE,0x00,0x00,0x7E,0x80,0xE0,0x00,/*"流",39*/
0x40,0x22,0x14,0x08,0xF4,0x02,0x10,0x10,0xFF,0x10,0xF0,0x11,0x16,0x10,0x10,0x00,
0x08,0x44,0x82,0x41,0x3F,0x80,0x60,0x1C,0x03,0x00,0x3F,0x40,0x40,0x40,0x78,0x00,/*"犹",40*/
0x00,0x02,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x00,
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x44,0x58,0x40,0x40,0x40,0x00,/*"玉",41*/
0x20,0x18,0x0F,0x08,0xF8,0x08,0x08,0x00,0x00,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,
0x81,0x41,0x31,0x0D,0x03,0x0D,0x71,0x01,0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,/*"知",42*/
0x04,0xE4,0x5C,0x44,0xC4,0x80,0x80,0xFE,0x40,0x44,0x04,0xFC,0x04,0x04,0xFC,0x00,
0x01,0x3F,0x10,0x10,0x3F,0x00,0x00,0x1F,0x88,0x44,0x30,0x0F,0x40,0x80,0x7F,0x00,/*"砌",43*/
0x24,0x24,0xA4,0xFE,0x23,0x22,0x80,0x70,0x00,0xFF,0x00,0x80,0x40,0x30,0x00,0x00,
0x08,0x06,0x01,0xFF,0x01,0x86,0x40,0x30,0x0E,0x01,0x06,0x18,0x20,0x40,0x80,0x00,/*"秋",44*/
0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00,
0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00,/*"能",45*/
0x04,0x04,0x04,0x84,0x6F,0x04,0x04,0x04,0xE4,0x04,0x8F,0x44,0x24,0x04,0x04,0x00,
0x04,0x02,0x01,0xFF,0x00,0x10,0x08,0x04,0x3F,0x41,0x40,0x40,0x40,0x40,0x78,0x00,/*"花",46*/
0x00,0xF8,0x01,0x02,0x00,0xE2,0x22,0x22,0x22,0xE2,0x02,0x02,0x02,0xFE,0x00,0x00,
0x00,0xFF,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00,/*"问",47*/
0x00,0xFE,0x42,0x52,0x7E,0x52,0x42,0xFE,0x10,0xFC,0x4B,0x48,0xF9,0x4A,0x48,0x00,
0x80,0x7F,0x00,0x0F,0x09,0x4F,0x80,0x7F,0x00,0xFF,0x22,0x22,0x3F,0x22,0x22,0x00,/*"雕",48*/
0x00,0xE4,0x2C,0x35,0xA6,0x74,0x2C,0x24,0x02,0xF2,0x1A,0xD6,0x12,0xF2,0x02,0x00,
0x40,0x3F,0x80,0x89,0x44,0x22,0x11,0x08,0x80,0x4F,0x30,0x0F,0x10,0x2F,0xC0,0x00,/*"颜",49*/
0x00,0x00,0xFE,0x02,0x12,0x22,0xC2,0x02,0xC2,0x32,0x02,0xFE,0x00,0x00,0x00,0x00,
0x80,0x60,0x1F,0x00,0x20,0x10,0x0C,0x03,0x0C,0x30,0x00,0x0F,0x30,0x40,0xF8,0x00,/*"风",50*/
0x04,0x04,0xE4,0x25,0x26,0x34,0x2C,0x24,0x24,0x24,0x26,0x25,0xE4,0x04,0x04,0x00,
0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,/*"首",51*/
};
至此,精简字库准备完成,接下来是字库的使用。
三 精简字库的调用
【1】新建一个头文件并转化成 UTF-8 编码格式(我这边命名为 Gui_Text_UTF8.h ),里面通过宏定义,管理程序中用到的所有中文文本内容。好处是该头文件可以随时替换为其他的编码格式:
#ifndef __GUI_TEXT_UTF8_H_
#define __GUI_TEXT_UTF8_H_/* Screen 1: List Components. */
#define TEXT_TEST ("春花秋月何时了?往事知多少.小楼昨夜又东风,故国不堪回首月明中.雕栏玉砌应犹在,只是朱颜改.问君能有几多愁?恰似一江春水向东流.")/* Screen 2: Basic Paint*//* Screen 3: Text demo*//* Screen 4: Variable box. *//* Screen 5: Realtime graph. *//* Screen 6: Variable box. *//* Screen 7: Notice box. */#endif
【2】主函数中调用(例子中使用多行文本显示函数 SGUI_Text_DrawMultipleLinesText ,该函数中的内容遇到设定的空间边界自动换行):
/**************************************************************************
* 函数名称: Gui_Task
* 功能描述: 液晶显示子任务
**************************************************************************/
SGUI_SCR_DEV disp_dev; //中文屏设备源
#define BMP_DATA_BUFFER_SIZE (512)
SGUI_BYTE s_pBmpDataBuffer[BMP_DATA_BUFFER_SIZE];void Gui_Task(void)
{SGUI_RECT disp_area;SGUI_POINT disp_offs;//点阵屏初始化/配置命令/清屏LDZ_Init();LDZ_Cfg();LDZ_Clear();//设备内存地址初始化SGUI_SystemIF_MemorySet(&disp_dev, 0x00, sizeof(disp_dev));//一些相关初始化配置disp_area.iX = 0;disp_area.iY = 0;disp_area.iWidth = 128;disp_area.iHeight = 64;disp_offs.iX = 0;disp_offs.iY = 0;disp_dev.stSize.iWidth = 128;disp_dev.stSize.iHeight = 64;/* Initialize interface object. */disp_dev.fnSetPixel = LDZ_SetPixel;disp_dev.fnClear = LDZ_Clear;disp_dev.fnSyncBuffer = LDZ_Refresh;disp_dev.stBuffer.pBuffer = s_pBmpDataBuffer;disp_dev.stBuffer.sSize = BMP_DATA_BUFFER_SIZE;//...while(1){//显示多行文本disp_area.iX = 0;disp_area.iY = 0;disp_area.iWidth = 128;disp_area.iHeight = 64;SGUI_Text_DrawMultipleLinesText(&disp_dev, TEXT_TEST, &SGUI_DEFAULT_FONT_16, &disp_area, 0, SGUI_DRAW_NORMAL);LDZ_Refresh();os_dly_wait(50);}
}
【3】实际显示效果如下:
【注意】:有的时候keil工程中会因为UTF-8兼容问题报错“error: #8: missing closing quote”,解决办法如下(网上也有不少帖子记录这个问题):
方法一:在KEIL中魔术棒Options for Target ‘Flash’ -> C/C++ -> Misc Controls 中添加 --locale=english --no-multibyte-chars
方法二:将格式由UTF8替换为UTF8-BOM
四 参考资料
【1】【嵌入式】STM32&12864点阵屏使用SimpleGUI单色屏接口库——(1)移植-CSDN博客
【2】SimpleGUI: 一个面向单色显示屏的开源GUI接口库。
【3】MinimumFontLib: 一个用于精简单色点阵字库数据的工具
【4】关于Simple GUI精简字库的制作方法_simplegui-CSDN博客
【5】单色显示屏GUI库simpleGUI使用自定义中文字体资源_freesimplegui-CSDN博客
【6】simplegui自定义字库——UTF8版-CSDN博客
【7】有关SimpleGUI移植非等宽字符的介绍_simplegui 移植-CSDN博客