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
a=dejavu-2.22
b=dejavu-2.23

vsdir="${a}_vs_${b}"
mkdir $vsdir

for f in $(find $a -name '*.pdf') ; do
f=$(basename $f)
apng=${a}/${f/.pdf/}
bpng=${b}/${f/.pdf/}
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}
else
echo " - ${p}"
fi
done
done

This is what you get when a glyph was modified:

In case of newly introduced glyphs you get the following:


Comments:
brilliant tip, thanks for sharing it.

Kudos for your amazing work in this area!

We should probably integrate this nifty comparison feature with the font review by the debian pkg-fonts team . Maybe between unstable and testing?
 
Hello. And Bye. Thank you very much.
 
Post a Comment

<< Home

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