Skip to content

Commit a7f7ae0

Browse files
authored
Merge pull request #942 from googlefonts/fix-instance-en-localised-name
[instantiator] skip 'en' in localized instance names
2 parents 3eb9851 + f72b33c commit a7f7ae0

File tree

8 files changed

+125
-0
lines changed

8 files changed

+125
-0
lines changed

Lib/ufo2ft/instantiator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
abstraction, varLib for instance computation and fontMath as a font data shell for
2929
instance computation directly and exclusively.
3030
"""
31+
3132
from __future__ import annotations
3233

3334
import copy
@@ -756,6 +757,8 @@ def _generate_instance_info(
756757
OT_STYLE_MAP_FAMILY_NAME_ID = 1
757758
OT_STYLE_MAP_STYLE_NAME_ID = 2
758759
for language_tag in declared_language_tags:
760+
if language_tag == "en":
761+
continue
759762
if font.info.openTypeNameRecords is None:
760763
font.info.openTypeNameRecords = []
761764
# currently only make records for Windows language tag
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<designspace format="5.0">
3+
<axes>
4+
<axis tag="wght" name="Weight" minimum="400" maximum="400" default="400">
5+
<map input="400" output="100"/>
6+
</axis>
7+
</axes>
8+
<sources>
9+
<source filename="BagelFatOne-Regular.ufo" name="Bagel Fat One Regular" familyname="Bagel Fat One" stylename="Regular">
10+
<lib copy="1"/>
11+
<groups copy="1"/>
12+
<features copy="1"/>
13+
<info copy="1"/>
14+
<location>
15+
<dimension name="Weight" xvalue="100"/>
16+
</location>
17+
</source>
18+
</sources>
19+
<instances>
20+
<instance name="Bagel Fat One Regular" familyname="Bagel Fat One" stylename="Regular" filename="../instance_ufo/BagelFatOne-Regular.ufo" stylemapfamilyname="Bagel Fat One" stylemapstylename="regular">
21+
<location>
22+
<dimension name="Weight" xvalue="100"/>
23+
</location>
24+
</instance>
25+
</instances>
26+
</designspace>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>ascender</key>
6+
<integer>880</integer>
7+
<key>capHeight</key>
8+
<integer>726</integer>
9+
<key>descender</key>
10+
<integer>-288</integer>
11+
<key>familyName</key>
12+
<string>Bagel Fat One</string>
13+
<key>styleMapFamilyName</key>
14+
<string>Bagel Fat One</string>
15+
<key>styleMapStyleName</key>
16+
<string>regular</string>
17+
<key>styleName</key>
18+
<string>Regular</string>
19+
<key>unitsPerEm</key>
20+
<integer>1000</integer>
21+
<key>versionMajor</key>
22+
<integer>1</integer>
23+
<key>versionMinor</key>
24+
<integer>0</integer>
25+
<key>xHeight</key>
26+
<integer>523</integer>
27+
</dict>
28+
</plist>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>space</key>
6+
<string>space.glif</string>
7+
</dict>
8+
</plist>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<glyph name="space" format="2">
3+
<advance width="180"/>
4+
<unicode hex="0020"/>
5+
<outline>
6+
</outline>
7+
</glyph>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<array>
5+
<array>
6+
<string>public.default</string>
7+
<string>glyphs</string>
8+
</array>
9+
</array>
10+
</plist>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>creator</key>
6+
<string>com.github.fonttools.ufoLib</string>
7+
<key>formatVersion</key>
8+
<integer>3</integer>
9+
</dict>
10+
</plist>

tests/instantiator_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,39 @@ def assert_name_record_in_list(name_record, name_record_list):
942942
)
943943

944944

945+
def test_font_info_fallback_should_skip_english_in_localized(ufo_module, data_dir):
946+
designspace = designspaceLib.DesignSpaceDocument.fromfile(
947+
data_dir / "BagelFatOne-Regular.designspace"
948+
)
949+
designspace.loadSourceFonts(openFontFactory(ufo_module=ufo_module))
950+
951+
# fontmake calls `splitInterpolable` before constructing the Instantiator.
952+
# It does that to split a v5 designspace which may contain discrete axes into
953+
# 'interpolable' sub-designspaces. This code also handles generating instance
954+
# names from STAT-related elements like axis <labelname>. As part of this, it
955+
# can sometimes add "en" (English) names to the sub-doc instances' localized
956+
# names (English names are normally defined in the instance attributes, but
957+
# subsequent designspaceLib code wants to access all the instance names via
958+
# the same localized* interface).
959+
# The uf2ft code in Instantiator._generate_instance_info that handles
960+
# the localized instance names currently does not distinguish between the
961+
# true localized names and these "en" name duplicates, and ends up
962+
# writing unnecessary openTypeNameRecords for the latter.
963+
[(_, designspace2)] = designspaceLib.split.splitInterpolable(designspace)
964+
assert designspace.instances[0].localisedFamilyName == {}
965+
assert designspace2.instances[0].localisedFamilyName == {"en": "Bagel Fat One"}
966+
967+
generator = ufo2ft.instantiator.Instantiator.from_designspace(
968+
designspace2, round_geometry=True
969+
)
970+
971+
instance_font = generator.generate_instance(designspace2.instances[0])
972+
973+
assert instance_font.info.familyName == "Bagel Fat One"
974+
assert instance_font.info.styleName == "Regular"
975+
assert instance_font.info.openTypeNameRecords is None
976+
977+
945978
def test_data_independence(ufo_module, data_dir):
946979
designspace = designspaceLib.DesignSpaceDocument.fromfile(
947980
data_dir / "DesignspaceTest" / "DesignspaceTest.designspace"

0 commit comments

Comments
 (0)