An introduction. My teacher from university is kind of weird. She wants all essays handwritten by students and this is is a bit exaggerated given the fact the we live in computers era. I created a font family that resembles my handwriting and saved is as .ttf and installed it on windows and use it in word. It doesn't seem convincing, so I was wondering: If I create 100 ttf each with slight variations of a letter, is there a way in word, when you type a letter, to chose randomly from those 100 ttf files to make the writing seem more organic, because I'm not a callighraphist, I can't write a letter twice exactly the same way, so a slight variation would make it more convincing.
If it is not possible I have a way using HTML + JS:
document.getElementById("randomize").disabled=true;
function setupFonts(){
var handwritten = document.getElementsByTagName("handwritten")[0];
var raw_text = handwritten.innerHTML; //no tags in handwritten tag body
var taggedText = "";
var fontTag = "</font><font>";
for(var i = 0; i < raw_text.length;i++){
if((/[a-zA-Z]/).test(raw_text.charAt(i))){
taggedText = taggedText.concat("<font>", raw_text.charAt(i), "</font>");
}
else{
taggedText = taggedText.concat(raw_text.charAt(i));
}
}
handwritten.innerHTML = taggedText;
document.getElementById("randomize").disabled=false;
}
function randomizeFonts(){
var fontNames = ['Arial', 'Verdana', 'Consolas']; //here will be listed the variations
var fontsArray = document.getElementsByTagName("font");
for(var i = 0; i < fontsArray.length;i++){
fontsArray[i].setAttribute("face", fontNames[Math.floor(Math.random()*fontNames.length)]);
}
}
<html>
<body>
<!-- Just 1 handwritten tag allowen on a page -->
<handwritten>
This is a sentence handwritten.
</handwritten>
<br>
<button id="setup" onclick="setupFonts()">Setup Fonts</button>
<button id="randomize" onclick="randomizeFonts()">Randomize Fonts</button>
</body>
<html>
It works, however if this is possible in word it would be better.
Rather than making 100 different font files, it’s possible to include alternate glyphs within an OpenType font itself. Then, the font can define when the different glyphs should be applied, using OpenType feature rules.
There are many fonts that already support these features kinds of features, and a common use case is for imitating calligraphy and handwriting to some degree. An especially comprehensive example is the font LiebeHeide.
That said, if you’re set on doing this with your own handwriting (and, as the other commenter mentioned, set on resolving your problem using a font rather than some other way), then you could add the alternate glyphs to your own font.
If you are able to produce an OpenType font, you should be able to add OpenType feature code to it. A lot of the specifics for this will depend on what set of tools you are using to produce the font.
Once you’ve been able to add, ex. an “A” glyph, and an alternate “A” glyph that is drawn differently, I’d recommend looking at the OpenType Cookbook by Tal Leming.
There, he discusses how to implement pseudo-randomization of glyphs using OpenType feature rules.
More complex randomization (ex. programatic randomization within the font, or modifying outlines on the fly), isn’t possible using the font alone, which is also described there. There is a “Random” rand
OpenType feature rule in the specification, but it probably isn’t supported reliably anywhere where you’d want to use the font.
For type designers and font developers, a pseudo-random technique like in the guidebook is a practical way to swap alternates in and out to make a font that imitates writing.
Since this font is presumably just for you to use, you have more options since you control where the font is going to be used as well. You might decide to only add the alternate glyphs within the font, and then randomly apply them outside the font using HTML & CSS as you’ve described, so you can have something “more random.” In that case, this technique for applying alternates in HTML & CSS might be useful for you.