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

fix: fix ofl License info and url records #813

Merged
merged 3 commits into from
Jan 23, 2024
Merged
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
8 changes: 8 additions & 0 deletions Lib/gftools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,11 @@
PLATFORM_ID__WINDOWS: "WINDOWS",
PLATFORM_ID__CUSTOM: "CUSTOM"
}

OFL_LICENSE_INFO = (
"This Font Software is licensed under the SIL Open Font License, "
"Version 1.1. This license is available with a FAQ at: "
"https://openfontlicense.org"
)

OFL_LICENSE_URL = "https://openfontlicense.org"
14 changes: 14 additions & 0 deletions Lib/gftools/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,18 @@ def fix_nbspace_glyph(ttfont: TTFont):
cmap = ttfont.getBestCmap()
if 0x00A0 in cmap:
return


def fix_license_strings(ttfont: TTFont):
"""Update font's nametable license and license url strings"""
from gftools.constants import OFL_LICENSE_URL, OFL_LICENSE_INFO
name_table = ttfont["name"]
for r in name_table.names:
if r.nameID == 13:
current_string = r.toUnicode()
if "SIL Open Font License" in current_string:
name_table.setName(OFL_LICENSE_INFO, r.nameID, r.platformID, r.platEncID, r.langID)
name_table.setName(OFL_LICENSE_URL, 14, r.platformID, r.platEncID, r.langID)


def fix_font(font, include_source_fixes=False, new_family_name=None, fvar_instance_axis_dflts=None):
Expand All @@ -721,6 +733,8 @@ def fix_font(font, include_source_fixes=False, new_family_name=None, fvar_instan
if fixed_font["OS/2"].version > 1:
fixed_font["OS/2"].version = 4

fix_license_strings(fixed_font)

if "fpgm" in fixed_font:
fix_hinted_font(fixed_font)
else:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,14 @@ def test_fix_colr_v1_font(colr_v1_font):
colr_v1_font["COLR"].version = 1
fixed = fix_colr_font(colr_v1_font)
assert "SVG " in fixed


def test_ofl_license_strings(static_font):
from gftools.fix import fix_license_strings
from gftools.constants import OFL_LICENSE_INFO, OFL_LICENSE_URL

for id in (13, 14):
assert "http://scripts.sil.org/OFL" in static_font["name"].getName(id, 3, 1, 0x409).toUnicode()
fix_license_strings(static_font)
for id, expected in ((13, OFL_LICENSE_INFO), (14, OFL_LICENSE_URL)):
assert expected == static_font["name"].getName(id, 3, 1, 0x409).toUnicode()
Loading