Skip to content

Commit

Permalink
Add support for getting languages from gfglyphsets
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Sep 16, 2024
1 parent e319e7f commit a2d48be
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
17 changes: 16 additions & 1 deletion Lib/shaperglot/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from shaperglot.cli.describe import describe
from shaperglot.cli.report import report

try:
import glyphsets
except ImportError:
glyphsets = None


def main(args=None) -> None:
if args is None:
Expand All @@ -30,7 +35,11 @@ def main(args=None) -> None:
)
parser_check.add_argument('font', metavar='FONT', help='the font file')
parser_check.add_argument(
'lang', metavar='LANG', help='one or more ISO639-3 language codes', nargs="+"
'lang',
metavar='LANG',
help='one or more ISO639-3 language codes'
+ (" or glyphsets" if glyphsets else ""),
nargs="+",
)
parser_check.set_defaults(func=check)

Expand All @@ -50,6 +59,12 @@ def main(args=None) -> None:
parser_report.add_argument(
'--filter', type=str, help="Regular expression to filter languages"
)
if glyphsets:
parser_report.add_argument(
'--glyphset',
help="Glyph set to use for checking",
choices=glyphsets.defined_glyphsets(),
)
parser_report.set_defaults(func=report)

options = parser.parse_args(args)
Expand Down
14 changes: 13 additions & 1 deletion Lib/shaperglot/cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from shaperglot.languages import Languages
from shaperglot.reporter import Reporter

try:
import glyphsets
except ImportError:
glyphsets = None


def find_lang(lang: str, langs: Languages) -> Optional[str]:
# Find the language in the languages list; could be by ID, by name, etc.
Expand All @@ -27,7 +32,14 @@ def check(options) -> None:
checker = Checker(options.font)
langs = Languages()
fixes_needed = defaultdict(set)
for orig_lang in options.lang:
lang_arg = []
for lang in options.lang:
if glyphsets and lang in glyphsets.defined_glyphsets():
lang_arg.extend(glyphsets.languages_per_glyphset(lang))
else:
lang_arg.append(lang)

for orig_lang in lang_arg:
lang = find_lang(orig_lang, langs)
if not lang:
print(f"Language '{orig_lang}' not known")
Expand Down
12 changes: 12 additions & 0 deletions Lib/shaperglot/cli/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
from shaperglot.reporter import Result


try:
import glyphsets
except ImportError:
glyphsets = None


def report(options) -> None:
"""Report which languages are supported by the given font"""
checker = Checker(options.font)
Expand All @@ -18,6 +24,10 @@ def report(options) -> None:
unsupported = []
fixes_needed = defaultdict(set)

lang_filter = None
if options.glyphset:
lang_filter = glyphsets.languages_per_glyphset(options.glyphset)

if options.csv:
print(
"Language,Name,Supported,Bases Missing,Marks Missing,Orphaned Marks,Other"
Expand All @@ -26,6 +36,8 @@ def report(options) -> None:
for lang in sorted(langs.keys()):
if options.filter and not re.search(options.filter, lang):
continue
if lang_filter and lang not in lang_filter:
continue
results = checker.check(langs[lang])

if results.is_unknown:
Expand Down

0 comments on commit a2d48be

Please sign in to comment.