mirror of
https://github.com/slavfox/Cozette.git
synced 2026-03-11 08:54:33 +00:00
Fix image generation
This commit is contained in:
parent
a0d8de634d
commit
786b0b2d51
4 changed files with 36 additions and 12 deletions
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
|
|
@ -20,7 +20,7 @@ jobs:
|
|||
- uses: actions/checkout@v2
|
||||
- name: Build fonts
|
||||
run: |
|
||||
pipenv install; pipenv run python build.py
|
||||
pipenv install; pipenv run python build.py fonts
|
||||
- uses: ncipollo/release-action@v1
|
||||
with:
|
||||
artifacts: "build/*"
|
||||
|
|
|
|||
30
build.py
30
build.py
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import argparse
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from shlex import quote
|
||||
|
|
@ -9,7 +10,8 @@ from typing import Optional, Sequence, cast
|
|||
|
||||
import crayons # type: ignore
|
||||
|
||||
from cozette_builder.imagegen import read_sample, save_charlist, save_sample
|
||||
from cozette_builder.imagegen import read_sample, save_charlist, \
|
||||
save_sample, add_margins
|
||||
from cozette_builder.ttfbuilder import TTFBuilder
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent
|
||||
|
|
@ -50,6 +52,7 @@ def save_images(bdfpath):
|
|||
)
|
||||
subprocess.run(["xset", "-fp", tmpdirname])
|
||||
subprocess.run(["xset", "fp", "rehash"])
|
||||
add_margins(REPO_ROOT / "img" / "sample.png", )
|
||||
|
||||
|
||||
def fontforge(open: Path, generate: Sequence[Generate]):
|
||||
|
|
@ -123,6 +126,9 @@ def fix_ttf(ttfpath: Path):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("action", choices=["images", "fonts"])
|
||||
args = parser.parse_args()
|
||||
BUILD_DIR.mkdir(exist_ok=True)
|
||||
os.chdir(BUILD_DIR)
|
||||
print(crayons.blue("Building .bdf..."))
|
||||
|
|
@ -131,13 +137,15 @@ if __name__ == "__main__":
|
|||
print(crayons.blue("Building bitmap formats..."))
|
||||
gen_bitmap_formats(bdfpath)
|
||||
print(crayons.green("Done!", bold=True))
|
||||
print(crayons.blue("Saving sample images..."))
|
||||
save_images(bdfpath)
|
||||
print(crayons.green("Done!", bold=True))
|
||||
print(crayons.blue("Generating TTF..."))
|
||||
ttfbuilder = TTFBuilder.from_bdf_path(bdfpath)
|
||||
ttfbuilder.build("cozette-tmp.ttf")
|
||||
print(crayons.green("Done!", bold=True))
|
||||
print(crayons.blue("Fixing TTF..."))
|
||||
fix_ttf(Path("cozette-tmp.ttf"))
|
||||
print(crayons.green("Done!", bold=True))
|
||||
if args.action == "images":
|
||||
print(crayons.blue("Saving sample images..."))
|
||||
save_images(bdfpath)
|
||||
print(crayons.green("Done!", bold=True))
|
||||
else:
|
||||
print(crayons.blue("Generating TTF..."))
|
||||
ttfbuilder = TTFBuilder.from_bdf_path(bdfpath)
|
||||
ttfbuilder.build("cozette-tmp.ttf")
|
||||
print(crayons.green("Done!", bold=True))
|
||||
print(crayons.blue("Fixing TTF..."))
|
||||
fix_ttf(Path("cozette-tmp.ttf"))
|
||||
print(crayons.green("Done!", bold=True))
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from pathlib import Path
|
|||
from shlex import quote
|
||||
from typing import Dict, NamedTuple, Optional, Tuple
|
||||
from unicodedata import east_asian_width as charwidth
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
from cozette_builder.bdffont import BdfFont
|
||||
|
||||
|
|
@ -151,3 +152,18 @@ def save_charlist(fnt: str, bdf_font: Path, output_path: Path):
|
|||
),
|
||||
output_path,
|
||||
)
|
||||
|
||||
|
||||
def add_margins(sample_path: Path, color: str = "#282c34"):
|
||||
im: Image.Image = Image.open(sample_path).convert("RGB")
|
||||
new_w = round((im.height / 3) * 4)
|
||||
im.load()
|
||||
new_im = ImageOps.pad(
|
||||
im,
|
||||
(new_w, im.height),
|
||||
method=Image.NEAREST,
|
||||
color=color
|
||||
)
|
||||
new_im.save(sample_path)
|
||||
|
||||
|
||||
|
|
|
|||
BIN
img/sample.png
BIN
img/sample.png
Binary file not shown.
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 5.8 KiB |
Loading…
Reference in a new issue