For our particular application, we needed to be able to easily switch between the standard FreeMono18pt font and our new SymbolMono18pt font. We decided at first that we would use characters 0-31 and write a special draw function that would automatically switch between the symbol font for these first 32 characters and the regular mono font for anything 32 and up. However eventually we had to expand the font beyond the 32 available slots so we picked up again at character 127 and upwards. Our special draw routine properly handles all of this. You could just as easily design a font that uses the usual 32-127 printable ASCII characters if you have some other mechanism for deciding which font to use. Our application also was going to display these characters in a grid for a virtual infrared remote to operate TV, cable, Blu-ray etc. devices. We weren't really planning on printing normal strings using print()
or println()
. You might be able to adapt these methods to use regular print
routines if you need to.
Look at the sample sketch font_test and you will see the following function.
/* * Use this function instead of display.drawChar to draw the symbol or to use * the default font if it's not in the symbol range. */ void drawSymbol(uint16_t x, uint16_t y, uint8_t c, uint16_t color, uint16_t bg, uint8_t Size){ if( (c>=32) && (c<=126) ){ //If it's 33-126 then use standard mono 18 font display.setFont(&FreeMono18pt7b); } else { display.setFont(&SymbolMono18pt7b);//Otherwise use special symbol font if (c>126) { //Remap anything above 126 to be in the range 32 and upwards c-=(127-32); } } display.drawChar(x,y,c,color,bg,Size); }
You can use this function instead of display.drawChar(x,y,c,color,bg,Size)
to display the characters. It will handle switching back and forth between the symbol font and the FreeMono font. Note that when using these style fonts, the background color parameter is ignored as explained in the Adafruit GFX library documentation. For example if you wanted to draw our "heart suit" at location 0, 20 in red at double size you would do…
drawSymbol(0,20, MY_HEART_SUIT,ILI9341_RED,0,2);
Page last edited March 08, 2024
Text editor powered by tinymce.