mathr / blog / #

Fonts in GridFlow

Fonts in GridFlow

I've been playing around with fonts in Pd/GridFlow. GridFlow fonts are 4-dimensional grids, with dimension Dim[N,H,W,C], which can be imagined as an N-vector of HxWxC images. Initially I implemented something with 1-bit fonts, with C=1 and the values in the grid cells being either 0 or 1 for transparent or opaque, which was ok, but then I realised this was a needless limitation. Now I have settled on 4-channel fonts, in RGBA format, with values from 0 to 255 in each channel.

To make fonts, I've been using Public Domain images from the Open Clip Art Library. Luckily Gentoo provides an openclipart package, making it super-easy to download all the images in SVG format with PNG previews. Then, I used Inkscape to export each "interesting" SVG file to 512x512x4 PNG format (for some, I then used Gimp to resize the canvas to center the image). Finally I chose a reasonably sensible order for the images, and renamed them all to 01.png, 02.png, etc. 00.png is the same in all fonts, namely 100% transparent everywhere. The final step in making a Gridflow font is converting the sequence of images to a single 4-D grid, which is easily accomplished.

Then comes the fun part - using the fonts! Basically you provide a Dim[N,H,W,C] font, and then each Dim[Q,P,1] grid of character numbers you feed in gets converted to a Dim[Q*H,P*W,C] image. Then you can use [#layer] to overlay on top of a background image (if the font is RGBA and the background is RGB), or do any number of other things with it using any other number of Gridflow objects.