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: 3890
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: 19
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: 3890
Joined: Sun Oct 26, 2008 2:29 am

Re: Adafruit GFX library Font Colors

by Bitmizer on Sun Nov 19, 2017 9:48 pm

It hurt my brain a bit but I have just managed to overcome the LCD text flicker issue when using custom fonts.
Not by using a RAM expensive canvas but by overriding the Print::write(const uint8_t * buffer, size_t size) method and everything that comes later.
Instead of drawing each character one at a time as done in the original library I took the old CRT raster approach, this means that the whole line of text is printed one pixel line at a time. The beauty of this is that the largest buffer you will need is the length of the longest axis of your screen / 8. So 320 /8 = 40 bytes of RAM, quite tolerable even on a Uno.
Not only that but initial bench testing seem to indicate that it will be 50% faster than a normal print and 2-2.5 times faster than the 'draw box and reprint' flicker option.

Not quite ready for public release but it should only be a few days so if your interested watch this space.

Bitmizer
 
Posts: 1
Joined: Sun Nov 19, 2017 9:35 pm

Re: Adafruit GFX library Font Colors

by cwil on Thu Nov 30, 2017 9:01 pm

pburgess wrote: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).


Wow that actually works great! the 1- on a mo is actually still slow enough that it probably wouldn't work for most applications, but the 16 is decent. A little costly memory wise, but effective. Works well for a couple of high speed text fields.

Clever, bitmizer. Is the draw slow though? The nice thing about the canvas is that the text just kind of pops into existence, as opposed to being visibly drawn.

Any chance 36 and 48 fonts are in the pipeline?

<very quietly> because i can't unix </very quietly>

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

Re: Adafruit GFX library Font Colors

by cwil on Sun Dec 10, 2017 3:25 pm

OK maybe I do.

Actually not that hard. Used cygwin.

Learned a little about unix; Can make fonts.

Good all around.

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

Please be positive and constructive with your questions and comments.


cron