Page 1 of 1

MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 31 May 2018, 06:34
by ferreiradaselva
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:
{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
};

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 31 May 2018, 20:35
by Lyberta
Deleted.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 31 May 2018, 21:07
by ferreiradaselva
Lyberta {l Wrote}:Contradiction much? There is a reason people stopped using bitmap fonts - they don't scale and can't handle Unicode.


People certainly did not stop using bitmap fonts. By "scalable" I mean that I can add new fonts to a project in an easier way. Bitmap fonts can handle Unicode, tho (one example: http://unifoundry.com/unifont.html). The problem with that example is that certain glyphs (chinese/japanese for example), require wider space to render, and will simultaneously affect the other characters. Consequence of adding everything in a single sheet.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 03:02
by ferreiradaselva
Working on a set of hiragana characters:

Image

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 03:29
by onpon4
wouldn't it be easier in the case of hiragana to just use an existing vector font and convert it to raster? Considering you're not exactly stylizing it, that is.

By the way, take this with a grain of salt since I'm not a native speaker, but I think those small versions are too big. I wouldn't have noticed they were small versions if they hadn't been right next to the big versions. I could definitely see myself misreading びょういん as びよういん if you sized ょ like that.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 03:50
by ferreiradaselva
onpon4 {l Wrote}:wouldn't it be easier in the case of hiragana to just use an existing vector font and convert it to raster? Considering you're not exactly stylizing it, that is.


Yeah, I tried that first (with inkscape), but at this resolution, requiring 1px of precision, it looked like poop :lol: But, that's totally a better workflow for bigger fonts.

onpon4 {l Wrote}:By the way, take this with a grain of salt since I'm not a native speaker, but I think those small versions are too big. I wouldn't have noticed they were small versions if they hadn't been right next to the big versions. I could definitely see myself misreading びょういん as びよういん if you sized ょ like that.


Thanks for the tip, I will try to make them smaller to distinguish better. :)

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 04:04
by onpon4
Yeah, I tried that first (with inkscape), but at this resolution, requiring 1px of precision, it looked like poop :lol: But, that's totally a better workflow for bigger fonts.

What? No, just open up the GIMP or KolourPaint and type the letters out in whatever size you need. If you're worried about licensing, just use a libre font and put the same license on for the raster version. It took me no more than 5 minutes to type it up:

あぁいぃうぃえぇおぉ
かがきぎくぐけげこご
さざしじすずせぜそぞ
ただちぢつづってでとど
なにぬねの
はばぱひびぴふぶぷへべぺほぼぽ
まみむめも
やゃゆゅよょ
らりるれろ
わゎをん
ゐゑ

And copying/pasting that into a text field would take seconds (or maybe a couple minutes rearranging it and optimizing it for space).

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 04:28
by ferreiradaselva
onpon4 {l Wrote}:
Yeah, I tried that first (with inkscape), but at this resolution, requiring 1px of precision, it looked like poop :lol: But, that's totally a better workflow for bigger fonts.

What? No, just open up the GIMP or KolourPaint and type the letters out in whatever size you need. If you're worried about licensing, just use a libre font and put the same license on for the raster version. It took me no more than 5 minutes to type it up:


Oh, with GIMP indeed looks good! Even without antialiasing, just requiring minor tweaks.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 04:32
by Lyberta
Deleted.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 06:58
by ferreiradaselva
Lyberta {l Wrote}:There are also combining marks and other things. Unicode is hard. I expect modern code to use specialized libraries to draw text. Also, that font is barely readable on my HiDPI monitor.


I know, all those other things also require a lot of work if using TTF/OTF. I work with unicode too, in other projects, both with the low-level handling of inputs and with rendering. Combining marks, contextual characters (like in arabic), all require the same work, whether is vector or bitmap-based font. It's just a matter of covering the codepoints. As for the font not being readable enough n HiDPI monitor, like I mentioned in the first post, it's a project about increasing a database of fonts, which include fonts of different sizes. It's not something that I alone will acomplish, the point of having a generator is exactily to make possible other people to contribute.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 19:34
by Lyberta
Deleted.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 22:34
by SecureUvula
I use bitmap fonts cause they're easy to set up

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 01 Jun 2018, 22:52
by onpon4
I like using bitmap fonts sometimes, but only because they can look nicer. Other than that, vector fonts are way more convenient.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 04 Jun 2018, 00:04
by leilei
and I use bitmap fonts because VRAM is precious, and there's not a lot of Free vector fonts out there that scale well down into 8x16 characters and be well readable.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 04 Jun 2018, 02:31
by SecureUvula
That reminds me, I saw this link from the AGG genius on his idea for ideal font rendering:

http://www.antigrain.com/research/font_ ... n/#toc0001

The bit about perfect sub-pixel positioning is satisfying to look at. Of course he is using vector fonts because he is going for quality and not simplicity.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 04 Jun 2018, 05:55
by ferreiradaselva
Just skimming at that link, that looks awesome. I will take some time reading that.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 06 Jun 2018, 00:18
by Lyberta
Deleted.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 06 Jun 2018, 12:49
by ferreiradaselva
Lyberta {l Wrote}:
SecureUvula {l Wrote}:That reminds me, I saw this link from the AGG genius on his idea for ideal font rendering:

http://www.antigrain.com/research/font_ ... n/#toc0001

The bit about perfect sub-pixel positioning is satisfying to look at. Of course he is using vector fonts because he is going for quality and not simplicity.


Case in point, I can't read the text in many of the pictures there. It's too small for my monitor.


I don't know if you are trolling at this point. The article in the link speaks about truetype/opentype fonts. Font size is also not the point, but the anti-aliasing techniques. And, even if it was about bitmap fonts, size is determined by the font of choice, doesn't mean that all bitmap fonts must be 8x8, like I said before. There are plenty of games out there that uses bitmap font, large and small, colored and black/white, indies and non-indies.

Back to the project, I've removed the Lua and ImageMagick dependencies. I converted the whole Lua script (which I was using because of the nice UTF8 module) into a small C program. The PNG is loaded using the PNG loader from Randy Gaul (https://github.com/RandyGaul/cute_heade ... cute_png.h), doing the job that ImageMagick was doing. This means the command line was simplified:

{l Code}: {l Select All Code}
generate ../fonts/hiragana1_16x16x16


The argument for the command is the text file with the characters. The PNG file is assumed to be "../fonts/hiragana1_16x16x16.png".

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 06 Jun 2018, 13:34
by Lyberta
Deleted.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 06 Jun 2018, 17:26
by SecureUvula
I've been using stb_image, is cute_png any different? I see both are permissive licensed.

Re: MonoGlyph project - monospaced bitmap fonts for C!

PostPosted: 06 Jun 2018, 19:05
by ferreiradaselva
SecureUvula {l Wrote}:I've been using stb_image, is cute_png any different? I see both are permissive licensed.


I like "cute headers" more (old name was "tiny headers"), because the code seems cleaner, has less "code smell". But, I can't speak about which one is more bug-free, as I don't know much about PNG loading. And cute_png is focused on PNG, while stb_image has implementation for many formats. I'm the kind of person that will trust more a library that is focused on a specific task than a library that does many tasks.