当前位置:   article > 正文

【嵌入式】STM32&12864点阵屏使用SimpleGUI单色屏接口库——(2)精简字库_stm32的gui关联字库

stm32的gui关联字库

一 开源库简介与移植

        最近一个项目需要用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 中:

  1. static const SGUI_UINT32 s_arrUnicodeTable[] = {
  2. 0x4E00, // U+4E00 一
  3. 0x4E0D, // U+4E0D 不
  4. 0x4E1C, // U+4E1C 东
  5. 0x4E2D, // U+4E2D 中
  6. 0x4E86, // U+4E86 了
  7. 0x4E8B, // U+4E8B 事
  8. 0x4F3C, // U+4F3C 似
  9. 0x4F55, // U+4F55 何
  10. 0x51E0, // U+51E0 几
  11. 0x53C8, // U+53C8 又
  12. 0x53EA, // U+53EA 只
  13. 0x5411, // U+5411 向
  14. 0x541B, // U+541B 君
  15. 0x56DE, // U+56DE 回
  16. 0x56FD, // U+56FD 国
  17. 0x5728, // U+5728 在
  18. 0x582A, // U+582A 堪
  19. 0x591A, // U+591A 多
  20. 0x591C, // U+591C 夜
  21. 0x5C0F, // U+5C0F 小
  22. 0x5C11, // U+5C11 少
  23. 0x5E94, // U+5E94 应
  24. 0x5F80, // U+5F80 往
  25. 0x6070, // U+6070 恰
  26. 0x6101, // U+6101 愁
  27. 0x6539, // U+6539 改
  28. 0x6545, // U+6545 故
  29. 0x65F6, // U+65F6 时
  30. 0x660E, // U+660E 明
  31. 0x6625, // U+6625 春
  32. 0x6628, // U+6628 昨
  33. 0x662F, // U+662F 是
  34. 0x6708, // U+6708 月
  35. 0x6709, // U+6709 有
  36. 0x6731, // U+6731 朱
  37. 0x680F, // U+680F 栏
  38. 0x697C, // U+697C 楼
  39. 0x6C34, // U+6C34 水
  40. 0x6C5F, // U+6C5F 江
  41. 0x6D41, // U+6D41 流
  42. 0x72B9, // U+72B9 犹
  43. 0x7389, // U+7389 玉
  44. 0x77E5, // U+77E5 知
  45. 0x780C, // U+780C 砌
  46. 0x79CB, // U+79CB 秋
  47. 0x80FD, // U+80FD 能
  48. 0x82B1, // U+82B1 花
  49. 0x95EE, // U+95EE 问
  50. 0x96D5, // U+96D5 雕
  51. 0x989C, // U+989C 颜
  52. 0x98CE, // U+98CE 风
  53. 0x9996, // U+9996 首
  54. };

【3】将重新排序后的文字(上图中的Extracted Text)用字库处理软件(推荐: PCtoLCD2002完美版 )处理成C51形式:

【4】将上一步生成的内容直接复制替换到 GUI\src\SGUI_FontResource.c 文件中默认 SGUI_DEFAULT_FONT_16 字库的字符库数组 SGUI_FONT_H16 中(注意:中文是从第95下标往后添加):

  1. //======================================================================//
  2. //= 16 Pix font library.宋体16 //
  3. //======================================================================//
  4. const SGUI_BYTE SGUI_FONT_H16[] = {
  5. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space Index 0
  6. 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,/*"!",0*/
  7. 0x00,0x10,0x0C,0x02,0x10,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*""",1*/
  8. 0x00,0x40,0xC0,0x78,0x40,0xC0,0x78,0x00,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x00,/*"#",2*/
  9. 0x00,0x70,0x88,0x88,0xFC,0x08,0x30,0x00,0x00,0x18,0x20,0x20,0xFF,0x21,0x1E,0x00,/*"$",3*/
  10. 0xF0,0x08,0xF0,0x80,0x60,0x18,0x00,0x00,0x00,0x31,0x0C,0x03,0x1E,0x21,0x1E,0x00,/*"%",4*/
  11. 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x2C,0x19,0x27,0x21,0x10,/*"&",5*/
  12. 0x00,0x12,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"'",6*/
  13. 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,/*"(",7*/
  14. 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,/*")",8*/
  15. 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,/*"*",9*/
  16. 0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x0F,0x01,0x01,0x01,/*"+",10*/
  17. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x70,0x00,0x00,0x00,0x00,0x00,/*",",11*/
  18. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,/*"-",12*/
  19. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,/*".",13*/
  20. 0x00,0x00,0x00,0x00,0xC0,0x38,0x04,0x00,0x00,0x60,0x18,0x07,0x00,0x00,0x00,0x00,/*"/",14*/
  21. 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*"0",15*/
  22. 0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,/*"1",16*/
  23. 0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",17*/
  24. 0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00,/*"3",18*/
  25. 0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24,/*"4",19*/
  26. 0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00,/*"5",20*/
  27. 0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00,/*"6",21*/
  28. 0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00,/*"7",22*/
  29. 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*"8",23*/
  30. 0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00,/*"9",24*/
  31. 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,/*":",25*/
  32. 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,/*";",26*/
  33. 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,/*"<",27*/
  34. 0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x00,/*"=",28*/
  35. 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,/*">",29*/
  36. 0x00,0x70,0x48,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x30,0x37,0x00,0x00,0x00,/*"?",30*/
  37. 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x28,0x2F,0x28,0x17,0x00,/*"@",31*/
  38. 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,/*"A",32*/
  39. 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,/*"B",33*/
  40. 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,/*"C",34*/
  41. 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,/*"D",35*/
  42. 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,/*"E",36*/
  43. 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,/*"F",37*/
  44. 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,/*"G",38*/
  45. 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,/*"H",39*/
  46. 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"I",40*/
  47. 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,/*"J",41*/
  48. 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,/*"K",42*/
  49. 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,/*"L",43*/
  50. 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x01,0x3E,0x01,0x3F,0x20,0x00,/*"M",44*/
  51. 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,/*"N",45*/
  52. 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,/*"O",46*/
  53. 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,/*"P",47*/
  54. 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x28,0x28,0x30,0x50,0x4F,0x00,/*"Q",48*/
  55. 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,/*"R",49*/
  56. 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,/*"S",50*/
  57. 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,/*"T",51*/
  58. 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,/*"U",52*/
  59. 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,/*"V",53*/
  60. 0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00,/*"W",54*/
  61. 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,/*"X",55*/
  62. 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,/*"Y",56*/
  63. 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,/*"Z",57*/
  64. 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,/*"[",58*/
  65. 0x00,0x04,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,/*"\",59*/
  66. 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,/*"]",60*/
  67. 0x00,0x00,0x04,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"^",61*/
  68. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,/*"_",62*/
  69. 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"`",63*/
  70. 0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00,/*"a",64*/
  71. 0x10,0xF0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,/*"b",65*/
  72. 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,/*"c",66*/
  73. 0x00,0x00,0x80,0x80,0x80,0x90,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,/*"d",67*/
  74. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x24,0x24,0x24,0x24,0x17,0x00,/*"e",68*/
  75. 0x00,0x80,0x80,0xE0,0x90,0x90,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"f",69*/
  76. 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,/*"g",70*/
  77. 0x10,0xF0,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,/*"h",71*/
  78. 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"i",72*/
  79. 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,/*"j",73*/
  80. 0x10,0xF0,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x06,0x29,0x30,0x20,0x00,/*"k",74*/
  81. 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"l",75*/
  82. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,/*"m",76*/
  83. 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,/*"n",77*/
  84. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,/*"o",78*/
  85. 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0x91,0x20,0x20,0x11,0x0E,0x00,/*"p",79*/
  86. 0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0x91,0xFF,0x80,/*"q",80*/
  87. 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,/*"r",81*/
  88. 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,/*"s",82*/
  89. 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x10,0x00,/*"t",83*/
  90. 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,/*"u",84*/
  91. 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,/*"v",85*/
  92. 0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x01,0x0E,0x30,0x0C,0x07,0x38,0x06,0x01,/*"w",86*/
  93. 0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x20,0x31,0x0E,0x2E,0x31,0x20,0x00,/*"x",87*/
  94. 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00,/*"y",88*/
  95. 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,/*"z",89*/
  96. 0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x02,0x00,0x00,0x00,0x00,0x01,0x3E,0x40,0x40,/*"{",90*/
  97. 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,/*"|",91*/
  98. 0x02,0x02,0xFC,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x3E,0x01,0x00,0x00,0x00,0x00,/*"}",92*/
  99. 0x00,0x02,0x01,0x02,0x02,0x04,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"~",93*/
  100. 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. ] */
  101. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
  102. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"一",0*/
  103. 0x00,0x02,0x02,0x02,0x02,0x82,0x42,0xF2,0x0E,0x42,0x82,0x02,0x02,0x02,0x00,0x00,
  104. 0x10,0x08,0x04,0x02,0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x01,0x02,0x0C,0x00,0x00,/*"不",1*/
  105. 0x00,0x08,0x88,0x48,0x28,0x18,0x0F,0xE8,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
  106. 0x00,0x20,0x11,0x09,0x05,0x41,0x81,0x7F,0x01,0x01,0x05,0x09,0x11,0x20,0x00,0x00,/*"东",2*/
  107. 0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,
  108. 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00,/*"中",3*/
  109. 0x00,0x02,0x02,0x02,0x02,0x02,0x02,0xE2,0x22,0x12,0x0A,0x06,0x02,0x00,0x00,0x00,
  110. 0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"了",4*/
  111. 0x04,0x04,0x74,0x54,0x54,0x54,0x54,0xFF,0x54,0x54,0x54,0x54,0x74,0x04,0x04,0x00,
  112. 0x04,0x04,0x15,0x15,0x15,0x55,0x95,0x7F,0x15,0x15,0x15,0x15,0x1F,0x04,0x04,0x00,/*"事",5*/
  113. 0x80,0x60,0xF8,0x07,0x00,0xF8,0x00,0x02,0x04,0x18,0x00,0x00,0xFF,0x00,0x00,0x00,
  114. 0x00,0x00,0xFF,0x00,0x00,0x3F,0x10,0x88,0x40,0x20,0x18,0x07,0x08,0x30,0xC0,0x00,/*"似",6*/
  115. 0x00,0x80,0x60,0xF8,0x07,0x04,0xE4,0x24,0x24,0xE4,0x04,0x04,0xFC,0x04,0x04,0x00,
  116. 0x01,0x00,0x00,0xFF,0x00,0x00,0x0F,0x04,0x04,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00,/*"何",7*/
  117. 0x00,0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x00,
  118. 0x80,0x40,0x30,0x0C,0x03,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x78,0x00,/*"几",8*/
  119. 0x00,0x00,0x02,0x1E,0x62,0x82,0x02,0x02,0x02,0x82,0x72,0x0E,0x00,0x00,0x00,0x00,
  120. 0x80,0x80,0x40,0x40,0x20,0x11,0x0A,0x04,0x0A,0x11,0x20,0x40,0x40,0x80,0x80,0x00,/*"又",9*/
  121. 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,
  122. 0x00,0x80,0x40,0x23,0x19,0x01,0x01,0x01,0x01,0x01,0x09,0x13,0x20,0xC0,0x00,0x00,/*"只",10*/
  123. 0x00,0xF8,0x08,0x08,0x0C,0xCA,0x49,0x48,0x48,0xC8,0x08,0x08,0x08,0xF8,0x00,0x00,
  124. 0x00,0xFF,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00,/*"向",11*/
  125. 0x10,0x10,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x10,0x10,0x00,
  126. 0x40,0x20,0x10,0x0C,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFC,0x00,0x00,0x00,/*"君",12*/
  127. 0x00,0x00,0xFE,0x02,0x02,0xF2,0x12,0x12,0x12,0xF2,0x02,0x02,0xFE,0x00,0x00,0x00,
  128. 0x00,0x00,0x7F,0x20,0x20,0x27,0x24,0x24,0x24,0x27,0x20,0x20,0x7F,0x00,0x00,0x00,/*"回",13*/
  129. 0x00,0xFE,0x02,0x12,0x92,0x92,0x92,0xF2,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00,
  130. 0x00,0xFF,0x40,0x48,0x48,0x48,0x48,0x4F,0x48,0x4A,0x4C,0x48,0x40,0xFF,0x00,0x00,/*"国",14*/
  131. 0x08,0x08,0x88,0xC8,0x38,0x0C,0x0B,0x08,0x08,0xE8,0x08,0x08,0x08,0x08,0x08,0x00,
  132. 0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,/*"在",15*/
  133. 0x20,0x20,0x20,0xFF,0x20,0x20,0x04,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x04,0x00,
  134. 0x10,0x30,0x10,0x0F,0x08,0x08,0x02,0x7E,0x53,0x4A,0x42,0x42,0x4B,0x52,0x42,0x00,/*"堪",16*/
  135. 0x00,0x00,0x10,0x10,0x98,0xA4,0x47,0x44,0xA4,0x54,0x0C,0x04,0x00,0x00,0x00,0x00,
  136. 0x00,0x81,0x89,0x89,0x44,0x44,0x4A,0x31,0x21,0x11,0x09,0x05,0x03,0x00,0x00,0x00,/*"多",17*/
  137. 0x04,0x04,0x84,0xE4,0x1C,0x04,0x05,0xC6,0x3C,0xA4,0x24,0x24,0xE4,0x04,0x04,0x00,
  138. 0x02,0x01,0x00,0xFF,0x00,0x82,0x81,0x46,0x28,0x10,0x29,0x46,0x41,0x80,0x80,0x00,/*"夜",18*/
  139. 0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x20,0x40,0x80,0x00,0x00,
  140. 0x08,0x04,0x03,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x01,0x0E,0x00,/*"小",19*/
  141. 0x00,0x00,0x80,0x60,0x18,0x00,0x00,0xFF,0x00,0x00,0x08,0x90,0x20,0xC0,0x00,0x00,
  142. 0x00,0x81,0x80,0x80,0x40,0x40,0x20,0x13,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,/*"少",20*/
  143. 0x00,0x00,0xFC,0x04,0x44,0x84,0x04,0x25,0xC6,0x04,0x04,0x04,0x04,0xE4,0x04,0x00,
  144. 0x40,0x30,0x0F,0x40,0x40,0x41,0x4E,0x40,0x40,0x63,0x50,0x4C,0x43,0x40,0x40,0x00,/*"应",21*/
  145. 0x00,0x10,0x88,0xC4,0x33,0x08,0x08,0x08,0x09,0xFA,0x08,0x08,0x08,0x08,0x00,0x00,
  146. 0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,/*"往",22*/
  147. 0x00,0xE0,0x00,0xFF,0x10,0x20,0x50,0x48,0x44,0x43,0x44,0x48,0x50,0x20,0x20,0x00,
  148. 0x01,0x00,0x00,0xFF,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,/*"恰",23*/
  149. 0x10,0x92,0x52,0x32,0xFF,0x51,0x91,0x20,0x18,0xC0,0x3F,0xC0,0x10,0x0C,0x00,0x00,
  150. 0x01,0x40,0x30,0x00,0x77,0x80,0x84,0x8A,0xB1,0x80,0xE0,0x00,0x11,0x62,0x04,0x00,/*"愁",24*/
  151. 0x04,0x84,0x84,0x84,0x84,0xFC,0x40,0x30,0xCC,0x0B,0x08,0x08,0xF8,0x08,0x08,0x00,
  152. 0x00,0x7F,0x20,0x10,0x10,0x08,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,/*"改",25*/
  153. 0x10,0x10,0x10,0xFF,0x10,0x10,0x50,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,
  154. 0x00,0x7F,0x21,0x21,0x21,0x7F,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,/*"故",26*/
  155. 0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
  156. 0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00,/*"时",27*/
  157. 0x00,0xFC,0x44,0x44,0x44,0xFC,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,
  158. 0x00,0x0F,0x04,0x04,0x04,0x8F,0x40,0x30,0x0F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,/*"明",28*/
  159. 0x40,0x44,0x54,0x54,0xD4,0x54,0x74,0x5F,0x54,0x54,0xD4,0x54,0x54,0x44,0x40,0x00,
  160. 0x04,0x04,0x02,0x01,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x01,0x02,0x04,0x04,0x00,/*"春",29*/
  161. 0x00,0xFC,0x84,0x84,0xFC,0x40,0x30,0x0F,0xF8,0x88,0x88,0x88,0x88,0x08,0x08,0x00,
  162. 0x00,0x3F,0x10,0x10,0x3F,0x00,0x00,0x00,0xFF,0x08,0x08,0x08,0x08,0x08,0x00,0x00,/*"昨",30*/
  163. 0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x7F,0x00,0x00,0x00,0x00,
  164. 0x81,0x41,0x21,0x1D,0x21,0x41,0x81,0xFF,0x89,0x89,0x89,0x89,0x89,0x81,0x81,0x00,/*"是",31*/
  165. 0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,
  166. 0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,/*"月",32*/
  167. 0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00,
  168. 0x04,0x02,0x01,0x00,0xFF,0x09,0x09,0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,0x00,/*"有",33*/
  169. 0x80,0xA0,0x90,0x8E,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0x88,0x80,0x80,0x00,
  170. 0x20,0x20,0x10,0x08,0x04,0x02,0x01,0xFF,0x01,0x02,0x04,0x08,0x10,0x20,0x20,0x00,/*"朱",34*/
  171. 0x10,0x10,0xD0,0xFF,0x90,0x10,0x20,0x22,0x2C,0x20,0x20,0x28,0x26,0x20,0x20,0x00,
  172. 0x04,0x03,0x00,0xFF,0x00,0x03,0x40,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x40,0x00,/*"栏",35*/
  173. 0x10,0x90,0xFF,0x90,0x10,0x00,0x90,0x52,0x34,0x10,0x7F,0x10,0x34,0x52,0x90,0x00,
  174. 0x06,0x01,0xFF,0x00,0x01,0x82,0x82,0x5A,0x56,0x23,0x22,0x52,0x4E,0x82,0x02,0x00,/*"楼",36*/
  175. 0x00,0x20,0x20,0x20,0xA0,0x60,0x00,0xFF,0x60,0x80,0x40,0x20,0x18,0x00,0x00,0x00,
  176. 0x20,0x10,0x08,0x06,0x01,0x40,0x80,0x7F,0x00,0x01,0x02,0x04,0x08,0x10,0x10,0x00,/*"水",37*/
  177. 0x10,0x60,0x02,0x0C,0xC0,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,0x00,
  178. 0x04,0x04,0x7C,0x03,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x00,/*"江",38*/
  179. 0x10,0x60,0x02,0x8C,0x00,0x44,0x64,0x54,0x4D,0x46,0x44,0x54,0x64,0xC4,0x04,0x00,
  180. 0x04,0x04,0x7E,0x01,0x80,0x40,0x3E,0x00,0x00,0xFE,0x00,0x00,0x7E,0x80,0xE0,0x00,/*"流",39*/
  181. 0x40,0x22,0x14,0x08,0xF4,0x02,0x10,0x10,0xFF,0x10,0xF0,0x11,0x16,0x10,0x10,0x00,
  182. 0x08,0x44,0x82,0x41,0x3F,0x80,0x60,0x1C,0x03,0x00,0x3F,0x40,0x40,0x40,0x78,0x00,/*"犹",40*/
  183. 0x00,0x02,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x00,
  184. 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x44,0x58,0x40,0x40,0x40,0x00,/*"玉",41*/
  185. 0x20,0x18,0x0F,0x08,0xF8,0x08,0x08,0x00,0x00,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,
  186. 0x81,0x41,0x31,0x0D,0x03,0x0D,0x71,0x01,0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,/*"知",42*/
  187. 0x04,0xE4,0x5C,0x44,0xC4,0x80,0x80,0xFE,0x40,0x44,0x04,0xFC,0x04,0x04,0xFC,0x00,
  188. 0x01,0x3F,0x10,0x10,0x3F,0x00,0x00,0x1F,0x88,0x44,0x30,0x0F,0x40,0x80,0x7F,0x00,/*"砌",43*/
  189. 0x24,0x24,0xA4,0xFE,0x23,0x22,0x80,0x70,0x00,0xFF,0x00,0x80,0x40,0x30,0x00,0x00,
  190. 0x08,0x06,0x01,0xFF,0x01,0x86,0x40,0x30,0x0E,0x01,0x06,0x18,0x20,0x40,0x80,0x00,/*"秋",44*/
  191. 0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00,
  192. 0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00,/*"能",45*/
  193. 0x04,0x04,0x04,0x84,0x6F,0x04,0x04,0x04,0xE4,0x04,0x8F,0x44,0x24,0x04,0x04,0x00,
  194. 0x04,0x02,0x01,0xFF,0x00,0x10,0x08,0x04,0x3F,0x41,0x40,0x40,0x40,0x40,0x78,0x00,/*"花",46*/
  195. 0x00,0xF8,0x01,0x02,0x00,0xE2,0x22,0x22,0x22,0xE2,0x02,0x02,0x02,0xFE,0x00,0x00,
  196. 0x00,0xFF,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00,/*"问",47*/
  197. 0x00,0xFE,0x42,0x52,0x7E,0x52,0x42,0xFE,0x10,0xFC,0x4B,0x48,0xF9,0x4A,0x48,0x00,
  198. 0x80,0x7F,0x00,0x0F,0x09,0x4F,0x80,0x7F,0x00,0xFF,0x22,0x22,0x3F,0x22,0x22,0x00,/*"雕",48*/
  199. 0x00,0xE4,0x2C,0x35,0xA6,0x74,0x2C,0x24,0x02,0xF2,0x1A,0xD6,0x12,0xF2,0x02,0x00,
  200. 0x40,0x3F,0x80,0x89,0x44,0x22,0x11,0x08,0x80,0x4F,0x30,0x0F,0x10,0x2F,0xC0,0x00,/*"颜",49*/
  201. 0x00,0x00,0xFE,0x02,0x12,0x22,0xC2,0x02,0xC2,0x32,0x02,0xFE,0x00,0x00,0x00,0x00,
  202. 0x80,0x60,0x1F,0x00,0x20,0x10,0x0C,0x03,0x0C,0x30,0x00,0x0F,0x30,0x40,0xF8,0x00,/*"风",50*/
  203. 0x04,0x04,0xE4,0x25,0x26,0x34,0x2C,0x24,0x24,0x24,0x26,0x25,0xE4,0x04,0x04,0x00,
  204. 0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,/*"首",51*/
  205. };

        至此,精简字库准备完成,接下来是字库的使用。

三 精简字库的调用

【1】新建一个头文件并转化成 UTF-8 编码格式(我这边命名为 Gui_Text_UTF8.h ),里面通过宏定义,管理程序中用到的所有中文文本内容。好处是该头文件可以随时替换为其他的编码格式:

  1. #ifndef __GUI_TEXT_UTF8_H_
  2. #define __GUI_TEXT_UTF8_H_
  3. /* Screen 1: List Components. */
  4. #define TEXT_TEST ("春花秋月何时了?往事知多少.小楼昨夜又东风,故国不堪回首月明中.雕栏玉砌应犹在,只是朱颜改.问君能有几多愁?恰似一江春水向东流.")
  5. /* Screen 2: Basic Paint*/
  6. /* Screen 3: Text demo*/
  7. /* Screen 4: Variable box. */
  8. /* Screen 5: Realtime graph. */
  9. /* Screen 6: Variable box. */
  10. /* Screen 7: Notice box. */
  11. #endif

【2】主函数中调用(例子中使用多行文本显示函数 SGUI_Text_DrawMultipleLinesText ,该函数中的内容遇到设定的空间边界自动换行):

  1. /**************************************************************************
  2. * 函数名称: Gui_Task
  3. * 功能描述: 液晶显示子任务
  4. **************************************************************************/
  5. SGUI_SCR_DEV disp_dev; //中文屏设备源
  6. #define BMP_DATA_BUFFER_SIZE (512)
  7. SGUI_BYTE s_pBmpDataBuffer[BMP_DATA_BUFFER_SIZE];
  8. void Gui_Task(void)
  9. {
  10. SGUI_RECT disp_area;
  11. SGUI_POINT disp_offs;
  12. //点阵屏初始化/配置命令/清屏
  13. LDZ_Init();
  14. LDZ_Cfg();
  15. LDZ_Clear();
  16. //设备内存地址初始化
  17. SGUI_SystemIF_MemorySet(&disp_dev, 0x00, sizeof(disp_dev));
  18. //一些相关初始化配置
  19. disp_area.iX = 0;
  20. disp_area.iY = 0;
  21. disp_area.iWidth = 128;
  22. disp_area.iHeight = 64;
  23. disp_offs.iX = 0;
  24. disp_offs.iY = 0;
  25. disp_dev.stSize.iWidth = 128;
  26. disp_dev.stSize.iHeight = 64;
  27. /* Initialize interface object. */
  28. disp_dev.fnSetPixel = LDZ_SetPixel;
  29. disp_dev.fnClear = LDZ_Clear;
  30. disp_dev.fnSyncBuffer = LDZ_Refresh;
  31. disp_dev.stBuffer.pBuffer = s_pBmpDataBuffer;
  32. disp_dev.stBuffer.sSize = BMP_DATA_BUFFER_SIZE;
  33. //...
  34. while(1)
  35. {
  36. //显示多行文本
  37. disp_area.iX = 0;
  38. disp_area.iY = 0;
  39. disp_area.iWidth = 128;
  40. disp_area.iHeight = 64;
  41. SGUI_Text_DrawMultipleLinesText(&disp_dev, TEXT_TEST, &SGUI_DEFAULT_FONT_16, &disp_area, 0, SGUI_DRAW_NORMAL);
  42. LDZ_Refresh();
  43. os_dly_wait(50);
  44. }
  45. }

【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博客

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/926884
推荐阅读
相关标签
  

闽ICP备14008679号