#ifndef COOT_LIDIA_CORE_SVG_CONTAINER_HH #define COOT_LIDIA_CORE_SVG_CONTAINER_HH #include #include // for debugging - remove later. #include "lig-build.hh" class svg_container_t { public: svg_container_t() { init(); } explicit svg_container_t(const std::string &s) : svg(s) { init(); } std::string svg; std::string svg_header_1; std::string svg_header_2; std::string svg_footer; float min_x; float min_y; float max_x; float max_y; void init() { svg_header_1 = " max_x) { std::cout << "debug:: max_x was " << max_x << " now " << max_xx << std::endl; } if (max_yy > max_y) { std::cout << "debug:: max_y was " << max_y << " now " << max_yy << std::endl; } #endif if (min_xx < min_x) { min_x = min_xx; bounding_box_updated = true; } if (min_yy < min_y) { min_y = min_yy; bounding_box_updated = true; } if (max_xx > max_x) { max_x = max_xx; bounding_box_updated = true; } if (max_yy > max_y) { max_y = max_yy; bounding_box_updated = true; } return bounding_box_updated; } // used to add a key to flev void add_to_y_bounds(double yy) { max_y += yy; } std::string make_viewbox_string() const { float width = max_x - min_x; float height = max_y - min_y; std::string viewBox_string = "viewBox=" + std::string("\"") + std::to_string(min_x) + std::string(" ") + std::to_string(min_y) + std::string(" ") + std::to_string(width) + std::string(" ") + std::to_string(height) + std::string("\""); return viewBox_string; } void add(const std::string &s) { svg += s; } void prepend(const svg_container_t &svgc_in) { svg = svgc_in.svg + svg; update_bounds(svgc_in.min_x, svgc_in.min_y, svgc_in.max_x, svgc_in.max_y); } void add(const svg_container_t &svgc_in) { svg += svgc_in.svg; update_bounds(svgc_in.min_x, svgc_in.min_y, svgc_in.max_x, svgc_in.max_y); } void add_comment(const std::string &comment) { svg += "\n"; } void add_line(const lig_build::pos_t &p1, const lig_build::pos_t &p2, double line_width, const std::string &stroke_colour, bool dashed) { std::string s; s += " \n"; svg += s; }; std::string compose(bool add_background_rect) const { auto quoted = [] (float v) { std::string s = std::to_string(v); return std::string("'" + s + "'"); }; auto make_background_rect = [quoted] (float min_x, float min_y, float max_x, float max_y) { float w = max_x - min_x; float h = max_y - min_y; std::string s = "\n"; s += " min_x) { std::string s = svg_header_1; s += make_viewbox_string(); s += svg_header_2; if (add_background_rect) s += make_background_rect(min_x, min_y, max_x, max_y); s += svg; s += svg_footer; return s; } else { return ""; } } }; #endif // SVG_COOT_LIDIA_CORE_CONTAINER_HH