Skip to content

Commit

Permalink
Fix the Windows subfamily recognition issue by dropping redundant STA…
Browse files Browse the repository at this point in the history
…T table.
  • Loading branch information
Pal3love committed Mar 14, 2022
1 parent 63c5e10 commit bf82663
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
28 changes: 21 additions & 7 deletions script/build_fonts_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@


binary_folder="binary"
temp_folder="temp"
release_folder="release"
script_folder="script"
source_folder="source"
temp_folder="temp"

style_linked_weights=(40 70)
weights=(25 30 35 40 45 50 55 60 65 70 75 80 85 90)
Expand Down Expand Up @@ -32,10 +34,20 @@ function convert() {
done
}

function patch() {
function trimLegacyFamily() {
for style_linked_weight in ${style_linked_weights[@]}; do
for fontPath in `ls *"-W${style_linked_weight}.ttf"`; do {
python3 ../script/trim_english_font_family.py ${fontPath}
python3 ../${script_folder}/trim_english_font_family.py ${fontPath}
} & done
wait
done
}

function dropStatTable() {
for family in ${families[@]}; do
for weight in ${weights[@]}; do {
fontFileName="${family}-W${weight}.ttf"
python3 ../${script_folder}/drop_STAT_table.py ${fontFileName}
} & done
wait
done
Expand Down Expand Up @@ -113,7 +125,7 @@ mkdir ${temp_folder}
mkdir ${release_folder}

# Instantiate fonts from VF masters.
cd source/source-han-sans
cd ${source_folder}/source-han-sans
instantiate
cd ../source-han-serif
instantiate
Expand All @@ -132,15 +144,17 @@ rename "s/^Source/Dream/" Source*.ttf

# Generate TOML configuration files.
# Rebuild `name` table with generated configuration file.
python3 ../script/generate_config.py
python3 ../${script_folder}/generate_config.py
convert

# Patch style-linked font families.
# Trim style-linked font legacy families.
# Drop `STAT` table (containing variable font metadata) from all instance fonts.
# Combine full language fonts into TTC files.
# Delete duplicate TTF files.
# Compress font files into ZIPs.
cd ../${release_folder}
patch
trimLegacyFamily
dropStatTable
makeTtc
deleteTtf
compress
Expand Down
28 changes: 21 additions & 7 deletions script/build_fonts_wsl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@


binary_folder="binary"
temp_folder="temp"
release_folder="release"
script_folder="script"
source_folder="source"
temp_folder="temp"

style_linked_weights=(40 70)
weights=(25 30 35 40 45 50 55 60 65 70 75 80 85 90)
Expand Down Expand Up @@ -32,10 +34,20 @@ function convert() {
done
}

function patch() {
function trimLegacyFamily() {
for style_linked_weight in ${style_linked_weights[@]}; do
for fontPath in `ls *"-W${style_linked_weight}.ttf"`; do {
python3 ../script/trim_english_font_family.py ${fontPath}
python3 ../${script_folder}/trim_english_font_family.py ${fontPath}
} & done
wait
done
}

function dropStatTable() {
for family in ${families[@]}; do
for weight in ${weights[@]}; do {
fontFileName="${family}-W${weight}.ttf"
python3 ../${script_folder}/drop_STAT_table.py ${fontFileName}
} & done
wait
done
Expand Down Expand Up @@ -113,7 +125,7 @@ mkdir ${temp_folder}
mkdir ${release_folder}

# Instantiate fonts from VF masters.
cd source/source-han-sans
cd ${source_folder}/source-han-sans
instantiate
cd ../source-han-serif
instantiate
Expand All @@ -132,15 +144,17 @@ rename "s/^Source/Dream/" Source*.ttf

# Generate TOML configuration files.
# Rebuild `name` table with generated configuration file.
python3 ../script/generate_config.py
python3 ../${script_folder}/generate_config.py
convert

# Patch style-linked font families.
# Trim style-linked font legacy families.
# Drop `STAT` table (containing variable font metadata) from all instance fonts.
# Combine full language fonts into TTC files.
# Delete duplicate TTF files.
# Compress font files into ZIPs.
cd ../${release_folder}
patch
trimLegacyFamily
dropStatTable
makeTtc
deleteTtf
compress
Expand Down
22 changes: 22 additions & 0 deletions script/drop_STAT_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*

import sys
from fontTools.ttLib import TTFont


def main():
if len(sys.argv) < 2:
print("Usage: python3 drop_STAT_table.py <fontfile>", file = sys.stderr)
sys.exit(2)
fontPath = sys.argv[1]
font = TTFont(fontPath)
if font.has_key("STAT"):
del font["STAT"]
else:
pass
font.save(fontPath)


if __name__ == "__main__":
sys.exit(main())
2 changes: 1 addition & 1 deletion script/trim_english_font_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def main():
if len(sys.argv) < 2:
print("Usage: python3 trim-english-font-family.py <fontfile>", file = sys.stderr)
print("Usage: python3 trim_english_font_family.py <fontfile>", file = sys.stderr)
sys.exit(2)
fontPath = sys.argv[1]
font = TTFont(fontPath)
Expand Down

0 comments on commit bf82663

Please sign in to comment.