如何使用文本列表生成svg文件



我在inkscape中制作了一个svg。这是一个平假名文本。有没有一种方法可以从平假名文本列表中批量导出svg文件?那可以是46个平假名svg文件。

id="tspan849">あ</tspan></text>

我已经编写了一个py脚本来完成任务希望这个py脚本能帮助到需要它的人。

#Check if the output folder is missing,it will create a new one, if output folder is not found.
import os
path = 'output'
if not os.path.isdir(path):
os.mkdir(path)
#Create a List.
ListFileName='HiraganaList.txt'
with open(ListFileName, mode="r", encoding="utf-8") as f:
#Read the contents of the file into a list.
lines=f.readlines()   
#Read the sample file.
SampleFileName='Hiragana_01.svg'
with open(SampleFileName, mode="r", encoding="utf-8") as s:
#Read the sample file contents into a list.
sLines=s.readlines()
#Output directory and named variables.
OutFileFolder='Output'
OutPixFileName='Hiragana_'
#Specifies the string to find.
sTokenString='あ'
iNum=1
#Cycle through List from first line to end line.
for line in lines:
#Declares an output list.
OutputContext=[]
#Numbering
sNum='0' + str(iNum)
#Output file name + path
OutFileName=OutFileFolder + '\'+OutPixFileName+sNum[-2:]+'.svg'
#Save a new file.
with open(OutFileName, mode="w", encoding="utf-8") as w:
#Cycle through sample contents
for sLine in sLines:    
#Determine whether it is consistent with sTokenString
if sLine.find(sTokenString)>0:
print('old->'+sLine)
#Replaced by a new string
sNew=sLine.replace(sTokenString,line.replace('n',''))
print('New->'+sNew)
#write in to list
OutputContext.append(sNew)          
else:
OutputContext.append(sLine)
print(line)
w.writelines(OutputContext)
iNum+=1

最新更新