Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only include a format 4 cmap subtable when there are BMP codepoints #899

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Hoolean
Copy link
Collaborator

@Hoolean Hoolean commented Mar 5, 2025

Seeking thoughts on the below - a reasonable path to fewer diffs with fontc, or too dramatic a change given what shipped software might rely on, and we should change the the Rusty behaviour instead? As seen in the snapshots, this would mean we would ship TTFs with zero subtables for the first time.


This produces minutely smaller fonts when there are no characters represented inside of the Unicode BMP (U+0000 to U+FFFF), and matches fontations' current behaviour.

The OpenType specification state that a format 4 subtable is not mandatory, but that it may be included for backwards compatibility for legacy environments that do not support format 12. As in our case there are no overlapping codepoints, this suggests that we can drop the format 4 subtable entirely (at least, unless there has been software developed since that unconditionally assumes its existence).

Extra Notes

  • (!) On a re-read, in both fontations and ufo2ft we are not following the separate recommendation to include all BMP codepoints in the format 12 table too; this does not seem to have caused problems though. (ignore this, we explicitly extend the mapping to include)
  • In the case where this would result in 0 subtables, we still cannot drop cmap entirely, as it is a required table.

Note: this is a personal contribution independent of my employer, and so I've submitted from a fork under my personal profile and email to make this distinction

Hoolean added 2 commits March 5, 2025 23:03
This will produce slightly smaller fonts when there are no characters
represented inside of the Unicode BMP (U+0000 to U+FFFF), and matches
fontations' current behaviour:

https://github.com/googlefonts/fontations/blob/9cc956edd1b4b36a1653c6faf341c9ed7dac753a/write-fonts/src/tables/cmap.rs#L192-L210

The OpenType specification states that a format 4 subtable is not
mandatory, but that it may be included for backwards compatibility for
legacy environments that do not support format 12. As in our case there
are no overlapping codepoints, this suggests we can drop the format 4
subtable entirely (at least, unless there has been software developed
since that unconditionally assumes its existence).

(a small aside after re-reading: in fontations and ufo2ft we are not
following the recommendation to include all BMP codepoints in the format
12 table too [!]; this does not seem to have caused problems though)

https://learn.microsoft.com/en-us/typography/opentype/spec/recom#cmap-table

In the case where this would result in 0 subtables, we still cannot drop
`cmap` entirely, as it is a required table.

https://learn.microsoft.com/en-us/typography/opentype/spec/otff#required-tables
@Hoolean Hoolean force-pushed the prune-cmap-format4 branch from 7ec3209 to 6077a8f Compare March 5, 2025 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant