Skip to content

Commit

Permalink
Update build script: added format options
Browse files Browse the repository at this point in the history
+ instead of Mutant Standard, the font family is Mutant Standard Emoji (like it used to be)
+ update readme, install script
  • Loading branch information
Zentropivity committed Oct 7, 2024
1 parent 2cc5e92 commit f92461c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 28 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ First you need to make sure the required tools are installed:

0. Make sure you have the submodules. Either clone this repo with `--recursive` or do `git submodule update --init`
1. Create a python virtual environment and activate it, like: `python -m venv venv` then source the activation file for your shell (for nushell just run `./pyvenv`)
2. Run `./build_ttf.nu`
this produces the font file in `out/build/MutantStandard-Regular.ttf`
2. Run `./build_ttf.nu -i cbdt`
this produces the font file in `out/build/MutantStandardEmoji-CBDT.ttf`
(Note: you can build other font formats too, check `./build_ttf.nu -h` or the script for more info)
3. On linux, you could also copy the font and its license to the system fonts by running `sudo ./install.nu`

## Fuzzy finder!
## Fuzzy finder in the command line!

If you want to be able to fuzzy find specific emoji from the Mutant Standard set, you could try running `export_memoji_codes.nu`
The output text file will have the format of `emoji character` `space` `emoji shortcode` (so a line may be like this: `😸 cat_smile`)
Expand Down
104 changes: 81 additions & 23 deletions build_ttf.nu
Original file line number Diff line number Diff line change
@@ -1,34 +1,92 @@
#!/usr/bin/nu

# Build ttf font file for Mutant Standard.
# you should be running this from some venv...
def main [
--install_deps (-i) # install the deps of orxporter and nanoemoji
--all_formats (-a) # build all the formats (that we may need)
format="cbdt" # colr_glyf / colr_cff / cbdt / sbix / svg / raw
] {
if $install_deps {
pip install -r orxporter/requirements.txt
pip install -e nanoemoji
}

#install deps
pip install -r orxporter/requirements.txt
pip install -e nanoemoji
if $all_formats {
generate
[
["glyf_colr_1","COLR-GLYF"],
["cff2_colr_1","COLR-CFF"],
["cbdt","CBDT"],
["sbix","SBIX"],
["picosvg","SVG"],
["untouchedsvg","Raw"],
] | each {|p| do_build $p.0 $p.1 e>| print -e | print}
return null
} else {
if $format == "colr_glyf" {
generate
do_build "glyf_colr_1" "COLR-GLYF"
} else if $format == "colr_cff" {
generate
do_build "cff2_colr_1" "COLR-CFF"
} else if $format == "cbdt" {
generate
do_build "cbdt" "CBDT"
} else if $format == "sbix" {
generate
do_build "sbix" "SBIX"
} else if $format == "svg" {
generate
do_build "picosvg" "SVG"
} else if $format == "raw" {
generate
do_build "untouchedsvg" "SVG-Raw"
} else {
print $"Unrecognized format: ($format)"
exit 1
}
}
}

#NOTE conversion from/to hex is like this
# ❯ 128488 | fmt | $in.lowerhex | str substring 2..
# 1f5e8
# ❯ "1f5e8" | into int --radix 16
# 128488

mkdir out
python ./orxporter/orxport.py -m ./mutant_standard/manifest/out.orx -i ../input -q 32x32 -o ./out/font_sources -F svg -t 8 -f %f/%u
python ./orxporter/orxport.py -m ./mutant_standard/manifest/out.orx -i ../input -j ./out/meta.json
open ./out/meta.json | reduce -f {} {|it, acc| try { let emoji = char --integer ...($it.code); $acc |
insert ($it.code | each {|i| $i | fmt | $in.lowerhex | str substring 2..} | str join "-") {
name: $it.short,
glyph_name: (if 0 < ($it.short | find -r "^[0-9]" | length) { "_" | append $it.short | str join } else { $it.short })
} } catch { $acc }} | to json | save -f ./out/unicode_map.json

# remove px from lengths as picosvg (used by nanoemoji) dies from it and its fine without px probably
ls ./out/font_sources/svg/ | get name | par-each {|fp| open $fp | str replace --all -r "(:[0-9.]+)px" "$1" | save -f $fp}

let version = open ./mutant_standard/manifest/font/manifest.json | $in.metadata.version | split row "."
let version_major = $version | get 0
let version_minor = $version | get 1

cd out
#TODO figure out glyphmap generation for glyph names in ttf
# nanoemoji --color_format glyf_colr_1 --glyphmap_generator ../glyphmap_generator.nu --family "Mutant Standard" --output_file MutantStandard-Regular.ttf --version_major $version_major --version_minor $version_minor ./font_sources/svg/*.svg
nanoemoji --color_format glyf_colr_1 --family "Mutant Standard" --output_file MutantStandard-Regular.ttf --version_major $version_major --version_minor $version_minor ./font_sources/svg/*.svg
# Generate output using orxporter
def generate [] {
mkdir out
python ./orxporter/orxport.py -m ./mutant_standard/manifest/out.orx -i ../input -q 32x32 -o ./out/font_sources -F svg -t 8 -f %f/%u
python ./orxporter/orxport.py -m ./mutant_standard/manifest/out.orx -i ../input -j ./out/meta.json

#TODO? use this for glyphmap name generation?
open ./out/meta.json | reduce -f {} {|it, acc| try { let emoji = char --integer ...($it.code); $acc |
insert ($it.code | each {|i| $i | fmt | $in.lowerhex | str substring 2..} | str join "-") {
name: $it.short,
glyph_name: (if 0 < ($it.short | find -r "^[0-9]" | length) { "_" | append $it.short | str join } else { $it.short })
} } catch { $acc }} | to json | save -f ./out/unicode_map.json

# remove px from lengths as picosvg (used by nanoemoji) dies from it and its fine without px probably
ls ./out/font_sources/svg/ | get name | par-each {|fp| open $fp | str replace --all -r "(:[0-9.]+)px" "$1" | save -f $fp}
}

# Build it for real!
def do_build [
color_format # nanoemoji color_format
file_ext # text added to base ttf file name after "-" (no "-" if empty)
] {
let version = open ./mutant_standard/manifest/font/manifest.json | $in.metadata.version | split row "."
let version_major = $version | get 0
let version_minor = $version | get 1

let file_name = if $file_ext == "" { "MutantStandardEmoji.ttf" } else { $"MutantStandardEmoji-($file_ext).ttf" }
# let build_dir = if $file_ext == "" { "./out/build/" } else { $"./out/TTF-($file_ext)/" }
let build_dir = "./out/build/"
mkdir $build_dir

#TODO figure out glyphmap generation for glyph names in ttf
# --glyphmap_generator ../glyphmap_generator.nu
nanoemoji --color_format $color_format --family "Mutant Standard Emoji" --build_dir $build_dir --output_file $file_name --version_major $version_major --version_minor $version_minor ./out/font_sources/svg/*.svg
}
5 changes: 3 additions & 2 deletions install.nu
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/nu

cp -r ./mutant_standard/manifest/license /usr/share/licenses/ttf-mutant-standard
cp ./out/build/MutantStandard-Regular.ttf /usr/share/fonts/TTF/
cp -r -f ./mutant_standard/manifest/license /usr/share/licenses/ttf-mutant-standard
mkdir /usr/share/fonts/mutant-standard
cp -f ./out/build/MutantStandard-*.ttf /usr/share/fonts/mutant-standard/

0 comments on commit f92461c

Please sign in to comment.