Skip to content

Commit

Permalink
Full oxipng integration
Browse files Browse the repository at this point in the history
  • Loading branch information
PoomSmart committed Jan 28, 2023
1 parent 43945e2 commit 462d3cb
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Internal resources
Fonts
release
release.sh
update-deb.sh

# Font assets
Expand Down
2 changes: 1 addition & 1 deletion QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ macOS machine with homebrew and Python 3.7+ installed, assumed:

```
bash -c "pip3 install afdko fonttools[repacker]"
brew install pngquant freetype imagemagick librsvg inkscape php
brew install bash pngquant oxipng freetype imagemagick librsvg inkscape php
```

## AppleColorEmoji font
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Python and shell scripts to backport and theme [Apple Color Emoji font](https://

# Prerequisites

- Bash version 5+ (`brew install bash`)
- [Python 3.7 or later](http://www.python.org/download/)
- [pip](https://pip.pypa.io/en/stable/)
- [fonttools](https://github.com/fonttools/fonttools) (`pip3 install fonttools[repacker]`)
Expand Down Expand Up @@ -48,6 +49,8 @@ EmojiFonts deals with certain font tables; mainly `GDEF` and `sbix`.

Theming scripts for all emojis vendors produce the font in TTC format. The font may be used by EmojiFontManager iOS tweak, and is guaranteed to work on iOS 6 and higher. Ensure that you executed `apple.sh` before following instructions below.

It is recommended to limit the depth of clone to `1` (`git clone --depth 1 REPO-URL`) because the repository size is usually big.

## Blobmoji Emoji

1. Clone [blobmoji](https://github.com/C1710/blobmoji) and place its folder alongside this project.
Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# TODOs

- [ ] Batch convert SVGs into PNGs faster (something other than `rsvg-convert`)
- [ ] Convert from SVGs into PNGs with sufficient memory (to replace the slow `inkscape`)
- [ ] Decouple from `emoji-data` repository
- [ ] FluentUI Emoji HD
Expand Down
11 changes: 6 additions & 5 deletions apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
from fontTools import ttLib
from shared import get_image_data, prepare_strikes

# input: input font ttf, output font ttf, assets folder
# input: HD boolean, input font ttf, output font ttf, assets folder

ittf = sys.argv[1]
ottf = sys.argv[2]
assets = sys.argv[3]
hd = int(sys.argv[1]) == 1
ittf = sys.argv[2]
ottf = sys.argv[3]
assets = sys.argv[4]

f = ttLib.TTFont(ittf)

prepare_strikes(f)
prepare_strikes(f, hd)
for ppem, strike in f['sbix'].strikes.items():
print(f'Reading strike of size {ppem}x{ppem}')
for name, glyph in strike.glyphs.items():
Expand Down
12 changes: 6 additions & 6 deletions apple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MAC_FONT_NAME=AppleColorEmoji_macOS
ASSETS=$NAME
MOD=$1
COLORS=
[[ $MOD = 'HD' ]] && HD=1 || HD=0

mkdir -p $ASSETS

Expand All @@ -28,15 +29,14 @@ then
wait
fi

echo "Optimizing PNGs using pngquant..."
[[ $MOD == 'HD' ]] && pngquant -f --ext .png $ASSETS/160/*.png &
echo "Optimizing PNGs..."
[[ $HD ]] && pngquant -f --ext .png $ASSETS/160/*.png &
pngquant $COLORS -f --ext .png $ASSETS/96/*.png &
pngquant $COLORS -f --ext .png $ASSETS/64/*.png &
pngquant $COLORS -f --ext .png $ASSETS/40/*.png &
wait

echo "Optimizing PNGs using oxipng..."
[[ $MOD == 'HD' ]] && oxipng -q $ASSETS/160/*.png &
[[ $HD ]] && oxipng -q $ASSETS/160/*.png &
oxipng -q $ASSETS/96/*.png &
oxipng -q $ASSETS/64/*.png &
oxipng -q $ASSETS/40/*.png &
Expand All @@ -49,8 +49,8 @@ else
OUT_FONT_NAME=AppleColorEmoji@2x
fi

python3 $NAME.py common/${IOS_FONT_NAME}_00.ttf apple/${OUT_FONT_NAME}_00.ttf $ASSETS &
python3 $NAME.py common/${IOS_FONT_NAME}_01.ttf apple/${OUT_FONT_NAME}_01.ttf $ASSETS &
python3 $NAME.py $HD common/${IOS_FONT_NAME}_00.ttf apple/${OUT_FONT_NAME}_00.ttf $ASSETS &
python3 $NAME.py $HD common/${IOS_FONT_NAME}_01.ttf apple/${OUT_FONT_NAME}_01.ttf $ASSETS &
wait
rm -f apple/$OUT_FONT_NAME.ttf
ln apple/${OUT_FONT_NAME}_00.ttf apple/$OUT_FONT_NAME.ttf
Expand Down
6 changes: 5 additions & 1 deletion facebook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mogrify -resize 40x40 -path $NAME-extra/images/40 $NAME-extra/images/64/*.png
# mogrify -resize 32x32 -path $NAME-extra/images/32 $NAME-extra/images/40/*.png
# mogrify -resize 20x20 -path $NAME-extra/images/20 $NAME-extra/images/32/*.png

echo "Optimizing PNGs using pngquant..."
echo "Optimizing PNGs..."
pngquant -f --ext .png $NAME/images/96/*.png &
pngquant -f --ext .png $NAME/images/64/*.png &
# pngquant -f --ext .png $NAME/images/48/*.png &
Expand All @@ -45,6 +45,10 @@ pngquant -f --ext .png $NAME/images/40/*.png &
# pngquant -f --ext .png $NAME/images/20/*.png &
pngquant -f --ext .png $NAME-extra/images/*/*.png &
wait
oxipng -q $NAME/images/96/*.png &
oxipng -q $NAME/images/64/*.png &
oxipng -q $NAME/images/40/*.png &
wait

python3 $NAME.py apple/${FONT_NAME}_00.ttf &
python3 $NAME.py apple/${FONT_NAME}_01.ttf &
Expand Down
6 changes: 5 additions & 1 deletion fluentui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ mogrify -resize 40x40 -path "$ASSETS"/40 "$ASSETS"/64/*.png
# mogrify -resize 32x32 -path "$ASSETS"/32 "$ASSETS"/40/*.png
# mogrify -resize 20x20 -path "$ASSETS"/20 "$ASSETS"/32/*.png

echo "Optimizing PNGs using pngquant..."
echo "Optimizing PNGs..."
pngquant -f --ext .png "$ASSETS"/96/*.png &
pngquant -f --ext .png "$ASSETS"/64/*.png &
# pngquant -f --ext .png "$ASSETS"/48/*.png &
pngquant -f --ext .png "$ASSETS"/40/*.png &
# pngquant -f --ext .png "$ASSETS"/32/*.png &
# pngquant -f --ext .png "$ASSETS"/20/*.png &
wait
oxipng -q "$ASSETS"/96/*.png &
oxipng -q "$ASSETS"/64/*.png &
oxipng -q "$ASSETS"/40/*.png &
wait

python3 $NAME.py apple/${FONT_NAME}_00.ttf "$STYLE" &
python3 $NAME.py apple/${FONT_NAME}_01.ttf "$STYLE" &
Expand Down
5 changes: 4 additions & 1 deletion joypixels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ mogrify -resize 40x40 -path $ASSETS/40 $ASSETS/64/*.png
# mogrify -resize 32x32 -path $ASSETS/32 $ASSETS/40/*.png
# mogrify -resize 20x20 -path $ASSETS/20 $ASSETS/32/*.png

echo "Optimizing PNGs using pngquant..."
echo "Optimizing PNGs..."
pngquant -f --ext .png $ASSETS/*/*.png &
pngquant -f --ext .png $NAME-extra/images/*/*.png &
wait
oxipng -q $ASSETS/*/*.png &
oxipng -q $NAME-extra/images/*/*.png &
wait

python3 $NAME.py apple/${FONT_NAME}_00.ttf $MOD &
python3 $NAME.py apple/${FONT_NAME}_01.ttf $MOD &
Expand Down
7 changes: 4 additions & 3 deletions noto-emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

fontname = 'noto-emoji'

# input: font ttf
# input: HD boolean, font ttf

ttf = sys.argv[1]
hd = sys.argv[1] == 'true'
ttf = sys.argv[2]

f = ttLib.TTFont(ttf)

Expand All @@ -21,7 +22,7 @@ def noto_name(name: str):
result = '_'.join(n)
return 'u' + result

prepare_strikes(f)
prepare_strikes(f, hd)
for ppem, strike in f['sbix'].strikes.items():
print(f'Reading strike of size {ppem}x{ppem}')
for name, glyph in strike.glyphs.items():
Expand Down
8 changes: 4 additions & 4 deletions noto-emoji.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ NAME=noto-emoji
ASSETS=../$NAME/svg
FLAG_ASSETS=../$NAME/third_party/region-flags/waved-svg
MAX_SIZE=96
[[ $1 == 'HD' ]] && HD=true
[[ $1 == 'HD' ]] && HD=true || HD=false

[[ $HD = true ]] && MAX_SIZE=160

rm -rf $NAME
rm -rf $NAME/images
mkdir -p $NAME/images/160 $NAME/images/96 $NAME/images/64 $NAME/images/48 $NAME/images/40 $NAME/images/32 $NAME/images/20

echo "Converting SVGs into PNGs..."
Expand Down Expand Up @@ -48,8 +48,8 @@ echo "Resizing and optimizing PNGs..."
./resize.sh $NAME $HD false false
./resize.sh $NAME-extra $HD false false

python3 $NAME.py apple/${FONT_NAME}_00.ttf &
python3 $NAME.py apple/${FONT_NAME}_01.ttf &
python3 $NAME.py $HD apple/${FONT_NAME}_00.ttf &
python3 $NAME.py $HD apple/${FONT_NAME}_01.ttf &
wait

if [[ $HD = true ]]; then
Expand Down
1 change: 1 addition & 0 deletions oneui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cp $NAME-extra/original/*.png $NAME-extra/images/96
./get-assets.sh oneui

pngquant -f --ext .png $NAME-extra/images/*/*.png
oxipng -q $NAME-extra/images/*/*.png

python3 $NAME.py apple/${APPLE_FONT_NAME}_00.ttf $NAME/$FONT_NAME.ttf $NAME/$FONT_NAME.G_S_U_B_.ttx &
python3 $NAME.py apple/${APPLE_FONT_NAME}_01.ttf $NAME/$FONT_NAME.ttf $NAME/$FONT_NAME.G_S_U_B_.ttx &
Expand Down
7 changes: 4 additions & 3 deletions openmoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

fontname = 'openmoji'

# input: font ttf
# input: HD boolean, font ttf

ttf = sys.argv[1]
hd = sys.argv[1] == 'true'
ttf = sys.argv[2]

f = ttLib.TTFont(ttf)

Expand All @@ -25,7 +26,7 @@ def norm_special(name: str):
def openmoji_name(name: str):
return name.replace('_', '-').upper()

prepare_strikes(f)
prepare_strikes(f, hd)
for ppem, strike in f['sbix'].strikes.items():
print(f'Reading strike of size {ppem}x{ppem}')
for name, glyph in strike.glyphs.items():
Expand Down
8 changes: 4 additions & 4 deletions openmoji.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ FONT_NAME=AppleColorEmoji@2x
NAME=openmoji
ASSETS=../$NAME/color/svg
MAX_SIZE=96
[[ $1 == 'HD' ]] && HD=true
[[ $1 == 'HD' ]] && HD=true || HD=false

[[ $HD = true ]] && MAX_SIZE=160

rm -rf $NAME
rm -rf $NAME/images
mkdir -p $NAME/images/160 $NAME/images/96 $NAME/images/64 $NAME/images/48 $NAME/images/40 $NAME/images/32 $NAME/images/20

cd $NAME-extra
Expand Down Expand Up @@ -42,8 +42,8 @@ echo "Resizing and optimizing PNGs..."
./resize.sh $NAME $HD false false true
./resize.sh $NAME-extra $HD false false true

python3 $NAME.py apple/${FONT_NAME}_00.ttf &
python3 $NAME.py apple/${FONT_NAME}_01.ttf &
python3 $NAME.py $HD apple/${FONT_NAME}_00.ttf &
python3 $NAME.py $HD apple/${FONT_NAME}_01.ttf &
wait

if [[ $HD = true ]]; then
Expand Down
5 changes: 1 addition & 4 deletions resize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ set -e
NAME=$1
HD=$2
FULL=$3
COLORS=
[[ $4 = true ]] && COLORS=256

[[ $4 = true ]] && COLORS=256 || COLORS=

if [[ $HD = true ]]; then
mogrify -resize 160x160 $NAME/images/160/*.png
Expand All @@ -34,5 +32,4 @@ else
fi
wait

echo "Optimizing PNGs using oxipng..."
oxipng -q $NAME/images/*/*.png
5 changes: 2 additions & 3 deletions shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ def get_image_data(path: str):
with open(path, 'rb') as fin:
return fin.read()

def prepare_strikes(f: ttLib.TTFont):
if 160 in f['sbix'].strikes:
def prepare_strikes(f: ttLib.TTFont, hd = False):
if not hd and 160 in f['sbix'].strikes:
f['sbix'].strikes.pop(160)
# pass
11 changes: 3 additions & 8 deletions templates/semi-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ mogrify -resize 32x32 -path $NAME/images/32 $NAME/images/40/*.png
mogrify -resize 20x20 -path $NAME/images/20 $NAME/images/32/*.png
rm -rf $NAME/bitmaps

echo "Optimizing PNGs using pngquant..."
pngquant -f --ext .png $NAME/images/96/*.png
pngquant -f --ext .png $NAME/images/64/*.png
pngquant -f --ext .png $NAME/images/48/*.png
pngquant -f --ext .png $NAME/images/40/*.png
pngquant -f --ext .png $NAME/images/32/*.png
pngquant -f --ext .png $NAME/images/20/*.png
# pngquant -f --ext .png $NAME-extra/images/*/*.png
echo "Optimizing PNGs..."
./resize.sh $NAME false false false
# ./resize.sh $NAME-extra false false false

python3 $NAME.py common/${APPLE_FONT_NAME}_00.ttf $NAME/$FONT_NAME.ttf $NAME/$FONT_NAME.G_S_U_B_.ttx
python3 $NAME.py common/${APPLE_FONT_NAME}_01.ttf $NAME/$FONT_NAME.ttf $NAME/$FONT_NAME.G_S_U_B_.ttx
Expand Down
7 changes: 4 additions & 3 deletions twemoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

fontname = 'twemoji'

# input: font ttf
# input: HD boolean, font ttf

ttf = sys.argv[1]
hd = sys.argv[1] == 'true'
ttf = sys.argv[2]

f = ttLib.TTFont(ttf)

Expand All @@ -23,7 +24,7 @@ def norm_special(name: str):
def twitter_name(name: str):
return name.replace('_', '-')

prepare_strikes(f)
prepare_strikes(f, hd)
for ppem, strike in f['sbix'].strikes.items():
print(f'Reading strike of size {ppem}x{ppem}')
for name, glyph in strike.glyphs.items():
Expand Down
8 changes: 4 additions & 4 deletions twemoji.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ FONT_NAME=AppleColorEmoji@2x
NAME=twemoji
ASSETS=../$NAME/assets/svg
MAX_SIZE=96
[[ $1 == 'HD' ]] && HD=true
[[ $1 == 'HD' ]] && HD=true || HD=false

[[ $HD = true ]] && MAX_SIZE=160

rm -rf $NAME
rm -rf $NAME/images
mkdir -p $NAME/images/160 $NAME/images/96 $NAME/images/64 $NAME/images/48 $NAME/images/40 $NAME/images/32 $NAME/images/20

echo "Converting SVGs into PNGs..."
Expand Down Expand Up @@ -39,8 +39,8 @@ echo "Resizing and optimizing PNGs..."
./resize.sh $NAME $HD false false
./resize.sh $NAME-extra $HD false false

python3 $NAME.py apple/${FONT_NAME}_00.ttf &
python3 $NAME.py apple/${FONT_NAME}_01.ttf &
python3 $NAME.py $HD apple/${FONT_NAME}_00.ttf &
python3 $NAME.py $HD apple/${FONT_NAME}_01.ttf &
wait

if [[ $HD = true ]]; then
Expand Down
1 change: 1 addition & 0 deletions whatsapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rm -rf $NAME/bitmaps
./get-assets.sh whatsapp

pngquant -f --ext .png $NAME-extra/images/*/*.png
oxipng -q $NAME-extra/images/*/*.png

python3 $NAME.py apple/${APPLE_FONT_NAME}_00.ttf $NAME/$FONT_NAME.ttf $NAME/$FONT_NAME.G_S_U_B_.ttx &
python3 $NAME.py apple/${APPLE_FONT_NAME}_01.ttf $NAME/$FONT_NAME.ttf $NAME/$FONT_NAME.G_S_U_B_.ttx &
Expand Down

0 comments on commit 462d3cb

Please sign in to comment.