Randomized Comic Lettering Font - Code help needed

Greetings Typohiles!

I have been lurking this forum for quite awhile and now that I have run into a serious fontmaking problem myself I could think of no better people to turn to than the Typophiles.

So here is my project: this is part of my final thesis, so I am pretty desperate in making it work. The basic idea behind it all is create a font that will—via script–generate the outlines of each glyph that is typed. So if a user were to type one line, erase it and then type the same line afterwards, the glyphs would come out completely different.

This is why the working title for this font is “Aaaargh!!”.

Unlike with Beowolf, whose PostScript method will render the changes applied to the letters only in print, this font is supposed to do it on screen. From what I have gathered so far, this is possible with OpenType-fonts as they allow the inclusion of Python scripts. These in turn can manipulate glyph outlines, positioning, etc.

I have no idea how to script Python. And while I do have some experience with actionscripting in Flash and the syntax is pretty similar, what I need here is way beyond the scope of my skills. First, let me show you what I mean to do:

Phase 1: Generating random glyph outlines by interpolation of several “Master Phases”.

Fig 1: The master phases, shown with very little variance here. This will effect on the degree of “mutation” the interpolation will output. Compare Fig. 5 and 6.

Fig 2: Master phases, with more variance between the glyphs this time.

Fig 3: The master phases, overlayed. The blue areas show the boundaries of of movement the interpolation has for placing the nodes. The green areas stand for the possible positions of the handles. These polygons are created by the x/y-coordinates of the respective points in the master phases.

Fig 4: This figure demonstrates why four master phases are in use. Interpolation requires, naturally, a minimum of two phases. If more than two are used however, the degree of possible variations multiplies. This also enables a better simulation of variation within characters that ahndwriting would produce as body machanics and the flow of writing influence the appearance of characters in writing.

Fig 5: Variation is even more noticeable when more differently styled masters are used. Enjoyably, the interpolated phases are very consistent in style, so even though a degree of randomness is introduced into the character outlines, they still look like they belong together.

Fig 6: Masters and interpolated characters in a row (low variance).

Fig 7: Masters and interpolated characters in a row (high variance).

Fig 8: The introduction of two additional parameters that randomly rotate and scale one out of five characters are supposed to further simulate the changing angles of strokes in handwriting.

Phase 2: Expanding the basic lines with tools to true outlines

Fig 9: Now that the characteres base strokes are randomized, they get expanded by a “tooltip” which is a geomtrical shape–although more complex shapes would also be concievable–that is applied over the length of the path.
In this stage, the tooltip is still static, I am however considering adding another parameter to its rotation to make it react to changes in the path.

Fig 10: After the base strokes are expanded, terminators that simulate the dynamics of starting/ending a stroke and the slight bleeding that occurs when the writing tool rest on or is pulled away from a surface.
As of now, the method in creating these is rather primitve, taking the last position of the tool applied to the outline, moving a copy of this along the direction of the path, rotating an scaling it and the connect the extrema of those two shapes.
This will change though, as soon as I can find a method for doing so.

Phase 3: Altering the baseline

Fig 11: The circular movement of the wrist when writing left to right results in the lines moving slightly upward until the hand is moved to the right for an easier writing position. To encorparate this effect, the first character of the first syllable is moved slightly below the baseline and a random character between 10-15 characters to the right is chosen and has its baseline lifted. The positions of the characters in between those extrema are interpolated in non-linear fashion, resulting in a slight curvature of the baseline.
I am still working on the selection criteria, so they remain subject to change.
Still I would like the frequency and amplitude of the basline undulation to be controllable factors.

So far this is what I would like to. Which leads me to the problem of how to do it.
Is what I have cooked up here possible in Python? Has anybody tried to implement this before? Do you know of anybody who would like to collaborate in such a project or can be hired for it? Your help would be much appreciated!

28 Mar 2008 — 1:00am

update: as Miguel points out, live update while typing cannot be done with OpenType, at least not in the way I wanted to do it…

There might be a way of faking the effect though by using the various ligatures and alternates features. Obviously I would prefer the real deal.

If anyone of you guys see a way of still making it fly, please let me know.


I'm afraid it is not possible to get true random in OpenType. The random effect of Beowolf used to be realized in old PostScript Type 3 font format.
You will have to include many alternative glyphs and switch them via layout features, so something at least similar to random will be happening.
FF Kosmik OT, FF Beowolf OT and FF BeoSans OT do it this way, more to come.


This is an attempt to take you in a new direction complete with rationale so watch out!

Real randomness may not be completely desirable speaking anyway. When you look at real comic book writing done by a pro the changes you see have an element of chance built in. I don't deny that. And that's the part that is interesting to you at the moment - but it isn't all chance. Not by a long shot! And less & less so as the better the lettering artist is. I don't mean that they become more like a machine but that their lettering responds to context more. Put another way, the variations you get with real comic book lettering start to be the result of interactions between letters. I think it would be more pleasing & powerful to detail what the interactions are and build on that. I am actually doing some like that but for text faces and it's hellaciously complicated. But fun! Very fun. With enough interactions the font will look quite random even if it is just psudo-random. And better than that it will feel more like real hand lettering and best of all it will please the eye more than a real random font can.

You might want to look carefully at Tal Leming's work. It's not the same style but his programming for "Ed Interlock" is the kind of thing I mean.

Good luck!

I completely agree with your view on total randomness being a fonts demise. After all, letters are supposed to be read and to fulfill that requirement they must adhere to a constant shape. Which is entirely the opposite of randomness.

So what I want could be described as a randomized variation. You control the degree in which the changes take place, in my case by the variance in the master faces, but _ not the direction_ in which it goes.

I guess there will be no other choice for me but to give up on the random generation if I want to have an OpenType font in the end.

Are there any other formats that could support what I need from them?

I remember reading something quite awhile about a font or tool called "Metamorfont" that experimented with random glyph alteration. Was this thing just in an experimental stage? Has it been abandoned? Anyone know?

You make a good a fine ( excellent ) distinction there. That said I think that it's still a question of how noisy not if it's noisy. If that makes sense. It may be that gentle noise is a good thing.

Surely by now somebody has pointed at the sample OpenType AFDKO/FontLab code chunks I posted for pretty much this exact purpose. One of the bits I specifically devised for an OpenType implementation of Beowolf, even.




Actually, no, no one has, thanks Thomas. I googled this two or three weeks back when I was trying to figure out a way to alternate glyph outlines.

I was a little irritated by you calling– I'm not sure what the right expression for that is– "function" so many times, like here (I tried to interprete what the script does in the comments):

`feature calt {

Connection or other contextual Forms


lookup rotate { sub @default @default' by @alt1; # shouldn't this be calt1? sub @calt1 @default' by @alt2; # shouldn't this be calt2? sub @calt2 @default' by @calt3; sub @calt3 @default' by @calt4; sub @calt4 @default' by @calt5; sub @calt5 @default' by @calt6; sub @calt6 @default' by @calt7; } rotate; # this creates a "function" called rotate

that replaces a glyph from font 1 with one from font 2,

one from font 2 with one from font 3, etc.

lookup rotate; lookup rotate; lookup rotate; lookup rotate; lookup rotate; lookup rotate; lookup rotate; lookup rotate; lookup rotate; lookup rotate; lookup rotate; lookup rotate; lookup rotate; # call aforesaid function a couple of times } calt; `

I'm not sure why you called the function multiple times, but I'm guessing you did it so the calt-block needs not to be executed so often.

I really think that you can achieve great effects with contextual alternates and ligatures. Zapfino is living proof of their might.

The only reason for me not to start using contextual alternates right away is that I wanted to give a font what handwriting has inbuilt by nature: a feature that would make every glyph rendered different from the ones before.

I am currently drawing the key characters of the base font, so I will definitely go deeper on the calt-feature in future.

Thanks again for sharing your code, Thomas, much appreciated.

By the way:
If a German says "I was irritated", most likely (s)he translated "ich war irritiert" too literally. "Ich war irritiert" means "I didn't understand why" or "I was wondering why" rather than "I was upset" ...
One of my favorite mistakes. A dear French collegue made me aware of this not too long ago when I used this phrase again.  :D

I’m not sure why you called the function multiple times, but I’m guessing you did it so the calt-block needs not to be executed so often.

Benjamin, you might wish to take a look at this earlier thread: Opentype Random Contextual Alternates

Oh, and good luck too. This can get a touch maddening at times.


Hooray for Thomas! I may want to use this kind of thing eventually.

I finally gave some thought to Thomas' code, and as far as I can tell it doesn't have to be as complex in order to achieve the same results. Analysis here http://typophile.com/node/19625#comment-269297

Karsten: Totally true. "Irritated" is one of those words that has a counterpart in the other language that takes a completely different tone. I was just wondering what the code was doing. ^^

rcc: I hope this will not become a self-fulfilling prophecy.

Miguel: Great! Reading your latest post, I finally got the syntax. I had misinterpreted the substitution argument.

sub @default @default' by @alt1;

So, the part after sub marks the glyph sequence that is looked for, the apostrophe marks the glyph that is to be substituted and the part after by gives the glyph that substitutes the apostrophied one. Finally got it.

Yes, there are several ways that old code of mine could be simplified. By now Miguel is probably many times better at coding this stuff than I ever was, and I've forgotten half of what I used to know do to disuse.

One of the reasons for the complexity was to make it more "showy" for demo purposes. Specifically, I wanted to make it so that adding another letter changed all the preceding letters. If one doesn't care about that, it can be made much simpler. But even given that, there are ways to simplify it.



I don't mean to be nagging, but I haven't yet given up on the randomness concept. As far as I see the situation, the only thing stopping randomly generated letters from appearing on screen is the OpenType format.

So, I've been thinking, as Adobe applications support plugins, why not write a plugin for InDesign/Illustrator/Photoshop that simply takes randomly generated PostScript data and renders it on screen?

Has this been done or at least tried yet?

Do you know of anybody who can write code for this?

I will try to extract some background on this from the web and also pester the FontLab and Adobe guys about it. If you have an idea, please share.

Best regards, Benjamin

Re: special plugins. I think before you commit to a large and complex project, you just do some tests to find out how much randomness you actually need. I think for cartoon lettering, if your glyphset has 4-6 alternates it's doing just fine. When subs prevent glyph pairs, the eye is already 90% fooled.

Re: special code to render glyphs. If you already have outlines for all the extremes, and they happen to be point compatible, you could use robofab and glyphmath (or Tal's FontMath) to make a collection of intermediates. This is probably the easiest to try out. Make a script which has access to all the masters, interpolate each glyph from all masters with random (or non-random) factors and store the results in a new font. Like a multiple master, but with more master. Or like Superpolator, but without the app.

Re: illustrator pen tools. If you want to build something which applies a shape as a pen tool to a skeleton path, you're in very deep water. Tracing the shape made by the tool, collecting the points and building sane contours is heavy duty bezier math. Stuff like this exists, but it's likely that sharing goes beyond the polite help and discourse of this forum.

My 2¢ would be: learn some robofab code and try stuff yourself, see where you end up. My hunch is you'll need much less than you think to get good results. It will also get you results faster than waiting for Adobe or FL to implement it :)

Cheers, Erik

"... the only thing stopping randomly generated letters from appearing on screen is the OpenType format."

And the overarching desire as represented in that format, the OS and applications that support them, that fonts not contain "open-ended" or potentially infinite loops.

There is always the glyph window in InDesign. In that case, the only thing stopping randomly generated letters, is human energy.

"Are there any other formats that could support what I need from them?"

Your thesis goes against reading, and in your strict desire to write the completely unreaderly thing, you have left the map.

Good luck and Cheers!

Thanks for the encouragement and guidance, much appreciated. I have a pretty good idea now of what to do, I just hope I can manage all of it in the time I have left.

There is always the glyph window in InDesign. In that case, the only thing stopping randomly generated letters, is human energy.
Not quite sure what you mean by that. Would mind elaborating a little?

Your thesis goes against reading, and in your strict desire to write the completely unreaderly thing, you have left the map.
I don't see why the idea of putting variation into glyph outlines would mean hampering readability. From what I have gathered from my interpolation experiments this far, the stability and readability is excellent, especially compared to genuine handwriting.
Am I simply missing your point here?

View original article