Skip to content

Instantly share code, notes, and snippets.

@karlding
Last active July 19, 2019 09:56
Show Gist options
  • Save karlding/c885b91051bd346d93ee to your computer and use it in GitHub Desktop.
Save karlding/c885b91051bd346d93ee to your computer and use it in GitHub Desktop.
Parse TTX dumps and grab ligatures substitution rules found in GSUB tables (using Sans Bullshit Sans as an example)
import xml.dom.minidom
import sys
data = "".join(sys.stdin)
dom = xml.dom.minidom.parseString(data)
ligature_sets = dom.getElementsByTagName('LigatureSet')
char_map = dom.getElementsByTagName('cmap')[0].getElementsByTagName('cmap_format_4')[0].getElementsByTagName('map')
for ligature_set in ligature_sets:
ligatures = ligature_set.getElementsByTagName('Ligature')
start_letter = ligature_set.getAttribute('glyph')
for word in ligatures:
output = start_letter + ',' + word.getAttribute('components')
for char in output.split(','):
for node in char_map:
hex_val = node.getAttribute('code').replace('0x', '')
if node.getAttribute('name') == char:
sys.stdout.write(hex_val.decode('hex'))
break
print

Parsing TTX dumps

After seeing Roel Nieskens's Sans Bullshit Sans font, I wanted to grab a list of all the words or phrases that were included in the GSUB table for something I was working on (relating to JobMine and buzzword metrics). Sans Bullshit Sans uses the GSUB table to tell the font which letter combinations rules to replace with their custom ligatures.

None of the tools I found after a quick search seemed to allow me to dump all the strings that the GSUB table defined for replacements, so I wrote this simple Python script to traverse the TTX output (which is simply a valid XML file, at least according to xmllint) and print out the ligature substitutions that the font uses. It grabs each LigatureSet (which corresponds to the first character), and then the remaining characters are in the children Ligature tags.

The script takes input from stdin, and output is sent to stdout.

python bs-sans.py < SansBullshitSans.ttx > words.txt
DRM
DNA
IoT
MVP
SEM
SEO
ROI
agile
analytics
alignment
algorithm
aggregator
accelerate
actionable
action items
accountability
at sca
as a service
at the end of the day
cloud
curate
codify
crowdfund
collateral
credibility
coopetition
crowdsource
convergence
create value
change agent
clickthrough
come to Jesus
collaboration
close the loop
cross the chasm
content strategy
cyber
beta
big data
blueprint
bandwidth
brogrammer
bottom line
bounce rate
bleeding edge
best of breed
best practices
boil the ocean
below the fold
brand evangelist
bricks and clicks
bring to the party
bring to the table
epic
enable
empathy
engaging
emerging
entitled
eyeballs
engagement
enterprise
evangelist
exit strategy
eat your own dog food
diversity
discovery
deep dive
disruptive
downsizing
data mining
digital divide
design pattern
digital natives
do more with less
drink the Kool Aid
guru
green
gameify
groupthink
growth hack
gamification
game changer
globalization
glamour metrics
flat
flow
fusion
funnel
funded
fanboy
finalize
freemium
fail fast
face time
fail forward
first or best
ignite
iconic
impact
innovate
ideation
immersive
integrated
infographic
impressions
industry 4.0
in the weeds
internet of things
html5
homerun
holistic
headlights
heads down
high level
hyperlocal
herding cats
knee deep
jellyfish
maker
mashup
monetize
modernity
moonshot
mindshare
milestone
make it pop
moving forward
marketing funnel
make the logo bigger
lean
lean in
leverage
level up
long tail
lizard brain
low hanging fruit
organic
optimize
offshoring
opportunity
outsourcing
over the top
out of pocket
on the runway
operationalize
open the kimono
outside the box
ninja
next gen
next level
netiquette
nextify
qualified leads
pop
p2p
ping
pivot
portal
pipeline
proactive
productize
public facing
paradigm shift
proof of concept
pull the trigger
push the envelope
peeling the onion
patent pending design
personal brand
sexy
storify
scrum
shift
sizzle
sticky
startup
standup
synergy
strategy
solution
seamless
slam dunk
strategery
sea change
soft launch
stakeholder
scalability
synergistic
social proof
social media
stealth mode
storytelling
sustainability
social currency
stealth startup
sweat your assets
social media expert
scratch your own itch
rich
rockstar
reach out
real time
responsive
rightsizing
reimagining
rightshoring
revolutionize
reinvent the wheel
uber
user
unpack
unicorn
uniques
usercentric
tee off
tollgate
the cloud
tiger team
touch base
top of mind
touchpoints
transparent
trickthrough
team building
transgenerate
thought leader
take it offline
the easiest way to
wizard
webinar
web scale
what is our solve
viral
vision
visibility
value proposition
@DonaldTsang
Copy link

Can you also make a script that actually add ligatures into a "clean font"? Would like something fun like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment