Thursday, February 21, 2008


Font tips #2: comparing fonts

Being able to compare images can be really useful sometimes; I found it extremely helpful when I wanted to know what changed between two releases of the same font.

Imagemagick does the trick via a set of really powerful command line tools.

Here's a very simple demonstration:

pango-view --font="DejaVu Sans Mono" -t "Hello World" -w 180 -q -o a.png
pango-view --font="DejaVu Sans Mono" -t "Hello world" -w 180 -q -o b.png
compare a.png b.png hello_diff.png

which results in the following output:

We can now apply the previous tip to something more useful; let's say we want to know how the glyphs in a font changed from a release to another. In a previous post I've explained how to render all the glyphs into a nice PDF using fntsample; we just need to create PDFs for both releases and compare them... ain't that easy?

# Let's suppose you have already created PDF files inside the following dirs

mkdir $vsdir

for f in $(find $a -name '*.pdf') ; do
f=$(basename $f)
mkdir ${apng} ${bpng}

echo "*** ${f} ***"

# pdf -> pngs
convert ${a}/${f} ${apng}/${f/.pdf/}.png
convert ${b}/${f} ${bpng}/${f/.pdf/}.png

# compare pngs and, if different, show whre they differ in a png
for p in $(find ${apng} -name '*.png') ; do
p=$(basename $p)
meas=$(compare -metric AE ${apng}/${p} ${bpng}/${p} ${vsdir}/${p} 2>&1)
if [ ${meas} -eq 0 ] ; then
rm ${vsdir}/${p} ${apng}/${p} ${bpng}/${p}
echo " - ${p}"

This is what you get when a glyph was modified:

In case of newly introduced glyphs you get the following:

Wednesday, February 20, 2008


Font tips #1: PDF charts with fntsample

Around the end of 2006 I come up with the idea of setting up something I called font-machine: a collection of scripts / utilities, intended to improve quality of fonts by defining and implementing automatic tests able to catch errors and provide screenshots.

Some pioneering work on this area was done a while ago by Miriam who set up a page showing how fonts currently in Debian look like.

I did something similar focusing on the fonts used by the Debian graphical installer (will write a separate post to describe the way it works).

I'll start describing the tools which I've used more frequently; of course my preference goes to the ones which can be run non-interactively: those that can be invoked inside shell scrips and keep your CPU busy!

fntsample is probably one of the programs I've used more frequently during the last months: it was written by Eugeniy Meshcheryakov, who also made it available as a Debian package, and creates really nice and professional PDF / PS charts showing all the glyphs contained in a particular font file.

The following code snippet shows how you can use fntsample to create pdf charts for each of the ttf files contained in ttf-dejavu package (will often refer to this package since I maintain it :-) ):

deb=$(basename ${font})
wget $font
dpkg -x ${deb} ${deb/.deb/}

mkdir $outdir
for ttf in $(find ${deb/.deb/} -name '*.ttf') ; do
pdf="$(basename ${ttf} | sed -e "s|\.ttf$|\.pdf|")"
fntsample -f ${ttf} -o ${outdir}/${pdf} -l > ${outdir}/${pdf/.pdf/.outline}
pdfoutline ${outdir}/${pdf} ${outdir}/${pdf/.pdf/.outline} ${outdir}/${pdf}

Note that PDF files will have useful outlines (aka bookmarks) courtesy of the pdfoutline tool shipped with the fntsample package.

Results are IMHO very imperessive!

PS: looking at the above chart for Cyrillic, I've just noticed the glyphs are ordered as to read "SEX"... I did not choose that particular chart snippet on purpose!

This page is powered by Blogger. Isn't yours?