Making framed text in a font file

Hi there :slight_smile:

I’m wondering if it’s somehow possible to create colored blocks behind single words by programming it into an OTF as a feature? it would look like this when applied:

For instance: If you write “hello” in the font it’s displayed as normal, but if you write “[[ hello ]]” the brackets will add the block behind the word corresponding in width to the width of the word.

Is doing something like this at all feasible?

Do you need this to work for all combinations of glyphs or a predefined list of words?

That can be done with a color font.
You need a copy of each glyph that gets a color background. That can become a bit tricky as the glyphs are drawn one after the other, so the background of the “l” might overlap the foreground of the “s”.
Then you write some contextual feature code to switch in the colored glyphs.

How to set up the colors: Creating a Microsoft color font (CPAL/COLR) | Glyphs

1 Like

Not sure it isn’t better done outside the font. You will run into issues with kerning and negative sidebearings. Plus, not all apps support color fonts.

1 Like

It would need to be flexible and possible to apply with many different words. And many different colors for the background should be possible to select. So i can imagine it’d become a rather huge endeavour

Alright, thanks for letting me know

What you’re trying to achieve is definitely too big a scope to make sense in a font file. It’s technically possible, just not feasible (and would be an unnecessarily big file in the end). Best accomplish this in whatever programme you use the font in to set and style text.

In which apps should it work? Browser?