A subroutine for matching fonts to patterns