Can I create a font to replace words with icons?

I have a text that contains lists of countries. The country names take up too much space. So I would like to create a custom font that will replace the country names with icons.

For example, if I type the word “Mexico”, the font will replace Mexico with an icon to represent “Mexico”.

Is it possible to create a font to do that? I know some fonts use ligatures to replace certain combination of letters. For example, if you type “the”, then font will replace “th” with a special new symbol that has “th” placed next to each other with better spacing. So would it be possible to do something like that but on a bigger scale, so you are replacing entire words and not just pairs of letters?

The reason I want to do it using fonts is because my text has to be copy and pasted between different documents. In some documents, I wouldn’t want the icons. So if I can just change the font to make the country names display as I wish, that would be easier.

1 Like

Look into basic OpenType feature scripting.
You could have a glyph named france and add a feature with the following code:

sub B a g u e t t e by france;

This will replace the word “Baguette” (with a capital B) with your glyph named france. Honhon.

Read more here: Features, part 1: simple substitutions | Glyphs

1 Like

The main question is in which exact feature to write such a substitution? Standard Ligatures is not the good choice for that because they are active by default. If the user wanted to write “Mexico”, he expect to see the word Mexico, by default. So the better idea is to use Stylistic Set for that.

If the flag of Mexico should be displayed, then:

– Create a glyph with the name MexicoFlag
– Open Font Info –> Features –> Add feature → Stylistic Set (ss…)
– Add the substitution code like Sebastian proposed:

sub M e x i c o by MexicoFlag;

But it would be more safe to wrap the word into colon context like :mexico:
The substitution for that will looks like:

sub colon m e x i c o colon by MexicoFlag;
1 Like

Don’t put this in a release font, because this effectively breaks your font for most languages except the one for which you write the opentype feature. This would only be for very special purposes.

Don’t forget to add clauses that limit it to the word with a preceding ignore clause. Something like: ignore @AllLetters M' e' x'… and the like.

1 Like

As it was said before. Doing this in shipping fonts is not a good ideas.
The safest is to put this into a font that contains only this. Then one would apply the font very specifically.
But if you really need it to be in the same font, put it into a stylistic set.

1 Like

You could also consider using the same Unicode sequences that are used for flags. For example, you would use the Unicode code points

  • 🇲 U+1F1F2 REGIONAL INDICATOR SYMBOL LETTER M
  • 🇽 U+1F1FD REGIONAL INDICATOR SYMBOL LETTER X

for Mexico as it is abbreviated as “MX”. Wikipedia has a list of the common country codes.

The glyph names for these symbols, for example, are MRegion and XRegion. These glyphs should be designed such that they contain the letter and some frame or something to differentiate them from the regular letters in your font.

Then, add a ligature glyph containing the icon for the country. The name of this icon glyph should combine the glyph names of the two symbol letters with an underscore, for example, MRegion_XRegion.

This will cause the icon to be used when the dlig feature (which is deactivated by default) is activated. You can also use the liga feature (which is activated by default) by naming your icon glyph MRegion_XRegion.liga.

Now, typing the :mexico: flag emoji when using your font will display your icon glyph instead of the emoji.

1 Like

Also keep in mind that words-based subs might be tricky: New Mexico, Georgias, Guineas, Dominica and Dominican Republic, Niger and Nigeria, etc.

1 Like

Indeed Alex, that’s why I proposed to wrap the key-word with a colon like :mexico: to exclude unwanted context. I tried it in one of my projects.

depicto-4

Also I tried a chaining substitution to display two pictograms at once like a :flowers: on the image above.

sub colon' f' l' o' w e r s colon by tulip;
sub tulip w' e' r' s' colon' by rose;
2 Likes

Sure, but if the Kute_Kitty wants to make it easy to switch between icons and full words depending on the document…

Perhaps, the safest way would be to put the icons under flags unicodes and just run find-and-replace in the text editor rather than overcomplicating it with OT.

1 Like

Here, you could also use the respective emoji: :apple::pear::bouquet::house_with_garden:

2 Likes

What would the sub code be for a word that has a space in it.

For example, “Latin America”

I tried:
sub L a t i n A m e r i c a by LatinAmerica;

But it didn’t work. I tried putting in extra spaces, but that didn’t work either. I’m guessing maybe it’s not possible to have font substitutions for words that have a space?

Also, thank you so much to everyone who replied.

Did you try sub L a t i n space A m e r i c a by LatinAmerica; ?

1 Like

In a substitution, you need to use glyph name instead of character name.

The character A has the same glyph name A, like all the English alphabet. But other glyphs have more complex and descriptive names:
. is period
, is comma and so on.

Just open the Font window on Glyphs app and you’ll be able to see all the glyph names right below the glyph icons.

Select the glyph(s) → right click on it → Copy Glyph Names → Space Separated or Line Separated.

1 Like

This worked perfectly. Thank you so much, and again thank you to everyone who replied.