Search code examples
opentype

FontLab - OpenType feature for changing numbers to roman notation


I would like to use an opentype feature in my font, I'm creating in FontLab, that would transform all the numbers to roman notation. This is the OpeType Feature code I'm using:

feature liga{
  sub @arabic by @roman1;
  sub @roman1' @roman1 by @roman2;
  sub @roman2' @roman2 by @roman3;
  sub @roman3' @roman3 by @roman4;
} liga;

Classes 'arabic' and 'roman1-4' all contain numbers from 0 to 9, where roman1 contains: [empty symbol], I, II... IX, roman2: [empty smbol], X, XX... XC, etc.

Numbers up to 99 are working as they should, but above 100 only roman2 glyphs are being repeated, so instead 111 being 'CXI', I get 'XXI'. I'm not sure what the right syntax for opentype features should look like and where exactly is the problem.


Solution

  • So I have solved my problem already. The reason why it wasn't working was that all the rules were run in a single pass of the word as one rule instead of them being run one after another through whole word. This is the correct solution:

    feature liga{
       lookup rOne {
          sub @arabic by @roman1;
       } rOne;
       lookup rTwo {
          sub @roman1' @roman1 by @roman2;
       } rTwo;
       lookup rThree {
          sub @roman2' @roman2 by @roman3;
       } rThree;
       lookup rFour {
          sub @roman3' @roman3 by @roman4;
       } rFour;
    } liga;
    

    P.S.: To clarify, this code is for FontLab's OpenType features coding