How to deal with conextual alternatives and separator & punctuations?

Hi there! 
I'm working on a font which is based on the idea of contextual alternates. 
I'm using only the lowercase and the uppercase characters. The idea is that with stylistic set the uppercase and the lowercase letters vary cyclicly by typing only lowercase (not using the 'shift' button).

It looks like this: AaAaAaA

The problem is when there is a space (or any kind of punctuations) between two words the cycle considers the space as a letter(?). 
Looks like this: AaAaAaA AaAaAaA AaAa
What I try to do is that any time a word ends on an uppercase letter the following word should start with a lowercase, and vice versa, so start with always the opposite as the other ends, no matter how many spaces I have between the words. Like this: AaAaAaA aAaAaAa AaAa

The first code is to change the lowercase to upercase when I start typing:
  #lc=lowercase  UC=uppercase

  lookup x01 {
    sub @lc' by @UC; }
  lookup x02 {
    sub @UC @UC' by @lc; }

And after I couldn't figure it out how avoid the space and punctutations. 
Any idea how to tackle this question?


  • Erwin DenissenErwin Denissen Posts: 111
    edited December 2017
    This should do the trick:

    script latn {
      feature StandardLigatures1;

    class @UC [A-Z];
    class @lc [a-z];
    class @SP [space comma period exclam question];

    feature StandardLigatures1 liga {
      lookup ChainingContext1;

    lookup ChainingContext1 {
      context (@lc @SP @SP) @lc;
      sub 0 SingleSubstitution1;
      context (@lc @SP) @lc;
      sub 0 SingleSubstitution1;
      context (@lc) @lc;
      sub 0 SingleSubstitution1;

    lookup SingleSubstitution1 {
      sub @lc -> @UC;

    It is in OpenType Layout Feature code as used by FontCreator, but you can easily adapt it to other code.
  • Thank you very much for your reply. 
    I'm new to coding. I tried to translate it to FontLab and Glyphs, but I need to understand some parts. Could you give me a good source where I can find explanation and a way to implement these codes into FontLab or Glyphs?
  • Bahman EslamiBahman Eslami Posts: 52
    edited December 2017
    This is the code in AFDKO syntax as you would use it in Fontlab or Glyphs or Robofont.

    languagesystem DFLT dflt;
    languagesystem latn dflt;

    @UC = [A-Z];
    @lc = [a-z];
    @SP = [
    space comma period exclam question];

    lookup ChainingContext1 {
        sub @lc @SP @SP @SP @lc' @lc by @UC;
        sub @lc @SP @SP @lc' @lc by @UC;
        sub @lc @SP @lc' @lc by @UC;
        sub @lc @lc' @lc by @UC;
        sub @lc @lc' by @UC;    
    } ChainingContext1;

    feature liga {
      lookup ChainingContext1;
    } liga;

  • Thank you so much, it works perfectly!
Sign In or Register to comment.