#!/bin/bash shopt -s extglob fontdir="$1.sfdir" DEFAULT_GLYPH_WIDTH=555 read -r -p "Font name:" fontname read -r -p "Full name:" fullname read -r -p "Unicode page offset (/256, 0 is 0xF3Axx):" offset mkdir "$fontdir" cat < "$fontdir/font.props" SplineFontDB: 3.2 FontName: $fontname FullName: $fullname Weight: Book Copyright: Copyright (C) $(date +%Y), $(id -un) UComments: "$(date +%Y-%M-%d): Created with mkemptyfont.sh" Version: 001.000 ItalicAngle: 0 UnderlinePosition: -150 UnderlineWidth: 50 Ascent: 800 Descent: 200 sfntRevision: 0x00010000 LayerCount: 2 Layer: 0 0 "Back" 1 Layer: 1 0 "Fore" 0 DisplaySize: -48 AntiAlias: 1 FitToEm: 0 Encoding: Custom CreationTime: $(date +%s) ModificationTime: $(date +%s) DEI: 91125 Lookup: 4 0 1 "'liga' Standard Ligatures in Latin lookup 0" { "'liga' Standard Ligatures in Latin lookup 0-1" } ['liga' ('DFLT' <'dflt' > 'latn' <'dflt' > ) ] EOF ord() { LC_CTYPE=C printf '%d' "'$1" } codepoint="$((0xF3A00 + offset * 256))" encodingidx=0 # generate the 'raw' replacement glyphs while read -r glyph_json; do while read -r liga_code_point; do glyph_file="$fontdir/raw$liga_code_point.glyph" if [ ! -e "$glyph_file" ]; then echo -n "Generating raw$liga_code_point..." cat < "$glyph_file" StartChar: raw$liga_code_point Encoding: $encodingidx $liga_code_point $encodingidx Width: $DEFAULT_GLYPH_WIDTH LayerCount: 2 Comment: "Raw glyph for ligature replacement" Colour: ff0000 EndChar EOF encodingidx=$((encodingidx + 1)) echo ' DONE' fi done < <(jq -r '.ortho | gsub("θ"; "th") | gsub("∫"; "sh") | explode[]' <<<"$glyph_json") done < <(cue export -p shenikan | jq -c '.dictionary.glyphs[]') # generate the 'real' ligature glyphs while read -r glyph_json; do liga=( ) while read -r liga_code_point; do liga+=( "raw$liga_code_point" ) done < <(jq -r '.ortho | gsub("θ"; "th") | gsub("∫"; "sh") | explode[]' <<<"$glyph_json") ortho="$(jq -r '.ortho' <<<"$glyph_json")" ascii_ortho="$(jq -r '.ortho | gsub("θ"; "th") | gsub("∫"; "sh") | @uri | gsub("%"; "q")' <<<"$glyph_json")" echo -n "Generating $ortho..." glyph_file="$fontdir/sh$ascii_ortho.glyph" cat < "$glyph_file" StartChar: sh$ascii_ortho Encoding: $encodingidx $codepoint $encodingidx Width: $DEFAULT_GLYPH_WIDTH LayerCount: 2 Comment: "Shenikan $ascii_ortho glyph" Ligature2: "'liga' Standard Ligatures in Latin lookup 0-1" ${liga[*]} EOF if [ "$(jq '.ortho | length' <<<"$glyph_json")" -gt 1 ]; then liga=( ) while read -r liga_code_point; do liga+=( "raw$liga_code_point" ) done < <(jq -r '.ortho | explode | reverse | implode | gsub("θ"; "th") | gsub("∫"; "sh") | explode[]' <<<"$glyph_json") echo "Ligature2: \"'liga' Standard Ligatures in Latin lookup 0-1\" ${liga[*]}" >> "$glyph_file" fi echo 'EndChar' >> "$glyph_file" encodingidx=$((encodingidx + 1)) codepoint=$((codepoint + 1)) echo ' DONE' done < <(cue export -p shenikan | jq -c '.dictionary.glyphs[]')