Context-sensitive Substitution

Get help with FontCreator here. Please do not post feature requests or bug reports here.
Post Reply
westdale
Posts: 9
Joined: Wed Mar 29, 2017 6:09 pm
Location: UK

Context-sensitive Substitution

Post by westdale »

Apologies if already answered but I cannot see how to do this. Pointers welcome.

In one of my fonts it uses < f shaped s> . This should become< snake s > at the end of a word or in combination as a double s. That is if followed by space, period,s etc
I am failing to see how to express <fshaped s><period> => <snake s><period> and <fshaped s><space> => <snake s><period> etcetc.
Ordinary ligatures work fine where the target is a single glyph.

thanks
Gareth
Bhikkhu Pesala
Top Typographer
Top Typographer
Posts: 9907
Joined: Tue Oct 29, 2002 5:28 am
Location: Seven Kings, London UK
Contact:

Re: Context-sensitive Substitution

Post by Bhikkhu Pesala »

In the OpenType Designer, click on the first button on the toolbar to Generate and Update OpenType Features. Add Historical Ligatures and Historical Forms. (Click the All checkbox to clear all unwanted features).

Image
My FontsReviews: MainTypeFont CreatorHelpFC15 + MT12.0 @ Win 10 64-bit build 19045.2486
Erwin Denissen
Moderator
Moderator
Posts: 11472
Joined: Fri Oct 04, 2002 12:41 am
Location: Bilthoven, The Netherlands
Contact:

Re: Context-sensitive Substitution

Post by Erwin Denissen »

westdale wrote: Thu Dec 15, 2022 4:45 pm Apologies if already answered but I cannot see how to do this. Pointers welcome.

In one of my fonts it uses < f shaped s> . This should become< snake s > at the end of a word or in combination as a double s. That is if followed by space, period,s etc
I am failing to see how to express <fshaped s><period> => <snake s><period> and <fshaped s><space> => <snake s><period> etcetc.
Ordinary ligatures work fine where the target is a single glyph.

thanks
Gareth
Since OpenType layout features are processed in separate glyph runs, e.g. divided per script, it is not always guaranteed a space character is part of a glyph run as it is a common character, just like punctuation marks.

It is therefor good practice to use a contextual substitution that starts with an exception that represents the default. This way it will also work at the end of a line.

Here is fea syntax that substitutes the fshapeds if it is not followed by another letter.

Code: Select all

languagesystem latn dflt; # Latin default
@letters = [A-Z a-z fshapeds];

lookup SingleSubstitution1 { # GSUB lookup type SingleSubstitution
    sub fshapeds by snakes;
} SingleSubstitution1;

feature calt { # Contextual Alternates
    ignore sub @letters' @letters;
    sub @letters' lookup SingleSubstitution1;
} calt;
Erwin Denissen
High-Logic
Proven Font Technology
westdale
Posts: 9
Joined: Wed Mar 29, 2017 6:09 pm
Location: UK

Re: Context-sensitive Substitution

Post by westdale »

Thank you - most helpful
westdale
Posts: 9
Joined: Wed Mar 29, 2017 6:09 pm
Location: UK

Re: Context-sensitive Substitution

Post by westdale »

Hi
while I now understand the aim of this code, I have failed to get it to compile.
I had to make a couple of changes ...
I added the calt feature to the script features
I changed 'by' to '->' to match existing code that worked.
I removed trailing names after the '}' on the subroutines as the compiler objected to them.
I recognise that my version will not cope completely with 'ss' - but I'm starting with the basics.
as in the attached images....
case 1.
the layout editor does not expect the 'ignore' in the feature
case2.
I tried moving the exception into the lookup - as per the open cookbook Style Guide
and that failed as it was not expecting 'sub' after ignore.

I used to test software and know that it could be just a silly error - or a parser case missing.
I can't send the file as modified as it is not allowed to save it --- but any advice would be welcome.

Gareth
Attachments
Clipboard01.jpg
Clipboard01.jpg (527.07 KiB) Viewed 1895 times
Erwin Denissen
Moderator
Moderator
Posts: 11472
Joined: Fri Oct 04, 2002 12:41 am
Location: Bilthoven, The Netherlands
Contact:

Re: Context-sensitive Substitution

Post by Erwin Denissen »

It seems you use an outdated version of FontCreator. It is strongly recommended to use the latest version, as that solves many issues, comes with numerous improvements, and has fea support, while your version seems to use the outdated OTLFD syntax.
Erwin Denissen
High-Logic
Proven Font Technology
westdale
Posts: 9
Joined: Wed Mar 29, 2017 6:09 pm
Location: UK

Re: Context-sensitive Substitution

Post by westdale »

Many thanks Erwin. As a retired person who does the occasional specific job for charities, I can't justify the cost of an upgrade - especially as simple additional glyphs work fine in my current version. Thanks for your help and for taking the trouble to reply.
Erwin Denissen
Moderator
Moderator
Posts: 11472
Joined: Fri Oct 04, 2002 12:41 am
Location: Bilthoven, The Netherlands
Contact:

Re: Context-sensitive Substitution

Post by Erwin Denissen »

I understand. Not sure if this helps, but we do offer a 50% discount for non-profit and educational purposes.

Here is the feature code in OTLFD format:

Code: Select all

script latn {
  feature ContextualAlternates;
}

class @letters [A-Z a-z fshapeds];

feature ContextualAlternates calt {
  lookup ChainingContext1;
}

lookup ChainingContext1 {
  ignore context @letters (@letters);
  context @letters;
  sub 0 SingleSubstitution1;
}

lookup SingleSubstitution1 {
  sub fshapeds -> snakes;
}
Erwin Denissen
High-Logic
Proven Font Technology
Post Reply