Skip to content

Commit

Permalink
Build COLR TTFs with nanoemoji
Browse files Browse the repository at this point in the history
This is done via the container at https://gitlab.com/mavit/nanoemoji-container.

For me, the resulting COLR TTFs work in Firefox and in the Gnome desktop
on Fedora 32 (although they display rather small).

Caveats:
- It may be premature to replace `scfbuild` for SVG builds.  If we decide to go ahead without `scfbuild`, then we’ll want to remove the remaining files related to it.  If we decide to keep `scfbuild`, then we’ll want to revert those parts of this patch.  In either case we’ll want to update the readme to link to the new outputs.
- I’ve tested this with Podman, not Docker.

Relates to hfg-gmuend#93.
  • Loading branch information
mavit authored and JeppeKlitgaard committed Jan 6, 2023
1 parent 5e6d57c commit 2f42f81
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 17 deletions.
62 changes: 62 additions & 0 deletions font/OpenMoji-Color.ttx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.6">
<name>
<namerecord nameID="0" platformID="3" platEncID="1" langID="0x409">
OpenMoji © HfG Schwäbisch Gmünd CC-BY-SA-4.0
</namerecord>
<namerecord nameID="1" platformID="3" platEncID="1" langID="0x409">
OpenMoji
</namerecord>
<namerecord nameID="2" platformID="3" platEncID="1" langID="0x409">
Color
</namerecord>
<namerecord nameID="3" platformID="3" platEncID="1" langID="0x409">
OpenMoji Color openmoji.org
</namerecord>
<namerecord nameID="4" platformID="3" platEncID="1" langID="0x409">
OpenMoji Color
</namerecord>
<namerecord nameID="5" platformID="3" platEncID="1" langID="0x409">
To be filled in at build time.
</namerecord>
<namerecord nameID="6" platformID="3" platEncID="1" langID="0x409">
OpenMojiColor
</namerecord>
<namerecord nameID="7" platformID="3" platEncID="1" langID="0x409">
Hochschule für Gestaltung Schwäbisch Gmünd
</namerecord>
<namerecord nameID="8" platformID="3" platEncID="1" langID="0x409">
Hochschule für Gestaltung Schwäbisch Gmünd
</namerecord>
<namerecord nameID="9" platformID="3" platEncID="1" langID="0x409">
Daniel Utz &amp; Benedikt Groß with students of the HfG Schwäbisch Gmünd and other contributors
</namerecord>
<namerecord nameID="10" platformID="3" platEncID="1" langID="0x409">
Open-source emojis for designers, developers and everyone else! http://openmoji.org/ https:/hfg-gmuend/openmoji
</namerecord>
<namerecord nameID="11" platformID="3" platEncID="1" langID="0x409">
http://openmoji.org/
</namerecord>
<namerecord nameID="12" platformID="3" platEncID="1" langID="0x409">
http://openmoji.org/about.html
</namerecord>
<namerecord nameID="13" platformID="3" platEncID="1" langID="0x409">
Creative Commons Share Alike 4.0
</namerecord>
<namerecord nameID="14" platformID="3" platEncID="1" langID="0x409">
https://creativecommons.org/licenses/by-sa/4.0/
</namerecord>
<namerecord nameID="16" platformID="3" platEncID="1" langID="0x409">
OpenMoji
</namerecord>
<namerecord nameID="17" platformID="3" platEncID="1" langID="0x409">
Color
</namerecord>
<namerecord nameID="21" platformID="3" platEncID="1" langID="0x409">
OpenMoji Color
</namerecord>
<namerecord nameID="22" platformID="3" platEncID="1" langID="0x409">
Regular
</namerecord>
</name>
</ttFont>
68 changes: 51 additions & 17 deletions helpers/generate-fonts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,62 @@ set -ueo pipefail
# -- prepare assets --
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/.. || exit 1

# copy and prepare svg assets for OpenMoji font generator
echo "👉 generate-font-glyphs.js"
helpers/generate-font-glyphs.js

# generate css file for OpenMoji fonts
echo "👉 generate-font-css.js"
helpers/generate-font-css.js

# -- OpenMoji font generator via scfbuild Docker --
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"/../font || exit 1
sed 's/Color/Black/;' font/OpenMoji-Color.ttx > font/OpenMoji-Black.ttx


# -- OpenMoji COLR TTF font generator via nanoemoji container --
version=$(git describe --tags)

# If we're connected to a terminal, don't flood it with ninja output,
# and enable ^C.
if [[ -t 1 ]]; then
tty='--tty --interactive'
else
tty=''
fi

IMAGE='scfbuild:latest'
NAME='scfbuild_bash'
# FIXME: Upgrade glyf_colr_0 to glyf_colr_1 once
# https:/googlefonts/colr-gradients-spec stabilises.
#
# FIXME: Switch untouchedsvgz for picosvgz when
# https:/googlefonts/nanoemoji/issues/113 is fixed.
#
# FIXME: Here we build OpenMoji Black as a colour font that just happens
# to use black as the only colour. This is probably a bad idea.
# https:/googlefonts/nanoemoji/issues/114
#
for saturation in black color; do
name=OpenMoji-${saturation^}
build_dir=/mnt/build/$saturation

# is docker container "scfbuild_bash" running?
# if not ... start container
[[ "$(docker ps -f "name=$NAME" --format '{{.Names}}')" == "$NAME" ]] ||
docker run --name "$NAME" --rm -t -d --volume "$PWD":/wd --workdir /wd "$IMAGE" bash
for format in glyf_colr_0 untouchedsvgz; do
mkdir -p font/$format

# generate fonts
docker exec -ti "$NAME" bash -c "/scfbuild/bin/scfbuild -c /wd/scfbuild-color.yml"
docker exec -ti "$NAME" bash -c "/scfbuild/bin/scfbuild -c /wd/scfbuild-black.yml"
docker run \
--mount=type=bind,source="$PWD",destination=/mnt,relabel=private \
--rm \
$tty \
registry.gitlab.com/mavit/nanoemoji-container:master \
sh -c "
set -o errexit
# stop container
docker stop "$NAME"
nanoemoji \
--color_format=$format \
--build_dir=$build_dir \
--output_file=$build_dir/$name.$format.ttf \
/mnt/$saturation/svg/*.svg
xmlstarlet edit --inplace --update \
'/ttFont/name/namerecord[@nameID=\"5\"][@platformID=\"3\"]' \
--value '$version' \
/mnt/font/$name.ttx
ttx \
-m $build_dir/$name.$format.ttf \
-o /mnt/font/$format/$name.ttf \
/mnt/font/$name.ttx
"
done
done

0 comments on commit 2f42f81

Please sign in to comment.