rdkcentral / Lightning

Lightning - The WPE UI Framework for developing Apps and UX
Apache License 2.0
188 stars 108 forks source link

BitmapFont Text Rendering #375

Open itsjamie opened 2 years ago

itsjamie commented 2 years ago

I'm opening an issue to discuss implementation in Lightning for Text Rendering that is based on Bitmap Fonts rather than the usage of Canvas2D and the browser-based text rendering.

Positives of current implementation as I see it:

The negatives:


I'm working on benchmarking an implementation that uses https://github.com/Chlumsky/msdf-atlas-gen to generate an MSDF text atlas. It outputs font information such as kerning pairs and line-height already all in a GL normalized coordinate system.

I was planning that if the implementation had any positive impact on our own project I would raise a PR that added a BitmapFontMSDF shader to Lightning Core. However, it is unlikely that it would support every text styling property above. Which is what I wanted to open for discussion.

My intention was the shader would be written to support the following attributes:

The bonus I've been made aware of is that there are some browsers where the ability to load custom fonts through the document.fonts API is not available, which may offer a path on those browsers.

The benchmark we are doing internally will be focused on testing lines of text that increase by character pairs. So I would include some of the resulting data on the PR to help aid any supporting documentation. My expectation is that there will not be a large reduction in CPU work, but hopefully GCs and memory pressure issues will be reduced.


Is this something that the Lightning team would be interested in accepting into the core?

g-zachar commented 2 years ago

Hi @itsjamie

this is indeed something we were considering for some time now but haven't come up with any POC yet. The main reason was the current implementation of text rendering proved to be good enough.

The points you've raised are valid:

The main advantage of the MSDF approach is that the text retains its quality after scaling up/down and this is our primary point of interest. We're definitely interested in any contributions, especially in the aforementioned areas.

Best regards