Is letter-spacing possible?

Hello,

Is there a way to adjust the letter-spacing for text / labels / font ? I read thru the TCastleFont documentation but was unable to find anything.

Thanks

Hello, del159!
Indeed, I can’t seem to find the appropriate property. But I could get the effect easily by tweaking TGlyph.AdvanceX.

@michalis I wonder if we can make something like that? It seems like it’ll require some modifications in multiple places of code and there isn’t any reliable way to make a child class for TCastleFont with this feature - would be better to have it in parent class.

It’s not available right now.

Though we could add it. Just like we have TCastleLabel.LineSpacing, that just adds additional space between lines, we could add TCastleLabel.LetterSpacing to add additional space between letters. I see the name “letter spacing” is consistent with CSS, letter-spacing - CSS: Cascading Style Sheets | MDN , so it makes sense.

I see @eugeneloza just pointed out the same :slight_smile: Indeed, deep down it’s just a matter of changing in TCastleFont.Print how the ScreenX is advanced. Right now we do

ScreenX := ScreenX + G.AdvanceX * Scale + Outline * 2

we could add there LetterSpacing trivially, just

ScreenX := ScreenX + G.AdvanceX * Scale + Outline * 2 + LetterSpacing

On TCastleLabel you would expose LetterSpacing property and multiply it by UIScale when passing to fonts. You also should handle it at TCastleBitmapFont .

So it’s mostly a matter of passing LetterSpacing value around everywhere :slight_smile:

It’ll break TCastleFont.TextWidth and thus breaks TCastleLabel.MaxWidth behavior. So the change is getting a bit more extensive.

Agreed, I mean: all these things would have to be enhanced to support LetterSpacing. I guess TextWidth method should get extra parameter const LetterSpacing: Single = 0. The TCastleLabel.MaxWidth should honor the maximum width, taking into account that text is rendered with given LetterSpacing * UIScale.

Thanks for the info and speedy reply !

Sounds like a fair bit of work so its totally understandable if it does not get implemented.

@eugeneloza

how were you able to drill down to TGlyph.AdvanceX ? I tried but couldn’t figure how to get it ?