自己设计一种运行在单片机的嵌入式gui图形库—字体转换工具

使用Qt编写一个字体转换工具

1、界面布局
在这里插入图片描述

2、移植矢量字体解码库stb_truetype
#define STB_TRUETYPE_IMPLEMENTATION
#include “stb_truetype.h”

3、编写字体转换的代码

 /* 循环加载word中每个字符 */
    for (int i = 0; i < num ; i++)
    {
        int advanceWidth = 0;  //字宽
        int leftSideBearing = 0;  //左侧位置
        /* 获取水平方向上的度量 */
        stbtt_GetCodepointHMetrics(&info, word[i], &advanceWidth, &leftSideBearing);

        /* 获取字符的边框(边界) */
        int c_x1, c_y1, c_x2, c_y2;
        stbtt_GetCodepointBitmapBox(&info, word[i], scale, scale, &c_x1, &c_y1, &c_x2, &c_y2);

        fv_glyph_array[i]->glyph_unicode = word[i];
        fv_glyph_array[i]->glyph_width = c_x2 - c_x1;
        fv_glyph_array[i]->glyph_height = c_y2 - c_y1;
        fv_glyph_array[i]->glyph_map = (uint8_t *)malloc(fv_glyph_array[i]->glyph_width * fv_glyph_array[i]->glyph_height);
        fv_glyph_array[i]->glyph_ascent = 0 - c_y1;   //基准线上方的尺寸
        fv_glyph_array[i]->glyph_descent = c_y2;  //基准线下方的尺寸
        fv_glyph_array[i]->glyph_advance = roundf(advanceWidth * scale);  //水平方向的总尺寸 = glyph数据的宽度 + 左边距 + 右边距
        fv_glyph_array[i]->glyph_leading = roundf(leftSideBearing * scale);  //左边距

        stbtt_MakeCodepointBitmap(&info, fv_glyph_array[i]->glyph_map, c_x2 - c_x1, c_y2 - c_y1, c_x2 - c_x1, scale, scale, word[i]);
    }

4、字体转换工具生成的文件如下:

#include "fv_types_def.h" 
    
static const uint8_t font_24_map_unicode_0030[] = {  
    0x00, 0x06, 0xbe, 0xc6, 0x00,   //...35763..
    0x00, 0x9f, 0xb8, 0xdf, 0x70,   //..4754673.
    0x03, 0xfa, 0x00, 0x0d, 0xf1,   //.175...67.
    0x09, 0xf2, 0x00, 0x06, 0xf6,   //.471...373
    0x0e, 0xd0, 0x00, 0x02, 0xfa,   //.76....175
    0x0f, 0xb0, 0x00, 0x00, 0xfb,   //.75.....75
    0x1f, 0xa0, 0x00, 0x00, 0xfd,   //.75.....76
    0x2f, 0x90, 0x00, 0x00, 0xed,   //174.....76
    0x1f, 0xa0, 0x00, 0x00, 0xfb,   //.75.....75
    0x0f, 0xc0, 0x00, 0x01, 0xfa,   //.76.....75
    0x0d, 0xf0, 0x00, 0x05, 0xf6,   //.67....273
    0x07, 0xf6, 0x00, 0x0b, 0xf0,   //.373...57.
    0x01, 0xef, 0x74, 0x9f, 0x70,   //..7732473.
    0x00, 0x1c, 0xff, 0xe7, 0x00,   //...67773..
    0x00, 0x00, 0x12, 0x00, 0x00,   //.....1....
}; 
    
static const uint8_t font_24_map_unicode_0031[] = {  
    0x00, 0x00, 0x00, 0x00, 0x00,   //.........
    0x00, 0x27, 0xc7, 0x00, 0x00,   //..1363...
    0x4e, 0xff, 0xf7, 0x00, 0x00,   //277773...
    0x5b, 0x65, 0xf7, 0x00, 0x00,   //253273...
    0x00, 0x03, 0xf7, 0x00, 0x00,   //...173...
    0x00, 0x03, 0xf7, 0x00, 0x00,   //...173...
    0x00, 0x03, 0xf7, 0x00, 0x00,   //...173...
    0x00, 0x03, 0xf7, 0x00, 0x00,   //...173...
    0x00, 0x03, 0xf7, 0x00, 0x00,   //...173...
    0x00, 0x03, 0xf7, 0x00, 0x00,   //...173...
    0x00, 0x03, 0xf7, 0x00, 0x00,   //...173...
    0x00, 0x03, 0xf7, 0x00, 0x00,   //...173...
    0x00, 0x03, 0xf7, 0x00, 0x00,   //...173...
    0x28, 0x89, 0xfb, 0x88, 0x40,   //144475442
    0x5f, 0xff, 0xff, 0xff, 0x80,   //277777774
}; 
    
static const uint8_t font_24_map_unicode_0032[] = {  
    0x00, 0x05, 0xae, 0x94, 0x00,   //...25742..
    0x04, 0xfd, 0x99, 0xef, 0x80,   //.27644774.
    0x05, 0x70, 0x00, 0x0c, 0xe0,   //.23....67.
    0x00, 0x00, 0x00, 0x07, 0xf5,   //.......372
    0x00, 0x00, 0x00, 0x07, 0xf3,   //.......371
    0x00, 0x00, 0x00, 0x0b, 0xe0,   //.......57.
    0x00, 0x00, 0x00, 0x5f, 0x80,   //......274.
    0x00, 0x00, 0x03, 0xfc, 0x00,   //.....176..
    0x00, 0x00, 0x2e, 0xd1, 0x00,   //....176...
    0x00, 0x02, 0xed, 0x10, 0x00,   //...176....
    0x00, 0x2e, 0xd1, 0x00, 0x00,   //..176.....
    0x02, 0xed, 0x10, 0x00, 0x00,   //.176......
    0x0e, 0xfa, 0x88, 0x88, 0x82,   //.775444441
    0x0f, 0xff, 0xff, 0xff, 0xf4,   //.777777772
}; 
    
static const uint8_t font_24_map_unicode_0033[] = {  
    0x06, 0x9d, 0xc7, 0x20, 0x00,   //.346631..
    0x3f, 0xd8, 0xcf, 0xf1, 0x00,   //1764677..
    0x13, 0x00, 0x06, 0xf7, 0x00,   //.1...373.
    0x00, 0x00, 0x01, 0xfb, 0x00,   //......75.
    0x00, 0x00, 0x04, 0xf7, 0x00,   //.....273.
    0x00, 0x00, 0x4c, 0xe2, 0x00,   //....2671.
    0x04, 0xdf, 0xf9, 0x00, 0x00,   //.26774...
    0x03, 0x9c, 0xfe, 0x81, 0x00,   //.146774..
    0x00, 0x00, 0x06, 0xfa, 0x00,   //.....375.
    0x00, 0x00, 0x00, 0xcf, 0x10,   //......67.
    0x00, 0x00, 0x00, 0x9f, 0x30,   //......471
    0x20, 0x00, 0x01, 0xff, 0x00,   //1.....77.
    0xbd, 0x84, 0x8d, 0xf6, 0x00,   //56424673.
    0x6c, 0xff, 0xfd, 0x50, 0x00,   //3677762..
    0x00, 0x03, 0x10, 0x00, 0x00,   //...1.....
}; 
    
static const uint8_t font_24_map_unicode_0034[] = {  
    0x00, 0x00, 0x00, 0xbc, 0x30, 0x00,   //......561..
    0x00, 0x00, 0x09, 0xff, 0x40, 0x00,   //.....4772..
    0x00, 0x00, 0x4f, 0xaf, 0x40, 0x00,   //....27572..
    0x00, 0x00, 0xea, 0x6f, 0x40, 0x00,   //....75372..
    0x00, 0x09, 0xe1, 0x6f, 0x40, 0x00,   //...47.372..
    0x00, 0x4f, 0x50, 0x6f, 0x40, 0x00,   //..272.372..
    0x01, 0xea, 0x00, 0x6f, 0x40, 0x00,   //..75..372..
    0x0a, 0xe1, 0x00, 0x6f, 0x40, 0x00,   //.57...372..
    0x4f, 0x50, 0x00, 0x6f, 0x40, 0x00,   //272...372..
    0xcf, 0xff, 0xff, 0xff, 0xff, 0x00,   //6777777777.
    0x56, 0x66, 0x66, 0xaf, 0x96, 0x00,   //2333335743.
    0x00, 0x00, 0x00, 0x6f, 0x40, 0x00,   //......372..
    0x00, 0x00, 0x00, 0x6f, 0x40, 0x00,   //......372..
    0x00, 0x00, 0x00, 0x6f, 0x40, 0x00,   //......372..
}; 
    
static const uint8_t font_24_map_unicode_0035[] = {  
    0x0c, 0xcc, 0xcc, 0xc9, 0x00,   //.6666664.
    0x0f, 0xec, 0xcc, 0xc9, 0x00,   //.7766664.
    0x0f, 0x90, 0x00, 0x00, 0x00,   //.74......
    0x0f, 0x90, 0x00, 0x00, 0x00,   //.74......
    0x0f, 0x90, 0x00, 0x00, 0x00,   //.74......
    0x0f, 0xb5, 0x41, 0x00, 0x00,   //.7522....
    0x0f, 0xff, 0xff, 0xa1, 0x00,   //.777775..
    0x03, 0x23, 0x7c, 0xfb, 0x00,   //.1113675.
    0x00, 0x00, 0x00, 0xef, 0x20,   //......771
    0x00, 0x00, 0x00, 0x8f, 0x50,   //......472
    0x00, 0x00, 0x00, 0xaf, 0x40,   //......572
    0x00, 0x00, 0x01, 0xff, 0x10,   //......77.
    0x6d, 0x84, 0x9e, 0xf6, 0x00,   //36424773.
    0x4d, 0xff, 0xfd, 0x50, 0x00,   //2677762..
    0x00, 0x03, 0x10, 0x00, 0x00,   //...1.....
}; 
    
static const uint8_t font_24_map_unicode_0036[] = {  
    0x00, 0x06, 0xbe, 0xda, 0x00,   //...35765.
    0x00, 0x9f, 0xc8, 0xae, 0x00,   //..476457.
    0x08, 0xf7, 0x00, 0x00, 0x00,   //.473.....
    0x1f, 0xb0, 0x00, 0x00, 0x00,   //.75......
    0x7f, 0x40, 0x00, 0x00, 0x00,   //372......
    0xaf, 0x03, 0x86, 0x00, 0x00,   //57.143...
    0xce, 0x7f, 0xef, 0xf9, 0x00,   //67377774.
    0xef, 0xc4, 0x03, 0xbf, 0x20,   //7762.1571
    0xef, 0x50, 0x00, 0x4f, 0x80,   //772...274
    0xcf, 0x00, 0x00, 0x0f, 0xd0,   //67.....76
    0xaf, 0x30, 0x00, 0x1f, 0xc0,   //571....76
    0x4f, 0x90, 0x00, 0x6f, 0x80,   //274...374
    0x0b, 0xfb, 0x59, 0xfe, 0x00,   //.5752477.
    0x00, 0xaf, 0xff, 0xb1, 0x00,   //..57775..
    0x00, 0x00, 0x20, 0x00, 0x00,   //....1....
}; 
    
static const uint8_t font_24_map_unicode_0037[] = {  
    0x2c, 0xcc, 0xcc, 0xcc, 0xc9,   //1666666664
    0x2c, 0xcc, 0xcc, 0xcd, 0xf8,   //1666666674
    0x00, 0x00, 0x00, 0x09, 0xf1,   //.......47.
    0x00, 0x00, 0x00, 0x0f, 0xb0,   //.......75.
    0x00, 0x00, 0x00, 0x6f, 0x40,   //......372.
    0x00, 0x00, 0x00, 0xdd, 0x00,   //......66..
    0x00, 0x00, 0x04, 0xf7, 0x00,   //.....273..
    0x00, 0x00, 0x0a, 0xf1, 0x00,   //.....57...
    0x00, 0x00, 0x1f, 0xa0, 0x00,   //.....75...
    0x00, 0x00, 0x8f, 0x30, 0x00,   //....471...
    0x00, 0x00, 0xed, 0x00, 0x00,   //....76....
    0x00, 0x05, 0xf6, 0x00, 0x00,   //...273....
    0x00, 0x0c, 0xf0, 0x00, 0x00,   //...67.....
    0x00, 0x3f, 0x90, 0x00, 0x00,   //..174.....
}; 
    
static const uint8_t font_24_map_unicode_0038[] = {  
    0x00, 0x05, 0xae, 0xa5, 0x00,   //...25752..
    0x00, 0xaf, 0xc8, 0xdf, 0x80,   //..5764674.
    0x02, 0xf9, 0x00, 0x0d, 0xe0,   //.174...67.
    0x07, 0xf4, 0x00, 0x08, 0xf3,   //.372...471
    0x03, 0xf9, 0x00, 0x0d, 0xe0,   //.174...67.
    0x00, 0xbf, 0x82, 0xbf, 0x50,   //..5741572.
    0x00, 0x08, 0xff, 0xf3, 0x00,   //...47771..
    0x00, 0x3d, 0xfc, 0xfb, 0x10,   //..167675..
    0x04, 0xfb, 0x10, 0x5e, 0xf1,   //.275..277.
    0x0b, 0xf1, 0x00, 0x06, 0xf6,   //.57....373
    0x0f, 0xc0, 0x00, 0x01, 0xfa,   //.76.....75
    0x0a, 0xf2, 0x00, 0x06, 0xf8,   //.571...374
    0x03, 0xfd, 0x74, 0x9e, 0xe2,   //.176324771
    0x00, 0x5b, 0xff, 0xfb, 0x30,   //..2577751.
    0x00, 0x00, 0x12, 0x00, 0x00,   //.....1....
}; 
    
static const uint8_t font_24_map_unicode_0039[] = {  
    0x00, 0x09, 0xde, 0xb4, 0x00,   //...46752..
    0x01, 0xdf, 0xca, 0xff, 0x50,   //..6765772.
    0x09, 0xf6, 0x00, 0x2d, 0xe0,   //.473..167.
    0x0e, 0xe0, 0x00, 0x08, 0xf5,   //.77....472
    0x0f, 0xb0, 0x00, 0x03, 0xf8,   //.75....174
    0x0c, 0xf0, 0x00, 0x05, 0xfa,   //.67....275
    0x06, 0xf7, 0x00, 0x1c, 0xfa,   //.373...675
    0x01, 0xef, 0xea, 0xfb, 0xf9,   //..77757574
    0x00, 0x05, 0xcc, 0x82, 0xf7,   //...2664173
    0x00, 0x00, 0x00, 0x04, 0xf5,   //.......272
    0x00, 0x00, 0x00, 0x0a, 0xe0,   //.......57.
    0x00, 0x00, 0x00, 0x4f, 0x80,   //......274.
    0x04, 0xa5, 0x48, 0xfc, 0x10,   //.2522476..
    0x04, 0xef, 0xfe, 0x90, 0x00,   //.277774...
    0x00, 0x01, 0x20, 0x00, 0x00,   //....1.....
}; 
    
static const fv_glyph_t font_24_glyph_array[] = {  
    {.glyph_unicode = 0x0030, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 14, .glyph_descent = 1, .glyph_advance = 11, .glyph_leading = 1, .glyph_width = 10, .glyph_height = 15, .glyph_map = font_24_map_unicode_0030},
    {.glyph_unicode = 0x0031, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 15, .glyph_descent = 0, .glyph_advance = 11, .glyph_leading = 2, .glyph_width = 9, .glyph_height = 15, .glyph_map = font_24_map_unicode_0031},
    {.glyph_unicode = 0x0032, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 14, .glyph_descent = 0, .glyph_advance = 11, .glyph_leading = 1, .glyph_width = 10, .glyph_height = 14, .glyph_map = font_24_map_unicode_0032},
    {.glyph_unicode = 0x0033, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 14, .glyph_descent = 1, .glyph_advance = 11, .glyph_leading = 1, .glyph_width = 9, .glyph_height = 15, .glyph_map = font_24_map_unicode_0033},
    {.glyph_unicode = 0x0034, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 14, .glyph_descent = 0, .glyph_advance = 11, .glyph_leading = 0, .glyph_width = 11, .glyph_height = 14, .glyph_map = font_24_map_unicode_0034},
    {.glyph_unicode = 0x0035, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 14, .glyph_descent = 1, .glyph_advance = 11, .glyph_leading = 2, .glyph_width = 9, .glyph_height = 15, .glyph_map = font_24_map_unicode_0035},
    {.glyph_unicode = 0x0036, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 14, .glyph_descent = 1, .glyph_advance = 11, .glyph_leading = 1, .glyph_width = 9, .glyph_height = 15, .glyph_map = font_24_map_unicode_0036},
    {.glyph_unicode = 0x0037, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 14, .glyph_descent = 0, .glyph_advance = 11, .glyph_leading = 1, .glyph_width = 10, .glyph_height = 14, .glyph_map = font_24_map_unicode_0037},
    {.glyph_unicode = 0x0038, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 14, .glyph_descent = 1, .glyph_advance = 11, .glyph_leading = 1, .glyph_width = 10, .glyph_height = 15, .glyph_map = font_24_map_unicode_0038},
    {.glyph_unicode = 0x0039, .glyph_format = FV_GLYPH_FORMAT_4BPP, .glyph_ascent = 14, .glyph_descent = 1, .glyph_advance = 11, .glyph_leading = 1, .glyph_width = 10, .glyph_height = 15, .glyph_map = font_24_map_unicode_0039},
}; 
    
const fv_font_t font_24 = {  
    .font_name = "font_24", 
    .font_location = FV_FONT_LOCATION_ROM_BIN, 
    .font_line_height = 24, 
    .font_baseline = 19, 
    .font_glyphs = font_24_glyph_array, 
    .font_glyphs_cnt = 10, 
}; 
    
FV_ADD_FONT(font_24);  //将字体的指针添加到自定义数据段  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 嵌入式单片机emwin面试题主要集中在以下几个方面: 1. 熟悉emwin库的使用:面试官可能会问关于emwin库的基本使用和功能的问题,如如何创建一个窗口、如何在窗口中添加控件等等。在回答时,应该展示出对emwin库熟练使用的能力,并能够详细解释函数的功能和参数的含义。 2. 界面设计能力:嵌入式单片机的界面设计非常重要,因此面试官可能会要求展示自己的界面设计能力,如如何设计一个用户友好的界面、如何优化界面的性能等。回答时,可以给出一些实际的例子来说明自己的设计思路和对界面优化的理解。 3. 嵌入式开发经验:除了emwin库的具体使用,面试官可能还会问一些关于嵌入式开发的相关问题,如如何用emwin库实现与硬件的通信、如何处理中断等。在回答时,应该展现出对嵌入式开发领域的经验和理解,并能够灵活应对面试官的问题。 4. 解决问题的能力:在嵌入式开发中,遇到问题是常有的事情,因此面试官可能会问一些关于解决问题的能力的问题,如如何调试emwin库中的bug、如何进行性能优化等。回答时,可以分享自己在以往项目中遇到的问题及解决方案,并强调自己的分析和解决问题的能力。 总的来说,回答嵌入式单片机emwin面试题需要展示出对emwin库的熟练掌握、界面设计的能力、嵌入式开发经验和解决问题的能力。在面试前最好多练习一些emwin相关的操作,了解嵌入式开发的基本原理和常用的工具,以便更好地回答面试题。 ### 回答2: 嵌入式单片机emwin是一种用于开发嵌入式系统的图形界面库。它可以实现在单片机中显示图形和文本,以及与用户进行交互。 emwin在嵌入式系统开发中有着广泛的应用。它可以帮助开发人员快速构建出用户友好的图形界面,提高产品的易用性和用户体验。emwin支持多种常见的图形绘制操作,如绘制直线、矩形、圆形等,同时也支持文本的显示和编辑。 在开发嵌入式系统时,使用emwin可以极大地提高开发效率。emwin提供了丰富的开发工具和模板,可以方便地编辑和设计界面,减少了开发人员的工作量。同时,emwin还提供了丰富的事件处理机制,可以对用户的输入进行响应和处理,增加了系统的灵活性。 emwin还支持多国语言的显示,可以满足不同地区用户的需求。同时,emwin还具备一定的扩展性,可以根据具体应用需求进行二次开发和定制。 总之,嵌入式单片机emwin是一款功能强大的图形界面库,可以帮助开发人员快速构建出高效、易用的嵌入式系统。它在嵌入式系统开发领域有着广泛的应用,并且具备丰富的开发工具和事件处理机制,同时还支持多国语言的显示和定制扩展。 ### 回答3: 嵌入式单片机emwin面试题是关于图形用户界面(GUI)的开发和应用的问题。emwin是一款由Segger公司开发的GUI开发工具,主要用于在嵌入式系统上实现图形化界面。 首先,emwin能够帮助嵌入式开发人员实现丰富的图形用户界面,包括按钮、滑动条、文本框等控件的创建和操作。通过emwin,开发人员可以使用简单的API进行界面设计和编程。emwin还提供了丰富的图形绘制函数,可以实现自定义图形的绘制,例如直线、圆形、矩形等。 其次,emwin还支持触摸屏的操作,可以通过触摸屏实现用户交互。开发人员可以使用emwin的触摸屏驱动和事件处理函数,实现触摸事件的捕捉和处理。通过触摸屏,用户可以轻松地操作界面,例如点击按钮、拖动滑动条等。 最后,emwin还提供了丰富的图形效果和动画效果,可以为界面增添更多的交互和视觉效果。开发人员可以使用emwin的渐变填充、渐变透明、阴影等效果函数,实现界面的美化和优化。 总的来说,emwin是一款功能强大的GUI开发工具,可以帮助嵌入式开发人员快速实现图形用户界面。它提供了丰富的功能和接口,使得界面开发和用户交互变得简单而灵活。在嵌入式单片机领域,emwin已经被广泛应用于许多领域,如工业控制、家用电器、汽车电子等。使用emwin,可以为嵌入式系统提供友好的用户界面,提升用户体验和产品竞争力。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值