takkaO / OpenFontRender

TTF font render support library for microcomputer.
Other
112 stars 17 forks source link

OpenFontRender.cpp/.h: Bring back transparent background & add backgr… #10

Closed rudcode closed 1 year ago

rudcode commented 1 year ago

Bring back transparent background, add background draw to new optimized drawing method, add fill background

Tested with ESP32 and platformio

Hi @takkaO, I'm not sure about where to put the ascender value, and what do you think about the added fillRect function? Is it okay if I add it?

cc: @Bodmer I use your method in smoothfont for this. Do you have any comment?

Bodmer commented 1 year ago

Italic fonts and others have glyphs that overlap. This complicates background rendering since it is necessary to maintain two cursors, one for the glyph position and one for the last background end coordinate.

Another complication is that the background clear start coordinate may need to start at a different x coordinate after the setCursor has been called. This again is required for glyphs (e.g. italics) that can extend in front of the cursor coordinate.

The carriage return/line feed case also needs consideration.

TFT_eSPI handles these cases in it's smooth font functions.

I would expect any useful graphics library to provide a fill rectangle function so do not anticipate a problem there.

This OpenFontRender library is amazing, it is so useful to have a fully scaleable font. Really appreciated.

takkaO commented 1 year ago

I agree about the need for background drawing. I have recognized that in some code it is more convenient to draw the background as well, even if user accept some performance loss.

I will bring back the transparent background option in the next release.

However, as Bodmer said, we need to fully consider how to render the background.

Bodmer commented 1 year ago

This illustrates the problem with a script style font. The three successive non-overlapping rectangles represent the areas to be filled as each character is drawn. So a character cursor and background clear cursor is needed: fig2

I implemented this approach for "smooth fonts" in TFT_eSPI here so that technique does work: https://github.com/Bodmer/TFT_eSPI/blob/master/Extensions/Smooth_font.cpp#L355-L542

takkaO commented 1 year ago

Thank you @Bodmer .

I will refer to your code. Can you tell me about the fonts you have pasted because I want to use for test my development code.

Bodmer commented 1 year ago

I don't remember which font that was but will try to find it and post information here. Many italic fonts have overlapping glyphs.

takkaO commented 1 year ago

Thank you very much. I would like to implement and verify using the appropriate italic font.

Bodmer commented 1 year ago

The font is Vladimir Script, it should be available on any Windows machine.

takkaO commented 1 year ago

The functions which requested has been implemented in v1.1. Thank you.

rudcode commented 1 year ago

Great, thank you very much. Will test it soon.