Skip to content

Commit

Permalink
Correct PS private values & new auto-hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
sungsit committed Dec 1, 2015
1 parent 41ab104 commit 4fa0ea3
Show file tree
Hide file tree
Showing 25 changed files with 201 additions and 69,877 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ components/*

*backup/*
*.sfd-*
*/unhinted/*
fonts/unhinted/*
fonts/eot/*
fonts/svg/*
*-temp*
*-backup*
*.bak
Expand Down
2 changes: 1 addition & 1 deletion features.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<header>
<h1 class="title">BoonBaan</h1>
<h2 class="subtitle">ฟอนต์บุญบ้าน</h2>
<h3 class="date">2015/10/30</h3>
<h3 class="date">2015/12/01</h3>
</header>

<div class="print-hide" style="margin-top:60px;">
Expand Down
Binary file modified fonts/otf/BoonBaan-400.otf
Binary file not shown.
Binary file modified fonts/otf/BoonBaan-400i.otf
Binary file not shown.
Binary file modified fonts/otf/BoonBaan-700.otf
Binary file not shown.
Binary file modified fonts/otf/BoonBaan-700i.otf
Binary file not shown.
Binary file modified fonts/ttf/BoonBaan-400.ttf
Binary file not shown.
Binary file modified fonts/ttf/BoonBaan-400i.ttf
Binary file not shown.
Binary file modified fonts/ttf/BoonBaan-700.ttf
Binary file not shown.
Binary file modified fonts/ttf/BoonBaan-700i.ttf
Binary file not shown.
Binary file modified fonts/woff/BoonBaan-400.woff
Binary file not shown.
Binary file modified fonts/woff/BoonBaan-400i.woff
Binary file not shown.
Binary file modified fonts/woff/BoonBaan-700.woff
Binary file not shown.
Binary file modified fonts/woff/BoonBaan-700i.woff
Binary file not shown.
Binary file modified fonts/woff2/BoonBaan-400.woff2
Binary file not shown.
Binary file modified fonts/woff2/BoonBaan-400i.woff2
Binary file not shown.
Binary file modified fonts/woff2/BoonBaan-700.woff2
Binary file not shown.
Binary file modified fonts/woff2/BoonBaan-700i.woff2
Binary file not shown.
File renamed without changes.
279 changes: 188 additions & 91 deletions scripts/build-master.py → scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
import shutil
import time
import datetime
import glob

# Predifined vars
foundry = 'FontUni'
family = 'BoonBaan'
version = '1.0'
version = '1.0.1'
sources = ['sources/boonbaan-master.sfd', 'sources/boonbaan-master-oblique.sfd']
layers = ['400', '700']
licensetxt = 'OFT.txt'
Expand All @@ -38,7 +39,25 @@
if not os.path.exists(unhinted_dir):
os.makedirs(unhinted_dir)

exts = ['otf', 'ttf', 'woff', 'woff2']
def fontPath(ext,name):
path = build_dir + ext
if not os.path.exists(path):
os.makedirs(path)
fontfile = path + '/' + name + '.' + ext
return fontfile

def printFontInfo(fontfile):
font = fontforge.open(fontfile)
print('\nFont File: ' + fontfile)
print('Family Name: ' + font.familyname)
print('Font Name: ' + font.fontname)
print('Full Name: ' + font.fullname)
print('Font Weight: ' + font.weight)
print('OS2 Weight: ' + str(font.os2_weight))
print('Oblique Angle: ' + str(font.italicangle))
print('Font Version: ' + font.version)
print('Font Copyright: ' + font.copyright)
font.close()

def weights2Strings(weight):
switcher = {
Expand Down Expand Up @@ -83,81 +102,72 @@ def msStyleName(weight):
}
return switcher.get(weight, "Regular")

def printFontInfo(fontfile):
font = fontforge.open(fontfile)
print('\nFont File: ' + fontfile)
print('Family Name: ' + font.familyname)
print('Font Name: ' + font.fontname)
print('Full Name: ' + font.fullname)
print('Font Weight: ' + font.weight)
print('OS2 Weight: ' + str(font.os2_weight))
print('Italic Angle: ' + str(font.italicangle))
print('Font Version: ' + font.version)
print('Font Copyright: ' + font.copyright)
font.close()

def ttfHint(unhinted,hinted):
subprocess.call([
'ttfautohint',
'--default-script=thai',
'--fallback-script=latn',
'--strong-stem-width=G',
'--hinting-range-min=7',
'--hinting-range-max=28',
'--hinting-limit=50',
'--increase-x-height=13',
'--no-info',
'--verbose',
unhinted,
hinted
])
def BlueValues(weight):
switcher = {
400: (-20, 0, 600, 620, 780, 800, 840, 840),
700: (-20, 0, 600, 620, 780, 800, 840, 840)
}
return switcher.get(weight)

# Optimize
def fontOptimize(fontfile):
subprocess.call([
'pyftsubset',
fontfile,
'--glyphs=*',
'--layout-features=*',
'--name-IDs=*',
'--hinting',
'--legacy-kern',
'--notdef-outline',
'--no-subset-tables+=DSIG',
'--drop-tables-=DSIG',
'--output-file=' + fontfile
])
def OtherBlues(weight):
switcher = {
400: (-260, -240),
700: (-260, -240)
}
return switcher.get(weight)

def ttf2Woff(ttf,woff,genflags):
font = fontforge.open(ttf)
font.generate(woff, flags=genflags)
font.close()
def StdHW(weight):
switcher = {
400: (80,),
700: (120,)
}
return switcher.get(weight)

def fontPath(ext,name):
path = build_dir + ext
if not os.path.exists(path):
os.makedirs(path)
fontfile = path + '/' + name + '.' + ext
return fontfile
def StdVW(weight):
switcher = {
400: (95,),
700: (160,)
}
return switcher.get(weight)

def otf2Sfd(otf,sfd_dir):

font = fontforge.open(otf)
sfd = sfd_dir + font.fontname + '.sfd'
if not os.path.exists(sfd_dir):
os.makedirs(sfd_dir)

font.appendSFNTName('English (US)', 'UniqueID', '')

weight = font.os2_weight
font.private['BlueValues'] = BlueValues(weight)
font.private['OtherBlues'] = OtherBlues(weight)
font.private['StdHW'] = StdHW(weight)
font.private['StdVW'] = StdHW(weight)
font.selection.all()
font.autoHint()
font.save(sfd)
#font.private.guess('StdHW')
#font.private.guess('StdVW')
font.private.guess('StemSnapH')
font.private.guess('StemSnapV')
font.private.guess('BlueShift')
font.selection.all()
font.autoHint()
font.save(sfd)
print(font.fontname, 'SFD files saved.')

print(sfd, 'file saved.')
font.close()

def buildFont(source,family):
def buildSFD(source,family):

# prepare master
font = fontforge.open(source)
font.familyname = family
font.appendSFNTName('English (US)', 'Preferred Family', family)
font.version = version
font.copyright = copyright
font.appendSFNTName('English (US)', 'Manufacturer', foundry)
font.save()

if source.endswith('oblique.sfd'):
Expand All @@ -166,7 +176,6 @@ def buildFont(source,family):
font.mergeFeature(feature_dir + features[0] + '.fea')

# loop through each layer & save it as sfd files
# then generate ttf, autohint & make woff + woff2
for layer in layers:

layername = font.layers[layer].name
Expand Down Expand Up @@ -198,51 +207,138 @@ def buildFont(source,family):
font.appendSFNTName('English (US)', 'SubFamily', 'Regular')
font.appendSFNTName('English (US)', 'Preferred Styles', subfamily)

# UniqueID with timestamp
ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
uniqueid = foundry + ' : ' + font.fullname + ' ' + version + ' : ' + ts
font.appendSFNTName('English (US)', 'UniqueID', uniqueid)


otf = fontPath('otf',font.fontname)
ttf = fontPath('ttf',font.fontname)
woff = fontPath('woff',font.fontname)
woff2 = fontPath('woff2',font.fontname)
tempwoff2 = build_dir + 'ttf/' + font.fontname + '.woff2'

# generate otf
otf = fontPath('otf',font.fontname)
otfgenflags = ('opentype', 'PfEd-lookups')
font.generate(otf, flags=otfgenflags, layer = layername)
print(font.fullname, 'OTF instance generated.')
print(otf, 'instance generated.')

# save sfd
otf2Sfd(otf,sfd_dir)

# generate unhinted ttf
ttfgenflags = ('opentype', 'no-hints')
ttfunhinted = unhinted_dir + font.fontname + '-unhinted.ttf'
font.generate(ttfunhinted, flags=ttfgenflags, layer = layername)
print(font.fullname, 'Unhinted TTF instance generated.')
font.close()

# ttfautohint
ttfHint(ttfunhinted,ttf)
fontOptimize(ttf)
printFontInfo(ttf)
print(font.fullname, 'TTF autohinted.')
for source in sources:
buildSFD(source,family)

# Generate & hint SFD files

# hinted ttf to woff
ttf2Woff(ttf,woff,ttfgenflags)
print(font.fullname, 'WOFF instance generated.')
exts = ['otf', 'ttf', 'woff', 'woff2', 'eot', 'svg']

def otfHint(unhinted,hinted):
subprocess.call([
'autohint',
'-q',
'-o',
hinted,
unhinted
])
print(hinted, 'autohinted.')

def ttfHint(unhinted,hinted):
subprocess.call([
'ttfautohint',
'--default-script=latn',
'--fallback-script=thai',
'--strong-stem-width=G',
'--hinting-range-min=7',
'--hinting-range-max=28',
'--hinting-limit=50',
'--increase-x-height=13',
'--no-info',
'--verbose',
unhinted,
hinted
])
print(hinted, 'autohinted.')

# hinted ttf to woff2
subprocess.call(['woff2_compress',ttf])
os.rename(tempwoff2, woff2)
print(font.fullname, 'WOFF2 instance generated.')
# Optimize
def fontOptimize(fontfile):
subprocess.call([
'pyftsubset',
fontfile,
'--glyphs=*',
'--layout-features=*',
'--name-IDs=*',
'--hinting',
'--legacy-kern',
'--notdef-outline',
'--no-subset-tables+=DSIG',
'--drop-tables-=DSIG',
'--output-file=' + fontfile
])
print(fontfile, 'optimized.')

# http://wizard.ae.krakow.pl/~jb/ttf2woff/
def ttf2Woff(ttf,woff):
subprocess.call([ 'ttf2woff', '-v', ttf, woff ])
print(woff, 'instance generated.')

def ttf2Woff2(ttf,woff2):
subprocess.call(['woff2_compress',ttf])
(root, ext) = os.path.splitext(ttf)
os.rename(root + '.woff2', woff2)
print(woff2, 'instance generated.')

def ttf2Eot(ttf,eot):
subprocess.call(['ttf2eot',ttf,eot])
print(eot, 'instance generated.')

def buildFont(sfd):
font = fontforge.open(sfd)

# UniqueID with timestamp
ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
uniqueid = foundry + ' : ' + font.fullname + ' ' + font.version + ' : ' + ts
font.appendSFNTName('English (US)', 'UniqueID', uniqueid)

otf = fontPath('otf',font.fontname)
ttf = fontPath('ttf',font.fontname)
woff = fontPath('woff',font.fontname)
woff2 = fontPath('woff2',font.fontname)
eot = fontPath('eot',font.fontname)
svg = fontPath('svg',font.fontname)
tempwoff2 = build_dir + 'ttf/' + font.fontname + '.woff2'

# generate otf
otfgenflags = ('opentype', 'PfEd-lookups')
otfunhinted = unhinted_dir + font.fontname + '-unhinted.otf'
font.generate(otfunhinted, flags=otfgenflags)
print(otfunhinted, 'instance generated.')

# AFDKO autohint
otfHint(otfunhinted,otf)
fontOptimize(otf)
printFontInfo(otf)

# generate unhinted ttf
ttfgenflags = ('opentype', 'no-hints')
ttfunhinted = unhinted_dir + font.fontname + '-unhinted.ttf'
font.generate(ttfunhinted, flags=ttfgenflags)
print(ttfunhinted, 'instance generated.')

# ttfautohint
ttfHint(ttfunhinted,ttf)
fontOptimize(ttf)
printFontInfo(ttf)

# ttf2woff
ttf2Woff(ttf,woff)

# ttf2woff2
ttf2Woff2(ttf,woff2)

# ttf2eot
ttf2Eot(ttf,eot)

# gen svg
font.generate(svg, flags=otfgenflags)
print(svg, 'instance generated.')

font.close()

for source in sources:
buildFont(source,family)
for sfd in sorted(glob.glob('./sfd/*.sfd')):
buildFont(sfd)

# Create zip package for each font extension
def fontZip(family,version,ext):
Expand All @@ -255,6 +351,7 @@ def fontZip(family,version,ext):
os.chdir('..')
print(package, 'created.')

exts = ['otf', 'ttf', 'woff', 'woff2', 'eot', 'svg']

for ext in exts:
fontZip(family,version,ext)

Loading

0 comments on commit 4fa0ea3

Please sign in to comment.