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.
Louis, I will do a Pull Request, after I improve the scroll font and do a lot of test
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).
@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 @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.
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.
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
@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).
gotcha. sorry that SmartMatrix_GFX didn’t work for you. If you ever need it for another reason, ask for help
(and no, no double buffering, it writes directly in the SmartMatrix buffer)
(I’m updating old threads mentioning fonts.) SmartMatrix Library 4.0 will have much better support for custom fonts and larger fonts. I’m posting more details here: