Skip to main content
Amybeth M. ACI G7
Community Expert
Community Expert
December 21, 2022
Question

Looking for a way to randomize font alternates

  • December 21, 2022
  • 3 replies
  • 3003 views

I created an OTF font using the Fontself plugin, which is a handwriting font for a graphic novel.

Uppercase and Lowercase (done in the Illustrator version of Fonself).

There are 4 alternates for each glyph. Would like the font to cycle through the alternates as I type. 

I have found articles on contextual coding but I was wondering if anyone knows what I can use, script perhaps with this allready created font.

This topic has been closed for replies.

3 replies

m1b
Community Expert
Community Expert
December 22, 2022

Hi @Amybeth M. ACI G7, I think the most robust way to achieve what you want is to use some clever OpenType Substitution Rules in your font. Basically the idea is that, while still deterministic, the rules can be sufficiently complex (and clever) to mix glyph alternates apparently randomly. Here is an interesting article that talks about the thinking involved in make a font randomised. It unfortunately doesn't show any example rulesets, which would have been cool. In the simplest case, you can replace glyphs E E' with E E.001 so that when the user types "BEER" the 2nd E doesn't match the first.

I'm not familiar with Fontself, and I'm not sure it gives much control over OpenType Substitution, so you may have to look for another tool if you decide to go this way.

- Mark

Amybeth M. ACI G7
Community Expert
Community Expert
December 22, 2022

Thank you all for the information. Where Fontself is easy to use and an "in application"plug-in. (and works very well), it dosen't have alot of the options to code each glyph, as you create the font like some of the more expensive font creation software. Something to look into. I am going to play with the Indesign script. THX

Amybeth MACI G7 Certified Expert
Participant
December 7, 2023

Hi Amybeth - did you make any progress on this? - im in a similar situaion, having created a hand drawn font with Fontself (which i was very impressed with). Mine is all uppercase so i have used the lowercase set as a way to get some variance in the handwriting, and avoid obvious repetition of identical letters, but would like to find a way to automate RanDOm uppercase / lowercase. Hope you found a solution!

Monika Gause
Community Expert
Community Expert
December 21, 2022

Looks like it's possible to access this in InDesign: https://github.com/samiartur/Character-Variant-Java-Script-for-Indesign

 

This might or might not help with scripting Illustrator.

Amybeth M. ACI G7
Community Expert
Community Expert
December 21, 2022

Unfortunately the author is using the font in Photoshop but I am going to look into that  thank you 

Amybeth MACI G7 Certified Expert
Mylenium
Legend
December 21, 2022

You probably could use good old string.fromCharCode() in a script and randomize the character code in the parentheses. This wouldn't be interactive, of course, but could work. You just need to come up with a set of rules when to use what.

 

Mylenium 

Inspiring
December 22, 2022

To clarify, alternates use different Unicode codepoints to the canonical characters, typically somewhere in the U+E000–U+F8FF private use range. To insert alternate characters in AI using JSX, you need to know their codepoints.

 

e.g. OP might build a lookup table that maps the canonical A–Z, a–z, etc characters to their alternates. For each character in the original text, look up its alternate characters, pick one at random, and substitute:

 

var characterMap = {
  'A': 'A\ue001\ue002\ue003',
  'B': 'B\ue004\ue005\ue006',
  'C': ...
};

var oldText = someTextFrame.contents;

var newText = '';
for (var i = 0; i < oldText.length; i++) {
  var c = oldText[i];
  var alternates = characterMap[c];
  if (alternates) {
    c = alternates[Math.floor(Math.random() * alternates.length)];
  }
  newText += c;
}
someTextFrame.contents = newText;

 

 

FontForge is ugly but free and should suffice for examining the generated font’s glyph table to determine the alternates’ code points.