text_placements_ptr text_placements_simple::from_xml(xml_node const& xml, fontset_map const& fontsets, bool is_shield) { // TODO - handle X cleaner std::string placements_string = xml.get_attr<std::string>("placements", "X"); // like set_property_from_xml in properties_util.hpp if (!placements_string.empty()) { if (placements_string == "X") { text_placements_ptr ptr = std::make_shared<text_placements_simple>(placements_string); ptr->defaults.from_xml(xml, fontsets, is_shield); return ptr; } else { try { // we don't use parse_expression(placements_string) directly here to benefit from the cache in the xml_node boost::optional<expression_ptr> val = xml.get_opt_attr<expression_ptr>("placements"); if (val) { text_placements_ptr ptr = std::make_shared<text_placements_simple>(*val); ptr->defaults.from_xml(xml, fontsets, is_shield); return ptr; } } catch (std::exception const& ex) { // otherwise ensure it is valid std::vector<directions_e> direction; std::vector<int> text_sizes; if (!parse_positions(placements_string,direction,text_sizes)) { MAPNIK_LOG_ERROR(text_placements) << "Could not parse text_placement_simple placement string ('" << placements_string << "')"; if (direction.size() == 0) { MAPNIK_LOG_ERROR(text_placements) << "text_placements_simple with no valid placements! ('"<< placements_string <<"')"; } return text_placements_ptr(); } else { text_placements_ptr ptr = std::make_shared<text_placements_simple>(placements_string,std::move(direction),std::move(text_sizes)); ptr->defaults.from_xml(xml, fontsets, is_shield); return ptr; } } text_placements_ptr ptr = std::make_shared<text_placements_simple>(placements_string); ptr->defaults.from_xml(xml, fontsets, is_shield); return ptr; } } return text_placements_ptr(); }
text_placements_ptr text_placements_reverse_combined::from_xml(xml_node const& xml, fontset_map const& fontsets, bool is_shield) { text_placements_ptr simple_placement_ptr = text_placements_simple::from_xml(xml, fontsets, is_shield); text_placements_ptr list_placement_ptr = text_placements_list::from_xml(xml, fontsets, is_shield); if(simple_placement_ptr && list_placement_ptr) { text_placements_ptr ptr = std::make_shared<text_placements_reverse_combined>(simple_placement_ptr, list_placement_ptr); ptr->defaults.from_xml(xml, fontsets, is_shield); return ptr; } return text_placements_ptr(); }
void copy_text_ptr(T* sym) { std::string name = to_expression_string(*sym->get_name()); sym->set_name( parse_expression(name) ); // FIXME - orientation doesn't appear to be initialized in constructor? //std::string orientation = to_expression_string(*sym->get_orientation()); //sym->set_orientation( parse_expression(orientation) ); float text_size = sym->get_text_size(); position displace = sym->get_displacement(); vertical_alignment_e valign = sym->get_vertical_alignment(); horizontal_alignment_e halign = sym->get_horizontal_alignment(); justify_alignment_e jalign = sym->get_justify_alignment(); text_placements_ptr placements = text_placements_ptr(boost::make_shared<text_placements_dummy>()); sym->set_placement_options( placements ); sym->set_text_size(text_size); sym->set_displacement(displace); sym->set_vertical_alignment(valign); sym->set_horizontal_alignment(halign); sym->set_justify_alignment(jalign); }