Skip to content

Commit eb6ab85

Browse files
committed
Updated patch-hack.sh to
- allow HACK_PATH to be provided as an environment variable - allow replacement glyphs to be provided as command-line arguments - automatically replace hinting rules for modified glyphs Update README.md to describe some of the changes to the repository. Added create-pngs.sh to create transparent pngs with a consistent size for all modified characters of a given font set. This should help a developer produce pngs suitable for use on the alt-hack github site.
1 parent 642ba47 commit eb6ab85

File tree

3 files changed

+103
-20
lines changed

3 files changed

+103
-20
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ This repository is open to contributions of new glyph designs intended to be use
99
## Usage
1010

1111
### View Alternate Glyph Styles
12-
The `*.glif` source files are located in the `glyphs` directory of this repository and are organized by Unicode code point. A short string is added to the Unicode code point to describe the type of design modification that was performed to the Hack default style. Source files are supplied for regular, bold, italic, and bold italic font variants.
13-
14-
You may view images of the alternate designs in the README.md files at the top level of each alternate glyph directory.
12+
The `*.glif` source files are located in the `glyphs` directory of this repository. Each one is named to show the character modified along with a short string to describe the type of design modification that was performed to the Hack default style. Source files are supplied for regular, bold, italic, and bold italic font variants.
1513

14+
You may view images of the alternate designs in the README.md files at the top level of each alternate glyph directory or see an overview of all the modifications in README.md in the `glyphs` directory itself.
1615

1716
### How to Build a Custom Version of Hack
1817

@@ -50,6 +49,8 @@ Alternatively, you can do the copying manually. Copy the alternate glyph source
5049
#### Eliminate existing manual instruction sets for alternate glyphs (if present)
5150
Some of the glyphs in the Hack sets include manual changes to the ttfautohint automated instruction sets ("hints"). These must be eliminated if you replace an existing glyph in the main Hack sets with a stylistic alternate from this repository or your build will fail (or create undesirable rendering changes that are not tuned for the alternate glyph).
5251

52+
This process is automated within the `patch-hack.sh` script but if you want to manually disable hints, keep reading.
53+
5354
The control instructions files that are used to manually modify the hints in the Hack builds are located in the [tt-hinting directory](https://github.com/source-foundry/Hack/tree/master/postbuild_processing/tt-hinting) of the Hack repository. There is one text file per Hack variant (i.e. for Regular, Italic, Bold, and Bold Italic sets). The manual hints are organized by Unicode code point.
5455

5556
Examine these control instructions files before you build your new fonts. If you identify a block of instructions under a heading for a Unicode code point that you intend to replace, either delete all lines associated with that glyph or comment out the block with `#` symbols at the beginning of each line.

create-pngs.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
if [ $# -eq 0 ]; then
6+
echo "Usage: create-pngs.sh PATH"
7+
echo " Create transparent pngs with a consistent size for all, potentially, replaced"
8+
echo " characters appropriate for uploading to the github alt-hack page."
9+
echo ""
10+
echo " PATH A Hack build directory containing Hack-{Regular,Bold,Italic,BoldItalic}.ttf files"
11+
echo ""
12+
echo "Image files are written to a pngs/ directory"
13+
echo ""
14+
echo "This tool depends on the \"convert\" tool from ImageMagick"
15+
exit 1
16+
fi
17+
18+
# Map each character to the glif name
19+
declare -A chars=(
20+
["&"]="ampersand"
21+
[">"]="greater"
22+
["<"]="less"
23+
["f"]="f"
24+
["ğ"]="gbreve"
25+
["ǧ"]="gcaron"
26+
["ĝ"]="gcircumflex"
27+
["ġ"]="gdotaccent"
28+
["g"]="g"
29+
["ģ"]="uni0123"
30+
["ı"]="dotlessi"
31+
["í"]="iacute"
32+
["ĭ"]="ibreve"
33+
["î"]="icircumflex"
34+
["ï"]="idieresis"
35+
["i"]="i"
36+
["ì"]="igrave"
37+
["ī"]="imacron"
38+
["į"]="iogonek"
39+
["ĩ"]="itilde"
40+
["і"]="uni0456"
41+
["ї"]="uni0457"
42+
["ĺ"]="lacute"
43+
["ľ"]="lcaron"
44+
["ŀ"]="ldot"
45+
["l"]="l"
46+
["ł"]="lslash"
47+
["ļ"]="uni013C"
48+
["1"]="one"
49+
["("]="parenleft"
50+
[")"]="parenright"
51+
["%"]="percent"
52+
["["]="bracketleft"
53+
["]"]="bracketright"
54+
["3"]="three"
55+
["0"]="zero"
56+
)
57+
58+
mkdir -p pngs
59+
60+
for char in "${!chars[@]}"; do
61+
desc="${chars[$char]}"
62+
for style in Regular Bold Italic BoldItalic; do
63+
filename=./pngs/"${desc}"-"${style}".png
64+
echo Creating "${filename}"
65+
convert -font "${1}"/Hack-"${style}".ttf -background transparent -size 36x60\
66+
label:"${char}" "${filename}"
67+
done
68+
done

patch-hack.sh

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,41 @@
66
# Source: https://github.com/source-foundry/alt-hack
77
# ---------------------------------------------------
88

9-
# 1. Set the path to the downloaded Hack repo here first
10-
HACK_PATH=""
9+
# 1. Set the path to the downloaded Hack repo, or set HACK_PATH environment variable
10+
HACK_PATH="${HACK_PATH:=""}"
1111

12-
# 2. List your alternate glyphs here
12+
# 2. List your alternate glyphs here, or specify them on the command line
1313
declare -a alternates=(
14-
# "zero-dotted"
15-
"zero-forwardslash"
16-
# "zero-backslash"
17-
# "zero-diamond"
18-
"one-noslab"
19-
# "three-flattop"
20-
"g-loop"
14+
"ampersand-nogap"
15+
# "angle-brackets-wider"
2116
# "f-knife"
17+
"g-loop"
2218
"i-slab"
2319
"l-slab"
24-
"percent-traditional"
25-
"ampersand-nogap"
20+
"one-noslab"
2621
# "parentheses-curved"
2722
"parentheses-rounder"
28-
# "angle-brackets-wider"
23+
"percent-traditional"
2924
# "square-brackets-oldv3"
25+
# "three-flattop"
26+
# "zero-dotted"
27+
"zero-forwardslash"
28+
# "zero-backslash"
29+
# "zero-diamond"
3030
)
3131

3232
# 3. Run this script and enjoy!
3333

3434
# ------------------------------------------------------------------------------------------------ #
3535

36-
if [ -z $HACK_PATH ]; then
37-
echo "❌ Set the HACK_PATH variable in this script to your downloaded Hack repo root."
36+
# If arguments provided, use them as alternates instead
37+
if [ $# -gt 0 ]; then
38+
alternates=("$@")
39+
fi
40+
41+
if [ -z "$HACK_PATH" ]; then
42+
echo "❌ Set the HACK_PATH variable in this script or via an environment variable to your"\
43+
"downloaded Hack repo root."
3844
exit 1
3945
fi
4046

@@ -48,13 +54,21 @@ do
4854
lowercaseStyle=$(echo "$style" | tr '[:upper:]' '[:lower:]')
4955
alternatePath="./glyphs/${alternate}/${lowercaseStyle}"
5056

51-
if ! cp "$alternatePath"/*.glif "$stylePath"; then
57+
if ! cp "${alternatePath}"/*.glif "${stylePath}"; then
5258
echo "❌ Aborting patching of Hack, check errors above."
5359
exit 1
5460
fi
61+
62+
# Extract the unicode hex values from each glif
63+
while read -r hexcode
64+
do
65+
# Remove hinting of patched glyphs
66+
sed -i "s/^\(uni${hexcode}\)/#\1/" \
67+
"${HACK_PATH}"/postbuild_processing/tt-hinting/Hack-"${style}"-TA.txt
68+
done < <(grep "unicode hex=" "${alternatePath}"/*.glif | sed 's/.*"\(.*\)".*/\1/' | sort -u)
5569
done
5670

57-
echo "✅ Patched $alternate"
71+
echo "✅ Patched ${alternate}"
5872
done
5973

6074
echo

0 commit comments

Comments
 (0)