HOG2
SVGUtil.cpp
Go to the documentation of this file.
1 //
2 // SVGUtil.cpp
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 10/29/15.
6 // Copyright © 2015 University of Denver. All rights reserved.
7 //
8 
9 #include "SVGUtil.h"
10 #include <iostream>
11 #include <fstream>
12 
13 //<svg height="500" width="500">
14 //<defs>
15 //<radialGradient id="grad1" cx="60%" cy="40%" r="50%" fx="70%" fy="40%">
16 //<stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:0.5" />
17 //<stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1" />
18 //</radialGradient>
19 //</defs>
20 //<ellipse cx="200" cy="200" rx="55" ry="55" fill="url(#grad1)" />
21 //Sorry, your browser does not support inline SVG.
22 //</svg>
23 
24 
25 std::string SVGGetRGB(rgbColor c)
26 {
27  std::string s;
28  s = "rgb(";
29  s += std::to_string(int(c.r*255)) + "," + std::to_string(int(c.g*255)) + "," + std::to_string(int(c.b*255));
30  s += ")";
31  return s;
32 }
33 
34 std::string SVGDefineGradient(bool horizontal, bool vertical, rgbColor c1, rgbColor c2, const char *name)
35 {
36  std::string s;
37  s += "<defs><linearGradient id=\"";
38  s += name;
39  s += "\" x1=\"0%\" y1=\"0%\" x2=\"0%\" y2=\"100%\">";
40  s += "<stop offset=\"0%\" style=\"stop-color:";
41  s += SVGGetRGB(c1);
42  s += ";stop-opacity:1\" />";
43  s += "<stop offset=\"100%\" style=\"stop-color:";
44  s += SVGGetRGB(c2);
45  s += ";stop-opacity:1\" />";
46  s += "</linearGradient></defs>";
47 
48  return s;
49 }
50 
51 std::string SVGFrameCircle(double x, double y, double radius, double border, rgbColor c)
52 {
53  std::string s;
54  s += "<circle cx=\"" + to_string_with_precision(x);
55  s += "\" cy=\"" + to_string_with_precision(y);
56  s += "\" r=\""+to_string_with_precision(radius)+"\" style=\"fill:none;stroke:"+SVGGetRGB(c)+";stroke-width:"+to_string_with_precision(border)+"\" />";
57  return s;
58 }
59 
60 std::string SVGDrawCircle(double x, double y, double radius, rgbColor c)
61 {
62  //double epsilon = 0.5;
63  std::string s;
64  s += "<circle cx=\"" + to_string_with_precision(x);
65  s += "\" cy=\"" + to_string_with_precision(y);
66  s += "\" r=\""+to_string_with_precision(radius)+"\" style=\"fill:"+SVGGetRGB(c)+";stroke-width:1\" />";
67  return s;
68 
69 // s += "<circle cx=\"" + std::to_string(10*x);
70 // s += "\" cy=\"" + std::to_string(10*y);
71 // s += "\" r=\""+std::to_string(radius*10)+"\" style=\"fill:"+SVGGetRGB(c)+";stroke-width:1\" />";
72 }
73 
74 std::string SVGDrawRect(float x, float y, float width, float height, const char *gradient)
75 {
76  double epsilon = 0.05;
77  std::string s;
78  s += "<rect x=\"" + std::to_string(10*x-epsilon);
79  s += "\" y=\"" + std::to_string(10*y-epsilon);
80  s += "\" width=\""+std::to_string(width*10+2*epsilon)+"\" height=\""+std::to_string(height*10+2*epsilon)+"\" ";
81  s += "fill=\"url(#";
82  s += gradient;
83  s += ")\"";
84  s += " style=\"stroke-width:1\" />";
85  return s;
86 }
87 
88 std::string SVGDrawRect(float x, float y, float width, float height, rgbColor c)
89 {
90  double epsilon = 0.0;//0.55;
91  std::string s;
92  s += "<rect x=\"" + to_string_with_precision(x-epsilon);
93  s += "\" y=\"" + to_string_with_precision(y-epsilon);
94  s += "\" width=\""+to_string_with_precision(width+2*epsilon, 8)+"\" height=\""+to_string_with_precision(height+2*epsilon, 8)+"\" style=\"fill:"+SVGGetRGB(c)+";\" />";
95 // s += "\" width=\""+to_string_with_precision(width+2*epsilon, 8)+"\" height=\""+to_string_with_precision(height+2*epsilon, 8)+"\" style=\"fill:"+SVGGetRGB(c)+";stroke:"+SVGGetRGB(c)+";stroke-width:5%\" />";
96  return s;
97 }
98 
99 std::string SVGFrameRect(float x, float y, float width, float height, float border, rgbColor c)
100 {
101  double epsilon = 0;//0.05;//0.5;
102  std::string s;
103  s += "<rect x=\"" + to_string_with_precision(x-epsilon+0);
104  s += "\" y=\"" + to_string_with_precision(y-epsilon+0);
105  s += "\" width=\""+to_string_with_precision(width+2*epsilon-0)+"\" height=\""+to_string_with_precision(height+2*epsilon-0)+"\" style=\"fill:none;stroke:"+SVGGetRGB(c);
106  s += ";stroke-width:"+std::to_string(border)+"\" />";
107  return s;
108 }
109 
110 std::string SVGFrameNGon(double _x, double _y, double radius, int segments, float rotation, int border, rgbColor c)
111 {
112  double resolution = TWOPI/segments;
113  std::string s;
114  s += "<polygon points=\"";
115 
116  for (int x = 0; x <= segments; x++)
117  {
118  s += to_string_with_precision(_x+sin(resolution*x+rotation*TWOPI/360.0)*radius);
119  s += ",";
120  s += to_string_with_precision(_y+cos(resolution*x+rotation*TWOPI/360.0)*radius);
121  s += " ";
122  }
123  s += "\" style=\"fill:none;stroke:purple;stroke-width:1\" />";
124  return s;
125 }
126 
127 std::string SVGDrawNGon(double _x, double _y, double radius, int segments, float rotation, rgbColor c)
128 {
129  double resolution = TWOPI/segments;
130  std::string s;
131  s += "<polygon points=\"";
132 
133  for (int x = 0; x <= segments; x++)
134  {
135  s += to_string_with_precision(_x+sin(resolution*x+rotation*TWOPI/360.0)*radius);
136  s += ",";
137  s += to_string_with_precision(_y+cos(resolution*x+rotation*TWOPI/360.0)*radius);
138  s += " ";
139  }
140  s += "\" style=\"fill:"+SVGGetRGB(c)+"\" />";
141  return s;
142 }
143 
144 //void DrawCircle(GLdouble _x, GLdouble _y, GLdouble tRadius, int segments = 32, float rotation = 0);
145 //void FrameCircle(GLdouble _x, GLdouble _y, GLdouble tRadius, GLdouble lineWidth, int segments = 32, float rotation = 0);
146 
147 std::string SVGBeginLinePath(float width, rgbColor c)
148 {
149  return "<path stroke-linejoin=\"round\" stroke-linecap=\"round\" stroke=\""+SVGGetRGB(c)+"\" stroke-width=\""+std::to_string(width)+"\" fill=\"none\" d=\"";
150 //
151 // s += "M "+std::to_string(lines[0].x)+" "+std::to_string(lines[0].y)+" L";
152 //
153 // for (int x = 1; x < lines.size(); x++)
154 // {
155 // s += " "+std::to_string(lines[x].x)+" "+std::to_string(lines[x].y)+" ";
156 // }
157 // // s += "\" stroke=\"black\" stroke-width=\""+std::to_string(width)+"\" fill=\"none\" vector-effect: \"non-scaling-stroke\";/>\n";
158 // s += "\" stroke=\""+SVGGetRGB(c)+"\" stroke-width=\""+std::to_string(width)+"\" fill=\"none\" />\n";
159 //
160 }
161 
162 std::string SVGAddLinePath(float x1, float y1)
163 {
164  return "L "+std::to_string(x1)+" "+std::to_string(y1)+" ";
165 }
166 
167 std::string SVGAddLinePath(float x1, float y1, float x2, float y2)
168 {
169  return "M "+std::to_string(x1)+" "+std::to_string(y1)+" L "+std::to_string(x2)+" "+std::to_string(y2)+" ";
170 }
171 
172 std::string SVGEndLinePath()
173 { return "\" />\n"; }
174 
175 
176 std::string SVGDrawLineSegments(const std::vector<Graphics::point> &lines, float width, rgbColor c)
177 {
178  std::string s = "<path d=\"";
179 
180  s += "M "+std::to_string(lines[0].x)+" "+std::to_string(lines[0].y)+" L";
181 
182  for (size_t x = 1; x < lines.size(); x++)
183  {
184  s += " "+std::to_string(lines[x].x)+" "+std::to_string(lines[x].y)+" ";
185  }
186 // s += "\" stroke=\"black\" stroke-width=\""+std::to_string(width)+"\" fill=\"none\" vector-effect: \"non-scaling-stroke\";/>\n";
187  s += "\" stroke=\""+SVGGetRGB(c)+"\" stroke-width=\""+std::to_string(width)+"\" fill=\"none\" />\n";
188  return s;
189 }
190 
191 
192 std::string SVGDrawLine(float x1, float y1, float x2, float y2, float width, rgbColor c)
193 {
194  std::string s;
195  s = "<line x1 = \"" + std::to_string(x1) + "\" ";
196  s += "y1 = \"" + std::to_string(y1) + "\" ";
197  s += "x2 = \"" + std::to_string(x2) + "\" ";
198  s += "y2 = \"" + std::to_string(y2) + "\" ";
199  s += "style=\"stroke:"+SVGGetRGB(c);
200  s += ";stroke-width:"+std::to_string(width)+"\" stroke-linecap=\"round\" />";
201  return s;
202 }
203 
204 std::string SVGDrawLine(int x1, int y1, int x2, int y2, int width, rgbColor c, bool center)
205 {
206  std::string s;
207  float offset = center?0.5:0;
208  s = "<line x1 = \"" + std::to_string(x1+offset) + "\" ";
209  s += "y1 = \"" + std::to_string(y1+offset) + "\" ";
210  s += "x2 = \"" + std::to_string(x2+offset) + "\" ";
211  s += "y2 = \"" + std::to_string(y2+offset) + "\" ";
212  s += "style=\"stroke:"+SVGGetRGB(c);
213  s += ";stroke-width:"+std::to_string(width)+"\" stroke-linecap=\"round\" />";
214  return s;
215 
216 // std::string s;
217 // int offset = center?5:0;
218 // s = "<line x1 = \"" + std::to_string(10*x1+offset) + "\" ";
219 // s += "y1 = \"" + std::to_string(10*y1+offset) + "\" ";
220 // s += "x2 = \"" + std::to_string(10*x2+offset) + "\" ";
221 // s += "y2 = \"" + std::to_string(10*y2+offset) + "\" ";
222 // s += "style=\"stroke:"+SVGGetRGB(c);
223 // s += ";stroke-width:"+std::to_string(width)+"\" stroke-linecap=\"round\" />";
224 // return s;
225 }
226 
227 std::string SVGDrawText(float x1, float y1, const char *txt, rgbColor c, double size, const char *typeface, SVG::svgAlignment align, SVG::svgBaseline base)
228 {
229  std::string s;
230 // s = "<text x=\""+std::to_string(x1*10+2)+"\" y=\""+std::to_string(y1*10-1)+"\" text-anchor=\"middle\" style=\"fill:"+SVGGetRGB(c);
231 // s += "; font-family:Helvetica, sans-serif; font-size:"+std::to_string(size*10)+"px\">";
232  // Helvetica Impact
233  s = "<text x=\""+std::to_string(x1)+"\" y=\""+std::to_string(y1)+"\" text-anchor=\"";
234  switch (align) {
235  case SVG::kLeft: s += "start"; break;
236  case SVG::kRight: s += "end"; break;
237  case SVG::kCenter: s += "middle"; break;
238  }//middle
239  s += "\" style=\"fill:"+SVGGetRGB(c);
240  s += "; font-family:";
241  if (typeface)
242  s += typeface;
243  else
244  s += "Helvetica";
245  s += ", sans-serif; font-weight:bold; font-size:"+std::to_string(size)+"px\"";
246  switch (base) {
247  case SVG::kBottom:
248  s += " dominant-baseline=\"baseline\">";
249  break;
250  case SVG::kTop:
251  s += " dominant-baseline=\"hanging\">";
252  break;
253  case SVG::kMiddle:
254  s += " dominant-baseline=\"middle\">";
255  break;
256  }
257  s += txt;
258  s += "</text>";
259  // s += "<text x=\""+std::to_string(x1*10+2)+"\" y=\""+std::to_string(y1*10-1)+"\" style=\"fill:"+SVGGetRGB(c);
260  // s += "; font-family:Impact, sans-serif; font-size:"+std::to_string(size*10)+"px; stroke:"+SVGGetRGB(notC)+"; stroke-width:0px\">";
261  // s += txt;
262  // s += "</text>";
263  return s;
264 }
265 
266 std::string SVGDrawStrokedText(float x1, float y1, const char *txt, rgbColor c, rgbColor strokeColor, double size)
267 {
268  std::string s;
269  s = "<text x=\""+std::to_string(x1*10+2)+"\" y=\""+std::to_string(y1*10-1)+"\" style=\"fill:"+SVGGetRGB(c);
270  s += "; font-family:Impact, sans-serif; font-size:"+std::to_string(size*10)+"px; stroke:"+SVGGetRGB(strokeColor)+"; stroke-width:"+std::to_string(size)+"px; stroke-linecap:round;stroke-linejoin:round\">";
271  s += txt;
272  s += "</text>\n";
273  return s;
274 }
275 
276 
277 float WidthToSVG(float w, float xMultiplier, float yMultiplier)
278 {
279  return std::min(xMultiplier, yMultiplier)*((w+1)/2.0-(0+1)/2.0);
280 }
281 
282 float PointToSVG(float p, float multiplier)
283 {
284  return (p+1)*multiplier/2.0;
285 }
286 
287 void PointToSVG(Graphics::point &p, float xmultiplier, float ymultiplier)
288 {
289  p.x = (p.x+1)*xmultiplier/2.0;
290  p.y = (p.y+1)*ymultiplier/2.0;
291 }
292 
293 
294 void HandleCommand(const std::vector<Graphics::Display::data> &drawCommands, std::string &s, int width, int height, int viewport)
295 {
296  for (size_t x = 0; x < drawCommands.size(); x++)
297  {
298  if (drawCommands[x].viewport != viewport)
299  continue;
300  switch (drawCommands[x].what)
301  {
303  {
304  //WidthToSVG(i.size, width, height)
305  s += SVGBeginLinePath(WidthToSVG(drawCommands[x].line.width, width, height), drawCommands[x].line.c);
306  bool first = true;
307  while (drawCommands[x].what == Graphics::Display::kLine &&
308  (first ||
309  (drawCommands[x].line.width == drawCommands[x-1].line.width &&
310  drawCommands[x].line.c == drawCommands[x-1].line.c)))
311  {
312  const Graphics::Display::lineInfo &o = drawCommands[x].line; //disp.lines[x];
313  if (first)
314  {
317  first = false;
318  }
319  else if (drawCommands[x-1].line.end == o.start)
320  {
322  }
323  else {
326  }
327 // s += SVGDrawLine((o.start.x+1)*width/2.0, (o.start.y+1)*height/2.0, (o.end.x+1)*width/2.0, (o.end.y+1)*height/2.0, o.width, o.c);
328  if (o.arrow)
329  {
330 
331  Graphics::point newEnd = o.end*0.975f+o.start*0.025f;
332  Graphics::point p1 = o.end-o.start;
333  Graphics::point p2 = o.start;
334  p2.z = 1;
335  p2 = p1*p2;
336  p2.normalise();
337  p2 *= (o.end-newEnd).length();
338 
339  s += SVGAddLinePath(PointToSVG(newEnd.x+p2.x, width), PointToSVG(newEnd.y+p2.y, height),
341  s += SVGAddLinePath(PointToSVG(newEnd.x-p2.x, width), PointToSVG(newEnd.y-p2.y, height),
343  }
344  x++;
345  }
346  x--;
347  s += SVGEndLinePath();
348  // if (o.arrow)
349  // {
350  // Graphics::point newEnd = o.end*0.975f+o.start*0.025f;
351  // Graphics::point p1 = o.end-o.start;
352  // Graphics::point p2 = o.start;
353  // p2.z = 1;
354  // p2 = p1*p2;
355  // p2.normalise();
356  // p2 *= (o.end-newEnd).length();
357  // CGContextMoveToPoint(context, ((o.end.x)*xscale+xoffset), height-(o.end.y*yscale+yoffset));
358  // CGContextAddLineToPoint(context, ((newEnd.x+p2.x)*xscale+xoffset), height-((newEnd.y+p2.y)*yscale+yoffset));
359  // CGContextMoveToPoint(context, ((o.end.x)*xscale+xoffset), height-(o.end.y*yscale+yoffset));
360  // CGContextAddLineToPoint(context, ((newEnd.x-p2.x)*xscale+xoffset), height-((newEnd.y-p2.y)*yscale+yoffset));
361  // }
362 
363  break;
364  }
366  {
367  const Graphics::Display::drawInfo &o = drawCommands[x].shape;
368  if (drawCommands.size() > x+1 && drawCommands[x+1].what == Graphics::Display::kFillRectangle &&
369  drawCommands[x+1].shape.c == o.c)
370  {
371  s += "<g style=\"fill:"+SVGGetRGB(o.c)+";\">\n";
372 
373  while (true)
374  {
375  const Graphics::Display::drawInfo &o1 = drawCommands[x].shape;
376  float x1 = PointToSVG(o1.r.left, width);
377  float y1 = PointToSVG(o1.r.top, height);
378  float w1 = PointToSVG(o1.r.right, width)-PointToSVG(o1.r.left, width);
379  float h1 = PointToSVG(o1.r.bottom, height)-PointToSVG(o1.r.top, height);
380  s += " <rect x=\"" + to_string_with_precision(x1);
381  s += "\" y=\"" + to_string_with_precision(y1);
382  s += "\" width=\""+to_string_with_precision(w1)+"\" height=\""+to_string_with_precision(h1)+"\"/>\n";
383 
384  x++;
385  if (drawCommands.size() > x && drawCommands[x].what == Graphics::Display::kFillRectangle &&
386  drawCommands[x].shape.c == o.c)
387  {
388 
389  }
390  else {
391  x--;
392  break;
393  }
394  }
395  s += "</g>";
396  }
397  else {
401  o.c);
402  }
403  break;
404  }
406  {
407  const Graphics::Display::drawInfo &o = drawCommands[x].shape;
411  WidthToSVG(o.width, width, height), o.c);
412  break;
413  }
415  {
416  const Graphics::Display::drawInfo &o = drawCommands[x].shape;
417  s += SVGDrawCircle(((o.r.left+o.r.right)/2.0+1)*width/2.0, ((o.r.top+o.r.bottom)/2.0+1)*height/2.0, width*(o.r.right-o.r.left)/4.0, o.c);
418  break;
419  }
421  {
422  const Graphics::Display::drawInfo &o = drawCommands[x].shape;
423  s += SVGFrameCircle(((o.r.left+o.r.right)/2.0+1)*width/2.0, ((o.r.top+o.r.bottom)/2.0+1)*height/2.0, width*(o.r.right-o.r.left)/4.0,
424  WidthToSVG(o.width, width, height), o.c);
425 
426  break;
427  }
429  {
430  const Graphics::Display::shapeInfo &i = drawCommands[x].polygon;
431  Graphics::point p = i.center;
432  PointToSVG(p, width, height);
433  s += SVGDrawNGon(p.x, p.y, width*i.radius/2.0, i.segments, i.rotate, i.c);
434  // s += SVGDrawNGon(i.center.x, i.center.y, i.radius, i.segments, i.rotate, i.c);
435  break;
436  }
438  {
439  const Graphics::Display::shapeInfo &i = drawCommands[x].polygon;
440  Graphics::point p = i.center;
441  PointToSVG(p, width, height);
442  s += SVGFrameNGon(p.x, p.y, width*i.radius/2.0, i.segments, i.rotate, 1/*border*/, i.c);
443  break;
444  }
446  {
447  Graphics::point p1, p2, p3;
448  const Graphics::Display::triangleInfo &i = drawCommands[x].triangle;
449  p1 = i.p1;
450  p2 = i.p2;
451  p3 = i.p3;
452  PointToSVG(p1, width, height);
453  PointToSVG(p2, width, height);
454  PointToSVG(p3, width, height);
455  s += "<polygon points=\""+
456  std::to_string(p1.x)+","+std::to_string(p1.y)+" "+
457  std::to_string(p2.x)+","+std::to_string(p2.y)+" "+
458  std::to_string(p3.x)+","+std::to_string(p3.y)+"\" ";
459  s += "style=\"fill:none;stroke:"+SVGGetRGB(i.c)+";stroke-width:"+std::to_string(i.width)+"\" />";
460 // s += "style=\"fill:"+SVGGetRGB(i.c);
461  //style="fill:lime;stroke:purple;stroke-width:1" />
462  break;
463  }
465  {
466  Graphics::point p1, p2, p3;
467  const Graphics::Display::triangleInfo &i = drawCommands[x].triangle;
468  p1 = i.p1;
469  p2 = i.p2;
470  p3 = i.p3;
471  PointToSVG(p1, width, height);
472  PointToSVG(p2, width, height);
473  PointToSVG(p3, width, height);
474  s += "<polygon points=\""+
475  std::to_string(p1.x)+","+std::to_string(p1.y)+" "+
476  std::to_string(p2.x)+","+std::to_string(p2.y)+" "+
477  std::to_string(p3.x)+","+std::to_string(p3.y)+"\" ";
478  s += "style=\"fill:"+SVGGetRGB(i.c)+";\" />";
479  }
480  }
481  }
482 }
483 
484 void MakeSVG(const Graphics::Display &disp, const char *filename, int width, int height, int viewport, const char *comment, bool crisp)
485 {
486  std::string s = MakeSVG(disp, width, height, viewport, comment, crisp);
487  FILE *f = fopen(filename, "w+");
488  if (f == 0)
489  {
490  printf("Error: Could not open file '%s'\n", filename);
491  return;
492  }
493  fputs(s.c_str(), f);
494  fclose(f);
495 // std::fstream myFile;
496 // std::fstream svgFile;
497 // svgFile.open(filename, std::fstream::out | std::fstream::trunc);
498 // svgFile << s;
499 // svgFile.close();
500 }
501 
502 std::string MakeSVG(const Graphics::Display &disp, int width, int height, int viewport, const char *comment, bool crisp)
503 {
504  std::string s;
505  s = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width = \""+std::to_string(width)+"\" height = \""+std::to_string(height)+"\" ";
506  s += "viewBox = \"0 0 "+std::to_string(width)+" "+std::to_string(height)+"\" ";
507 // s += "viewBox = \"-1 -1 "+std::to_string(width+2)+" "+std::to_string(height+2)+"\" ";
508  //s += "preserveAspectRatio = \"none\" shape-rendering=\"crispEdges\""; // crispEdges
509  //s += " preserveAspectRatio = \"none\"";
510  if (crisp)
511  s += " shape-rendering=\"crispEdges\""; // crispEdges
512  s += ">\n";
513 
514 // s += SVGDrawRect(0, 0, width, height, Colors::white);
515 
518 
519  for (size_t x = 0; x < disp.text.size(); x++)
520  {
521  const auto &i = disp.text[x];
522  if (i.viewport == viewport)
523  {
524  if (i.align == Graphics::textAlignLeft)
525  s += SVGDrawText(PointToSVG(i.loc.x, width),
526  PointToSVG(i.loc.y, height),
527  i.s.c_str(), i.c, i.size*width/2.0, i.typeface.c_str(), SVG::kLeft);
528  else if (i.align == Graphics::textAlignCenter)
529  s += SVGDrawText(PointToSVG(i.loc.x, width),
530  PointToSVG(i.loc.y, height),
531  i.s.c_str(), i.c, i.size*width/2.0, i.typeface.c_str(), SVG::kCenter);
532  else
533  s += SVGDrawText(PointToSVG(i.loc.x, width),
534  PointToSVG(i.loc.y, height),
535  i.s.c_str(), i.c, i.size*width/2.0, i.typeface.c_str(), SVG::kRight);
536  s += "\n";
537  }
538  }
539  static std::vector<Graphics::point> outputPoints;
540  for (size_t x = 0; x < disp.lineSegments.size(); x++)
541  {
542  const auto &i = disp.lineSegments[x];
543  if (i.viewport == viewport)
544  {
545  outputPoints = i.points;
546  for (auto &j : outputPoints)
547  PointToSVG(j, width, height);
548 // s += SVGDrawLineSegments(outputPoints, i.size, i.c);
549  s += SVGDrawLineSegments(outputPoints, WidthToSVG(i.size, width, height), i.c);
550 
551  s += "\n";
552  }
553  }
554 
555 
556  s += "\n";
557  if (comment)
558  {
559  s += "<!--";
560  s += comment;
561  s += "-->\n";
562  }
563  s += "</svg>";
564  return s;
565 }
Graphics::Display::drawInfo::r
rect r
Definition: Graphics.h:181
Graphics::point
Definition: Graphics.h:32
Graphics::point::y
float y
Definition: Graphics.h:36
SVGDefineGradient
std::string SVGDefineGradient(bool horizontal, bool vertical, rgbColor c1, rgbColor c2, const char *name)
Definition: SVGUtil.cpp:34
rgbColor::b
float b
Definition: Colors.h:71
rgbColor
A color; r/g/b are between 0...1.
Definition: Colors.h:17
SVG::kTop
@ kTop
Definition: SVGUtil.h:27
min
double min(double a, double b)
Definition: FPUtil.h:35
Graphics::Display::shapeInfo::segments
int segments
Definition: Graphics.h:194
SVGDrawText
std::string SVGDrawText(float x1, float y1, const char *txt, rgbColor c, double size, const char *typeface, SVG::svgAlignment align, SVG::svgBaseline base)
Definition: SVGUtil.cpp:227
Graphics::Display::kFrameRectangle
@ kFrameRectangle
Definition: Graphics.h:217
Graphics::Display::backgroundDrawCommands
std::vector< data > backgroundDrawCommands
Definition: Graphics.h:272
Graphics::Display::kLine
@ kLine
Definition: Graphics.h:224
SVGDrawRect
std::string SVGDrawRect(float x, float y, float width, float height, const char *gradient)
Definition: SVGUtil.cpp:74
Graphics::Display::shapeInfo
Definition: Graphics.h:190
Graphics::Display::triangleInfo
Definition: Graphics.h:185
Graphics::Display::kFillRectangle
@ kFillRectangle
Definition: Graphics.h:216
SVGBeginLinePath
std::string SVGBeginLinePath(float width, rgbColor c)
Definition: SVGUtil.cpp:147
WidthToSVG
float WidthToSVG(float w, float xMultiplier, float yMultiplier)
Definition: SVGUtil.cpp:277
width
int width
Definition: SFML_HOG.cpp:54
rotation
float rotation[3][3]
Definition: RC.cpp:21
Graphics::point::normalise
void normalise()
Definition: Graphics.h:69
SVG::kBottom
@ kBottom
Definition: SVGUtil.h:25
Graphics::Display::lineInfo::start
point start
Definition: Graphics.h:199
rgbColor::g
float g
Definition: Colors.h:71
SVGDrawCircle
std::string SVGDrawCircle(double x, double y, double radius, rgbColor c)
Definition: SVGUtil.cpp:60
Graphics::Display::triangleInfo::width
float width
Definition: Graphics.h:188
MakeSVG
void MakeSVG(const Graphics::Display &disp, const char *filename, int width, int height, int viewport, const char *comment, bool crisp)
Definition: SVGUtil.cpp:484
Graphics::Display::kFillTriangle
@ kFillTriangle
Definition: Graphics.h:218
Graphics::Display::kFrameOval
@ kFrameOval
Definition: Graphics.h:221
Graphics::Display::drawInfo
Definition: Graphics.h:180
Graphics::Display::drawInfo::width
float width
Definition: Graphics.h:183
viewport
Definition: Common.h:56
SVGDrawStrokedText
std::string SVGDrawStrokedText(float x1, float y1, const char *txt, rgbColor c, rgbColor strokeColor, double size)
Definition: SVGUtil.cpp:266
Graphics::Display::kFrameNGon
@ kFrameNGon
Definition: Graphics.h:223
to_string_with_precision
std::string to_string_with_precision(const T a_value, const int n=6)
Definition: GLUtil.h:185
Graphics::Display::lineInfo::arrow
bool arrow
Definition: Graphics.h:202
Graphics::rect::top
float top
Definition: Graphics.h:100
SVG::svgBaseline
svgBaseline
Definition: SVGUtil.h:24
Graphics::Display::drawCommands
std::vector< data > drawCommands
Definition: Graphics.h:268
SVGUtil.h
Graphics::Display::kFillOval
@ kFillOval
Definition: Graphics.h:220
Graphics::Display::lineInfo
Definition: Graphics.h:198
Graphics::Display::triangleInfo::p3
point p3
Definition: Graphics.h:186
Graphics::Display::shapeInfo::radius
float radius
Definition: Graphics.h:193
SVG::kMiddle
@ kMiddle
Definition: SVGUtil.h:26
SVG::kCenter
@ kCenter
Definition: SVGUtil.h:21
Graphics::Display
Definition: Graphics.h:146
Graphics::Display::drawInfo::c
rgbColor c
Definition: Graphics.h:182
Graphics::rect::right
float right
Definition: Graphics.h:100
PointToSVG
float PointToSVG(float p, float multiplier)
Definition: SVGUtil.cpp:282
Graphics::Display::kFillNGon
@ kFillNGon
Definition: Graphics.h:222
SVGDrawNGon
std::string SVGDrawNGon(double _x, double _y, double radius, int segments, float rotation, rgbColor c)
Definition: SVGUtil.cpp:127
height
int height
Definition: SFML_HOG.cpp:54
Graphics::Display::shapeInfo::rotate
float rotate
Definition: Graphics.h:195
Graphics::Display::triangleInfo::p1
point p1
Definition: Graphics.h:186
SVGGetRGB
std::string SVGGetRGB(rgbColor c)
Definition: SVGUtil.cpp:25
Graphics::textAlignCenter
@ textAlignCenter
Definition: Graphics.h:20
Graphics::Display::shapeInfo::c
rgbColor c
Definition: Graphics.h:192
Graphics::Display::text
std::vector< textInfo > text
Definition: Graphics.h:269
rgbColor::r
float r
Definition: Colors.h:71
SVGEndLinePath
std::string SVGEndLinePath()
Definition: SVGUtil.cpp:172
Graphics::Display::shapeInfo::center
point center
Definition: Graphics.h:191
SVGDrawLine
std::string SVGDrawLine(float x1, float y1, float x2, float y2, float width, rgbColor c)
Definition: SVGUtil.cpp:192
SVGDrawLineSegments
std::string SVGDrawLineSegments(const std::vector< Graphics::point > &lines, float width, rgbColor c)
Definition: SVGUtil.cpp:176
Graphics::point::x
float x
Definition: Graphics.h:36
SVG::kLeft
@ kLeft
Definition: SVGUtil.h:19
Graphics::point::z
float z
Definition: Graphics.h:36
SVGAddLinePath
std::string SVGAddLinePath(float x1, float y1)
Definition: SVGUtil.cpp:162
TWOPI
static const double TWOPI
Definition: GLUtil.h:65
Graphics::Display::lineSegments
std::vector< segments > lineSegments
Definition: Graphics.h:270
Graphics::textAlignLeft
@ textAlignLeft
Definition: Graphics.h:21
Graphics::Display::triangleInfo::c
rgbColor c
Definition: Graphics.h:187
Graphics::rect::left
float left
Definition: Graphics.h:100
SVG::kRight
@ kRight
Definition: SVGUtil.h:20
Graphics::Display::lineInfo::end
point end
Definition: Graphics.h:199
HandleCommand
void HandleCommand(const std::vector< Graphics::Display::data > &drawCommands, std::string &s, int width, int height, int viewport)
Definition: SVGUtil.cpp:294
Graphics::Display::kFrameTriangle
@ kFrameTriangle
Definition: Graphics.h:219
Graphics::Display::triangleInfo::p2
point p2
Definition: Graphics.h:186
Graphics::rect::bottom
float bottom
Definition: Graphics.h:100
SVG::svgAlignment
svgAlignment
Definition: SVGUtil.h:18
SVGFrameCircle
std::string SVGFrameCircle(double x, double y, double radius, double border, rgbColor c)
Definition: SVGUtil.cpp:51
SVGFrameRect
std::string SVGFrameRect(float x, float y, float width, float height, float border, rgbColor c)
Definition: SVGUtil.cpp:99
SVGFrameNGon
std::string SVGFrameNGon(double _x, double _y, double radius, int segments, float rotation, int border, rgbColor c)
Definition: SVGUtil.cpp:110