stash work on trying to convert font_feature_settings to be passed by value

This commit is contained in:
Dane Springmeyer 2014-10-09 19:23:11 -07:00
parent 2e4a9cfaf2
commit 364af033a2
10 changed files with 26 additions and 25 deletions

View File

@ -289,7 +289,6 @@ struct evaluate_expression_wrapper<mapnik::color>
mapnik::color operator() (T1 const& expr, T2 const& feature, T3 const& vars) const
{
mapnik::value_type val = util::apply_visitor(mapnik::evaluate<T2,mapnik::value_type,T3>(feature,vars), expr);
// FIXME - throw instead?
if (val.is_null()) return mapnik::color(255,192,203); // pink
return mapnik::color(val.to_string());
}
@ -314,7 +313,6 @@ struct evaluate_expression_wrapper<mapnik::dash_array>
mapnik::dash_array operator() (T1 const& expr, T2 const& feature, T3 const& vars) const
{
mapnik::value_type val = util::apply_visitor(mapnik::evaluate<T2,mapnik::value_type,T3>(feature,vars), expr);
// FIXME - throw?
if (val.is_null()) return dash_array();
dash_array dash;
std::vector<double> buf;
@ -327,17 +325,16 @@ struct evaluate_expression_wrapper<mapnik::dash_array>
}
};
// mapnik::font_feature_settings_ptr
// mapnik::font_feature_settings
template <>
struct evaluate_expression_wrapper<mapnik::font_feature_settings_ptr>
struct evaluate_expression_wrapper<mapnik::font_feature_settings>
{
template <typename T1, typename T2, typename T3>
mapnik::font_feature_settings_ptr operator() (T1 const& expr, T2 const& feature, T3 const& vars) const
mapnik::font_feature_settings operator() (T1 const& expr, T2 const& feature, T3 const& vars) const
{
mapnik::value_type val = util::apply_visitor(mapnik::evaluate<T2, mapnik::value_type, T3>(feature, vars), expr);
// FIXME - throw instead?
if (val.is_null()) return std::make_shared<mapnik::font_feature_settings>();
return std::make_shared<mapnik::font_feature_settings>(val.to_string());
if (val.is_null()) return mapnik::font_feature_settings();
return mapnik::font_feature_settings(val.to_string());
}
};

View File

@ -94,7 +94,7 @@ using value_base_type = util::variant<value_bool,
dash_array,
raster_colorizer_ptr,
group_symbolizer_properties_ptr,
font_feature_settings_ptr>;
font_feature_settings>;
struct strict_value : value_base_type
{

View File

@ -52,12 +52,16 @@ public:
const font_feature* get_features() const { return features_.data(); }
feature_vector::size_type count() const { return features_.size(); }
feature_vector const& features() const { return features_; }
private:
feature_vector features_;
};
using font_feature_settings_ptr = std::shared_ptr<font_feature_settings>;
inline bool operator==(font_feature_settings const& lhs, font_feature_settings const& rhs)
{
return (lhs.features() == rhs.features());
}
constexpr unsigned int font_feature_range_global_start = 0u;
static const unsigned int font_feature_range_global_end = std::numeric_limits<unsigned int>::max();

View File

@ -76,7 +76,7 @@ static void shape_text(text_line & line,
hb_buffer_pre_allocate(buffer.get(), length);
mapnik::value_unicode_string const& text = itemizer.text();
font_feature_settings_ptr features = list.front().format->font_feature_settings;
font_feature_settings features = list.front().format->font_feature_settings;
for (auto const& text_item : list)
{
@ -93,7 +93,7 @@ static void shape_text(text_line & line,
hb_buffer_set_direction(buffer.get(), (text_item.rtl == UBIDI_RTL)?HB_DIRECTION_RTL:HB_DIRECTION_LTR);
hb_buffer_set_script(buffer.get(), _icu_script_to_script(text_item.script));
hb_font_t *font(hb_ft_font_create(face->get_face(), nullptr));
hb_shape(font, buffer.get(), features->get_features(), features->count());
hb_shape(font, buffer.get(), features.get_features(), features.count());
hb_font_destroy(font);
unsigned num_glyphs = hb_buffer_get_length(buffer.get());

View File

@ -60,7 +60,7 @@ struct evaluated_format_properties
fill(0,0,0),
halo_fill(0,0,0),
halo_radius(0.0),
font_feature_settings(std::make_shared<mapnik::font_feature_settings>()) {}
font_feature_settings() {}
std::string face_name;
boost::optional<font_set> fontset;
double text_size;
@ -72,7 +72,7 @@ struct evaluated_format_properties
color fill;
color halo_fill;
double halo_radius;
font_feature_settings_ptr font_feature_settings;
font_feature_settings font_feature_settings;
};
}

View File

@ -201,13 +201,13 @@ struct do_xml_attribute_cast<mapnik::expression_ptr>
}
};
// specialization for mapnik::font_feature_settings_ptr
// specialization for mapnik::font_feature_settings
template <>
struct do_xml_attribute_cast<mapnik::font_feature_settings_ptr>
struct do_xml_attribute_cast<mapnik::font_feature_settings>
{
static inline boost::optional<mapnik::font_feature_settings_ptr> xml_attribute_cast_impl(xml_tree const& tree, std::string const& source)
static inline boost::optional<mapnik::font_feature_settings> xml_attribute_cast_impl(xml_tree const& tree, std::string const& source)
{
return std::make_shared<font_feature_settings>(source);
return font_feature_settings(source);
}
};

View File

@ -75,7 +75,7 @@ node_ptr format_node::from_xml(xml_node const& xml, fontset_map const& fontsets)
set_property_from_xml<color>(n->fill, "fill", xml);
set_property_from_xml<color>(n->halo_fill, "halo-fill", xml);
set_property_from_xml<text_transform_e>(n->text_transform, "text-transform", xml);
set_property_from_xml<font_feature_settings_ptr>(n->font_feature_settings, "font-feature-settings", xml);
set_property_from_xml<font_feature_settings>(n->font_feature_settings, "font-feature-settings", xml);
boost::optional<std::string> face_name = xml.get_opt_attr<std::string>("face-name");
if (face_name)
@ -115,7 +115,7 @@ void format_node::apply(evaluated_format_properties_ptr p, feature_impl const& f
if (fill) new_properties->fill = util::apply_visitor(extract_value<color>(feature,attrs), *fill);
if (halo_fill) new_properties->halo_fill = util::apply_visitor(extract_value<color>(feature,attrs), *halo_fill);
if (text_transform) new_properties->text_transform = util::apply_visitor(extract_value<text_transform_enum>(feature,attrs), *text_transform);
if (font_feature_settings) new_properties->font_feature_settings = util::apply_visitor(extract_value<font_feature_settings_ptr>(feature,attrs), *font_feature_settings);
if (font_feature_settings) new_properties->font_feature_settings = util::apply_visitor(extract_value<font_feature_settings>(feature,attrs), *font_feature_settings);
if (fontset)
{

View File

@ -70,7 +70,7 @@ struct property_serializer : public util::static_visitor<>
node_.put("<xmlattr>." + name_, str);
}
void operator() (font_feature_settings_ptr const& val) const
void operator() (font_feature_settings const& val) const
{
std::string str = val->to_string();
node_.put("<xmlattr>." + name_, str);

View File

@ -98,7 +98,7 @@ void text_symbolizer_properties::process(text_layout & output, feature_impl cons
format->face_name = format_defaults.face_name;
format->fontset = format_defaults.fontset;
format->font_feature_settings = util::apply_visitor(extract_value<font_feature_settings_ptr>(feature,attrs), format_defaults.font_feature_settings);
format->font_feature_settings = util::apply_visitor(extract_value<font_feature_settings>(feature,attrs), format_defaults.font_feature_settings);
// Turn off ligatures if character_spacing > 0.
if (format->character_spacing > .0 && format->font_feature_settings->count() == 0)
{
@ -345,7 +345,7 @@ void format_properties::from_xml(xml_node const& node, fontset_map const& fontse
set_property_from_xml<color>(fill, "fill", node);
set_property_from_xml<color>(halo_fill, "halo-fill", node);
set_property_from_xml<text_transform_e>(text_transform,"text-transform", node);
set_property_from_xml<font_feature_settings_ptr>(font_feature_settings, "font-feature-settings", node);
set_property_from_xml<font_feature_settings>(font_feature_settings, "font-feature-settings", node);
optional<std::string> face_name_ = node.get_opt_attr<std::string>("face-name");
if (face_name_) face_name = *face_name_;

View File

@ -77,7 +77,7 @@ DEFINE_NAME_TRAIT( mapnik::value_integer, "int" )
DEFINE_NAME_TRAIT( std::string, "string" )
DEFINE_NAME_TRAIT( color, "color" )
DEFINE_NAME_TRAIT( expression_ptr, "expression_ptr" )
DEFINE_NAME_TRAIT( font_feature_settings_ptr, "font-feature-settings" )
DEFINE_NAME_TRAIT( font_feature_settings, "font-feature-settings" )
template <typename ENUM, int MAX>
struct name_trait< mapnik::enumeration<ENUM, MAX> >
@ -429,7 +429,7 @@ compile_get_opt_attr(justify_alignment_e);
compile_get_opt_attr(text_upright_e);
compile_get_opt_attr(halo_rasterizer_e);
compile_get_opt_attr(expression_ptr);
compile_get_opt_attr(font_feature_settings_ptr);
compile_get_opt_attr(font_feature_settings);
compile_get_attr(std::string);
compile_get_attr(filter_mode_e);
compile_get_attr(point_placement_e);