Token language for base glyph

What would be the most efficient $token language to capture the glyph name up to the first [.], or the whole name if no [.]? For example, something that captures
/a and /a.ss01 and /a.ss02.

And: there isn’t a way to select for specific components, for example a token that captures all of the glyphs that include /a as a component? (/aacute, /agrave, etc.)

Check the NSPredicate docu. You can use something like ‘beginswith’ and connect two queries with ‘OR’.

Maybe re-using kerning classes can help with the components? Because usually all those glyphs are in the same kerning group.

Okay, I’d thought of the OR solution but wondered if there was anything cleaner.

Just stumbled across this. As I am getting into tokens, this is the most interesting use case. I need something that is exactly like “Show all glyphs that use this glyph as component” for a given glyph. Is this possible? Name-based hacks are certainly too unreliable.

I don’t think tokens can currently do this.

Actually, you can like so:

$["glyphname" in layer0.componentNames]

This does not take nested components into account.


Would you want nested components to also be taken into account or not?

Depending on your use case, an alternative might be to use glyph tags.

You are right, there are certain questions. I am just realising this as I am writing a small script that generates the feature class definitions. Nested components: Yes, I’d usually want that. Another issue is: glyphs don’t contain components, layers do. However, it’s practically safe to simply check the first layer as it is very unlikely that components are not the same in different layers.

Oh, that is very handy. Thanks! I’d probably use that for those cases when I know there aren’t any nested components.

Just tried this and it does not seem to include nested components.

In my font, the io-cy contains an e as nested component via ie-cy. If I use

@e = [e $["e" in layer0.componentNames]];

and opt-click the @e I cannot find the io-cy, only the glyphs with directly included e.

You are right, I must have messed something up when testing this myself. Looking at the code, nested components are not included.

With the next cutting-edge release, you will be able to use componentNamesTraversingComponents instead to also check for nested components.

Good to know.

FWIW, here is the script I use to generate the classes, in case someone finds it useful:

font = Glyphs.currentDocument.font

def glyphsThatContainComponent( baseName ):
	composites = []
	for glyph in font.glyphs:
		for component in glyph.layers[0].components:
			if component.componentName == baseName:
				composites.append( glyph.name )
				composites.extend( glyphsThatContainComponent( glyph.name ) )
				break
	return composites

for baseGlyph in font.glyphs:
	if baseGlyph.category != 'Letter':
		continue
	if not baseGlyph.layers[0].paths:
		continue
	composites = glyphsThatContainComponent( baseGlyph.name )
	if composites:
		print( '@' + baseGlyph.name + ' = [' + baseGlyph.name + ' ' + ' '.join( composites ) + '];' )
2 Likes