Created
March 3, 2012 15:54
-
-
Save baoilleach/1966793 to your computer and use it in GitHub Desktop.
Modify the SVG output of Open Babel to potentially improve performance (it doesn't really in the end)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputfile = open("mols_1000.svg", "r") | |
outputfile = open("tmp.svg", "w") | |
t = "" | |
DEFAULT, LINE = range(0, 2) | |
state = DEFAULT | |
for line in inputfile: | |
t = line | |
if line.startswith("<line x1"): | |
if state == DEFAULT: | |
outputfile.write('<g stroke="rgb(0,0,0)" stroke-width="2.0">\n') | |
state = LINE | |
broken = line.split() | |
t = " ".join(broken[:5]) + "/>\n" | |
else: | |
if state == LINE: | |
outputfile.write("</g>\n") | |
state = DEFAULT | |
if line.startswith("font-family"): | |
broken = line.split() | |
t = " ".join(broken[:1] + ['font-weight="bold"'] + broken[3:]) + "\n" | |
if line.startswith("<text"): | |
broken = line.split() | |
if broken[1].startswith("x="): | |
t = " ".join(broken[0:4] + broken[6:]) + "\n" | |
outputfile.write(t) | |
oldt = t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment