-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
716 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/.vscode | ||
/bin/merge-otd.exe | ||
/bin32/merge-otd.exe | ||
/release | ||
/.vscode | ||
/font-builder/src/*.otd | ||
/font-builder/out | ||
/bin/merge-otd.exe | ||
/bin32/merge-otd.exe | ||
/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# WFM Font Builder | ||
|
||
This is building script for fonts shipped with Warcraft Font Merger. It trims unneeded glyphs and features from original font files. | ||
|
||
## How to build | ||
|
||
```bash | ||
./build.bash | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
ver=0.4.0 | ||
|
||
for file in src/*.ttf ; do | ||
prefix=${file#*/} | ||
otfccdump --ignore-hints --pretty --glyph-name-prefix ${prefix,,}- $file -o ${file/ttf/otd} & | ||
done | ||
wait | ||
|
||
mkdir -p out | ||
|
||
python trim-droid.py & | ||
python trim-noto.py Medium $ver & | ||
python trim-shs-cn.py CN Medium gbk $ver & | ||
python trim-shs.py SC Medium gbk $ver & | ||
python trim-shs.py TC Medium big5 $ver & | ||
python trim-shs.py CL Medium big5 $ver & | ||
wait | ||
|
||
for file in out/*.otd ; do | ||
otfccbuild -O3 $file -o ${file/otd/ttf} & | ||
done | ||
wait | ||
|
||
rm src/*.otd out/*.otd |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
import json | ||
import sys | ||
|
||
def NameFont(font, region, weight, version): | ||
|
||
isStdStyle = weight == 'Regular' or weight == 'Bold' | ||
|
||
font['OS_2']['achVendID'] = 'Cyan' | ||
|
||
font['name'] = [ | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 0, | ||
"nameString": "Copyright © 2018—2019 Cyano Hao, with reserved font name “Nowar”, “有爱”, and “有愛”. Portions (c) Google Corporation 2006." | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 1, | ||
"nameString": "Nowar Sans (漢字 and 仮名) {}".format(region) if isStdStyle else "Nowar Sans (漢字 and 仮名) {} {}".format(region, weight) | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 2, | ||
"nameString": weight if isStdStyle else "Regular" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 3, | ||
"nameString": "Nowar Sans (漢字 and 仮名) {} {} {}".format(region, weight, version) | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 4, | ||
"nameString": "Nowar Sans (漢字 and 仮名) {} {}".format(region, weight) | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 5, | ||
"nameString": str(version) | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 6, | ||
"nameString": "Nowar-Sans-CJK-{}-{}".format(region, weight.replace(' ', '-')) | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 8, | ||
"nameString": "Cyano Hao" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 9, | ||
"nameString": "Steve Matteson" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 11, | ||
"nameString": "https://github.com/CyanoHao" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 13, | ||
"nameString": "Licensed under the Apache License, Version 2.0" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 14, | ||
"nameString": "http://www.apache.org/licenses/LICENSE-2.0" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 16, | ||
"nameString": "Nowar Sans (漢字 and 仮名) {}".format(region) | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 17, | ||
"nameString": weight | ||
}, | ||
] | ||
|
||
def CopyRef(glyph, a, b): | ||
if 'references' in glyph: | ||
for r in glyph['references']: | ||
if r['glyph'] not in a['glyf']: | ||
a['glyf'][r['glyph']] = b['glyf'][r['glyph']] | ||
CopyRef(a['glyf'][r['glyph']], a, b) | ||
|
||
def AddRef(n, font, ref): | ||
if n in ref: | ||
return | ||
glyph = font['glyf'][n] | ||
if 'references' in glyph: | ||
for r in glyph['references']: | ||
ref.append(r['glyph']) | ||
AddRef(r['glyph'], font, ref) | ||
|
||
def TrimGlyph(font): | ||
needed = [] | ||
for (_, n) in font['cmap'].items(): | ||
needed.append(n) | ||
ref = [] | ||
for n in needed: | ||
AddRef(n, font, ref) | ||
|
||
unneeded = [] | ||
for n in font['glyf']: | ||
if not (n in needed or n in ref): | ||
unneeded.append(n) | ||
|
||
for n in unneeded: | ||
del font['glyf'][n] | ||
|
||
if __name__ == '__main__': | ||
|
||
with open("src/NotoSans-SemiCondensedMedium.otd", 'rb') as latinFile: | ||
latinFont = json.loads(latinFile.read().decode('UTF-8', errors='replace')) | ||
|
||
# quotes, em-dash and ellipsis | ||
for u in [0x2014, 0x2018, 0x2019, 0x201C, 0x201D, 0x2026]: | ||
if str(u) in latinFont['cmap']: | ||
del latinFont['cmap'][str(u)] | ||
|
||
with open("src/DroidSansFallbackFull.otd", 'rb') as asianFile: | ||
baseFont = json.loads(asianFile.read().decode('UTF-8', errors='replace')) | ||
|
||
with open("src/DroidSansFallbackLegacy.otd", 'rb') as latinExtFile: | ||
latinExtFont = json.loads(latinExtFile.read().decode('UTF-8', errors='replace')) | ||
|
||
baseFont['OS_2']['ulCodePageRange1'] = { "gbk": True } | ||
baseFont['OS_2']['ulCodePageRange2'] = {} | ||
NameFont(baseFont, "Compressed", "Regular", "0.4.0") | ||
|
||
for (u, n) in latinExtFont['cmap'].items(): | ||
if int(u) < 0x3000 and u not in baseFont['cmap']: | ||
baseFont['cmap'][u] = latinExtFont['cmap'][u] | ||
if n not in baseFont['glyf']: | ||
baseFont['glyf'][n] = latinExtFont['glyf'][n] | ||
CopyRef(baseFont['glyf'][n], baseFont, latinExtFont) | ||
|
||
for u in latinFont['cmap']: | ||
if u in baseFont['cmap']: | ||
del baseFont['cmap'][u] | ||
|
||
del baseFont['vhea'] | ||
del baseFont['GSUB'] | ||
del baseFont['GDEF'] | ||
TrimGlyph(baseFont) | ||
|
||
asianOutStr = json.dumps(baseFont, ensure_ascii=False) | ||
with open("out/Nowar-Sans-CJK-XS-Regular.otd", 'w') as asianOutFile: | ||
asianOutFile.write(asianOutStr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import json | ||
import sys | ||
|
||
def NameFont(font, weight, version): | ||
|
||
isStdStyle = weight == 'Regular' or weight == 'Bold' | ||
|
||
font['OS_2']['achVendID'] = 'Cyan' | ||
font['name'] = [ | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 0, | ||
"nameString": "Copyright © 2018—2019 Cyano Hao, with reserved font name “Nowar”, “有爱”, and “有愛”. Portions Copyright 2015 Google Inc." | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 1, | ||
"nameString": "Nowar Sans (Latin, Кириллица and Ελληνικό)" if isStdStyle else "Nowar Sans (Latin, Кириллица and Ελληνικό) " + weight | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 2, | ||
"nameString": weight if isStdStyle else "Regular" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 3, | ||
"nameString": "Nowar Sans (Latin, Кириллица and Ελληνικό) " + weight + ' ' + str(version) | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 4, | ||
"nameString": "Nowar Sans (Latin, Кириллица and Ελληνικό) " + weight | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 5, | ||
"nameString": str(version) | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 6, | ||
"nameString": "Nowar-Sans-LCG-" + weight.replace(' ', '-') | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 8, | ||
"nameString": "Cyano Hao" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 9, | ||
"nameString": "Monotype Design Team" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 11, | ||
"nameString": "https://github.com/CyanoHao" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 13, | ||
"nameString": "This Font Software is licensed under the SIL Open Font License, Version 1.1. This Font Software is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the SIL Open Font License for the specific language, permissions and limitations governing your use of this Font Software." | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 14, | ||
"nameString": "http://scripts.sil.org/OFL" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 16, | ||
"nameString": "Nowar Sans (Latin, Кириллица and Ελληνικό)" | ||
}, | ||
{ | ||
"platformID": 3, | ||
"encodingID": 1, | ||
"languageID": 1033, | ||
"nameID": 17, | ||
"nameString": weight | ||
}, | ||
] | ||
|
||
def AddRef(n, font, ref): | ||
if n in ref: | ||
return | ||
glyph = font['glyf'][n] | ||
if 'references' in glyph: | ||
for r in glyph['references']: | ||
ref.append(r['glyph']) | ||
AddRef(r['glyph'], font, ref) | ||
|
||
def TrimGlyph(font): | ||
needed = [] | ||
for (_, n) in font['cmap'].items(): | ||
needed.append(n) | ||
ref = [] | ||
for n in needed: | ||
AddRef(n, font, ref) | ||
|
||
unneeded = [] | ||
for n in font['glyf']: | ||
if not (n in needed or n in ref): | ||
unneeded.append(n) | ||
|
||
for n in unneeded: | ||
del font['glyf'][n] | ||
|
||
if __name__ == '__main__': | ||
weight = sys.argv[1] | ||
version = sys.argv[2] | ||
|
||
with open("src/NotoSans-SemiCondensed{}.otd".format(weight), 'rb') as baseFile: | ||
baseFont = json.loads(baseFile.read().decode('UTF-8', errors='replace')) | ||
|
||
NameFont(baseFont, weight, version) | ||
|
||
# quotes, em-dash and ellipsis | ||
for u in [0x2014, 0x2018, 0x2019, 0x201C, 0x201D, 0x2026]: | ||
if str(u) in baseFont['cmap']: | ||
del baseFont['cmap'][str(u)] | ||
|
||
del baseFont['GSUB'] | ||
del baseFont['GPOS'] | ||
del baseFont['GDEF'] | ||
TrimGlyph(baseFont) | ||
|
||
outStr = json.dumps(baseFont, ensure_ascii=False) | ||
with open("out/Nowar-Sans-LCG-{}.otd".format(weight), 'w') as outFile: | ||
outFile.write(outStr) |
Oops, something went wrong.