具有位图字体的C头文件 [英] C header file with bitmapped fonts
问题描述
我需要对一个像素缓冲区做一些基本的文本渲染,我认为将一个以char为索引的表格作为一个二进制数组表示字符将会绰绰有余......任何人都知道一个空闲标题例如:
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} ,
};
}
我可以继续使用字母表的其余部分,但是,不需要问......但这给了我一个主意!如果没有可用的位图字体的空闲头文件,每个答案都可以实现一个字母,我可以在这里组合整个文件^ _ ^
更新:我尝试了这种方法,角色相当扭曲。可能Nimbus是一种糟糕的字体选择。
请使用imagemagick方法。您可以使用以下代码生成每个角色:
convert -resize 7x13 \! -font Nimbus-Mono-Regular -pointsize 10 label:A.xbm
A.xbm看起来像:
#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,};
循环遍历所需的字符并将其组装到一个头文件中。
$ b
即使Nimbus-Mono-Regular是一个等宽字体,有时字符宽度会被一个像素关闭。转换选项-resize 7x13!强制7x13的输出尺寸。同样,这可能是Nimbus字体的一个特殊问题。
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?
Example:
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 ^_^
Update: I tried this approach and the characters come out fairly distorted. Possibly Nimbus is a poor font choice.
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 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.
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屋!