34 #ifndef _RD_DRAWING_TO_SVG_H_ 35 #define _RD_DRAWING_TO_SVG_H_ 42 std::string getColor(
int atNum){
43 std::string res=
"#000000";
45 case 7: res=
"#0000FF";
break;
46 case 8: res=
"#FF0000";
break;
47 case 9: res=
"#33CCCC";
break;
48 case 15: res=
"#FF7F00";
break;
49 case 16: res=
"#CCCC00";
break;
50 case 17: res=
"#00CC00";
break;
51 case 35: res=
"#7F4C19";
break;
52 case 0: res=
"#7F7F7F";
break;
53 default: res=
"#000000";
57 void drawLine(std::vector<int>::const_iterator &pos,std::ostringstream &sstr,
58 unsigned int lineWidthMult){
63 std::string dashString=
"";
68 dashString=
";stroke-dasharray:2, 6";
71 dashString=
";stroke-dasharray:6, 6";
75 std::string c1=getColor(an1);
76 std::string c2=getColor(an2);
79 sstr<<
"d='M "<<*pos<<
","<<*(pos+1)<<
" "<<*(pos+2)<<
","<<*(pos+3)<<
"' ";
81 sstr<<
"style='fill:none;fill-rule:evenodd;stroke:"<<c1<<
";stroke-width:"<<width<<
"px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"<<dashString<<
"'";
88 int mx = xp1+(xp2-xp1)/2;
89 int my = yp1+(yp2-yp1)/2;
91 sstr<<
"d='M "<<xp1<<
","<<yp1<<
" "<<mx<<
","<<my<<
"' ";
92 sstr<<
"style='fill:none;fill-rule:evenodd;stroke:"<<c1<<
";stroke-width:"<<width<<
"px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"<<dashString<<
"'";
95 sstr<<
"d='M "<<mx<<
","<<my<<
" "<<xp2<<
","<<yp2<<
"' ";
96 sstr<<
"style='fill:none;fill-rule:evenodd;stroke:"<<c2<<
";stroke-width:"<<width<<
"px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"<<dashString<<
"'";
101 void drawAtom(std::vector<int>::const_iterator &pos,std::ostringstream &sstr,
unsigned int fontSz,
102 bool includeAtomCircles=
false){
107 std::string label=
"";
108 for(
unsigned int i=0;i<slen;++i){
113 int width=fontSz*label.length();
115 sstr<<
"<svg:g transform='translate("<<xp<<
","<<yp<<
")'><svg:rect ";
116 sstr<<
"style='opacity:1.0;fill:#FFFFFF;stroke:none'";
117 sstr<<
" width='"<<width<<
"' height='"<<height<<
"'";
118 sstr<<
" x='-"<<width/2<<
"' y='-"<<height/2<<
"'";
119 sstr<<
"> </svg:rect>\n";
121 sstr<<
" style='font-size:"<<fontSz<<
"px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:middle"<<
";fill:"<<getColor(atNum)<<
"'";
122 sstr<<
" y='"<<.75*fontSz/2<<
"'>";
124 sstr<<label<<
"</svg:tspan>";
128 if(includeAtomCircles){
130 sstr<<
"<svg:circle cx='"<<xp<<
"' cy='"<<yp<<
"' r='5' />\n";
132 sstr<<
"<svg:circle cx='"<<xp<<
"' cy='"<<yp<<
"' r='0' style='fill:none;stroke:none' />\n";
139 unsigned int lineWidthMult=2,
unsigned int fontSize=50,
140 bool includeAtomCircles=
false){
141 std::vector<int>::const_iterator pos=drawing.begin()+2;
143 std::cerr<<
"no bounds token found"<<std::endl;
147 unsigned int width,height;
150 std::ostringstream sstr;
151 sstr<<
"<?xml version='1.0' encoding='iso-8859-1'?>\n";
152 sstr <<
"<svg:svg version='1.1' baseProfile='full'\n \ 153 xmlns:svg='http://www.w3.org/2000/svg'\n \ 154 xmlns:xlink='http://www.w3.org/1999/xlink'\n \ 155 xml:space='preserve'\n";
156 sstr<<
"width='"<<width<<
"px' height='"<<height<<
"px' >\n";
158 sstr<<
"style='opacity:1.0;fill:#FFFFFF;stroke:none'";
159 sstr<<
" width='"<<width<<
"' height='"<<height<<
"'";
160 sstr<<
" x='0' y='0'";
161 sstr<<
"> </svg:rect>\n";
162 sstr<<
"<svg:g transform='translate("<<width*.05<<
","<<height*.05<<
") scale(.85,.85)'>";
163 while(pos!=drawing.end()){
170 drawAtom(pos,sstr,fontSize,includeAtomCircles);
173 std::cerr<<
"unrecognized token: "<<token<<std::endl;
176 sstr<<
"</svg:g></svg:svg>";
std::string DrawingToSVG(const std::vector< int > &drawing, unsigned int lineWidthMult=2, unsigned int fontSize=50, bool includeAtomCircles=false)
Includes a bunch of functionality for handling Atom and Bond queries.
void drawLine(std::vector< ElementType > &res, int atnum1, int atnum2, int lineWidth, int dashed, double x1, double y1, double x2, double y2)