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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions Lib/ufo2ft/outlineCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,9 @@ def setupTable_cmap(self):
if "cmap" not in self.tables:
return

from fontTools.ttLib.tables._c_m_a_p import cmap_format_4
self.otf["cmap"] = cmap = newTable("cmap")
cmap.tableVersion = 0
cmap.tables = []

nonBMP = {k: v for k, v in self.unicodeToGlyphNameMapping.items() if k > 65535}
if nonBMP:
Expand All @@ -492,24 +494,29 @@ def setupTable_cmap(self):
}
else:
mapping = dict(self.unicodeToGlyphNameMapping)
# mac
cmap4_0_3 = cmap_format_4(4)
cmap4_0_3.platformID = 0
cmap4_0_3.platEncID = 3
cmap4_0_3.language = 0
cmap4_0_3.cmap = mapping
# windows
cmap4_3_1 = cmap_format_4(4)
cmap4_3_1.platformID = 3
cmap4_3_1.platEncID = 1
cmap4_3_1.language = 0
cmap4_3_1.cmap = mapping
# store
self.otf["cmap"] = cmap = newTable("cmap")
cmap.tableVersion = 0
cmap.tables = [cmap4_0_3, cmap4_3_1]
# If we have glyphs outside Unicode BMP, we must set another
# subtable that can hold longer codepoints for them.

# If we have glyphs within the Unicode BMP, include a Format 4 subtable
# to hold their codepoints.
if mapping:
from fontTools.ttLib.tables._c_m_a_p import cmap_format_4

# mac
cmap4_0_3 = cmap_format_4(4)
cmap4_0_3.platformID = 0
cmap4_0_3.platEncID = 3
cmap4_0_3.language = 0
cmap4_0_3.cmap = mapping
# windows
cmap4_3_1 = cmap_format_4(4)
cmap4_3_1.platformID = 3
cmap4_3_1.platEncID = 1
cmap4_3_1.language = 0
cmap4_3_1.cmap = mapping

cmap.tables.extend([cmap4_0_3, cmap4_3_1])

# If we have glyphs outside the Unicode BMP, we must include a subtable
# that can hold their longer codepoints.
if nonBMP:
from fontTools.ttLib.tables._c_m_a_p import cmap_format_12

Expand All @@ -527,7 +534,7 @@ def setupTable_cmap(self):
cmap12_3_10.language = 0
cmap12_3_10.cmap = nonBMP
# update tables registry
cmap.tables = [cmap4_0_3, cmap4_3_1, cmap12_0_4, cmap12_3_10]
cmap.tables.extend([cmap12_0_4, cmap12_3_10])
# unicode variation sequences
uvsMapping = self.ufo.lib.get(UNICODE_VARIATION_SEQUENCES_KEY)
if uvsMapping:
Expand Down
4 changes: 0 additions & 4 deletions tests/data/DSv5/MutatorSansVariable_Weight-CFF2.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
</cmap_format_4>
</cmap>

<name>
Expand Down
4 changes: 0 additions & 4 deletions tests/data/DSv5/MutatorSansVariable_Weight-TTF.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
</cmap_format_4>
</cmap>

<fpgm>
Expand Down
4 changes: 0 additions & 4 deletions tests/data/DSv5/MutatorSansVariable_Weight_Width-CFF2.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
</cmap_format_4>
</cmap>

<name>
Expand Down
4 changes: 0 additions & 4 deletions tests/data/DSv5/MutatorSansVariable_Weight_Width-TTF.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
</cmap_format_4>
</cmap>

<fpgm>
Expand Down
4 changes: 0 additions & 4 deletions tests/data/DSv5/MutatorSansVariable_Width-CFF2.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
</cmap_format_4>
</cmap>

<name>
Expand Down
4 changes: 0 additions & 4 deletions tests/data/DSv5/MutatorSansVariable_Width-TTF.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
</cmap_format_4>
</cmap>

<fpgm>
Expand Down
4 changes: 0 additions & 4 deletions tests/data/DSv5/MutatorSerifVariable_Width-CFF2.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
</cmap_format_4>
</cmap>

<name>
Expand Down
4 changes: 0 additions & 4 deletions tests/data/DSv5/MutatorSerifVariable_Width-TTF.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@

<cmap>
<tableVersion version="0"/>
<cmap_format_4 platformID="0" platEncID="3" language="0">
</cmap_format_4>
<cmap_format_4 platformID="3" platEncID="1" language="0">
</cmap_format_4>
</cmap>

<cvt>
Expand Down