fontNames woes

Neville Smythe neville.smythe at optusnet.com.au
Sun Oct 23 03:26:52 EDT 2022


My grand project to compile a database of cross-platform LC font metrics is slowly progressing, though rather hindered by bugs in LC.

In particular fontNames() produces inconsistent results between Mac and Windows (and is not available in Linux) and worse can produce incorrect results on the Mac.

To demonstrate, start using font file Akshar[wght].ttf, which is one of the Google opentype fonts. This file includes 5 style variations, which are certainly all quite different fonts in appearance. The naming and style conventions for fonts are so complex that the bug is understandable — but its still a bug.

On the Mac, fontNames() produces
	Akshar Light
	Akshar Light
	Akshar Light Medium
	Akshar Light SemiBold
	Akshar Light Bold

This is a bug: the first two are supposed to be references to quite different variations (a Regular and Light version of Akshar). Since they have the same name one of them cannot be accessed by setting textFont. This list does not match the MacOS knowledge of the font.

On Windows, fontNames() produces
	Akshar

This is perhaps not a bug, but gives no way to access the 4 non-Regular versions of the font; the variations would be accessed by a Windows user or app by setting a style variation, but this cannot be done in LC.  It also does not match what the Windows system knows about the fonts in the family.. 

If you look at Akshar[wght].ttf in the Mac Font Book application, you find that the system says the name of the font family is Akshar, with fonts
	Akshar Regular
	Akshar Light
	Akshar Medium
	Akshar SemiBold
	Akshar Bold

If you look at Akshar[wght].ttf in the Windows Font Manager application, you find that the system says the name of the font family is Akshar Light, with fonts
	Akshar
	Akshar Light
	Akshar Medium
	Akshar SemiBold
	Akshar Bold	

Using Linux the Fonts application (Ubuntu) the family name appears as Akshar, Light (note the comma) and with named variations
	Regular, Light, Bold, Medium, SemiBold

The LC function fontNames() is not implemented in Linux but there is a shell command fc-list which explains a lot. After parsing a little we get
	Akshar,Akshar Light		
	Akshar,Akshar Light:style=Regular		
	Akshar,Akshar Light:style=Bold
	Akshar,Akshar Light:style=Medium
	Akshar,Akshar Light:style=SemiBold
	Akshar,Akshar Light:style=Light,Regular

The items before the colon are alternative names for the font. The first line with no styles attached give the family names – 2 alternative names, Mac uses #2, Win uses #1. So fonts can have many names, often including non-Roman script names. They also can have multiple styles, many being international names of English style names. Akshar is actually a comparatively straightforward case. Which names should be returned by fontNames() for each platform is clearly a difficult problem.

Apart from the bug in the Mac version of fontNames(), there may be problems, which I cannot yet pin down, with using custom fonts in Windows as well. A stack which works in the IDE crashes as a standalone, the error dialog returning a seemingly irrelevant line for the source of the error so likely it is in the engine somewhere and almost certainly to do with fontNames. Furthermore even in the IDE there may be a problem with stop using font file, as it does not seem to clear the font cache after multiple use, which means fontNames() returns stale values.

Finally of course there is fontStyles(), which has been dead for years on the Mac, and even when it did work returned only plain, italic, bold, bold-italic instead of the actual available font style variations — and even if it did would be useless because you can’t set such styles within LC. A vast number of modern fonts are just inaccessible from LC.

Neville Smythe




More information about the use-livecode mailing list