Convert Font - sumotoy/TFT_ILI9163C GitHub Wiki
ATTENTION! Fonts are copyrighted!
Remember to use FREE-LICENSED fonts and do not convert Adobe or whatever that's copyrighted!
Version 1.0p7 use an updated font scheme that will be interchageable with all my library so please read this for any future font conversion!
Conversion use lcd-image-converter from Riuson (thanks a lot man, wonderful work) that have binaries for WIN only. For other OS its needed to build from source code by using GD.
Download the last beta here: http://www.riuson.com/lcd-image-converter/download
-
Launch LCD Image Converter

-
Press'New Font' and give a legal name (no spaces or weird char or starting with numbers)

-
You get a screen like that, select the font from the list. In the bottom you see the 'range' of the char will be converted, I'm usually use:
!"#$%&'()*+,-./0123456789:;<=>?\x0040ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~
You can choose the range yourself but BE SURE' you always add a space since it's the char used by library for many calculations, if you not include the font will not loaded!
Do not use alpha channel or antialiasing, is 'Not Supported'
You can experiment between Proportional or Monospaced, style and size but remember that big fonts uses a lot of program space!

You should have something similar....

Now you can modify/correct glyps as your needs, remember that in real life fonts are 'vectors' but here we are dealing with 'bitmaps' that are much worst in quality!
4) After your editing I will go to menu 'Font-->Optimize Height...', this will probably save save some precious space.

-
Now go to 'Options-->Conversion...'

-
Now the 'Conversion Window' let you choose what to do. For convenience it's time to import my sumotoy_Font.xml preset, then select it. This should set everithing like the following images but not the path of the conversion template that we do at last, follow me, it's easy!





Here we choose templates. I provided 3 different templates for Fonts,Icons and Images. The Font one remain common to all presets but the image one has to be changed.
In brief, drag the 3 templates (sumotoy_icon_1.3.tmpl,sumotoy_font_2.4.tmpl,sumotoy_picture_1.3.tmpl) inside your LCD Image converter folder and choose templates as font:
You hould press the 'Save As' button on top and save. This ensure the correct path of templates has been stored together all parameters. In future you should only change preset!
Now press 'OK' if you get a save prompt, do it.

-
Now you just need to convert your font. This is very simple, choose 'File-->Convert..' al follow and save your converted font in desktop or directly in the TFT_ILI9163C/_fonts folder.

-
IMPORTANT: Remember to save your font in LCD Image Converter native file for future modifications! If you forget this you will to do again all editings! To do that go to menu 'File-->Save as..' and save in a separate folder you choose.
The program let you easy modify glyphs by simple clicking with mouse, left(add),right(delete), You will notice that some font it's antialiased, well, during conversion the grayscale will gone but it uses the parameter inside conversion dialog (threshold). You can avoid this by editing your font manually since the threshold works only to get rid of grayscale
You can also copy some glyph and paste or even add lately more glyph by clicking Menu->Change.. but you have to remember that new glyph added should have the same 'HEIGHT' of the old one, if not, select the glyph, click on menu Image->resize and adapt it to the same exact Height (width it's not important, it's handled by my library automatically), if you don't do that the glyph will be cutted or you will get unexpected bad results
As I mentioned before, it's really important you have at list one space char in every font file, my library use this data when you select font, I will add an error exception in a future if you forget this but actually this create unexpected results.
Want to see the result?
/*******************************************************************************
* name: defaultFont
* family: Arial
* size: 10
* style: Normal
* --------------------------------------
* included characters: !"#$%&'()*+,-./0123456789:;<=>?\x0040ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~°
* --------------------------------------
* antialiasing: no
* type: proportional
* encoding: latin1
* unicode bom: no
*
* data block size: 8 bit(s), uint8_t
* RLE compression enabled: no
* conversion type: Monochrome, Edge 144
* bits per pixel: 1
*
* preprocess:
* main scan direction: top_to_bottom
* line scan direction: forward
* inverse: yes
* ------------------------------------------------------------------------------
* Created by a custom template of LCD-Image-Converter for .s.u.m.o.t.o.y.
* Font template version: 2.3
* Note: Font height should be fixed and all glyps must have the same height!
* ------------------------------------------------------------------------------
*******************************************************************************/
#if !defined(SUMO_FNT_LIB_defaultFont)
#define SUMO_FNT_LIB_defaultFont
#include <stdlib.h>
static const _smCharType image_data_defaultFont_0x20[3]
#if defined(_FORCE_PROGMEM__)
PROGMEM
#endif
= { 0x00,0x00,0x00};
const tImage defaultFont_0x20
#if defined(_FORCE_PROGMEM__)
PROGMEM
#endif
= { image_data_defaultFont_0x20,
2, 3};//character: ' ' , height: 9, (charW,total bytes)
const tChar defaultFont_array[] = {{0x20, &defaultFont_0x20},...};
const tFont defaultFont = { 96, defaultFont_array,0,9, RLE_no };
#endif
The 'space' char, an important note! (optional)
The library render font as sequence of bytes but the 'space' char it's an exception since I use only it's 'width' parameter, this speed up a bit rendering but it's also possible modify easily the space with, Space in every font it's code 0x20. Inside your font.c check for this line:
static const _smCharType image_data_defaultFont_0x20[3]
#if defined(_FORCE_PROGMEM__)
PROGMEM
#endif
= { 0x00,0x00,0x00};
const tImage defaultFont_0x20
#if defined(_FORCE_PROGMEM__)
PROGMEM
#endif
= { image_data_defaultFont_0x20,
2, 3};
You can modify the 'space' width by changing 2 to wharever you like!
Please note that ONLY space has this exception, any other char needs glyph data for render!
Since the 'space' (char 0x20) it's the only char that library treat specially, it just read his 'width', we can erase useless array items, this is optional but best to learn because it save just a little space. First, we shrink the array to 1 on top:
static const _smCharType image_data_defaultFont_0x20[1]
then we erase useless array items, here's result (compare with the original):
static const _smCharType image_data_defaultFont_0x20[1]
#if defined(_FORCE_PROGMEM__)
PROGMEM
#endif
= { 0x00};
We just need to update the tImage array to reflect last changes as follow:
const tImage defaultFont_0x20
#if defined(_FORCE_PROGMEM__)
PROGMEM
#endif
= { image_data_defaultFont_0x20,
2, 1};
The new font scheme it's much better than old one, it uses PROGMEM on tiny processors and not in fast ones, also it's just one file.
The data organization it's better than many other font file I have seen around, it uses less resources and will be ready for RLE compression soon!