3

I decided to investigate the OpenType features of the fonts installed in my computer by using the XeLaTeX code from the chosen answer to How do I get a list of all font features supported by current font. However, I run into some problems very soon after I started.

Running the aforementioned code on Calibri (a Windows font) revealed 4 stylistic sets (among other features), out of which only Stylistic Set #4 seemed to affect Latin characters: it replaces the default two-story g in upright characters with a singe-story alternative, and does the reverse in italic letters. HOWEVER, the Wikipedia article on Calibri(https://en.wikipedia.org/wiki/Calibri) specifically mentioned Stylistic Sets #4 and #5. That was puzzling because the aforementioned XeLaTeX code did not find Stylistic Set #5. Yet, selecting said ghost Stylistic Set #5 did indeed produce the effect advertized by Wikipedia: it revealed an alternate f in the italic form. It seems that the XeLaTeX code is not finding features that are available in the font.

On the other hand, the opposite happens with Andika New Basic (http://software.sil.org/andika/andika-new-basic-5-500/). There the XeLaTeX code is finding as selectable a feature which is actually not present in the font: cv01-. SIL claims that this feature corresponds to an alternate 1 figure (http://software.sil.org/wp-content/uploads/sites/19/2015/12/AndikaNewBasic-features5.5.pdf), but selecting it with CharacterVariant=1:1 has absolutely no effect on the result.

So, what is going wrong here? Is this a bug in XeTeX's ability to detect OpenType features? Or is there something wrong with the way in which the features are encoded to the font? Or is the font is engaging in "false advertising" to those programs which query its OpenType features?


Here is the XeLaTeX code I am running.

For the part about detecting features, I copied the code from the previous question-answer I mentioned above --- with a slight change in the order of the features. For the Andika New Basic case (analogous code for Calibri):

\documentclass{article} \usepackage{fontspec,etoolbox,expl3} \setmainfont{Andika New Basic} \def\fontfeatures{abvf, abvm, abvs, aalt, akhn, nalt, halt, afrc, valt, vhal, blwf, blwm, blws, case, cpsp, smcp, c2pc, c2sc, unic, cpct, cjct, cfar, clig, cswh, curs, frac, numr, dnom, ordn, sups, subs, sinf, dist, expt, falt, fwid, haln, half, hwid, hngl, hkna, hojo, init, isol, ital, jp04, jp78, jp83, jp90, jalt, tnum, lnum, onum, pnum, ljmo, lfbd, ltra, ltrm, locl, mset, mgrk, medi, med2, nlck, nukt, opbd, size, ornm, pcap, pref, pres, psts, pstf, palt, vpal, pkna, pwid, qwid, rand, rkrf, rphf, rlig, rtbd, rtla, rtlm, ruby, smpl, liga, dlig, hlig, zero, cv01-, cv99, hist, salt, ss01, ss02, ss03, ss04, ss05, ss06, ss07, ss08, ss09, ss10, ss11, ss12, ss13, ss14, ss15, ss16, ss17, ss18, ss19, ss20, swsh, fina, fin2, fin3, twid, titl, trad, tnam, tjmo, vatu, vert, vrt2, vkna, vkrn, vjmo, ccmp, kern, mark, mkmk, calt} % see http://en.wikipedia.org/wiki/OpenType_feature_tag_list#OpenType_Typographic_Features for their list \ExplSyntaxOn \newcommand\listfontfeatures{% \renewcommand*{\do}[1]{ \fontspec_if_feature:nTF {##1}{##1,\ }{} } \expandafter\docsvlist\expandafter{\fontfeatures} } \ExplSyntaxOff \begin{document} \listfontfeatures \end{document} 

Now for the testing part of the code. For the Andika New Basic MINIMAL code:

\documentclass{article} \usepackage{fontspec} \defaultfontfeatures[\rmfamily]{Scale=1} \defaultfontfeatures+{Scale=MatchLowercase} \defaultfontfeatures+{Ligatures=TeX} \setmainfont{Andika New Basic} \newcommand{\txt}{páck my bóx with fíve dozéñ liqüor júgs, \ae, \oe, \ss.} \newcommand{\txtital}{{\itshape\txt}} \newcommand{\numb}{¡ j i I l L | 1234567890 O o} \newcommand{\CharVar}[2]{{\addfontfeature{CharacterVariant=#1}}#2 {\tiny(CharacterVariant = #1)}} \newcommand{\StylSet}[2]{{\addfontfeature{StylisticSet=#1}#2 {\tiny(Stylistic Set = #1)}}} \newcommand{\grup}[1]{% \noindent#1\\% \CharVar{1:0}{#1}\\% \CharVar{1:1}{#1}\\% } \begin{document} \pagestyle{empty} \grup{\txt} \grup{\numb} \end{document} 

And I do not get the 1 variant that I am supposed to get, as the following screenshot shows:

Andika New Basic

The Calibri code is exactly the same, except that (1) I change the font line to read \setmainfont{Calibri} and (2) I replace the definition of my \grup command (for this MINIMAL example) as follows:

\newcommand{\grup}[1]{% \noindent#1\\% \StylSet{4}{#1}\\% \StylSet{5}{#1}\\% } 

and test as follows:

\begin{document} \pagestyle{empty} \grup{\txt} \grup{\txtital} \end{document} 

I do get an error message in the console warning that Variant=5 (ss05) is not available when I run the Calibri code. And nonetheless I get the italic f replacement, as the following screenshot shows:

Calibri

Hopefully people can reproduce the puzzling results I am getting.

10
  • Please post the code you used for each stage of this. Commented Jun 20, 2017 at 1:35
  • What does otfinfo -f say about the fonts? Commented Jun 20, 2017 at 1:36
  • Usually the fonts are broken, because most font vendors don't care about the OpenType standard at all and just throw their features into random slots. Hans wrote a rant about this situation on a bug with the prime character in LuaTeX. Commented Jun 20, 2017 at 2:11
  • 1
    Regarding Andika New Basic : CharacterVariant=1:1 is the default (1 has a base), CharacterVariant=1:0 gives the other variant (without a base) and selecting it works fine for me. Commented Jun 20, 2017 at 9:23
  • Why I Prefer Traditional TeX Fonts. Commented Jun 21, 2017 at 2:15

1 Answer 1

4

I can reproduce this, and not just in XeTeX but in other applications. (Spoiler: There's no bug.)


Minimal example

First, I reduced your files to a real minimal example:

\documentclass{article} \usepackage{fontspec} \newcommand{\txtital}{{\itshape f g}} \newcommand{\numb}{1} \newcommand{\CharVar}[2]{{\addfontfeature{CharacterVariant=#1}}#2 {\tiny(CharacterVariant = #1)}} \newcommand{\StylSet}[2]{{\addfontfeature{StylisticSet=#1}#2 {\tiny(Stylistic Set = #1)}}} \begin{document} \setmainfont{Andika New Basic} \numb \CharVar{1:0}{\numb} \CharVar{1:1}{\numb} \setmainfont{Calibri} \txtital \StylSet{4}{\txtital} \StylSet{5}{\txtital} \end{document} 

which produced:

First version

where it appears that your problem is fully reproduced. You will shortly see why starting with actually minimal examples is useful.


Issue 1 of 2 (Andika New Basic)

Firstly ignore the hyphen after cv01- that you got; it's just a bug in the macro in the answer from which you copied it; I've left a comment there.

Anyway, let's look at why it doesn't seem to take effect...

A closer look reveals that your \CharVar{1:0}{\numb} expands to:

{{\addfontfeature{CharacterVariant=1:0}}\numb {\tiny(CharacterVariant = 1:0)}} 

where your test text \numb is outside the {\addfontfeature{CharacterVariant=1:0}} group. So the \addfontfeature has no effect on the text. You can fix this bug in the macro by writing the text as

{\addfontfeature{CharacterVariant=1:0}\numb {\tiny(CharacterVariant = 1:0)}} 

(always best to start with the dumbest and most explicit code), testing that it works, and then fixing your macro to, say:

\newcommand{\CharVar}[2]{{\addfontfeature{CharacterVariant=#1}#2 {\tiny(CharacterVariant = #1)}}} 

which works: produces

fixed

So there is no bug here: the font feature (cv01 or "Digit One without base") is documented, detected, selectable, and effectual.


Issue 2 of 2 (Calibri)

With Calibri, things get more interesting. As you saw, XeTeX did not detect a ss05 font feature. But it's not just XeTeX: here's otfinfo:

% otfinfo -f /Library/Fonts/Microsoft/Calibri.ttf c2sc Small Capitals From Capitals calt Contextual Alternates case Case-Sensitive Forms ccmp Glyph Composition/Decomposition cpsp Capital Spacing dlig Discretionary Ligatures dnom Denominators frac Fractions kern Kerning liga Standard Ligatures lnum Lining Figures mark Mark Positioning mkmk Mark to Mark Positioning numr Numerators onum Oldstyle Figures ordn Ordinals pnum Proportional Figures salt Stylistic Alternates sinf Scientific Inferiors smcp Small Capitals ss01 Stylistic Set 1 ss02 Stylistic Set 2 ss03 Stylistic Set 3 ss04 Stylistic Set 4 subs Subscript sups Superscript tnum Tabular Figures 

which is the same set of features detected by XeTeX.

In even more detail, one can install fonttools and run ttx on the font to get it in human-readable XML format:

% ttx -o Calibri.ttx /Library/Fonts/Microsoft/Calibri.ttf Dumping "/Library/Fonts/Microsoft/Calibri.ttf" to "Calibri.ttx"... 

and it dumps all the tables. If you open the file Calibri.ttx in a text editor, you'll find that it contains mentions of ss01 through ss04, but no ss05.

And yet another source: if you load Calibri.ttf into opentype.js, the results are similar.

But the regular system application TextEdit (on macOS) seems to do something interesting: if you type fgfg into it, select Calibri as the font, italicize the last two characters, select them, and then go to Show Fonts → [Gear symbol] → Typography → Alternative Stylistic Sets, there is a Stylistic Set 5, selecting which does change the shape of the f (as XeTeX did):

Calibri in TextEdit

What magic is this? How are TextEdit (and XeTeX) able to select a stylistic set which is clearly not present in the font, as confirmed from so many distinct sources?

Well, a little bit of thought will lead you to the answer :-)

% otfinfo -f /Library/Fonts/Microsoft/Calibri\ Italic.ttf c2sc Small Capitals From Capitals calt Contextual Alternates case Case-Sensitive Forms ccmp Glyph Composition/Decomposition cpsp Capital Spacing dlig Discretionary Ligatures dnom Denominators frac Fractions kern Kerning liga Standard Ligatures lnum Lining Figures mark Mark Positioning mkmk Mark to Mark Positioning numr Numerators onum Oldstyle Figures ordn Ordinals pnum Proportional Figures salt Stylistic Alternates sinf Scientific Inferiors smcp Small Capitals ss01 Stylistic Set 1 ss02 Stylistic Set 2 ss03 Stylistic Set 3 ss04 Stylistic Set 4 ss05 Stylistic Set 5 subs Subscript sups Superscript tnum Tabular Figures 

and similar results with ttx or opentype.js or indeed even XeTeX:

\documentclass{article} \usepackage{fontspec,etoolbox,expl3} \setmainfont{Calibri Italic} \def\somefontfeatures{ss01, ss02, ss03, ss04, ss05, ss06, ss07, ss08, ss09, ss10} \ExplSyntaxOn \newcommand\listsomefontfeatures{% \renewcommand*{\do}[1]{ \fontspec_if_feature:nTF {##1}{##1,\ }{} } \expandafter\docsvlist\expandafter{\somefontfeatures} } \ExplSyntaxOff \begin{document} \listsomefontfeatures \end{document} 

That's all there is to the mystery: the stylistic variant ss05 is present in the Calibri Italic font, but not in the Calibri font. This is consistent with everything you saw in the question, and, again, there's no bug in XeTeX's detection or selection of font features.

1
  • That was some clumsy coding on my part. Thanks! Commented Jun 24, 2017 at 14:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.