#989626 diffoscope: when comparing fonts with .ttx files, convert the font to .ttx first

#989626#5
Date:
2021-06-09 01:13:39 UTC
From:
To:
diffoscope currently prints a hex dump when comparing a TTF font with a
.ttx XML dump of a TTF font. If it used ttx (from fonttools) to convert
that TTF font to .ttx instead, then the comparison would become an XML
diff, which diffoscope treats as a text diff, which is better than hex.

   $ git clone -q https://gitlab.gnome.org/GNOME/gtksourceview

   $ diffoscope gtksourceview/data/fonts/BuilderBlocks.tt{f,x}
   --- gtksourceview/data/fonts/BuilderBlocks.ttf
   +++ gtksourceview/data/fonts/BuilderBlocks.ttx
   @@ -1,28 +1,259 @@
   -00000000: 0001 0000 0008 0080 0003 0000 636d 6170  ............cmap
   -00000010: 0021 0258 0000 0114 0000 004c 676c 7966  .!.X.......Lglyf
   -00000020: 2644 7e48 0000 016c 0000 0030 6865 6164  &D~H...l...0head
   -00000030: 0733 9950 0000 008c 0000 0036 6868 6561  .3.P.......6hhea
   -00000040: 0c01 0402 0000 00c4 0000 0024 686d 7478  ...........$hmtx
   -00000050: 0400 0000 0000 0108 0000 000a 6c6f 6361  ............loca
   -00000060: 0024 000c 0000 0160 0000 000a 6d61 7870  .$.....`....maxp
   -00000070: 0006 0005 0000 00e8 0000 0020 6e61 6d65  ........... name
   ...
   +00000000: 3c3f 786d 6c20 7665 7273 696f 6e3d 2231  <?xml version="1
   +00000010: 2e30 2220 656e 636f 6469 6e67 3d22 7574  .0" encoding="ut
   +00000020: 662d 3822 3f3e 0a3c 7474 466f 6e74 2073  f-8"?>.<ttFont s
   +00000030: 666e 7456 6572 7369 6f6e 3d22 5c78 3030  fntVersion="\x00
   +00000040: 5c78 3031 5c78 3030 5c78 3030 2220 7474  \x01\x00\x00" tt
   +00000050: 4c69 6256 6572 7369 6f6e 3d22 322e 3422  LibVersion="2.4"
   +00000060: 3e0a 0a20 203c 476c 7970 684f 7264 6572  >..  <GlyphOrder
   +00000070: 3e0a 2020 2020 3c21 2d2d 2054 6865 2027  >.    <!-- The '
   ...

   $ dpkg -S `which ttx`
   fonttools: /usr/bin/ttx

   $ ttx -o gtksourceview/data/fonts/BuilderBlocks.ttf.ttx gtksourceview/data/fonts/BuilderBlocks.ttf
   Dumping "gtksourceview/data/fonts/BuilderBlocks.ttf" to "gtksourceview/data/fonts/BuilderBlocks.ttf.ttx"...
   Dumping 'GlyphOrder' table...
   Dumping 'head' table...
   Dumping 'hhea' table...
   Dumping 'maxp' table...
   Dumping 'hmtx' table...
   Dumping 'cmap' table...
   Dumping 'loca' table...
   Dumping 'glyf' table...
   Dumping 'name' table...

   $ diffoscope gtksourceview/data/fonts/BuilderBlocks{,.ttf}.ttx
   --- gtksourceview/data/fonts/BuilderBlocks.ttx
   +++ gtksourceview/data/fonts/BuilderBlocks.ttf.ttx
   @@ -1,65 +1,65 @@
   -<?xml version="1.0" encoding="utf-8"?>
   -<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="2.4">
   +<?xml version="1.0" encoding="UTF-8"?>
   +<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.19">

      <GlyphOrder>
        <!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
        <GlyphID id="0" name=".notdef"/>
   -    <GlyphID id="1" name="block"/>
   -    <GlyphID id="2" name="empty"/>
   -    <GlyphID id="3" name="smallblock"/>
   +    <GlyphID id="1" name="exclam"/>
   +    <GlyphID id="2" name="uni0001"/>
   +    <GlyphID id="3" name="a"/>
      </GlyphOrder>

      <head>
        <!-- Most of this table will be recalculated by the compiler -->
        <tableVersion value="1.0"/>
        <fontRevision value="1.0"/>
   -    <checkSumAdjustment value="0x2a3f4cae"/>
   +    <checkSumAdjustment value="0x6b7bfd56"/>
        <magicNumber value="0x5f0f3cf5"/>
        <flags value="00000000 00000010"/>
        <unitsPerEm value="2048"/>
        <created value="Mon Oct  7 00:00:00 2013"/>
   -    <modified value="Fri Jan 31 15:45:50 2014"/>
   +    <modified value="Tue Aug  1 21:25:46 2017"/>
        <xMin value="0"/>
        <yMin value="0"/>
   -    <xMax value="0"/>
   -    <yMax value="0"/>
   +    <xMax value="1024"/>
   +    <yMax value="2048"/>
        <macStyle value="00000000 00000000"/>
        <lowestRecPPEM value="1"/>
        <fontDirectionHint value="2"/>
        <indexToLocFormat value="0"/>
        <glyphDataFormat value="0"/>
      </head>
   ...