From a2d48be33597803c9d0b36c82e6aeecf905741fb Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Mon, 16 Sep 2024 13:32:05 +0100 Subject: [PATCH] Add support for getting languages from gfglyphsets --- Lib/shaperglot/cli/__init__.py | 17 ++++++++++++++++- Lib/shaperglot/cli/check.py | 14 +++++++++++++- Lib/shaperglot/cli/report.py | 12 ++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Lib/shaperglot/cli/__init__.py b/Lib/shaperglot/cli/__init__.py index 332a187..7542102 100644 --- a/Lib/shaperglot/cli/__init__.py +++ b/Lib/shaperglot/cli/__init__.py @@ -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: @@ -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) @@ -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) diff --git a/Lib/shaperglot/cli/check.py b/Lib/shaperglot/cli/check.py index 9749d8e..a55c80b 100644 --- a/Lib/shaperglot/cli/check.py +++ b/Lib/shaperglot/cli/check.py @@ -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. @@ -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") diff --git a/Lib/shaperglot/cli/report.py b/Lib/shaperglot/cli/report.py index 2430e1f..b5d570f 100644 --- a/Lib/shaperglot/cli/report.py +++ b/Lib/shaperglot/cli/report.py @@ -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) @@ -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" @@ -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: