MonoGlyph project - monospaced bitmap fonts for C!
Posted: 31 May 2018, 06:34
I'm working on this project, and I needed an scalable method for including bitmap fonts in the future, for any language that I might need. Then I started this project "MonoGlyph" (like, 2 hours ago).
In short words, it's a Lua script, that you provide a PNG file containing the characters, and a text file containing the same characters. The script converts everything to a C header file, which contains the RGBA pixels of the image and the glyphs (with Unicode codepoint, and location on the image).
Project link: https://github.com/ferreiradaselva/monoglyph
"But, there's only one font in the repository!" The objective is: if more people contribute, that could be a big database of monospaced bitmap fonts, easily accessible from C.
You can contribute by making monospaced fonts and the text file containing the characters (check the repo to see the guidelines on how to make these).
License: ZLIB
Example
This image:
[img width=256]https://raw.githubusercontent.com/ferreiradaselva/monoglyph/master/fonts/simple1_5x8x8.png[/img]
This text file:
And this command:
Will generate a header like this:
In short words, it's a Lua script, that you provide a PNG file containing the characters, and a text file containing the same characters. The script converts everything to a C header file, which contains the RGBA pixels of the image and the glyphs (with Unicode codepoint, and location on the image).
Project link: https://github.com/ferreiradaselva/monoglyph
"But, there's only one font in the repository!" The objective is: if more people contribute, that could be a big database of monospaced bitmap fonts, easily accessible from C.
You can contribute by making monospaced fonts and the text file containing the characters (check the repo to see the guidelines on how to make these).
License: ZLIB
Example
This image:
[img width=256]https://raw.githubusercontent.com/ferreiradaselva/monoglyph/master/fonts/simple1_5x8x8.png[/img]
This text file:
- {l Code}: {l Select All Code}
!"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]_a
bcdefghijklmnopq
rstuvwxyz{|}
And this command:
- {l Code}: {l Select All Code}
lua generate.lua /absolute/path/monoglyph/fonts/simple1_5x8x8
/absolute/path/monoglyph/fonts/simple1_5x8x8.png
128 48 // image size
simple1_5x8x8 5 8 8 // font name, baseline, glyph width, glyph height
/absolute/path/monoglyph/fonts/simple1_5x8x8.h
Will generate a header like this:
- {l Code}: {l Select All Code}
#ifndef SIMPLE1_5X8X8_GLYPHS_H
#define SIMPLE1_5X8X8_GLYPHS_H
#include "monoglyph.h"
static uint8_t simple1_5x8x8_rgba[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
...
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static struct glyph simple1_5x8x8_glyphs[] = {
{
/* " " */
.codepoint = 32,
.col = 0,
.row = 0
},
...
};
static struct glyph_set simple1_5x8x8_glyph_set = {
.count = 0,
.glyph_baseline = 5,
.glyph_width = 8,
.glyph_height = 8,
.image_width = 128,
.image_height = 48,
.rgba = simple1_5x8x8_rgba,
.glyphs = simple1_5x8x8_glyphs
};