Improving fonts

I have been working on the code to have bigger fonts, because according to me the fonts work only when they at maximum 8 bits wide.
The hack will be in file MatrixFont.cpp
at function getBitmapFontPixelAtXY, the line:

if (font->Bitmap[(location * font->Height) + y] & (0x80 >> x))

replace with

if (font->Bitmap[(location * font->Height * ((font->Width + 4) / 8)) + (y*((font->Width + 4) / 8)) + (x >> 3)] & (0x80 >> (x&7)))

This will take into account the width of the font, so if you have a font that is more than 8bits wide will work. At this time this work only for the backgroundLayer. Iā€™m still working for the others layers.
I also add a font function to provide a Bitmap font directly on Layer_Background.h

void setBitmapFont(bitmap_font *newFont);

in Layer_Background_Impl.h add:

template <typename RGB, unsigned int optionFlags>
 void SMLayerBackground<RGB, optionFlags>::setBitmapFont(bitmap_font *newFont) {
     font = (bitmap_font *)newFont;
 }

So if you have your own font you could call usign the function like this:

backgroundLayer.setBitmapFont((bitmap_font *)&myOwnFont);

Example of a big font

// Created from bdf2c Version 3, (c) 2009, 2010 by Lutz Sammer
//  License AGPLv3: GNU Affero General Public License version 3

#include "MatrixFontCommon.h"

static const unsigned char __calibri21x28b_bitmap__[] = {
//  48 $30 '0030'
//  width 22, bbx 2, bby 0, bbw 19, bbh 28
  _______X,XXXXXXX_,________,
  ______XX,XXXXXXXX,X_______,
  _____XXX,XXXXXXXX,XX______,
  ____XXXX,X_____XX,XXX_____,
  ___XXXX_,_______X,XXX_____,
  ___XXXX_,________,XXXX____,
  ___XXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,_XXX____,
  __XXXX__,________,_XXXX___,
  __XXX___,________,_XXXX___,
  __XXX___,________,_XXXX___,
  __XXX___,________,_XXXX___,
  __XXX___,________,_XXXX___,
  __XXX___,________,_XXXX___,
  __XXX___,________,_XXXX___,
  __XXX___,________,_XXXX___,
  __XXX___,________,_XXXX___,
  __XXXX__,________,_XXXX___,
  __XXXX__,________,_XXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  ___XXXX_,________,XXXX____,
  ___XXXX_,_______X,XXX_____,
  ___XXXXX,______XX,XXX_____,
  ____XXXX,XXXXXXXX,XX______,
  _____XXX,XXXXXXXX,X_______,
  _______X,XXXXXXX_,________,
//  49 $31 '0031'
//  width 22, bbx 4, bby 0, bbw 16, bbh 28
  ________,__XXXX__,________,
  ________,_XXXXX__,________,
  _______X,XXXXXX__,________,
  ______XX,XXXXXX__,________,
  ____XXXX,X_XXXX__,________,
  ____XXXX,__XXXX__,________,
  ____XX__,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ____XXXX,XXXXXXXX,XXXX____,
  ____XXXX,XXXXXXXX,XXXX____,
  ____XXXX,XXXXXXXX,XXXX____,
//  50 $32 '0032'
//  width 22, bbx 2, bby 0, bbw 18, bbh 28
  _______X,XXXXXX__,________,
  ____XXXX,XXXXXXXX,________,
  ___XXXXX,XXXXXXXX,X_______,
  ___XXXX_,____XXXX,XX______,
  ___XX___,_____XXX,XX______,
  ________,______XX,XX______,
  ________,______XX,XXX_____,
  ________,______XX,XXX_____,
  ________,______XX,XXX_____,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
  ________,____XXXX,________,
  ________,___XXXX_,________,
  ________,__XXXXX_,________,
  ________,_XXXXX__,________,
  ________,_XXXX___,________,
  ________,XXXX____,________,
  _______X,XXX_____,________,
  ______XX,XX______,________,
  _____XXX,X_______,________,
  ____XXXX,________,________,
  ___XXXX_,________,________,
  __XXXXXX,XXXXXXXX,XXXX____,
  __XXXXXX,XXXXXXXX,XXXX____,
  ___XXXXX,XXXXXXXX,XXXX____,
//  51 $33 '0033'
//  width 22, bbx 2, bby 0, bbw 18, bbh 28
  ______XX,XXXXXX__,________,
  ____XXXX,XXXXXXXX,________,
  ___XXXXX,XXXXXXXX,X_______,
  ___XXXX_,____XXXX,XX______,
  ___XX___,______XX,XX______,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,_____XXX,X_______,
  ________,____XXXX,X_______,
  _____XXX,XXXXXXX_,________,
  _____XXX,XXXXX___,________,
  _____XXX,XXXXXXXX,________,
  ________,___XXXXX,XX______,
  ________,_____XXX,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXXX____,
  ________,_______X,XXXX____,
  ________,_______X,XXXX____,
  ________,_______X,XXX_____,
  __X_____,______XX,XXX_____,
  __XXXX__,_____XXX,XX______,
  __XXXXXX,XXXXXXXX,XX______,
  ___XXXXX,XXXXXXXX,X_______,
  _____XXX,XXXXXXX_,________,
//  52 $34 '0034'
//  width 22, bbx 1, bby 0, bbw 20, bbh 28
  ________,____XXXX,X_______,
  ________,___XXXXX,X_______,
  ________,___XXXXX,X_______,
  ________,__XXXXXX,X_______,
  ________,_XXXXXXX,X_______,
  ________,_XXX_XXX,X_______,
  ________,XXXX_XXX,X_______,
  ________,XXX__XXX,X_______,
  _______X,XX___XXX,X_______,
  ______XX,XX___XXX,X_______,
  ______XX,X____XXX,X_______,
  _____XXX,X____XXX,X_______,
  _____XXX,_____XXX,X_______,
  ____XXX_,_____XXX,X_______,
  ___XXXX_,_____XXX,X_______,
  ___XXX__,_____XXX,X_______,
  __XXXX__,_____XXX,X_______,
  __XXX___,_____XXX,X_______,
  _XXX____,_____XXX,X_______,
  _XXXXXXX,XXXXXXXX,XXXXX___,
  _XXXXXXX,XXXXXXXX,XXXXX___,
  __XXXXXX,XXXXXXXX,XXXX____,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
  ________,______XX,X_______,
//  53 $35 '0035'
//  width 22, bbx 2, bby 0, bbw 18, bbh 28
  ____XXXX,XXXXXXXX,XX______,
  ____XXXX,XXXXXXXX,XX______,
  ____XXXX,XXXXXXXX,XX______,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXXX,XXXXXX__,________,
  ____XXXX,XXXXXXXX,________,
  ____XXXX,XXXXXXXX,XX______,
  ________,____XXXX,XX______,
  ________,______XX,XXX_____,
  ________,_______X,XXX_____,
  ________,________,XXXX____,
  ________,________,XXXX____,
  ________,________,XXXX____,
  ________,________,XXXX____,
  ________,________,XXX_____,
  ________,_______X,XXX_____,
  ________,______XX,XXX_____,
  __XXX___,_____XXX,XX______,
  __XXXXXX,XXXXXXXX,X_______,
  __XXXXXX,XXXXXXXX,________,
  ____XXXX,XXXXXX__,________,
//  54 $36 '0036'
//  width 22, bbx 2, bby 0, bbw 19, bbh 28
  ________,__XXXXXX,XX______,
  ________,XXXXXXXX,XXX_____,
  ______XX,XXXXXXXX,XXX_____,
  _____XXX,XX______,__X_____,
  _____XXX,X_______,________,
  ____XXXX,________,________,
  ____XXX_,________,________,
  ___XXXX_,________,________,
  ___XXXX_,________,________,
  ___XXX__,________,________,
  ___XXX__,________,________,
  __XXXX__,_XXXXXXX,________,
  __XXXXXX,XXXXXXXX,XX______,
  __XXXXXX,XXXXXXXX,XXX_____,
  __XXXXXX,_______X,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,_XXX____,
  __XXXX__,________,_XXXX___,
  ___XXX__,________,_XXXX___,
  ___XXX__,________,_XXX____,
  ___XXXX_,________,_XXX____,
  ___XXXX_,________,XXXX____,
  ___XXXXX,________,XXXX____,
  ____XXXX,_______X,XXX_____,
  _____XXX,XXXXXXXX,XX______,
  _____XXX,XXXXXXXX,X_______,
  _______X,XXXXXXXX,________,
//  55 $37 '0037'
//  width 22, bbx 2, bby 0, bbw 18, bbh 28
  __XXXXXX,XXXXXXXX,XXXX____,
  __XXXXXX,XXXXXXXX,XXXX____,
  __XXXXXX,XXXXXXXX,XXXX____,
  ________,________,XXXX____,
  ________,________,XXXX____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,______XX,X_______,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
  ________,____XXXX,________,
  ________,____XXXX,________,
  ________,___XXXX_,________,
  ________,___XXXX_,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,_XXXX___,________,
  ________,_XXXX___,________,
  ________,XXXX____,________,
  ________,XXXX____,________,
  _______X,XXX_____,________,
  _______X,XXX_____,________,
  ______XX,XXX_____,________,
  ______XX,XX______,________,
  ______XX,XX______,________,
//  56 $38 '0038'
//  width 22, bbx 2, bby 0, bbw 18, bbh 28
  _______X,XXXXXXXX,________,
  _____XXX,XXXXXXXX,X_______,
  ____XXXX,XXXXXXXX,XX______,
  ___XXXXX,______XX,XXX_____,
  ___XXXX_,_______X,XXX_____,
  ___XXXX_,________,XXX_____,
  ___XXX__,________,XXXX____,
  ___XXX__,________,XXX_____,
  ___XXXX_,_______X,XXX_____,
  ___XXXXX,_______X,XXX_____,
  ____XXXX,X_____XX,XX______,
  _____XXX,XX__XXXX,X_______,
  ______XX,XXXXXXXX,________,
  _______X,XXXXXX__,________,
  _______X,XXXXXXXX,________,
  _____XXX,XX_XXXXX,XX______,
  ____XXXX,X____XXX,XXX_____,
  ___XXXX_,_______X,XXX_____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,_XXX____,
  __XXXX__,________,_XXX____,
  __XXXX__,________,_XXX____,
  __XXXX__,________,XXXX____,
  __XXXXX_,_______X,XXXX____,
  ___XXXXX,XXXXXXXX,XXX_____,
  ____XXXX,XXXXXXXX,XX______,
  ______XX,XXXXXXXX,________,
//  57 $39 '0039'
//  width 22, bbx 2, bby 0, bbw 18, bbh 28
  _______X,XXXXXXX_,________,
  _____XXX,XXXXXXXX,X_______,
  ____XXXX,XXXXXXXX,X_______,
  ___XXXXX,______XX,XX______,
  ___XXXX_,_______X,XXX_____,
  __XXXX__,_______X,XXX_____,
  __XXXX__,________,XXX_____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  ___XXXX_,_______X,XXXX____,
  ___XXXXX,XXXXXXXX,XXXX____,
  ____XXXX,XXXXXXXX,XXXX____,
  ______XX,XXXXXX__,XXXX____,
  ________,________,XXXX____,
  ________,________,XXXX____,
  ________,________,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ___X____,____XXXX,X_______,
  ___XXXXX,XXXXXXXX,________,
  ___XXXXX,XXXXXXX_,________,
  ___XXXXX,XXXXX___,________,
};

  /// character width for each encoding
static const unsigned char __calibri21x28b_widths__[] = {
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
  22,
};

  /// character encoding for each index entry
static const unsigned short __calibri21x28b_index__[] = {
  48,
  49,
  50,
  51,
  52,
  53,
  54,
  55,
  56,
  57,
};

  /// bitmap font structure
const struct bitmap_font calibri21x28b = {
  .Width = 21, .Height = 28,
  .Chars = 10,
  .Widths = __calibri21x28b_widths__,
  .Index = __calibri21x28b_index__,
  .Bitmap = __calibri21x28b_bitmap__,
};

To use the font the call will be

backgroundLayer.setBitmapFont((bitmap_font *)&calibri21x28b);

Finally this is the result on 4 pannels, 32x16, total => 64x32:


Well thats all at this time, thanks again for the code.
Best regards from Chile
Ɓlvaro Monares G.

2 Likes

Great work @amonares! Iā€™ll make sure this gets in the next major release of the SmartMatrix Library. If you can do a Pull Request on Github for the changes that would be best, but if not, Iā€™ll just take your changes from here and add them to the library.

I linked to this post from Github Issues: Font Improvements Ā· Issue #30 Ā· pixelmatix/SmartMatrix Ā· GitHub

Louis, I will do a Pull Request, after I improve the scroll font and do a lot of test :grinning:
But so far I have do bigger fonts in backgroundLayer and in scrollLayer, the idea now is to do test that include different font width, top offset (positive/negative) and left offset (positive/negative).

Best regards
Ɓlvaro Monares G.

1 Like

Hi there.

I have tried to implement this in my library but I canā€™t seem to get it to work. Do you have a pull request for this yet?

Thanks!

Hi,

I understand that this is an old topic, but is there any other way to increase the font size? I also cannot seem to get this to work.

Thank you!

I made it work by following the instructions:

1

Iā€™ve replaced the line from

if (font->Bitmap[(location * font->Height) + y] & (0x80 >> x))

to

if (font->Bitmap[(location * font->Height * ((font->Width + 4) / 8)) + (y*((font->Width + 4) / 8)) + (x >> 3)] & (0x80 >> (x&7)))

2

Iā€™ve added void setBitmapFont(bitmap_font *newFont); to Layer_Background.h

3

Added

template <typename RGB, unsigned int optionFlags>
 void SMLayerBackground<RGB, optionFlags>::setBitmapFont(bitmap_font *newFont) {
     font = (bitmap_font *)newFont;
 }

to Layer_Background_Impl.h

4

Iā€™ve made a calibri21x28b.c file inside src/ and copied all of the example font.

5

Iā€™ve added #include <calibri21x28b.c> to my code.

6

Iā€™ve called it using backgroundLayer.setBitmapFont((bitmap_font *)&calibri21x28b);

And it works just fine for now. I will test it more.

Hi Thanks @GeorgeFlorian for this write up on changing fonts. It worked for me also. But i need to display string.

@amonares is there a c file of calibri with characters also included ?

@karakbot

These settings will enable you a Background Layer and a Scrolling layer.

SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
SMARTMATRIX_ALLOCATE_SCROLLING_LAYER(scrollingLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kScrollingLayerOptions);

Both have the possibility to print.

For BackgroundLayer you will want to use:

drawString(int16_t x, int16_t y, const RGB& charColor, const char text[])

If you have a scrollingLayer you may use:

start(const char inputtext[], int numScrolls)

Examples:

String IP = WiFi.localIP().toString();
backgroundLayer.drawString(0,1,CYAN,(char*)IP.c_str());

scrollingLayer.start("Error 1 - Restarting in 5 sec!",1);`

I ended up using @marcmerlin 's SmartMatrix_GFX. It gives you the possibility to use Adafruit_GFXā€™s methods and fonts.

And here is a piece of advice: look out for the color format if you decide to switch to SmartMatrix_GFX.

@GeorgeFlorian Thanks for the walk throughā€¦Theoretically the calibri file doesnt have characters mapped right ? Or am i missing a file with characters mapped as well ?

I will definitely look into gfx library in a while, just need a quick fix for now for a demo.

Thanks in advanceā€¦

@karakbot
You are right, the calibri21x28b.c file was made from @amonares original post.

Here is a smaller font: Font_calibri20x26.c file that I modified and used:

// Created from bdf2c Version 3, (c) 2009, 2010 by Lutz Sammer
//  License AGPLv3: GNU Affero General Public License version 3

#include "MatrixFontCommon.h"

static const unsigned char __calibri20x26_bitmap__[] = {
//  48 $30 '0030'
//  width 20, bbx 2, bby 0, bbw 18, bbh 26
  ________,XXXXXX__,________,
  _______X,XXXXXXX_,________,
  ______XX,XXXXXXXX,________,
  _____XXX,______XX,X_______,
  ____XXX_,_______X,XX______,
  ___XXX__,________,XXX_____,
  ___XXX__,________,XXX_____,
  __XXXX__,________,XXXX____,
  __XXX___,________,_XXX____,
  __XXX___,________,_XXX____,
  __XXX___,________,_XXX____,
  __XXX___,________,_XXX____,
  __XXX___,________,_XXX____,
  __XXX___,________,_XXX____,
  __XXX___,________,_XXX____,
  __XXX___,________,_XXX____,
  __XXX___,________,_XXX____,
  __XXX___,________,_XXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  ___XXX__,________,XXX_____,
  ____XXX_,_______X,XX______,
  _____XXX,______XX,X_______,
  ______XX,XXXXXXXX,________,
  _______X,XXXXXXX_,________,
  ________,XXXXXX__,________,
//  49 $31 '0031'
//  width 20, bbx 4, bby 0, bbw 16, bbh 26
  ________,__XXXX__,________,
  ________,_XXXXX__,________,
  _______X,XXXXXX__,________,
  ______XX,XXXXXX__,________,
  ____XXXX,X_XXXX__,________,
  ____XXXX,__XXXX__,________,
  ____XX__,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ____XXXX,XXXXXXXX,XXXX____,
  ____XXXX,XXXXXXXX,XXXX____,
  ____XXXX,XXXXXXXX,XXXX____,
//  50 $32 '0032'
//  width 20, bbx 3, bby 0, bbw 17, bbh 26
  ________,XXXXXXX_,________,
  _____XXX,XXXXXXXX,X_______,
  ____XXXX,XXXXXXXX,XX______,
  ____XXXX,_____XXX,XXX_____,
  ____XX__,______XX,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,______XX,XX______,
  ________,_____XXX,X_______,
  ________,____XXXX,________,
  ________,___XXXX_,________,
  ________,__XXXX__,________,
  ________,_XXXX___,________,
  ________,XXXX____,________,
  _______X,XXX_____,________,
  ______XX,XX______,________,
  _____XXX,X_______,________,
  ____XXXX,________,________,
  ___XXXX_,________,________,
  ___XXXX_,________,________,
  ___XXXXX,XXXXXXXX,XXXX____,
  ___XXXXX,XXXXXXXX,XXXX____,
  ___XXXXX,XXXXXXXX,XXXX____,
//  51 $33 '0033'
//  width 20, bbx 2, bby 0, bbw 18, bbh 26
  ______XX,XXXXXX__,________,
  ____XXXX,XXXXXXXX,________,
  ___XXXXX,XXXXXXXX,X_______,
  ___XXXX_,____XXXX,XX______,
  ___XX___,______XX,XX______,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,_____XXX,X_______,
  ________,____XXXX,X_______,
  _______X,XXXXXXX_,________,
  _______X,XXXXX___,________,
  _______X,XXXXXXXX,________,
  ________,___XXXXX,XX______,
  ________,_____XXX,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  __X_____,______XX,XXX_____,
  __XXXX__,_____XXX,XXX_____,
  __XXXXXX,XXXXXXXX,XX______,
  ___XXXXX,XXXXXXXX,X_______,
  _____XXX,XXXXXXX_,________,
//  52 $34 '0034'
//  width 20, bbx 1, bby 0, bbw 20, bbh 26
  ________,____XXXX,X_______,
  ________,___XXXXX,X_______,
  ________,__XXXXXX,X_______,
  ________,_XXXXXXX,X_______,
  ________,_XXX_XXX,X_______,
  ________,XXXX_XXX,X_______,
  ________,XXX__XXX,X_______,
  _______X,XX___XXX,X_______,
  ______XX,XX___XXX,X_______,
  ______XX,X____XXX,X_______,
  _____XXX,X____XXX,X_______,
  _____XXX,_____XXX,X_______,
  ____XXX_,_____XXX,X_______,
  ___XXXX_,_____XXX,X_______,
  ___XXX__,_____XXX,X_______,
  __XXXX__,_____XXX,X_______,
  __XXX___,_____XXX,X_______,
  _XXX____,_____XXX,X_______,
  _XXXXXXX,XXXXXXXX,XXXX____,
  _XXXXXXX,XXXXXXXX,XXXX____,
  __XXXXXX,XXXXXXXX,XXXX____,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
  ________,_____XXX,X_______,
//  53 $35 '0035'
//  width 20, bbx 2, bby 0, bbw 18, bbh 26
  ____XXXX,XXXXXXXX,XX______,
  ____XXXX,XXXXXXXX,XX______,
  ____XXXX,XXXXXXXX,XX______,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXX_,________,________,
  ____XXXX,XXXXXX__,________,
  ____XXXX,XXXXXXXX,________,
  ____XXXX,XXXXXXXX,XX______,
  ________,____XXXX,XX______,
  ________,______XX,XXX_____,
  ________,_______X,XXX_____,
  ________,________,XXXX____,
  ________,________,XXXX____,
  ________,________,XXXX____,
  ________,________,XXX_____,
  ________,_______X,XXX_____,
  ________,______XX,XXX_____,
  __XXX___,_____XXX,XX______,
  __XXXXXX,XXXXXXXX,X_______,
  __XXXXXX,XXXXXXXX,________,
  ____XXXX,XXXXXX__,________,
//  54 $36 '0036'
//  width 20, bbx 2, bby 0, bbw 19, bbh 26
  ________,__XXXXXX,XX______,
  ________,XXXXXXXX,XXX_____,
  ______XX,XXXXXXXX,XXX_____,
  _____XXX,XX______,__X_____,
  _____XXX,X_______,________,
  ____XXXX,________,________,
  ____XXX_,________,________,
  ___XXXX_,________,________,
  __XXXXX_,________,________,
  __XXXX__,________,________,
  __XXXX__,________,________,
  __XXXX__,_XXXXXXX,________,
  __XXXXXX,XXXXXXXX,XX______,
  __XXXXXX,XXXXXXXX,XXX_____,
  __XXXXXX,_______X,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,_XXX____,
  __XXXX__,________,_XXX____,
  __XXXXX_,________,_XXX____,
  __XXXXX_,________,XXXX____,
  ___XXXXX,________,XXXX____,
  ____XXXX,_______X,XXX_____,
  _____XXX,XXXXXXXX,XX______,
  ______XX,XXXXXXXX,X_______,
  _______X,XXXXXXXX,________,
//  55 $37 '0037'
//  width 20, bbx 2, bby 0, bbw 18, bbh 26
  __XXXXXX,XXXXXXXX,XXXX____,
  __XXXXXX,XXXXXXXX,XXXX____,
  __XXXXXX,XXXXXXXX,XXXX____,
  ________,________,XXXX____,
  ________,________,XXXX____,
  ________,_______X,XXX_____,
  ________,_______X,XXX_____,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ________,_____XXX,X_______,
  ________,____XXXX,________,
  ________,____XXXX,________,
  ________,___XXXX_,________,
  ________,___XXXX_,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,__XXXX__,________,
  ________,_XXXX___,________,
  ________,_XXXX___,________,
  ________,XXXX____,________,
  ________,XXXX____,________,
  _______X,XXX_____,________,
  _______X,XXX_____,________,
  ______XX,XXX_____,________,
  ______XX,XX______,________,
  ______XX,XX______,________,
//  56 $38 '0038'
//  width 20, bbx 2, bby 0, bbw 18, bbh 26
  _______X,XXXXXXXX,________,
  _____XXX,XXXXXXXX,X_______,
  ____XXXX,XXXXXXXX,XX______,
  ___XXXXX,______XX,XXX_____,
  ___XXXX_,_______X,XXX_____,
  ___XXXX_,________,XXX_____,
  ___XXX__,________,XXX_____,
  ___XXXX_,_______X,XXX_____,
  ___XXXXX,_______X,XXX_____,
  ____XXXX,X_____XX,XX______,
  _____XXX,XX__XXXX,X_______,
  ______XX,XXXXXXXX,________,
  _______X,XXXXXX__,________,
  _______X,XXXXXXXX,________,
  _____XXX,XX_XXXXX,XX______,
  ____XXXX,X____XXX,XXX_____,
  ___XXXX_,_______X,XXX_____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,_XXX____,
  __XXXX__,________,_XXX____,
  __XXXX__,________,XXXX____,
  __XXXXX_,_______X,XXXX____,
  ___XXXXX,XXXXXXXX,XXX_____,
  ____XXXX,XXXXXXXX,XX______,
  ______XX,XXXXXXXX,________,
//  57 $39 '0039'
//  width 20, bbx 2, bby 0, bbw 18, bbh 26
  _______X,XXXXXXX_,________,
  _____XXX,XXXXXXXX,X_______,
  ____XXXX,XXXXXXXX,X_______,
  ___XXXXX,______XX,XX______,
  ___XXXX_,_______X,XXX_____,
  __XXXX__,_______X,XXX_____,
  __XXXX__,________,XXX_____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  __XXXX__,________,XXXX____,
  ___XXXX_,_______X,XXXX____,
  ___XXXXX,XXXXXXXX,XXXX____,
  ____XXXX,XXXXXXXX,XXXX____,
  ______XX,XXXXXX__,XXXX____,
  ________,________,XXXX____,
  ________,________,XXXX____,
  ________,________,XXX_____,
  ________,_______X,XXX_____,
  ________,______XX,XX______,
  ________,______XX,XX______,
  ___X____,____XXXX,X_______,
  ___XXXXX,XXXXXXXX,________,
  ___XXXXX,XXXXXXX_,________,
  ___XXXXX,XXXXX___,________,
};

  /// character width for each encoding
static const unsigned char __calibri20x26_widths__[] = {
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
  19,
};

  /// character encoding for each index entry
static const unsigned short __ccalibri20x26_index__[] = {
  48,
  49,
  50,
  51,
  52,
  53,
  54,
  55,
  56,
  57,
};

  /// bitmap font structure
const struct bitmap_font calibri20x26 = {
  .Width = 20, .Height = 26,
  .Chars = 10,
  .Widths = __calibri20x26_widths__,
  .Index = __ccalibri20x26_index__,
  .Bitmap = __calibri20x26_bitmap__,
};

I think you can go 1 pixel smaller, but I am not sure. I believe that after youā€™ve made the font smaller past a certain value it wonā€™t work anymore.

Iā€™ve used it by calling this method:

backgroundLayer.setBitmapFont((bitmap_font *)&calibri20x26);

Thanks @GeorgeFlorian. I had tried this and it worked to certain extent.

My setup is with teensy 3.6 and smartmatrix shield v4, 64x192 panel. Is there a guide for teensy with @marcmerlinā€™s smartmatrix_gfx ?? Most of them i saw with esp32.

Thanks a lot in advance.

I doubt youā€™ll be able to run that big without running out of RAM

It works the same on both CPUs, it doesnā€™t care :slight_smile:

I am going to port gfx to rPi which can run bigger panel strings but for now, the resolution you want might work or not depending on the panel type you use

@marcmerlin Tried the demo code, its working for 128x64ā€¦is there any quick work around to run 192 x 64 ? I only need to display big fonts in the display. nothing else for now.

Thanks for the replies.

Iā€™m assuming you meant to say 128x64 worked and 192x64 crashed (due to lack of RAM).
First thing you need to do is post your code on github or gist.github.com so that we can see how you init your basic example (I hope you tried a very simple hello world that uses as little RAM as possible)

I got 128x128 working on teensy once by using ABCDE panels that seem to need less RAM than ABCD panels, but otherwise I donā€™t know the SmartMatrix backend code well enough.
@Louis may be able to help on maybe removing rendering layers to save more RAM.

One thing Iā€™ve done is if 128x96 crashes, I try 128x70 128x80 and 128x90 to see where it crashes. It will look wrong in those odd sizes, but it gives me an idea of how close I am to the limit and how hopeless it is, or not :slight_smile:

@marcmerlin Thanks. I did tried with a basic code and the one in your matrix gfx demo code. But i will retry with reduced sizes and see, if it can be done by optimizing ram issues. I am using ABCDE type panels with 64x64 px.

In addition to this, Iā€™ve implemented some rough font scaling on the background which is similar to the setFontSize function in the Adafruit GFX libraries. I did go down the path of implementing it as a separate function to set font size, but ran into issues with the const bitmap_font struct, so decided to have it just as a separate overload to the printString/Char calls so as to not make too many changes (part of the reason why itā€™s rough as there are more extensive changes required to make scaling much better).

Here the code from Layer_Backgroun_Impl.h:

template <typename RGB, unsigned int optionFlags>
void SMLayerBackground<RGB, optionFlags>::setFont(fontChoices newFont) {
    font = (bitmap_font *)fontLookup(newFont);
}

template <typename RGB, unsigned int optionFlags>
void SMLayerBackground<RGB, optionFlags>::drawChar(int16_t x, int16_t y, const RGB& charColor, char character, int xScale, int yScale) {
    int xcnt, ycnt;

    int xPos = 0;
    int yPos = 0;
    
    if (xScale <= 0 || xScale > 4) xScale = 1;
    if (yScale <= 0 || yScale > 4) yScale = 1;
    
    for (ycnt = 0; ycnt < font->Height; ycnt++) {
        for (xcnt = 0; xcnt < font->Width; xcnt++) {
            if (getBitmapFontPixelAtXY(character, xcnt, ycnt, font)) {
                xPos = (x + xcnt) * xScale;
                yPos = (y + ycnt) * yScale;
                
                for (int i = 0; i < xScale; i++) {
                    for (int j = 0; j < yScale; j++) {
                        drawPixel(xPos + i, yPos + j, charColor);
                    }
                }
            }
        }
    }
}

template <typename RGB, unsigned int optionFlags>
void SMLayerBackground<RGB, optionFlags>::drawChar(int16_t x, int16_t y, const RGB& charColor, char character) {
    drawChar(x, y, charColor, character, 1, 1);
}

template <typename RGB, unsigned int optionFlags>
void SMLayerBackground<RGB, optionFlags>::drawString(int16_t x, int16_t y, const RGB& charColor, const char text[], int xScale, int yScale) {
    int xcnt, ycnt, offset = 0;
    char character;

    int xPos = 0;
    int yPos = 0;
    
    if (xScale <= 0 || xScale > 4) xScale = 1;
    if (yScale <= 0 || yScale > 4) yScale = 1;
    
    
    while ((character = text[offset++]) != '\0') {
        for (ycnt = 0; ycnt < font->Height; ycnt++) {
            for (xcnt = 0; xcnt < font->Width; xcnt++) {
                if (getBitmapFontPixelAtXY(character, xcnt, ycnt, font)) {                    
                    xPos = (x + xcnt) * xScale;
                    yPos = (y + ycnt) * yScale;
                    
                    for (int i = 0; i < xScale; i++) {
                        for (int j = 0; j < yScale; j++){
                            drawPixel(xPos + i, yPos + j, charColor);
                        }
                    }
                }
            }
        }
        x += font->Width;
    }
}

template <typename RGB, unsigned int optionFlags>
void SMLayerBackground<RGB, optionFlags>::drawString(int16_t x, int16_t y, const RGB& charColor, const char text[]) {
    drawString(x, y, charColor, text, 1, 1);
}

// draw string while clearing background
template <typename RGB, unsigned int optionFlags>
void SMLayerBackground<RGB, optionFlags>::drawString(int16_t x, int16_t y, const RGB& charColor, const RGB& backColor, const char text[], int xScale, int yScale) {
    int xcnt, ycnt, offset = 0;
    char character;
    
    int xPos = 0;
    int yPos = 0;
    
    if (xScale <= 0 || xScale > 4) xScale = 1;
    if (yScale <= 0 || yScale > 4) yScale = 1;

    while ((character = text[offset++]) != '\0') {
        for (ycnt = 0; ycnt < font->Height; ycnt++) {
            for (xcnt = 0; xcnt < font->Width; xcnt++) {
                if (getBitmapFontPixelAtXY(character, xcnt, ycnt, font)) {
                    xPos = (x + xcnt) * xScale;
                    yPos = (y + ycnt) * yScale;
                    
                    for (int i = 0; i < xScale; i++) {
                        for (int j = 0; j < yScale; j++) {
                            drawPixel(xPos + i, yPos + j, charColor);
                        }
                    }
                } else {
                    xPos = (x + xcnt) * xScale;
                    yPos = (y + ycnt) * yScale;
                    
                    for (int i = 0; i < xScale; i++) {
                        for (int j = 0; j < yScale; j++) {
                            drawPixel(xPos + i, yPos + j, backColor);
                        }
                    }
                }
            }
        }
        x += font->Width;
    }
}

And add the appropriate defines in Layer_Background.h:

void drawChar(int16_t x, int16_t y, const RGB& charColor, char character, int xScale, int yScale);
void drawString(int16_t x, int16_t y, const RGB& charColor, const char text[], int xScale, int yScale);
void drawString(int16_t x, int16_t y, const RGB& charColor, const RGB& backColor, const char text[], int xScale, int yScale);

Now as for implementing this in the layer and scrolling, they will require some more changes to the way fonts are handled, so Iā€™m not going to touch this. But hopefully someone finds this useful if they stumble across it.

Forgive me for my asking, but given that you can run both Adafruit::GFX and LEDMatrix fonts on top of SmartMatrix already, are there benefits to using the font code in SmartMatrix since it doesnā€™t support the same amount of fonts out of the box?

To be honest I couldnā€™t get the SmartMatrix_GFX library to work (and havenā€™t heard of LEDMatrix fonts) and just needed font scaling (was just quicker to mod than mess about trying to get things to work). The Adafruit font availability isnā€™t an issue when just scripting up font generation (which is needed anyway for the Adafruit libs if the font you want isnā€™t there).

Plus if Iā€™m not mistaken, no double buffering.

gotcha. sorry that SmartMatrix_GFX didnā€™t work for you. If you ever need it for another reason, ask for help :slight_smile:
(and no, no double buffering, it writes directly in the SmartMatrix buffer)