OpenType code with @ in it.

Get help with FontCreator here. Please do not post feature requests or bug reports here.
Post Reply
William
Top Typographer
Top Typographer
Posts: 2038
Joined: Tue Sep 14, 2004 6:41 pm
Location: Worcestershire, England
Contact:

OpenType code with @ in it.

Post by William »

The following web page shows what substitutions are available in the OpenType specification and which of them are available in FontCreator 7 at present.

http://www.high-logic.com/fontcreator/m ... tions.html

Within that page is type 6, Chaining Context.

There are notes that Chaining Context is partially supported and "Only group based".

At present I do not understand how to use OpenType code with an @ in it or for what the @ is used.

Could you possibly provide one or two simple examples of code that uses the @ please that FontCreator 7 will compile, also saying for what it is used, so that readers can learn about it and hopefully try it out as part of the learning process.

William Overington

17 June 2013
León Fridsma
Posts: 694
Joined: Mon Dec 07, 2009 10:26 am
Location: De Bilt, Netherlands
Contact:

Re: OpenType code with @ in it.

Post by León Fridsma »

The @ is used to reference a group of glyphs in chaining context substitutions.

As the name suggests, chaining context substitutions are used to substitute characters in a specific context. The script below shows a basic ordinals feature which will substitute the alphanumeric characters with superscript variants in a string starting with ordinals. To illustrate I've created a screen shot with this enabled and disabled:
onum.png
onum.png (23.05 KiB) Viewed 6867 times
The logic behind is quite complex, but in this post I'll try to explain how to create one of these ordinal features using a custom script in the OpenType Layout Feature Compiler.

First off: the syntax. A chaining context contains an input group and a lookahead and/or backtrack group and a regular substitution table:

Code: Select all

group @OptionalBacktrackGroup [ <groupmembers> ];
group @InputGroup [ <groupmembers> ];
group @OptionalLookaheadGroup[ <groupmembers> ];

feature SomeFeature <featuretag> {
  context (@OptionalLookaheadGroup) @InputGroup (@OptionalBacktrackGroup);
  sub 0, SubstitutionTable
}

lookup SubstitutionTable {
  <substitutions>
}



Let's start by writing down in plain text what we want to achieve:

"If a sequence starting with numbers is found followed by one or more alphanumeric characters, substitute the alphanumeric characters with superscript glyphs."

Because we want to substitute glyphs at the end of our sequence we need a backtrack group here. So lets start off by creating a group of the alphanumeric characters:

Code: Select all

group @Alphas [A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z];
Then we create the group of ordinals:

Code: Select all

group @Ordinals [zero one two three four five six seven eight nine A.sups B.sups C.sups D.sups E.sups F.sups G.sups H.sups I.sups J.sups K.sups L.sups M.sups N.sups O.sups P.sups Q.sups R.sups S.sups T.sups U.sups V.sups W.sups X.sups Y.sups Z.sups a.sups b.sups c.sups d.sups e.sups f.sups g.sups h.sups i.sups j.sups k.sups l.sups m.sups n.sups o.sups p.sups q.sups r.sups s.sups t.sups u.sups v.sups w.sups x.sups y.sups z.sups];
As you may notice the superscript glyphs are also in this group, and here is the reason why: The OpenType feature engine of applications will continue substituting glyphs for as long as the input sequence matches, so if we did not list the superscript variants here the engine would stop after matching the first alphanumeric character. I hope this breakdown explains how this works:

"2" => matches @Ordinals
"21" => matches @Ordinals
"21s" => 21 matches @Ordinals, "s" matches @Alphas and is substituted by s.sups
Now the engine would try to match "21<s.sups>t" but because the <s.sups> does not match @Ordinals the sequence ends.

End result: "21<s.sups>t"

So when we add all superscript glyphs to the @Ordinals group this happens:

"2" => matches @Ordinals
"21" => matches @Ordinals
"21s" => "21" matches @Ordinals, "s" matches @Alphas and is substituted by s.sups
"21<s.sups>t" => "21<s.sups>" matches @Ordinals, "t" matches @Alphas and is substituted by t.sups

End result: "21<s.sups><t.sups>"


And finally we create a lookup table of the glyphs we want to substitute:

Code: Select all

lookup Super {
    sub A -> A.sups; 
    sub B -> B.sups; 
    sub C -> C.sups; 
    sub D -> D.sups; 
    sub E -> E.sups; 
    sub F -> F.sups; 
    sub G -> G.sups; 
    sub H -> H.sups; 
    sub I -> I.sups; 
    sub J -> J.sups; 
    sub K -> K.sups; 
    sub L -> L.sups; 
    sub M -> M.sups; 
    sub N -> N.sups; 
    sub O -> O.sups; 
    sub P -> P.sups; 
    sub Q -> Q.sups; 
    sub R -> R.sups; 
    sub S -> S.sups; 
    sub T -> T.sups; 
    sub U -> U.sups; 
    sub V -> V.sups; 
    sub W -> W.sups; 
    sub X -> X.sups; 
    sub Y -> Y.sups; 
    sub Z -> Z.sups; 
    sub a -> a.sups; 
    sub b -> b.sups; 
    sub c -> c.sups; 
    sub d -> d.sups; 
    sub e -> e.sups; 
    sub f -> f.sups; 
    sub g -> g.sups; 
    sub h -> h.sups; 
    sub i -> i.sups; 
    sub j -> j.sups; 
    sub k -> k.sups; 
    sub l -> l.sups; 
    sub m -> m.sups; 
    sub n -> n.sups; 
    sub o -> o.sups; 
    sub p -> p.sups; 
    sub q -> q.sups; 
    sub r -> r.sups; 
    sub s -> s.sups; 
    sub t -> t.sups; 
    sub u -> u.sups; 
    sub v -> v.sups; 
    sub w -> w.sups; 
    sub x -> x.sups; 
    sub y -> y.sups; 
    sub z -> z.sups; 
}
These are the 3 base ingredients we need for our feature to work, so let's put them together in a lookup table:

Code: Select all

lookup Ordinals{
  context (@Ordinals) @Alphas;
  sub 0 Super;
}  
Which will give us the following script:

Code: Select all

script latn {
  feature Ordinals;
}

feature Ordinals ordn {
    lookup Ordinals;
}
 
group @Ordinals [zero one two three four five six seven eight nine A.sups B.sups C.sups D.sups E.sups F.sups G.sups H.sups I.sups J.sups K.sups L.sups M.sups N.sups O.sups P.sups Q.sups R.sups S.sups T.sups U.sups V.sups W.sups X.sups Y.sups Z.sups a.sups b.sups c.sups d.sups e.sups f.sups g.sups h.sups i.sups j.sups k.sups l.sups m.sups n.sups o.sups p.sups q.sups r.sups s.sups t.sups u.sups v.sups w.sups x.sups y.sups z.sups];

group @Alphas [A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z];

lookup Ordinals{
  context (@Ordinals) @Alphas;
  sub 0 Super;
}  

lookup Super {
    sub A -> A.sups; 
    sub B -> B.sups; 
    sub C -> C.sups; 
    sub D -> D.sups; 
    sub E -> E.sups; 
    sub F -> F.sups; 
    sub G -> G.sups; 
    sub H -> H.sups; 
    sub I -> I.sups; 
    sub J -> J.sups; 
    sub K -> K.sups; 
    sub L -> L.sups; 
    sub M -> M.sups; 
    sub N -> N.sups; 
    sub O -> O.sups; 
    sub P -> P.sups; 
    sub Q -> Q.sups; 
    sub R -> R.sups; 
    sub S -> S.sups; 
    sub T -> T.sups; 
    sub U -> U.sups; 
    sub V -> V.sups; 
    sub W -> W.sups; 
    sub X -> X.sups; 
    sub Y -> Y.sups; 
    sub Z -> Z.sups; 
    sub a -> a.sups; 
    sub b -> b.sups; 
    sub c -> c.sups; 
    sub d -> d.sups; 
    sub e -> e.sups; 
    sub f -> f.sups; 
    sub g -> g.sups; 
    sub h -> h.sups; 
    sub i -> i.sups; 
    sub j -> j.sups; 
    sub k -> k.sups; 
    sub l -> l.sups; 
    sub m -> m.sups; 
    sub n -> n.sups; 
    sub o -> o.sups; 
    sub p -> p.sups; 
    sub q -> q.sups; 
    sub r -> r.sups; 
    sub s -> s.sups; 
    sub t -> t.sups; 
    sub u -> u.sups; 
    sub v -> v.sups; 
    sub w -> w.sups; 
    sub x -> x.sups; 
    sub y -> y.sups; 
    sub z -> z.sups; 
}
William
Top Typographer
Top Typographer
Posts: 2038
Joined: Tue Sep 14, 2004 6:41 pm
Location: Worcestershire, England
Contact:

Re: OpenType code with @ in it.

Post by William »

Thank you.

William
William
Top Typographer
Top Typographer
Posts: 2038
Joined: Tue Sep 14, 2004 6:41 pm
Location: Worcestershire, England
Contact:

Re: OpenType code with @ in it.

Post by William »

Earlier this morning I tried to make a font using the code that León Fridsma kindly supplied in the second post of this thread.

Here is some transcript.

The font is attached after the transcript.

----

Tuesday 18 June 2013

7:54 am

Try to implement a font that has the code from the second post in the "OpenType code with @ in it" thread in it.

viewtopic.php?p=19575#p19575

The code uses the ordn tag.

http://www.microsoft.com/typography/ots ... relist.htm

http://www.microsoft.com/typography/ots ... o.htm#ordn

Open the project Learning_aalt_004 in FontCraetor 7.0.0 (build 396).

This is simply so as to have a basic font with which to try to implement the code.

Save as the project Learning_ordn_001

Font Properties... Identification Font Family to become Learning_ordn_001

File Export Font Export Settings, left column to become as follows.

Learning_ordn_001.otf
Yes
Custom Script
KERN and GPOS
Auto Hinting

Redate and time the font.

Delete the OpenType code that is in the font.

Copy the code from the forum post.

Paste the code into the font.

Save the code.

I need 26 superscript capitals and 26 superscript lowercase letters.

Rather than design them all properly, for this experiment simply produce raised versions of the capitals and mostly raised versions of the lowercase, as the purpose here is to learn about the OpenType code.

Try raising the capitals by 256 font units and raising the lowercase letters by 256 font units yet not raising the tops of ascenders and being careful with the lowercase f.

Add 26 glyphs at the end of the font.

Copy the capital letters into those 26 cells.

Raise them all by 256 font units using the Glyph Transformer.

Add 26 glyphs at the end of the font.

Copy the lowercase letters into those 26 cells.

Lower the tops of the ascenders each by 256 font units, also the bar of the lowercase t.

The f did not need to be lowered.

Raise all of the lowercase letters by 256 font units using the Glyph Transformer.

Name the glyphs as A.sups B.sups and so on for 52 glyphs.

Try compiling the code.

Success

8:43 am

----

Update the modified time manually.

Try exporting the font.

Temporarily install the font.

Try the font in PagePlus X5.

It works well.

8:51 am

----

10:50 am

Temporarily install the font.

Try the font in PagePlus X5.

It works well.

Make a graphic for the forum.

----
Learning_ordn_001.png
Learning_ordn_001.png (22.74 KiB) Viewed 6852 times
Here is the font.
Learning_ordn_001.otf
(26.45 KiB) Downloaded 394 times
William Overington

18 June 2013
William
Top Typographer
Top Typographer
Posts: 2038
Joined: Tue Sep 14, 2004 6:41 pm
Location: Worcestershire, England
Contact:

Re: OpenType code with @ in it.

Post by William »

I wondered if I could apply what I have learned from this thread to a similar yet different problem.

I wondered about a font that would support producing subscript numbers in simple chemical molecule notation.

For example, with the facility on, converting H2SO4 such that the numbers became subscripts within such molecules, but not elsewhere.

I reasoned that C12H26 would need to work, with all digits becoming subscripts.

I managed to adapt the code that León Fridsma kindly supplied in the second post of this thread so as to solve the problem.

In case any readers would like to try the problem themselves I am hoping to place the result in a later post in this thread, with a post containing some clues in between in case anyone would like to know the clues before knowing of my solution.

Please note that I am learning so my solution might not be the best way to proceed, so discussion is welcomed.

William
William
Top Typographer
Top Typographer
Posts: 2038
Joined: Tue Sep 14, 2004 6:41 pm
Location: Worcestershire, England
Contact:

Re: OpenType code with @ in it.

Post by William »

(spacing post to avoid giving clues away too early)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
21
23
24
William
Top Typographer
Top Typographer
Posts: 2038
Joined: Tue Sep 14, 2004 6:41 pm
Location: Worcestershire, England
Contact:

Re: OpenType code with @ in it.

Post by William »

I looked at the following web page.

http://www.microsoft.com/typography/ots ... relist.htm

There I found the subs feature and a link to the following web page.

http://www.microsoft.com/typography/ots ... t.htm#subs

I did not understand all of that description, yet I decided to try to adapt the code by using subs instead of ordn and using Subscript with subs instead of the original Ordinals.

In the original code, for ordn, a sequence of a digit followed by a letter results in the letter becoming a superscript letter.

In the code for this font, a sequence of a letter followed by a digit results in the digit becoming a subscripted digit.

The final result needs to ensure that a subscripted digit followed by a digit causes that digit also to become subscripted.

William
William
Top Typographer
Top Typographer
Posts: 2038
Joined: Tue Sep 14, 2004 6:41 pm
Location: Worcestershire, England
Contact:

Re: OpenType code with @ in it.

Post by William »

(spacing post to avoid giving an answer away too early)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
21
23
24
William
Top Typographer
Top Typographer
Posts: 2038
Joined: Tue Sep 14, 2004 6:41 pm
Location: Worcestershire, England
Contact:

Re: OpenType code with @ in it.

Post by William »

First of all I tried to work out the code, before starting to make the font and to write the transcript.

Here is the transcript with that code pasted within it.

----

11:46 am

Open the project Learning_ordn_001 in FontCraetor 7.0.0 (build 396).

This is simply so as to have a basic font with which to try to implement the code.

Save as the project Learning_subs_001

Font Properties... Identification Font Family to become Learning_subs_001

File Export Font Export Settings, left column to become as follows.

Learning_subs_001.otf
Yes
Custom Script
KERN and GPOS
Auto Hinting

Redate and time the font.

Delete the OpenType code that is in the font.

Paste in the following code.

Code: Select all

    script latn {
      feature Subscript;
    }

    feature Subscript subs {
        lookup Subscript;
    }
     
    group @Alphas [A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z zero.subs one.subs two.subs three.subs four.subs five.subs six.subs seven.subs eight.subs nine.subs];

    group @Digits [zero one two three four five six seven eight nine];

    lookup Subscript {
      context (@Alphas) @Digits;
      sub 0 Sub;
    } 

    lookup Sub {
        sub zero -> zero.subs;
        sub one -> one.subs;
        sub two -> two.subs;
        sub three -> three.subs;
        sub four -> four.subs;
        sub five -> five.subs;
        sub six -> six.subs;
        sub seven -> seven.subs;
        sub eight -> eight.subs;
        sub nine -> nine.subs;
    }
Save the code.

Add 10 glyphs at the end of the font.

Paste copies of the glyphs for the digits into them.

Lower the glyphs each by 256 font units using the Glyph Transformer.

Name the glyphs as zero.subs one.subs and so on.

Try compiling the code.

Success

Manually update the time.

Export the font.

Temporarily install the font.

Try the font in PagePlus X5.

Having enabled the subs feature, test data of H2SO4 worked well as did C12H26

Excellent

12:07 pm

----
Learning_subs_001.png
Learning_subs_001.png (22.83 KiB) Viewed 6835 times
Here is the font.
Learning_subs_001.otf
(27.3 KiB) Downloaded 411 times
William
Post Reply