mirror of https://github.com/dnomd343/klotski.git
Dnomd343
2 years ago
3 changed files with 32 additions and 46 deletions
@ -1,50 +1,28 @@ |
|||||
#include "svg.h" |
#include "svg.h" |
||||
|
|
||||
#include <cstdio> |
|
||||
|
|
||||
#include <iostream> |
|
||||
|
|
||||
std::string SvgRect::dump() const { |
std::string SvgRect::dump() const { |
||||
|
/// basic attribute of svg-rect
|
||||
/// <rect x="120" width="100" height="100" rx="15" />
|
std::string xml = "<rect "; |
||||
|
xml += "x=\"" + std::to_string(left) + "\" "; |
||||
// char *radius_str = nullptr;
|
xml += "y=\"" + std::to_string(top) + "\" "; |
||||
// if (radius == 0) {
|
xml += "width=\"" + std::to_string(width) + "\" "; |
||||
// asprintf(&radius_str, " ");
|
xml += "height=\"" + std::to_string(height) + "\" "; |
||||
// } else {
|
|
||||
// asprintf(&radius_str, R"( rx="%lu" )", radius);
|
|
||||
// }
|
|
||||
|
|
||||
std::string style; |
|
||||
|
|
||||
// style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9"
|
|
||||
|
|
||||
char *xml = nullptr; |
|
||||
asprintf(&xml, R"(<rect x="%ld" y="%ld" width="%ld" height="%ld")", left, top, width, height); |
|
||||
std::string ret(xml); |
|
||||
free(xml); |
|
||||
|
|
||||
if (radius != 0) { |
if (radius != 0) { |
||||
char *radius_str = nullptr; |
xml += "rx=\"" + std::to_string(radius) + "\" "; |
||||
asprintf(&radius_str, R"( rx="%lu")", radius); |
|
||||
|
|
||||
ret += radius_str; |
|
||||
|
|
||||
free(radius_str); |
|
||||
} |
} |
||||
|
/// style attribute of svg-rect
|
||||
|
std::string style = "stroke-width:" + std::to_string(stroke) + ";"; |
||||
// std::cout << xml << std::endl;
|
if (!color.empty()) { |
||||
|
style += "fill:" + color + ";"; |
||||
// std::string result = xml;
|
} |
||||
|
if (!line_color.empty()) { |
||||
// free(xml);
|
style += "stroke:" + line_color + ";"; |
||||
|
} |
||||
// std::string xml("<rect ");
|
if (opacity != 0) { |
||||
// xml += "x = ";
|
style += "fill-opacity:" + std::to_string(opacity).substr(0, 4) + ";"; |
||||
//
|
} |
||||
// xml += atoi();
|
if (line_opacity != 0) { |
||||
|
style += "stroke-opacity:" + std::to_string(line_opacity).substr(0, 4) + ";"; |
||||
return ret + " />"; |
} |
||||
|
return xml + "style=\"" + style + "\" />"; |
||||
} |
} |
||||
|
Loading…
Reference in new issue