0

Adafruit GFX library Font Colors
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit GFX library Font Colors

by xitosman327 on Tue May 03, 2016 3:05 pm

Hello,
I am trying to make a project with an spi lcd monitor and some sensors.
I try to use a font (FreeSans9pt7b in specific) to look a litle nicer, but i notuced that i cant change the background collor of the text anymore!
is that not suported or what?
thanks!

xitosman327
 
Posts: 1
Joined: Tue May 03, 2016 3:00 pm

Re: Adafruit GFX library Font Colors

by pburgess on Thu May 05, 2016 2:36 pm

Background color only works on the built-in (fixed size) font; it's not supported on proportionally-spaced fonts because handling overlapping glyphs opens numerous cans of worms. There's some workarounds you can do though:

- You can use the getTextBounds() function to get the bounding rectangle of a proportionally-spaced text block, then fill this using the fillRect() function and draw new text atop it. This is probably best for Uno- and Mega-class devices.

- If you dig around at the bottom of Adafruit_GFX.cpp, there's a not-yet-widely-documented class called GFXcanvas1, which lets you create offscreen bitmaps in RAM that can be passed to drawBitmap(). Declare a canvas of whatever size, then each time you need it: clear the canvas, print the new text there and call drawBitmap() passing both a foreground and background color. This is probably best for M0/Due/Teensy3-class devices due to the major RAM overhead required.

pburgess
 
Posts: 3882
Joined: Sun Oct 26, 2008 2:29 am

Re: Adafruit GFX library Font Colors

by cwil on Sun Nov 12, 2017 12:56 am

pburgess,
Do you know if you can draw on the canvas using the gfx library text functions or do you have you only able to use your own font graphics management? having watched the gradual development of the GFXcanvas routines, i have been anticipating finally being able to make practical use of the custom fonts without the flicker that makes fast changing text essentially unreadable. After looking through the gfxcanvas routines so far, it's not clear how you could direct the drawChar or write functions to print text on a canvas. Is this facility present somehow, or is that still to come. I don't know what version of adafruit_GFX.cpp I have, but it was recently downloaded.

cwil
 
Posts: 14
Joined: Wed Nov 23, 2016 1:01 pm

Re: Adafruit GFX library Font Colors

by pburgess on Sun Nov 12, 2017 1:05 am

Since they're all subclasses of Adafruit_GFX, the canvas types (1-, 8- and 16-bit) inherit ALL the stuff, including text functions. setFont(), setCursor(), write(), print() and println() all work on canvases (RAM permitting; Uno boards aren't good at this, except maybe a small 1-bit canvas).

pburgess
 
Posts: 3882
Joined: Sun Oct 26, 2008 2:29 am

Please be positive and constructive with your questions and comments.