Last active
May 27, 2020 14:31
-
-
Save jansindl3r/fda2020bdfdbdaaec5addd6e257ed140 to your computer and use it in GitHub Desktop.
make sheet of current of a font in RoboFont
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
# this is a script that creates a .pdf of current font with given letters | |
# custom settings file can be provided in folder where the output goes to | |
import drawBot as db | |
from pathlib import Path | |
import json | |
from datetime import datetime | |
db.newDrawing() | |
db.size('A4Landscape') | |
f = CurrentFont() | |
uniMap = {k:v[0] for k,v in f.getCharacterMapping().items()} | |
path = Path(f.path) | |
#print(dir(f.info)) | |
logs = path.parent/f'logs_{path.stem}' | |
if not logs.exists(): | |
logs.mkdir() | |
if 'settings.json' in logs.glob('.json'): | |
with open(logs/'settings.json') as inputFile: | |
settings = json.load(inputFile) | |
else: | |
settings = { | |
'rows': [ | |
'ABCDEFGHIJKLM', | |
'NOPQRSTUVWXYZ', | |
'abcdefghijklm', | |
'nopqrstuvwxyz', | |
'0123456789'], | |
'fontSize': 20, | |
'lineHeight': 1.2 | |
} | |
scaleRatio = 0.06# settings['fontSize'] | |
db.translate(10, db.height()) | |
bezier = db.BezierPath() | |
for row in settings['rows']: | |
rowWidth = 0 | |
for character in row: | |
glyphName = uniMap.get(ord(character)) | |
if glyphName in f: | |
glyph = f[glyphName] | |
bezier.addGlyph(glyph) | |
bezier.translate(-glyph.width, 0) | |
rowWidth += glyph.width | |
bezier.translate(rowWidth, -f.info.unitsPerEm*settings['lineHeight']) | |
db.scale(scaleRatio, scaleRatio) | |
db.drawPath(bezier) | |
now = datetime.now() | |
time = now.strftime("%Y_%m_%d_%H-%M-%S") | |
imagePath = str((logs/f'{time}.pdf').absolute()) | |
db.endDrawing() | |
db.saveImage(imagePath) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment