Contextual Underlining: Linking Lines to Length of Words

Hello Everybody,

I am designing a Font with a handwritten look and would like to implement underlining that resembles the stroke of the characters.

My idea:

  1. designing glyphs with lines of different length

  2. linking them to the underscore glyph (underscore.s01, underscore.s02 … )

  3. linking the underscores to words with the same length
    A_ → becomes and underlined A
    AA_ → becomes an underlined AA

I thought I could do this with contextual alternates as shown here:

  1. I created glyph classes according to the width of letters:
    → H_Normal, I_Narrow and W_wide

  2. I wrote Code:

sub @H-Normal @H-Normal underscore’ by underscore.ss01;
sub @H-Normal @H-Normal @H-Normal underscore’ by underscore.ss02;
sub @H-Normal @H-Normal @H-Normal @H-Normal underscore’ by underscore.ss03;

Problem
The code is applied from top to bottom, so I just get a result for the first line: an underlines that applies to two letters. When I turn of “Stylistic Set 1”, the second line is applied.

Do you people have an idea?

  1. You will have problems with the width of the glyph.
    1.1. Coordinate value beyond 8191 can cause problems for the Remove Overlap. You can circumvent this by putting Filter:RemoveOverlap;exclude:underline.1,underline.2,... into the parameters, and disabling Remove Overlap in the Export dialog.
    1.2. Some apps will give you rendering headache with wide glyphs, typically beyond 3000 or 4000 units. Make sure you test early. There may be no good solution that works in every app in this case. Make sure you communicate that to your clients.
  2. Unless I am not getting something, I do not see the need for stylistic sets in this case. Just call them underscore.001 etc.
  3. You can try reversing the lines:
sub @H-Normal @H-Normal @H-Normal @H-Normal underscore' by underscore.ss03;
sub @H-Normal @H-Normal @H-Normal underscore' by underscore.ss02;
sub @H-Normal @H-Normal underscore' by underscore.ss01;

Thank you mekkablue! Thats’s awesome :slight_smile:

  1. Reversing the lines was what I was looking for!

  2. I am kind of new to Glyphs and thought, that I had to call the alternative characters “.ss01”

1.2 I decided to make the longest stroke 2950 units wide, do you think thats’s gonna be OK?

1.1 I didn’t quite get this part. Do I have to deal with this Aspect if I don’t use strokes wider than 2950 units? Also I thought I would need the Remove Overlap function in order to merge the glyphs which consist of several parts.

Now, there seems to be a problem with my ligatures.

It seems like the code doesn’t recognize the existence of the glyphs in front of the ligature.

One Screenshot with ligatures turned off, and one turned on:

I tried to solve this with the following code, which didn’t work:

sub [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] underscore’ by underscore.05;
sub [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] underscore’ by underscore.04;
sub [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] underscore’ by underscore.03;
sub [@Uppercase @AllLigatures] [@Uppercase @AllLigatures] underscore’ by underscore.02;
sub [@Uppercase @AllLigatures] underscore’ by underscore.01;

Hey, thanks for your help but I decided to juste create ligatures for the strokes of different length. I know, it’s not that elegant, but I think all this scripting exceeds my basic understanding of Glyphs :sweat_smile:

Instead of this, [@Uppercase @AllLigatures], use the standard class AllLetters (add the class and set it to automatically update). But that works only if all your glyphs have a similar width.