====== Custom fonts for Ucglib ====== This is how I built custom fonts for [[https://github.com/olikraus/ucglib | Ucglib]]/[[https://github.com/olikraus/Ucglib_Arduino | Ucglib_Arduino]] on Linux. Ucglib uses [[https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format | BDF]] fonts as a source. The basic process to convert a typical font file for use in Ucglib is: * Convert an OTF or TTF font to BDF format using ''[[ http://sofia.nmsu.edu/~mleisher/Software/otf2bdf/ | otf2bdf ]]'', ''[[http://sofia.nmsu.edu/~mleisher/Software/gbdfed/ | gbdfed]]'', or ''[[https://fontforge.github.io/en-US/ | fontforge]]''. //Check font licenses!// * Use ''bdconf'' to convert the BDF format to C. * Add the new code to the appropriate Ucglib file. Details are provided below. ===== Requirements ===== ==== Getting otf2bdf and fontforge ==== ''%%otf2bdf%%'', ''%%gbdfed%%'' and ''%%fontforge%%'' are available in many Linux distributions. ==== Building bdfconv ==== You will probably have to build ''%%bdfconv%%'' yourself. Download the [[https://github.com/olikraus/ucglib|Ucglib repository]], move into ''%%tools/font/bdfconv%%'' and $ make This will build a ''%%bdfconv%%'' executable. Put that executable or a symbolic link to it into your ''bin'' directory. ===== The process ===== ==== Convert OTF or TTF to BDF ==== Using ''otf2bdf'': $ otf2bdf -v -n -r 72 -p 71 -l '32 48_57 65_90' -c M -o filename.bdf filename.otf ''%%gbdfed%%'' also can import and convert fonts, but the monospace/proportional setting seems to be wonky. ''%%fontforge%%'' may be another option. View the result using ''%%gbdfed%%'' or ''%%fontforge%%''. Once the font is in BDF format, you can use ''%%fontforge%%'' to edit it, which might include removing unused characters or tweaking bitmaps. ==== Convert the BDF file to C using bdfconv ==== $ bdfconv -v -b 2 -f 0 -n fontname -d image.tga -o filename.c filename.bdf Note: There seems to be an upper limit to the size of the font. FIXME What is it? ==== Add new code to Ucglib ==== - Paste the content of the new C file to ''%%src/clib/ucg_pixel_font_data.c%%'' --- making sure to remove the redundant#include "ucg.h" - Add an ''%%extern%%'' entry for the above variable to ''%%src/clib/ucg.h%%''