diff --git a/build.py b/build.py index 9a1e102..3062801 100644 --- a/build.py +++ b/build.py @@ -1,7 +1,7 @@ +import argparse import os import subprocess import tempfile -import argparse from dataclasses import dataclass from pathlib import Path from shlex import quote @@ -10,19 +10,19 @@ from typing import Optional, Sequence, cast import crayons # type: ignore +from cozette_builder.changeloggen import get_changelog from cozette_builder.imagegen import ( + add_margins, read_sample, save_charlist, save_sample, - add_margins, +) +from cozette_builder.scanner import ( + find_missing_codepoints, + print_codepoints_for_changelog, + scan_for_codepoints, ) from cozette_builder.ttfbuilder import TTFBuilder -from cozette_builder.scanner import ( - scan_for_codepoints, - print_codepoints_for_changelog, - find_missing_codepoints, -) -from cozette_builder.changeloggen import get_changelog REPO_ROOT = Path(__file__).resolve().parent BUILD_DIR = REPO_ROOT / "build" @@ -138,8 +138,9 @@ if __name__ == "__main__": ) if missing_codepoints: print_codepoints_for_changelog( - missing_codepoints, print_source_files=args.print_source_files, - reverse=args.reverse + missing_codepoints, + print_source_files=args.print_source_files, + reverse=args.reverse, ) else: print( diff --git a/cozette_builder/changeloggen.py b/cozette_builder/changeloggen.py index 485cdb9..3bee7e1 100644 --- a/cozette_builder/changeloggen.py +++ b/cozette_builder/changeloggen.py @@ -1,21 +1,30 @@ -from git import Repo import re from pathlib import Path from unicodedata import name +from git import Repo + REPO_ROOT = Path(__file__).parent.parent COZETTE_SFD = REPO_ROOT / "Cozette" / "Cozette.sfd" -repo = Repo(REPO_ROOT) -last_ver = sorted(repo.tags, key=lambda tag: tag.commit.committed_date)[-1] -last_cozette_sfd: str = ( - last_ver - .commit - .tree["Cozette/Cozette.sfd"] - .data_stream - .read().decode('utf-8') + +def get_last_ver(): + repo = Repo(REPO_ROOT) + return sorted(repo.tags, key=lambda tag: tag.commit.committed_date)[-1] + + +def get_last_cozette_sfd() -> str: + return ( + get_last_ver() + .commit.tree["Cozette/Cozette.sfd"] + .data_stream.read() + .decode("utf-8") + ) + + +char_regex = re.compile( + r"BDFChar: (-?\d+) (-?\d+) (-?\d+) (-?\d+) (-?\d+) (-?\d+) (-?\d+)" ) -char_regex = re.compile(r'BDFChar: (-?\d+) (-?\d+) (-?\d+) (-?\d+) (-?\d+) (-?\d+) (-?\d+)') def get_codepoints(cozette_sfd: str): @@ -35,17 +44,17 @@ def print_codepoint(codepoint): chrname = " " + name(chr(codepoint)) except ValueError: chrname = "" - print( - f"- {chr(codepoint)} (U+{codepoint:04X}{chrname})" - ) + print(f"- {chr(codepoint)} (U+{codepoint:04X}{chrname})") def get_changelog(): - previous_codepoints = get_codepoints(last_cozette_sfd) + previous_codepoints = get_codepoints(get_last_cozette_sfd()) with COZETTE_SFD.open() as f: current_codepoints = get_codepoints(f.read()) - print(f"Changelog since {last_ver}: {len(current_codepoints)} glyphs found") + print( + f"Changelog since {get_last_ver()}: {len(current_codepoints)} glyphs found" + ) added = set(current_codepoints) - set(previous_codepoints) removed = set(previous_codepoints) - set(current_codepoints) changed = set() @@ -69,4 +78,4 @@ def get_changelog(): print("### Removed\n") for codepoint in sorted(removed): print_codepoint(codepoint) - print("") \ No newline at end of file + print("") diff --git a/cozette_builder/imagegen.py b/cozette_builder/imagegen.py index e13dfe7..4f42319 100644 --- a/cozette_builder/imagegen.py +++ b/cozette_builder/imagegen.py @@ -2,8 +2,9 @@ import subprocess import tempfile from pathlib import Path from shlex import quote -from typing import Dict, NamedTuple, Optional, Tuple, List +from typing import Dict, List, NamedTuple, Optional, Tuple from unicodedata import east_asian_width as charwidth + from PIL import Image, ImageOps # type: ignore Color = Tuple[int, int, int] @@ -135,6 +136,7 @@ def color_text(text: str, palette: Palette) -> str: ) return colored_text + def make_charmap(sfd: Path) -> List[str]: text = [ " 0 1 2 3 4 5 6 7 8 9 A B C D E F", @@ -155,6 +157,7 @@ def make_charmap(sfd: Path) -> List[str]: text.append(f"U+{i//16:04X}_│{line}") return text + def sfd_codepoints(sfd: Path) -> List[int]: codepoints = [] with sfd.open() as f: diff --git a/cozette_builder/scanner.py b/cozette_builder/scanner.py index 9edce08..6c11a3b 100644 --- a/cozette_builder/scanner.py +++ b/cozette_builder/scanner.py @@ -1,10 +1,11 @@ -from typing import Set, Dict, Iterable, List, Set -from pathlib import Path import re +from pathlib import Path +from typing import Dict, Iterable, List, Set from unicodedata import name as uniname UESCAPE = re.compile(r"\\[uU]([0-9A-Fa-f]{4,5})") + def scan_file_for_nonascii(path: Path) -> Set[int]: with path.open() as f: try: @@ -17,13 +18,10 @@ def scan_file_for_nonascii(path: Path) -> Set[int]: return nonascii - # noinspection PyShadowingBuiltins def scan_for_codepoints(dir: Path) -> Dict[int, List[Path]]: if dir.is_file(): - return { - cp: [dir] for cp in scan_file_for_nonascii(dir) - } + return {cp: [dir] for cp in scan_file_for_nonascii(dir)} non_ascii_codepoints: Dict[int, List[Path]] = {} for path in dir.glob("**/*"): if path.is_file(): diff --git a/cozette_builder/ttfbuilder.py b/cozette_builder/ttfbuilder.py index 5f93634..50a269f 100644 --- a/cozette_builder/ttfbuilder.py +++ b/cozette_builder/ttfbuilder.py @@ -96,8 +96,8 @@ class TTFBuilder: panose={ **_panoseDefaults, "bFamilyType": 2, # Text and display - "bProportion": 9 # Monospace - } + "bProportion": 9, # Monospace + }, ) self.fb.setupPost(isFixedPitch=1) self.fb.save(output_path)