我正在尝试在 Ubuntu VM 上安装 Tornado 服务器,其任务是从 .svg 文件开始生成完整的字体包。我在没有服务器的情况下运行了以下脚本,效果很好。 https://gist.github.com/jorgegarciadev/6127832
现在我尝试在我的服务器上执行此任务,Fontforge 似乎对 .svg 文件有问题。一开始我以为是块问题,好像我的文件没有被完全读取或发送,但是当我在服务器上打开最近上传的文件时,它是完整的并且与原始文件具有相同的大小。更令人不安的是,Fontforge 告诉我这个文件不是字体文件。这就是让我想到块的东西(因为它似乎是解析错误)
pastebin 上的 SVG 文件就在那里: http: //pastebin.com/ai5pr1DG
python服务器代码:
import tornado, tornado.ioloop, tornado.web
import os, uuid
import fontforge, re, zipfile
__UPLOADS__ = "uploads/"
EXTS = [".woff", ".ttf", ".otf", ".svg", ".eot"]
class Userform(tornado.web.RequestHandler):
def get(self):
self.render("fileuploadform.html")
class Upload(tornado.web.RequestHandler):
@staticmethod
def cssGenerator(name, fullname):
cssFile = name + ".css"
template = "@font-face {\
\n\tfont-family: '" + fullname + "';\
\n\tsrc: url('" + name + ".eot');\
\n\tsrc: url('" + name + ".eot?#iefix') format('embedded-opentype'),\
\n\turl('" + name + ".woff') format('woff'),\
\n\turl('" + name + ".ttf') format('truetype'),\
\n\turl('" + name + ".svg#ywftsvg') format('svg');\
\n\tfont-style: normal;\
\n\tfont-weight: normal;\
\n}\n\n"
open(cssFile, 'w+').writelines(template)
@staticmethod
def fontGenerator(filename):
#exts = ["woff", "ttf", "otf", "svg", "eot"]
name = os.path.splitext(filename)[0]
'''if not os.path.exists(name):
os.makedirs(name)'''
font = fontforge.open(filename)
fullname = font.fullname
for ext in EXTS:
f = name + ext
font.generate(f)
def post(self):
fileinfo = self.request.files['filearg'][0]
fname = fileinfo['filename']
extn = os.path.splitext(fname)[1]
cname = str(uuid.uuid4()) + extn
zname = os.path.splitext(fname)[0]
fh = open(cname, 'w+')
fh.write(fileinfo['body'])
os.system("mv " + cname + " " + zname + extn)
#zname is default, extn is .svg, fname is default.svg, cname is file name in the server
self.cssGenerator(zname, 'testfont')
self.fontGenerator(zname + extn)
application = tornado.web.Application([
(r"/", Userform),
(r"/upload", Upload),
], debug=True)
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
启动服务器并单击客户端上的“上传”按钮后的输出:
strippedname:/home/bill/proto.svg
/home/bill/proto.svg:109: parser error : AttValue: ' expected
-18 403 -18 L 403 -18 C 352 -18 301 0 251 0 C 225 0 210 15 210 41 C 210 63 225 7
^
/home/bill/proto.svg:109: parser error : attributes construct error
-18 403 -18 L 403 -18 C 352 -18 301 0 251 0 C 225 0 210 15 210 41 C 210 63 225 7
^
/home/bill/proto.svg:109: parser error : Couldn't find end of Start Tag glyph line 109
-18 403 -18 L 403 -18 C 352 -18 301 0 251 0 C 225 0 210 15 210 41 C 210 63 225 7
^
/home/bill/proto.svg:109: parser error : Premature end of data in tag font line 6
-18 403 -18 L 403 -18 C 352 -18 301 0 251 0 C 225 0 210 15 210 41 C 210 63 225 7
^
/home/bill/proto.svg:109: parser error : Premature end of data in tag defs line 5
-18 403 -18 L 403 -18 C 352 -18 301 0 251 0 C 225 0 210 15 210 41 C 210 63 225 7
^
/home/bill/proto.svg:109: parser error : Premature end of data in tag svg line 3
-18 403 -18 L 403 -18 C 352 -18 301 0 251 0 C 225 0 210 15 210 41 C 210 63 225 7
^
Couldn't find a font file named /home/bill/proto.svg
proto.svg is not in a known format (or uses features of that format fontforge does not support, or is so badly corrupted as to be unreadable)
ERROR:tornado.application:Uncaught exception POST /upload (82.225.61.131)
HTTPServerRequest(protocol='http', host='py-fontconv.cloudapp.net', method='POST', uri='/upload', version='HTTP/1.1', remote_ip='82.225.61.131', headers={'Content-Length': '32378', 'Accept-Language': 'en-us,en;q=0.8,fr;q=0.5,fr-fr;q=0.3', 'Accept-Encoding': 'gzip, deflate', 'Host': 'py-fontconv.cloudapp.net', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:28.0) Gecko/20100101 Firefox/28.0', 'Connection': 'keep-alive', 'Content-Type': 'multipart/form-data; boundary=---------------------------191335620930032341323215978'})
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1332, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "tornadofileupload.py", line 53, in post
self.fontGenerator(zname + extn)
File "tornadofileupload.py", line 35, in fontGenerator
font = fontforge.open(filename)
EnvironmentError: Open failed
ERROR:tornado.access:500 POST /upload (82.225.61.131) 283.75ms
如果有人发现这里缺少什么,那将是一种解脱,因为我真的在这方面苦苦挣扎。