Go Down

Topic: u8g: reducing footprint (Read 6357 times) previous topic - next topic

cider101

Hi

I have a problem with the footprint of the Ug8Lib. When using the 3 fonts below, my sketch size explodes from 14800bytes to 31200 bytes. This means, that the footprint for the u8g is almost 17kb. Using the only the 10x20 font, the the sketch size is something like 20k - still making a 5k footprint.  I know that those fonts are large/huge - but i need that large digits.


Code: [Select]

struct u8g_fntpgm_uint8_t{};
static u8g_fntpgm_uint8_t *u8g_font_10x20r = NULL;
static u8g_fntpgm_uint8_t *u8g_font_fub49n = NULL;
static u8g_fntpgm_uint8_t *u8g_font_fub30r = NULL;

struct U8GLIB_Stub : {
U8GLIB_Stub() {}
void setFont(const u8g_fntpgm_uint8_t *) {}
void firstPage() {}
bool nextPage() {}
void print(const char*) {}
void setPrintPos(uint8_t, uint8_t) {}
void setFontPosBottom() {}
};


Is there a simple way to reduce the footprint of the u8g lib ? Well, i actualy can live with an "7 segment" font - so as workaround i'm thinking about rendering the digits with the drawing primitves. But if there is an easy way the reduce the footprint - i would obviously would prefere the simple way...

olikraus

The size in bytes of each font is given in the overview pictures. You could also use a smaller font (with lesser size) and the setScale2x2 command.

Oliver

cider101

Hi Oliver

thanks for your quick reply - I was just experimenting with the scale2x2 before reading your answer ;)
Using 25 resp 14 font sizes yields in an sketch-size of about 23k. Still a bit on the heavy size, but for the moment, it's giving me enough free memory to continue. the only "problem" is, that the charackters look a bit "rough" due to the scaling.
Yet another question: How do i "make" my own font ? Is there a tool for it ? I have the use the 14r instead of the 14n because i need to display a capital "N" - but thats the only charakter I need ? Is  there a tool to create my own font ? (i.e. replacing the "+" with an "N")

Btw: keep on your great work!

bperrybap


The size in bytes of each font is given in the overview pictures. You could also use a smaller font (with lesser size) and the setScale2x2 command.

Oliver


Oliver, does u8glib support partial fonts?
That way, if a person only wants something like large numbers, they can trim the font down
to contain only the numbers.
I include a few large fixed width fonts in openGLCD that are only + through :
i.e.
+ , - . / 0 1 2 3 4 5 6 7 8 9 :

Very useful for many applications.
The font format used in openGLCD also supports holes
so you have some characters with no definition.
So not only do you have a range (start and end character in the font),
but you can also have no definition for some characters within the range.

If you have a font definition in front of the data, it is pretty simple
to support partial fonts, but if you don't have a font definition, then it becomes
a much bigger task to add one to all the fonts.

--- bill





olikraus

Hi All

Yes, partial fonts are supported, however one extra byte will be required for each "left out" glyph. For example with the glyphs "a", "b", "d", the start character is "a", end is "d", but one extra byte will be required for the none existing "c".

In U8glib i decided to provide three variants of a font. These variants are:
XXX
XXXr
XXXn

where font XXX contains up to 255 glyphs, XXXr only contains glyphs from 32 to 127 and XXXn only contains some numbers and numerical operators. For example the font "chikita" with variant "r" only has the following glyphs:

The "n" variant looks like this:

The "n" contains sufficient chars to create time and date information: "01.01.2014" or "05:55".

For U8glib fonts are derived from the .bdf file format. A simple tool (bdf2u8g) will convert the .bdf file into the internal format. ".bdf" is a plain text format which has been defined by Adobe long time back (see here http://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format). The .bdf file can be modfied by any text editor.
Here is a part of the 4x6 font:
Code: [Select]
STARTFONT 2.1
FONT -Misc-Fixed-Medium-R-Normal--6-60-75-75-C-40-ISO10646-1
SIZE 6 75 75
FONTBOUNDINGBOX 4 6 0 -1

STARTPROPERTIES 25
FONTNAME_REGISTRY ""
FOUNDRY "Misc"
FAMILY_NAME "Fixed"
WEIGHT_NAME "Medium"
SLANT "R"
SETWIDTH_NAME "Normal"
ADD_STYLE_NAME ""
PIXEL_SIZE 6
POINT_SIZE 60
RESOLUTION_X 75
RESOLUTION_Y 75
SPACING "C"
AVERAGE_WIDTH 40
CHARSET_REGISTRY "ISO10646"
CHARSET_ENCODING "1"
DESTINATION 1
COPYRIGHT "Public domain font.  Share and enjoy."
_XMBDFED_INFO "Edited with xmbdfed 4.3."
CAP_HEIGHT 5
X_HEIGHT 4
WEIGHT 10
QUAD_WIDTH 4
DEFAULT_CHAR 0
FONT_DESCENT 1
FONT_ASCENT 5
ENDPROPERTIES

CHARS 919

STARTCHAR char0
ENCODING 0
SWIDTH 640 0
DWIDTH 4 0
BBX 4 6 0 -1
BITMAP
A0
00
A0
00
A0
00
ENDCHAR

STARTCHAR space
ENCODING 32
SWIDTH 640 0
DWIDTH 4 0
BBX 4 6 0 -1
BITMAP
00
00
00
00
00
00
ENDCHAR

STARTCHAR exclam
ENCODING 33
SWIDTH 640 0
DWIDTH 4 0
BBX 4 6 0 -1
BITMAP
40
40
40
00
40
00
ENDCHAR

STARTCHAR quotedbl
ENCODING 34
SWIDTH 640 0
DWIDTH 4 0
BBX 4 6 0 -1
BITMAP
A0
A0
00
00
00
00
ENDCHAR

A glyph starts with the "STARTCHAR" command and are terminated with the "ENDCHAR" command. With your text editor, simply remove chars by deleting everything between and including STARTCHAR and ENDCHAR. Then rerun bdf2u8g.
There are still some tools (like fontforge) for updating the bdf format itself. This might be more comfortable to delete single glyphs.

Fonts within U8glib are derived either directly from .bdf or are converted from .ttf files.
Those fonts which are derived from .bdf files only, are located here http://code.google.com/p/u8glib/source/browse/#hg%2Ftools%2Ffont%2Fbdf. For the .ttf fonts, the .bdf file is not part of the u8glib repo, but i can attach the bdf file for further modification to this thread (fubXX fonts for example).

There is a small wiki page covering bdf2u8g usage: http://code.google.com/p/u8glib/wiki/bdf2u8g.

One final note on bdf2u8g and the internal font format: bdf2u8g also does a compression on the font data. It is not just a simple collection of fixed sized bitmap images.

Oliver



champro

Hi Oliver,

Thanks for this post, Im trying to save space by trimming some fonts and this made it very easy.  I was hoping you could attach the bdf files for a few fonts that are not in the repo.  I'm looking for the following if possible.

fub17b
lucasfont_alternate


thanks,
Duncan

olikraus

I would sent you the .bdf files via PM, but PM is not active...

Oliver

Go Up