Skip to content

Commit

Permalink
Merge pull request #1 from Radically/testing
Browse files Browse the repository at this point in the history
Font generation has been tested with the "test" character subset
  • Loading branch information
Transfusion authored Mar 29, 2021
2 parents 417b5ed + 3c8d1c9 commit a984b71
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 5 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/generate-woff2-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Generate woff2 tarballs using font-splitter container (Release)

on:
push:
tags:
- "release-*"

jobs:
build:
runs-on: ubuntu-latest
container:
image: transfusion/font-splitter
steps:
- run: apk update && apk upgrade && apk add --no-cache bash git python3 py3-pip curl nodejs npm build-base
- run: npm install clean-css-cli -g
- run: cleancss
- run: git --version
- run: python --version
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
# - name: Set up Python 3.9.x
# uses: actions/setup-python@v2
# with:
# python-version: 3.9.x

- name: Files
run: ls -lah && ls -lah /

- run: python --version
- run: echo $PATH

- name: Install Poetry
uses: snok/[email protected]

- name: Cache Poetry virtualenv
uses: actions/cache@v1
id: cache
with:
path: ~/.virtualenvs
key: poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
poetry-${{ hashFiles('**/poetry.lock') }}
- name: Set Poetry config
run: |
poetry config virtualenvs.in-project false
poetry config virtualenvs.path ~/.virtualenvs
- name: Install Dependencies
run: poetry install
if: steps.cache.outputs.cache-hit != 'true'

- name: What OS is running
run: uname -a && cat /etc/issue

- name: Generate woff2
run: poetry run driver /font-splitter/bin/font-splitter
# env:
# TEST_RUN: true

- uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: built

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
*.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 28 additions & 4 deletions .github/workflows/generate-woff2.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
name: Test font-splitter container
name: Generate woff2 tarballs using font-splitter container (Testing)

on:
push:
tags:
- "testing-*"

on: push
jobs:
print-information:
build:
runs-on: ubuntu-latest
container:
image: transfusion/font-splitter
steps:
- run: apk update && apk upgrade && apk add --no-cache bash git openssh python3 py3-pip curl nodejs npm
- run: apk update && apk upgrade && apk add --no-cache bash git python3 py3-pip curl nodejs npm build-base
- run: npm install clean-css-cli -g
- run: cleancss
- run: git --version
- run: python --version
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
# - name: Set up Python 3.9.x
# uses: actions/setup-python@v2
# with:
Expand Down Expand Up @@ -47,3 +53,21 @@ jobs:

- name: What OS is running
run: uname -a && cat /etc/issue

- name: Generate woff2
run: poetry run driver /font-splitter/bin/font-splitter
env:
TEST_RUN: true

- uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: built

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
*.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
__pycache__/
*.py[cod]
*$py.class

*.tgz
1 change: 1 addition & 0 deletions hanazono_lite_webfont_gen/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.0'
62 changes: 62 additions & 0 deletions hanazono_lite_webfont_gen/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
LOCALES = {
"g": {"tla": "ZHS", "suffix": "SC"},
"t": {"tla": "ZHT", "suffix": "TC"},
"h": {"tla": "ZHH", "suffix": "HK"},
"j": {"tla": "JAN", "suffix": "JP"},
"k": {"tla": "KOR", "suffix": "KR"},
"v": {"tla": "VIT", "suffix": "VN"},
"test": {"tla": "TEST", "suffix": "Test"},
}

_PACKAGE_JSON_TEMPLATE = """{{
"name": "{Name}",
"version": "0.0.1",
"description": "{Description}",
"keywords": [
"font",
"serif",
"type",
"face",
"mincho",
"songti",
"hanazono",
"hanamin",
"明朝体",
"宋体",
"明朝體",
"宋體",
"web",
"split",
"subset",
"woff2",
"cjk",
"chinese",
"japanese",
"korean",
"hanzi",
"kanji",
"hanja",
"unicode"
],
"main": "{MinifiedName}.min.css",
"repository": {{
"type": "git",
"url": "git+https://github.com/HanazonoLite-webfont.git"
}},
"author": {{
"name": "Bryan Kok",
"email": "[email protected]"
}},
"license": "OFL-1.1",
"bugs": {{
"url": "https://github.com/HanazonoLite-webfont/issues"
}},
"homepage": "https://github.com/HanazonoLite-webfont#readme"
}}
"""


def PACKAGE_JSON_TEMPLATE(Name, Description, MinifiedName):
return _PACKAGE_JSON_TEMPLATE.format(
Name=Name, Description=Description, MinifiedName=MinifiedName
)
128 changes: 128 additions & 0 deletions hanazono_lite_webfont_gen/driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import re
import os
import argparse
import subprocess
import requests
from requests.models import Response

from .constants import *

parser = argparse.ArgumentParser()
parser.add_argument("font_splitter", help="Path to font-splitter binary")
# parser.add_argument("locale", help="g, t, h, j, k, or v")

rls = None
program_args = None


def get_release() -> Response:
global rls
if rls:
return rls
rls = requests.get(
url="https://api.github.com/repos/radically/hanazonolite/releases/latest"
)
return rls


def download_otf(locale: str, is_mincho: bool, cjk: bool):
resp = get_release().json()
tmp = filter(lambda x: x["content_type"] == "font/otf", resp["assets"])

search_regex = (
f"Hana{'Min' if is_mincho else 'Goth'}Lite{'CJK' if cjk else ''}Test{LOCALES[locale]['suffix']}.otf\Z"
if "TEST_RUN" in os.environ
else f"Hana{'Min' if is_mincho else 'Goth'}Lite{'CJK' if cjk else ''}([A-C0-9]{{1,2}}){LOCALES[locale]['suffix']}.otf\Z"
)
tmp = list(
filter(
lambda x: re.search(
search_regex,
x["name"],
),
tmp,
)
)
# print(tmp)
# otfs = map(lambda x: {"name": x["name"], "url": x["browser_download_url"]}, tmp)
otfs = map(lambda x: x["browser_download_url"], tmp)
subprocess.run(["wget", "-nc"] + list(otfs)) # for debugging purposes
return list(map(lambda x: x["name"], tmp))


def remove_downloaded_otf():
subprocess.Popen("rm *.otf", shell=True)


def generate_woff2(locale: str, is_mincho: bool, cjk):
font_splitter = program_args.font_splitter
dirname = f"{'Mincho' if is_mincho else 'Gothic'}/{LOCALES[locale]['suffix']}/{'CJK' if cjk else 'single'}"
family_name = (
f"Hanazono {'Mincho' if is_mincho else 'Gothic'} Lite{' CJK' if cjk else ''}"
)
combined_css_name = f"Hana{'Min' if is_mincho else 'Goth'}Lite{'CJK' if cjk else ''}{LOCALES[locale]['suffix']}"
subprocess.run(
[
"rm",
"-rf",
dirname,
]
)
subprocess.run(
[
"mkdir",
"-p",
dirname,
]
)
tasks = []
otf_names = download_otf(locale, is_mincho, cjk)

for name in otf_names:
tasks.append(
subprocess.Popen(
[font_splitter, "-o", dirname, "-n", f"'{family_name}'", name]
)
)
for task in tasks:
task.wait()

remove_downloaded_otf()
task = subprocess.Popen(
f"cat ./{dirname}/*.css > {dirname}/{combined_css_name}.css", shell=True
)
task.wait()
subprocess.run(
[
"cleancss",
"-o" f"{dirname}/{combined_css_name}.min.css",
f"{dirname}/{combined_css_name}.css",
]
)
# generate package.json and tarballs (package.json should obviously be in the tgz)
f = open(f"{dirname}/package.json", "w")
description = (
f"{family_name} {LOCALES[locale]['suffix']} webfont leveraging unicode-range"
)
f.write(
PACKAGE_JSON_TEMPLATE(
f"{family_name} {LOCALES[locale]['suffix']}".replace(" ", "-").lower(),
description,
combined_css_name,
)
)
f.close()

subprocess.run(["npm", "pack", dirname])


def cli(args=None):
global program_args
program_args = parser.parse_args()
print(program_args.font_splitter)
for (is_mincho, cjk) in [(x, y) for x in [True, False] for y in [True, False]]:
for locale in ["g", "t", "h", "j", "k", "v"]:
generate_woff2(locale, is_mincho, cjk)

# break
# finally at the end, commit back to repo (after this script has ended)
Loading

0 comments on commit a984b71

Please sign in to comment.