Merge pull request #2889 from fonttools/unicodedata-Zmth

[unicodedata] map Zmth<->math in ot_tag_{to,from}_script
This commit is contained in:
Cosimo Lupo 2022-11-11 20:37:36 +00:00 committed by GitHub
commit a1fc9b1efc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View File

@ -22,11 +22,16 @@ SCRIPT_EXCEPTIONS = {
"Yiii": "yi ", "Yiii": "yi ",
"Nkoo": "nko ", "Nkoo": "nko ",
"Vaii": "vai ", "Vaii": "vai ",
"Zmth": "math",
"Zinh": DEFAULT_SCRIPT, "Zinh": DEFAULT_SCRIPT,
"Zyyy": DEFAULT_SCRIPT, "Zyyy": DEFAULT_SCRIPT,
"Zzzz": DEFAULT_SCRIPT, "Zzzz": DEFAULT_SCRIPT,
} }
SCRIPT_EXCEPTIONS_REVERSED = {
"math": "Zmth",
}
NEW_SCRIPT_TAGS = { NEW_SCRIPT_TAGS = {
"Beng": ("bng2",), "Beng": ("bng2",),
"Deva": ("dev2",), "Deva": ("dev2",),

View File

@ -239,15 +239,13 @@ def ot_tags_from_script(script_code):
Unicode script code. Unicode script code.
Return ['DFLT'] script tag for invalid/unknown script codes. Return ['DFLT'] script tag for invalid/unknown script codes.
""" """
if script_code in OTTags.SCRIPT_EXCEPTIONS:
return [OTTags.SCRIPT_EXCEPTIONS[script_code]]
if script_code not in Scripts.NAMES: if script_code not in Scripts.NAMES:
return [OTTags.DEFAULT_SCRIPT] return [OTTags.DEFAULT_SCRIPT]
script_tags = [ script_tags = [script_code[0].lower() + script_code[1:]]
OTTags.SCRIPT_EXCEPTIONS.get(
script_code,
script_code[0].lower() + script_code[1:]
)
]
if script_code in OTTags.NEW_SCRIPT_TAGS: if script_code in OTTags.NEW_SCRIPT_TAGS:
script_tags.extend(OTTags.NEW_SCRIPT_TAGS[script_code]) script_tags.extend(OTTags.NEW_SCRIPT_TAGS[script_code])
script_tags.reverse() # last in, first out script_tags.reverse() # last in, first out
@ -278,6 +276,9 @@ def ot_tag_to_script(tag):
if tag in OTTags.NEW_SCRIPT_TAGS_REVERSED: if tag in OTTags.NEW_SCRIPT_TAGS_REVERSED:
return OTTags.NEW_SCRIPT_TAGS_REVERSED[tag] return OTTags.NEW_SCRIPT_TAGS_REVERSED[tag]
if tag in OTTags.SCRIPT_EXCEPTIONS_REVERSED:
return OTTags.SCRIPT_EXCEPTIONS_REVERSED[tag]
# This side of the conversion is fully algorithmic # This side of the conversion is fully algorithmic
# Any spaces at the end of the tag are replaced by repeating the last # Any spaces at the end of the tag are replaced by repeating the last

View File

@ -210,6 +210,7 @@ def test_ot_tags_from_script():
assert unicodedata.ot_tags_from_script("Deva") == ["dev2", "deva"] assert unicodedata.ot_tags_from_script("Deva") == ["dev2", "deva"]
# exceptions # exceptions
assert unicodedata.ot_tags_from_script("Hira") == ["kana"] assert unicodedata.ot_tags_from_script("Hira") == ["kana"]
assert unicodedata.ot_tags_from_script("Zmth") == ["math"]
# special script codes map to DFLT # special script codes map to DFLT
assert unicodedata.ot_tags_from_script("Zinh") == ["DFLT"] assert unicodedata.ot_tags_from_script("Zinh") == ["DFLT"]
assert unicodedata.ot_tags_from_script("Zyyy") == ["DFLT"] assert unicodedata.ot_tags_from_script("Zyyy") == ["DFLT"]
@ -232,6 +233,7 @@ def test_ot_tag_to_script():
assert unicodedata.ot_tag_to_script("vai ") == "Vaii" assert unicodedata.ot_tag_to_script("vai ") == "Vaii"
assert unicodedata.ot_tag_to_script("lao ") == "Laoo" assert unicodedata.ot_tag_to_script("lao ") == "Laoo"
assert unicodedata.ot_tag_to_script("yi") == "Yiii" assert unicodedata.ot_tag_to_script("yi") == "Yiii"
assert unicodedata.ot_tag_to_script("math") == "Zmth"
# both 'hang' and 'jamo' tags map to the Hangul script # both 'hang' and 'jamo' tags map to the Hangul script
assert unicodedata.ot_tag_to_script("hang") == "Hang" assert unicodedata.ot_tag_to_script("hang") == "Hang"
assert unicodedata.ot_tag_to_script("jamo") == "Hang" assert unicodedata.ot_tag_to_script("jamo") == "Hang"