ToxicFrog / Ligaturizer

Programming Fonts with Ligatures added (& a script to add them to other fonts)
GNU General Public License v3.0
2.19k stars 112 forks source link

Setting a ligature's width #91

Open kris10ansn opened 3 years ago

kris10ansn commented 3 years ago

I made a ligature that changes ['l', 'a', 'm', 'b', 'd', 'a'] into the actual lambda character λ, and it worked fine. The only problem is that the single λ character takes up the space of the entire "lambda" word and just looks kinda weird. Is it possible to change the width of a single ligature?

I'm using VS Code (VSCodium to be precise) if that makes any difference.

Showcase: image

denispaluca commented 3 years ago

@kris10ansn Did you find a solution to this problem?

kris10ansn commented 3 years ago

I did not unfortunately

ToxicFrog commented 2 years ago

I think that it might be possible to do this, in theory.

Glyph width is characterized by three values: left bearing (how much the pen advances before it starts drawing the glyph), advance (how wide the actual glyph is), and right bearing (how much the pen advances afterwards). Ligatures are nominally drawn overtop the last glyph in the ligature (as you can see in your example); wide ligatures overdraw the earlier columns by using a very wide negative left bearing and positive advance.

Fira's <!--, for example, has a left bearing of about¹ -3em and advance of +4em, so to draw the ligature, it starts at the last -, backtracks three columns to the <, then draws the 4em-wide glyph, leaving the pen sitting just after the last -.

For your λ, I think if you subtracted 5em from the left bearing and left the other metrics intact, you would get a lambda ligature that backtracks 5 columns from the start of the last a and then advances only one column in drawing the glyph, getting the effect you want. I can't guarantee it won't confuse the editor though!

Did you inject the ligature by hand, or did you patch ligaturizer? If the latter, I'd be glad to incorporate it as an "inject arbitrary ligatures" feature, and it might be possible to include bearing correction in that.

¹ in practice there's fractional ems there so the letter spacing looks nice, but I'm rounding here for simplicity's sake

kris10ansn commented 2 years ago

Hey. I'm not very familiar with this codebase. I just wanted to make some ligatures that allowed me to use greek letters in my code. I added this to the ligatures array:

{ 'chars': ['l', 'a', 'm', 'b', 'd', 'a'], 'firacode_ligature_name': 'lambda', }

Is there an easy way to modify the ligature width, or do I have to dive into the code? How so in that case?

ToxicFrog commented 2 years ago

There is not currently any easy way of doing this. It would probably have be done by adding options that control that feature to the table of ligatures, and then respecting those options, if present, in correct_ligature_width; correct_character_width has an example of left and right bearing adjustment, albeit for a different purpose.

This does seem like an interesting feature to have, but I can't make any promises as to when I'll have time to poke at it.