Skip to content

Commit

Permalink
This is a start.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zentropivity committed Sep 27, 2024
0 parents commit ea83660
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
venv
out
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "mutant_standard"]
path = mutant_standard
url = https://github.com/mutantstandard/build.git
[submodule "orxporter"]
path = orxporter
url = https://github.com/mutantstandard/orxporter.git
[submodule "nanoemoji"]
path = nanoemoji
url = https://github.com/googlefonts/nanoemoji.git
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Build Mutant Standard as TTF font

Why? Because its a great emoji font! I want to see them all over my desktop.

## How?

First you need to make sure the required tools are installed:

- `nushell` (probably could have made it without, but I like to script using it `¯\_(ツ)_/¯`)
- `python` (and its virtualenv/venv and pip)
- `git` of course

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 right activation file for your shell
2. Run `build_ttf.nu`
this produces the font file in `out/build/MutantStandard-Regular.ttf`
3. On linux, you could also copy the font and its license to the system fonts by running `sudo install.nu`

## License

Everything in this repository is licensed under a MIT license, except the materials used under the repositories in the folliwing folders have their own licensing:

- Mutant Standard emoji in `mutant_standard` are licensed CC BY-NC-SA 4.0 International
- Orxporter in `orxporter` is licensed under the Cooperative Non-Violent License (CNPL) v4
- nanoemoji in `nanoemoji` is licensed under the Apache-2.0 license

## Your contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.
34 changes: 34 additions & 0 deletions build_ttf.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/nu

# you should be running this from some venv...

#install deps
pip install -r orxporter/requirements.txt
pip install -e nanoemoji

#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
18 changes: 18 additions & 0 deletions glyphmap_generator.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/nu

# It is recommended to name the glyphs so here we go taking the short names. Undefined codepoints don't make it into the font unfortunately.
# according some page on the internet: http://silnrsi.github.io/FDBP/en-US/Glyph_Naming.html
# nanoemoji needs the generator to output csv like: filename,codepoints,glyphname
#TODO? this may need to be python? why no docs on glyphmap generator usage? I will keep searching...

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

def main [...files] {
let codes_req = $files | par-each {|fp| $fp | split row "/" | last 1 | get 0 | split row "." | get 0 | {path: $fp, code: $in} }
let map = open "./out/unicode_map.json"
return ($codes_req | par-each {|e| $"($e.path),($e.code | str replace --all "-" ","),($map | get $e.code | get glyph_name)"} | str join "\n")
}
4 changes: 4 additions & 0 deletions install.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/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/
1 change: 1 addition & 0 deletions mutant_standard
Submodule mutant_standard added at b0f12c
1 change: 1 addition & 0 deletions nanoemoji
Submodule nanoemoji added at fbd1a3
1 change: 1 addition & 0 deletions orxporter
Submodule orxporter added at 5e053a

0 comments on commit ea83660

Please sign in to comment.