Hi,
I am very aware that this question hardly belongs in Arduino, but...
I want to use GFX fonts in Unity.
I have created a Unity project, where I use a cube of LEDs on which I show running text. I have created a simple character generator by hand, which was a terrible job. So I was thinking of using ready-made fonts instead and my thoughts went to GFX fonts since I was using them in Arduino. Now you will tell me, that GFX fonts are useless if you do not have corresponding GFX library in C#. But extracting bitmaps out of the GFX structure is an intuitively easy job if you only can compile the font in C#.
When you look at the GFX font, it is basically a C-code describing arrays of bitmaps and glyphs and a simple structure of pointers. The huge part is the glyph data and bitmap data, that does not need to convert at all. There are just a few language-specific things.
That should be easy to convert to C#. But I am not so experienced, therefore I ask for little help.
And remember! - there is an open source fonconvert.c utility for creating GFX fonts out of Truetype fonts. So once I know how to code the corresponding structures, I can simply fix the fontconvert.c and recompile, which makes the conversion to C# automatic.
First I need to create corresponding types to the typedef from the GFX-library
typedef struct {
uint16_t bitmapOffset; ///< Pointer into GFXfont->bitmap
uint8_t width; ///< Bitmap dimensions in pixels
uint8_t height; ///< Bitmap dimensions in pixels
uint8_t xAdvance; ///< Distance to advance cursor (x axis)
int8_t xOffset; ///< X dist from cursor pos to UL corner
int8_t yOffset; ///< Y dist from cursor pos to UL corner
} GFXglyph;
/// Data stored for FONT AS A WHOLE
typedef struct {
uint8_t *bitmap; ///< Glyph bitmaps, concatenated
GFXglyph *glyph; ///< Glyph array
uint16_t first; ///< first char (code point) of the Font
uint16_t last; ///< last char (code point) of the first part of the Font
uint8_t yAdvance; ///< Newline distance (y axis)
} GFXfont;
that I can use in the font definition itself.
So, what else we have to convert to C# is:
const uint8_t FreeMono9pt7bBitmaps[] PROGMEM = {
0xAA, 0xA8, 0x0C, 0xED, 0x24, 0x92, 0x48, 0x24, 0x48, 0x91, 0x2F, 0xE4,
0x89, 0x7F, 0x28, 0x51, 0x22, 0x40, 0x08, 0x3E, 0x62, 0x40, 0x30, 0x0E,
0x01, 0x81, 0xC3, 0xBE, 0x08, 0x08, 0x71, 0x12, 0x23, 0x80, 0x23, 0xB8,
...
}
const GFXglyph FreeMono9pt7bGlyphs[] PROGMEM = {
{ 0, 0, 0, 11, 0, 1 }, // 0x20 ' '
{ 0, 2, 11, 11, 4, -10 }, // 0x21 '!'
{ 3, 6, 5, 11, 2, -10 }, // 0x22 '"'
....
}
}
const GFXfont FreeMono9pt7b PROGMEM = {
(uint8_t *)FreeMono9pt7bBitmaps,
(GFXglyph *)FreeMono9pt7bGlyphs,
0x20, 0x7E, 18 };
The PROGMEM is of course not relevant here, is it?
The question is, if there are corresponding types for uint8_t and uint16_t in C#. But that is not critical since I can always use int, meaning int32_t
I would really appreciate anyone's help. Please, be as specific as possible and "translate" the above code so that I can just complete it with the skipped parts of data and compile since I know that making conclusions and improvising in C# is a dangerous business.
Thank you so much.