Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a ligature's width #91

Open
kris10ansn opened this issue Feb 16, 2021 · 5 comments
Open

Setting a ligature's width #91

kris10ansn opened this issue Feb 16, 2021 · 5 comments
Assignees

Comments

@kris10ansn
Copy link

kris10ansn commented Feb 16, 2021

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
Copy link

@kris10ansn Did you find a solution to this problem?

@kris10ansn
Copy link
Author

I did not unfortunately

@ToxicFrog
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants