-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateFnt.py
58 lines (49 loc) · 1.51 KB
/
generateFnt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
import os
import sys
import codecs
#import chardet
import shutil
import json
import subprocess
import lib.syscmd
def getUnicode(Line):
local = os.getcwd()
originUTF = open("string.txt","rb")
configFile = open('config/config.bmfc', 'a')
str = originUTF.read()
#print chardet.detect(str)
str=str.decode('utf-16')
index = 0
for j in str:
lineToWrite = Line[index] +"," + unicode(ord(j)) +",0,0,0"
configFile.write(lineToWrite + '\n')
index += 1
originUTF.close()
configFile.close()
def getFilePathAndWirteTofile(picPath):
os.chdir(os.getcwd()+"/config/")
fileNameOfconfig = "config.bmfc"
shutil.copyfile("configModel.bmfc", fileNameOfconfig)
L = []
originUTF = open(fileNameOfconfig,"rb")
for root, dirs, files in os.walk(path):
for file in files:
L.append("icon=\"" + root+"/"+file + '\"')
local = os.getcwd()
os.chdir(os.getcwd()+"/..")
getUnicode(L)
def callBmFont():
file=open(os.getcwd()+"/config/config.json",'r')
jObj= file.read()
jObj=jObj.decode("utf-8-sig")
pythonObj=json.loads(jObj)
exePath = os.getcwd() +"/BMFont/bmfont.exe"
outPutName = pythonObj["PublishName"]
stringName = os.getcwd() + "/" + pythonObj["stringName"]
configName = os.getcwd() + "/config/" + pythonObj["configName"]
strs = exePath + " -t " + stringName + " -c " + configName + " -o " +outPutName
lib.syscmd.exec_cmd(strs)
path = os.getcwd()+ "/pic"
getFilePathAndWirteTofile(path)
callBmFont()