带有位图字体的 C 头文件 [英] C header file with bitmapped fonts

查看:26
本文介绍了带有位图字体的 C 头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对像素缓冲区进行一些基本的文本渲染,我认为有一个由 char 索引的表,将字母表示为二进制数组就足够了......任何人都知道免费标题就这样?

I need to do some rudimentary text rendering to a pixel buffer, and I think that having a table indexed by char with the representation of the letters as a binary array would be more than enough... Anybody knows about a free header as such?

示例:

char data[256][8][8];
void init()
{
  data['a'] = {
    {0,0,1,1,1,0,0,0},
    {0,1,0,0,0,1,0,0},
    {0,0,0,0,0,0,1,0},
    {0,0,1,1,1,0,1,0},
    {0,1,0,0,0,1,1,0},
    {0,1,0,0,0,0,1,0},
    {0,1,0,0,0,1,1,0},
    {0,0,1,1,1,0,1,0},
  };
}

我可以继续使用字母表的其余部分,但是我不需要问...... ¡但这给了我一个想法!如果没有可用的带有位图字体的免费标题,每个答案都可以实现一个字母,我可以在这里组装整个文件^_^

I could go on with the rest of the alphabet, but then I wouldn't need to ask... ¡But that gives me an idea! if there's no free header with a bitmapped font readily available, each answer could implement a letter and I could assemble the whole file here ^_^

推荐答案

更新:我尝试了这种方法,结果显示出来的字符相当扭曲.可能 Nimbus 是一个糟糕的字体选择.

Update: I tried this approach and the characters come out fairly distorted. Possibly Nimbus is a poor font choice.

采用 imagemagick 方法.您可以使用此生成每个字符:

Go with the imagemagick approach. You can generate each character with this:

convert -resize 7x13! -font Nimbus-Mono-Regular -pointsize 10 label:A A.xbm

A.xbm 看起来像:

A.xbm looks like:

#define A_width 7
#define A_height 13
static char A_bits[] = {
  0x00, 0x00, 0x00, 0x00, 0x1C, 0x08, 0x00, 0x3C, 0x00, 0x66, 0x00, 0x00,
  0x00, };

遍历您需要的字符并将其组合成一个头文件.

Loop through the characters you need and assemble this into a single header file.

即使 Nimbus-Mono-Regular 是等宽字体,有时字符宽度也会偏离一个像素.转换选项-resize 7x13!"强制 7x13 输出大小.同样,这可能是 Nimbus 字体的问题.

Even though Nimbus-Mono-Regular is a monospace font, sometimes the character widths are off by a pixel. The convert option "-resize 7x13!" forces a 7x13 output size. Again, this might be a problem specifically with the Nimbus font.

这篇关于带有位图字体的 C 头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆