Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: Docker container, --glyph-only feature, fix etree dependency issue #20

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
75 changes: 75 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Docker

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:

env:
IMAGE_NAME: scfbuild

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi

# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test

runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Log into registry
run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME

# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')

# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')

# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest

echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION

docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:18.04

RUN apt-get update && apt-get upgrade -y
RUN apt-get install python-pip -y
RUN pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org fonttools
RUN pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org pyyaml
RUN pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org lxml
RUN apt-get install fontforge python-fontforge -y

COPY . /scfbuild
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ Required Python libraries:

* FontTools 2.5+
* FontForge
* lxml

Run: `bin/scfbuild`

@@ -74,6 +75,7 @@ optional arguments:
-s DIR, --color-svg-dir DIR
directory of SVGinOT color SVG glyphs to add to the
font.
--glyph-only generate font with no-color SVG glyphs only
--transform TRANSFORM
add a transform to the <svg> tag of each color SVG.
Example "translate(0 -1638) scale(2.048)"
@@ -89,6 +91,23 @@ optional arguments:
-V, --version print version information
```

## Docker

If you don't want to install the required Python libraries from above locally on your machine, then you can use the provided Docker container, which bundles nicely all requirements.

1. Install [Docker](https://www.docker.com/)

2. Either A) build the container on your onw: `docker build -t scfbuild .` or B) pull the latest published container: `docker pull ghcr.io/b-g/scfbuild/scfbuild:latest`
3. Run and share folder with container:

```bash
$ cd path/to/repo/scfbuild
$ docker run --interactive --tty --rm --volume $PWD:/wd --workdir /wd scfbuild:latest bash
# now you can use bin/scfbuild via the docker container
$ bin/scfbuild --help
```



## Other Tools
`scfbuild` softens the learning curve for font creation, but cannot replace more
19 changes: 14 additions & 5 deletions scfbuild/builder.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
import tempfile
import time
from distutils.version import LooseVersion
import xml.etree.ElementTree as ET
from lxml import etree as ET

import fontTools
from fontTools.ttLib import TTFont
@@ -69,9 +69,14 @@ def run(self):

logger.info("Reading intermediate font file")
self.font = TTFont(tmp_file)
logger.info("Adding SVGinOT SVG files")
# TODO: Validate color SVGs
self.add_color_svg()

if self.conf['glyph_only'] == False:
logger.info("Adding SVGinOT SVG files")
self.add_color_svg()
else:
logger.info("Not Adding SVGinOT SVG files")

self.add_name_table()
logger.info("Saving output file: %s", self.conf['output_file'])
self.font.save(self.conf['output_file'])
@@ -89,7 +94,7 @@ def add_color_svg(self):
svg_list = []

# Set default namespace (avoids "ns0:svg")
ET.register_namespace("", "http://www.w3.org/2000/svg")
ET.register_namespace("svg", "http://www.w3.org/2000/svg")

for filepath in svg_files:
glyph_id = self.get_glyph_id(filepath)
@@ -258,7 +263,11 @@ def add_name_table(self):
('url_vendor', NR.URL_VENDOR),
('url_designer', NR.URL_DESIGNER),
('license', NR.LICENSE),
('url_license', NR.URL_LICENSE)):
('url_license', NR.URL_LICENSE),
('typographic_family', NR.TYPOGRAPHIC_FAMILY),
('typographic_subfamily', NR.TYPOGRAPHIC_SUBFAMILY),
('wws_family', NR.WWS_FAMILY),
('wws_subfamily', NR.WWS_SUBFAMILY)):
if key in tn:
self.add_name_records(tn[key], name_id)

4 changes: 4 additions & 0 deletions scfbuild/constants/name_record.py
Original file line number Diff line number Diff line change
@@ -51,3 +51,7 @@
URL_DESIGNER = 12
LICENSE = 13
URL_LICENSE = 14
TYPOGRAPHIC_FAMILY = 16
TYPOGRAPHIC_SUBFAMILY = 17
WWS_FAMILY = 21
WWS_SUBFAMILY = 22
8 changes: 8 additions & 0 deletions scfbuild/main.py
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ def main():
dest='glyph_svg_dir',
metavar='DIR',
help='directory of regular no-color SVG glyphs to add to the font')
parser.add_argument('--glyph-only',
dest='glyph_only',
action='store_true',
help='generate font with no-color SVG glyphs only')
parser.add_argument('-s', '--color-svg-dir',
dest='color_svg_dir',
metavar='DIR',
@@ -89,6 +93,8 @@ def main():
conf['table_name'] = {}
if 'verbose' not in conf:
conf['verbose'] = False
if 'glyph_only' not in conf:
conf['glyph_only'] = False

# Command line options override YAML
if args.output:
@@ -101,6 +107,8 @@ def main():
conf['color_svg_transform'] = args.transform
if args.verbose:
conf['verbose'] = True
if args.glyph_only:
conf['glyph_only'] = args.glyph_only

# Be sure family name, subfamily, and version are set to something.
if 'family' not in conf['table_name'] or args.family is not default_family: