From bd694cfdf092354bb70048a43b17dce01b5c9f3e Mon Sep 17 00:00:00 2001 From: Koji Ishii Date: Sat, 28 Aug 2021 18:01:34 +0900 Subject: [PATCH] Add the `ttc` sub-command A separate script `splitttc.py` is merged as the sub-command of the `east-asian-spacing` command line tool. --- README.md | 6 ++++- east_asian_spacing/__main__.py | 6 +++++ .../splitttc.py => east_asian_spacing/ttc.py | 24 +++++++++++-------- pyproject.toml | 2 +- 4 files changed, 26 insertions(+), 12 deletions(-) rename scripts/splitttc.py => east_asian_spacing/ttc.py (62%) diff --git a/README.md b/README.md index 2b70fff..492c3cf 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,11 @@ It can test fonts you built locally. Note, when you want to test a TTC (TrueType Collection) but your browser can load only the first font in the TTC, -`script/splitttc.py` can split TTC into OTF/TTF. +the following command extracts all OpenType fonts (.otf or .ttf) +from an OpenType Collection font file (.ttc or .otc). +```sh +east-asian-spacing ttc build/NotoSansCJK-Regular.ttc +``` [test HTML page]: https://kojiishi.github.io/chws/test.html diff --git a/east_asian_spacing/__main__.py b/east_asian_spacing/__main__.py index 036a12c..41f94f5 100644 --- a/east_asian_spacing/__main__.py +++ b/east_asian_spacing/__main__.py @@ -2,6 +2,7 @@ import sys import east_asian_spacing +import east_asian_spacing.ttc def main(): @@ -13,6 +14,11 @@ def main(): asyncio.run(east_asian_spacing.Dump.main()) return + if sub_command == 'ttc': + del args[1] + east_asian_spacing.ttc.main() + return + asyncio.run(east_asian_spacing.Builder.main()) diff --git a/scripts/splitttc.py b/east_asian_spacing/ttc.py similarity index 62% rename from scripts/splitttc.py rename to east_asian_spacing/ttc.py index 12c2c08..b37a3d4 100755 --- a/scripts/splitttc.py +++ b/east_asian_spacing/ttc.py @@ -7,7 +7,19 @@ from east_asian_spacing.log_utils import init_logging -logger = logging.getLogger('splitttc') +logger = logging.getLogger('ttc') + + +def ttc_split(path: pathlib.Path): + ttc = TTCollection(path) + for i, ttfont in enumerate(ttc.fonts): + if ttfont.has_key('glyf'): + ext = '.ttf' + else: + ext = '.otf' + output = path.with_name(f'{path.name}-{i}{ext}') + logger.info('%s', output) + ttfont.save(output) def main(): @@ -21,15 +33,7 @@ def main(): args = parser.parse_args() init_logging(args.verbose, main=logger) for path in args.path: - ttc = TTCollection(path) - for i, ttfont in enumerate(ttc.fonts): - if ttfont.has_key('glyf'): - ext = '.ttf' - else: - ext = '.otf' - output = path.with_name(f'{path.name}-{i}{ext}') - logger.info('%s', output) - ttfont.save(output) + ttc_split(path) if __name__ == '__main__': diff --git a/pyproject.toml b/pyproject.toml index 4846204..5b38e87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "east_asian_spacing" -version = "1.3.4" +version = "1.3.5-alpha.0" description = "East Asian Contextual Spacing Build Tools" authors = ["Koji Ishii "] readme = "README.md"