| 188 | } |
| 189 | |
| 190 | bool svgfill::svg_to_polygons(const std::string& data, const boost::optional<std::string>& class_name, std::vector<polygon_2>& polygons) { |
| 191 | Context context; |
| 192 | context.class_name = class_name; |
| 193 | xmlDoc* doc = xmlReadMemory(data.c_str(), data.size(), nullptr, nullptr, 0); |
| 194 | xmlNode* elem = xmlDocGetRootElement(doc); |
| 195 | |
| 196 | try { |
| 197 | document_traversal< |
| 198 | processed_elements<processed_elements_t>, |
| 199 | processed_attributes<processed_attributes_t> |
| 200 | >::load_document(elem, context); |
| 201 | } catch (std::exception& e) { |
| 202 | std::cerr << e.what() << std::endl; |
| 203 | return false; |
| 204 | } |
| 205 | std::function<void(float)> fn = [](float f) {}; |
| 206 | std::vector<std::vector<polygon_2>> ps; |
| 207 | if (!line_segments_to_polygons(svgfill::EXACT_PREDICATES, 0., context.segments, ps, fn)) { |
| 208 | return false; |
| 209 | } |
| 210 | if (ps.empty()) { |
| 211 | return false; |
| 212 | } |
| 213 | for (auto& p : ps) { |
| 214 | polygons.insert(polygons.end(), p.begin(), p.end()); |
| 215 | } |
| 216 | return true; |
| 217 | } |
| 218 | |
| 219 | template <typename Kernel> |
| 220 | class cgal_arrangement : public svgfill::abstract_arrangement { |