Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Unfortunately the author is using the font in Photoshop but I am going to look into that thank you
Copy link to clipboard
Copied
I still cant figure out what to change on the script?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Hey @benbneben, I've written a simple script that does what you ask. Let me know if it works in your case.
- Mark
/**
* Randomise text case.
* @author m1b
* @discussion https://community.adobe.com/t5/illustrator-discussions/looking-for-a-way-to-randomize-font-alternates/m-p/14283044
*/
(function () {
if (app.documents.length === 0) {
alert('Please open a document and try again.');
return;
}
randomizeTextCase(app.activeDocument.selection);
})();
/**
* Randomizes case of each character in text.
* Equal chance of upper or lower, except will
* deliberately alternate for same letters in
* the same word, so that double letters will
* always differ, eg. "bOok" but not "bOOk".
* @author m1b
* @version 2023-12-01
* @param {TextRange|TextFrame|Array|GroupItem} text - the text to search.
*/
function randomizeTextCase(text) {
if (text == undefined)
throw Error('randomizeTextCase: bad `text` supplied.');
if (
(
// to bypass bug in TextFrames object:
text.typename
&& text.typename == 'TextFrames'
)
|| text.constructor.name == 'Stories'
|| text.constructor.name == 'Array'
) {
// handle array of text frames
for (var i = text.length - 1; i >= 0; i--)
randomizeTextCase(text[i]);
return;
}
else if (text.constructor.name == 'GroupItem') {
// handle the group's items
for (var i = text.pageItems.length - 1; i >= 0; i--)
randomizeTextCase(text.pageItems[i]);
return;
}
else if (text.constructor.name == 'Document')
return randomizeTextCase(text.stories);
else if (
text.constructor.name == 'Story'
|| text.constructor.name == 'TextFrame'
)
text = text.textRange;
else if (text.constructor.name !== 'TextRange')
return;
// do the randomization
var words = text.words,
characters,
cases;
for (var i = 0; i < words.length; i++) {
characters = words[i].characters;
cases = {};
for (var j = 0; j < characters.length; j++) {
var ch = characters[j],
lower = ch.contents.toLowerCase(),
changeToUpper = Math.random() < 0.5 ? 1 : 0;
if (
changeToUpper === 1
&& cases[lower] !== 1
) {
ch.contents = ch.contents.toUpperCase();
cases[lower] = 1;
}
else if (cases[lower] === 0) {
ch.contents = ch.contents.toUpperCase();
cases[lower] = 1;
}
else {
ch.contents = lower;
cases[lower] = 0;
}
}
}
};
Copy link to clipboard
Copied
Hello everyone,
I recently created a font with Fontself with three alternates for each lowercase letter. I am also searching for a way to automate glyphs alternates, in Photoshop (not InDesign) based on the otf file used in the program. And hopefully not have to do it all manually. The best option would be to have a rotation between the three glyphs (1,2,3,1,2,3...) or completely random, or with rules like your explained earlier.... Any idea if implementing a script is the way to go in Photoshop ? Or code ? I'm not familiar with any of those procedures. So if I want to try and change the script for Photoshop do you know where to start ? I'm sorry for troubling you with my beginner questions.
Thank you all for your help !
Copy link to clipboard
Copied
For Photoshop you might need to do it in the font.
Copy link to clipboard
Copied
Hi @celiad87948489, the best way to do this is to use opentype substitution, built into the font (see my comment above). However, it can probably be done with a script, but because scripting text in Photoshop is *very* different to doing it in Illustrator, I doubt that this script will help much.
I suggest you ask this question in the Photoshop forum along with a demo .psd with a text layer set up the way you want. This means that a photoshop scripter can look at the demo file and see the glyph names or unicodes that they will need to manipulate. Maybe a text layer with "AAABBBCCCDDDEEE ..." with one of each glyph variant?
But as I said earlier, if you were able to do it in the font—or pay someone to do it—it would work automatically in any opentype-capable app.
- Mark