Commit cbb0f66c authored by Sebastian Friedl's avatar Sebastian Friedl
Browse files

Create Webfonts with fonttools

parent c77971ca
......@@ -18,8 +18,7 @@ build:
- source venv/bin/activate
- pip install -r dep/dep.pip
script:
- ./scripts/11-slice.py
- ./scripts/21-webfonts.sh
- ./build.py
after_script:
- echo "Git commit $CI_COMMIT_SHORT_SHA" > BUILD
- echo "Build finished on `date -R`" >> BUILD
......
......@@ -10,7 +10,7 @@ from fontTools.ttLib import TTFont
from fontTools.varLib import instancer
_root_dir = Path(__file__).parent.parent.resolve(strict=True)
_root_dir = Path(__file__).parent.resolve(strict=True)
_timestamp = int(time())
_copyright = '© 2021 German Young Physicists’ Tournament, with reserved Font Name ‘GYPT’.'
......@@ -159,11 +159,13 @@ def slice_font(style, source, weight, adobe_weight, verbose_weight, italic=False
update_flags(instance, weight, italic)
patch_small_caps(instance, style, italic)
output_dir = _root_dir / 'out' / f'gypt-{style.lower()}' / 'TTF'
output_fnt = f'GYPT{style}-{(weight != 400 or not italic)*verbose_weight}{italic*"It"}.ttf'
for flavor in (None, 'woff', 'woff2'):
output_dir = _root_dir / 'out' / f'gypt-{style.lower()}' / f'{(flavor or "ttf").upper()}'
output_fnt = f'GYPT{style}-{(weight != 400 or not italic) * verbose_weight}{italic * "It"}.{flavor or "ttf"}'
os.makedirs(output_dir, exist_ok=True)
instance.save(output_dir / output_fnt)
instance.flavor = flavor
os.makedirs(output_dir, exist_ok=True)
instance.save(output_dir / output_fnt)
def main():
......
git
python3
python3-venv
woff-tools
woff2
brotli==1.0.9
fonttools==4.26.2
#!/usr/bin/env bash
set -e
# get absolute path to root dir
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && cd .. > /dev/null && pwd )"
# copy TrueType font folders
mapfile -t font_folders < <(find "$ROOT_DIR"/out/ -name TTF -type d -printf '%h\n')
for font_folder in "${font_folders[@]}"; do
cp -r "$font_folder/TTF" "$font_folder/WOFF"
cp -r "$font_folder/TTF" "$font_folder/WOFF2"
done
# create WOFF fonts
for file in "$ROOT_DIR"/out/*/WOFF/*.ttf; do
sfnt2woff "$file"
rm "$file"
done
# create WOFF2 files
for file in "$ROOT_DIR"/out/*/WOFF2/*.ttf; do
woff2_compress "$file"
rm "$file"
done
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment