Skip to content

Commit

Permalink
check latest git hash and add to version names if needed
Browse files Browse the repository at this point in the history
clarify usage for version name patcher

fix typo
  • Loading branch information
thundernixon committed Jan 22, 2020
1 parent be0ed97 commit 3644302
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
23 changes: 21 additions & 2 deletions misc/googlefonts-qa/fix-move-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ rm ${interFullVF/".ttf"/".ttx"}

set -e

# # -------------------------------------------------------------------
# # fix variable font versions: add git hash if missing ---------------

latestHash=$(git log --author=Rasmus -n 1 --pretty=format:"%h")
python misc/googlefonts-qa/patch-git-hash-version-names.py $interFullVF -g $latestHash -i


# # -------------------------------------------------------------------
# # fix variable font metadata as needed ------------------------------
# # these fixes all address things flagged by fontbakery --------------
Expand Down Expand Up @@ -79,6 +86,18 @@ ttx ${interFullVF/'.ttf'/'.ttx'} # convert back to TTF
rm ${interFullVF/'.ttf'/'.ttx'} # erase temp TTX
mv ${interFullVF/'.ttf'/'#1.ttf'} $interFullVF # overwrite original TTF with edited copy


# add family suffix to static fonts to avoid font menu clashes
# TODO: test on whole folder

statics=$(ls $interDir/build/googlefonts/statics/*.ttf)
for ttf in $statics; do
python misc/googlefonts-qa/patch-static-family-names.py $ttf --inplace
done




# -------------------------------------------------------------------
# navigate to google/fonts repo, get latest, then update inter branch

Expand Down Expand Up @@ -119,15 +138,15 @@ cp $interQADir/gfonts-description.html ofl/inter/DESCRIPTION.en_us.html
# # -------------------------------------------------------------------
# # run checks, saving to inter/misc/googlefonts-qa/checks ------------

pip install -U fontbakery # update
# pip install -U fontbakery # update

set +e # otherwise, the script stops after the first fontbakery check output

cd ofl/inter

# # just to make it easy to see fontbakery checks

fontbakery check-googlefonts Inter*slnt*wght*.ttf --ghmarkdown $interQADir/checks/Inter-Full-VF.checks.md
# fontbakery check-googlefonts Inter*slnt*wght*.ttf --ghmarkdown $interQADir/checks/Inter-Full-VF.checks.md

# -------------------------------------------------------------------
# adds and commits new changes, then force pushes -------------------
Expand Down
79 changes: 79 additions & 0 deletions misc/googlefonts-qa/patch-git-hash-version-names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# coding=utf8

'''
Check whether names 3 & 5 have git hashes. If they don't, this adds one.
USAGE:
latestHash=$(git log --author=Rasmus -n 1 --pretty=format:"%h")
python misc/googlefonts-qa/patch-git-hash-version-names.py build/googlefonts/Inter.var.ttf -g $latestHash
'''


import os
import argparse
from fontTools.ttLib import TTFont

def getFontNameID(font, ID, platformID=3, platEncID=1):
name = str(font['name'].getName(ID, platformID, platEncID))
return name

def setFontNameID(font, ID, newName, platformID=3, platEncID=1, langID=0x409):
print(f"\n\t• name {ID}:")
oldName = font['name'].getName(ID, platformID, platEncID)
print(f"\n\t\t was '{oldName}'")
font['name'].setName(newName, ID, platformID, platEncID, langID)
print(f"\n\t\t now '{newName}'")

parser = argparse.ArgumentParser(description='Add "static" suffix to a static font family name.')

parser.add_argument('fonts', nargs="+")

parser.add_argument(
"-i",
"--inplace",
action='store_true',
help="Edit fonts and save under the same filepath, without an added suffix.",
)

parser.add_argument(
"-g",
"--gitHash",
help="Provide a git hash to add to names 3 & 5.",
)

def main():
args = parser.parse_args()

for font_path in args.fonts:
# open font path as a font object, for manipulation
ttfont = TTFont(font_path)

name3 = getFontNameID(ttfont, 3)
# if last character is ":", add the git hash
if name3[-1:] is ":":
setFontNameID(ttfont, 3, name3 + args.gitHash)
else:
print(f"name 3 looks fine: {name3}")

name5 = getFontNameID(ttfont, 5)

# if last character is "-", add the git hash
if name5[-1:] is "-":
setFontNameID(ttfont, 5, name5 + args.gitHash)
else:
print(f"name 5 looks fine: {name5}")

# SAVE FONT
if name3[-1:] is ":" or name5[-1:] is "-":
if args.inplace:
print(f"Saving {font_path}")
ttfont.save(font_path)
else:
print(f"Saving {font_path}.fix")
ttfont.save(font_path + '.fix')


if __name__ == '__main__':
main()

0 comments on commit 3644302

Please sign in to comment.