带有位图字体的 C 头文件
我需要对像素缓冲区进行一些基本的文本渲染,并且我认为拥有一个由 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},
};
}
我可以继续学习字母表的其余部分,但那样我就不需要问...但这给了我一个想法!如果没有可用的带有位图字体的免费标题,每个答案都可以实现一个字母,我可以在这里组装整个文件^_^
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 ^_^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
更新:我尝试了这种方法,但字符显示得相当扭曲。 Nimbus 可能是一个糟糕的字体选择。
采用 imagemagick 方法。您可以使用以下命令生成每个字符:
A.xbm 如下所示:
循环遍历您需要的字符并将其组装到单个头文件中。
尽管 Nimbus-Mono-Regular 是等宽字体,但有时字符宽度会偏离一个像素。转换选项“-resize 7x13!”强制输出尺寸为 7x13。同样,这可能是 Nimbus 字体特有的问题。
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:
A.xbm looks like:
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.
我最终使用: https://github.com/dhepper/font8x8
8x8 单色位图字体。
许可证:公共领域
印刷品:
I ended up using: https://github.com/dhepper/font8x8
A 8x8 monochrome bitmap font.
License: Public Domain
Prints:
我知道你可以在 gimp 中将图像保存为 ac 头文件。也许您可以找到一个在命令行上完成这项工作的工具。所以你可以自动化创建。 ImageMagick至少可以加载ttf字体。
编辑:Gimp 仅支持 RGB 数据作为输出格式,因此它不适合您。
无论如何,这里有一个“b”给你:
I know you can save images as a c header file in gimp. Maybe you can find a tool which does the job on the command line. So you could automate the creation. ImageMagick can at least load ttf fonts.
EDIT: Gimp does only support RGB data as output format, so it's not a solution for you.
Anyway here is an 'b' for you:
“像素字体”可能是一个很好的资源:
http://www.alvit.de/blog/article/ 25 种最佳免许可像素字体
"Pixel fonts" may be a good resource:
http://www.alvit.de/blog/article/25-best-license-free-pixelfonts
该网站有许多不同的位图字体以及使用它们的方法:
https: //jared.geek.nz/2014/jan/custom-fonts-for-microcontrollers
(有点旧,但非常有用)
注意:他们的
DrawChar()
实现没有为我工作,所以我用这个代替:this site has many different bitmap fonts, and ways to use them:
https://jared.geek.nz/2014/jan/custom-fonts-for-microcontrollers
(its a bit old, but its very useful)
Note: their implementation of
DrawChar()
didnt work for me, so i used this instead:我知道它不能回答您的问题,但我建议仅使用 http://www. Angelcode.com/products/bmfont/ 生成简单的位图字体。加载 tga 文件非常简单。我不希望众包字体看起来非常漂亮。
I know it doesn't answer your question but I would recommend just using something like http://www.angelcode.com/products/bmfont/ to generate a simple bitmap font. Loading a tga file is pretty simple. I wouldn't expect a crowdsourced font to look very nice.
来自 Archlinux,我总是首先查看官方和用户包存储库。有一堆 bdf 字体可以用作单独的包,还有一个 bdf2c 脚本可以用于转换它。
Coming from Archlinux, I always first look into both the official and user package repos. There's a bunch of bdf fonts that you can use as individual packages, there's also a bdf2c script you can use to convert it.
我从 nimbus_debug 的答案中获取了字体,并从 madeso 的答案中获取了渲染,看看它会是什么样子。
人物塑造得相当不错,
旋转了 180 但这是一个小问题。
这就是“3”的样子:
I took the font from nimbus_debug's answer and the rendering from madeso's answer to see what it would look like.
Characters come out pretty nice,
rotated 180 but that's a minor issue.
This is what the '3' look like: