Search code examples
fontsttx-fonttools

Finding the differences in two (probably OpenType) font files


I have the same font in two files, both without file extensions.

Both files begin with the type code OTTO, so the fonts must be OpenType.

When I add the file extension .otf and open the files in a font editor, they both look the same and contain the same glyphs.

But when I diff the files in Vim, some parts of the files differ, but since the code is unintelligible to me, I cannot understand what aspect of the font these parts of the files refer to.

How can I find out what the difference between these two font files is?


Solution

  • You should locate the tool ttx [1].

    That's a command line tool to convert a font file from OpenType format to an XML representation and back again.

    The XML representation is very easy to edit in any text editor (for minor changes to a font, for example). It should also be easy to (ab)use it as a format where you can do your comparison.

    So these commands should give you a starting point:

    ttx -l otf1file
    ttx -l otf2file
    

    The -l option does not yet dissect (and convert to XML) the font files. Instead, it prints an overview of tables like the following:

     Listing table info for "/Library/Fonts/WeidemannStd-Medium.otf":
         tag     checksum   length   offset
         ----  ----------  -------  -------
         BASE  0x3f624fba       52    24836
         CFF   0xec0764e1    18801     2752
         DSIG  0xa4d90535     5180    24888
         GPOS  0xffb60926     1456    23380
         GSUB  0x6de87013      812    22568
         OS/2  0x7c681439       96      320
         cmap  0x79e54a16      932     1788
         head  0xd391fc8f       54      220
         hhea  0x06fd0364       36      276
         hmtx  0xf9581b97     1012    21556
         maxp  0x00fd5000        6      312
         name  0x987b2db3     1370      416
         post  0xffb80032       32     2720
    

    Now that you are familiar with some of the table specifics, you may want to just look at these tables which are different. Assuming it's only the cmap and name tables:

    ttx -o otf1-cmap+name-tables.ttx -t cmap -t name otf1file
    ttx -o otf2-cmap+name-tables.ttx -t cmap -t name otf2file
    vimdiff otf1-cmap+name-tables.ttx otf2-cmap+name-tables.ttx
    

    In case all tables were different, you can create the complete fontfile's TTX dump by skipping the -t parameters:

    ttx -o otf1.ttx  otf1file
    ttx -o otf2.ttx  otf2file
    vimdiff otf1.ttx  otf2.ttx
    

    Update: Another useful tool to look into (also from the Adobe Type Tools repository) may be sfntdiff.

    But possibly the ttxn tool is what serves you best. Here is its self-description:

    "This tool is used to test if two fonts are functionally the same. It sorts and modifies the output from the ttx and tx tools to build a normalized text dump that eliminates differences due to issues such as OTL table record order, glyph order and subroutinzation differences. It writes one file for each table in the font. A good difference editor, such as BBEdit on the Mac, or UltraEdit on the PC, can then be used to compare the output files from two different fonts. It is particularly useful in comparing older and newer versions of the same font."


    [1]: TTX was originally developed by Just van Rossum in 1999 and maintained as an Open Source project on SourceForge (sf.net/projects/fonttools/). It is written in Python:

    1. Git Repository: github.com/adobe-type-tools/afdko.git (Look in the "afdko/FDK/Tools/${operatingsystem}/" subdirectory!)
    2. "Friendly" Fork of original repo, with lots of fixes, improvements and additions by Behdad Esfahbod: github.com/behdad/fonttools/