Exemplo n.º 1
0
void grid_renderer<T>::process(text_symbolizer const& sym,
                               mapnik::feature_impl & feature,
                               proj_transform const& prj_trans)
{
    text_symbolizer_helper<face_manager<freetype_engine>,
        label_collision_detector4> helper(
            sym, feature, prj_trans,
            width_, height_,
            scale_factor_ * (1.0/pixmap_.get_resolution()),
            t_, font_manager_, *detector_,
            query_extent_);
    bool placement_found = false;

    text_renderer<T> ren(pixmap_,
                         font_manager_,
                         sym.get_halo_rasterizer(),
                         sym.comp_op(),
                         scale_factor_);

    while (helper.next()) {
        placement_found = true;
        placements_type const& placements = helper.placements();
        for (unsigned int ii = 0; ii < placements.size(); ++ii)
        {
            ren.prepare_glyphs(placements[ii]);
            ren.render_id(feature.id(), placements[ii].center);
        }
    }
    if (placement_found) pixmap_.add_feature(feature);

}
   static boost::python::tuple
   getinitargs(const text_symbolizer& t)
   {

       return boost::python::make_tuple("TODO",//t.get_name(),
					t.get_face_name(),t.get_text_size(),t.get_fill());
       
   }
Exemplo n.º 3
0
 void operator () (text_symbolizer const& sym)
 {
     expression_set::const_iterator it;
     expression_set expressions;
     sym.get_placement_options()->add_expressions(expressions);
     for (it=expressions.begin(); it != expressions.end(); it++)
     {
         if (*it) boost::apply_visitor(f_attr, **it);
     }
     collect_transform(sym.get_transform());
 }
void agg_renderer<T>::process(text_symbolizer const& sym,
                              mapnik::feature_impl & feature,
                              proj_transform const& prj_trans)
{
    box2d<double> clip_box = clipping_extent();
    text_symbolizer_helper helper(
            sym, feature, prj_trans,
            width_, height_,
            scale_factor_,
            t_, font_manager_, *detector_,
            clip_box);

    agg_text_renderer<T> ren(*current_buffer_, sym.get_halo_rasterizer(), sym.comp_op(), scale_factor_, font_manager_.get_stroker());

    placements_list const& placements = helper.get();
    for (glyph_positions_ptr glyphs : placements)
    {
        ren.render(*glyphs);
    }
}
Exemplo n.º 5
0
void grid_renderer<T>::process(text_symbolizer const& sym,
                              Feature const& feature,
                              proj_transform const& prj_trans)
{
    typedef  coord_transform2<CoordTransform,geometry_type> path_type;

    bool placement_found = false;
    text_placement_info_ptr placement_options = sym.get_placement_options()->get_placement_info();
    while (!placement_found && placement_options->next())
    {
        expression_ptr name_expr = sym.get_name();
        if (!name_expr) return;
        value_type result = boost::apply_visitor(evaluate<Feature,value_type>(feature),*name_expr);
        UnicodeString text = result.to_unicode();

        if ( sym.get_text_transform() == UPPERCASE)
        {
            text = text.toUpper();
        }
        else if ( sym.get_text_transform() == LOWERCASE)
        {
            text = text.toLower();
        }
        else if ( sym.get_text_transform() == CAPITALIZE)
        {
            text = text.toTitle(NULL);
        }

        if ( text.length() <= 0 ) continue;
        color const& fill = sym.get_fill();

        face_set_ptr faces;

        if (sym.get_fontset().size() > 0)
        {
            faces = font_manager_.get_face_set(sym.get_fontset());
        }
        else
        {
            faces = font_manager_.get_face_set(sym.get_face_name());
        }

        stroker_ptr strk = font_manager_.get_stroker();
        if (!(faces->size() > 0 && strk))
        {
            throw config_error("Unable to find specified font face '" + sym.get_face_name() + "'");
        }
        text_renderer<T> ren(pixmap_, faces, *strk);
        ren.set_pixel_size(placement_options->text_size * (scale_factor_ * (1.0/pixmap_.get_resolution())));
        ren.set_fill(fill);
        ren.set_halo_fill(sym.get_halo_fill());
        ren.set_halo_radius(sym.get_halo_radius() * scale_factor_);
        ren.set_opacity(sym.get_text_opacity());

        // /pixmap_.get_resolution() ?
        box2d<double> dims(0,0,width_,height_);
        placement_finder<label_collision_detector4> finder(detector_,dims);

        string_info info(text);

        faces->get_string_info(info);
        unsigned num_geom = feature.num_geometries();
        for (unsigned i=0; i<num_geom; ++i)
        {
            geometry_type const& geom = feature.get_geometry(i);
            if (geom.num_points() == 0) continue; // don't bother with empty geometries
            while (!placement_found && placement_options->next_position_only())
            {
                placement text_placement(info, sym, scale_factor_);
                text_placement.avoid_edges = sym.get_avoid_edges();
                if (sym.get_label_placement() == POINT_PLACEMENT ||
                        sym.get_label_placement() == INTERIOR_PLACEMENT)
                {
                    double label_x, label_y, z=0.0;
                    if (sym.get_label_placement() == POINT_PLACEMENT)
                        geom.label_position(&label_x, &label_y);
                    else
                        geom.label_interior_position(&label_x, &label_y);
                    prj_trans.backward(label_x,label_y, z);
                    t_.forward(&label_x,&label_y);

                    double angle = 0.0;
                    expression_ptr angle_expr = sym.get_orientation();
                    if (angle_expr)
                    {
                        // apply rotation
                        value_type result = boost::apply_visitor(evaluate<Feature,value_type>(feature),*angle_expr);
                        angle = result.to_double();
                    }

                    finder.find_point_placement(text_placement, placement_options,
                                                label_x, label_y,
                                                angle, sym.get_line_spacing(),
                                                sym.get_character_spacing());

                    finder.update_detector(text_placement);
                }
                else if ( geom.num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT)
                {
                    path_type path(t_,geom,prj_trans);
                    finder.find_line_placements<path_type>(text_placement, placement_options, path);
                }

                if (!text_placement.placements.size()) continue;
                placement_found = true;

                for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ii)
                {
                    double x = text_placement.placements[ii].starting_x;
                    double y = text_placement.placements[ii].starting_y;
                    ren.prepare_glyphs(&text_placement.placements[ii]);
                    ren.render_id(feature.id(),x,y,2);
                }
            }
        }
    }
    if (placement_found)
        pixmap_.add_feature(feature);
}
	void operator () (text_symbolizer const& sym)
	{
	    names_.insert(sym.get_name());
	}
   static void
   setstate (text_symbolizer& t, boost::python::tuple state)
   {
        using namespace boost::python;
        
        if (len(state) != 14)
        {
            PyErr_SetObject(PyExc_ValueError,
                         ("expected 15-item tuple in call to __setstate__; got %s"
                          % state).ptr()
            );
            throw_error_already_set();
        }
        
        list disp = extract<list>(state[0]);
        double dx = extract<double>(disp[0]);
        double dy = extract<double>(disp[1]);
        t.set_displacement(dx,dy);
        
        t.set_label_placement(extract<label_placement_e>(state[1]));

        t.set_vertical_alignment(extract<vertical_alignment_e>(state[2]));
        
        t.set_halo_radius(extract<unsigned>(state[3]));

        t.set_halo_fill(extract<color>(state[4]));

        t.set_text_ratio(extract<unsigned>(state[5]));

        t.set_wrap_width(extract<unsigned>(state[6]));

        t.set_label_spacing(extract<unsigned>(state[7]));

        t.set_minimum_distance(extract<double>(state[8]));

        t.set_allow_overlap(extract<bool>(state[9]));
        
        list anch = extract<list>(state[10]);
        double x = extract<double>(anch[0]);
        double y = extract<double>(anch[1]);
        t.set_anchor(x,y);
        
        t.set_force_odd_labels(extract<bool>(state[11]));
        
        t.set_max_char_angle_delta(extract<double>(state[12]));
        
        list extras = extract<list>(state[13]);
        t.set_wrap_char_from_string(extract<std::string>(extras[0]));
        t.set_line_spacing(extract<unsigned>(extras[1]));
        t.set_character_spacing(extract<unsigned>(extras[2]));
        t.set_text_convert(extract<text_convert_e>(extras[3]));

   }
 static  boost::python::tuple
 getstate(const text_symbolizer& t)
 {
      boost::python::list disp = get_displacement_list(t);
      boost::python::list anchor = get_anchor_list(t);
      
      // so we do not exceed max args accepted by make_tuple,
      // lets put the increasing list of parameters in a list
      boost::python::list extras;
      extras.append(t.get_wrap_char_string());
      extras.append(t.get_line_spacing());
      extras.append(t.get_character_spacing());
      extras.append(t.get_text_convert());
              
      return boost::python::make_tuple(disp,t.get_label_placement(),
      t.get_vertical_alignment(),t.get_halo_radius(),t.get_halo_fill(),t.get_text_ratio(),
      t.get_wrap_width(),t.get_label_spacing(),t.get_minimum_distance(),t.get_allow_overlap(),
      anchor,t.get_force_odd_labels(),t.get_max_char_angle_delta(),extras
      );
 }