fontations icon indicating copy to clipboard operation
fontations copied to clipboard

roundtripping fontc-built Oswald's cmap table with ttx mysteriously halves its size

Open anthrotype opened this issue 2 years ago • 9 comments

I'm still not sure why

$ git clone https://github.com/googlefonts/OswaldFont
$ cd OswaldFont
$ fontc -s sources/Oswald.glyphs
$ ttx -q -o - build/font.ttf | ttx -q -o build/font#1.ttf -
$ ls build/*.ttf
build/font#1.ttf  build/font.ttf
$ diff -u <(ttx -q -o - -t cmap build/font.ttf) <(ttx -q -o - -t cmap build/font#1.ttf)
$ echo $?
0

So far no diffs in the high-level XML content after roundtripping through ttx, but if I compare the cmap table sizes before and after ttx, I get:

$ diff -u <(ttx -l build/font.ttf | grep cmap) <(ttx -l build/font#1.ttf | grep cmap)
      tag     checksum    length    offset
      ----  ----------  --------  --------
-     cmap  0x8D57590D      6212     30844
+     cmap  0x90BB83AA      2392      4036

The fonttools generated cmap is less than half the size of the fontc/write-fonts generated one.. Why?

anthrotype avatar Sep 25 '23 15:09 anthrotype

interesting, will take a look. :)

cmyr avatar Sep 25 '23 16:09 cmyr

The fonttools generated cmap is less than half the size of the fontc/write-fonts generated one.. Why?

For beginners, table sharing?

behdad avatar Sep 25 '23 20:09 behdad

Also see https://github.com/fonttools/fonttools/blob/main/Lib/fontTools/ttLib/tables/_c_m_a_p.py#L783

behdad avatar Sep 25 '23 20:09 behdad

Also see https://github.com/fonttools/fonttools/blob/main/Lib/fontTools/ttLib/tables/_c_m_a_p.py#L783

I believe it's this. The number of segments is 772 in fontc-generated font, and 103 in fonttools.

behdad avatar Sep 25 '23 20:09 behdad

The fonttools generated cmap is less than half the size of the fontc/write-fonts generated one.. Why?

For beginners, table sharing?

Ruled this out.

behdad avatar Sep 25 '23 20:09 behdad

Also see https://github.com/fonttools/fonttools/blob/main/Lib/fontTools/ttLib/tables/_c_m_a_p.py#L783

I believe it's this. The number of segments is 772 in fontc-generated font, and 103 in fonttools.

And length of glyphIndexArray is 0 in fontc one, and 766 in fonttools. So, the fontc code is not using the glyphIndexArray mechanism at all.

behdad avatar Sep 25 '23 20:09 behdad

So, the fontc code is not using the glyphIndexArray mechanism at all.

https://github.com/googlefonts/fontations/blob/main/write-fonts/src/tables/cmap.rs#L56

behdad avatar Sep 25 '23 20:09 behdad

Also see https://github.com/fonttools/fonttools/blob/main/Lib/fontTools/ttLib/tables/_c_m_a_p.py#L783

And more importantly: https://github.com/fonttools/fonttools/blob/0a3360e52727cdefce2e9b28286b074faf99033c/Lib/fontTools/ttLib/tables/_c_m_a_p.py#L994-L1010

behdad avatar Sep 25 '23 21:09 behdad

thanks behdad for investigating this! Looks like @rsheeter already had opened an issue about this at the time it was first PR'ed, linking to the same fonttools code: https://github.com/googlefonts/fontations/issues/282

anthrotype avatar Sep 26 '23 12:09 anthrotype