Created
May 22, 2019 11:55
-
-
Save LettError/d0d2688abe959595a88b3fdb85c18db3 to your computer and use it in GitHub Desktop.
Export Robofont glyph image to iCloud, then reimport it again. After editing it on an ipad for instance.
This file contains hidden or 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
import drawBot as ctx | |
import os | |
from os.path import expanduser | |
home = expanduser("~") | |
imagesDir = "Library/Mobile Documents/com~apple~CloudDocs/RoboFont/" | |
path = os.path.join(home, imagesDir) | |
if not os.path.exists(path): | |
os.makedirs(path) | |
if not os.path.exists(path): | |
print('Could not make RoboFont iCloud images folder at', path ) | |
padding = 100 | |
f = CurrentFont() | |
if f is not None: | |
ufoName = os.path.basename(f.path) | |
ufoName = ufoName.replace(".ufo", "_images") | |
#print(ufoName) | |
ufoImagesPath = os.path.join(path, ufoName) | |
print("exporting to", ufoImagesPath) | |
if not os.path.exists(ufoImagesPath): | |
os.makedirs(ufoImagesPath) | |
g = CurrentGlyph() | |
if g is not None: | |
ctx.newPage(int(g.width) + 2*padding, int(f.info.unitsPerEm) + 2*padding) | |
ctx.translate(padding,-f.info.descender + padding) | |
ctx.stroke(0.5) | |
ctx.strokeWidth(1) | |
ctx.line((0,0), (g.width, 0)) | |
ctx.fill(0) | |
ctx.drawGlyph(g) | |
imageName = os.path.join(ufoImagesPath, "%s.png" % g.name) | |
ctx.saveImage(imageName) | |
ctx.newDrawing() | |
else: | |
print("no open font") |
This file contains hidden or 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
import os | |
from mojo.UI import GetFile | |
import drawBot as ctx | |
from os.path import expanduser | |
home = expanduser("~") | |
#print(home) | |
padding = 100 | |
imagesDir = "Library/Mobile Documents/com~apple~CloudDocs/RoboFont/" | |
path = os.path.join(home, imagesDir) | |
if not os.path.exists(path): | |
print("no icloud images folder found", path) | |
else: | |
f = CurrentFont() | |
if f is not None: | |
ufoName = os.path.basename(f.path) | |
ufoName = ufoName.replace(".ufo", "_images") | |
#print(ufoName) | |
ufoImagesPath = os.path.join(path, ufoName) | |
#print(ufoImagesPath, os.path.exists(ufoImagesPath)) | |
g = CurrentGlyph() | |
imageName = os.path.join(ufoImagesPath, "%s.png" % g.name) | |
#print(imageName, os.path.exists(imageName)) | |
w, h = ctx.imageSize(imageName) | |
scale = f.info.unitsPerEm / (h - 2*padding) | |
#print(scale) | |
g.addImage(imageName, scale=scale, position=(-padding, f.info.descender - padding)) | |
g.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment