有时侯定义字体是使用base64来做的,所以需要转换处理并将字体文件下载下来
from base64 import decodestring
b64_file = open("fontbase64.txt", "r") # change the file if you want
b64_data = b64_file.read()
mime = ""
font_type = "N/A"
if b64_data.find(":") > -1: # it found a mime type
mime = b64_data[b64_data.find(":")+1:b64_data.find(";")]
if mime is not "": # get the actual data if a mime type was found
b64_data = b64_data[b64_data.find(",")]
# detect font type
if mime == "application/x-font-otf":
font_type = "OTF"
elif mime == "application/x-font-ttf":
font_type = "TTF"
elif mime == "application/x-font-woff":
font_type = "WOFF"
print "Font is " + font_type
with open("fontbinary.bin", "wb") as fb: # change the file if you want
fb.write(b64_data.decode("base64"))
print "Done!"