fix handling of shield-text-opacity/text-opacity - closes #2507

This commit is contained in:
Dane Springmeyer 2014-10-06 21:52:29 -07:00
parent 6e7935b959
commit 7ce776a79c
11 changed files with 38 additions and 27 deletions

View file

@ -61,7 +61,6 @@ enum class keys : std::uint8_t
shield_dx,
shield_dy,
unlock_image,
text_opacity,
mode,
scaling,
filter_factor,

View file

@ -38,7 +38,7 @@ public:
text_symbolizer_properties & add();
text_symbolizer_properties & get(unsigned i);
unsigned size() const;
static text_placements_ptr from_xml(xml_node const& xml, fontset_map const& fontsets);
static text_placements_ptr from_xml(xml_node const& xml, fontset_map const& fontsets, bool is_shield);
private:
std::vector<text_symbolizer_properties> list_;
friend class text_placement_info_list;

View file

@ -36,7 +36,7 @@ namespace mapnik
namespace placements
{
using from_xml_function_ptr = text_placements_ptr (*) (xml_node const&, fontset_map const&) ;
using from_xml_function_ptr = text_placements_ptr (*) (xml_node const&, fontset_map const&, bool) ;
class registry : public singleton<registry, CreateStatic>,
private mapnik::noncopyable
@ -47,7 +47,8 @@ public:
void register_name(std::string name, from_xml_function_ptr ptr, bool overwrite=false);
text_placements_ptr from_xml(std::string name,
xml_node const& xml,
fontset_map const & fontsets);
fontset_map const & fontsets,
bool is_shield);
private:
std::map<std::string, from_xml_function_ptr> map_;
};

View file

@ -39,7 +39,7 @@ public:
text_placement_info_ptr get_placement_info(double scale_factor) const;
void set_positions(std::string const& positions);
std::string get_positions();
static text_placements_ptr from_xml(xml_node const &xml, fontset_map const & fontsets);
static text_placements_ptr from_xml(xml_node const &xml, fontset_map const & fontsets, bool is_shield);
private:
std::string positions_;
std::vector<directions_e> direction_;

View file

@ -95,7 +95,7 @@ using fontset_map = std::map<std::string, font_set>;
struct MAPNIK_DECL format_properties
{
format_properties();
void from_xml(xml_node const& sym, fontset_map const& fontsets);
void from_xml(xml_node const& sym, fontset_map const& fontsets, bool is_shield);
void to_xml(boost::property_tree::ptree & node, bool explicit_defaults,
format_properties const& dfl) const;
// collect expressions
@ -172,7 +172,7 @@ struct MAPNIK_DECL text_symbolizer_properties
// Load only placement related values from XML ptree.
void text_properties_from_xml(xml_node const& node);
// Load all values from XML ptree.
void from_xml(xml_node const& node, fontset_map const& fontsets);
void from_xml(xml_node const& node, fontset_map const& fontsets, bool is_shield);
// Save all values to XML ptree (but does not create a new parent node!).
void to_xml(boost::property_tree::ptree & node, bool explicit_defaults,
text_symbolizer_properties const& dfl) const;

View file

@ -1076,12 +1076,12 @@ void map_parser::parse_text_symbolizer(rule & rule, xml_node const& node)
optional<std::string> placement_type = node.get_opt_attr<std::string>("placement-type");
if (placement_type)
{
placements = placements::registry::instance().from_xml(*placement_type, node, fontsets_);
placements = placements::registry::instance().from_xml(*placement_type, node, fontsets_, false);
}
else
{
placements = std::make_shared<text_placements_dummy>();
placements->defaults.from_xml(node, fontsets_);
placements->defaults.from_xml(node, fontsets_, false);
}
if (strict_ && !placements->defaults.format_defaults.fontset)
{
@ -1110,11 +1110,11 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& node)
optional<std::string> placement_type = node.get_opt_attr<std::string>("placement-type");
if (placement_type)
{
placements = placements::registry::instance().from_xml(*placement_type, node, fontsets_);
placements = placements::registry::instance().from_xml(*placement_type, node, fontsets_, true);
} else {
placements = std::make_shared<text_placements_dummy>();
}
placements->defaults.from_xml(node, fontsets_);
placements->defaults.from_xml(node, fontsets_, true);
if (strict_ &&
!placements->defaults.format_defaults.fontset)
{
@ -1128,7 +1128,6 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& node)
set_symbolizer_property<symbolizer_base,double>(sym, keys::shield_dx, node);
set_symbolizer_property<symbolizer_base,double>(sym, keys::shield_dy, node);
set_symbolizer_property<symbolizer_base,double>(sym, keys::opacity, node);
set_symbolizer_property<symbolizer_base,double>(sym, keys::text_opacity, node);
set_symbolizer_property<symbolizer_base,mapnik::boolean_type>(sym, keys::unlock_image, node);
std::string file = node.get_attr<std::string>("file");

View file

@ -73,7 +73,6 @@ static const property_meta_type key_meta[const_max_key] =
property_meta_type{ "shield-dx", 0.0, nullptr, property_types::target_double },
property_meta_type{ "shield-dy", 0.0, nullptr, property_types::target_double },
property_meta_type{ "unlock-image",false, nullptr, property_types::target_bool },
property_meta_type{ "text-opacity", 1.0, nullptr, property_types::target_double },
property_meta_type{ "mode",false, nullptr, property_types::target_double },
property_meta_type{ "scaling", 1.0, nullptr, property_types::target_double },
property_meta_type{ "filter-factor", 1.0, nullptr, property_types::target_double },

View file

@ -89,15 +89,15 @@ unsigned text_placements_list::size() const
}
text_placements_ptr text_placements_list::from_xml(xml_node const& node, fontset_map const& fontsets)
text_placements_ptr text_placements_list::from_xml(xml_node const& node, fontset_map const& fontsets, bool is_shield)
{
auto list = std::make_shared<text_placements_list>();
list->defaults.from_xml(node, fontsets);
list->defaults.from_xml(node, fontsets, is_shield);
for( auto const& child : node)
{
if (child.is_text() || !child.is("Placement")) continue;
text_symbolizer_properties & p = list->add();
p.from_xml(child, fontsets);
p.from_xml(child, fontsets, is_shield);
//if (strict_ && !p.format.fontset.size())
// ensure_font_face(p.format.face_name);
}

View file

@ -47,11 +47,11 @@ void registry::register_name(std::string name, from_xml_function_ptr ptr, bool o
}
}
text_placements_ptr registry::from_xml(std::string name, xml_node const& xml, fontset_map const& fontsets)
text_placements_ptr registry::from_xml(std::string name, xml_node const& xml, fontset_map const& fontsets, bool is_shield)
{
std::map<std::string, from_xml_function_ptr>::const_iterator itr = map_.find(name);
if (itr == map_.end()) throw config_error("Unknown placement-type '" + name + "'", xml);
return itr->second(xml, fontsets);
return itr->second(xml, fontsets, is_shield);
}
} //ns formatting
} //ns mapnik

View file

@ -141,11 +141,11 @@ std::string text_placements_simple::get_positions()
return positions_; //TODO: Build string from data in direction_ and text_sizes_
}
text_placements_ptr text_placements_simple::from_xml(xml_node const& xml, fontset_map const& fontsets)
text_placements_ptr text_placements_simple::from_xml(xml_node const& xml, fontset_map const& fontsets, bool is_shield)
{
text_placements_ptr ptr = std::make_shared<text_placements_simple>(
xml.get_attr<std::string>("placements", "X"));
ptr->defaults.from_xml(xml, fontsets);
ptr->defaults.from_xml(xml, fontsets, is_shield);
return ptr;
}

View file

@ -150,7 +150,7 @@ void text_symbolizer_properties::text_properties_from_xml(xml_node const& node)
set_property_from_xml<text_upright_e>(expressions.upright, "upright", node);
}
void text_symbolizer_properties::from_xml(xml_node const& node, fontset_map const& fontsets)
void text_symbolizer_properties::from_xml(xml_node const& node, fontset_map const& fontsets, bool is_shield)
{
text_properties_from_xml(node);
layout_defaults.from_xml(node,fontsets);
@ -161,7 +161,7 @@ void text_symbolizer_properties::from_xml(xml_node const& node, fontset_map cons
set_old_style_expression(*name_);
}
format_defaults.from_xml(node, fontsets);
format_defaults.from_xml(node, fontsets, is_shield);
formatting::node_ptr n(formatting::node::from_xml(node,fontsets));
if (n) set_format_tree(n);
}
@ -326,13 +326,21 @@ format_properties::format_properties()
text_transform(enumeration_wrapper(NONE)),
font_feature_settings(std::make_shared<mapnik::font_feature_settings>()) {}
void format_properties::from_xml(xml_node const& node, fontset_map const& fontsets)
void format_properties::from_xml(xml_node const& node, fontset_map const& fontsets, bool is_shield)
{
set_property_from_xml<double>(text_size, "size", node);
set_property_from_xml<double>(character_spacing, "character-spacing", node);
set_property_from_xml<double>(line_spacing, "line-spacing", node);
set_property_from_xml<double>(halo_radius, "halo-radius", node);
set_property_from_xml<double>(text_opacity, "opacity", node);
// https://github.com/mapnik/mapnik/issues/2507
if (is_shield)
{
set_property_from_xml<double>(text_opacity, "text-opacity", node);
}
else
{
set_property_from_xml<double>(text_opacity, "opacity", node);
}
set_property_from_xml<double>(halo_opacity, "halo-opacity", node);
set_property_from_xml<color>(fill, "fill", node);
set_property_from_xml<color>(halo_fill, "halo-fill", node);
@ -380,10 +388,15 @@ void format_properties::to_xml(boost::property_tree::ptree & node, bool explicit
if (!(character_spacing == dfl.character_spacing) || explicit_defaults) serialize_property("character-spacing", character_spacing, node);
if (!(line_spacing == dfl.line_spacing) || explicit_defaults) serialize_property("line-spacing", line_spacing, node);
if (!(halo_radius == dfl.halo_radius) || explicit_defaults) serialize_property("halo-radius", halo_radius, node);
// for shield_symbolizer this is later overridden -- FIXME
if (!(text_opacity == dfl.text_opacity) || explicit_defaults) serialize_property("opacity", text_opacity, node);
// NOTE: this is dodgy: for text-symbolizer this should do the right thing
// but for shield_symbolizer it won't but 'opacity' should be overwritten by save_map later on
// since it is a property of the symbolizer_base rather than these properties
if (!(text_opacity == dfl.text_opacity) || explicit_defaults)
{
serialize_property("text-opacity", text_opacity, node);
serialize_property("opacity", text_opacity, node);
}
if (!(halo_opacity == dfl.halo_opacity) || explicit_defaults) serialize_property("halo-opacity", halo_opacity, node);
//
if (!(fill == dfl.fill) || explicit_defaults) serialize_property("fill", fill, node);
if (!(halo_fill == dfl.halo_fill) || explicit_defaults) serialize_property("halo-fill", halo_fill, node);
if (!(text_transform == dfl.text_transform) || explicit_defaults) serialize_property("text-transform", text_transform, node);