Stupid font tricks revisited
Following on from my previous “stupid font tricks” post, I went down a handful of rabbit holes, including the design of the non-binary LFSRs which would be needed to generate the patterns. More recently I got an AI to start hacking on Noto Emoji to make this actually happen.
Neither ChatGPT nor I are great graphic artists; but AI is a top-notch plagiarist, so that was useful.
Like all my slopcoding projects it’s a bit of a mess, but it gets the idea across and that’s all I ever hoped to accomplish.
Super-quick recap: OpenType fonts have embedded rules for ligatures and contextual substitutions which give you the control to program all sorts of silliness which modern font rendering engines support, so you can get these effects in a lot of software just through manipulation of the font itself.
Core ideas
random clustering
🪦🪦🪦🪦🪦🪦🪦🪦🪦🪦🪦🪦
For a long string of the same glyph, randomly ligate either two or three of the characters. This allows the addition of some depth to a cluster of the same glyph, where some instances can be moved back in the field a bit.
In the implementation I have so far, I use a binary, five-tap LFSR. That is, depending on the last five decisions made in this class the next decision will be whether to combine two or three of the same codepoint into a single glyph.
five taps means the period is 31 (leaving out the all-zeroes case because LFSRs are like that). 31 is prime, so it has the desirable property of making it co-prime to any other generator I’m likely to contemplate in the short term.
Random skin-tone
🦶🦶🦶🦶🦶🦶🦶🦶🦶🦶🦶🦶
Since many emoji can be modified with a skin tone, of which there are five (you can’t really include Simpsons-yellow, because that stands out too much; as does zombie-green). So a base-five, four-tap LFSR inserts skin tone modifiers against every emoji. Whether they need it or not.
It doesn’t have to be used as skin tone, though. It’s just a modifier, and it can make any random modification, even if it’s just “more permutations”.
Random gender
🧑🧑🧑🧑🧑🧑🧑🧑🧑🧑🧑🧑
Same deal as above; you can add male and female modifiers, or not. Make that base three because the not-specified option in Noto provides a perfectly good option as well.
Random hair colour and age
🧓🧒👶🧓🧒👶🧓🧒👶🧓🧒👶
I skipped these because it wasn’t going to affect many emoji by default. And more permutations is just more work and more storage and more problems; and I already had enough of all those things.
A stupid project name
The idea of imposing an even distribution of skin tones and genders across all emoji is what puts the “DEI” into the “DEImoji” project name.
Not to coment on anybody’s politics or ideals, of course. It’s just maths, and the original plan was working its way up to the next step, before I decided to make fun of how I got there.
Disconnecting LFSRs from skin and gender modifiers
🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟
As mentioned already, not all emoji can change skin colour or gender or hair colour. But that doesn’t prohibit the use of the combining markers to generate other variations.
Zombies, for example, have their own skin tone. So what can be done instead is to just make a bunch of random zombies with different looks, and mix them up into five variants of pairs, and five variants of trios. Then the random mix of pairs and trios helps to break up the regularity even further.
🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟
🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟
🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟
🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟
🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟
🧟🧟🧟🧟🧟🧟🧟🧟🧟🧟
This is what I had in mind at the outset; that I could make a horde of zombies look more varied by throwing random modifiers at them, thereby avoiding all the extra work of making a lot of different zombies by myself. But the combining rules just weren’t there. I would have had to do it the hard way; but then I got the idea to make AI do it for me.
Where things get difficult
It’s actually a bad idea
Just like it would be nonsense to add random diacritics to latin letters when nobody asked for them, forcing a skin tone or gender onto a Unicode codepoint that was entered without those, and in some cases defined to reject them, is a failure to let the user write what they meant to write. It adds spurious detail to their message.
That’s always been a risk in Unicode, where different fonts draw the same codepoint in different ways leading to different interpretations. It’s a whole lot worse when the differences are already codified explicitly in the standard, and then those explicit differences are added despite the author’s intent.
A much more appropriate implementation would just distribute a generic “random-variant-X” modifier across the string and then combine or discard as appropriate. Yellow people would stay yellow, but their clothes might change colour instead.
Longer generators
The longer you make a generator, the harder it is to seed. This means that it’s likely to start with the same pattern and carry on with the same pattern, and then the string will end before feedback can make it interesting.
PRNG seeding
My original plan was that I would scan a bunch of surrounding text to establish some kind of randomised starting state for the LFSRs. This fell through almost immediately. What I soon realised is that an emoji font is the fallback font that the renderer will switch to when its regular text can’t provide a glyph. That switch is a barrier to external context. You can’t hash the text leading up to a string of emoji in order to establish a random starting state.
The effect of that is that every string of the same characters starts the same way and continues the same way. The runners always wear the same shirts and follow the same pattern from that point on, and there’s no entropy source to mix it up and make it varied. Under normal conditions you probably don’t see more than half a dozen emoji strung together, and they’ll always be the same variants up to the end of the string.
A small mitigation for this is to hash the whole string ahead of time. At least this way you get to make the best use of everything that is available. Different length strings of the same character can start differently, and continue differently, even if same-length strings must always be the same.
RTL PRNG seeding
To achieve whole-string seeding it’s possible to make a right-to-left rule set, which iterates from the end of the string back to the beginning, which can integrate characters in the string into a running hash which then gets stored at the start of the string. The result of that pass can then be used by the PRNGs to go directly to a starting state which integrates influence from the entire string. Any variation anywhere in the string can lead to a different starting condition.
But the string still ends when the font changes. So a space or a period or an obscure glyph that the main emoji font doesn’t support resets the whole game.
Performance
Normally these are very short strings (unfortunate for variety) and the rules are linear, so it’s not a grossly disproportionate cost. However, with a very long string these rules can interact badly with line wrapping.
What happens is that the renderer has to figure out where to cut the string. Those cuts are decided by some Unicode stuff, and that’ll do whatever it does without being affected by this. However, to get the length of the string to decide where to cut you have to work through these shaping rules. Once you cut it you then have to double-check that the cut didn’t change the lengths of the two pieces by interrupting a shaping rule.
In order to determine whether or not the cut changed the answer HarfBuzz keeps a running dependency check along the shaped string, indicating whether a cut requires another shaping run to compensate, and how far that work must extend before the old work can be re-used.
And by making the initial state of a PRNG depend on the whole string means that there is no place to cut which is free of that requirement. And this is where quadratic time starts to become a risk for very long strings.
So… just don’t do that, I guess?
Improving performance
It is possible, but quite fiddly, to limit the length of the readahead. You can use forward rules to drop periodic barriers which interrupt the entropy sweeps. The challenge is to define such a rule in a way that doesn’t itself straddle the barrier and cause a new dependency there.
I fiddled with this a bit and then decided that it wasn’t worth the complexity, and I defer to my previous solution. Just don’t do that. Keep strings sensibly sized.
🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻
🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉
🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
💰💰💰💰💰💰💰💰💰💰💰💰
🎆🎆🎆🎆🎆🎆🎆🎆🎆🎆🎆🎆