Go Down

Topic: u8glib custom font (Read 994 times) previous topic - next topic

paulsvang

I like the library u8glib but does anyone know if it's possible to created custom fonts?  I've looked on the internet and couldn't find a how to guide.

olikraus

Ok, there is no guide as such, but a description of the converter:
https://github.com/olikraus/u8glib/wiki/bdf2u8g

U8glib requires a ".bdf" file for the conversion.
".bdf" can be created from true type fonts with several tools (otf2bdf or fontforge) or you can create a bdf file directly with a font editor, for example fony (http://hukka.ncn.fi/?fony)

Oliver

paulsvang

Oliver,

Thanks.  I'll take a look at that.

Paul

paulsvang

#3
Nov 27, 2015, 01:51 am Last Edit: Nov 27, 2015, 02:31 am by paulsvang
Oliver,
I was able to create the font for u8glib but it just doesn't seem right.  I used fony and opened up the font I wanted converted.  then I select export to export to a bdf file.  Next I used the bdf2u8g software to convert it to a u8glib "c" file.  The font I'm converting is  Square Sans Serif 7 font.  This was the output I got which seems too short.
Code: [Select]

/*
  Fontname:
  Copyright:
  Capital A Height: 0, '1' Height: 0
  Calculated Max Values w= 0 h= 0 x= 0 y= 0 dx= 0 dy= 0 ascent= 0 len= 0
  Font Bounding box     w= 0 h= 0 x= 0 y= 0
  Calculated Min Values           x= 0 y= 0 dx= 0 dy= 0
  Pure Font   ascent = 0 descent= 0
  X Font      ascent = 0 descent= 0
  Max Font    ascent = 0 descent= 0
*/
#include "u8g.h"
const u8g_fntpgm_uint8_t SquareSansSerif7[113] U8G_FONT_SECTION("SquareSansSerif7") = {
  0,0,0,0,0,0,0,50,0,82,32,127,0,0,0,0,
  0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  255};


I look forward to your response.

olikraus

Hi

The bdf2u8g version should be this:
https://drive.google.com/folderview?id=0B5b6Dv0wCeCRLWJkYTh2TUlYVDg&usp=sharing

Where are your glyphs in the bdf font? Which commandline options did you use?

Oliver

jonbarril

#5
Feb 02, 2016, 07:53 pm Last Edit: Feb 02, 2016, 08:03 pm by jonbarril
I too am trying to create a custom font.  I have gotten as far as creating the .c font file (see below for the start of it). I am having trouble using it in an .ino that already works with other fonts.

#include "u8g.h"
const u8g_fntpgm_uint8_t u8g_font_bombdrop[1755] U8G_FONT_SECTION("u8g_font_bombdrop") = {
  0,6,8,0,255,5,1,9,2,109,32,255,0,8,255,6,...



The first problem is how to reference "u8g.h".  I tried relative paths in my .ino, like "clib/u8g.h", but the file is not found (seems that Arduino IDE does not play well with subdirs in such matters).  So, I tried copying "clib" as a subdir in my .ino dir, but then the compiler complains that a lot of stuff is doubly defined.

Also, to deal with another compiler complaint I had to add the line...

extern const u8g_fntpgm_uint8_t u8g_font_bombdrop[] U8G_FONT_SECTION("u8g_font_bombdrop");


.... at the top of my .ino file so that I could reference my new font, as in....

u8g.setFont(u8g_font_bombdrop);

So, how best to include "u8g.h" for use in the Arduino IDE with a custom font?


jonbarril

To fill out the picture a bit more, I noticed that u8glib.h includes u8g.h, so I deleted the clib library from my project, added my custom font .c file to the arduino clib subdir (yes, a kludge), added the extern statement to the clib/u8g.h file (an uber kludge) and then referenced my font in the .ino file as I would any other font.  This worked, but is really ugly.

I tried to move the custom font stuff to a project library (subdir where my .ino file is).  Unfortunately this seems to confuse the Arduino IDE: In the custom font .c file if I include "u8g.h" of <u8g.h> the compiler can't find it.  If, instead, I try to include <u8Glib.h>, the compiler finds it but complains about keyword "class" not being found -- seems to get the idea that this is all .cpp.  I tried a few combinations of wrapping the custom font stuff in .cpp, .c, and ,h files but that didn't work.

So, can you suggest a better way to incorporate a custom font such that it is outside of the u8glib dirs and files?

olikraus

I would suggest to just copy the font data into the .ino file itself. Put it somewhere at the top of the .ino file, so that you can refer to the font in the setFont statement. The #include "u8g.h" is not required in this case.

Oliver

eptheca

Hi,
Thank's for the library.
I have got it working, but would also like to make a custom font and icons.
I have made a .bdf of my font, and have downloaded the bdf2u8g_101.exe, but I don't understand how I can use the .exe to convert the .bdf file.
I have read this page https://github.com/olikraus/u8glib/wiki/bdf2u8g, but I still don't get it.
Can someone please enlighten me.

Cheers, Hal

olikraus

Hal,
What exactly does not work? Can you generate the .c file file?

Oliver

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy