fontspec icon indicating copy to clipboard operation
fontspec copied to clipboard

FontIndex indirectly by PostScript name

Open svenper opened this issue 5 years ago • 2 comments

Description

Font collection indexes are confusing and fragile. Since every index should only match a single PostScript name, that field could be used to match the indexes in a more human friendly way, that also would not break if the font is updated to change the index numbers.

So in addition to FontIndex=n it would be nice to have FontIndexPS=postscriptname. Or perhaps it could use the same field "FontIndex" and behave one way with a string and another with an integer.

Using PostScript names would be both more change robust and human friendly.

Check/indicate

  • [x] Relevant for XeTeX
  • [x] Relevant for LuaTeX
  • [x] Issue tracker has been searched for similar issues?
  • [ ] Links to <tex.stackexchange.com> discussion if appropriate

Minimal example demonstrating the issue

A use case where this would be helpful is Chinese fonts that come in traditional and simplified variants with varying implementations of bold and "italic".

Free TTC fonts are hard to come by, especially ones that can be used to showcase issues. I choose the proprietary Kaiti TC because it behaves poorly by default, has especially troublesome postscript names, weight numbers, and style linkings. In order to get matching "italics" it has to be combined with another font like Xingkai TC, which has different indexes. After updates fonts like these might also change indexes for no apparent reason. All of this makes index numbers needlessly confusing for a human, which would be moot if TTC indexes were targeted instead by PostScript names.

The MWE should compile with both LuaLaTeX and XeLaTeX on macOS. The fonts are part of macOS and can be enabled/downloaded with Font Book.

\documentclass{article}

\usepackage{fontspec}

\newfontfamily\TC{Kaiti TC}[
	Path=/System/Library/Assets/com_apple_MobileAsset_Font5/b2d7b382c0fbaa5777103242eb048983c40fb807.asset/AssetData/,
	Extension=.ttc,
	UprightFont=Kaiti,
	UprightFeatures={
		FontIndex=2,% STKaitiTC-Regular
	},
	BoldFont=Kaiti,
	BoldFeatures={
		FontIndex=6,% STKaitiTC-Black
	},
	ItalicFont=Xingkai,
	ItalicFeatures={
		Path=/System/Library/Assets/com_apple_MobileAsset_Font5/4cecce0dd640f147de4d0e4155a97d3cdf47971e.asset/AssetData/,
		FontIndex=3,% STXingkaiTC-Light
	},
	BoldItalicFont=Xingkai,
	BoldItalicFeatures={
		Path=/System/Library/Assets/com_apple_MobileAsset_Font5/4cecce0dd640f147de4d0e4155a97d3cdf47971e.asset/AssetData/,
		FontIndex=1,% STXingkaiTC-Bold
	},
]

\newfontfamily\TCauto{Kaiti TC}

\def\example{起}


\begin{document}

\Huge

postscriptname:

{\fontspec{STKaitiTC-Regular} \example}
{\fontspec{STKaitiTC-Black}   \example}
{\fontspec{STXingkaiTC-Light} \example}
{\fontspec{STXingkaiTC-Bold}  \example}

TC:

{\TC    \mdseries\upshape     \example}
{\TC    \bfseries\upshape     \example}
{\TC    \mdseries\itshape     \example}
{\TC    \bfseries\itshape     \example}

TCauto:

{\TCauto\mdseries\upshape     \example}
{\TCauto\bfseries\upshape     \example}
{\TCauto\mdseries\itshape     \example}
{\TCauto\bfseries\itshape     \example}

\end{document}

Further details

To really illustrate the confusion in this use case, a challenge left for the reader is to attempt to recreate the MWE but with the SC fonts instead of TC. This would be trivial with PostScript names (s/TC/SC/g), but with indexes requires deep diving with fc-query or such, and it's not just a matter of subtracting or adding the same number to all index values.

svenper avatar Aug 23 '19 15:08 svenper

Could you please try if with the newest luaotfload (version 3.10) (and lualatex naturally) the syntax FontIndex=STXingkaiTC-Light works?

(the FontIndex key treats the argument as a string, so there should be no need for a special option).

u-fischer avatar Nov 07 '19 10:11 u-fischer

The new syntax works! Fantastic, thanks.

svenper avatar Nov 08 '19 13:11 svenper