Skip to content

How to convert a font

max mc costa edited this page Nov 2, 2015 · 10 revisions

From version 0.70b11 (so do not run to convert until it's released!!!) the RA8875 library use a brand new font rendering engine highly optimized for rendering any type of font but for use within library you need to convert first!
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 codes.
ATTENTION! Fonts are copyrighted! Remember to use FREE-LICENSED fonts and do not convert Adobe or whatever that's copyrighted!
I'm using lcd-image-converter http://www.riuson.com/lcd-image-converter/download , you can get the last beta, download and put in your computer, sorry, only WINDOWS (if you are on mac or linux, you can use an emulator or build it from sources for your OS).
Then you need a special file I provide in the library utility folder, sumotoy_font.tmpl , put inside the lcd-image-converter folder.

screen 1

Now we start... Launch application, click font
screen 2

Give the font a right nime (no spaces, strange chars, do not start with a number, etc.) screen 3

Now select a font... screen 4

Select basic latin... screen 5

Note that you can create your range by erasing the font range and double-click on any glyph on the right table, but it's really important that you provide ALWAYS a space, once finished your custom range press the button 'Sort' to get a right order in the array will be created.

Font will be displayed, check if all font are rendered, if NOT erased from the bottom the chars that are not displayed (it will use resources for nothing) screen 6 Note that selecting BIG fonts will use a lot of resources! You better choose only the chars you really need if you can!

Now click OK screen 7 Before start to modify fonts (in this program you can) you need to set template first...

Go to Options->Conversion, select Templates and select the file sumotoy_font.tmpl as show screen 8 You should also select from the preset menu 'Monocrome'

Now go to tab Prepare and set as showed... screen 9

Now go to tab Matrix, should be like this... screen 10

Tab Reordering should be like this... screen 11

Tab Image... screen 12

...And Tab Font... screen 13

Now close window, you will be asked to save. Before this you can also save the preset so it remain stored between any version of the program screen 14

For saving even more data, you can go in Font->Optimize weight.. menu screen 15 Scroll the window and check if you can trim up and down some pixel, library render engine has been optimized to detect blank lines but every line occupy space so better avoid.

Finally you can save the new font file in your font directory, file->Convert screen 16 Please NOTE, the first time you setup the program (and choosed the custom template) it's VERY IMPORTANT you first save the font, close the program and reopen font, this because the program doesn't accept the template file immediately but it load during startup!

So to save the font file for future manipulations select file->Save as... screen 1

It's look long but remember that you DON'T need all steps for every font! This is just the setup, conversion menu has to be set once only so for successive font you just need open font, trim space and convert!

Font Editing

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: akashi_36
  • family: Akashi
  • size: 36
  • style: Normal

  • included characters: !"#$%&'()*+,-./0123456789:;<=>?\x0040ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}

  • antialiasing: no
  • type: proportional
  • encoding: latin0
  • 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. RA8875

*******************************************************************************/ `

#include <stdint.h>

`

static const uint8_t image_data_akashi_36_0x20[60] _PRGMTAG = { 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, 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 const tImage akashi_36_0x20 _PRGMTAG = { image_data_akashi_36_0x20,12,60};//character: ' ' , height: 40

static const uint8_t image_data_akashi_36_0x21[45] _PRGMTAG = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe1, 0xf0, 0xf8, 0x7c, 0x3e, 0x1f, 0x0f, 0x87, 0xc3, 0xe1, 0xf0, 0xf8, 0x7c, 0x3e, 0x1f, 0x0f, 0x87, 0xc3, 0xe1, 0xf0, 0xf8, 0x00, 0x00, 0x1f, 0x0f, 0x87, 0xc3, 0xe1, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const tImage akashi_36_0x21 _PRGMTAG = { image_data_akashi_36_0x21,9,45};//character: '!' , height: 40 ...
static const tChar akashi_36_array[] = {

// character: ' '
{0x20, &akashi_36_0x20},

// character: '!'
{0x21, &akashi_36_0x21},
...
//num chars, array, width, height, compression

const tFont akashi_36 = { 94, akashi_36_array,0,40,0 };
`


The 'space' char, an important note!
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 tImage aerial_22_0x20 __PRGMTAG_ = { image_data_aerial_22_0x20, 21, 58};//character: ' ' , height: 22, (charW,total bytes)
You can modify the 'space' width by changing 21 to wharever you like!
Please note that ONLY space has this exception, any other char needs glyph data for render!


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!