Skip to content

Commit

Permalink
Add the ttc sub-command
Browse files Browse the repository at this point in the history
A separate script `splitttc.py` is merged as the sub-command of the
`east-asian-spacing` command line tool.
  • Loading branch information
kojiishi committed Aug 30, 2021
1 parent af95def commit bd694cf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions east_asian_spacing/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys

import east_asian_spacing
import east_asian_spacing.ttc


def main():
Expand All @@ -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())


Expand Down
24 changes: 14 additions & 10 deletions scripts/splitttc.py → east_asian_spacing/ttc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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__':
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit bd694cf

Please sign in to comment.