BoUML都收费了,argoUML半年没更新了,而startUML六年多没更新了,免费的UML工具里就数VP的社区版还不错了。唯一的缺憾就是输出图片有浮水印,虽说咱们也四处宣传VP,但输出的图片实在不方便。VP 9已经将浮水印贴满整个背景,影响导出图片的可读性。
不过,SVG导出功能还在!(这是我唯一还在坚持VP的理由!) 我写了一段脚本,帮助去除VP输出SVG图片中的浮水印,并转成PNG。这个PNG转换的功能依赖于Inkscape,没有的话去SourceForge.net下吧。 注意安装后要把Inkscape的安装路径放在PATH中去。
Inkscape支持命令行,如下:
inkscape -f srcSVGFile -e tgtPNGFile -d 150 (d后面的dpi值,150基本可以适用于放到PPT讲解用了. 其它参数用--help就可以看了)
脚本也简单,就是把SVG文件的某个特定的浮水印字符去除,然后呼叫inkscape转换下就可以了。支持单个文件转换或者一个目录下所有文件转换,还算方便吧。
#!/usr/bin/python # coding: utf-8 #/*! #@brief Description # A simple utility to remove watermark for SVG files exported by VP 9.0 ~ VP 12.x #*/ import os,sys,string,datetime,copy,re srcSVGString = ["Visual Paradigm for UML Enterprise Edition [evaluation copy]", "Visual Paradigm for UML Community Edition [not for commercial use]", "Visual Paradigm for UML Modeler Edition [evaluation copy]"] pathInkSpace = "/Applications/Inkscape.app/Contents/Resources/bin/inkscape" def replaceStringInNewFile(srcFile): file=open(srcFile, "r") if None==file: print "Could not open for %s updating" %srcFile return -1 allLines=file.readlines() file.close() index = 0 for eachLine in allLines: for srcString in srcSVGString: if 0<=string.find(eachLine,srcString): allLines[index] = eachLine.replace(srcString,' ') break index = index+1 file = open(srcFile,"w") file.writelines(allLines) file.close() return 0 def convertSVGToPNG(filename): fileStr, extStr = os.path.splitext(filename) if 0 == replaceStringInNewFile(filename): convertCmd=pathInkSpace+" -f\""+filename+"\" -e \""+fileStr+".png\" -d 150"; return os.system(convertCmd) else: return -1 def convertAllSVNInFolder(srcFolder): if not os.path.isdir( srcFolder ): return -1 paths = os.listdir( srcFolder ) for path in paths: filePath = os.path.join( srcFolder, path ) if filePath[-4:].lower() == ".svg": convertSVGToPNG(filePath) return 0 # Main entry if __name__ =="__main__": print 'Please ensure the Inkscape has been installed,' print ' and put the installed folder in the PATH!' if len(sys.argv) < 2: print '\tUsage: ' print '\t python svgconvert.py sourceSVGFile or' print '\t python svgconvert.py svnFolder' print ' ' elif os.path.isdir(sys.argv[1]): convertAllSVNInFolder(sys.argv[1]) else: convertSVGToPNG(sys.argv[1]) print '\nFinished! Enjoy the conversation result! ' print 'If you have any comment, pls mail to' print '\t horky.chen@gmail.com' print ''
时间: 2024-09-21 03:56:55